FREEDM DGI
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
freedm::broker::gm::GMAgent Class Reference

Declaration of Garcia-Molina Invitation Leader Election algorithm.

#include <GroupManagement.hpp>

Inheritance diagram for freedm::broker::gm::GMAgent:
freedm::broker::IDGIModule

Public Types

enum  {
  NORMAL, DOWN, RECOVERY, REORGANIZATION,
  ELECTION
}
 Module states. More...
 

Public Member Functions

 GMAgent ()
 Constructor for using this object as a module. More...
 
 ~GMAgent ()
 Module destructor. More...
 
int Run ()
 Called to start the system. More...
 

Static Public Member Functions

static PeerSet ProcessPeerList (const PeerListMessage &msg)
 Handles Processing a PeerList. More...
 

Protected Member Functions

CPeerNode GetMe ()
 Gets a CPeerNode representing this process. More...
 
std::string GetUUID () const
 Gets the UUID of this process. More...
 

Private Member Functions

ModuleMessage Accept ()
 Creates an Accept Message. More...
 
CPeerNode AddPeer (std::string uuid)
 Adds a peer to the peer set from UUID. More...
 
CPeerNode AddPeer (CPeerNode peer)
 Adds a peer from a pointer to a peer node object. More...
 
ModuleMessage AreYouCoordinator ()
 Creates AYC Message. More...
 
ModuleMessage AreYouCoordinatorResponse (std::string payload, int seq)
 Creates A Response message. More...
 
ModuleMessage AreYouThere ()
 Creates a AYT, used for Timeout. More...
 
ModuleMessage AreYouThereResponse (std::string payload, int seq)
 Creates A Response message. More...
 
void Check (const boost::system::error_code &err)
 Checks for other up leaders. More...
 
std::string Coordinator () const
 Returns the coordinators uuid. More...
 
CPeerNode GetPeer (const std::string &uuid)
 Gets a pointer to a peer from UUID. More...
 
int GetStatus () const
 Gets the status of a node. More...
 
void HandleAccept (const AcceptMessage &msg, CPeerNode peer)
 Handles recieving accept messsages. More...
 
void HandleAreYouCoordinator (const AreYouCoordinatorMessage &msg, CPeerNode peer)
 Handles recieving are you coordinator messages. More...
 
void HandleAreYouThere (const AreYouThereMessage &msg, CPeerNode peer)
 Handles recieving are you there messsages. More...
 
void HandleIncomingMessage (boost::shared_ptr< const ModuleMessage > msg, CPeerNode peer)
 Handles received messages. More...
 
void HandleInvite (const InviteMessage &msg, CPeerNode peer)
 Handles recieving invite messages. More...
 
void HandlePeerList (const PeerListMessage &msg, CPeerNode peer)
 Hadles recieving peerlists. More...
 
void HandlePeerListQuery (const PeerListQueryMessage &msg, CPeerNode peer)
 Handles recieving peerlist requests. More...
 
void HandleResponseAYC (const AreYouCoordinatorResponseMessage &msg, CPeerNode peer)
 Handles recieving AYC responses. More...
 
void HandleResponseAYT (const AreYouThereResponseMessage &msg, CPeerNode peere)
 Handles recieving AYT responses. More...
 
ModuleMessage Invitation ()
 Creates Group Invitation Message. More...
 
void InviteGroupNodes (const boost::system::error_code &err, PeerSet p_tempSet)
 Sends invitations to all group members. More...
 
bool IsCoordinator () const
 Returns true if this node considers itself a coordinator. More...
 
void Merge (const boost::system::error_code &err)
 Sends invitations to all known nodes. More...
 
ModuleMessage PeerList (std::string requester="all")
 Generates a peer list. More...
 
void Premerge (const boost::system::error_code &err)
 Waits a time period determined by UUID for merge. More...
 
void PushPeerList ()
 Sends the peer list to all group members. More...
 
void Recovery ()
 Resets the algorithm to the default startup state. More...
 
void Recovery (const boost::system::error_code &err)
 Handles no response from timeout message. More...
 
void Reorganize (const boost::system::error_code &err)
 Puts the system into the working state. More...
 
void SetStatus (int status)
 Sets the status of the node. More...
 
void StartMonitor (const boost::system::error_code &err)
 Start the monitor after transient is over. More...
 
void SystemState ()
 Outputs information about the current state to the logger. More...
 
void Timeout (const boost::system::error_code &err)
 Checks that the leader is still alive and working. More...
 

Static Private Member Functions

static ModuleMessage PeerListQuery (std::string requester)
 Generates a CMessage that can be used to query for the group. More...
 
static ModuleMessage PrepareForSending (const GroupManagementMessage &message, std::string recipient="gm")
 Wraps a GroupManagementMessage in a ModuleMessage. More...
 

Private Attributes

boost::posix_time::time_duration AYC_RESPONSE_TIMEOUT
 How long to wait for responses from other nodes. More...
 
boost::posix_time::time_duration AYT_RESPONSE_TIMEOUT
 How long to wait for responses from other nodes. More...
 
boost::posix_time::time_duration CHECK_TIMEOUT
 How long between AYC checks. More...
 
boost::posix_time::time_duration FID_TIMEOUT
 How long to wait before checking attached FIDs. More...
 
boost::posix_time::time_duration INVITE_RESPONSE_TIMEOUT
 How long to wait for responses from other nodes. More...
 
TimedPeerSet m_AYCResponse
 Nodes expecting AYC response from. More...
 
TimedPeerSet m_AYTResponse
 Nodes expecting AYT response from. More...
 
PeerSet m_Coordinators
 Known Coordinators. More...
 
std::map< std::string, bool > m_fidstate
 A store for the state of attached FIDs. More...
 
CBroker::TimerHandle m_fidtimer
 Timer for checking FIDs. More...
 
google::protobuf::uint32 m_GroupID
 The ID number of the current group (Never initialized for fun) More...
 
std::string m_GroupLeader
 The uuid of the group leader. More...
 
int m_groupsbroken
 Number of groups broken. More...
 
int m_groupselection
 Number of elections started. More...
 
int m_groupsformed
 Number of groups formed. More...
 
int m_groupsjoined
 Number of accepts sent. More...
 
unsigned int m_GrpCounter
 The number of groups being formed. More...
 
boost::asio::io_service m_localservice
 The io_service used. More...
 
int m_membership
 Total size of groups after all checks. More...
 
int m_membershipchecks
 Number of membership checks. More...
 
int m_status
 A store for the status of this node. More...
 
CBroker::TimerHandle m_timer
 A timer for stepping through the election process. More...
 
PeerSet m_UpNodes
 Nodes In My Group. More...
 
boost::posix_time::time_duration TIMEOUT_TIMEOUT
 How long beteween AYT checks. More...
 

Member Enumeration Documentation

anonymous enum
Enumerator
NORMAL 
DOWN 
RECOVERY 
REORGANIZATION 
ELECTION 

Constructor & Destructor Documentation

freedm::broker::gm::GMAgent::GMAgent ( )

GMAgent::GMAgent

Description:
Constructor for the group management module.
Limitations:
None
Precondition:
None
Postcondition:
Object initialized and ready to enter run state.
freedm::broker::gm::GMAgent::~GMAgent ( )

GMAgent::~GMAgent

Description:
Class desctructor
Precondition:
None
Postcondition:
The object is ready to be destroyed.

Member Function Documentation

ModuleMessage freedm::broker::gm::GMAgent::Accept ( )
private

GMAgent::Accept

Description:
Creates a new accept message from this node
Precondition:
This node is in a group.
Postcondition:
No change.
Returns
A GroupManagementMessage with the contents of an Accept message
CPeerNode freedm::broker::gm::GMAgent::AddPeer ( std::string  uuid)
private

GMAgent::AddPeer

Description:
Adds a peer to allpeers by uuid.
Precondition:
the UUID is registered in the connection manager
Postcondition:
A new peer object is created and inserted in CGlobalPeerList::instance().
Returns
A pointer to the new peer
Parameters
uuidof the peer to add.
CPeerNode freedm::broker::gm::GMAgent::AddPeer ( CPeerNode  peer)
private

GMAgent::AddPeer

Description:
Adds a peer to all peers by pointer.
Precondition:
the pointer is valid
Postcondition:
The peer object is inserted in CGlobalPeerList::instance().
Returns
A pointer that is the same as the input pointer
Parameters
peera pointer to a peer.
ModuleMessage freedm::broker::gm::GMAgent::AreYouCoordinator ( )
private

GMAgent::AreYouCoordinator

Description:
Creates a new Are You Coordinator message, from this object
Precondition:
The UUID is set
Postcondition:
No change
Returns
A GroupManagementMessage with the contents of an Are You Coordinator Message.
Limitations:
: Can only author messages from this node.
ModuleMessage freedm::broker::gm::GMAgent::AreYouCoordinatorResponse ( std::string  payload,
int  seq 
)
private

GMAgent::AreYouCoordinatorResponse

Description:
Creates a response message (Yes/No) message from this node
Precondition:
This node has a UUID.
Postcondition:
No change.
Parameters
payloadResponse message (typically yes or no)
seqsequence number? (?)
Returns
A GroupManagementMessage with the contents of a Response message
ModuleMessage freedm::broker::gm::GMAgent::AreYouThere ( )
private

GMAgent::AreYouThere

Description:
Creates a new AreYouThere message from this node
Precondition:
This node is in a group.
Postcondition:
No Change.
Returns
A GroupManagementMessage with the contents of an AreYouThere message
ModuleMessage freedm::broker::gm::GMAgent::AreYouThereResponse ( std::string  payload,
int  seq 
)
private

GMAgent::AreYouThereResponse

Description:
Creates a response message (Yes/No) message from this node
Precondition:
This node has a UUID.
Postcondition:
No change.
Parameters
payloadResponse message (typically yes or no)
seqsequence number? (?)
Returns
A GroupManagementMessage with the contents of a Response message
void freedm::broker::gm::GMAgent::Check ( const boost::system::error_code &  err)
private

GMAgent::Check

Description:
This method queries all nodes to Check and see if any of them consider themselves to be Coordinators.
Precondition:
This node is in the normal state.
Postcondition:
Output of a system state and sent messages to all nodes to Check for Coordinators.
Parameters
errError associated with calling timer.
Citation:
GroupManagement (Check).
std::string freedm::broker::gm::GMAgent::Coordinator ( ) const
inlineprivate
CPeerNode IDGIModule::GetMe ( )
protectedinherited

GetMe

Description:
Gets a CPeerNode that refers to this process.
Returns
A CPeerNode referring to this process.
CPeerNode freedm::broker::gm::GMAgent::GetPeer ( const std::string &  uuid)
private

GMAgent::GetPeer

Description:
Gets a peer from All Peers by uuid
Precondition:
None
Postcondition:
None
Parameters
uuidThe uuid of the peer to fetch
Returns
A pointer to the requested peer, or a null pointer if the peer could not be found.
int freedm::broker::gm::GMAgent::GetStatus ( ) const
private
Description:
returns the status stored in the node as an an integer. This means that in an inherited class, you may either define integer constants or an enumeration to generate status values.
std::string IDGIModule::GetUUID ( ) const
protectedinherited

GetUUID

Description:
Gets this process's UUID.
Returns
This process's UUID
void freedm::broker::gm::GMAgent::HandleAccept ( const AcceptMessage &  msg,
CPeerNode  peer 
)
private

GMAgent::HandleAccept

Description:
Handles receiveing the invite accept
Key:
gm.Accept
Precondition:
In an election, and invites have been sent out.
Postcondition:
The sender is added to the tenative list of accepted peers for the group, if the accept messag is for the correct group identifier.
Interaction Peers:
Any node which has received an invite. (This can be any selection of the global peerlist, not just the ones this specific node sent the message to.)
void freedm::broker::gm::GMAgent::HandleAreYouCoordinator ( const AreYouCoordinatorMessage &  msg,
CPeerNode  peer 
)
private

GMAgent::HandleAreYouCoordinator

Description:
Handles receiveing the AYC message
Key:
gm.AreYouCoordinator
Precondition:
None
Postcondition:
The node responds yes or no to the request.
Interaction Peers:
Any node in the system is eligible to receive this at any time.
void freedm::broker::gm::GMAgent::HandleAreYouThere ( const AreYouThereMessage &  msg,
CPeerNode  peer 
)
private

GMAgent::HandleAreYouThere

Description:
Handles recieving the AYT message
Key:
gm.AreYouThere
Precondition:
None
Postcondition:
The node responds yes or no to the request.
Interaction Peers:
Any node in the system is eligible to receive this message at any time.
void freedm::broker::gm::GMAgent::HandleIncomingMessage ( boost::shared_ptr< const ModuleMessage >  msg,
CPeerNode  peer 
)
privatevirtual

"Downcasts" incoming messages into a specific message type, and passes the message to an appropriate handler.

Parameters
msgthe incoming message
peerthe node that sent this message (could be this DGI)

Implements freedm::broker::IDGIModule.

void freedm::broker::gm::GMAgent::HandleInvite ( const InviteMessage &  msg,
CPeerNode  peer 
)
private

GMAgent::HandleInvite

Description:
Handles recieving the invite
Key:
gm.Invite
Precondition:
The system is in the NORMAL state
Postcondition:
The system updates its group to accept the invite and switches to reorganization mode; it will wait for a timeout. If the Ready/Peerlist has not arrived, it will enter recovery. Otherwise, it will resume work as part of the group it was invited to.
Interaction Peers:
Any node could send an invite at any time.
void freedm::broker::gm::GMAgent::HandlePeerList ( const PeerListMessage &  msg,
CPeerNode  peer 
)
private

GMAgent::HandlePeerList

Description:
Handles receiveing the peerlist.
Key:
any.PeerList
Precondition:
The node is in the reorganization or normal state
Postcondition:
The node's peerlist is updated to match that of the incoming message if the message has come from his coordinator.
Interaction Peers:
Coordinator only.
void freedm::broker::gm::GMAgent::HandlePeerListQuery ( const PeerListQueryMessage &  msg,
CPeerNode  peer 
)
private

GMAgent::HandlePeerListQuery

Description:
Handles responding to peerlist queries.
Key:
gm.PeerListQuery
Precondition:
None
Postcondition:
Dispatched a message to the requester with a peerlist.
Interaction Peers:
Any. (Local or remote, doesn't have to be a member of group)
void freedm::broker::gm::GMAgent::HandleResponseAYC ( const AreYouCoordinatorResponseMessage &  msg,
CPeerNode  peer 
)
private

GMAgent::HandleResponseAYC

Description:
Handles recieving the Response
Key:
gm.Response.AreYouCoordinator
Precondition:
The timer for the AYC request batch the original request was a part of has not expired
Postcondition:
The response from the sender is noted, if yes, the groups will attempt to merge in the future.
Interaction Peers:
A node the AYC request was sent to.
void freedm::broker::gm::GMAgent::HandleResponseAYT ( const AreYouThereResponseMessage &  msg,
CPeerNode  peer 
)
private

GMAgent::HandleResponseAYT

Description:
Handles recieving the Response
Key:
gm.Response.AreYouThere
Precondition:
The timer for the AYT request batch (typically 1) the original request was a part of has not expired
Postcondition:
The response from the sender is noted. If the answer is no, then this node will enter recovery, if the recovery timer has not already been set, otherwise we will allow it to expire.
ModuleMessage freedm::broker::gm::GMAgent::Invitation ( )
private

GMAgent::Invitation

Description:
Creates a new invation message from the leader of this node's current leader, to join this group.
Precondition:
The node is currently in a group.
Postcondition:
No change
Returns
A GroupManagementMessage with the contents of a Invitation message.
void freedm::broker::gm::GMAgent::InviteGroupNodes ( const boost::system::error_code &  err,
PeerSet  p_tempSet 
)
private

GMAgent::InviteGroupNodes

Description:
This function will invite all the members of a node's old group to join it's new group.
Precondition:
None
Postcondition:
Invitations have been sent to members of this node's old group. if this node is a Coordinator, this node sets a timer for Reorganize
Parameters
errThe error message associated with the calling thimer
p_tempSetThe set of nodes that were members of the old group.
Citation:
Group Management (Merge)
bool freedm::broker::gm::GMAgent::IsCoordinator ( ) const
inlineprivate
void freedm::broker::gm::GMAgent::Merge ( const boost::system::error_code &  err)
private

GMAgent::Merge

Description:
If this node is a Coordinator, this method sends invites to join this node's group to all Coordinators, and then makes a call to second function to invite all current members of this node's old group to the new group.
Precondition:
This node has waited for a Premerge.
Postcondition:
If this node was a Coordinator, this node has been placed in an election state. Additionally, invitations have been sent to all Coordinators this node is aware of. Lastly, this function has called a function or set a timer to invite its old group nodes.
Parameters
errA error associated with the calling timer.
Citation:
Group Management (Merge)
ModuleMessage freedm::broker::gm::GMAgent::PeerList ( std::string  requester = "all")
private

GMAgent::PeerList

Description:
Packs the group list (Up_Nodes) in GroupManagementMessage
Precondition:
This node is a leader.
Postcondition:
No Change.
Returns
A GroupManagementMessage with the contents of group membership
ModuleMessage freedm::broker::gm::GMAgent::PeerListQuery ( std::string  requester)
staticprivate

GMAgent::PeerListQuery

Description:
Generates a GroupManagementMessage that can be used to query the peerlist of a node.
Precondition:
: None
Postcondition:
: No change
Parameters
requesterThe module who the response should be addressed to.
Returns
A GroupManagementMessage which can be used to query for
void freedm::broker::gm::GMAgent::Premerge ( const boost::system::error_code &  err)
private

GMAgent::Premerge

Description:
Handles a proportional wait prior to calling Merge
Precondition:
Check has been called and responses have been collected from other nodes. This node is a Coordinator.
Postcondition:
A timer has been set based on this node's UUID to break up ties before merging.
Parameters
errAn error associated with the clling timer.
Citation:
GroupManagement (Merge)
ModuleMessage freedm::broker::gm::GMAgent::PrepareForSending ( const GroupManagementMessage &  message,
std::string  recipient = "gm" 
)
staticprivate

Wraps a GroupManagementMessage in a ModuleMessage.

Parameters
messagethe message to prepare. If any required field is unset, the DGI will abort.
recipientthe module (sc/lb/gm/clk etc.) the message should be delivered to
Returns
a ModuleMessage containing a copy of the GroupManagementMessage
PeerSet freedm::broker::gm::GMAgent::ProcessPeerList ( const PeerListMessage &  msg)
static

GMAgent::ProcessPeerList

Description:
Provides a utility function for correctly handling incoming peer lists.
Parameters
msgThe message to parse
Returns
A PeerSet with all nodes in the group.
void freedm::broker::gm::GMAgent::PushPeerList ( )
private

GMAgent::PushPeerList

Description:
Sends the membership list to other modules of this node and other nodes
Precondition:
This node is new group leader
Postcondition:
A peer list is pushed to the group members
Returns
Nothing
void freedm::broker::gm::GMAgent::Recovery ( )
private

GMAgent::Recovery

Description:
The method used to set or reset a node into a "solo" state where it is its own leader. To do this, it forms an empty group, then enters a normal state.
Precondition:
None
Postcondition:
The node enters a NORMAL state.
Citation:
Group Management Algorithmn (Recovery).
void freedm::broker::gm::GMAgent::Recovery ( const boost::system::error_code &  err)
private

GMAgent::Recovery

Description:
Recovery function extension for handling timer expirations.
Precondition:
Some timer leading to this function has expired or been canceled.
Postcondition:
If the timer has expired, Recovery begins, if the timer was canceled and this node is NOT a Coordinator, this will cause a Timeout Check using Timeout()
Parameters
errThe error code associated with the calling timer.
void freedm::broker::gm::GMAgent::Reorganize ( const boost::system::error_code &  err)
private

GMAgent::Reorganize

Description:
Organizes the members of the group and prepares them to do their much needed work!
Precondition:
The node is a leader of group.
Postcondition:
The group has received work assignments, ready messages have been sent out, and this node enters the NORMAL state.
Citation:
Group Management Reorganize
int freedm::broker::gm::GMAgent::Run ( )

GMAgent::Run

Description:
Main function which initiates the algorithm
Precondition:
connections to peers should be instantiated
Postcondition:
execution of group management algorithm
void freedm::broker::gm::GMAgent::SetStatus ( int  status)
private
Description:
Sets the internal status variable, m_status based on the paramter status. See GetStatus for tips on establishing the status code numbers.
Parameters
statusThe status code to set
Precondition:
None
Postcondition:
The modules status code has been set to "status"
void freedm::broker::gm::GMAgent::StartMonitor ( const boost::system::error_code &  err)
private
void freedm::broker::gm::GMAgent::SystemState ( )
private

GMAgent::SystemState

Description:
Puts the system state to the logger.
Precondition:
None
Postcondition:
None
void freedm::broker::gm::GMAgent::Timeout ( const boost::system::error_code &  err)
private

GMAgent::Timeout

Description:
Sends an AreYouThere message to the coordinator and sets a timer if the timer expires, this node goes into recovery.
Precondition:
The node is a member of a group, but not the leader
Postcondition:
A timer for recovery is set.
Citation:
Group Managment Timeout

Member Data Documentation

boost::posix_time::time_duration freedm::broker::gm::GMAgent::AYC_RESPONSE_TIMEOUT
private
boost::posix_time::time_duration freedm::broker::gm::GMAgent::AYT_RESPONSE_TIMEOUT
private
boost::posix_time::time_duration freedm::broker::gm::GMAgent::CHECK_TIMEOUT
private
boost::posix_time::time_duration freedm::broker::gm::GMAgent::FID_TIMEOUT
private
boost::posix_time::time_duration freedm::broker::gm::GMAgent::INVITE_RESPONSE_TIMEOUT
private
TimedPeerSet freedm::broker::gm::GMAgent::m_AYCResponse
private
TimedPeerSet freedm::broker::gm::GMAgent::m_AYTResponse
private
PeerSet freedm::broker::gm::GMAgent::m_Coordinators
private
std::map< std::string , bool > freedm::broker::gm::GMAgent::m_fidstate
private
CBroker::TimerHandle freedm::broker::gm::GMAgent::m_fidtimer
private
google::protobuf::uint32 freedm::broker::gm::GMAgent::m_GroupID
private
std::string freedm::broker::gm::GMAgent::m_GroupLeader
private
int freedm::broker::gm::GMAgent::m_groupsbroken
private
int freedm::broker::gm::GMAgent::m_groupselection
private
int freedm::broker::gm::GMAgent::m_groupsformed
private
int freedm::broker::gm::GMAgent::m_groupsjoined
private
unsigned int freedm::broker::gm::GMAgent::m_GrpCounter
private
boost::asio::io_service freedm::broker::gm::GMAgent::m_localservice
private
int freedm::broker::gm::GMAgent::m_membership
private
int freedm::broker::gm::GMAgent::m_membershipchecks
private
int freedm::broker::gm::GMAgent::m_status
private
CBroker::TimerHandle freedm::broker::gm::GMAgent::m_timer
private
PeerSet freedm::broker::gm::GMAgent::m_UpNodes
private
boost::posix_time::time_duration freedm::broker::gm::GMAgent::TIMEOUT_TIMEOUT
private

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