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