1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
#include <simgrid/s4u.hpp>
#include <simgrid/s4u/Mailbox.hpp>
#include <simgrid/s4u/Host.hpp>
#include <simgrid/plugins/energy.h>
#include <xbt/log.h>
#include <string>
#include <sstream>
#include "Inputs.hpp"
#define PLATFORM_FILE "platform.xml"
#define MODE_OFF() simgrid::s4u::this_actor::get_host()->set_pstate(0);
#define MODE_ON() simgrid::s4u::this_actor::get_host()->set_pstate(1);
#define MODE_RX() simgrid::s4u::this_actor::get_host()->set_pstate(2);
#define MODE_TX() simgrid::s4u::this_actor::get_host()->set_pstate(3);
#define CLOCK (simgrid::s4u::Engine::get_clock())
#define TRACK_UPTIME(instruction) \
{ \
double uptimeTrack=CLOCK; \
instruction; \
uptimeTrack=CLOCK-uptimeTrack; \
uptime-=uptimeTrack; \
uptime=uptime > 0 ? uptime : 0; \
}
/// @brief Required by SimGrid
XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[DAO]");
/// @brief For convenience sake
typedef unsigned int u32;
/**
* Data that will be exchange between the nodes
*/
class Payload{
public:
Payload():hint(0),duration(0),HasHint(false){}
double hint;
double duration;
bool HasHint;
std::string DedicatedMailbox;
};
/// @brief Observation node code
static void obs_node(std::vector<std::string> args);
/**
* No arguments are require (cf inputs.json)
*/
int main(int argc, char **argv) {
// Build engine
sg_host_energy_plugin_init();
simgrid::s4u::Engine engine(&argc, argv);
Inputs::GeneratePlatform(PLATFORM_FILE);
engine.load_platform(PLATFORM_FILE);
// Headline
XBT_INFO("-------------------------------------------------");
XBT_INFO("Sarting loosely coupled data dissemination experiments");
XBT_INFO("-------------------------------------------------");
// Init all nodes actors
u32 nON=simgrid::s4u::Engine::get_instance()->get_host_count();
for(u32 i=0;i<nON;i++){
std::vector<std::string> args;
std::ostringstream ss;
ss<< "on" <<i;
simgrid::s4u::Actor::create("ON", simgrid::s4u::Host::by_name(ss.str()), obs_node, args);
}
// Launch the simulation
engine.run();
XBT_INFO("Simulation took %fs", simgrid::s4u::Engine::get_clock());
XBT_INFO("The simulated platform file is available in \"%s\"",PLATFORM_FILE);
return (0);
}
/**
* This is the brain behind each node
*/
static void obs_node(std::vector<std::string> args) {
// Init various variables
std::string selfName = simgrid::s4u::this_actor::get_host()->get_name();
simgrid::s4u::this_actor::get_host()->turn_on();
Inputs i(selfName);
simgrid::s4u::Mailbox *m = simgrid::s4u::Mailbox::by_name("medium");
XBT_INFO("Deploying observation node %s",selfName.c_str());
// Starting node
bool isObserver=false;
u32 nWakeUp=0;
u32 nDataRcv=0;
u32 nSendFail=0;
u32 nRcvFail=0;
u32 nSend=0;
double totalUptime=0;
while(i.ShouldContinue()){
// Start by sleeping
XBT_INFO("%s is spleeping",selfName.c_str());
MODE_OFF();
simgrid::s4u::this_actor::sleep_until(i.GetTS());
MODE_ON();
XBT_INFO("%s wakes up",selfName.c_str());
// Doing wake up stuff
double uptime=i.GetDuration();
double upsince=simgrid::s4u::Engine::get_clock();
double upuntil=i.GetTS()+i.GetDuration();
while(uptime>0.0000001)
{
if(i.is_sender){
Payload *p=new Payload();
p->DedicatedMailbox="dedicated"+selfName;
if(i.use_hint && i.HasNext()){
p->HasHint=i.use_hint;
p->duration=i.GetNextDuration();
p->hint=i.GetNextTS();
}
MODE_ON();
try {
TRACK_UPTIME(m->put(p,0,uptime)); // Send instantaneous message
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
// First send hint if it is required
if(p->HasHint){
TRACK_UPTIME(m_ded->put(p,i.hint_size,uptime));
XBT_INFO("%s sent a hint successfully",selfName.c_str());
}
// Then try sending the data
MODE_TX();
if(i.extended)
m_ded->put(p,i.data_size);
else
m_ded->put(p,i.data_size,uptime);
XBT_INFO("%s sent data successfully",selfName.c_str());
nSend++;
i.is_sender=(nSend<(i.n_nodes-1));
isObserver=!i.is_sender;
}
catch(...){
XBT_INFO("%s could not send any data",selfName.c_str());
nSendFail++;
}
}
else if(!isObserver){
Payload *p;
Payload *hint; // To Save the received hint
bool hintReceived=false;
MODE_ON();
try {
TRACK_UPTIME(p=m->get<Payload>(uptime)); // Get the instantaneous message
simgrid::s4u::Mailbox *m_ded= simgrid::s4u::Mailbox::by_name(p->DedicatedMailbox);
if(p->HasHint){
TRACK_UPTIME(p=m_ded->get<Payload>(uptime));
XBT_INFO("%s received a hint successfully",selfName.c_str());
hintReceived=true;
}
MODE_RX();
if(i.extended)
p=m_ded->get<Payload>(); // Fetch data
else
p=m_ded->get<Payload>(uptime); // Fetch data
XBT_INFO("%s received data successfully",selfName.c_str());
nDataRcv++;
isObserver=true;
i.is_sender=false;
}catch(...){
XBT_INFO("%s could not receive any data",selfName.c_str());
nRcvFail++;
if(hintReceived)
i.AddEvent(p->hint, p->duration); // Add the hint to the event list
}
}
else {
XBT_INFO("%s is observing his environment...",selfName.c_str());
MODE_ON();
simgrid::s4u::this_actor::sleep_for(uptime);
}
uptime=upuntil-CLOCK; // Note that uptime can be < 0 in extended mode
}
// Load next event
i.GotoNextEvent();
nWakeUp++; // Increase the number of wake up
totalUptime+=CLOCK-upsince;
}
// Done
MODE_OFF()
XBT_INFO("Observation node %s finished [LOG2PARSE](node:%s|isSender:%d|nSend:%d|nWakeUp:%d|nDataRcv:%d|nSendFail:%d|nRcvFail:%d|totalUptime:%f|seed:%d)",selfName.c_str(),selfName.c_str(),i.is_sender,nSend,nWakeUp,nDataRcv,nSendFail,nRcvFail,totalUptime,i.seed);
}
|