From 4d107863208d72ee755b6de2392bcba0372a40fa Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Wed, 30 Jun 2021 15:41:03 +0200 Subject: Extend simulator --- src/Inputs.cc | 35 +++++++++++++++++++++++++++++++++++ src/Inputs.hpp | 14 ++++++++++++++ src/scenarios.cc | 12 ++++++++++-- src/simulator.cc | 11 ++++++++--- 4 files changed, 67 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Inputs.cc b/src/Inputs.cc index 8c3ac9c..0781be8 100644 --- a/src/Inputs.cc +++ b/src/Inputs.cc @@ -21,15 +21,21 @@ Inputs::Inputs(std::string node_name){ hint_size=d["hint_size"].GetInt(); n_nodes=d["nodes"].MemberCount(); latency=d["latency"].GetDouble(); + unschedule_on_rcv=d["unschedule_on_rcv"].GetBool(); + shutdown_on_rcv=d["shutdown_on_rcv"].GetBool(); + farhint=d["farhint"].GetBool(); + hintdist=d["hintdist"].GetDouble(); // Instantiate wake_ts for(auto& v:d["nodes"][node_name.c_str()]["wake_ts"].GetArray()){ wake_ts.push_back(v.GetDouble()); + wake_ts_backup.push_back(v.GetDouble()); } // Instantiate wake_duration for(auto& v:d["nodes"][node_name.c_str()]["wake_duration"].GetArray()){ wake_duration.push_back(v.GetDouble()); + wake_duration_backup.push_back(v.GetDouble()); } // Identity check @@ -89,11 +95,40 @@ double Inputs::GetNextDuration(){ return wake_duration[1]; } +double Inputs::GetHintTS(double clock){ + if(farhint){ + for(int i=0;i=(clock+hintdist)) + return(wake_ts[i]); + } + } + return(GetNextTS()); +} + +double Inputs::GetHintDuration(double clock){ + if(farhint){ + for(int i=0;i=(clock+hintdist)) + return(wake_duration[i]); + } + } + return GetNextDuration(); +} + void Inputs::GotoNextEvent(){ wake_ts.erase(wake_ts.begin()); wake_duration.erase(wake_duration.begin()); } +void Inputs::ResetEvents(double clock){ + wake_ts=wake_ts_backup; + wake_duration=wake_duration_backup;; + // Restore current event + while(HasNext() && (GetTS()+GetNextDuration()) < clock){ + GotoNextEvent(); + } +} + void Inputs::DumpEvents(){ std::cout << "Timestamps: "; for(auto a:wake_ts){ diff --git a/src/Inputs.hpp b/src/Inputs.hpp index 487686f..50ce8e2 100644 --- a/src/Inputs.hpp +++ b/src/Inputs.hpp @@ -21,6 +21,10 @@ class Inputs { std::vector wake_ts; /// @brief Wake up time durations std::vector wake_duration; + /// @brief To handle unschedule_on_rcv + std::vector wake_ts_backup; + std::vector wake_duration_backup; + /** * Recursively merge overlapping events */ @@ -46,10 +50,12 @@ public: * Get current event timestamp */ double GetTS(){return wake_ts.front();} + double GetHintTS(double clock); /** * Get current event duration */ double GetDuration(){return wake_duration.front();} + double GetHintDuration(double clock); /** * Get next event timestamp */ @@ -63,6 +69,10 @@ public: * of thermodynamics) */ void GotoNextEvent(); + /** + * Reset the initial event list + */ + void ResetEvents(double clock); /** * Allows to add a *FUTURE* event and merge overlapping events */ @@ -76,9 +86,13 @@ public: bool is_sender; bool use_hint; bool extended; + bool farhint; + bool unschedule_on_rcv; + bool shutdown_on_rcv; int data_size; int hint_size; int seed; int n_nodes; double latency; + double hintdist; }; \ No newline at end of file diff --git a/src/scenarios.cc b/src/scenarios.cc index 90a7849..0e7c596 100644 --- a/src/scenarios.cc +++ b/src/scenarios.cc @@ -17,10 +17,10 @@ using namespace rapidjson; int main(int argc, char **argv){ // Setup seed - if(argc!=16){ + if(argc!=20){ cerr << "Usage: " << argv[0] << " " << - " " << + " " << endl; exit(1); } @@ -41,6 +41,10 @@ int main(int argc, char **argv){ string bitrate(argv[13]); unsigned int hintsize=atoi(argv[14]); double latency=stod(argv[15]); + bool shutdown_on_rcv=!strcmp("true",argv[16]); + bool unschedule_on_rcv=!strcmp("true",argv[17]); + bool farhint=!strcmp("true",argv[18]); + double hintdist=stod(argv[19]); // Setup seed @@ -56,6 +60,10 @@ int main(int argc, char **argv){ d.AddMember("latency",latency,d.GetAllocator()); d.AddMember("extended",extended,d.GetAllocator()); d.AddMember("hint_size",hintsize,d.GetAllocator()); + d.AddMember("shutdown_on_rcv",shutdown_on_rcv,d.GetAllocator()); + d.AddMember("unschedule_on_rcv",unschedule_on_rcv,d.GetAllocator()); + d.AddMember("farhint",farhint,d.GetAllocator()); + d.AddMember("hintdist",hintdist,d.GetAllocator()); // Create nodes Value nodes(kObjectType); diff --git a/src/simulator.cc b/src/simulator.cc index aedf810..865aabc 100644 --- a/src/simulator.cc +++ b/src/simulator.cc @@ -188,8 +188,8 @@ static void obs_node(std::vector args) { // Add hint to the data if possible if(i.use_hint && i.HasNext()){ p->HasHint=true; - p->duration=i.GetNextDuration(); - p->hint=i.GetNextTS(); + p->duration=i.GetHintDuration(CLOCK); + p->hint=i.GetHintTS(CLOCK); p->DataSize+=i.hint_size; // Don't forget!! } // Send the data @@ -283,6 +283,8 @@ static void obs_node(std::vector args) { XBT_INFO("%s received a hint along with data successfully",CNAME); hint_forward=new Payload(*p); // Enable hint forwarding } + if(i.shutdown_on_rcv) + upuntil=CLOCK; nDataRcv++; isObserver=true; is_sender=false; @@ -342,6 +344,9 @@ static void obs_node(std::vector args) { uptime=upuntil-CLOCK; // Note that uptime can be < 0 in extended mode uptime=uptime > 0 ? uptime : 0; // Just in case } + // Check if we use unschedule_on_rcv + if(i.unschedule_on_rcv) + i.ResetEvents(CLOCK); // Load next event i.GotoNextEvent(); nWakeUp++; // Increase the number of wake up @@ -349,5 +354,5 @@ static void obs_node(std::vector args) { } // Done MODE_OFF() - XBT_INFO("Observation node %s finished [LOG2PARSE](node:%s|isSender:%d|nSend:%d|nWakeUp:%d|nDataRcv:%d|nSendFail:%d|nRcvFail:%d|totalUptime:%f|seed:%d|hint_added:%d|timeDataRcv:%f)",CNAME,CNAME,i.is_sender,nSend,nWakeUp,nDataRcv,nSendFail,nRcvFail,totalUptime,i.seed,hint_added,timeDataRcv); + XBT_INFO("Observation node %s finished [LOG2PARSE](node:%s|isSender:%d|nSend:%d|nWakeUp:%d|nDataRcv:%d|nSendFail:%d|nRcvFail:%d|totalUptime:%f|seed:%d|hint_added:%d|timeDataRcv:%f|shutdown_on_rcv:%d|unschedule_on_rcv:%d|farhint:%d|hintdist:%f)",CNAME,CNAME,i.is_sender,nSend,nWakeUp,nDataRcv,nSendFail,nRcvFail,totalUptime,i.seed,hint_added,timeDataRcv,i.shutdown_on_rcv,i.unschedule_on_rcv,i.farhint,i.hintdist); } \ No newline at end of file -- cgit v1.2.3