GHS
Leader Election Based on GHS Minimum Spanning Tree
Public Member Functions | Static Public Member Functions | List of all members
demo::Comms Class Reference

a message passing class that uses nng, suitable for testing GhsState More...

#include <ghs-demo-comms.h>

Public Member Functions

bool ok ()
 
Commswith_config (Config &)
 
Errno send (demo::WireMessage &, demo::OptMask=0)
 
void start_receiver ()
 
void stop_receiver ()
 
bool has_msg ()
 
bool get_next (demo::WireMessage &)
 
void little_iperf ()
 
void exchange_iperf ()
 
void print_iperf ()
 
Kbps kbps_to (const uint16_t agent_id) const
 
CommsEdgeMetric unique_link_metric_to (const uint16_t agent_id) const
 This function is really important for the working of your system More...
 

Static Public Member Functions

static Commsinst ()
 

Detailed Description

a message passing class that uses nng, suitable for testing GhsState

This class encapsulates the network layer for a demonstration of GHS over a real network. It is initialized by populating a DemoConfig struct and calling with_config()

After that, you can use send() and call get_next() at will to exchanges messages using nng_socket of type req-rep.

Member Function Documentation

◆ exchange_iperf()

void demo::Comms::exchange_iperf ( )

This will block for a while, during which time it will synchronize with all known endpoints so that everyone uses the same link metric values.

However, the actual link metrics that are used are calculated by unique_link_metric_to()

◆ get_next()

bool demo::Comms::get_next ( demo::WireMessage m)

If has_msg returns true, then this will copy the next message out of the buffer for you to process.

◆ has_msg()

bool demo::Comms::has_msg ( )

Returns true if there is a message waiting in the incoming buffer.

This will always return false until you call start_receiver()

◆ inst()

static Comms& demo::Comms::inst ( )
static

Keep one static instance on hand. You're not required to use it, but we have it nonetheless An usual way to initialize is to call Comms::inst().with_config()

◆ kbps_to()

Kbps demo::Comms::kbps_to ( const uint16_t  agent_id) const

Returns the calculated and observed throughput to the given agent

◆ little_iperf()

void demo::Comms::little_iperf ( )

This will block for a while, during which time it will repeatedly send and receive messages from all known endpoints to guage the throughput of the links. This information is used to populate the GhsState::mwoe() and Edge metric_t information. However, the actual link metrics that are used are calculated by unique_link_metric_to()

◆ print_iperf()

void demo::Comms::print_iperf ( )

Will dump link metric information to stdout

◆ send()

Errno demo::Comms::send ( demo::WireMessage msg,
demo::OptMask  mask = 0 
)

Sends a demo::WireMessage. The demo::WireMessage contains all the destination and routing information in it, so this is a singular call that blocks then returns a status message.

Returns
demo::WireMessageErrno denoting success or failure

◆ start_receiver()

void demo::Comms::start_receiver ( )

Starts a background process to copy incoming message into a buffer for later processing.

This is implementation specific, I use plain old threads here. Note, ZMQ does this for you, but requires a lot of std:: and platform assumptions.

So, we avoid some of that with nng, and one use of std::thread.

◆ stop_receiver()

void demo::Comms::stop_receiver ( )

Stops the background process by interrupting it after it's next timeout, then joining the thread until it exits cleanly. This will block for a few seconds, but shouldn't fail.

◆ unique_link_metric_to()

uint64_t demo::Comms::unique_link_metric_to ( const uint16_t  agent_id) const

This function is really important for the working of your system

Calculates and returns a globally unique metric value that is suitable for use as a metric_t inside GhsState. The metric, once little_iperf() and exchange_iperf() complete and agent ids are globally unique, satisfies:

  • symmetric: All pairs of agents use the same metric for the links between them
  • unique: No edge metric is duplicated between any two edges.

The implementation I used is sym_metric() but that's not required, compile in your own if you want.

See also
sym_metric
le::ghs::metric_t

◆ with_config()

Comms & demo::Comms::with_config ( Config c)

Initialie all the internal data and communication structures with the given config information

The intent is that you would extend this class with other with_config() options.

See also
ghs_read_cfg_file()
ghs_read_cfg_stdin()
ghs_read_cfg_cli()

The documentation for this class was generated from the following files: