Create simulator

This commit is contained in:
Loic Guegan 2021-05-05 16:42:11 +02:00
commit f0208cbc86
7 changed files with 142 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
simulator
libs
compile_commands.json

14
Makefile Normal file
View file

@ -0,0 +1,14 @@
EXEC := simulator
SG_LIBS := ./libs/simgrid/build/lib
SG_INC := -I ./libs/simgrid/build/include -I ./libs/simgrid/include -I libs/rapidjson/include
CC := g++ -lsimgrid $(SG_INC) -L $(SG_LIBS)
$(EXEC): simulator.cc inputs.cc
$(CC) $^ -o $@
run: $(EXEC)
export LD_LIBRARY_PATH=$(SG_LIBS) && ./$(EXEC) 10 --cfg=network/bandwidth-factor:1.05 --cfg=network/model:CM02 -cfg=network/crosstraffic:0
clean:
-rm $(EXEC)

14
inputs.cc Normal file
View file

@ -0,0 +1,14 @@
#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();
}

17
inputs.hpp Normal file
View file

@ -0,0 +1,17 @@
#include "rapidjson/document.h"
#include "rapidjson/filereadstream.h"
#include <cstdio>
#include <string>
#define INPUTS_FILE "inputs.json"
using namespace rapidjson;
class Inputs {
Document d;
std::string node_name;
public:
Inputs(std::string node_name);
double wake_duration;
double wake_interval;
};

10
inputs.json Normal file
View file

@ -0,0 +1,10 @@
{
"ou0":{
"wake_interval": 10,
"wake_duration": 5
},
"ou1":{
"wake_interval": 10,
"wake_duration": 5
}
}

17
platform.xml Normal file
View file

@ -0,0 +1,17 @@
<?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 Normal file
View file

@ -0,0 +1,67 @@
#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");
}
}
}