A Discrete-Event Network Simulator
API
lte-rlc-sequence-number.h
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Manuel Requena <manuel.requena@cttc.es>
19  */
20 
21 #ifndef LTE_RLC_SEQUENCE_NUMBER_H
22 #define LTE_RLC_SEQUENCE_NUMBER_H
23 
24 #include <limits>
25 #include <iostream>
26 #include <stdint.h>
27 
28 // #include "ns3/lte-rlc.h"
29 
30 namespace ns3 {
31 
32 
34 {
35 public:
37  : m_value (0),
38  m_modulusBase (0)
39  {}
40 
41  explicit SequenceNumber10 (uint16_t value)
42  : m_value (value % 1024),
43  m_modulusBase (0)
44  {}
45 
47  : m_value (value.m_value),
49  {}
50 
51  SequenceNumber10& operator= (uint16_t value)
52  {
53  m_value = value % 1024;
54  return *this;
55  }
56 
57 
62  uint16_t GetValue () const
63  {
64  return m_value;
65  }
66 
67  void SetModulusBase (SequenceNumber10 modulusBase)
68  {
69  m_modulusBase = modulusBase.m_value;
70  }
71 
72  void SetModulusBase (uint16_t modulusBase)
73  {
74  m_modulusBase = modulusBase;
75  }
76 
77  // postfix ++
79  {
80  SequenceNumber10 retval (m_value);
81  m_value = ((uint32_t)m_value + 1) % 1024;
83  return retval;
84  }
85 
86  SequenceNumber10 operator + (uint16_t delta) const
87  {
88  SequenceNumber10 ret ((m_value + delta) % 1024);
90  return ret;
91  }
92 
93  SequenceNumber10 operator - (uint16_t delta) const
94  {
95  SequenceNumber10 ret ((m_value - delta) % 1024);
97  return ret;
98  }
99 
100  uint16_t operator - (const SequenceNumber10 &other) const
101  {
102  uint16_t diff = m_value - other.m_value;
103  return (diff);
104  }
105 
106  bool operator > (const SequenceNumber10 &other) const
107  {
108  SequenceNumber10 v1 ((m_value - m_modulusBase) % 1024);
109  SequenceNumber10 v2 ((other.m_value - other.m_modulusBase) % 1024);
110  return ( v1.GetValue () > v2.GetValue () );
111  }
112 
113  bool operator == (const SequenceNumber10 &other) const
114  {
115  return (m_value == other.m_value);
116  }
117 
118  bool operator != (const SequenceNumber10 &other) const
119  {
120  return (m_value != other.m_value);
121  }
122 
123  bool operator <= (const SequenceNumber10 &other) const
124  {
125  return (!this->operator> (other));
126  }
127 
128  bool operator >= (const SequenceNumber10 &other) const
129  {
130  return (this->operator> (other) || this->operator== (other));
131  }
132 
133  bool operator < (const SequenceNumber10 &other) const
134  {
135  return !this->operator> (other) && m_value != other.m_value;
136  }
137 
138 
139  friend std::ostream & operator<< (std::ostream& os, const SequenceNumber10 &val);
140 
141 private:
142  uint16_t m_value;
143  uint16_t m_modulusBase;
144 };
145 
146 
147 } // namespace ns3
148 
149 #endif // LTE_RLC_SEQUENCE_NUMBER_H
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
friend std::ostream & operator<<(std::ostream &os, const SequenceNumber10 &val)
SequenceNumber10 operator++(int)
bool operator!=(const SequenceNumber10 &other) const
bool operator>=(const SequenceNumber10 &other) const
void SetModulusBase(SequenceNumber10 modulusBase)
bool operator>(const SequenceNumber10 &other) const
bool operator<=(const SequenceNumber10 &other) const
SequenceNumber10 operator+(uint16_t delta) const
SequenceNumber10 & operator=(uint16_t value)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
SequenceNumber10 operator-(uint16_t delta) const
bool operator<(const SequenceNumber10 &other) const
void SetModulusBase(uint16_t modulusBase)
SequenceNumber10(SequenceNumber10 const &value)
bool operator==(const SequenceNumber10 &other) const