diff --git a/src/simulator/timer.cc b/src/simulator/timer.cc index d17a69c11..d3c09a0c8 100644 --- a/src/simulator/timer.cc +++ b/src/simulator/timer.cc @@ -57,7 +57,25 @@ Timer::GetDelay (void) const { return m_delay; } - +Time +Timer::GetDelayLeft (void) const +{ + switch (GetState ()) { + case Timer::RUNNING: + return Simulator::GetDelayLeft (m_event); + break; + case Timer::EXPIRED: + return TimeStep (0); + break; + case Timer::SUSPENDED: + return m_delayLeft; + break; + default: + NS_ASSERT (false); + return TimeStep (0); + break; + } +} void Timer::Cancel (void) diff --git a/src/simulator/timer.h b/src/simulator/timer.h index 2d573c3df..5087db294 100644 --- a/src/simulator/timer.h +++ b/src/simulator/timer.h @@ -177,6 +177,12 @@ public: * \returns the currently-configured delay for the next Schedule. */ Time GetDelay (void) const; + /** + * \returns the amount of time left until this timer expires. + * + * This method returns zero if the timer is in EXPIRED state. + */ + Time GetDelayLeft (void) const; /** * Cancel the currently-running event if there is one. Do nothing * otherwise.