A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-rlc-sequence-number.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Manuel Requena <manuel.requena@cttc.es>
7 */
8
9#ifndef LTE_RLC_SEQUENCE_NUMBER_H
10#define LTE_RLC_SEQUENCE_NUMBER_H
11
12#include <ns3/assert.h>
13
14#include <iostream>
15#include <limits>
16#include <stdint.h>
17
18namespace ns3
19{
20
21/// SequenceNumber10 class
23{
24 public:
26 : m_value(0),
28 {
29 }
30
31 /**
32 * Constructor
33 *
34 * @param value the value
35 */
36 explicit SequenceNumber10(uint16_t value)
37 : m_value(value % 1024),
39 {
40 }
41
42 /**
43 * Constructor
44 *
45 * @param value the value
46 */
48 : m_value(value.m_value),
50 {
51 }
52
53 /**
54 * Assignment operator
55 *
56 * @param value the value
57 * @returns SequenceNumber10
58 */
59 SequenceNumber10& operator=(uint16_t value)
60 {
61 m_value = value % 1024;
62 return *this;
63 }
64
65 /**
66 * @brief Extracts the numeric value of the sequence number
67 * @returns the sequence number value
68 */
69 uint16_t GetValue() const
70 {
71 return m_value;
72 }
73
74 /**
75 * @brief Set modulus base
76 * @param modulusBase the modulus
77 */
79 {
80 m_modulusBase = modulusBase.m_value;
81 }
82
83 /**
84 * @brief Set modulus base
85 * @param modulusBase the modulus
86 */
87 void SetModulusBase(uint16_t modulusBase)
88 {
89 m_modulusBase = modulusBase;
90 }
91
92 /**
93 * postfix ++ operator
94 * @returns SequenceNumber10
95 */
97 {
99 m_value = ((uint32_t)m_value + 1) % 1024;
101 return retval;
102 }
103
104 /**
105 * addition operator
106 * @param delta the amount to add
107 * @returns SequenceNumber10
108 */
109 SequenceNumber10 operator+(uint16_t delta) const
110 {
111 SequenceNumber10 ret((m_value + delta) % 1024);
113 return ret;
114 }
115
116 /**
117 * subtraction operator
118 * @param delta the amount to subtract
119 * @returns SequenceNumber10
120 */
121 SequenceNumber10 operator-(uint16_t delta) const
122 {
123 SequenceNumber10 ret((m_value - delta) % 1024);
125 return ret;
126 }
127
128 /**
129 * subtraction operator
130 * @param other the amount to subtract
131 * @returns SequenceNumber10
132 */
133 uint16_t operator-(const SequenceNumber10& other) const
134 {
135 uint16_t diff = m_value - other.m_value;
136 return diff;
137 }
138
139 /**
140 * greater than operator
141 * @param other the object to compare
142 * @returns true if greater than
143 */
144 bool operator>(const SequenceNumber10& other) const
145 {
147 uint16_t v1 = (m_value - m_modulusBase) % 1024;
148 uint16_t v2 = (other.m_value - other.m_modulusBase) % 1024;
149 return v1 > v2;
150 }
151
152 /**
153 * equality operator
154 * @param other the object to compare
155 * @returns true if equal
156 */
157 bool operator==(const SequenceNumber10& other) const
158 {
159 return (m_value == other.m_value);
160 }
161
162 /**
163 * inequality operator
164 * @param other the object to compare
165 * @returns true if not equal
166 */
167 bool operator!=(const SequenceNumber10& other) const
168 {
169 return (m_value != other.m_value);
170 }
171
172 /**
173 * less than or equal operator
174 * @param other the object to compare
175 * @returns true if less than or equal
176 */
177 bool operator<=(const SequenceNumber10& other) const
178 {
179 return (!this->operator>(other));
180 }
181
182 /**
183 * greater than or equal operator
184 * @param other the object to compare
185 * @returns true if greater than or equal
186 */
187 bool operator>=(const SequenceNumber10& other) const
188 {
189 return (this->operator>(other) || this->operator==(other));
190 }
191
192 /**
193 * less than operator
194 * @param other the object to compare
195 * @returns true if less than
196 */
197 bool operator<(const SequenceNumber10& other) const
198 {
199 return !this->operator>(other) && m_value != other.m_value;
200 }
201
202 friend std::ostream& operator<<(std::ostream& os, const SequenceNumber10& val);
203
204 private:
205 uint16_t m_value; ///< the value
206 uint16_t m_modulusBase; ///< the modulus base
207};
208
209} // namespace ns3
210
211#endif // LTE_RLC_SEQUENCE_NUMBER_H
SequenceNumber10 class.
uint16_t m_modulusBase
the modulus base
bool operator==(const SequenceNumber10 &other) const
equality operator
uint16_t operator-(const SequenceNumber10 &other) const
subtraction operator
SequenceNumber10(const SequenceNumber10 &value)
Constructor.
bool operator<(const SequenceNumber10 &other) const
less than operator
void SetModulusBase(uint16_t modulusBase)
Set modulus base.
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
bool operator!=(const SequenceNumber10 &other) const
inequality operator
SequenceNumber10(uint16_t value)
Constructor.
SequenceNumber10 operator+(uint16_t delta) const
addition operator
SequenceNumber10 operator-(uint16_t delta) const
subtraction operator
SequenceNumber10 & operator=(uint16_t value)
Assignment operator.
SequenceNumber10 operator++(int)
postfix ++ operator
bool operator>=(const SequenceNumber10 &other) const
greater than or equal operator
bool operator>(const SequenceNumber10 &other) const
greater than operator
friend std::ostream & operator<<(std::ostream &os, const SequenceNumber10 &val)
Ostream output function.
bool operator<=(const SequenceNumber10 &other) const
less than or equal operator
void SetModulusBase(SequenceNumber10 modulusBase)
Set modulus base.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Every class exported by the ns3 library is enclosed in the ns3 namespace.