FREEDM DGI
LoadBalance.hpp
Go to the documentation of this file.
1 
24 #ifndef LOAD_BALANCE_HPP
25 #define LOAD_BALANCE_HPP
26 
27 #include "CBroker.hpp"
28 #include "CDevice.hpp"
29 #include "CPeerNode.hpp"
30 #include "PeerSets.hpp"
31 #include "IDGIModule.hpp"
32 #include "messages/ModuleMessage.pb.h"
33 
34 #include <map>
35 #include <set>
36 #include <string>
37 #include <boost/shared_ptr.hpp>
38 #include <boost/date_time/posix_time/posix_time_types.hpp>
39 
40 namespace freedm {
41 namespace broker {
42 namespace lb {
43 
44 class LBAgent
45  : public IDGIModule
46 {
47 public:
48  LBAgent();
49  int Run();
50 private:
51  enum State { SUPPLY, DEMAND, NORMAL };
52  //
54  ModuleMessage MessageStateChange(std::string state);
56  ModuleMessage MessageDraftRequest();
58  ModuleMessage MessageDraftAge(float age);
60  ModuleMessage MessageDraftSelect(float amount);
62  ModuleMessage MessageDraftAccept(float amount);
64  ModuleMessage MessageTooLate(float amount);
66  ModuleMessage MessageStateCollection();
68  ModuleMessage MessageCollectedState(float state);
69 
71  ModuleMessage PrepareForSending(const LoadBalancingMessage & m, std::string recipient = "lb");
73  void SendToPeerSet(const PeerSet & ps, const ModuleMessage & m);
74 
76  void HandleIncomingMessage(boost::shared_ptr<const ModuleMessage> m, CPeerNode peer);
78  void HandleStateChange(const StateChangeMessage & m, CPeerNode peer);
80  void HandleDraftRequest(const DraftRequestMessage & m, CPeerNode peer);
82  void HandleDraftAge(const DraftAgeMessage & m, CPeerNode peer);
84  void HandleDraftSelect(const DraftSelectMessage & m, CPeerNode peer);
86  void HandleDraftAccept(const DraftAcceptMessage & m, CPeerNode peer);
88  void HandleTooLate(const TooLateMessage & m);
90  void HandlePeerList(const gm::PeerListMessage & m, CPeerNode peer);
92  void HandleCollectedState(const sc::CollectedStateMessage & m);
94  void HandleCollectedState(const CollectedStateMessage & m);
95 
97  void MoveToPeerSet(PeerSet & ps, CPeerNode peer);
98 
100  void LoadManage(const boost::system::error_code & error);
102  void FirstRound(const boost::system::error_code & error);
104  void DraftStandard(const boost::system::error_code & error);
105 
107  void ScheduleNextRound();
109  void ReadDevices();
111  void UpdateState();
113  void LoadTable();
115  void SendDraftRequest();
117  void SendDraftAge(CPeerNode peer);
119  void SendDraftSelect(CPeerNode peer, float step);
121  void SendDraftAccept(CPeerNode peer, float step);
123  void SendTooLate(CPeerNode peer, float step);
125  void SetPStar(float pstar);
127  void SetDESD(float desd);
131  void Synchronize(float k);
133  bool InvariantCheck();
134 
136  const boost::posix_time::time_duration ROUND_TIME;
138  const boost::posix_time::time_duration REQUEST_TIMEOUT;
139 
144 
153 
156 
158  float m_Gateway;
167 
170 
172  std::string m_Leader;
174  std::map<std::string, float> m_DraftAge;
175 };
176 
177 } // namespace lb
178 } // namespace broker
179 } // namespace freedm
180 
181 #endif // LOAD_BALANCE_HPP
182 
void SetDESD(float desd)
Sets DESD value to the specified level.
Definition: LoadBalance.cpp:1038
void SendDraftAge(CPeerNode peer)
Sends draftage to the specified peer.
Definition: LoadBalance.cpp:688
Definition: LoadBalance.hpp:44
bool m_Synchronized
If the system is synchronized with the physical system.
Definition: LoadBalance.hpp:169
void SendTooLate(CPeerNode peer, float step)
Sends too late to the specified peer.
void HandleDraftAccept(const DraftAcceptMessage &m, CPeerNode peer)
Handles the draft accept message coming from the demand node.
Definition: LoadBalance.cpp:932
Definition: LoadBalance.hpp:51
void HandleStateChange(const StateChangeMessage &m, CPeerNode peer)
Handles a node announcing its state change.
Definition: LoadBalance.cpp:557
float m_NetGeneration
The amount of generation created by attached devices.
Definition: LoadBalance.hpp:160
ModuleMessage MessageDraftRequest()
Generates message supply nodes send to demand nodes.
Definition: LoadBalance.cpp:595
void LoadTable()
Displays the load table to show DGI state.
Definition: LoadBalance.cpp:454
ModuleMessage MessageTooLate(float amount)
Generates the message sent by the demand node to refuse migration.
Definition: LoadBalance.cpp:910
ModuleMessage MessageStateCollection()
Generates the message used to request a state collection.
Definition: LoadBalance.cpp:1106
void HandleIncomingMessage(boost::shared_ptr< const ModuleMessage > m, CPeerNode peer)
First handler for an incoming message.
Definition: LoadBalance.cpp:137
void SetPStar(float pstar)
Sets PStar to the specified level.
Definition: LoadBalance.cpp:1000
void DraftStandard(const boost::system::error_code &error)
The code that runs after the draft request replies have arrived.
Definition: LoadBalance.cpp:749
CBroker::TimerHandle m_RoundTimer
Timer handle for the round timer.
Definition: LoadBalance.hpp:141
void SendDraftRequest()
Sends Draft request to all the demand peers.
Definition: LoadBalance.cpp:609
Base interface for agents/broker modules.
Definition: CPeerNode.hpp:37
void Synchronize(float k)
Synchronizes the Fast-Style Loadbalance with the physical system.
Definition: LoadBalance.cpp:1217
const boost::posix_time::time_duration REQUEST_TIMEOUT
The time it takes to get a draftrequest response.
Definition: LoadBalance.hpp:138
void SendToPeerSet(const PeerSet &ps, const ModuleMessage &m)
Sends a message to all peers in a peerset.
Definition: LoadBalance.cpp:238
ModuleMessage MessageStateChange(std::string state)
Generates the message announcing current node state.
Definition: LoadBalance.cpp:536
void HandleCollectedState(const sc::CollectedStateMessage &m)
Handles the collected state coming from state collection.
Definition: LoadBalance.cpp:1160
float m_Gateway
The gateway of this node.
Definition: LoadBalance.hpp:158
const boost::posix_time::time_duration ROUND_TIME
The amount of time it takes to do an LB round.
Definition: LoadBalance.hpp:136
ModuleMessage MessageDraftSelect(float amount)
Generates the message that the supply node uses to select a demand node.
Definition: LoadBalance.cpp:805
void MoveToPeerSet(PeerSet &ps, CPeerNode peer)
Moves a peer to the specified peerset.
Definition: LoadBalance.cpp:220
ModuleMessage MessageDraftAge(float age)
Generates message demand nodes send in response to DraftRequest.
Definition: LoadBalance.cpp:671
bool InvariantCheck()
Check the invariant prior to starting a new migration.
Definition: LoadBalance.cpp:1237
void HandleDraftRequest(const DraftRequestMessage &m, CPeerNode peer)
Handles the draft request originating from the supply node.
Definition: LoadBalance.cpp:649
CBroker::TimerHandle m_WaitTimer
Timer handle for the request timer.
Definition: LoadBalance.hpp:143
int Run()
Definition: LoadBalance.cpp:118
State
Definition: LoadBalance.hpp:51
void ScheduleStateCollection()
Sends the request to perform state collection.
Definition: LoadBalance.cpp:1130
unsigned int TimerHandle
Definition: CBroker.hpp:66
std::map< std::string, float > m_DraftAge
Pending migrations.
Definition: LoadBalance.hpp:174
void ReadDevices()
Updates the state from the devices.
Definition: LoadBalance.cpp:382
LBAgent()
Definition: LoadBalance.cpp:87
An interface for an object which can handle recieving incoming messages.
Definition: IDGIModule.hpp:36
PeerSet m_InSupply
Peers in the supply state.
Definition: LoadBalance.hpp:148
void FirstRound(const boost::system::error_code &error)
The code that runs the firtst round of the LB phase.
Definition: LoadBalance.cpp:265
ModuleMessage PrepareForSending(const LoadBalancingMessage &m, std::string recipient="lb")
Boilerplate for preparing a message.
Definition: LoadBalance.cpp:1090
ModuleMessage MessageCollectedState(float state)
Definition: LoadBalance.cpp:1182
void SendDraftSelect(CPeerNode peer, float step)
Sends a draft select to the specified peer.
Definition: LoadBalance.cpp:820
float m_PowerDifferential
The powerflow used by the physical invariant.
Definition: LoadBalance.hpp:166
General FREEDM Namespace.
Definition: CBroker.cpp:53
void HandlePeerList(const gm::PeerListMessage &m, CPeerNode peer)
Handles the peerlist coming from the group leader.
Definition: LoadBalance.cpp:969
float m_MigrationStep
The amount to migrate.
Definition: LoadBalance.hpp:164
std::string m_Leader
The coordinator of the group.
Definition: LoadBalance.hpp:172
State m_State
The current state of this peer.
Definition: LoadBalance.hpp:155
PeerSet m_AllPeers
All peers in group.
Definition: LoadBalance.hpp:146
float m_PredictedGateway
The gateway that we predict will be met by the devices.
Definition: LoadBalance.hpp:162
void UpdateState()
Updates the node&#39;s state.
Definition: LoadBalance.cpp:412
PeerSet m_InDemand
Peers in the demand state.
Definition: LoadBalance.hpp:150
PeerSet m_InNormal
Peers in the normal state.
Definition: LoadBalance.hpp:152
void ScheduleNextRound()
Schedules the LoadManage that runs next round.
Definition: LoadBalance.cpp:358
void SendDraftAccept(CPeerNode peer, float step)
Sends draft accept to the specified peer.
ModuleMessage MessageDraftAccept(float amount)
Generates the message that the demand node uses to confirm the migration.
Definition: LoadBalance.cpp:895
void HandleTooLate(const TooLateMessage &m)
Handles the draft reject message coming from the demand node.
Definition: LoadBalance.cpp:951
void LoadManage(const boost::system::error_code &error)
The code that the supply nodes use to start doing migrations.
Definition: LoadBalance.cpp:299
void HandleDraftSelect(const DraftSelectMessage &m, CPeerNode peer)
Handles the draft select message coming from the supply node.
Definition: LoadBalance.cpp:854
std::map< std::string, CPeerNode > PeerSet
Provides a PeerSet type for a module templated on T.
Definition: PeerSets.hpp:35
Definition: LoadBalance.hpp:51
void HandleDraftAge(const DraftAgeMessage &m, CPeerNode peer)
Handles the draft age message coming from the demand node.
Definition: LoadBalance.cpp:726
Definition: LoadBalance.hpp:51