GHS
Leader Election Based on GHS Minimum Spanning Tree
ghs.h
Go to the documentation of this file.
1 
41 #ifndef GHS_H
42 #define GHS_H
43 
44 #include "ghs/msg.h"
45 #include "ghs/agent.h"
46 #include "ghs/level.h"
47 #include "ghs/edge.h"
48 #include "le/errno.h"
49 #include "seque/static_queue.h"
50 #include <array>
51 
52 using seque::StaticQueue;
53 
57 namespace le{
58 
62  namespace ghs{
63 
81  template <std::size_t NUM_AGENTS, std::size_t MSG_Q_SIZE>
82  class GhsState
83  {
84 
85  public:
86 
116  GhsState(agent_t my_id, Edge* edges, size_t num_edges);
117  ~GhsState();
118 
144  le::Errno start_round(StaticQueue<Msg, MSG_Q_SIZE> &outgoing_msgs, size_t&);
145 
160  le::Errno process(const Msg &msg, StaticQueue<Msg, MSG_Q_SIZE> &outgoing_buffer, size_t& sz);
161 
166  bool is_converged() const;
167 
172  size_t get_n_peers() const { return n_peers; }
173 
174 
175 
188  le::Errno get_edge(const agent_t& to, Edge& out) const;
189 
209  bool has_edge( const agent_t to) const;
210 
221  le::Errno get_edge_status(const agent_t&to, status_t& out) const;
222 
223 
234  le::Errno get_edge_metric(const agent_t &to, metric_t& m) const;
235 
236 
247  le::Errno is_waiting_for(const agent_t& who, bool & out_waiting_for);
248 
259  le::Errno is_response_required(const agent_t &who, bool & response_required);
260 
271 
279  agent_t get_id() const;
280 
285  agent_t get_parent_id() const;
286 
287 
291  agent_t get_leader_id() const;
292 
296  level_t get_level() const;
297 
308  size_t waiting_count() const;
309 
319  size_t delayed_count() const;
320 
339  Edge mwoe() const;
340 
341 
353  le::Errno checked_index_of(const agent_t&, size_t& ) const;
354 
355 
356 
384  le::Errno mst_broadcast(const msg::Type, const msg::Data&, StaticQueue<Msg, MSG_Q_SIZE> &buf, size_t&) const;
385 
386 
411 
427  le::Errno typecast(const status_t status, const msg::Type, const msg::Data&, StaticQueue<Msg, MSG_Q_SIZE> &buf, size_t&) const;
428 
429 
430  private:
431 
432 
452  le::Errno set_edge(const Edge &e);
453 
458  le::Errno add_edge(const Edge &e){ return set_edge(e);}
459 
488  le::Errno set_edge_status(const agent_t &to, const status_t &status);
489 
510  le::Errno set_edge_metric(const agent_t &to, const metric_t m);
511 
516  le::Errno set_leader_id(const agent_t &leader);
517 
522  le::Errno set_level(const level_t &level);
523 
536  le::Errno set_waiting_for(const agent_t &who, const bool waiting_for);
537 
558  le::Errno set_response_required(const agent_t &who, const bool response_required);
559 
571  le::Errno set_response_prompt(const agent_t &who, const msg::InPartPayload& m);
572 
587  le::Errno set_parent_id(const agent_t& id);
588 
589 
593  le::Errno reset();
594 
595 
596 
600  le::Errno process_srch( agent_t from, const msg::SrchPayload&, StaticQueue<Msg, MSG_Q_SIZE>&, size_t&);
604  le::Errno process_srch_ret( agent_t from, const msg::SrchRetPayload&, StaticQueue<Msg, MSG_Q_SIZE>&, size_t&);
608  le::Errno process_in_part( agent_t from, const msg::InPartPayload&, StaticQueue<Msg, MSG_Q_SIZE>&, size_t&);
612  le::Errno process_ack_part( agent_t from, const msg::AckPartPayload&, StaticQueue<Msg, MSG_Q_SIZE>&, size_t&);
616  le::Errno process_nack_part( agent_t from, const msg::NackPartPayload&, StaticQueue<Msg, MSG_Q_SIZE>&, size_t&);
620  le::Errno process_noop( StaticQueue<Msg, MSG_Q_SIZE>&, size_t&);
621 
626  le::Errno check_search_status( StaticQueue<Msg, MSG_Q_SIZE>&, size_t&);
627 
628  /* Join / Merge / Absorb stage message */
629  //join_us does some heavy lifting to determine how partitions should be restructured and joined
630  le::Errno process_join_us( agent_t from, const msg::JoinUsPayload&, StaticQueue<Msg, MSG_Q_SIZE>&, size_t&);
631 
635  le::Errno check_new_level( StaticQueue<Msg, MSG_Q_SIZE>&, size_t& );
636 
641  le::Errno respond_later(const agent_t&, const msg::InPartPayload);
642 
646  le::Errno respond_no_mwoe( StaticQueue<Msg, MSG_Q_SIZE>&, size_t & );
647 
648 
649  agent_t my_id;
650  agent_t my_leader;
651  level_t my_level;
652  bool algorithm_converged;
653 
654  Edge best_edge;
655 
656  size_t n_peers;
657  std::array<agent_t,NUM_AGENTS> peers;
658  std::array<bool,NUM_AGENTS> waiting_for_response;
659  std::array<Edge,NUM_AGENTS> outgoing_edges;
660  std::array<msg::InPartPayload,NUM_AGENTS> response_prompt;
661  std::array<bool,NUM_AGENTS> response_required;
662 
663  };
664 
665 #include "ghs_impl.hpp"
666 
667  }
668 }
669 
670 #endif
le::ghs::agent_t
int agent_t
problems for GhsState
Definition: agent.h:51
le::ghs::GhsState::get_edge_metric
le::Errno get_edge_metric(const agent_t &to, metric_t &m) const
Definition: ghs_impl.hpp:892
le::ghs::GhsState::get_response_prompt
le::Errno get_response_prompt(const agent_t &who, msg::InPartPayload &m)
Definition: ghs_impl.hpp:825
le::ghs::GhsState::get_edge
le::Errno get_edge(const agent_t &to, Edge &out) const
Definition: ghs_impl.hpp:855
le::ghs::GhsState::waiting_count
size_t waiting_count() const
Definition: ghs_impl.hpp:966
le::ghs::GhsState::typecast
le::Errno typecast(const status_t status, const msg::Type, const msg::Data &, StaticQueue< Msg, MSG_Q_SIZE > &buf, size_t &) const
Definition: ghs_impl.hpp:625
le::ghs::GhsState::mst_broadcast
le::Errno mst_broadcast(const msg::Type, const msg::Data &, StaticQueue< Msg, MSG_Q_SIZE > &buf, size_t &) const
Definition: ghs_impl.hpp:644
le::ghs::GhsState::mst_convergecast
le::Errno mst_convergecast(const msg::Type, const msg::Data &, StaticQueue< Msg, MSG_Q_SIZE > &buf, size_t &) const
Definition: ghs_impl.hpp:662
le::ghs::metric_t
unsigned long metric_t
Definition: edge.h:63
le::ghs::status_t
status_t
A status enumeration, for the ghs edges.
Definition: edge.h:82
le::ghs::GhsState::checked_index_of
le::Errno checked_index_of(const agent_t &, size_t &) const
Definition: ghs_impl.hpp:753
le::ghs::GhsState::start_round
le::Errno start_round(StaticQueue< Msg, MSG_Q_SIZE > &outgoing_msgs, size_t &)
Definition: ghs_impl.hpp:102
le::Errno
Errno
Definition: errno.h:49
static_queue.h
a static-sized single-ended queue for use in GhsState
le::ghs::msg::Type
Type
Stores what type of Msg this is.
Definition: msg.h:58
ghs_impl.hpp
the implementation for le::ghs::GhsState
msg.h
provides the defs for the struct le::ghs::msg
le::ghs::Msg
An aggregate type containing all the data to exchange with to/from information.
Definition: msg.h:143
le::ghs::GhsState::get_level
level_t get_level() const
Definition: ghs_impl.hpp:735
le::ghs::GhsState::process
le::Errno process(const Msg &msg, StaticQueue< Msg, MSG_Q_SIZE > &outgoing_buffer, size_t &sz)
Definition: ghs_impl.hpp:118
level.h
defintion for le::ghs::level_t
le
Definition: agent.h:43
le::ghs::GhsState::mwoe
Edge mwoe() const
Definition: ghs_impl.hpp:113
le::ghs::GhsState::get_n_peers
size_t get_n_peers() const
Definition: ghs.h:172
seque::StaticQueue
a static-sized single-ended queue for use in GhsState
Definition: static_queue.h:60
edge.h
Edge structure definition and functions.
le::ghs::GhsState::get_edge_status
le::Errno get_edge_status(const agent_t &to, status_t &out) const
Definition: ghs_impl.hpp:867
le::ghs::GhsState::is_response_required
le::Errno is_response_required(const agent_t &who, bool &response_required)
Definition: ghs_impl.hpp:803
le::ghs::GhsState::get_id
agent_t get_id() const
Definition: ghs_impl.hpp:991
agent.h
provides le::ghs::agent_t defintion
le::ghs::msg::InPartPayload
Asks "Are you in my partition".
Definition: msg.h:92
le::ghs::GhsState::has_edge
bool has_edge(const agent_t to) const
Definition: ghs_impl.hpp:848
le::ghs::GhsState::delayed_count
size_t delayed_count() const
Definition: ghs_impl.hpp:979
le::ghs::msg::Data
Definition: msg.h:116
le::ghs::GhsState::get_parent_id
agent_t get_parent_id() const
Definition: ghs_impl.hpp:712
le::ghs::Edge
A struct to hold all the communication edge information.
Definition: edge.h:98
le::ghs::GhsState::GhsState
GhsState(agent_t my_id, Edge *edges, size_t num_edges)
Definition: ghs_impl.hpp:56
le::ghs::GhsState::is_waiting_for
le::Errno is_waiting_for(const agent_t &who, bool &out_waiting_for)
Definition: ghs_impl.hpp:780
le::ghs::level_t
int level_t
A "level" which is an internal item for GhsState to track how many times the MST has merged with anot...
Definition: level.h:49
le::ghs::GhsState::is_converged
bool is_converged() const
Definition: ghs_impl.hpp:747
le::ghs::GhsState::get_leader_id
agent_t get_leader_id() const
Definition: ghs_impl.hpp:723
errno.h
Provides error codes for all classes / functions.
le::ghs::GhsState
The main state machine for the GHS algorithm
Definition: ghs.h:82