mirror of
https://gitlab.com/manzerbredes/loosely-coupled-dss.git
synced 2025-04-18 03:42:04 +00:00
112 lines
3.5 KiB
C++
112 lines
3.5 KiB
C++
![]() |
#include "simgrid/s4u.hpp"
|
||
|
#include <simgrid/s4u/Mailbox.hpp>
|
||
|
#include <string>
|
||
|
#include <sstream>
|
||
|
#include "inputs.hpp"
|
||
|
#include "simgrid/s4u/Host.hpp"
|
||
|
#include "simgrid/plugins/energy.h"
|
||
|
#include "xbt/log.h"
|
||
|
|
||
|
#define PLATFORM_FILE "platform.xml"
|
||
|
#define TURN_OFF() simgrid::s4u::this_actor::get_host()->set_pstate(0);
|
||
|
#define TURN_ON() simgrid::s4u::this_actor::get_host()->set_pstate(1);
|
||
|
|
||
|
|
||
|
XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[DAO]");
|
||
|
|
||
|
typedef unsigned int u32;
|
||
|
typedef struct{
|
||
|
double hint;
|
||
|
bool isHint;
|
||
|
} Payload;
|
||
|
|
||
|
/// @brief Observation unit code
|
||
|
static void obs_node(std::vector<std::string> args);
|
||
|
|
||
|
|
||
|
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);
|
||
|
|
||
|
XBT_INFO("-------------------------------------------------");
|
||
|
XBT_INFO("Sarting loosely coupled data dissemination experiments");
|
||
|
XBT_INFO("-------------------------------------------------");
|
||
|
|
||
|
u32 nObsUnit=simgrid::s4u::Engine::get_instance()->get_host_count();
|
||
|
for(u32 i=0;i<nObsUnit;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);
|
||
|
}
|
||
|
|
||
|
// Setup/Run simulation
|
||
|
engine.run();
|
||
|
|
||
|
XBT_INFO("Simulation took %fs", simgrid::s4u::Engine::get_clock());
|
||
|
|
||
|
return (0);
|
||
|
}
|
||
|
|
||
|
|
||
|
static void obs_node(std::vector<std::string> args) {
|
||
|
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());
|
||
|
|
||
|
double wake_interval=i.wake_interval;
|
||
|
double wake_duration=i.wake_duration;
|
||
|
double startup_delay=i.startup_delay;
|
||
|
int max_attempts=i.max_attempts;
|
||
|
bool isSender=i.is_sender;
|
||
|
|
||
|
// Starting node
|
||
|
u32 effectiveAttemps=0;
|
||
|
double effective_wake_duration=wake_duration;
|
||
|
double effective_wake_interval=wake_interval;
|
||
|
simgrid::s4u::this_actor::sleep_for(startup_delay);
|
||
|
Payload p;
|
||
|
for(u32 i=0;i<max_attempts;i++){
|
||
|
XBT_INFO("%s is spleeping",selfName.c_str());
|
||
|
simgrid::s4u::this_actor::sleep_for(effective_wake_interval);
|
||
|
XBT_INFO("%s wakes up",selfName.c_str());
|
||
|
|
||
|
try
|
||
|
{
|
||
|
if(isSender){
|
||
|
p.isHint=false;
|
||
|
p.hint=500;
|
||
|
m->put(&p,0,effective_wake_duration);
|
||
|
XBT_INFO("%s send data successfully",selfName.c_str());
|
||
|
effective_wake_interval=wake_interval;
|
||
|
}
|
||
|
else {
|
||
|
Payload *p=m->get<Payload>(effective_wake_duration);
|
||
|
if(p->isHint){
|
||
|
XBT_INFO("%s received and hint of %f",selfName.c_str(),p->hint);
|
||
|
effective_wake_interval=p->hint;
|
||
|
}
|
||
|
else{
|
||
|
XBT_INFO("%s received data successfully",selfName.c_str());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (...)
|
||
|
{
|
||
|
if(isSender)
|
||
|
XBT_INFO("%s failed to send data",selfName.c_str());
|
||
|
else
|
||
|
XBT_INFO("%s failed to receive data",selfName.c_str());
|
||
|
}
|
||
|
effectiveAttemps++;
|
||
|
}
|
||
|
|
||
|
// Done
|
||
|
XBT_INFO("Observation node %s finished (attemps:%d)",selfName.c_str(),effectiveAttemps);
|
||
|
}
|