A Trickle Timer following RFC 6206 . More...
#include "trickle-timer.h"
Public Member Functions | |
TrickleTimer () | |
Constructor. | |
TrickleTimer (Time minInterval, uint8_t doublings, uint16_t redundancy) | |
Constructor. | |
~TrickleTimer () | |
Destructor. | |
int64_t | AssignStreams (int64_t streamNum) |
Assigns the stream number for the uniform random number generator to use. | |
void | ConsistentEvent () |
Records a consistent event. | |
void | Enable () |
Enable the timer. | |
Time | GetDelayLeft () const |
uint8_t | GetDoublings () const |
Get the doublings of the timer. | |
Time | GetIntervalLeft () const |
Time | GetMaxInterval () const |
Get the MaxInterval of the timer. | |
Time | GetMinInterval () const |
Get the MinInterval of the timer. | |
uint16_t | GetRedundancy () const |
Get the Redundancy constant of the timer. | |
void | InconsistentEvent () |
Records an inconsistent event. | |
void | Reset () |
Reset the timer. | |
template<typename FN > | |
void | SetFunction (FN fn) |
Set the function to execute when the timer expires. | |
template<typename MEM_PTR , typename OBJ_PTR > | |
void | SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr) |
Set the function to execute when the timer expires. | |
void | SetParameters (Time minInterval, uint8_t doublings, uint16_t redundancy) |
Set the timer parameters. | |
void | Stop () |
Stop the timer. | |
template<typename... Ts> | |
void | SetArguments (Ts &&... args) |
Set the arguments to be used when invoking the expire function. | |
Private Member Functions | |
void | IntervalExpire () |
Internal callback invoked when the interval expires. | |
void | TimerExpire () |
Internal callback invoked when the timer expires. | |
Private Attributes | |
uint16_t | m_counter |
Event counter. | |
Time | m_currentInterval |
Current interval. | |
internal::TimerImpl * | m_impl |
The timer implementation, which contains the bound callback function and arguments. | |
EventId | m_intervalExpiration |
The future event scheduled to expire the interval. | |
Time | m_maxInterval |
Maximum interval. | |
Time | m_minInterval |
Minimum interval. | |
uint16_t | m_redundancy |
Redundancy constant. | |
uint64_t | m_ticks |
Interval span (i.e., exp2(doublings)). | |
EventId | m_timerExpiration |
The future event scheduled to expire the timer. | |
Ptr< UniformRandomVariable > | m_uniRand |
Object to generate uniform random numbers. | |
A Trickle Timer following RFC 6206 .
A Trickle Timer is a timer that varies its frequency between a minimum and a maximum, depending on events. It is typically used to exchange information in a highly robust, energy efficient, simple, and scalable manner.
The Trickle Timer has three parameters:
The timer period is variable. It starts at minInterval, and it doubles the period length up to maxInterval = std::exp2 (doublings) * minInterval.
The period is reset to minInterval when an inconsistent event is detected (see TrickleTimer::InconsistentEvent
).
The actual function fired by the timer is not called when a period expires. Rather, it is called in random moment between half of the actual period, and the end of actual the period. Moreover, the function is not fired if the timer did detect in the actual period a number of consistent events (see TrickleTimer::ConsistentEvent
) greater than the redundancy constant. Setting the redundancy constant to zero disables this feature.
The Trickle Timer is mainly used to self-regulate the transmission of periodic information (e.g., Router Advertisements) in wireless networks - and particularly in LLNs. In these contexts the frequency of the timer is adjusted according to, e.g., RS multicast messages. Moreover, the redundancy constant can be used to avoid congestion in high density networks.
Please refer to RFC 6206 for a full description and discussion of the Trickle Timer.
Definition at line 67 of file trickle-timer.h.
ns3::TrickleTimer::TrickleTimer | ( | ) |
Constructor.
Definition at line 21 of file trickle-timer.cc.
References m_maxInterval, m_minInterval, m_redundancy, m_ticks, and NS_LOG_FUNCTION.
ns3::TrickleTimer::TrickleTimer | ( | Time | minInterval, |
uint8_t | doublings, | ||
uint16_t | redundancy ) |
Constructor.
The maximum interval is set to std::exp2 (doublings) * minInterval.
minInterval | Minimum interval. |
doublings | Number of doublings to reach the maximum interval. |
redundancy | Redundancy constant. |
A zero value in the redundancy constant means that the suppression algorithm is disabled.
Definition at line 37 of file trickle-timer.cc.
References m_maxInterval, m_minInterval, m_redundancy, m_ticks, NS_ASSERT_MSG, and NS_LOG_FUNCTION.
ns3::TrickleTimer::~TrickleTimer | ( | ) |
Destructor.
Definition at line 56 of file trickle-timer.cc.
References ns3::EventId::Cancel(), m_impl, m_intervalExpiration, m_timerExpiration, and NS_LOG_FUNCTION.
int64_t ns3::TrickleTimer::AssignStreams | ( | int64_t | streamNum | ) |
Assigns the stream number for the uniform random number generator to use.
streamNum | first stream index to use |
Definition at line 65 of file trickle-timer.cc.
References m_uniRand.
void ns3::TrickleTimer::ConsistentEvent | ( | ) |
Records a consistent event.
Definition at line 173 of file trickle-timer.cc.
References m_counter, and NS_LOG_FUNCTION.
Referenced by ns3::tests::TrickleTimerTestCase::ConsistentEvent().
void ns3::TrickleTimer::Enable | ( | ) |
Enable the timer.
Definition at line 146 of file trickle-timer.cc.
References IntervalExpire(), m_counter, m_currentInterval, m_intervalExpiration, m_minInterval, m_ticks, m_timerExpiration, m_uniRand, NS_ASSERT_MSG, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and TimerExpire().
Referenced by ns3::tests::TrickleTimerTestCase::TestRedundancy(), and ns3::tests::TrickleTimerTestCase::TestSteadyState().
Time ns3::TrickleTimer::GetDelayLeft | ( | ) | const |
This method returns zero if the timer has never been started.
Definition at line 120 of file trickle-timer.cc.
References ns3::Simulator::GetDelayLeft(), ns3::EventId::IsPending(), m_timerExpiration, and NS_LOG_FUNCTION.
uint8_t ns3::TrickleTimer::GetDoublings | ( | ) | const |
Get the doublings of the timer.
Definition at line 100 of file trickle-timer.cc.
References m_ticks, and NS_LOG_FUNCTION.
Referenced by ns3::tests::TrickleTimerTestCase::TestRedundancy(), and ns3::tests::TrickleTimerTestCase::TestSteadyState().
Time ns3::TrickleTimer::GetIntervalLeft | ( | ) | const |
This method returns zero if the timer has never been started.
Definition at line 133 of file trickle-timer.cc.
References ns3::Simulator::GetDelayLeft(), ns3::EventId::IsPending(), m_intervalExpiration, and NS_LOG_FUNCTION.
Time ns3::TrickleTimer::GetMaxInterval | ( | ) | const |
Get the MaxInterval of the timer.
The timer MaxInterval is always std::exp2 (doublings) * minInterval
Definition at line 93 of file trickle-timer.cc.
References m_maxInterval, and NS_LOG_FUNCTION.
Time ns3::TrickleTimer::GetMinInterval | ( | ) | const |
Get the MinInterval of the timer.
Definition at line 86 of file trickle-timer.cc.
References m_minInterval, and NS_LOG_FUNCTION.
uint16_t ns3::TrickleTimer::GetRedundancy | ( | ) | const |
Get the Redundancy constant of the timer.
Definition at line 113 of file trickle-timer.cc.
References m_redundancy, and NS_LOG_FUNCTION.
void ns3::TrickleTimer::InconsistentEvent | ( | ) |
Records an inconsistent event.
Definition at line 180 of file trickle-timer.cc.
References m_currentInterval, m_minInterval, NS_LOG_FUNCTION, and Reset().
|
private |
Internal callback invoked when the interval expires.
Definition at line 230 of file trickle-timer.cc.
References IntervalExpire(), m_counter, m_currentInterval, m_intervalExpiration, m_maxInterval, m_timerExpiration, m_uniRand, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and TimerExpire().
Referenced by Enable(), IntervalExpire(), and Reset().
void ns3::TrickleTimer::Reset | ( | ) |
Reset the timer.
Definition at line 190 of file trickle-timer.cc.
References ns3::EventId::Cancel(), IntervalExpire(), m_counter, m_currentInterval, m_intervalExpiration, m_minInterval, m_timerExpiration, m_uniRand, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and TimerExpire().
Referenced by InconsistentEvent(), ns3::tests::TrickleTimerTestCase::TestRedundancy(), and ns3::tests::TrickleTimerTestCase::TestSteadyState().
void ns3::TrickleTimer::SetArguments | ( | Ts &&... | args | ) |
Set the arguments to be used when invoking the expire function.
Ts | [deduced] Argument types. |
[in] | args | arguments |
Definition at line 275 of file trickle-timer.h.
References m_impl, NS_FATAL_ERROR, and ns3::internal::TimerImpl::SetArgs().
void ns3::TrickleTimer::SetFunction | ( | FN | fn | ) |
Set the function to execute when the timer expires.
FN | [deduced] The type of the function. |
[in] | fn | The function |
Store this function in this Timer for later use by Timer::Schedule.
Definition at line 259 of file trickle-timer.h.
References m_impl, and ns3::internal::MakeTimerImpl().
Referenced by ns3::tests::TrickleTimerTestCase::TestRedundancy(), and ns3::tests::TrickleTimerTestCase::TestSteadyState().
void ns3::TrickleTimer::SetFunction | ( | MEM_PTR | memPtr, |
OBJ_PTR | objPtr ) |
Set the function to execute when the timer expires.
MEM_PTR | [deduced] Class method function type. |
OBJ_PTR | [deduced] Class type containing the function. |
[in] | memPtr | The member function pointer |
[in] | objPtr | The pointer to object |
Store this function and object in this Timer for later use by Timer::Schedule.
Definition at line 267 of file trickle-timer.h.
References m_impl, and ns3::internal::MakeTimerImpl().
void ns3::TrickleTimer::SetParameters | ( | Time | minInterval, |
uint8_t | doublings, | ||
uint16_t | redundancy ) |
Set the timer parameters.
The maximum interval is set to std::exp2 (doublings) * minInterval.
minInterval | Minimum interval. |
doublings | Number of doublings to reach the maximum interval. |
redundancy | Redundancy constant. |
A zero value in the redundancy constant means that the suppression algorithm is disabled.
Definition at line 72 of file trickle-timer.cc.
References m_maxInterval, m_minInterval, m_redundancy, m_ticks, NS_ASSERT_MSG, and NS_LOG_FUNCTION.
void ns3::TrickleTimer::Stop | ( | ) |
Stop the timer.
This will reset the timer and cancel all the pending events.
Definition at line 208 of file trickle-timer.cc.
References ns3::EventId::Cancel(), m_counter, m_currentInterval, m_intervalExpiration, m_minInterval, m_timerExpiration, and NS_LOG_FUNCTION.
|
private |
Internal callback invoked when the timer expires.
Definition at line 219 of file trickle-timer.cc.
References ns3::internal::TimerImpl::Invoke(), m_counter, m_impl, m_redundancy, and NS_LOG_FUNCTION.
Referenced by Enable(), IntervalExpire(), and Reset().
|
private |
Event counter.
Definition at line 241 of file trickle-timer.h.
Referenced by ConsistentEvent(), Enable(), IntervalExpire(), Reset(), Stop(), and TimerExpire().
|
private |
Current interval.
Definition at line 240 of file trickle-timer.h.
Referenced by Enable(), InconsistentEvent(), IntervalExpire(), Reset(), and Stop().
|
private |
The timer implementation, which contains the bound callback function and arguments.
Definition at line 227 of file trickle-timer.h.
Referenced by ~TrickleTimer(), SetArguments(), SetFunction(), SetFunction(), and TimerExpire().
|
private |
The future event scheduled to expire the interval.
Definition at line 233 of file trickle-timer.h.
Referenced by ~TrickleTimer(), Enable(), GetIntervalLeft(), IntervalExpire(), Reset(), and Stop().
|
private |
Maximum interval.
Definition at line 236 of file trickle-timer.h.
Referenced by TrickleTimer(), TrickleTimer(), GetMaxInterval(), IntervalExpire(), and SetParameters().
|
private |
Minimum interval.
Definition at line 235 of file trickle-timer.h.
Referenced by TrickleTimer(), TrickleTimer(), Enable(), GetMinInterval(), InconsistentEvent(), Reset(), SetParameters(), and Stop().
|
private |
Redundancy constant.
Definition at line 237 of file trickle-timer.h.
Referenced by TrickleTimer(), TrickleTimer(), GetRedundancy(), SetParameters(), and TimerExpire().
|
private |
Interval span (i.e., exp2(doublings)).
Definition at line 239 of file trickle-timer.h.
Referenced by TrickleTimer(), TrickleTimer(), Enable(), GetDoublings(), and SetParameters().
|
private |
The future event scheduled to expire the timer.
Definition at line 230 of file trickle-timer.h.
Referenced by ~TrickleTimer(), Enable(), GetDelayLeft(), IntervalExpire(), Reset(), and Stop().
|
private |
Object to generate uniform random numbers.
Definition at line 243 of file trickle-timer.h.
Referenced by AssignStreams(), Enable(), IntervalExpire(), and Reset().