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. More... | |
LollipopCounter (T val) | |
Builds a Lollipop counter with a specific initial value. More... | |
T | GetValue () const |
Get the counter value. More... | |
bool | IsComparable (const LollipopCounter &val) const |
Checks if the counter is comparable with another counter (i.e., not desynchronized). More... | |
bool | IsInit () const |
Checks if a counter is in its starting region. More... | |
LollipopCounter & | operator= (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 | |
T | AbsoluteMagnitudeOfDifference (LollipopCounter const &val) const |
Compute the Absolute Magnitude Of Difference between two counters. More... | |
Private Attributes | |
T | m_sequenceWindow |
Sequence window used for comparing two counters. More... | |
T | 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... | |
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.
T | [explicit] The type being used for the counter. |
Definition at line 63 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 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.
|
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 90 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 372 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().
|
inline |
Get the counter value.
Definition at line 340 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 152 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 174 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 104 of file lollipop-counter.h.
References ns3::LollipopCounter< T >::m_value.
|
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.
|
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 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.
|
friend |
Prefix increment operator.
[in] | val | LollipopCounter to be incremented |
Definition at line 310 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 328 of file lollipop-counter.h.
|
friend |
Arithmetic operator less-than.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 286 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 352 of file lollipop-counter.h.
|
friend |
Arithmetic operator equal-to.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 189 of file lollipop-counter.h.
|
friend |
Arithmetic operator greater-than.
[in] | lhs | Left hand argument |
[in] | rhs | Right hand argument |
Definition at line 207 of file lollipop-counter.h.
|
staticconstexprprivate |
Circular region of the counter.
Definition at line 389 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 388 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 387 of file lollipop-counter.h.
Referenced by 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 386 of file lollipop-counter.h.
Referenced by 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().