5G-LENA nr-v4.0-29-g6d8085cd
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-rlc-sequence-number.h
1// Copyright (c) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4//
5// Author: Manuel Requena <manuel.requena@cttc.es>
6
7#ifndef NR_RLC_SEQUENCE_NUMBER_H
8#define NR_RLC_SEQUENCE_NUMBER_H
9
10#include "ns3/assert.h"
11
12#include <iostream>
13#include <limits>
14#include <stdint.h>
15
16namespace ns3
17{
18namespace nr
19{
22{
23 public:
25 : m_value(0),
26 m_modulusBase(0)
27 {
28 }
29
35 explicit SequenceNumber10(uint16_t value)
36 : m_value(value % 1024),
37 m_modulusBase(0)
38 {
39 }
40
47 : m_value(value.m_value),
48 m_modulusBase(value.m_modulusBase)
49 {
50 }
51
58 SequenceNumber10& operator=(uint16_t value)
59 {
60 m_value = value % 1024;
61 return *this;
62 }
63
68 uint16_t GetValue() const
69 {
70 return m_value;
71 }
72
78 {
79 m_modulusBase = modulusBase.m_value;
80 }
81
86 void SetModulusBase(uint16_t modulusBase)
87 {
88 m_modulusBase = modulusBase;
89 }
90
96 {
97 SequenceNumber10 retval(m_value);
98 m_value = ((uint32_t)m_value + 1) % 1024;
99 retval.SetModulusBase(m_modulusBase);
100 return retval;
101 }
102
108 SequenceNumber10 operator+(uint16_t delta) const
109 {
110 SequenceNumber10 ret((m_value + delta) % 1024);
111 ret.SetModulusBase(m_modulusBase);
112 return ret;
113 }
114
120 SequenceNumber10 operator-(uint16_t delta) const
121 {
122 SequenceNumber10 ret((m_value - delta) % 1024);
123 ret.SetModulusBase(m_modulusBase);
124 return ret;
125 }
126
132 uint16_t operator-(const SequenceNumber10& other) const
133 {
134 uint16_t diff = m_value - other.m_value;
135 return diff;
136 }
137
143 bool operator>(const SequenceNumber10& other) const
144 {
145 NS_ASSERT(m_modulusBase == other.m_modulusBase);
146 uint16_t v1 = (m_value - m_modulusBase) % 1024;
147 uint16_t v2 = (other.m_value - other.m_modulusBase) % 1024;
148 return v1 > v2;
149 }
150
156 bool operator==(const SequenceNumber10& other) const
157 {
158 return (m_value == other.m_value);
159 }
160
166 bool operator!=(const SequenceNumber10& other) const
167 {
168 return (m_value != other.m_value);
169 }
170
176 bool operator<=(const SequenceNumber10& other) const
177 {
178 return (!this->operator>(other));
179 }
180
186 bool operator>=(const SequenceNumber10& other) const
187 {
188 return (this->operator>(other) || this->operator==(other));
189 }
190
196 bool operator<(const SequenceNumber10& other) const
197 {
198 return !this->operator>(other) && m_value != other.m_value;
199 }
200
201 friend std::ostream& operator<<(std::ostream& os, const SequenceNumber10& val);
202
203 private:
204 uint16_t m_value;
205 uint16_t m_modulusBase;
206};
207
208} // namespace nr
209} // namespace ns3
210
211#endif // NR_RLC_SEQUENCE_NUMBER_H
SequenceNumber10 & operator=(uint16_t value)
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
bool operator!=(const SequenceNumber10 &other) const
bool operator>=(const SequenceNumber10 &other) const
bool operator>(const SequenceNumber10 &other) const
SequenceNumber10 operator+(uint16_t delta) const
bool operator<(const SequenceNumber10 &other) const
uint16_t operator-(const SequenceNumber10 &other) const
SequenceNumber10(const SequenceNumber10 &value)
SequenceNumber10 operator-(uint16_t delta) const
bool operator==(const SequenceNumber10 &other) const
void SetModulusBase(uint16_t modulusBase)
Set modulus base.
void SetModulusBase(SequenceNumber10 modulusBase)
Set modulus base.
bool operator<=(const SequenceNumber10 &other) const
friend std::ostream & operator<<(std::ostream &os, const SequenceNumber10 &val)
SequenceNumber10 operator++(int)