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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Manuel Requena <manuel.requena@cttc.es>
18 */
19
20#ifndef LTE_RLC_SEQUENCE_NUMBER_H
21#define LTE_RLC_SEQUENCE_NUMBER_H
22
23#include <ns3/assert.h>
24
25#include <iostream>
26#include <limits>
27#include <stdint.h>
28
29namespace ns3
30{
31
32/// SequenceNumber10 class
34{
35 public:
37 : m_value(0),
39 {
40 }
41
42 /**
43 * Constructor
44 *
45 * \param value the value
46 */
47 explicit SequenceNumber10(uint16_t value)
48 : m_value(value % 1024),
50 {
51 }
52
53 /**
54 * Constructor
55 *
56 * \param value the value
57 */
59 : m_value(value.m_value),
61 {
62 }
63
64 /**
65 * Assignment operator
66 *
67 * \param value the value
68 * \returns SequenceNumber10
69 */
70 SequenceNumber10& operator=(uint16_t value)
71 {
72 m_value = value % 1024;
73 return *this;
74 }
75
76 /**
77 * \brief Extracts the numeric value of the sequence number
78 * \returns the sequence number value
79 */
80 uint16_t GetValue() const
81 {
82 return m_value;
83 }
84
85 /**
86 * \brief Set modulus base
87 * \param modulusBase the modulus
88 */
90 {
91 m_modulusBase = modulusBase.m_value;
92 }
93
94 /**
95 * \brief Set modulus base
96 * \param modulusBase the modulus
97 */
98 void SetModulusBase(uint16_t modulusBase)
99 {
100 m_modulusBase = modulusBase;
101 }
102
103 /**
104 * postfix ++ operator
105 * \returns SequenceNumber10
106 */
108 {
110 m_value = ((uint32_t)m_value + 1) % 1024;
112 return retval;
113 }
114
115 /**
116 * addition operator
117 * \param delta the amount to add
118 * \returns SequenceNumber10
119 */
120 SequenceNumber10 operator+(uint16_t delta) const
121 {
122 SequenceNumber10 ret((m_value + delta) % 1024);
124 return ret;
125 }
126
127 /**
128 * subtraction operator
129 * \param delta the amount to subtract
130 * \returns SequenceNumber10
131 */
132 SequenceNumber10 operator-(uint16_t delta) const
133 {
134 SequenceNumber10 ret((m_value - delta) % 1024);
136 return ret;
137 }
138
139 /**
140 * subtraction operator
141 * \param other the amount to subtract
142 * \returns SequenceNumber10
143 */
144 uint16_t operator-(const SequenceNumber10& other) const
145 {
146 uint16_t diff = m_value - other.m_value;
147 return diff;
148 }
149
150 /**
151 * greater than operator
152 * \param other the object to compare
153 * \returns true if greater than
154 */
155 bool operator>(const SequenceNumber10& other) const
156 {
158 uint16_t v1 = (m_value - m_modulusBase) % 1024;
159 uint16_t v2 = (other.m_value - other.m_modulusBase) % 1024;
160 return v1 > v2;
161 }
162
163 /**
164 * equality operator
165 * \param other the object to compare
166 * \returns true if equal
167 */
168 bool operator==(const SequenceNumber10& other) const
169 {
170 return (m_value == other.m_value);
171 }
172
173 /**
174 * inequality operator
175 * \param other the object to compare
176 * \returns true if not equal
177 */
178 bool operator!=(const SequenceNumber10& other) const
179 {
180 return (m_value != other.m_value);
181 }
182
183 /**
184 * less than or equal operator
185 * \param other the object to compare
186 * \returns true if less than or equal
187 */
188 bool operator<=(const SequenceNumber10& other) const
189 {
190 return (!this->operator>(other));
191 }
192
193 /**
194 * greater than or equal operator
195 * \param other the object to compare
196 * \returns true if greater than or equal
197 */
198 bool operator>=(const SequenceNumber10& other) const
199 {
200 return (this->operator>(other) || this->operator==(other));
201 }
202
203 /**
204 * less than operator
205 * \param other the object to compare
206 * \returns true if less than
207 */
208 bool operator<(const SequenceNumber10& other) const
209 {
210 return !this->operator>(other) && m_value != other.m_value;
211 }
212
213 friend std::ostream& operator<<(std::ostream& os, const SequenceNumber10& val);
214
215 private:
216 uint16_t m_value; ///< the value
217 uint16_t m_modulusBase; ///< the modulus base
218};
219
220} // namespace ns3
221
222#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:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.