A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
13
namespace
ns3
14
{
15
16
NS_LOG_COMPONENT_DEFINE
(
"LteRlcHeader"
);
17
18
NS_OBJECT_ENSURE_REGISTERED
(LteRlcHeader);
19
20
LteRlcHeader::LteRlcHeader
()
21
: m_headerLength(0),
22
m_framingInfo(0xff),
23
m_sequenceNumber(0xfffa)
24
{
25
}
26
27
LteRlcHeader::~LteRlcHeader
()
28
{
29
m_headerLength
= 0;
30
m_framingInfo
= 0xff;
31
m_sequenceNumber
= 0xfffb;
32
}
33
34
void
35
LteRlcHeader::SetFramingInfo
(uint8_t framingInfo)
36
{
37
m_framingInfo
= framingInfo & 0x03;
38
}
39
40
void
41
LteRlcHeader::SetSequenceNumber
(
SequenceNumber10
sequenceNumber)
42
{
43
m_sequenceNumber
= sequenceNumber;
44
}
45
46
uint8_t
47
LteRlcHeader::GetFramingInfo
()
const
48
{
49
return
m_framingInfo
;
50
}
51
52
SequenceNumber10
53
LteRlcHeader::GetSequenceNumber
()
const
54
{
55
return
m_sequenceNumber
;
56
}
57
58
void
59
LteRlcHeader::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
76
void
77
LteRlcHeader::PushLengthIndicator
(uint16_t lengthIndicator)
78
{
79
m_lengthIndicators
.push_back(lengthIndicator);
80
}
81
82
uint8_t
83
LteRlcHeader::PopExtensionBit
()
84
{
85
uint8_t extensionBit =
m_extensionBits
.front();
86
m_extensionBits
.pop_front();
87
88
return
extensionBit;
89
}
90
91
uint16_t
92
LteRlcHeader::PopLengthIndicator
()
93
{
94
uint16_t lengthIndicator =
m_lengthIndicators
.front();
95
m_lengthIndicators
.pop_front();
96
97
return
lengthIndicator;
98
}
99
100
TypeId
101
LteRlcHeader::GetTypeId
()
102
{
103
static
TypeId
tid =
TypeId
(
"ns3::LteRlcHeader"
)
104
.
SetParent
<
Header
>()
105
.SetGroupName(
"Lte"
)
106
.AddConstructor<
LteRlcHeader
>();
107
return
tid;
108
}
109
110
TypeId
111
LteRlcHeader::GetInstanceTypeId
()
const
112
{
113
return
GetTypeId
();
114
}
115
116
void
117
LteRlcHeader::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
149
uint32_t
150
LteRlcHeader::GetSerializedSize
()
const
151
{
152
return
m_headerLength
;
153
}
154
155
void
156
LteRlcHeader::Serialize
(
Buffer::Iterator
start)
const
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
201
uint32_t
202
LteRlcHeader::Deserialize
(
Buffer::Iterator
start)
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
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8()
Definition
buffer.h:1016
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition
buffer.h:870
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
ns3::LteRlcHeader
The packet header for the Radio Link Control (RLC) protocol packets.
Definition
lte-rlc-header.h:30
ns3::LteRlcHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
lte-rlc-header.cc:156
ns3::LteRlcHeader::m_framingInfo
uint8_t m_framingInfo
2 bits
Definition
lte-rlc-header.h:121
ns3::LteRlcHeader::m_extensionBits
std::list< uint8_t > m_extensionBits
Includes extensionBit of the fixed part.
Definition
lte-rlc-header.h:124
ns3::LteRlcHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
lte-rlc-header.cc:150
ns3::LteRlcHeader::PushExtensionBit
void PushExtensionBit(uint8_t extensionBit)
Push extension bit.
Definition
lte-rlc-header.cc:59
ns3::LteRlcHeader::m_sequenceNumber
SequenceNumber10 m_sequenceNumber
sequence number
Definition
lte-rlc-header.h:122
ns3::LteRlcHeader::Print
void Print(std::ostream &os) const override
Definition
lte-rlc-header.cc:117
ns3::LteRlcHeader::DATA_FIELD_FOLLOWS
@ DATA_FIELD_FOLLOWS
Definition
lte-rlc-header.h:95
ns3::LteRlcHeader::E_LI_FIELDS_FOLLOWS
@ E_LI_FIELDS_FOLLOWS
Definition
lte-rlc-header.h:96
ns3::LteRlcHeader::GetSequenceNumber
SequenceNumber10 GetSequenceNumber() const
Get sequence number.
Definition
lte-rlc-header.cc:53
ns3::LteRlcHeader::m_headerLength
uint16_t m_headerLength
header length
Definition
lte-rlc-header.h:120
ns3::LteRlcHeader::SetSequenceNumber
void SetSequenceNumber(SequenceNumber10 sequenceNumber)
Set sequence number.
Definition
lte-rlc-header.cc:41
ns3::LteRlcHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
lte-rlc-header.cc:111
ns3::LteRlcHeader::SetFramingInfo
void SetFramingInfo(uint8_t framingInfo)
Set framing info.
Definition
lte-rlc-header.cc:35
ns3::LteRlcHeader::m_lengthIndicators
std::list< uint16_t > m_lengthIndicators
length indicators
Definition
lte-rlc-header.h:125
ns3::LteRlcHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
lte-rlc-header.cc:202
ns3::LteRlcHeader::PopExtensionBit
uint8_t PopExtensionBit()
Pop extension bit.
Definition
lte-rlc-header.cc:83
ns3::LteRlcHeader::~LteRlcHeader
~LteRlcHeader() override
Definition
lte-rlc-header.cc:27
ns3::LteRlcHeader::LteRlcHeader
LteRlcHeader()
Constructor.
Definition
lte-rlc-header.cc:20
ns3::LteRlcHeader::PopLengthIndicator
uint16_t PopLengthIndicator()
Pop length indicator.
Definition
lte-rlc-header.cc:92
ns3::LteRlcHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
lte-rlc-header.cc:101
ns3::LteRlcHeader::GetFramingInfo
uint8_t GetFramingInfo() const
Get framing info.
Definition
lte-rlc-header.cc:47
ns3::LteRlcHeader::PushLengthIndicator
void PushLengthIndicator(uint16_t lengthIndicator)
Push length indicator.
Definition
lte-rlc-header.cc:77
ns3::SequenceNumber10
SequenceNumber10 class.
Definition
lte-rlc-sequence-number.h:23
ns3::SequenceNumber10::GetValue
uint16_t GetValue() const
Extracts the numeric value of the sequence number.
Definition
lte-rlc-sequence-number.h:69
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
lte-rlc-header.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lte
model
lte-rlc-header.cc
Generated on Sat Oct 5 2024 19:40:43 for ns-3 by
1.11.0