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 namespace ns3
30 {
31 
34 {
35  public:
37  : m_value(0),
38  m_modulusBase(0)
39  {
40  }
41 
47  explicit SequenceNumber10(uint16_t value)
48  : m_value(value % 1024),
49  m_modulusBase(0)
50  {
51  }
52 
59  : m_value(value.m_value),
61  {
62  }
63 
70  SequenceNumber10& operator=(uint16_t value)
71  {
72  m_value = value % 1024;
73  return *this;
74  }
75 
80  uint16_t GetValue() const
81  {
82  return m_value;
83  }
84 
89  void SetModulusBase(SequenceNumber10 modulusBase)
90  {
91  m_modulusBase = modulusBase.m_value;
92  }
93 
98  void SetModulusBase(uint16_t modulusBase)
99  {
100  m_modulusBase = modulusBase;
101  }
102 
108  {
109  SequenceNumber10 retval(m_value);
110  m_value = ((uint32_t)m_value + 1) % 1024;
112  return retval;
113  }
114 
121  {
122  SequenceNumber10 ret((m_value + delta) % 1024);
124  return ret;
125  }
126 
133  {
134  SequenceNumber10 ret((m_value - delta) % 1024);
136  return ret;
137  }
138 
144  uint16_t operator-(const SequenceNumber10& other) const
145  {
146  uint16_t diff = m_value - other.m_value;
147  return diff;
148  }
149 
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 
168  bool operator==(const SequenceNumber10& other) const
169  {
170  return (m_value == other.m_value);
171  }
172 
178  bool operator!=(const SequenceNumber10& other) const
179  {
180  return (m_value != other.m_value);
181  }
182 
188  bool operator<=(const SequenceNumber10& other) const
189  {
190  return (!this->operator>(other));
191  }
192 
198  bool operator>=(const SequenceNumber10& other) const
199  {
200  return (this->operator>(other) || this->operator==(other));
201  }
202 
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;
217  uint16_t m_modulusBase;
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.