A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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.
 
 LollipopCounter (T val)
 Builds a Lollipop counter with a specific initial value.
 
GetValue () const
 Get the counter value.
 
bool IsComparable (const LollipopCounter &val) const
 Checks if the counter is comparable with another counter (i.e., not desynchronized).
 
bool IsInit () const
 Checks if a counter is in its starting region.
 
LollipopCounteroperator= (const LollipopCounter &o)
 Assignment.
 
void Reset ()
 Resets the counter to its initial value.
 
void SetSequenceWindowSize (uint16_t numberOfBits)
 Set the Sequence Window Size and resets the counter.
 

Private Member Functions

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

Private Attributes

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

Static Private Attributes

static constexpr T m_circularRegion = m_maxValue >> 1
 Circular region of the counter.
 
static constexpr T m_maxValue
 Maximum value of the counter.
 

Friends

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

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, https://web.archive.org/web/20180723135334/http://pbg.cs.illinois.edu/courses/cs598fa09/readings/p83.pdf.

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

Definition at line 56 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 65 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 ( T 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 84 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 ( const LollipopCounter< T > & 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 344 of file lollipop-counter.h.

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

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

+ Here is the caller graph for this function:

◆ GetValue()

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

Get the counter value.

Returns
the counter value.

Definition at line 314 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 the counter is comparable with another counter (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.

Parameters
valcounter to compare
Returns
true if the counters are comparable.

Definition at line 149 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 172 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 98 of file lollipop-counter.h.

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

◆ Reset()

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

Resets the counter to its initial value.

Definition at line 107 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 121 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 Symbol 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 284 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 302 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 264 of file lollipop-counter.h.

◆ operator<<

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

Output streamer for LollipopCounter.

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

Definition at line 326 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 183 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 197 of file lollipop-counter.h.

Member Data Documentation

◆ m_circularRegion

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

◆ m_maxValue

template<class T >
T ns3::LollipopCounter< T >::m_maxValue
staticconstexprprivate
Initial value:
=
std::numeric_limits<T>::max()

Maximum value of the counter.

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

Referenced by ns3::LollipopCounter< T >::LollipopCounter(), ns3::LollipopCounter< T >::Reset(), and ns3::LollipopCounter< T >::SetSequenceWindowSize().

◆ m_sequenceWindow

◆ m_value


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