Template class implementing a Lollipop counter as defined in RFC 8505 , RFC 6550 , and [Perlman83]. More...
#include "lollipop-counter.h"
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. | |
T | 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. | |
LollipopCounter & | operator= (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 | |
T | AbsoluteMagnitudeOfDifference (const LollipopCounter &val) const |
Compute the Absolute Magnitude Of Difference between two counters. | |
Private Attributes | |
T | m_sequenceWindow |
Sequence window used for comparing two counters. | |
T | 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. | |
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.
T | [explicit] The type being used for the counter. |
Definition at line 56 of file lollipop-counter.h.
|
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.
|
inline |
Builds a Lollipop counter with a specific initial value.
The Sequence Window is set to the default value.
val | the initial value of the Lollipop Counter |
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.
|
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.
[in] | val | Counter to compute the difference against |
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().
|
inline |
Get the counter value.
Definition at line 314 of file lollipop-counter.h.
References ns3::LollipopCounter< T >::m_value.
|
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.
val | counter to compare |
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().
|
inline |
Checks 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.
|
inline |
Assignment.
[in] | o | Value to assign to this LollipopCounter. |
Definition at line 98 of file lollipop-counter.h.
References ns3::LollipopCounter< T >::m_value.
|
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.
|
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.
numberOfBits | number 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.
|
friend |
Prefix increment operator.
[in] | val | LollipopCounter to be incremented |
Definition at line 284 of file lollipop-counter.h.
|
friend |
Postfix increment operator.
[in] | val | LollipopCounter to be incremented |
[in] | noop | ignored argument (used to mark it as a postfix, blame c++). |
Definition at line 302 of file lollipop-counter.h.
|
friend |
Arithmetic operator less-than.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 264 of file lollipop-counter.h.
|
friend |
Output streamer for LollipopCounter.
[in,out] | os | The output stream. |
[in] | counter | The LollipopCounter to print. |
Definition at line 326 of file lollipop-counter.h.
|
friend |
Arithmetic operator equal-to.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 183 of file lollipop-counter.h.
|
friend |
Arithmetic operator greater-than.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 197 of file lollipop-counter.h.
|
staticconstexprprivate |
Circular region of the counter.
Definition at line 364 of file lollipop-counter.h.
Referenced by ns3::LollipopCounter< T >::AbsoluteMagnitudeOfDifference(), ns3::LollipopCounter< T >::IsComparable(), and ns3::LollipopCounter< T >::IsInit().
|
staticconstexprprivate |
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().
|
private |
Sequence window used for comparing two counters.
Definition at line 361 of file lollipop-counter.h.
Referenced by ns3::LollipopCounter< T >::LollipopCounter(), ns3::LollipopCounter< T >::LollipopCounter(), ns3::LollipopCounter< T >::IsComparable(), ns3::LollipopCounter< T >::Reset(), and ns3::LollipopCounter< T >::SetSequenceWindowSize().
|
private |
Value of the Lollipop Counter.
Definition at line 360 of file lollipop-counter.h.
Referenced by ns3::LollipopCounter< T >::LollipopCounter(), ns3::LollipopCounter< T >::LollipopCounter(), ns3::LollipopCounter< T >::AbsoluteMagnitudeOfDifference(), ns3::LollipopCounter< T >::GetValue(), ns3::LollipopCounter< T >::IsComparable(), ns3::LollipopCounter< T >::IsInit(), ns3::LollipopCounter< T >::operator=(), ns3::LollipopCounter< T >::Reset(), and ns3::LollipopCounter< T >::SetSequenceWindowSize().