mirror of
https://gitlab.com/manzerbredes/loosely-coupled-dss.git
synced 2025-04-07 03:56:25 +02:00
Improve platform management and allow energy simulation
This commit is contained in:
parent
e8ad4ccb09
commit
4b321cfe80
9 changed files with 186 additions and 106 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
simulator
|
simulator
|
||||||
libs/simgrid
|
libs/simgrid
|
||||||
libs/rapidjson
|
libs/rapidjson
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
platform.xml
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ SG_INC := -I ./libs/simgrid/build/include -I ./libs/simgrid/include -I libs/rapi
|
||||||
CC := g++ -lsimgrid $(SG_INC) -L $(SG_LIBS)
|
CC := g++ -lsimgrid $(SG_INC) -L $(SG_LIBS)
|
||||||
|
|
||||||
|
|
||||||
$(EXEC): simulator.cc inputs.cc
|
$(EXEC): src/simulator.cc src/inputs.cc
|
||||||
$(CC) $^ -o $@
|
$(CC) $^ -o $@
|
||||||
|
|
||||||
run: $(EXEC)
|
run: $(EXEC)
|
||||||
|
|
14
inputs.cc
14
inputs.cc
|
@ -1,14 +0,0 @@
|
||||||
#include "inputs.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Inputs::Inputs(std::string node_name){
|
|
||||||
FILE* input_file = fopen(INPUTS_FILE, "rb");
|
|
||||||
char input_file_buffer[65536];
|
|
||||||
rapidjson::FileReadStream is(input_file, input_file_buffer, sizeof(input_file_buffer));
|
|
||||||
d.ParseStream(is);
|
|
||||||
fclose(input_file);
|
|
||||||
|
|
||||||
wake_duration=d[node_name.c_str()]["wake_duration"].GetDouble();
|
|
||||||
wake_interval=d[node_name.c_str()]["wake_interval"].GetDouble();
|
|
||||||
}
|
|
22
inputs.json
22
inputs.json
|
@ -1,10 +1,20 @@
|
||||||
{
|
{
|
||||||
"ou0":{
|
"on0":{
|
||||||
"wake_interval": 10,
|
"wake_interval": 5,
|
||||||
"wake_duration": 5
|
"is_sender": false,
|
||||||
|
"wake_duration": 5,
|
||||||
|
"startup_delay": 0,
|
||||||
|
"max_attemps" : 1,
|
||||||
|
"power_off": 0,
|
||||||
|
"power_on":10
|
||||||
},
|
},
|
||||||
"ou1":{
|
"on1":{
|
||||||
"wake_interval": 10,
|
"wake_interval": 5,
|
||||||
"wake_duration": 5
|
"is_sender": true,
|
||||||
|
"wake_duration": 5,
|
||||||
|
"startup_delay": 0,
|
||||||
|
"max_attemps" : 1,
|
||||||
|
"power_off": 0,
|
||||||
|
"power_on":10
|
||||||
}
|
}
|
||||||
}
|
}
|
17
platform.xml
17
platform.xml
|
@ -1,17 +0,0 @@
|
||||||
<?xml version='1.0'?>
|
|
||||||
<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
|
|
||||||
<platform version="4.1">
|
|
||||||
<AS id="AS0" routing="Full">
|
|
||||||
|
|
||||||
<host id="ou0" speed="100.0Mf,50.0Mf,20.0Mf" pstate="0"></host>
|
|
||||||
|
|
||||||
<host id="ou1" speed="100.0Mf,50.0Mf,20.0Mf" pstate="0"></host>
|
|
||||||
|
|
||||||
|
|
||||||
<link id="link" bandwidth="1bps" latency="0ms" sharing_policy="SPLITDUPLEX"></link>
|
|
||||||
|
|
||||||
<route src="ou0" dst="ou1" symmetrical="YES"><link_ctn id="link_UP" /></route>
|
|
||||||
|
|
||||||
</AS>
|
|
||||||
</platform>
|
|
||||||
|
|
67
simulator.cc
67
simulator.cc
|
@ -1,67 +0,0 @@
|
||||||
#include "simgrid/s4u.hpp"
|
|
||||||
#include <simgrid/s4u/Mailbox.hpp>
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
|
||||||
#include "inputs.hpp"
|
|
||||||
#include "xbt/log.h"
|
|
||||||
|
|
||||||
XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[DAO]");
|
|
||||||
|
|
||||||
typedef unsigned int u32;
|
|
||||||
u32 max_attempts=0;
|
|
||||||
|
|
||||||
/// @brief Observation unit code
|
|
||||||
static void obs_unit(std::vector<std::string> args);
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
|
|
||||||
// Build engine
|
|
||||||
simgrid::s4u::Engine engine(&argc, argv);
|
|
||||||
engine.load_platform("platform.xml");
|
|
||||||
|
|
||||||
// Parse arguments
|
|
||||||
max_attempts=std::stoi(argv[1]);
|
|
||||||
|
|
||||||
XBT_INFO("-------------------------------------------------");
|
|
||||||
XBT_INFO("Sarting loosely coupled data dissemination experiments");
|
|
||||||
XBT_INFO("Number of wake attempts per OU is %d",max_attempts);
|
|
||||||
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<< "ou" <<i;
|
|
||||||
simgrid::s4u::Actor::create("Sender", simgrid::s4u::Host::by_name(ss.str()), obs_unit, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup/Run simulation
|
|
||||||
engine.run();
|
|
||||||
|
|
||||||
XBT_INFO("Simulation took %fs", simgrid::s4u::Engine::get_clock());
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void obs_unit(std::vector<std::string> args) {
|
|
||||||
std::string selfName = simgrid::s4u::this_actor::get_host()->get_name();
|
|
||||||
Inputs i(selfName);
|
|
||||||
simgrid::s4u::Mailbox *m = simgrid::s4u::Mailbox::by_name("medium");
|
|
||||||
XBT_INFO("Deploying %s",selfName.c_str());
|
|
||||||
|
|
||||||
std::string msg("aloha");
|
|
||||||
double wake_interval=i.wake_interval;
|
|
||||||
for(u32 i=0;i<max_attempts;i++){
|
|
||||||
try
|
|
||||||
{
|
|
||||||
simgrid::s4u::this_actor::sleep_for(wake_interval);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
XBT_INFO("Not send");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
50
src/inputs.cc
Normal file
50
src/inputs.cc
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#include "inputs.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
Inputs::Inputs(std::string node_name){
|
||||||
|
FILE* input_file = fopen(INPUTS_FILE, "rb");
|
||||||
|
char input_file_buffer[65536];
|
||||||
|
rapidjson::FileReadStream is(input_file, input_file_buffer, sizeof(input_file_buffer));
|
||||||
|
d.ParseStream(is);
|
||||||
|
fclose(input_file);
|
||||||
|
|
||||||
|
wake_duration=d[node_name.c_str()]["wake_duration"].GetDouble();
|
||||||
|
wake_interval=d[node_name.c_str()]["wake_interval"].GetDouble();
|
||||||
|
startup_delay=d[node_name.c_str()]["startup_delay"].GetDouble();
|
||||||
|
is_sender=d[node_name.c_str()]["is_sender"].GetBool();
|
||||||
|
max_attempts=d[node_name.c_str()]["max_attemps"].GetInt();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Inputs::GeneratePlatform(std::string p){
|
||||||
|
FILE* input_file = fopen(INPUTS_FILE, "rb");
|
||||||
|
char input_file_buffer[65536];
|
||||||
|
rapidjson::FileReadStream is(input_file, input_file_buffer, sizeof(input_file_buffer));
|
||||||
|
rapidjson::Document d;
|
||||||
|
d.ParseStream(is);
|
||||||
|
fclose(input_file);
|
||||||
|
|
||||||
|
// Write platform file
|
||||||
|
std::ofstream pf;
|
||||||
|
pf.open (p);
|
||||||
|
pf << "<?xml version='1.0'?>\n";
|
||||||
|
pf << "<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n";
|
||||||
|
pf << "<platform version=\"4.1\">\n <AS id=\"AS0\" routing=\"Cluster\">\n";
|
||||||
|
pf << " <link id=\"link\" bandwidth=\"1Mbps\" latency=\"0ms\" sharing_policy=\"SHARED\"></link>\n";
|
||||||
|
for (Value::ConstMemberIterator itr = d.MemberBegin(); itr != d.MemberEnd(); ++itr)
|
||||||
|
{
|
||||||
|
std::string name=itr->name.GetString();
|
||||||
|
double power_on=d[itr->name.GetString()]["power_on"].GetDouble();
|
||||||
|
double power_off=d[itr->name.GetString()]["power_off"].GetDouble();
|
||||||
|
|
||||||
|
//db=d[itr->name.GetString()]["wake_interval"].GetDouble();
|
||||||
|
pf << " <host id=\""<<name<<"\" speed=\"100.0f,100.0f\" pstate=\"0\">\n";
|
||||||
|
pf << " <prop id=\"wattage_per_state\" value=\""<< power_off<<":"<<power_off<<", "<< power_on<<":"<<power_on<<"\" />\n";
|
||||||
|
pf << " <prop id=\"wattage_off\" value=\"0\" />\n </host>\n";
|
||||||
|
pf << " <host_link id=\""<<name<<"\" up=\"link\" down=\"link\"/>\n";
|
||||||
|
}
|
||||||
|
pf << " </AS>\n</platform>\n";
|
||||||
|
pf.close();
|
||||||
|
}
|
|
@ -12,6 +12,11 @@ class Inputs {
|
||||||
std::string node_name;
|
std::string node_name;
|
||||||
public:
|
public:
|
||||||
Inputs(std::string node_name);
|
Inputs(std::string node_name);
|
||||||
|
static void GeneratePlatform(std::string p);
|
||||||
|
|
||||||
double wake_duration;
|
double wake_duration;
|
||||||
double wake_interval;
|
double wake_interval;
|
||||||
|
double startup_delay;
|
||||||
|
bool is_sender;
|
||||||
|
int max_attempts;
|
||||||
};
|
};
|
112
src/simulator.cc
Normal file
112
src/simulator.cc
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
#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);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue