GHS
Leader Election Based on GHS Minimum Spanning Tree
ghs_printer_impl.hpp
Go to the documentation of this file.
1 
37 #include "ghs/ghs_printer.h"
38 
39 #include <sstream>
40 
41 using le::ghs::Edge;
42 using le::ghs::agent_t;
43 using le::ghs::UNKNOWN;
44 using le::ghs::MST;
46 using le::ghs::DELETED;
47 using namespace le;
48 
52 template <std::size_t A, std::size_t B>
53 std::string dump_edges(const le::ghs::GhsState<A,B> &s) {
54  std::stringstream ss;
55  ss<<"( ";
56  Edge mwoe = s.mwoe();
57  ss<<" m:"<<mwoe.peer;
58  ss<<" mw:"<<mwoe.metric_val;
59  for (std::size_t i=0;i<A;i++){
60  if (s.has_edge(i)){
61  Edge e;
62  if (OK!=s.get_edge((agent_t)i,e)){
63  ss<<"Err: "<<i;
64  continue;
65  };
66  ss<<" ";
67  ss<<e.root<<"-->"<<e.peer<<" ";
68  switch (e.status){
69  case UNKNOWN: {ss<<"UNK";break;}
70  case MST: {ss<<"MST+C ";break;}
71  case MST_PARENT: {ss<<"MST+P ";break;}
72  case DELETED: {ss<<"DEL";break;}
73  }
74  if (e.peer == mwoe.peer){
75  ss<<"m";
76  } else {
77  ss<<"_";
78  }
79  ss<<" "<<e.metric_val<<";";
80  }
81  }
82  ss<<")";
83  return ss.str();
84 }
85 
86 
90 template <std::size_t A, std::size_t B>
91 std::ostream& operator << ( std::ostream& outs, const le::ghs::GhsState<A,B> & s){
92  outs<<"{id:"<<s.get_id()<<" ";
93  outs<<"leader:"<<s.get_leader_id()<<" ";
94  outs<<"level:"<<s.get_level()<<" ";
95  outs<<"waiting:"<<s.waiting_count()<<" ";
96  outs<<"delayed:"<<s.delayed_count()<<" ";
97  outs<<"converged:"<<s.is_converged()<<" ";
98  outs<<"("<<dump_edges(s)<<")";
99  outs<<"}";
100  return outs;
101 }
102 
le::ghs::agent_t
int agent_t
problems for GhsState
Definition: agent.h:51
le::ghs::MST
@ MST
We have added this edge as an MST link.
Definition: edge.h:86
le::ghs::MST_PARENT
@ MST_PARENT
We have added this edge as parent MST link.
Definition: edge.h:88
le::ghs::DELETED
@ DELETED
We have decided not to further consider this edge, either it was "bad", or it is already part of our ...
Definition: edge.h:90
le::ghs::Edge::root
agent_t root
The root is the "from" side of the edge.
Definition: edge.h:106
le
Definition: agent.h:43
le::ghs::Edge::peer
agent_t peer
The peer is the "to" side of the edge.
Definition: edge.h:104
le::ghs::UNKNOWN
@ UNKNOWN
We have not probed this edge for information yet, or have not recieved a reponse.
Definition: edge.h:84
le::ghs::Edge::status
status_t status
The status of this edge, starting with UNKNOWN.
Definition: edge.h:108
ghs_printer.h
some conveneience implementations to print le::ghs::GhsState objects with std::ostream
dump_edges
std::string dump_edges(const le::ghs::GhsState< A, B > &s)
Definition: ghs_printer_impl.hpp:53
le::ghs::Edge::metric_val
metric_t metric_val
By default, this edge has metric_val = WORST_METRIC.
Definition: edge.h:110
le::ghs::Edge
A struct to hold all the communication edge information.
Definition: edge.h:98
operator<<
std::ostream & operator<<(std::ostream &outs, const le::ghs::GhsState< A, B > &s)
Definition: ghs_printer_impl.hpp:91
le::OK
@ OK
The operation was successful.
Definition: errno.h:50
le::ghs::GhsState
The main state machine for the GHS algorithm
Definition: ghs.h:82