A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
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
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Jaume Nin <jnin@cttc.cat>
18
*/
19
20
#include "
epc-gtpu-header.h
"
21
22
#include "ns3/log.h"
23
#include "ns3/packet.h"
24
25
namespace
ns3
26
{
27
28
NS_LOG_COMPONENT_DEFINE
(
"GtpuHeader"
);
29
30
/********************************************************
31
* GTP-U-v1 Header
32
********************************************************/
33
34
NS_OBJECT_ENSURE_REGISTERED
(GtpuHeader);
35
36
TypeId
37
GtpuHeader::GetTypeId
()
38
{
39
static
TypeId
tid =
TypeId
(
"ns3::GtpuHeader"
)
40
.
SetParent
<
Header
>()
41
.SetGroupName(
"Lte"
)
42
.AddConstructor<
GtpuHeader
>();
43
return
tid;
44
}
45
46
GtpuHeader::GtpuHeader
()
47
: m_version(1),
48
m_protocolType(true),
49
m_extensionHeaderFlag(false),
50
m_sequenceNumberFlag(true),
51
m_nPduNumberFlag(true),
52
m_messageType(255),
53
m_length(0),
54
m_teid(0),
55
m_sequenceNumber(0),
56
m_nPduNumber(0),
57
m_nextExtensionType(0)
58
{
59
}
60
61
GtpuHeader::~GtpuHeader
()
62
{
63
}
64
65
TypeId
66
GtpuHeader::GetInstanceTypeId
()
const
67
{
68
return
GetTypeId
();
69
}
70
71
uint32_t
72
GtpuHeader::GetSerializedSize
()
const
73
{
74
return
12;
75
}
76
77
void
78
GtpuHeader::Serialize
(
Buffer::Iterator
start
)
const
79
{
80
Buffer::Iterator
i =
start
;
81
uint8_t firstByte =
m_version
<< 5 |
m_protocolType
<< 4 | 0x1 << 3;
82
firstByte |=
m_extensionHeaderFlag
<< 2 |
m_sequenceNumberFlag
<< 1 |
m_nPduNumberFlag
;
83
i.
WriteU8
(firstByte);
84
i.
WriteU8
(
m_messageType
);
85
i.
WriteHtonU16
(
m_length
);
86
i.
WriteHtonU32
(
m_teid
);
87
i.
WriteHtonU16
(
m_sequenceNumber
);
88
i.
WriteU8
(
m_nPduNumber
);
89
i.
WriteU8
(
m_nextExtensionType
);
90
}
91
92
uint32_t
93
GtpuHeader::Deserialize
(
Buffer::Iterator
start
)
94
{
95
Buffer::Iterator
i =
start
;
96
uint8_t firstByte = i.
ReadU8
();
97
m_version
= firstByte >> 5 & 0x7;
98
m_protocolType
= firstByte >> 4 & 0x1;
99
m_extensionHeaderFlag
= firstByte >> 2 & 0x1;
100
m_sequenceNumberFlag
= firstByte >> 1 & 0x1;
101
m_nPduNumberFlag
= firstByte & 0x1;
102
m_messageType
= i.
ReadU8
();
103
m_length
= i.
ReadNtohU16
();
104
m_teid
= i.
ReadNtohU32
();
105
m_sequenceNumber
= i.
ReadNtohU16
();
106
m_nPduNumber
= i.
ReadU8
();
107
m_nextExtensionType
= i.
ReadU8
();
108
return
GetSerializedSize
();
109
}
110
111
void
112
GtpuHeader::Print
(std::ostream& os)
const
113
{
114
os <<
" version="
<< (uint32_t)
m_version
<<
" ["
;
115
if
(
m_protocolType
)
116
{
117
os <<
" PT "
;
118
}
119
if
(
m_extensionHeaderFlag
)
120
{
121
os <<
" E "
;
122
}
123
if
(
m_sequenceNumberFlag
)
124
{
125
os <<
" S "
;
126
}
127
if
(
m_nPduNumberFlag
)
128
{
129
os <<
" PN "
;
130
}
131
os <<
"], messageType="
<< (uint32_t)
m_messageType
<<
", length="
<< (uint32_t)
m_length
;
132
os <<
", teid="
<< (uint32_t)
m_teid
<<
", sequenceNumber="
<< (uint32_t)
m_sequenceNumber
;
133
os <<
", nPduNumber="
<< (uint32_t)
m_nPduNumber
134
<<
", nextExtensionType="
<< (uint32_t)
m_nextExtensionType
;
135
}
136
137
bool
138
GtpuHeader::GetExtensionHeaderFlag
()
const
139
{
140
return
m_extensionHeaderFlag
;
141
}
142
143
uint16_t
144
GtpuHeader::GetLength
()
const
145
{
146
return
m_length
;
147
}
148
149
uint8_t
150
GtpuHeader::GetMessageType
()
const
151
{
152
return
m_messageType
;
153
}
154
155
uint8_t
156
GtpuHeader::GetNPduNumber
()
const
157
{
158
return
m_nPduNumber
;
159
}
160
161
bool
162
GtpuHeader::GetNPduNumberFlag
()
const
163
{
164
return
m_nPduNumberFlag
;
165
}
166
167
uint8_t
168
GtpuHeader::GetNextExtensionType
()
const
169
{
170
return
m_nextExtensionType
;
171
}
172
173
bool
174
GtpuHeader::GetProtocolType
()
const
175
{
176
return
m_protocolType
;
177
}
178
179
uint16_t
180
GtpuHeader::GetSequenceNumber
()
const
181
{
182
return
m_sequenceNumber
;
183
}
184
185
bool
186
GtpuHeader::GetSequenceNumberFlag
()
const
187
{
188
return
m_sequenceNumberFlag
;
189
}
190
191
uint32_t
192
GtpuHeader::GetTeid
()
const
193
{
194
return
m_teid
;
195
}
196
197
uint8_t
198
GtpuHeader::GetVersion
()
const
199
{
200
return
m_version
;
201
}
202
203
void
204
GtpuHeader::SetExtensionHeaderFlag
(
bool
m_extensionHeaderFlag)
205
{
206
this->m_extensionHeaderFlag =
m_extensionHeaderFlag
;
207
}
208
209
void
210
GtpuHeader::SetLength
(uint16_t m_length)
211
{
212
this->m_length =
m_length
;
213
}
214
215
void
216
GtpuHeader::SetMessageType
(uint8_t m_messageType)
217
{
218
this->m_messageType =
m_messageType
;
219
}
220
221
void
222
GtpuHeader::SetNPduNumber
(uint8_t m_nPduNumber)
223
{
224
this->m_nPduNumber =
m_nPduNumber
;
225
}
226
227
void
228
GtpuHeader::SetNPduNumberFlag
(
bool
m_nPduNumberFlag)
229
{
230
this->m_nPduNumberFlag =
m_nPduNumberFlag
;
231
}
232
233
void
234
GtpuHeader::SetNextExtensionType
(uint8_t m_nextExtensionType)
235
{
236
this->m_nextExtensionType =
m_nextExtensionType
;
237
}
238
239
void
240
GtpuHeader::SetProtocolType
(
bool
m_protocolType)
241
{
242
this->m_protocolType =
m_protocolType
;
243
}
244
245
void
246
GtpuHeader::SetSequenceNumber
(uint16_t m_sequenceNumber)
247
{
248
this->m_sequenceNumber =
m_sequenceNumber
;
249
}
250
251
void
252
GtpuHeader::SetSequenceNumberFlag
(
bool
m_sequenceNumberFlag)
253
{
254
this->m_sequenceNumberFlag =
m_sequenceNumberFlag
;
255
}
256
257
void
258
GtpuHeader::SetTeid
(uint32_t m_teid)
259
{
260
this->m_teid =
m_teid
;
261
}
262
263
void
264
GtpuHeader::SetVersion
(uint8_t m_version)
265
{
266
// m_version is a uint3_t
267
this->m_version =
m_version
& 0x7;
268
}
269
270
bool
271
GtpuHeader::operator==
(
const
GtpuHeader
& b)
const
272
{
273
return
m_version
== b.
m_version
&&
m_protocolType
== b.
m_protocolType
&&
274
m_extensionHeaderFlag
== b.
m_extensionHeaderFlag
&&
275
m_sequenceNumberFlag
== b.
m_sequenceNumberFlag
&&
276
m_nPduNumberFlag
== b.
m_nPduNumberFlag
&&
m_messageType
== b.
m_messageType
&&
277
m_length
== b.
m_length
&&
m_teid
== b.
m_teid
&&
m_sequenceNumber
== b.
m_sequenceNumber
&&
278
m_nPduNumber
== b.
m_nPduNumber
&&
m_nextExtensionType
== b.
m_nextExtensionType
;
279
}
280
281
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8()
Definition:
buffer.h:1027
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition:
buffer.h:881
ns3::Buffer::Iterator::WriteHtonU16
void WriteHtonU16(uint16_t data)
Definition:
buffer.h:915
ns3::Buffer::Iterator::ReadNtohU32
uint32_t ReadNtohU32()
Definition:
buffer.h:978
ns3::Buffer::Iterator::WriteHtonU32
void WriteHtonU32(uint32_t data)
Definition:
buffer.h:933
ns3::Buffer::Iterator::ReadNtohU16
uint16_t ReadNtohU16()
Definition:
buffer.h:954
ns3::GtpuHeader
Implementation of the GPRS Tunnelling Protocol header according to GTPv1-U Release 10 as per 3Gpp TS ...
Definition:
epc-gtpu-header.h:40
ns3::GtpuHeader::SetSequenceNumber
void SetSequenceNumber(uint16_t sequenceNumber)
Set sequence number function.
Definition:
epc-gtpu-header.cc:246
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:244
ns3::GtpuHeader::SetExtensionHeaderFlag
void SetExtensionHeaderFlag(bool extensionHeaderFlag)
Set extension header flag function.
Definition:
epc-gtpu-header.cc:204
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:226
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:208
ns3::GtpuHeader::operator==
bool operator==(const GtpuHeader &b) const
Equality operator.
Definition:
epc-gtpu-header.cc:271
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:193
ns3::GtpuHeader::SetTeid
void SetTeid(uint32_t teid)
Set TEID function.
Definition:
epc-gtpu-header.cc:258
ns3::GtpuHeader::~GtpuHeader
~GtpuHeader() override
Definition:
epc-gtpu-header.cc:61
ns3::GtpuHeader::GetExtensionHeaderFlag
bool GetExtensionHeaderFlag() const
Get extension header flag function.
Definition:
epc-gtpu-header.cc:138
ns3::GtpuHeader::SetVersion
void SetVersion(uint8_t version)
Set version function.
Definition:
epc-gtpu-header.cc:264
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:185
ns3::GtpuHeader::m_messageType
uint8_t m_messageType
This field indicates the type of GTP-U message.
Definition:
epc-gtpu-header.h:212
ns3::GtpuHeader::GetVersion
uint8_t GetVersion() const
Get version function.
Definition:
epc-gtpu-header.cc:198
ns3::GtpuHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
epc-gtpu-header.cc:72
ns3::GtpuHeader::GtpuHeader
GtpuHeader()
Definition:
epc-gtpu-header.cc:46
ns3::GtpuHeader::GetSequenceNumberFlag
bool GetSequenceNumberFlag() const
Get sequence number flag function.
Definition:
epc-gtpu-header.cc:186
ns3::GtpuHeader::GetNPduNumberFlag
bool GetNPduNumberFlag() const
Get type of GTP-U message function.
Definition:
epc-gtpu-header.cc:162
ns3::GtpuHeader::SetNPduNumber
void SetNPduNumber(uint8_t nPduNumber)
Set NPDU number function.
Definition:
epc-gtpu-header.cc:222
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:239
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:228
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:232
ns3::GtpuHeader::GetNPduNumber
uint8_t GetNPduNumber() const
Get NPDU number function.
Definition:
epc-gtpu-header.cc:156
ns3::GtpuHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
epc-gtpu-header.cc:66
ns3::GtpuHeader::GetLength
uint16_t GetLength() const
Get length function.
Definition:
epc-gtpu-header.cc:144
ns3::GtpuHeader::Print
void Print(std::ostream &os) const override
Definition:
epc-gtpu-header.cc:112
ns3::GtpuHeader::SetMessageType
void SetMessageType(uint8_t messageType)
Set message type function.
Definition:
epc-gtpu-header.cc:216
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:179
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:219
ns3::GtpuHeader::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
epc-gtpu-header.cc:37
ns3::GtpuHeader::SetSequenceNumberFlag
void SetSequenceNumberFlag(bool sequenceNumberFlag)
Set sequence number flag function.
Definition:
epc-gtpu-header.cc:252
ns3::GtpuHeader::GetSequenceNumber
uint16_t GetSequenceNumber() const
Get protocol type function.
Definition:
epc-gtpu-header.cc:180
ns3::GtpuHeader::GetTeid
uint32_t GetTeid() const
Get a tunnel endpoint identificator (TEID)
Definition:
epc-gtpu-header.cc:192
ns3::GtpuHeader::GetProtocolType
bool GetProtocolType() const
Get protocol type function.
Definition:
epc-gtpu-header.cc:174
ns3::GtpuHeader::SetProtocolType
void SetProtocolType(bool protocolType)
Set protocol type function.
Definition:
epc-gtpu-header.cc:240
ns3::GtpuHeader::GetMessageType
uint8_t GetMessageType() const
Get message type function.
Definition:
epc-gtpu-header.cc:150
ns3::GtpuHeader::GetNextExtensionType
uint8_t GetNextExtensionType() const
Get next extension type function.
Definition:
epc-gtpu-header.cc:168
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:201
ns3::GtpuHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Definition:
epc-gtpu-header.cc:78
ns3::GtpuHeader::SetNextExtensionType
void SetNextExtensionType(uint8_t nextExtensionType)
Set next extension type function.
Definition:
epc-gtpu-header.cc:234
ns3::GtpuHeader::SetLength
void SetLength(uint16_t length)
Set the length in octets of the payload.
Definition:
epc-gtpu-header.cc:210
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:44
ns3::Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:931
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:202
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
two-ray-to-three-gpp-ch-calibration.start
start
Definition:
two-ray-to-three-gpp-ch-calibration.py:520
src
lte
model
epc-gtpu-header.cc
Generated on Sun Mar 3 2024 17:11:01 for ns-3 by
1.9.1