FREEDM DGI
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
freedm::broker::lb::LBAgent Class Reference

#include <LoadBalance.hpp>

Inheritance diagram for freedm::broker::lb::LBAgent:
freedm::broker::IDGIModule

Public Member Functions

 LBAgent ()
 
int Run ()
 

Protected Member Functions

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

Private Types

enum  State { SUPPLY, DEMAND, NORMAL }
 

Private Member Functions

void DraftStandard (const boost::system::error_code &error)
 The code that runs after the draft request replies have arrived. More...
 
void FirstRound (const boost::system::error_code &error)
 The code that runs the firtst round of the LB phase. More...
 
void HandleCollectedState (const sc::CollectedStateMessage &m)
 Handles the collected state coming from state collection. More...
 
void HandleCollectedState (const CollectedStateMessage &m)
 Handles the collected state coming from load balancing. More...
 
void HandleDraftAccept (const DraftAcceptMessage &m, CPeerNode peer)
 Handles the draft accept message coming from the demand node. More...
 
void HandleDraftAge (const DraftAgeMessage &m, CPeerNode peer)
 Handles the draft age message coming from the demand node. More...
 
void HandleDraftRequest (const DraftRequestMessage &m, CPeerNode peer)
 Handles the draft request originating from the supply node. More...
 
void HandleDraftSelect (const DraftSelectMessage &m, CPeerNode peer)
 Handles the draft select message coming from the supply node. More...
 
void HandleIncomingMessage (boost::shared_ptr< const ModuleMessage > m, CPeerNode peer)
 First handler for an incoming message. More...
 
void HandlePeerList (const gm::PeerListMessage &m, CPeerNode peer)
 Handles the peerlist coming from the group leader. More...
 
void HandleStateChange (const StateChangeMessage &m, CPeerNode peer)
 Handles a node announcing its state change. More...
 
void HandleTooLate (const TooLateMessage &m)
 Handles the draft reject message coming from the demand node. More...
 
bool InvariantCheck ()
 Check the invariant prior to starting a new migration. More...
 
void LoadManage (const boost::system::error_code &error)
 The code that the supply nodes use to start doing migrations. More...
 
void LoadTable ()
 Displays the load table to show DGI state. More...
 
ModuleMessage MessageCollectedState (float state)
 
ModuleMessage MessageDraftAccept (float amount)
 Generates the message that the demand node uses to confirm the migration. More...
 
ModuleMessage MessageDraftAge (float age)
 Generates message demand nodes send in response to DraftRequest. More...
 
ModuleMessage MessageDraftRequest ()
 Generates message supply nodes send to demand nodes. More...
 
ModuleMessage MessageDraftSelect (float amount)
 Generates the message that the supply node uses to select a demand node. More...
 
ModuleMessage MessageStateChange (std::string state)
 Generates the message announcing current node state. More...
 
ModuleMessage MessageStateCollection ()
 Generates the message used to request a state collection. More...
 
ModuleMessage MessageTooLate (float amount)
 Generates the message sent by the demand node to refuse migration. More...
 
void MoveToPeerSet (PeerSet &ps, CPeerNode peer)
 Moves a peer to the specified peerset. More...
 
ModuleMessage PrepareForSending (const LoadBalancingMessage &m, std::string recipient="lb")
 Boilerplate for preparing a message. More...
 
void ReadDevices ()
 Updates the state from the devices. More...
 
void ScheduleNextRound ()
 Schedules the LoadManage that runs next round. More...
 
void ScheduleStateCollection ()
 Sends the request to perform state collection. More...
 
void SendDraftAccept (CPeerNode peer, float step)
 Sends draft accept to the specified peer. More...
 
void SendDraftAge (CPeerNode peer)
 Sends draftage to the specified peer. More...
 
void SendDraftRequest ()
 Sends Draft request to all the demand peers. More...
 
void SendDraftSelect (CPeerNode peer, float step)
 Sends a draft select to the specified peer. More...
 
void SendTooLate (CPeerNode peer, float step)
 Sends too late to the specified peer. More...
 
void SendToPeerSet (const PeerSet &ps, const ModuleMessage &m)
 Sends a message to all peers in a peerset. More...
 
void SetDESD (float desd)
 Sets DESD value to the specified level. More...
 
void SetPStar (float pstar)
 Sets PStar to the specified level. More...
 
void Synchronize (float k)
 Synchronizes the Fast-Style Loadbalance with the physical system. More...
 
void UpdateState ()
 Updates the node's state. More...
 

Private Attributes

PeerSet m_AllPeers
 All peers in group. More...
 
std::map< std::string, float > m_DraftAge
 Pending migrations. More...
 
float m_Gateway
 The gateway of this node. More...
 
PeerSet m_InDemand
 Peers in the demand state. More...
 
PeerSet m_InNormal
 Peers in the normal state. More...
 
PeerSet m_InSupply
 Peers in the supply state. More...
 
std::string m_Leader
 The coordinator of the group. More...
 
float m_MigrationStep
 The amount to migrate. More...
 
float m_NetGeneration
 The amount of generation created by attached devices. More...
 
float m_PowerDifferential
 The powerflow used by the physical invariant. More...
 
float m_PredictedGateway
 The gateway that we predict will be met by the devices. More...
 
CBroker::TimerHandle m_RoundTimer
 Timer handle for the round timer. More...
 
State m_State
 The current state of this peer. More...
 
bool m_Synchronized
 If the system is synchronized with the physical system. More...
 
CBroker::TimerHandle m_WaitTimer
 Timer handle for the request timer. More...
 
const boost::posix_time::time_duration REQUEST_TIMEOUT
 The time it takes to get a draftrequest response. More...
 
const boost::posix_time::time_duration ROUND_TIME
 The amount of time it takes to do an LB round. More...
 

Member Enumeration Documentation

Enumerator
SUPPLY 
DEMAND 
NORMAL 

Constructor & Destructor Documentation

freedm::broker::lb::LBAgent::LBAgent ( )

LBAgent

Description:
: Constructor for the load balancing module
Precondition:
: Posix Main should register read handler and invoke this module
Postcondition:
: Object is initialized and ready to run load balancing
Limitations:
: None

Member Function Documentation

void freedm::broker::lb::LBAgent::DraftStandard ( const boost::system::error_code &  error)
private

DraftStandard

Description:
This function is used to select the process(es) that the migration will happen with. The demand nodes send DraftAge messages indicating the amount of demand to fill.
Precondition:
DraftRequests were sent to the nodes whose replies will be processed
Postcondition:
DraftSelect messages are sent to the selected demand nodes.
void freedm::broker::lb::LBAgent::FirstRound ( const boost::system::error_code &  error)
private

FirstRound

Description:
The code that is executed as part of the first loadbalance each round.
Precondition:
None
Postcondition:
if the timer wasn't cancelled this function requests state collection and calls the first load balance.
Parameters
errorThe reason this function was called.
CPeerNode IDGIModule::GetMe ( )
protectedinherited

GetMe

Description:
Gets a CPeerNode that refers to this process.
Returns
A CPeerNode referring to this process.
std::string IDGIModule::GetUUID ( ) const
protectedinherited

GetUUID

Description:
Gets this process's UUID.
Returns
This process's UUID
void freedm::broker::lb::LBAgent::HandleCollectedState ( const sc::CollectedStateMessage &  m)
private

HandleCollectedState

Description:
State collection returns the collected state (via a message) this function handles that message and stores it into this node.
Precondition:
The message is valid
Postcondition:
The aggregate gateway, normal and demand member variables are set. Sends the normal to the members of the group.
Parameters
mThe message body that was recieved by this process.
Interaction Peers:
My state collection module, Members of my group.
Limitations:
Does not validate the source, integrity or contents of the message.
void freedm::broker::lb::LBAgent::HandleCollectedState ( const CollectedStateMessage &  m)
private

HandleCollectedState

Description:
When the collected state arrives, the leader computes normal and pushes it out to all the peers. This method sets the normal value at this peer.
Precondition:
The message is valid
Postcondition:
This node is resynchronized.
Parameters
mThe message body that was recieved by this process.
Interaction Peers:
My leader.
Limitations:
Does not validate the source, integrity or contents of the message.
void freedm::broker::lb::LBAgent::HandleDraftAccept ( const DraftAcceptMessage &  m,
CPeerNode  peer 
)
private

HandleDraftAccept

Description:
An accept message will arrive from a demand node that has selected to accept a migration from this supply node.
Precondition:
m and peer is valid.
Postcondition:
If the node is in supply, it will adjust the gross powerflow to note the reciever has adjusted their power.
Parameters
mThe message body that was recieved by this process.
peerThe process that the message orginated from.
Interaction Peers:
A demand node in my group.
Limitations:
Does not validate the source, integrity or contents of the message.
void freedm::broker::lb::LBAgent::HandleDraftAge ( const DraftAgeMessage &  m,
CPeerNode  peer 
)
private

HandleDraftAge

Description:
A DraftAge message is sent by the demand node to a supply to indicate it is still in a demand state and would like to migrate. After the message is recieved this node will respond with drafting to instruct the demand node to commit a power change.
Precondition:
The message and peer are valid. This node should have sent a draft request message to peer previously.
Postcondition:
If in supply and the demand node is selected, a drafting message will be sent to the demand node.
Parameters
mThe message body that was recieved by this process.
peerThe process that the message orginated from.
Interaction Peers:
A demand node in the group.
Limitations:
Does not validate the source, integrity or contents of the message.
void freedm::broker::lb::LBAgent::HandleDraftRequest ( const DraftRequestMessage &  m,
CPeerNode  peer 
)
private

HandleDraftRequest

Description:
Handler for a DraftRequest message. A request message is sent by a supply node to see if a demand node wants to perform a migration.
Precondition:
The message is fully populated. The peer is valid.
Postcondition:
If this process is in the demand state, a DraftAge message is sent back to the orginating process.
Parameters
mThe message body that was recieved by this process.
peerThe process that the message orginated from.
Interaction Peers:
A group member who was in the supply state.
Limitations:
Does not validate the source, integrity or contents of the message.
void freedm::broker::lb::LBAgent::HandleDraftSelect ( const DraftSelectMessage &  m,
CPeerNode  peer 
)
private

HandleDraftSelect

Description:
A draft select message is accepted by a demand node as an indication a supply node is about to give it some tasty power. When the drafting message arrives the demand node will actuate it's physical leaves and signal the supply node to do the same by sending back an accept message.
Precondition:
There is a valid message pointer and peer passed into the module. All required ptree keys are present.
Postcondition:
If the node is in demand and will take the supply node's power this node will generate an accept message and change a device value to accept the new float.
Parameters
mThe message body that was recieved by this process.
peerThe process that the message orginated from.
Interaction Peers:
A supply node in my group.
Limitations:
Does not validate the source, integrity or contents of the message.
void freedm::broker::lb::LBAgent::HandleIncomingMessage ( boost::shared_ptr< const ModuleMessage >  m,
CPeerNode  peer 
)
privatevirtual

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

Precondition:
None
Postcondition:
The message is handled by the target handler or a warning is produced.
Parameters
mthe incoming message
peerthe node that sent this message (could be this DGI)

Implements freedm::broker::IDGIModule.

void freedm::broker::lb::LBAgent::HandlePeerList ( const gm::PeerListMessage &  m,
CPeerNode  peer 
)
private

HandlePeerList

Description:
Updates the list of peers this node is aware of.
Precondition:
There is a valid message pointer and peer passed into the module.
Postcondition:
The AllPeers, Normal, Supply, and Demand peersets are reset.
Parameters
mThe message body that was recieved by this process.
peerThe process that the message orginated from.
Interaction Peers:
Group leader.
Limitations:
Does not validate the source, integrity or contents of the message.
void freedm::broker::lb::LBAgent::HandleStateChange ( const StateChangeMessage &  m,
CPeerNode  peer 
)
private

HandleStateChange

Description:
Handles a peer announcing it is in a new state
Precondition:
The state message is fully populated. The peer is valid.
Postcondition:
The peer is removed from any state sets it is currently in and placed in a set by the contents of the message.
Parameters
mThe message body that was recieved by this process.
peerThe process that the message orginated from.
Interaction Peers:
A Group member.
Limitations:
Does not validate the source, integrity or contents of the message.
void freedm::broker::lb::LBAgent::HandleTooLate ( const TooLateMessage &  m)
private

HandleTooLate

Description:
An accept message will arrive from a demand node that has selected to accept a migration from this supply node, but no longer needs that power.
Precondition:
m and peer is valid.
Postcondition:
This node will adjust its gross powerflow and revert the power setting to cancel the migration.
Parameters
mThe message body that was recieved by this process.
Interaction Peers:
A demand node in my group.
Limitations:
Does not validate the source, integrity or contents of the message.
bool freedm::broker::lb::LBAgent::InvariantCheck ( )
private

InvariantCheck

Description:
Evaluates the current truth of the physical invariant
Precondition:
none
Postcondition:
calculate the physical invariant using the Omega device
Returns
the truth value of the physical invariant
void freedm::broker::lb::LBAgent::LoadManage ( const boost::system::error_code &  error)
private

LoadManage

Description:
: Manages the execution of the load balancing algorithm by broadcasting load changes and initiating SendDraftRequest() if in Supply
Precondition:
: Node is not in Fail state
Postcondition:
: Load state change is monitored, specific load changes are advertised to peers and restarts on timeout
Interaction Peers:
All peers in case of Demand state and transition to Normal from Demand;
Limitations:
void freedm::broker::lb::LBAgent::LoadTable ( )
private

LoadTable

Description:
Prints the load table: A tool for observing the state of the system.
Precondition:
None
Postcondition:
None
Limitations:
Some entries in Load table could become stale relative to the global state. The definition of Supply/Normal/Demand could change in future
ModuleMessage freedm::broker::lb::LBAgent::MessageCollectedState ( float  state)
private

MessageCollectedState

Description:
Given a state, return a message that announces that new state.
Precondition:
none
Postcondition:
returns a new message
Parameters
statethe normal value to send out.
ModuleMessage freedm::broker::lb::LBAgent::MessageDraftAccept ( float  amount)
private

MessageDraftAccept

Description:
Generates a new accept message
Precondition:
None
Postcondition:
an Accept message is generated.
ModuleMessage freedm::broker::lb::LBAgent::MessageDraftAge ( float  age)
private

MessageDraftAge

Precondition:
None
Postcondition:
A new message is generated
Description:
Creates a new DraftAge message.
ModuleMessage freedm::broker::lb::LBAgent::MessageDraftRequest ( )
private

MessageDraftRequest

Precondition:
None
Postcondition:
A new message is generated
Description:
Creates a new DraftRequest message.
ModuleMessage freedm::broker::lb::LBAgent::MessageDraftSelect ( float  amount)
private

MessageDrafting

Description:
Generates a new DraftSelect message.
Precondition:
None
Postcondition:
a new message is generated.
ModuleMessage freedm::broker::lb::LBAgent::MessageStateChange ( std::string  state)
private

MessageStateChange

Description:
Generates a state change message
Precondition:
None
Postcondition:
Returns the new message.
Parameters
stateis a string describing the new state of Load Balancing
ModuleMessage freedm::broker::lb::LBAgent::MessageStateCollection ( )
private

MessageStateCollection

Description:
Returns a message which is sent to state collection requesting that state collection runs for the given devices.
Precondition:
None
Postcondition:
A CollectState message is created.
ModuleMessage freedm::broker::lb::LBAgent::MessageTooLate ( float  amount)
private

MessageTooLate

Description:
Generates a new too late message
Precondition:
None
Postcondition:
A too late message is generated.
void freedm::broker::lb::LBAgent::MoveToPeerSet ( PeerSet ps,
CPeerNode  peer 
)
private

MoveToPeerSet Moves the given peer to the given peerset, removing it from all other categorized peersets (Normal, Supply Demand).

Precondition:
None
Postcondition:
Peer is removed from all specialized peersets, and then readded to ps.
Parameters
psThe peerset to move the peer to.
peerthe peer to move.
ModuleMessage freedm::broker::lb::LBAgent::PrepareForSending ( const LoadBalancingMessage &  m,
std::string  recipient = "lb" 
)
private

Wraps a LoadBalancingMessage in a ModuleMessage.

Parameters
mthe 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 LoadBalancingMessage
void freedm::broker::lb::LBAgent::ReadDevices ( )
private

ReadDevices

Description:
Reads the device state and updates the appropriate member vars.
Precondition:
None
Postcondition:
m_gateway and m_netgeneration are updated.
int freedm::broker::lb::LBAgent::Run ( )

Run

Description:
Main function which initiates the algorithm
Precondition:
: Posix Main should invoke this function
Postcondition:
: Triggers the drafting algorithm by calling LoadManage()
Limitations:
None
void freedm::broker::lb::LBAgent::ScheduleNextRound ( )
private

ScheduleNextRound

Description:
Computes how much time is remaining and if there isn't enough requests the loadbalance that will run next round.
Precondition:
None
Postcondition:
LoadManage is scheduled for this round OR FirstRound is scheduled for next time.
void freedm::broker::lb::LBAgent::ScheduleStateCollection ( )
private

ScheduleStateCollection

Description:
Sends the request to the state collection module to perform state collection
Precondition:
None
Postcondition:
If this node is the leader a state collection request is sent.
void freedm::broker::lb::LBAgent::SendDraftAccept ( CPeerNode  peer,
float  step 
)
private
void freedm::broker::lb::LBAgent::SendDraftAge ( CPeerNode  peer)
private

SendDraftAge

Description:
Sends a DraftAge message to specified peer announcing how much demand this node has.
Parameters
peerThe process to send this to.
Precondition:
None
Postcondition:
Sends a DraftAge message if this process was in the demand state.
void freedm::broker::lb::LBAgent::SendDraftRequest ( )
private

SendDraftRequest

Description:
Advertise willingness to share load whenever you can supply
Precondition:
: Current load state of this node is 'Supply'
Postcondition:
: Send DraftRequest message to peers in demand state
void freedm::broker::lb::LBAgent::SendDraftSelect ( CPeerNode  peer,
float  step 
)
private

SendDraftSelect

Description:
Sends a DraftSelect Message to specified peer.
Precondition:
Peer and step are valid
Postcondition:
A Draft select emssage is sent to the peer
void freedm::broker::lb::LBAgent::SendTooLate ( CPeerNode  peer,
float  step 
)
private
void freedm::broker::lb::LBAgent::SendToPeerSet ( const PeerSet ps,
const ModuleMessage &  m 
)
private

SendToPeerSet

Description:
Given a message m, send it to every process in peerSet
Precondition:
None
Postcondition:
m is sent to all processes in peerSet
Interaction Peers:
peerSet
Parameters
mThe message to send
psthe processes to send the message to.
void freedm::broker::lb::LBAgent::SetDESD ( float  desdv)
private

SetDesd

Description:
Migrates power by adjusting the gateway settings of the attched Desds
Precondition:
: Current load state of this node is 'Supply' or 'Demand'
Postcondition:
: Set command(s) to Desd
Parameters
Desdthe new desd setting to use.
void freedm::broker::lb::LBAgent::SetPStar ( float  pstar)
private

SetPStar

Description:
Migrates power by adjusting the gateway settings of the attched SSTs
Precondition:
: Current load state of this node is 'Supply' or 'Demand'
Postcondition:
: Set command(s) to SST
Parameters
pstarthe new pstar setting to use.
void freedm::broker::lb::LBAgent::Synchronize ( float  k)
private

Synchronize

Description:
Sets the start of phase values for member variables using the results obtained from state collection.
Precondition:
none
Postcondition:
sets the value of m_PowerDifferential and m_PredictedGateway
Parameters
kThe new value to use for m_PowerDifferential
void freedm::broker::lb::LBAgent::UpdateState ( )
private

UpdateState

Description:
Determines the state of this node with respect to Supply, Demand, Normal.
Precondition:
The values used such as the gateway and migration step are valid and up to date.
Postcondition:
This node may change state.

Member Data Documentation

PeerSet freedm::broker::lb::LBAgent::m_AllPeers
private
std::map<std::string, float> freedm::broker::lb::LBAgent::m_DraftAge
private
float freedm::broker::lb::LBAgent::m_Gateway
private
PeerSet freedm::broker::lb::LBAgent::m_InDemand
private
PeerSet freedm::broker::lb::LBAgent::m_InNormal
private
PeerSet freedm::broker::lb::LBAgent::m_InSupply
private
std::string freedm::broker::lb::LBAgent::m_Leader
private
float freedm::broker::lb::LBAgent::m_MigrationStep
private
float freedm::broker::lb::LBAgent::m_NetGeneration
private
float freedm::broker::lb::LBAgent::m_PowerDifferential
private
float freedm::broker::lb::LBAgent::m_PredictedGateway
private
CBroker::TimerHandle freedm::broker::lb::LBAgent::m_RoundTimer
private
State freedm::broker::lb::LBAgent::m_State
private
bool freedm::broker::lb::LBAgent::m_Synchronized
private
CBroker::TimerHandle freedm::broker::lb::LBAgent::m_WaitTimer
private
const boost::posix_time::time_duration freedm::broker::lb::LBAgent::REQUEST_TIMEOUT
private
const boost::posix_time::time_duration freedm::broker::lb::LBAgent::ROUND_TIME
private

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