aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-05-05 16:42:11 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-05-05 16:42:11 +0200
commitf0208cbc865822057196de77054163dbade48581 (patch)
treed6813d3dc122314014c18d56c4ade14d363129c0
Create simulator
-rw-r--r--.gitignore3
-rw-r--r--Makefile14
-rw-r--r--inputs.cc14
-rw-r--r--inputs.hpp17
-rw-r--r--inputs.json10
-rw-r--r--platform.xml17
-rw-r--r--simulator.cc67
7 files changed, 142 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..29951b5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+simulator
+libs
+compile_commands.json \ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..70ed266
--- /dev/null
+++ b/Makefile
@@ -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) \ No newline at end of file
diff --git a/inputs.cc b/inputs.cc
new file mode 100644
index 0000000..1f90ab6
--- /dev/null
+++ b/inputs.cc
@@ -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();
+} \ No newline at end of file
diff --git a/inputs.hpp b/inputs.hpp
new file mode 100644
index 0000000..611df0f
--- /dev/null
+++ b/inputs.hpp
@@ -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;
+}; \ No newline at end of file
diff --git a/inputs.json b/inputs.json
new file mode 100644
index 0000000..84c7e6c
--- /dev/null
+++ b/inputs.json
@@ -0,0 +1,10 @@
+{
+ "ou0":{
+ "wake_interval": 10,
+ "wake_duration": 5
+ },
+ "ou1":{
+ "wake_interval": 10,
+ "wake_duration": 5
+ }
+} \ No newline at end of file
diff --git a/platform.xml b/platform.xml
new file mode 100644
index 0000000..7faab20
--- /dev/null
+++ b/platform.xml
@@ -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>
+
diff --git a/simulator.cc b/simulator.cc
new file mode 100644
index 0000000..508a31a
--- /dev/null
+++ b/simulator.cc
@@ -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");
+ }
+ }
+
+} \ No newline at end of file