aboutsummaryrefslogtreecommitdiff
path: root/simulator.cc
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 /simulator.cc
Create simulator
Diffstat (limited to 'simulator.cc')
-rw-r--r--simulator.cc67
1 files changed, 67 insertions, 0 deletions
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