A Discrete-Event Network Simulator
API
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 
29 // #include "ns3/lte-rlc.h"
30 
31 namespace ns3
32 {
33 
36 {
37  public:
39  : m_value(0),
40  m_modulusBase(0)
41  {
42  }
43 
49  explicit SequenceNumber10(uint16_t value)
50  : m_value(value % 1024),
51  m_modulusBase(0)
52  {
53  }
54 
63  {
64  }
65 
73  {
74  m_value = value % 1024;
75  return *this;
76  }
77 
82  uint16_t GetValue() const
83  {
84  return m_value;
85  }
86 
91  void SetModulusBase(SequenceNumber10 modulusBase)
92  {
93  m_modulusBase = modulusBase.m_value;
94  }
95 
100  void SetModulusBase(uint16_t modulusBase)
101  {
102  m_modulusBase = modulusBase;
103  }
104 
110  {
111  SequenceNumber10 retval(m_value);
112  m_value = ((uint32_t)m_value + 1) % 1024;
114  return retval;
115  }
116 
123  {
124  SequenceNumber10 ret((m_value + delta) % 1024);
126  return ret;
127  }
128 
135  {
136  SequenceNumber10 ret((m_value - delta) % 1024);
138  return ret;
139  }
140 
146  uint16_t operator-(const SequenceNumber10& other) const
147  {
148  uint16_t diff = m_value - other.m_value;
149  return (diff);
150  }
151 
157  bool operator>(const SequenceNumber10& other) const
158  {
160  uint16_t v1 = (m_value - m_modulusBase) % 1024;
161  uint16_t v2 = (other.m_value - other.m_modulusBase) % 1024;
162  return v1 > v2;
163  }
164 
170  bool operator==(const SequenceNumber10& other) const
171  {
172  return (m_value == other.m_value);
173  }
174 
180  bool operator!=(const SequenceNumber10& other) const
181  {
182  return (m_value != other.m_value);
183  }
184 
190  bool operator<=(const SequenceNumber10& other) const
191  {
192  return (!this->operator>(other));
193  }
194 
200  bool operator>=(const SequenceNumber10& other) const
201  {
202  return (this->operator>(other) || this->operator==(other));
203  }
204 
210  bool operator<(const SequenceNumber10& other) const
211  {
212  return !this->operator>(other) && m_value != other.m_value;
213  }
214 
215  friend std::ostream& operator<<(std::ostream& os, const SequenceNumber10& val);
216 
217  private:
218  uint16_t m_value;
219  uint16_t m_modulusBase;
220 };
221 
222 } // namespace ns3
223 
224 #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.
value
Definition: second.py:41