Generic "sequence number" class. More...
#include "sequence-number.h"
Public Member Functions | |
SequenceNumber () | |
SequenceNumber (NUMERIC_TYPE value) | |
Constructs a SequenceNumber with the given value. More... | |
SequenceNumber (SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > const &value) | |
Constructs a SequenceNumber from a copy. More... | |
NUMERIC_TYPE | GetValue () const |
Extracts the numeric value of the sequence number. More... | |
bool | operator!= (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &other) const |
Inequality operator for comparing sequence numbers. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator+ (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &other) const |
Operator defining addition of two sequence numbers. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator+ (SIGNED_TYPE delta) const |
Addition operator for adding numeric value to sequence number. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator++ () |
Prefix increment operator. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator++ (int) |
Postfix increment operator. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > & | operator+= (SIGNED_TYPE value) |
Plus equals operator. More... | |
SIGNED_TYPE | operator- (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &other) const |
Subtraction operator for subtracting sequence number from sequence number. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator- (SIGNED_TYPE delta) const |
Subtraction operator for subtracting numeric value from sequence number. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator-- () |
Prefix decrement operator. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator-- (int) |
Postfix decrement operator. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > & | operator-= (SIGNED_TYPE value) |
Minus equals operator. More... | |
bool | operator< (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &other) const |
Less than operator for comparing sequence numbers. More... | |
bool | operator<= (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &other) const |
Less than or equal operator for comparing sequence numbers. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > & | operator= (NUMERIC_TYPE value) |
Constructs a SequenceNumber from an assignment of given value. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > & | operator= (SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > const &value) |
Constructs a SequenceNumber from an assignment of another sequence number. More... | |
bool | operator== (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &other) const |
Equality operator for comparing sequence number. More... | |
bool | operator> (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &other) const |
Here is the critical part, how the comparison is made taking into account wrap-around. More... | |
bool | operator>= (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &other) const |
Greater than or equal operator for comparing sequence numbers. More... | |
Private Member Functions | |
bool | operator! () const |
Logical NOT operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator% (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Modulo operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator& (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Bitwise AND operator - unimplemented. More... | |
bool | operator&& (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Logical AND operator - unimplemented. More... | |
int | operator* () |
Indirection operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator* (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Multiplication operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > & | operator+= (SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > const &value) |
Plus equals operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > & | operator-= (SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > const &value) |
Minus equals operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator/ (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Division operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator<< (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Bitwise left shift operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator>> (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Bitwise right shift operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator^ (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Bitwise XOR operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator| (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Bitwise OR operator - unimplemented. More... | |
bool | operator|| (const SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > &b) const |
Logical OR operator - unimplemented. More... | |
SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE > | operator~ () const |
Bitwise NOT operator - unimplemented. More... | |
Private Attributes | |
NUMERIC_TYPE | m_value |
Sequence number value. More... | |
Friends | |
template<typename NUMERIC_TYPE2 , typename SIGNED_TYPE2 > | |
std::ostream & | operator<< (std::ostream &os, const SequenceNumber< NUMERIC_TYPE2, SIGNED_TYPE2 > &val) |
For printing sequence number. More... | |
template<typename NUMERIC_TYPE2 , typename SIGNED_TYPE2 > | |
std::istream & | operator>> (std::istream &is, const SequenceNumber< NUMERIC_TYPE2, SIGNED_TYPE2 > &val) |
For loading sequence number from input streams. More... | |
Generic "sequence number" class.
This class can be used to handle sequence numbers. In networking protocols, sequence numbers are fixed precision integer numbers that are used to order events relative to each other. A sequence number is expected to increase over time but, since it has a limited number of bits, the number will "wrap around" from the maximum value that can represented with the given number of bits back to zero. For this reason, comparison of two sequence numbers, and subtraction, is non-trivial. The SequenceNumber class behaves like a number, with the usual arithmetic operators implemented, but knows how to correctly compare and subtract sequence numbers.
This is a templated class. To use it you need to supply two fundamental types as template parameters: NUMERIC_TYPE and SIGNED_TYPE. For instance, SequenceNumber<uint32_t, int32_t> gives you a 32-bit sequence number, while SequenceNumber<uint16_t, int16_t> is a 16-bit one. For your convenience, these are typedef'ed as SequenceNumber32 and SequenceNumber16, respectively.
Definition at line 59 of file sequence-number.h.
|
inline |
Definition at line 62 of file sequence-number.h.
|
inlineexplicit |
Constructs a SequenceNumber with the given value.
value | the sequence number value |
Definition at line 70 of file sequence-number.h.
|
inline |
Constructs a SequenceNumber from a copy.
value | sequence number to copy |
Definition at line 78 of file sequence-number.h.
|
inline |
Extracts the numeric value of the sequence number.
Definition at line 116 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
Referenced by ns3::TcpTxBuffer::CopyFromSequence(), SequenceNumberTestCase::DoRun(), TcpFastRetrTest::FinalChecks(), ns3::TcpSocketBase::IsPacingEnabled(), ns3::LrWpanMac::McpsDataRequest(), ns3::LrWpanMac::MlmePollRequest(), ns3::TcpTxBuffer::NextSeg(), TcpFastRetrTest::ProcessedAck(), TcpFastRetrTest::RcvAck(), TcpFastRetrTest::Rx(), TcpPktsAckedOpenTest::Rx(), TcpSlowStartNormalTest::Rx(), ns3::TcpSocketSmallAcks::SendEmptyPacket(), ns3::LrWpanMac::SendOneBeacon(), ns3::TcpHeader::Serialize(), ns3::TcpOptionSack::Serialize(), TcpTxBufferTestCase::TestNextSeg(), anonymous_namespace{traced-value-callback-typedef-test-suite.cc}::TracedValueCbSink< SequenceNumber32 >(), TcpFastRetrTest::Tx(), and TcpTimeRtoTest::Tx().
|
private |
Logical NOT operator - unimplemented.
|
inline |
Inequality operator for comparing sequence numbers.
other | sequence number to compare to this sequence number |
Definition at line 297 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
private |
Modulo operator - unimplemented.
b | value |
|
private |
Bitwise AND operator - unimplemented.
b | value |
|
private |
Logical AND operator - unimplemented.
b | value |
|
private |
Indirection operator - unimplemented.
|
private |
Multiplication operator - unimplemented.
b | value |
|
inline |
Operator defining addition of two sequence numbers.
other | sequence number added to this |
Definition at line 190 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Addition operator for adding numeric value to sequence number.
delta | value to add to sequence number |
Definition at line 200 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Prefix increment operator.
Definition at line 125 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Postfix increment operator.
Definition at line 135 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
private |
Plus equals operator - unimplemented.
value | value |
|
inline |
Plus equals operator.
value | value to add to sequence number |
Definition at line 168 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Subtraction operator for subtracting sequence number from sequence number.
other | sequence number to subtract from this sequence number |
Definition at line 220 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value, and max.
|
inline |
Subtraction operator for subtracting numeric value from sequence number.
delta | value to subtract from sequence number |
Definition at line 210 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Prefix decrement operator.
Definition at line 146 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Postfix decrement operator.
Definition at line 156 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
private |
Minus equals operator - unimplemented.
value | value |
|
inline |
Minus equals operator.
value | value to subtract from sequence number |
Definition at line 179 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
private |
Division operator - unimplemented.
b | value |
|
inline |
Less than operator for comparing sequence numbers.
other | sequence number to compare to this sequence number |
Definition at line 327 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value, and ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator>().
|
private |
Bitwise left shift operator - unimplemented.
b | value |
|
inline |
Less than or equal operator for comparing sequence numbers.
other | sequence number to compare to this sequence number |
Definition at line 307 of file sequence-number.h.
|
inline |
Constructs a SequenceNumber from an assignment of given value.
value | sequence number to copy |
Definition at line 87 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Constructs a SequenceNumber from an assignment of another sequence number.
value | sequence number to copy |
Definition at line 98 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Equality operator for comparing sequence number.
other | sequence number to compare to this sequence number |
Definition at line 287 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value.
|
inline |
Here is the critical part, how the comparison is made taking into account wrap-around.
From RFC 3626:
The sequence number S1 is said to be "greater than" the sequence number S2 if: S1 > S2 AND S1 - S2 <= MAXVALUE/2 OR S2 > S1 AND S2 - S1 > MAXVALUE/2
other | sequence number to compare to this one |
Definition at line 274 of file sequence-number.h.
References ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::m_value, and max.
Referenced by ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator<().
|
inline |
Greater than or equal operator for comparing sequence numbers.
other | sequence number to compare to this sequence number |
Definition at line 317 of file sequence-number.h.
|
private |
Bitwise right shift operator - unimplemented.
b | value |
|
private |
Bitwise XOR operator - unimplemented.
b | value |
|
private |
Bitwise OR operator - unimplemented.
b | value |
|
private |
Logical OR operator - unimplemented.
b | value |
|
private |
Bitwise NOT operator - unimplemented.
|
friend |
For printing sequence number.
os | output stream |
val | sequence number to display |
|
friend |
For loading sequence number from input streams.
is | input stream |
val | sequence number to load |
|
private |
Sequence number value.
Definition at line 441 of file sequence-number.h.
Referenced by ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::GetValue(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator!=(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator+(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator++(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator+=(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator-(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator--(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator-=(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator<(), ns3::operator<<(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator=(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator==(), ns3::SequenceNumber< NUMERIC_TYPE, SIGNED_TYPE >::operator>(), and ns3::operator>>().