A Discrete-Event Network Simulator
API
ns3::LollipopCounter< T > Class Template Reference

Template class implementing a Lollipop counter as defined in RFC 8505, RFC 6550, and [Perlman83]. More...

#include "lollipop-counter.h"

+ Collaboration diagram for ns3::LollipopCounter< T >:

Public Member Functions

 LollipopCounter ()
 Builds a Lollipop counter with a default initial value. More...
 
 LollipopCounter (T val)
 Builds a Lollipop counter with a specific initial value. More...
 
GetValue () const
 Get the counter value. More...
 
bool IsComparable (const LollipopCounter &val) const
 Checks if two counters are comparable (i.e., not desynchronized). More...
 
bool IsInit () const
 Checks if a counter is in its starting region. More...
 
LollipopCounteroperator= (const LollipopCounter &o)
 Assignment. More...
 
void Reset ()
 Resets the counter to its initial value. More...
 
void SetSequenceWindowSize (uint16_t numberOfBits)
 Set the Sequence Window Size and resets the counter. More...
 

Private Member Functions

AbsoluteMagnitudeOfDifference (LollipopCounter const &val) const
 Compute the Absolute Magnitude Of Difference between two counters. More...
 

Private Attributes

m_sequenceWindow
 Sequence window used for comparing two counters. More...
 
m_value
 Value of the Lollipop Counter. More...
 

Static Private Attributes

static constexpr T m_circularRegion = m_maxValue >> 1
 Circular region of the counter. More...
 
static constexpr T m_maxValue = std::numeric_limits<T>::max ()
 Maximum value of the counter. More...
 

Friends

LollipopCounter operator++ (LollipopCounter &val)
 Prefix increment operator. More...
 
LollipopCounter operator++ (LollipopCounter &val, int noop)
 Postfix increment operator. More...
 
bool operator< (const LollipopCounter &lhs, const LollipopCounter &rhs)
 Arithmetic operator less-than. More...
 
std::ostream & operator<< (std::ostream &os, LollipopCounter const &counter)
 Output streamer for LollipopCounter. More...
 
bool operator== (const LollipopCounter &lhs, const LollipopCounter &rhs)
 Arithmetic operator equal-to. More...
 
bool operator> (const LollipopCounter &lhs, const LollipopCounter &rhs)
 Arithmetic operator greater-than. More...
 

Detailed Description

template<class T>
class ns3::LollipopCounter< T >

Template class implementing a Lollipop counter as defined in RFC 8505, RFC 6550, and [Perlman83].

A Lollipop counter is a counter that solves initialization and out-of-order problems often occurring in Internet protocols.

The counter is split in two regions, an initializing region, and a circular region, having the same size. Assuming a counter using an uint8_t (max value 255), values from 128 and greater are used as a linear sequence to indicate a restart and bootstrap the counter, and the values less than or equal to 127 are used as a circular sequence number space of size 128 as mentioned in RFC 1982.

In both regions, the comparison between two counters is allowed only if both counters are inside a Sequence Window. The default value for the Sequence Window is equal to 2^N where N is half the number of digits of the underlying type. For an uint8_t the Sequence Window is 16.

The counter, by default, is initialized to the maximum counter value minus the Sequence Window plus one, e.g., in case of a uint8_t, to 240.

This implementation extends the case presented in RFCs, allowing to use a larger underlying type and to change the Sequence Window size.

Warning: two Lollipop counters can be compared only if they are of the same type (same underlying type, and same Sequence Window).

References: [Perlman83] Perlman, R., "Fault-Tolerant Broadcast of Routing Information", North-Holland Computer Networks 7: pp. 395-405, DOI 10.1016/0376-5075(83)90034-X, 1983, http://www.cs.illinois.edu/~pbg/courses/cs598fa09/readings/p83.pdf.

Template Parameters
T[explicit] The type being used for the counter.

Definition at line 63 of file lollipop-counter.h.

Constructor & Destructor Documentation

◆ LollipopCounter() [1/2]

template<class T>
ns3::LollipopCounter< T >::LollipopCounter ( )
inline

Builds a Lollipop counter with a default initial value.

The Sequence Window is set to the default value. The initial value is set to the maximum counter value minus the Sequence Window plus one.

Definition at line 72 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::m_maxValue, ns3::LollipopCounter< T >::m_sequenceWindow, ns3::LollipopCounter< T >::m_value, and NS_ABORT_MSG_UNLESS.

◆ LollipopCounter() [2/2]

template<class T>
ns3::LollipopCounter< T >::LollipopCounter ( val)
inline

Builds a Lollipop counter with a specific initial value.

The Sequence Window is set to the default value.

Parameters
valthe initial value of the Lollipop Counter
Template Parameters
T[deduced] The type being used for the counter.

Definition at line 90 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::m_sequenceWindow, and ns3::LollipopCounter< T >::m_value.

Member Function Documentation

◆ AbsoluteMagnitudeOfDifference()

template<class T>
T ns3::LollipopCounter< T >::AbsoluteMagnitudeOfDifference ( LollipopCounter< T > const &  val) const
inlineprivate

Compute the Absolute Magnitude Of Difference between two counters.

The Absolute Magnitude Of Difference is considered to be on a circular region, and it is represented by the smallest circular distance between two numbers.

Arithmetic operator.

Parameters
[in]valCounter to compute the difference against
Returns
The result of the difference.

Definition at line 371 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::m_circularRegion, ns3::LollipopCounter< T >::m_value, max, and min.

Referenced by ns3::LollipopCounter< T >::IsComparable().

+ Here is the caller graph for this function:

◆ GetValue()

template<class T>
T ns3::LollipopCounter< T >::GetValue ( void  ) const
inline

Get the counter value.

Returns
the counter value.

Definition at line 339 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::m_value.

◆ IsComparable()

template<class T>
bool ns3::LollipopCounter< T >::IsComparable ( const LollipopCounter< T > &  val) const
inline

Checks if two counters are comparable (i.e., not desynchronized).

If the absolute magnitude of difference of the two sequence counters is greater than Sequence Window, then a desynchronization has occurred and the two sequence numbers are not comparable.

Sequence Window is equal to 2^N where N is (by default) half the number of digits of the underlying type.

Returns
true if the two counters are comparable.

Definition at line 151 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::AbsoluteMagnitudeOfDifference(), ns3::LollipopCounter< T >::m_circularRegion, ns3::LollipopCounter< T >::m_sequenceWindow, ns3::LollipopCounter< T >::m_value, and NS_ABORT_MSG_IF.

Referenced by LollipopCounterTest::DoRun().

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

◆ IsInit()

template<class T>
bool ns3::LollipopCounter< T >::IsInit ( ) const
inline

Checks if a counter is in its starting region.

Returns
true if a counter is in its starting region.

Definition at line 173 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::m_circularRegion, and ns3::LollipopCounter< T >::m_value.

◆ operator=()

template<class T>
LollipopCounter& ns3::LollipopCounter< T >::operator= ( const LollipopCounter< T > &  o)
inline

Assignment.

Parameters
[in]oValue to assign to this LollipopCounter.
Returns
This LollipopCounter.

Definition at line 104 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::m_value.

◆ Reset()

template<class T>
void ns3::LollipopCounter< T >::Reset ( void  )
inline

Resets the counter to its initial value.

Definition at line 113 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::m_maxValue, ns3::LollipopCounter< T >::m_sequenceWindow, and ns3::LollipopCounter< T >::m_value.

◆ SetSequenceWindowSize()

template<class T>
void ns3::LollipopCounter< T >::SetSequenceWindowSize ( uint16_t  numberOfBits)
inline

Set the Sequence Window Size and resets the counter.

The sequence window is equal to 2^numberOfBits. The counter is reset to maxValue - m_sequenceWindow +1, where maxValue is the maximum number allowed by the underlying type.

Parameters
numberOfBitsnumber of bits to use in the Sequence Window

Definition at line 127 of file lollipop-counter.h.

References ns3::LollipopCounter< T >::m_maxValue, ns3::LollipopCounter< T >::m_sequenceWindow, ns3::LollipopCounter< T >::m_value, and NS_ABORT_MSG_IF.

Friends And Related Function Documentation

◆ operator++ [1/2]

template<class T>
LollipopCounter operator++ ( LollipopCounter< T > &  val)
friend

Prefix increment operator.

Parameters
[in]valLollipopCounter to be incremented
Returns
The result of the Prefix increment.

Definition at line 309 of file lollipop-counter.h.

◆ operator++ [2/2]

template<class T>
LollipopCounter operator++ ( LollipopCounter< T > &  val,
int  noop 
)
friend

Postfix increment operator.

Parameters
[in]valLollipopCounter to be incremented
[in]noopignored argument (used to mark it as a postfix, blame c++).
Returns
The result of the Postfix increment.

Definition at line 327 of file lollipop-counter.h.

◆ operator<

template<class T>
bool operator< ( const LollipopCounter< T > &  lhs,
const LollipopCounter< T > &  rhs 
)
friend

Arithmetic operator less-than.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 285 of file lollipop-counter.h.

◆ operator<<

template<class T>
std::ostream& operator<< ( std::ostream &  os,
LollipopCounter< T > const &  counter 
)
friend

Output streamer for LollipopCounter.

Parameters
[in,out]osThe output stream.
[in]counterThe LollipopCounter to print.
Returns
The stream.

Definition at line 352 of file lollipop-counter.h.

◆ operator==

template<class T>
bool operator== ( const LollipopCounter< T > &  lhs,
const LollipopCounter< T > &  rhs 
)
friend

Arithmetic operator equal-to.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 188 of file lollipop-counter.h.

◆ operator>

template<class T>
bool operator> ( const LollipopCounter< T > &  lhs,
const LollipopCounter< T > &  rhs 
)
friend

Arithmetic operator greater-than.

Parameters
[in]lhsLeft hand argument
[in]rhsRight hand argument
Returns
The result of the operator.

Definition at line 206 of file lollipop-counter.h.

Member Data Documentation

◆ m_circularRegion

template<class T>
constexpr T ns3::LollipopCounter< T >::m_circularRegion = m_maxValue >> 1
staticprivate

◆ m_maxValue

template<class T>
constexpr T ns3::LollipopCounter< T >::m_maxValue = std::numeric_limits<T>::max ()
staticprivate

◆ m_sequenceWindow

template<class T>
T ns3::LollipopCounter< T >::m_sequenceWindow
private

◆ m_value


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