diff options
Diffstat (limited to 'src/simulator.cc')
| -rw-r--r-- | src/simulator.cc | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/src/simulator.cc b/src/simulator.cc index 922cd15..3254c5c 100644 --- a/src/simulator.cc +++ b/src/simulator.cc @@ -17,8 +17,9 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[DAO]"); typedef unsigned int u32; class Payload{ public: - Payload():hint(0),containsHint(false){} + Payload():hint(0),duration(0),containsHint(false){} double hint; + double duration; bool containsHint; }; @@ -63,53 +64,40 @@ static void obs_node(std::vector<std::string> args) { XBT_INFO("Deploying observation node %s",selfName.c_str()); // Init convenien variables - double wake_interval=i.wake_interval; - double wake_duration=i.wake_duration; - double startup_delay=i.startup_delay; - int max_attempts=i.max_attempts; bool isSender=i.is_sender; bool useHint=i.use_hint; bool isObserver=false; u32 data_size=i.data_size; // Starting node - u32 effectiveAttemps=0; - double effective_wake_duration=wake_duration; - double effective_wake_interval=wake_interval; - TURN_OFF(); - simgrid::s4u::this_actor::sleep_for(startup_delay); - for(u32 i=0;i<max_attempts;i++){ - - // Sleeping + u32 nWakeUp=0; + u32 nDataRcv=0; + while(i.ShouldContinue()){ XBT_INFO("%s is spleeping",selfName.c_str()); TURN_OFF(); - simgrid::s4u::this_actor::sleep_for(effective_wake_interval); - effective_wake_interval=wake_interval; // Restore wake interval + simgrid::s4u::this_actor::sleep_until(i.GetTS()); TURN_ON(); XBT_INFO("%s wakes up",selfName.c_str()); - // Wake up: try to send/receive - try - { - if(isSender){ + // Doing wake up stuff + try { + if(isSender){ // If I am a sender Payload *p=new Payload(); - p->containsHint=true; - p->hint=5; - if(useHint){ - p->containsHint=i<(max_attempts-1); // Ensure that we will wake up again - p->hint=wake_interval; + if(useHint&&i.HasNext()){ + p->hint=i.GetNextTS(); + p->duration=i.GetNextDuration(); } - m->put(p,data_size,effective_wake_duration); + m->put(p,data_size,i.GetDuration()); XBT_INFO("%s send data successfully",selfName.c_str()); isObserver=true; // Do one send for now... isSender=false; } else if (!isObserver){ - Payload* p=m->get<Payload>(effective_wake_duration); + Payload* p=m->get<Payload>(i.GetDuration()); + nDataRcv++; if(p->containsHint){ XBT_INFO("%s received and hint of %f",selfName.c_str(),p->hint); - effective_wake_interval=p->hint; - i--; // Add new attempt + i.AddEvent(p->hint, p->duration); } else{ XBT_INFO("%s received data successfully and switch to forwarding mode",selfName.c_str()); @@ -118,6 +106,7 @@ static void obs_node(std::vector<std::string> args) { } else { XBT_INFO("%s is observing is environment...",selfName.c_str()); + simgrid::s4u::this_actor::sleep_until(i.GetDuration()); } } catch (...) @@ -127,9 +116,11 @@ static void obs_node(std::vector<std::string> args) { else XBT_INFO("%s failed to receive data",selfName.c_str()); } - effectiveAttemps++; + i.GotoNextEvent(); + nWakeUp++; } + // Done - XBT_INFO("Observation node %s finished (attemps:%d)",selfName.c_str(),effectiveAttemps); + XBT_INFO("Observation node %s finished (nWakeUp:%d|nDataRcv:%d)",selfName.c_str(),nWakeUp,nDataRcv); }
\ No newline at end of file |
