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. | |
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 73 of file trickle-timer.h.
ns3::TrickleTimer::TrickleTimer | ( | ) |
Constructor.
Definition at line 31 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 47 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 66 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 75 of file trickle-timer.cc.
References m_uniRand, and ns3::RandomVariableStream::SetStream().
void ns3::TrickleTimer::ConsistentEvent | ( | ) |
Records a consistent event.
Definition at line 196 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 169 of file trickle-timer.cc.
References ns3::UniformRandomVariable::GetInteger(), ns3::UniformRandomVariable::GetValue(), 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 143 of file trickle-timer.cc.
References ns3::Simulator::GetDelayLeft(), ns3::EventId::IsRunning(), m_timerExpiration, and NS_LOG_FUNCTION.
uint8_t ns3::TrickleTimer::GetDoublings | ( | ) | const |
Get the doublings of the timer.
Definition at line 110 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 156 of file trickle-timer.cc.
References ns3::Simulator::GetDelayLeft(), ns3::EventId::IsRunning(), 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 103 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 96 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 136 of file trickle-timer.cc.
References m_redundancy, and NS_LOG_FUNCTION.
void ns3::TrickleTimer::InconsistentEvent | ( | ) |
Records an inconsistent event.
Definition at line 203 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 253 of file trickle-timer.cc.
References ns3::UniformRandomVariable::GetValue(), 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 213 of file trickle-timer.cc.
References ns3::EventId::Cancel(), ns3::UniformRandomVariable::GetValue(), 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 281 of file trickle-timer.h.
References m_impl, NS_FATAL_ERROR, and ns3::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 265 of file trickle-timer.h.
References m_impl, and ns3::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 273 of file trickle-timer.h.
References m_impl, and ns3::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 82 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 231 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 242 of file trickle-timer.cc.
References ns3::TimerImpl::Invoke(), m_counter, m_impl, m_redundancy, and NS_LOG_FUNCTION.
Referenced by Enable(), IntervalExpire(), and Reset().
|
private |
Event counter.
Definition at line 247 of file trickle-timer.h.
Referenced by ConsistentEvent(), Enable(), IntervalExpire(), Reset(), Stop(), and TimerExpire().
|
private |
Current interval.
Definition at line 246 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 233 of file trickle-timer.h.
Referenced by ~TrickleTimer(), SetArguments(), SetFunction(), and TimerExpire().
|
private |
The future event scheduled to expire the interval.
Definition at line 239 of file trickle-timer.h.
Referenced by ~TrickleTimer(), Enable(), GetIntervalLeft(), IntervalExpire(), Reset(), and Stop().
|
private |
Maximum interval.
Definition at line 242 of file trickle-timer.h.
Referenced by TrickleTimer(), GetMaxInterval(), IntervalExpire(), and SetParameters().
|
private |
Minimum interval.
Definition at line 241 of file trickle-timer.h.
Referenced by TrickleTimer(), Enable(), GetMinInterval(), InconsistentEvent(), Reset(), SetParameters(), and Stop().
|
private |
Redundancy constant.
Definition at line 243 of file trickle-timer.h.
Referenced by TrickleTimer(), GetRedundancy(), SetParameters(), and TimerExpire().
|
private |
Interval span (i.e., exp2(doublings)).
Definition at line 245 of file trickle-timer.h.
Referenced by TrickleTimer(), Enable(), GetDoublings(), and SetParameters().
|
private |
The future event scheduled to expire the timer.
Definition at line 236 of file trickle-timer.h.
Referenced by ~TrickleTimer(), Enable(), GetDelayLeft(), IntervalExpire(), Reset(), and Stop().
|
private |
Object to generate uniform random numbers.
Definition at line 249 of file trickle-timer.h.
Referenced by AssignStreams(), Enable(), IntervalExpire(), and Reset().