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
epc-gtpu-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: Jaume Nin <jnin@cttc.cat>
7
*/
8
9
#include "
epc-gtpu-header.h
"
10
11
#include "ns3/log.h"
12
#include "ns3/packet.h"
13
14
namespace
ns3
15
{
16
17
NS_LOG_COMPONENT_DEFINE
(
"GtpuHeader"
);
18
19
/********************************************************
20
* GTP-U-v1 Header
21
********************************************************/
22
23
NS_OBJECT_ENSURE_REGISTERED
(GtpuHeader);
24
25
TypeId
26
GtpuHeader::GetTypeId
()
27
{
28
static
TypeId
tid =
TypeId
(
"ns3::GtpuHeader"
)
29
.
SetParent
<
Header
>()
30
.SetGroupName(
"Lte"
)
31
.AddConstructor<
GtpuHeader
>();
32
return
tid;
33
}
34
35
GtpuHeader::GtpuHeader
()
36
: m_version(1),
37
m_protocolType(true),
38
m_extensionHeaderFlag(false),
39
m_sequenceNumberFlag(true),
40
m_nPduNumberFlag(true),
41
m_messageType(255),
42
m_length(0),
43
m_teid(0),
44
m_sequenceNumber(0),
45
m_nPduNumber(0),
46
m_nextExtensionType(0)
47
{
48
}
49
50
GtpuHeader::~GtpuHeader
()
51
{
52
}
53
54
TypeId
55
GtpuHeader::GetInstanceTypeId
()
const
56
{
57
return
GetTypeId
();
58
}
59
60
uint32_t
61
GtpuHeader::GetSerializedSize
()
const
62
{
63
return
12;
64
}
65
66
void
67
GtpuHeader::Serialize
(
Buffer::Iterator
start)
const
68
{
69
Buffer::Iterator
i = start;
70
uint8_t firstByte =
m_version
<< 5 |
m_protocolType
<< 4 | 0x1 << 3;
71
firstByte |=
m_extensionHeaderFlag
<< 2 |
m_sequenceNumberFlag
<< 1 |
m_nPduNumberFlag
;
72
i.
WriteU8
(firstByte);
73
i.
WriteU8
(
m_messageType
);
74
i.
WriteHtonU16
(
m_length
);
75
i.
WriteHtonU32
(
m_teid
);
76
i.
WriteHtonU16
(
m_sequenceNumber
);
77
i.
WriteU8
(
m_nPduNumber
);
78
i.
WriteU8
(
m_nextExtensionType
);
79
}
80
81
uint32_t
82
GtpuHeader::Deserialize
(
Buffer::Iterator
start)
83
{
84
Buffer::Iterator
i = start;
85
uint8_t firstByte = i.
ReadU8
();
86
m_version
= firstByte >> 5 & 0x7;
87
m_protocolType
= firstByte >> 4 & 0x1;
88
m_extensionHeaderFlag
= firstByte >> 2 & 0x1;
89
m_sequenceNumberFlag
= firstByte >> 1 & 0x1;
90
m_nPduNumberFlag
= firstByte & 0x1;
91
m_messageType
= i.
ReadU8
();
92
m_length
= i.
ReadNtohU16
();
93
m_teid
= i.
ReadNtohU32
();
94
m_sequenceNumber
= i.
ReadNtohU16
();
95
m_nPduNumber
= i.
ReadU8
();
96
m_nextExtensionType
= i.
ReadU8
();
97
return
GetSerializedSize
();
98
}
99
100
void
101
GtpuHeader::Print
(std::ostream& os)
const
102
{
103
os <<
" version="
<< (
uint32_t
)
m_version
<<
" ["
;
104
if
(
m_protocolType
)
105
{
106
os <<
" PT "
;
107
}
108
if
(
m_extensionHeaderFlag
)
109
{
110
os <<
" E "
;
111
}
112
if
(
m_sequenceNumberFlag
)
113
{
114
os <<
" S "
;
115
}
116
if
(
m_nPduNumberFlag
)
117
{
118
os <<
" PN "
;
119
}
120
os <<
"], messageType="
<< (
uint32_t
)
m_messageType
<<
", length="
<< (
uint32_t
)
m_length
;
121
os <<
", teid="
<< (
uint32_t
)
m_teid
<<
", sequenceNumber="
<< (
uint32_t
)
m_sequenceNumber
;
122
os <<
", nPduNumber="
<< (
uint32_t
)
m_nPduNumber
123
<<
", nextExtensionType="
<< (
uint32_t
)
m_nextExtensionType
;
124
}
125
126
bool
127
GtpuHeader::GetExtensionHeaderFlag
()
const
128
{
129
return
m_extensionHeaderFlag
;
130
}
131
132
uint16_t
133
GtpuHeader::GetLength
()
const
134
{
135
return
m_length
;
136
}
137
138
uint8_t
139
GtpuHeader::GetMessageType
()
const
140
{
141
return
m_messageType
;
142
}
143
144
uint8_t
145
GtpuHeader::GetNPduNumber
()
const
146
{
147
return
m_nPduNumber
;
148
}
149
150
bool
151
GtpuHeader::GetNPduNumberFlag
()
const
152
{
153
return
m_nPduNumberFlag
;
154
}
155
156
uint8_t
157
GtpuHeader::GetNextExtensionType
()
const
158
{
159
return
m_nextExtensionType
;
160
}
161
162
bool
163
GtpuHeader::GetProtocolType
()
const
164
{
165
return
m_protocolType
;
166
}
167
168
uint16_t
169
GtpuHeader::GetSequenceNumber
()
const
170
{
171
return
m_sequenceNumber
;
172
}
173
174
bool
175
GtpuHeader::GetSequenceNumberFlag
()
const
176
{
177
return
m_sequenceNumberFlag
;
178
}
179
180
uint32_t
181
GtpuHeader::GetTeid
()
const
182
{
183
return
m_teid
;
184
}
185
186
uint8_t
187
GtpuHeader::GetVersion
()
const
188
{
189
return
m_version
;
190
}
191
192
void
193
GtpuHeader::SetExtensionHeaderFlag
(
bool
m_extensionHeaderFlag)
194
{
195
this->m_extensionHeaderFlag =
m_extensionHeaderFlag
;
196
}
197
198
void
199
GtpuHeader::SetLength
(uint16_t m_length)
200
{
201
this->m_length =
m_length
;
202
}
203
204
void
205
GtpuHeader::SetMessageType
(uint8_t m_messageType)
206
{
207
this->m_messageType =
m_messageType
;
208
}
209
210
void
211
GtpuHeader::SetNPduNumber
(uint8_t m_nPduNumber)
212
{
213
this->m_nPduNumber =
m_nPduNumber
;
214
}
215
216
void
217
GtpuHeader::SetNPduNumberFlag
(
bool
m_nPduNumberFlag)
218
{
219
this->m_nPduNumberFlag =
m_nPduNumberFlag
;
220
}
221
222
void
223
GtpuHeader::SetNextExtensionType
(uint8_t m_nextExtensionType)
224
{
225
this->m_nextExtensionType =
m_nextExtensionType
;
226
}
227
228
void
229
GtpuHeader::SetProtocolType
(
bool
m_protocolType)
230
{
231
this->m_protocolType =
m_protocolType
;
232
}
233
234
void
235
GtpuHeader::SetSequenceNumber
(uint16_t m_sequenceNumber)
236
{
237
this->m_sequenceNumber =
m_sequenceNumber
;
238
}
239
240
void
241
GtpuHeader::SetSequenceNumberFlag
(
bool
m_sequenceNumberFlag)
242
{
243
this->m_sequenceNumberFlag =
m_sequenceNumberFlag
;
244
}
245
246
void
247
GtpuHeader::SetTeid
(
uint32_t
m_teid)
248
{
249
this->m_teid =
m_teid
;
250
}
251
252
void
253
GtpuHeader::SetVersion
(uint8_t m_version)
254
{
255
// m_version is a uint3_t
256
this->m_version =
m_version
& 0x7;
257
}
258
259
bool
260
GtpuHeader::operator==
(
const
GtpuHeader
& b)
const
261
{
262
return
m_version
== b.
m_version
&&
m_protocolType
== b.
m_protocolType
&&
263
m_extensionHeaderFlag
== b.
m_extensionHeaderFlag
&&
264
m_sequenceNumberFlag
== b.
m_sequenceNumberFlag
&&
265
m_nPduNumberFlag
== b.
m_nPduNumberFlag
&&
m_messageType
== b.
m_messageType
&&
266
m_length
== b.
m_length
&&
m_teid
== b.
m_teid
&&
m_sequenceNumber
== b.
m_sequenceNumber
&&
267
m_nPduNumber
== b.
m_nPduNumber
&&
m_nextExtensionType
== b.
m_nextExtensionType
;
268
}
269
270
}
// 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::Buffer::Iterator::WriteHtonU16
void WriteHtonU16(uint16_t data)
Definition
buffer.h:904
ns3::Buffer::Iterator::ReadNtohU32
uint32_t ReadNtohU32()
Definition
buffer.h:967
ns3::Buffer::Iterator::WriteHtonU32
void WriteHtonU32(uint32_t data)
Definition
buffer.h:922
ns3::Buffer::Iterator::ReadNtohU16
uint16_t ReadNtohU16()
Definition
buffer.h:943
ns3::GtpuHeader
Implementation of the GPRS Tunnelling Protocol header according to GTPv1-U Release 10 as per 3Gpp TS ...
Definition
epc-gtpu-header.h:29
ns3::GtpuHeader::SetSequenceNumber
void SetSequenceNumber(uint16_t sequenceNumber)
Set sequence number function.
Definition
epc-gtpu-header.cc:235
ns3::GtpuHeader::m_nextExtensionType
uint8_t m_nextExtensionType
This field defines the type of Extension Header that follows this field in the GTP-PDU.
Definition
epc-gtpu-header.h:233
ns3::GtpuHeader::SetExtensionHeaderFlag
void SetExtensionHeaderFlag(bool extensionHeaderFlag)
Set extension header flag function.
Definition
epc-gtpu-header.cc:193
ns3::GtpuHeader::m_teid
uint32_t m_teid
This field unambiguously identifies a tunnel endpoint in the receiving GTP-U protocol entity.
Definition
epc-gtpu-header.h:215
ns3::GtpuHeader::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Definition
epc-gtpu-header.cc:82
ns3::GtpuHeader::m_nPduNumberFlag
bool m_nPduNumberFlag
This flag indicates the presence of a meaningful value of the N-PDU Number field.
Definition
epc-gtpu-header.h:197
ns3::GtpuHeader::operator==
bool operator==(const GtpuHeader &b) const
Equality operator.
Definition
epc-gtpu-header.cc:260
ns3::GtpuHeader::m_extensionHeaderFlag
bool m_extensionHeaderFlag
This flag indicates the presence of a meaningful value of the Next Extension Header field.
Definition
epc-gtpu-header.h:182
ns3::GtpuHeader::SetTeid
void SetTeid(uint32_t teid)
Set TEID function.
Definition
epc-gtpu-header.cc:247
ns3::GtpuHeader::~GtpuHeader
~GtpuHeader() override
Definition
epc-gtpu-header.cc:50
ns3::GtpuHeader::GetExtensionHeaderFlag
bool GetExtensionHeaderFlag() const
Get extension header flag function.
Definition
epc-gtpu-header.cc:127
ns3::GtpuHeader::SetVersion
void SetVersion(uint8_t version)
Set version function.
Definition
epc-gtpu-header.cc:253
ns3::GtpuHeader::m_protocolType
bool m_protocolType
This bit is used as a protocol discriminator between GTP (when PT is '1') and GTP' (when PT is '0').
Definition
epc-gtpu-header.h:174
ns3::GtpuHeader::m_messageType
uint8_t m_messageType
This field indicates the type of GTP-U message.
Definition
epc-gtpu-header.h:201
ns3::GtpuHeader::GetVersion
uint8_t GetVersion() const
Get version function.
Definition
epc-gtpu-header.cc:187
ns3::GtpuHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition
epc-gtpu-header.cc:61
ns3::GtpuHeader::GtpuHeader
GtpuHeader()
Definition
epc-gtpu-header.cc:35
ns3::GtpuHeader::GetSequenceNumberFlag
bool GetSequenceNumberFlag() const
Get sequence number flag function.
Definition
epc-gtpu-header.cc:175
ns3::GtpuHeader::GetNPduNumberFlag
bool GetNPduNumberFlag() const
Get type of GTP-U message function.
Definition
epc-gtpu-header.cc:151
ns3::GtpuHeader::SetNPduNumber
void SetNPduNumber(uint8_t nPduNumber)
Set NPDU number function.
Definition
epc-gtpu-header.cc:211
ns3::GtpuHeader::m_nPduNumber
uint8_t m_nPduNumber
This field is used at the Inter SGSN Routeing Area Update procedure and some inter-system handover pr...
Definition
epc-gtpu-header.h:228
ns3::GtpuHeader::SetNPduNumberFlag
void SetNPduNumberFlag(bool nPduNumberFlag)
Sets the flag that indicates the presence of a meaningful value of the N-PDU Number field.
Definition
epc-gtpu-header.cc:217
ns3::GtpuHeader::m_sequenceNumber
uint16_t m_sequenceNumber
If Sequence Number field is used for G-PDUs (T-PDUs+headers), an increasing sequence number for T-PDU...
Definition
epc-gtpu-header.h:221
ns3::GtpuHeader::GetNPduNumber
uint8_t GetNPduNumber() const
Get NPDU number function.
Definition
epc-gtpu-header.cc:145
ns3::GtpuHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition
epc-gtpu-header.cc:55
ns3::GtpuHeader::GetLength
uint16_t GetLength() const
Get length function.
Definition
epc-gtpu-header.cc:133
ns3::GtpuHeader::Print
void Print(std::ostream &os) const override
Definition
epc-gtpu-header.cc:101
ns3::GtpuHeader::SetMessageType
void SetMessageType(uint8_t messageType)
Set message type function.
Definition
epc-gtpu-header.cc:205
ns3::GtpuHeader::m_version
uint8_t m_version
This field is used to determine the version of the GTPU-U protocol.
Definition
epc-gtpu-header.h:168
ns3::GtpuHeader::m_length
uint16_t m_length
This field indicates the length in octets of the payload, i.e.
Definition
epc-gtpu-header.h:208
ns3::GtpuHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
epc-gtpu-header.cc:26
ns3::GtpuHeader::SetSequenceNumberFlag
void SetSequenceNumberFlag(bool sequenceNumberFlag)
Set sequence number flag function.
Definition
epc-gtpu-header.cc:241
ns3::GtpuHeader::GetSequenceNumber
uint16_t GetSequenceNumber() const
Get protocol type function.
Definition
epc-gtpu-header.cc:169
ns3::GtpuHeader::GetTeid
uint32_t GetTeid() const
Get a tunnel endpoint identificator (TEID)
Definition
epc-gtpu-header.cc:181
ns3::GtpuHeader::GetProtocolType
bool GetProtocolType() const
Get protocol type function.
Definition
epc-gtpu-header.cc:163
ns3::GtpuHeader::SetProtocolType
void SetProtocolType(bool protocolType)
Set protocol type function.
Definition
epc-gtpu-header.cc:229
ns3::GtpuHeader::GetMessageType
uint8_t GetMessageType() const
Get message type function.
Definition
epc-gtpu-header.cc:139
ns3::GtpuHeader::GetNextExtensionType
uint8_t GetNextExtensionType() const
Get next extension type function.
Definition
epc-gtpu-header.cc:157
ns3::GtpuHeader::m_sequenceNumberFlag
bool m_sequenceNumberFlag
This flag indicates the presence of a meaningful value of the Sequence Number field.
Definition
epc-gtpu-header.h:190
ns3::GtpuHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition
epc-gtpu-header.cc:67
ns3::GtpuHeader::SetNextExtensionType
void SetNextExtensionType(uint8_t nextExtensionType)
Set next extension type function.
Definition
epc-gtpu-header.cc:223
ns3::GtpuHeader::SetLength
void SetLength(uint16_t length)
Set the length in octets of the payload.
Definition
epc-gtpu-header.cc:199
ns3::Header
Protocol header serialization and deserialization.
Definition
header.h:33
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
epc-gtpu-header.h
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
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lte
model
epc-gtpu-header.cc
Generated on Fri Nov 8 2024 13:59:02 for ns-3 by
1.11.0