A Discrete-Event Network Simulator
API
ns3::TrickleTimer Class Reference

A Trickle Timer following RFC 6206. More...

#include "trickle-timer.h"

+ Collaboration diagram for ns3::TrickleTimer:

Public Member Functions

 TrickleTimer ()
 Constructor. More...
 
 TrickleTimer (Time minInterval, uint8_t doublings, uint16_t redundancy)
 Constructor. More...
 
 ~TrickleTimer ()
 Destructor. More...
 
int64_t AssignStreams (int64_t streamNum)
 Assigns the stream number for the uniform random number generator to use. More...
 
void ConsistentEvent ()
 Records a consistent event. More...
 
void Enable ()
 Enable the timer. More...
 
Time GetDelayLeft () const
 
uint8_t GetDoublings () const
 Get the doublings of the timer. More...
 
Time GetIntervalLeft () const
 
Time GetMaxInterval () const
 Get the MaxInterval of the timer. More...
 
Time GetMinInterval () const
 Get the MinInterval of the timer. More...
 
uint16_t GetRedundancy () const
 Get the Redundancy constant of the timer. More...
 
void InconsistentEvent ()
 Records an inconsistent event. More...
 
void Reset ()
 Reset the timer. More...
 
template<typename FN >
void SetFunction (FN fn)
 Set the function to execute when the timer expires. More...
 
template<typename MEM_PTR , typename OBJ_PTR >
void SetFunction (MEM_PTR memPtr, OBJ_PTR objPtr)
 Set the function to execute when the timer expires. More...
 
void SetParameters (Time minInterval, uint8_t doublings, uint16_t redundancy)
 Set the timer parameters. More...
 
void Stop ()
 Stop the timer. More...
 
template<typename... Ts>
void SetArguments (Ts &&... args)
 Set the arguments to be used when invoking the expire function. More...
 

Private Member Functions

void IntervalExpire ()
 Internal callback invoked when the interval expires. More...
 
void TimerExpire ()
 Internal callback invoked when the timer expires. More...
 

Private Attributes

uint16_t m_counter
 Event counter. More...
 
Time m_currentInterval
 Current interval. More...
 
TimerImplm_impl
 The timer implementation, which contains the bound callback function and arguments. More...
 
EventId m_intervalExpiration
 The future event scheduled to expire the interval. More...
 
Time m_maxInterval
 Maximum interval. More...
 
Time m_minInterval
 Minimum interval. More...
 
uint16_t m_redundancy
 Redundancy constant. More...
 
uint64_t m_ticks
 Interval span (i.e., exp2(doublings)). More...
 
EventId m_timerExpiration
 The future event scheduled to expire the timer. More...
 
Ptr< UniformRandomVariablem_uniRand
 Object to generate uniform random numbers. More...
 

Detailed Description

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:

  • minInterval Minimum interval.
  • doublings Number of doublings to reach the maximum interval.
  • redundancy Redundancy constant.

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.

Constructor & Destructor Documentation

◆ TrickleTimer() [1/2]

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.

◆ TrickleTimer() [2/2]

ns3::TrickleTimer::TrickleTimer ( Time  minInterval,
uint8_t  doublings,
uint16_t  redundancy 
)

Constructor.

The maximum interval is set to std::exp2 (doublings) * minInterval.

Parameters
minIntervalMinimum interval.
doublingsNumber of doublings to reach the maximum interval.
redundancyRedundancy 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.

◆ ~TrickleTimer()

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.

+ Here is the call graph for this function:

Member Function Documentation

◆ AssignStreams()

int64_t ns3::TrickleTimer::AssignStreams ( int64_t  streamNum)

Assigns the stream number for the uniform random number generator to use.

Parameters
streamNumfirst stream index to use
Returns
the number of stream indices assigned by this helper

Definition at line 75 of file trickle-timer.cc.

References m_uniRand, and ns3::RandomVariableStream::SetStream().

+ Here is the call graph for this function:

◆ ConsistentEvent()

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().

+ Here is the caller graph for this function:

◆ Enable()

◆ GetDelayLeft()

Time ns3::TrickleTimer::GetDelayLeft ( ) const
Returns
The amount of time left until this timer expires.

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.

+ Here is the call graph for this function:

◆ GetDoublings()

uint8_t ns3::TrickleTimer::GetDoublings ( ) const

Get the doublings of the timer.

Returns
The doublings

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().

+ Here is the caller graph for this function:

◆ GetIntervalLeft()

Time ns3::TrickleTimer::GetIntervalLeft ( ) const
Returns
The amount of time left until this timer interval expires.

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.

+ Here is the call graph for this function:

◆ GetMaxInterval()

Time ns3::TrickleTimer::GetMaxInterval ( ) const

Get the MaxInterval of the timer.

The timer MaxInterval is always std::exp2 (doublings) * minInterval

Returns
The MaxInterval

Definition at line 103 of file trickle-timer.cc.

References m_maxInterval, and NS_LOG_FUNCTION.

◆ GetMinInterval()

Time ns3::TrickleTimer::GetMinInterval ( ) const

Get the MinInterval of the timer.

Returns
The MinInterval

Definition at line 96 of file trickle-timer.cc.

References m_minInterval, and NS_LOG_FUNCTION.

◆ GetRedundancy()

uint16_t ns3::TrickleTimer::GetRedundancy ( ) const

Get the Redundancy constant of the timer.

Returns
The Redundancy

Definition at line 136 of file trickle-timer.cc.

References m_redundancy, and NS_LOG_FUNCTION.

◆ InconsistentEvent()

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().

+ Here is the call graph for this function:

◆ IntervalExpire()

void ns3::TrickleTimer::IntervalExpire ( )
private

Internal callback invoked when the interval expires.

Definition at line 253 of file trickle-timer.cc.

References ns3::UniformRandomVariable::GetValue(), m_counter, m_currentInterval, m_intervalExpiration, m_maxInterval, m_timerExpiration, m_uniRand, NS_LOG_FUNCTION, ns3::Simulator::Schedule(), and TimerExpire().

Referenced by Enable(), and Reset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Reset()

◆ SetArguments()

template<typename... Ts>
void ns3::TrickleTimer::SetArguments ( Ts &&...  args)

Set the arguments to be used when invoking the expire function.

Template Parameters
Ts[deduced] Argument types.
Parameters
[in]argsarguments

Definition at line 281 of file trickle-timer.h.

References check-style-clang-format::args, m_impl, NS_FATAL_ERROR, and ns3::TimerImpl::SetArgs().

+ Here is the call graph for this function:

◆ SetFunction() [1/2]

template<typename FN >
void ns3::TrickleTimer::SetFunction ( FN  fn)

Set the function to execute when the timer expires.

Template Parameters
FN[deduced] The type of the function.
Parameters
[in]fnThe 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetFunction() [2/2]

template<typename MEM_PTR , typename OBJ_PTR >
void ns3::TrickleTimer::SetFunction ( MEM_PTR  memPtr,
OBJ_PTR  objPtr 
)

Set the function to execute when the timer expires.

Template Parameters
MEM_PTR[deduced] Class method function type.
OBJ_PTR[deduced] Class type containing the function.
Parameters
[in]memPtrThe member function pointer
[in]objPtrThe 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().

+ Here is the call graph for this function:

◆ SetParameters()

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.

Parameters
minIntervalMinimum interval.
doublingsNumber of doublings to reach the maximum interval.
redundancyRedundancy 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.

◆ Stop()

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.

+ Here is the call graph for this function:

◆ TimerExpire()

void ns3::TrickleTimer::TimerExpire ( )
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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_counter

uint16_t ns3::TrickleTimer::m_counter
private

Event counter.

Definition at line 247 of file trickle-timer.h.

Referenced by ConsistentEvent(), Enable(), IntervalExpire(), Reset(), Stop(), and TimerExpire().

◆ m_currentInterval

Time ns3::TrickleTimer::m_currentInterval
private

Current interval.

Definition at line 246 of file trickle-timer.h.

Referenced by Enable(), InconsistentEvent(), IntervalExpire(), Reset(), and Stop().

◆ m_impl

TimerImpl* ns3::TrickleTimer::m_impl
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().

◆ m_intervalExpiration

EventId ns3::TrickleTimer::m_intervalExpiration
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().

◆ m_maxInterval

Time ns3::TrickleTimer::m_maxInterval
private

Maximum interval.

Definition at line 242 of file trickle-timer.h.

Referenced by TrickleTimer(), GetMaxInterval(), IntervalExpire(), and SetParameters().

◆ m_minInterval

Time ns3::TrickleTimer::m_minInterval
private

Minimum interval.

Definition at line 241 of file trickle-timer.h.

Referenced by TrickleTimer(), Enable(), GetMinInterval(), InconsistentEvent(), Reset(), SetParameters(), and Stop().

◆ m_redundancy

uint16_t ns3::TrickleTimer::m_redundancy
private

Redundancy constant.

Definition at line 243 of file trickle-timer.h.

Referenced by TrickleTimer(), GetRedundancy(), SetParameters(), and TimerExpire().

◆ m_ticks

uint64_t ns3::TrickleTimer::m_ticks
private

Interval span (i.e., exp2(doublings)).

Definition at line 245 of file trickle-timer.h.

Referenced by TrickleTimer(), Enable(), GetDoublings(), and SetParameters().

◆ m_timerExpiration

EventId ns3::TrickleTimer::m_timerExpiration
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().

◆ m_uniRand

Ptr<UniformRandomVariable> ns3::TrickleTimer::m_uniRand
private

Object to generate uniform random numbers.

Definition at line 249 of file trickle-timer.h.

Referenced by AssignStreams(), Enable(), IntervalExpire(), and Reset().


The documentation for this class was generated from the following files: