A Discrete-Event Network Simulator
API
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
25namespace ns3 {
26
27NS_LOG_COMPONENT_DEFINE ("GtpuHeader");
28
29/********************************************************
30 * GTP-U-v1 Header
31 ********************************************************/
32
34
35TypeId
37{
38 static TypeId tid = TypeId ("ns3::GtpuHeader")
39 .SetParent<Header> ()
40 .SetGroupName("Lte")
41 .AddConstructor<GtpuHeader> ();
42 return tid;
43}
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
61{
62}
63
66{
67 return GetTypeId ();
68}
69
72{
73 return 12;
74}
75void
77{
79 uint8_t firstByte = m_version << 5 | m_protocolType << 4 | 0x1 << 3;
81 i.WriteU8 (firstByte);
88
89}
92{
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 ();
104 m_nPduNumber = i.ReadU8 ();
106 return GetSerializedSize ();
107}
108void
109GtpuHeader::Print (std::ostream &os) const
110{
111 os << " version=" << (uint32_t) m_version << " [";
112 if (m_protocolType)
113 {
114 os << " PT ";
115 }
117 {
118 os << " E ";
119 }
121 {
122 os << " S ";
123 }
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
133bool
135{
137}
138
139uint16_t
141{
142 return m_length;
143}
144
145uint8_t
147{
148 return m_messageType;
149}
150
151uint8_t
153{
154 return m_nPduNumber;
155}
156
157bool
159{
160 return m_nPduNumberFlag;
161}
162
163uint8_t
165{
166 return m_nextExtensionType;
167}
168
169bool
171{
172 return m_protocolType;
173}
174
175uint16_t
177{
178 return m_sequenceNumber;
179}
180
181bool
183{
185}
186
189{
190 return m_teid;
191}
192
193uint8_t
195{
196 return m_version;
197}
198
199void
200GtpuHeader::SetExtensionHeaderFlag (bool m_extensionHeaderFlag)
201{
202 this->m_extensionHeaderFlag = m_extensionHeaderFlag;
203}
204
205void
206GtpuHeader::SetLength (uint16_t m_length)
207{
208 this->m_length = m_length;
209}
210
211void
212GtpuHeader::SetMessageType (uint8_t m_messageType)
213{
214 this->m_messageType = m_messageType;
215}
216
217void
218GtpuHeader::SetNPduNumber (uint8_t m_nPduNumber)
219{
220 this->m_nPduNumber = m_nPduNumber;
221}
222
223void
224GtpuHeader::SetNPduNumberFlag (bool m_nPduNumberFlag)
225{
226 this->m_nPduNumberFlag = m_nPduNumberFlag;
227}
228
229void
230GtpuHeader::SetNextExtensionType (uint8_t m_nextExtensionType)
231{
232 this->m_nextExtensionType = m_nextExtensionType;
233}
234
235void
236GtpuHeader::SetProtocolType (bool m_protocolType)
237{
238 this->m_protocolType = m_protocolType;
239}
240
241void
242GtpuHeader::SetSequenceNumber (uint16_t m_sequenceNumber)
243{
244 this->m_sequenceNumber = m_sequenceNumber;
245}
246
247void
248GtpuHeader::SetSequenceNumberFlag (bool m_sequenceNumberFlag)
249{
250 this->m_sequenceNumberFlag = m_sequenceNumberFlag;
251}
252
253void
255{
256 this->m_teid = m_teid;
257}
258
259void
260GtpuHeader::SetVersion (uint8_t m_version)
261{
262 // m_version is a uint3_t
263 this->m_version = m_version & 0x7;
264}
265
266bool
268{
269 if (m_version == b.m_version
275 && m_length == b.m_length
276 && m_teid == b.m_teid
280 )
281 {
282 return true;
283 }
284 return false;
285}
286
287} // namespace ns3
288
iterator in a Buffer instance
Definition: buffer.h:99
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
void WriteHtonU32(uint32_t data)
Definition: buffer.h:924
uint32_t ReadNtohU32(void)
Definition: buffer.h:970
Implementation of the GPRS Tunnelling Protocol header according to GTPv1-U Release 10 as per 3Gpp TS ...
virtual ~GtpuHeader()
void SetSequenceNumber(uint16_t sequenceNumber)
Set sequence number function.
uint8_t m_nextExtensionType
This field defines the type of Extension Header that follows this field in the GTP-PDU.
void SetExtensionHeaderFlag(bool extensionHeaderFlag)
Set extension header flag function.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_teid
This field unambiguously identifies a tunnel endpoint in the receiving GTP-U protocol entity.
bool m_nPduNumberFlag
This flag indicates the presence of a meaningful value of the N-PDU Number field.
bool operator==(const GtpuHeader &b) const
Equality operator.
bool m_extensionHeaderFlag
This flag indicates the presence of a meaningful value of the Next Extension Header field.
virtual void Print(std::ostream &os) const
void SetTeid(uint32_t teid)
Set TEID function.
bool GetExtensionHeaderFlag() const
Get extension header flag function.
void SetVersion(uint8_t version)
Set version function.
bool m_protocolType
This bit is used as a protocol discriminator between GTP (when PT is '1') and GTP' (when PT is '0').
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
uint8_t m_messageType
This field indicates the type of GTP-U message.
virtual uint32_t Deserialize(Buffer::Iterator start)
uint8_t GetVersion() const
Get version function.
bool GetSequenceNumberFlag() const
Get sequence number flag function.
bool GetNPduNumberFlag() const
Get type of GTP-U message function.
virtual uint32_t GetSerializedSize(void) const
void SetNPduNumber(uint8_t nPduNumber)
Set NPDU number function.
uint8_t m_nPduNumber
This field is used at the Inter SGSN Routeing Area Update procedure and some inter-system handover pr...
void SetNPduNumberFlag(bool nPduNumberFlag)
Sets the flag that indicates the presence of a meaningful value of the N-PDU Number field.
uint16_t m_sequenceNumber
If Sequence Number field is used for G-PDUs (T-PDUs+headers), an increasing sequence number for T-PDU...
uint8_t GetNPduNumber() const
Get NPDU number function.
uint16_t GetLength() const
Get length function.
void SetMessageType(uint8_t messageType)
Set message type function.
uint8_t m_version
This field is used to determine the version of the GTPU-U protocol.
uint16_t m_length
This field indicates the length in octets of the payload, i.e.
void SetSequenceNumberFlag(bool sequenceNumberFlag)
Set sequence number flag function.
virtual void Serialize(Buffer::Iterator start) const
uint16_t GetSequenceNumber() const
Get protocol type function.
uint32_t GetTeid() const
Get a tunnel endpoint identificator (TEID)
bool GetProtocolType() const
Get protocol type function.
void SetProtocolType(bool protocolType)
Set protocol type function.
uint8_t GetMessageType() const
Get message type function.
uint8_t GetNextExtensionType() const
Get next extension type function.
bool m_sequenceNumberFlag
This flag indicates the presence of a meaningful value of the Sequence Number field.
void SetNextExtensionType(uint8_t nextExtensionType)
Set next extension type function.
void SetLength(uint16_t length)
Set the length in octets of the payload.
Protocol header serialization and deserialization.
Definition: header.h:43
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1852