A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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.
 
 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::TimerImplm_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< UniformRandomVariablem_uniRand
 Object to generate uniform random numbers.
 

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 67 of file trickle-timer.h.

Constructor & Destructor Documentation

◆ TrickleTimer() [1/2]

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.

◆ 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 37 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 56 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 65 of file trickle-timer.cc.

References m_uniRand.

◆ ConsistentEvent()

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

+ Here is the caller graph for this function:

◆ Enable()

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

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

◆ 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 120 of file trickle-timer.cc.

References ns3::Simulator::GetDelayLeft(), ns3::EventId::IsPending(), 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 100 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 133 of file trickle-timer.cc.

References ns3::Simulator::GetDelayLeft(), ns3::EventId::IsPending(), 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 93 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 86 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 113 of file trickle-timer.cc.

References m_redundancy, and NS_LOG_FUNCTION.

◆ InconsistentEvent()

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

+ Here is the call graph for this function:

◆ IntervalExpire()

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

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

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

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

◆ 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 275 of file trickle-timer.h.

References m_impl, NS_FATAL_ERROR, and ns3::internal::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 259 of file trickle-timer.h.

References m_impl, and ns3::internal::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 267 of file trickle-timer.h.

References m_impl, and ns3::internal::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 72 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 208 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 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().

+ 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 241 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 240 of file trickle-timer.h.

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

◆ m_impl

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

◆ m_intervalExpiration

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

◆ m_maxInterval

Time ns3::TrickleTimer::m_maxInterval
private

Maximum interval.

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

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

◆ m_minInterval

Time ns3::TrickleTimer::m_minInterval
private

Minimum interval.

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

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

◆ m_redundancy

uint16_t ns3::TrickleTimer::m_redundancy
private

Redundancy constant.

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

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

◆ m_ticks

uint64_t ns3::TrickleTimer::m_ticks
private

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

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

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

◆ m_timerExpiration

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

◆ m_uniRand

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

Object to generate uniform random numbers.

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

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


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