From 66ba2be4eda2b0d8a5642390c3df4a11d95e3a71 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 7 May 2021 19:32:16 +0200 Subject: [PATCH] Correct scenarios and add new pstates and energy levels --- README.md | 2 +- inputs.json | 17 ++++++----------- src/Inputs.cc | 9 ++++++--- src/simulator.cc | 20 ++++++++++++-------- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index ff7f72e..4fa6ef0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ### Setup - First you need [Boost](https://www.boost.org/) -- From the root project folder run `cd ./libs && ./setup.sh && cd -` +- From the project root folder run `cd ./libs && ./setup.sh && cd -` - And `make` - If the project compiles successfully, you are ready to run the simulations! ### Simulations diff --git a/inputs.json b/inputs.json index 2cf87a6..9fda5e6 100644 --- a/inputs.json +++ b/inputs.json @@ -4,7 +4,9 @@ "on0":{ "is_sender": true, "power_off": 0, - "power_on":10, + "power_on": 1, + "power_rx": 2, + "power_tx": 3, "use_hint": true, "wake_ts": [ 1, 7, 7 ], "wake_duration": [ 5, 1, 2], @@ -13,20 +15,13 @@ "on1":{ "is_sender": false, "power_off": 0, - "power_on":10, + "power_on": 10, + "power_tx": 10, + "power_rx": 10, "use_hint": false, "wake_ts": [ 1, 7, 8 ], "wake_duration": [ 5, 5, 1], "data_size": 50 - }, - "on2":{ - "is_sender": false, - "power_off": 0, - "power_on":10, - "use_hint": false, - "wake_ts": [ 1, 7 , 8 ], - "wake_duration": [ 5, 5, 1], - "data_size": 50 } } } diff --git a/src/Inputs.cc b/src/Inputs.cc index d71d8f7..70f3d51 100644 --- a/src/Inputs.cc +++ b/src/Inputs.cc @@ -153,11 +153,14 @@ void Inputs::GeneratePlatform(std::string p){ for (Value::ConstMemberIterator itr = d["nodes"].MemberBegin(); itr != d["nodes"].MemberEnd(); ++itr) { std::string name=itr->name.GetString(); - double power_on=d["nodes"][itr->name.GetString()]["power_on"].GetDouble(); double power_off=d["nodes"][itr->name.GetString()]["power_off"].GetDouble(); + double power_on=d["nodes"][itr->name.GetString()]["power_on"].GetDouble(); + double power_rx=d["nodes"][itr->name.GetString()]["power_rx"].GetDouble(); + double power_tx=d["nodes"][itr->name.GetString()]["power_tx"].GetDouble(); + // Create node - pf << " \n"; - pf << " \n"; + pf << " \n"; + pf << " \n"; pf << " \n \n"; pf << " \n"; } diff --git a/src/simulator.cc b/src/simulator.cc index 5da125d..13bc711 100644 --- a/src/simulator.cc +++ b/src/simulator.cc @@ -11,8 +11,10 @@ #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); +#define MODE_OFF() simgrid::s4u::this_actor::get_host()->set_pstate(0); +#define MODE_ON() simgrid::s4u::this_actor::get_host()->set_pstate(1); +#define MODE_RX() simgrid::s4u::this_actor::get_host()->set_pstate(2); +#define MODE_TX() simgrid::s4u::this_actor::get_host()->set_pstate(3); /// @brief Required by SimGrid XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[DAO]"); @@ -92,9 +94,9 @@ static void obs_node(std::vector args) { u32 nRcvFail=0; while(i.ShouldContinue()){ XBT_INFO("%s is spleeping",selfName.c_str()); - TURN_OFF(); + MODE_OFF(); simgrid::s4u::this_actor::sleep_until(i.GetTS()); - TURN_ON(); + MODE_ON(); XBT_INFO("%s wakes up",selfName.c_str()); // Doing wake up stuff @@ -116,14 +118,14 @@ static void obs_node(std::vector args) { // channel (to avoid other receivers to get the message) m->put(p,0,i.GetDuration()); simgrid::s4u::Mailbox *m_ext= simgrid::s4u::Mailbox::by_name("medium"+selfName); + MODE_TX(); m_ext->put(p,data_size); } else{ + MODE_TX(); m->put(p,data_size,i.GetDuration()); } XBT_INFO("%s sent data successfully",selfName.c_str()); - isObserver=true; // Do one send for now... - isSender=false; } else if (!isObserver){ Payload* p; @@ -133,9 +135,11 @@ static void obs_node(std::vector args) { // and then we use a mailbox specific to the sender (to have an exclusive channel) p=m->get(i.GetDuration()); simgrid::s4u::Mailbox *m_ext_sender = simgrid::s4u::Mailbox::by_name("medium"+p->node); + MODE_RX(); p=m_ext_sender->get(); } else{ + MODE_RX(); p=m->get(i.GetDuration()); } nDataRcv++; // New data received @@ -145,8 +149,8 @@ static void obs_node(std::vector args) { } else{ XBT_INFO("%s received data successfully and switch to forwarding mode",selfName.c_str()); - isSender=!isSender; // Toggle isSender to start sending } + isObserver=true; // Now we received the data we switch to observer } else { XBT_INFO("%s is observing his environment...",selfName.c_str()); @@ -169,6 +173,6 @@ static void obs_node(std::vector args) { nWakeUp++; // Increase the number of wake up } // Done - TURN_OFF() + MODE_OFF() XBT_INFO("Observation node %s finished [LOG2PARSE](node:%s|nWakeUp:%d|nDataRcv:%d|nSendFail:%d|nRcvFail:%d)",selfName.c_str(),selfName.c_str(),nWakeUp,nDataRcv,nSendFail,nRcvFail); } \ No newline at end of file