A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-rlc-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Manuel Requena <manuel.requena@cttc.es>
7 */
8
9#include "lte-rlc-header.h"
10
11#include "ns3/log.h"
12
13namespace ns3
14{
15
16NS_LOG_COMPONENT_DEFINE("LteRlcHeader");
17
18NS_OBJECT_ENSURE_REGISTERED(LteRlcHeader);
19
21 : m_headerLength(0),
22 m_framingInfo(0xff),
23 m_sequenceNumber(0xfffa)
24{
25}
26
33
34void
35LteRlcHeader::SetFramingInfo(uint8_t framingInfo)
36{
37 m_framingInfo = framingInfo & 0x03;
38}
39
40void
42{
43 m_sequenceNumber = sequenceNumber;
44}
45
46uint8_t
51
57
58void
59LteRlcHeader::PushExtensionBit(uint8_t extensionBit)
60{
61 m_extensionBits.push_back(extensionBit);
62 if (m_extensionBits.size() == 1)
63 {
64 m_headerLength = 2; // Only fixed part
65 }
66 else if (m_extensionBits.size() % 2)
67 {
68 m_headerLength += 1;
69 }
70 else
71 {
72 m_headerLength += 2;
73 }
74}
75
76void
77LteRlcHeader::PushLengthIndicator(uint16_t lengthIndicator)
78{
79 m_lengthIndicators.push_back(lengthIndicator);
80}
81
82uint8_t
84{
85 uint8_t extensionBit = m_extensionBits.front();
86 m_extensionBits.pop_front();
87
88 return extensionBit;
89}
90
91uint16_t
93{
94 uint16_t lengthIndicator = m_lengthIndicators.front();
95 m_lengthIndicators.pop_front();
96
97 return lengthIndicator;
98}
99
100TypeId
102{
103 static TypeId tid = TypeId("ns3::LteRlcHeader")
104 .SetParent<Header>()
105 .SetGroupName("Lte")
106 .AddConstructor<LteRlcHeader>();
107 return tid;
108}
109
110TypeId
112{
113 return GetTypeId();
114}
115
116void
117LteRlcHeader::Print(std::ostream& os) const
118{
119 auto it1 = m_extensionBits.begin();
120 auto it2 = m_lengthIndicators.begin();
121
122 os << "Len=" << m_headerLength;
123 os << " FI=" << (uint16_t)m_framingInfo;
124 os << " E=" << (uint16_t)(*it1);
125 os << " SN=" << m_sequenceNumber;
126
127 it1++;
128 if (it1 != m_extensionBits.end())
129 {
130 os << " E=";
131 }
132 while (it1 != m_extensionBits.end())
133 {
134 os << (uint16_t)(*it1);
135 it1++;
136 }
137
138 if (it2 != m_lengthIndicators.end())
139 {
140 os << " LI=";
141 }
142 while (it2 != m_lengthIndicators.end())
143 {
144 os << (uint16_t)(*it2) << " ";
145 it2++;
146 }
147}
148
154
155void
157{
158 Buffer::Iterator i = start;
159
160 auto it1 = m_extensionBits.begin();
161 auto it2 = m_lengthIndicators.begin();
162
163 i.WriteU8(((m_framingInfo << 3) & 0x18) | (((*it1) << 2) & 0x04) |
164 ((m_sequenceNumber.GetValue() >> 8) & 0x0003));
165 i.WriteU8(m_sequenceNumber.GetValue() & 0x00FF);
166 it1++;
167
168 while (it1 != m_extensionBits.end() && it2 != m_lengthIndicators.end())
169 {
170 uint16_t oddLi;
171 uint16_t evenLi;
172 uint8_t oddE;
173 uint8_t evenE;
174
175 oddE = *it1;
176 oddLi = *it2;
177
178 it1++;
179 it2++;
180
181 if (it1 != m_extensionBits.end() && it2 != m_lengthIndicators.end())
182 {
183 evenE = *it1;
184 evenLi = *it2;
185
186 i.WriteU8(((oddE << 7) & 0x80) | ((oddLi >> 4) & 0x007F));
187 i.WriteU8(((oddLi << 4) & 0x00F0) | ((evenE << 3) & 0x08) | ((evenLi >> 8) & 0x0007));
188 i.WriteU8(evenLi & 0x00FF);
189
190 it1++;
191 it2++;
192 }
193 else
194 {
195 i.WriteU8(((oddE << 7) & 0x80) | ((oddLi >> 4) & 0x007F));
196 i.WriteU8((oddLi << 4) & 0x00F0); // Padding is implicit
197 }
198 }
199}
200
203{
204 Buffer::Iterator i = start;
205 uint8_t byte_1;
206 uint8_t byte_2;
207 uint8_t byte_3;
208 uint8_t extensionBit;
209
210 byte_1 = i.ReadU8();
211 byte_2 = i.ReadU8();
212 m_headerLength = 2;
213 m_framingInfo = (byte_1 & 0x18) >> 3;
214 m_sequenceNumber = ((byte_1 & 0x03) << 8) | byte_2;
215
216 extensionBit = (byte_1 & 0x04) >> 2;
217 m_extensionBits.push_back(extensionBit);
218
219 if (extensionBit == DATA_FIELD_FOLLOWS)
220 {
221 return GetSerializedSize();
222 }
223
224 uint16_t oddLi;
225 uint16_t evenLi;
226 uint8_t oddE;
227 uint8_t evenE;
228 bool moreLiFields = (extensionBit == E_LI_FIELDS_FOLLOWS);
229
230 while (moreLiFields)
231 {
232 byte_1 = i.ReadU8();
233 byte_2 = i.ReadU8();
234
235 oddE = (byte_1 & 0x80) >> 7;
236 oddLi = ((byte_1 & 0x7F) << 4) | ((byte_2 & 0xF0) >> 4);
237 moreLiFields = (oddE == E_LI_FIELDS_FOLLOWS);
238
239 m_extensionBits.push_back(oddE);
240 m_lengthIndicators.push_back(oddLi);
241 m_headerLength += 2;
242
243 if (moreLiFields)
244 {
245 byte_3 = i.ReadU8();
246
247 evenE = (byte_2 & 0x08) >> 3;
248 evenLi = ((byte_2 & 0x07) << 8) | (byte_3 & 0xFF);
249 moreLiFields = (evenE == E_LI_FIELDS_FOLLOWS);
250
251 m_extensionBits.push_back(evenE);
252 m_lengthIndicators.push_back(evenLi);
253
254 m_headerLength += 1;
255 }
256 }
257
258 return GetSerializedSize();
259}
260
261}; // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
Protocol header serialization and deserialization.
Definition header.h:33
The packet header for the Radio Link Control (RLC) protocol packets.
void Serialize(Buffer::Iterator start) const override
uint8_t m_framingInfo
2 bits
std::list< uint8_t > m_extensionBits
Includes extensionBit of the fixed part.
uint32_t GetSerializedSize() const override
void PushExtensionBit(uint8_t extensionBit)
Push extension bit.
SequenceNumber10 m_sequenceNumber
sequence number
void Print(std::ostream &os) const override
SequenceNumber10 GetSequenceNumber() const
Get sequence number.
uint16_t m_headerLength
header length
void SetSequenceNumber(SequenceNumber10 sequenceNumber)
Set sequence number.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
void SetFramingInfo(uint8_t framingInfo)
Set framing info.
std::list< uint16_t > m_lengthIndicators
length indicators
uint32_t Deserialize(Buffer::Iterator start) override
uint8_t PopExtensionBit()
Pop extension bit.
~LteRlcHeader() override
LteRlcHeader()
Constructor.
uint16_t PopLengthIndicator()
Pop length indicator.
static TypeId GetTypeId()
Get the type ID.
uint8_t GetFramingInfo() const
Get framing info.
void PushLengthIndicator(uint16_t lengthIndicator)
Push length indicator.
SequenceNumber10 class.
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.