FREEDM DGI
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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);
96  void HandleEcnMessage(const ecn::EcnMessage& msg, CPeerNode);
97 
99  void MoveToPeerSet(PeerSet & ps, CPeerNode peer);
100 
102  void LoadManage(const boost::system::error_code & error);
104  void FirstRound(const boost::system::error_code & error);
106  void DraftStandard(const boost::system::error_code & error);
107 
108 
110  int MigrationRateFactor();
112  void ScheduleNextRound();
114  void ReadDevices();
116  void UpdateState();
118  void LoadTable();
120  void SendDraftRequest();
122  void SendDraftAge(CPeerNode peer);
124  void SendDraftSelect(CPeerNode peer, float step);
126  void SendDraftAccept(CPeerNode peer, float step);
128  void SendTooLate(CPeerNode peer, float step);
130  void SetPStar(float pstar);
134  void Synchronize(float k);
136  bool InvariantCheck();
137 
139  const boost::posix_time::time_duration ROUND_TIME;
141  const boost::posix_time::time_duration REQUEST_TIMEOUT;
142 
147 
156 
159 
161  float m_Gateway;
170 
173 
175  std::string m_Leader;
177  std::map<std::string, float> m_DraftAge;
180 };
181 
182 } // namespace lb
183 } // namespace broker
184 } // namespace freedm
185 
186 #endif // LOAD_BALANCE_HPP
187 
void SendDraftAge(CPeerNode peer)
Sends draftage to the specified peer.
Definition: LoadBalance.cpp:686
Definition: LoadBalance.hpp:44
bool m_Synchronized
If the system is synchronized with the physical system.
Definition: LoadBalance.hpp:172
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:930
Definition: LoadBalance.hpp:51
void HandleStateChange(const StateChangeMessage &m, CPeerNode peer)
Handles a node announcing its state change.
Definition: LoadBalance.cpp:555
float m_NetGeneration
The amount of generation created by attached devices.
Definition: LoadBalance.hpp:163
ModuleMessage MessageDraftRequest()
Generates message supply nodes send to demand nodes.
Definition: LoadBalance.cpp:593
void LoadTable()
Displays the load table to show DGI state.
Definition: LoadBalance.cpp:464
ModuleMessage MessageTooLate(float amount)
Generates the message sent by the demand node to refuse migration.
Definition: LoadBalance.cpp:908
ModuleMessage MessageStateCollection()
Generates the message used to request a state collection.
Definition: LoadBalance.cpp:1048
void HandleIncomingMessage(boost::shared_ptr< const ModuleMessage > m, CPeerNode peer)
First handler for an incoming message.
Definition: LoadBalance.cpp:136
int MigrationRateFactor()
Gives the current migration time scale.
Definition: LoadBalance.cpp:364
void SetPStar(float pstar)
Sets PStar to the specified level.
Definition: LoadBalance.cpp:998
void DraftStandard(const boost::system::error_code &error)
The code that runs after the draft request replies have arrived.
Definition: LoadBalance.cpp:747
CBroker::TimerHandle m_RoundTimer
Timer handle for the round timer.
Definition: LoadBalance.hpp:144
void SendDraftRequest()
Sends Draft request to all the demand peers.
Definition: LoadBalance.cpp:607
Base interface for agents/broker modules.
Definition: CPeerNode.hpp:37
int m_soft_ecn_mode
ecn state
Definition: LoadBalance.hpp:179
void HandleEcnMessage(const ecn::EcnMessage &msg, CPeerNode)
Handles incoming ECN notifications.
Definition: LoadBalance.cpp:1229
void Synchronize(float k)
Synchronizes the Fast-Style Loadbalance with the physical system.
Definition: LoadBalance.cpp:1159
const boost::posix_time::time_duration REQUEST_TIMEOUT
The time it takes to get a draftrequest response.
Definition: LoadBalance.hpp:141
void SendToPeerSet(const PeerSet &ps, const ModuleMessage &m)
Sends a message to all peers in a peerset.
Definition: LoadBalance.cpp:250
ModuleMessage MessageStateChange(std::string state)
Generates the message announcing current node state.
Definition: LoadBalance.cpp:534
void HandleCollectedState(const sc::CollectedStateMessage &m)
Handles the collected state coming from state collection.
Definition: LoadBalance.cpp:1102
float m_Gateway
The gateway of this node.
Definition: LoadBalance.hpp:161
const boost::posix_time::time_duration ROUND_TIME
The amount of time it takes to do an LB round.
Definition: LoadBalance.hpp:139
ModuleMessage MessageDraftSelect(float amount)
Generates the message that the supply node uses to select a demand node.
Definition: LoadBalance.cpp:803
void MoveToPeerSet(PeerSet &ps, CPeerNode peer)
Moves a peer to the specified peerset.
Definition: LoadBalance.cpp:232
ModuleMessage MessageDraftAge(float age)
Generates message demand nodes send in response to DraftRequest.
Definition: LoadBalance.cpp:669
bool InvariantCheck()
Check the invariant prior to starting a new migration.
Definition: LoadBalance.cpp:1179
void HandleDraftRequest(const DraftRequestMessage &m, CPeerNode peer)
Handles the draft request originating from the supply node.
Definition: LoadBalance.cpp:647
CBroker::TimerHandle m_WaitTimer
Timer handle for the request timer.
Definition: LoadBalance.hpp:146
int Run()
Definition: LoadBalance.cpp:117
State
Definition: LoadBalance.hpp:51
void ScheduleStateCollection()
Sends the request to perform state collection.
Definition: LoadBalance.cpp:1072
unsigned int TimerHandle
Definition: CBroker.hpp:66
std::map< std::string, float > m_DraftAge
Pending migrations.
Definition: LoadBalance.hpp:177
void ReadDevices()
Updates the state from the devices.
Definition: LoadBalance.cpp:402
LBAgent()
Definition: LoadBalance.cpp:92
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:151
void FirstRound(const boost::system::error_code &error)
The code that runs the firtst round of the LB phase.
Definition: LoadBalance.cpp:277
ModuleMessage PrepareForSending(const LoadBalancingMessage &m, std::string recipient="lb")
Boilerplate for preparing a message.
Definition: LoadBalance.cpp:1032
ModuleMessage MessageCollectedState(float state)
Definition: LoadBalance.cpp:1124
void SendDraftSelect(CPeerNode peer, float step)
Sends a draft select to the specified peer.
Definition: LoadBalance.cpp:818
float m_PowerDifferential
The powerflow used by the physical invariant.
Definition: LoadBalance.hpp:169
void HandlePeerList(const gm::PeerListMessage &m, CPeerNode peer)
Handles the peerlist coming from the group leader.
Definition: LoadBalance.cpp:967
float m_MigrationStep
The amount to migrate.
Definition: LoadBalance.hpp:167
std::string m_Leader
The coordinator of the group.
Definition: LoadBalance.hpp:175
State m_State
The current state of this peer.
Definition: LoadBalance.hpp:158
PeerSet m_AllPeers
All peers in group.
Definition: LoadBalance.hpp:149
float m_PredictedGateway
The gateway that we predict will be met by the devices.
Definition: LoadBalance.hpp:165
void UpdateState()
Updates the node's state.
Definition: LoadBalance.cpp:422
PeerSet m_InDemand
Peers in the demand state.
Definition: LoadBalance.hpp:153
PeerSet m_InNormal
Peers in the normal state.
Definition: LoadBalance.hpp:155
void ScheduleNextRound()
Schedules the LoadManage that runs next round.
Definition: LoadBalance.cpp:377
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:893
void HandleTooLate(const TooLateMessage &m)
Handles the draft reject message coming from the demand node.
Definition: LoadBalance.cpp:949
void LoadManage(const boost::system::error_code &error)
The code that the supply nodes use to start doing migrations.
Definition: LoadBalance.cpp:311
void HandleDraftSelect(const DraftSelectMessage &m, CPeerNode peer)
Handles the draft select message coming from the supply node.
Definition: LoadBalance.cpp:852
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:724
Definition: LoadBalance.hpp:51