mirror of
https://gitlab.com/manzerbredes/loosely-coupled-dss.git
synced 2025-04-05 11:06:25 +02:00
Cleaning code
This commit is contained in:
parent
d0e57511fd
commit
fb38c4f0b7
2 changed files with 24 additions and 20 deletions
|
@ -16,14 +16,5 @@
|
|||
"wake_ts": [ 1, 7, 7 ],
|
||||
"wake_duration": [ 5, 1, 2],
|
||||
"data_size": 50
|
||||
},
|
||||
"on2":{
|
||||
"is_sender": false,
|
||||
"power_off": 0,
|
||||
"power_on":10,
|
||||
"use_hint": false,
|
||||
"wake_ts": [ 1, 7, 7 ],
|
||||
"wake_duration": [ 5, 1, 2],
|
||||
"data_size": 50
|
||||
}
|
||||
}
|
|
@ -11,22 +11,30 @@
|
|||
#define TURN_OFF() simgrid::s4u::this_actor::get_host()->set_pstate(0);
|
||||
#define TURN_ON() simgrid::s4u::this_actor::get_host()->set_pstate(1);
|
||||
|
||||
|
||||
/// @brief Required by SimGrid
|
||||
XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[DAO]");
|
||||
|
||||
/// @brief For convenience
|
||||
typedef unsigned int u32;
|
||||
|
||||
/**
|
||||
* Data that will be exchange between the nodes
|
||||
*/
|
||||
class Payload{
|
||||
public:
|
||||
public:
|
||||
Payload():hint(0),duration(0),containsHint(false){}
|
||||
double hint;
|
||||
double duration;
|
||||
bool containsHint;
|
||||
};
|
||||
|
||||
/// @brief Observation unit code
|
||||
/// @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
|
||||
|
@ -35,10 +43,12 @@ int main(int argc, char **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;
|
||||
|
@ -49,21 +59,23 @@ int main(int argc, char **argv) {
|
|||
|
||||
// Setup/Run 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());
|
||||
|
||||
// Init convenien variables
|
||||
// Init convenient variables
|
||||
bool isSender=i.is_sender;
|
||||
bool useHint=i.use_hint;
|
||||
bool isObserver=false;
|
||||
|
@ -94,14 +106,14 @@ static void obs_node(std::vector<std::string> args) {
|
|||
}
|
||||
else if (!isObserver){
|
||||
Payload* p=m->get<Payload>(i.GetDuration());
|
||||
nDataRcv++;
|
||||
nDataRcv++; // New data received
|
||||
if(p->containsHint){
|
||||
XBT_INFO("%s received and hint of %f",selfName.c_str(),p->hint);
|
||||
i.AddEvent(p->hint, p->duration);
|
||||
i.AddEvent(p->hint, p->duration); // Schedule a new wake up time
|
||||
}
|
||||
else{
|
||||
XBT_INFO("%s received data successfully and switch to forwarding mode",selfName.c_str());
|
||||
isSender=!isSender;
|
||||
isSender=!isSender; // Toggle isSender to start sending
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -116,8 +128,9 @@ static void obs_node(std::vector<std::string> args) {
|
|||
else
|
||||
XBT_INFO("%s failed to receive data",selfName.c_str());
|
||||
}
|
||||
// Load next event
|
||||
i.GotoNextEvent();
|
||||
nWakeUp++;
|
||||
nWakeUp++; // Increase the number of wake up
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue