A Discrete-Event Network Simulator
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
14namespace ns3
15{
16
17NS_LOG_COMPONENT_DEFINE("GtpuHeader");
18
19/********************************************************
20 * GTP-U-v1 Header
21 ********************************************************/
22
24
25TypeId
27{
28 static TypeId tid = TypeId("ns3::GtpuHeader")
30 .SetGroupName("Lte")
31 .AddConstructor<GtpuHeader>();
32 return tid;
33}
34
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
53
56{
57 return GetTypeId();
58}
59
62{
63 return 12;
64}
65
66void
68{
69 Buffer::Iterator i = start;
70 uint8_t firstByte = m_version << 5 | m_protocolType << 4 | 0x1 << 3;
72 i.WriteU8(firstByte);
79}
80
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;
93 m_teid = i.ReadNtohU32();
95 m_nPduNumber = i.ReadU8();
97 return GetSerializedSize();
98}
99
100void
101GtpuHeader::Print(std::ostream& os) const
102{
103 os << " version=" << (uint32_t)m_version << " [";
104 if (m_protocolType)
105 {
106 os << " PT ";
107 }
109 {
110 os << " E ";
111 }
113 {
114 os << " S ";
115 }
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
126bool
131
132uint16_t
134{
135 return m_length;
136}
137
138uint8_t
140{
141 return m_messageType;
142}
143
144uint8_t
146{
147 return m_nPduNumber;
148}
149
150bool
155
156uint8_t
161
162bool
164{
165 return m_protocolType;
166}
167
168uint16_t
173
174bool
179
182{
183 return m_teid;
184}
185
186uint8_t
188{
189 return m_version;
190}
191
192void
193GtpuHeader::SetExtensionHeaderFlag(bool m_extensionHeaderFlag)
194{
195 this->m_extensionHeaderFlag = m_extensionHeaderFlag;
196}
197
198void
199GtpuHeader::SetLength(uint16_t m_length)
200{
201 this->m_length = m_length;
202}
203
204void
205GtpuHeader::SetMessageType(uint8_t m_messageType)
206{
207 this->m_messageType = m_messageType;
208}
209
210void
211GtpuHeader::SetNPduNumber(uint8_t m_nPduNumber)
212{
213 this->m_nPduNumber = m_nPduNumber;
214}
215
216void
217GtpuHeader::SetNPduNumberFlag(bool m_nPduNumberFlag)
218{
219 this->m_nPduNumberFlag = m_nPduNumberFlag;
220}
221
222void
223GtpuHeader::SetNextExtensionType(uint8_t m_nextExtensionType)
224{
225 this->m_nextExtensionType = m_nextExtensionType;
226}
227
228void
229GtpuHeader::SetProtocolType(bool m_protocolType)
230{
231 this->m_protocolType = m_protocolType;
232}
233
234void
235GtpuHeader::SetSequenceNumber(uint16_t m_sequenceNumber)
236{
237 this->m_sequenceNumber = m_sequenceNumber;
238}
239
240void
241GtpuHeader::SetSequenceNumberFlag(bool m_sequenceNumberFlag)
242{
243 this->m_sequenceNumberFlag = m_sequenceNumberFlag;
244}
245
246void
248{
249 this->m_teid = m_teid;
250}
251
252void
253GtpuHeader::SetVersion(uint8_t m_version)
254{
255 // m_version is a uint3_t
256 this->m_version = m_version & 0x7;
257}
258
259bool
269
270} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void WriteHtonU16(uint16_t data)
Definition buffer.h:904
uint32_t ReadNtohU32()
Definition buffer.h:967
void WriteHtonU32(uint32_t data)
Definition buffer.h:922
uint16_t ReadNtohU16()
Definition buffer.h:943
Implementation of the GPRS Tunnelling Protocol header according to GTPv1-U Release 10 as per 3Gpp TS ...
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.
uint32_t m_teid
This field unambiguously identifies a tunnel endpoint in the receiving GTP-U protocol entity.
uint32_t Deserialize(Buffer::Iterator start) override
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.
void SetTeid(uint32_t teid)
Set TEID function.
~GtpuHeader() override
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').
uint8_t m_messageType
This field indicates the type of GTP-U message.
uint8_t GetVersion() const
Get version function.
uint32_t GetSerializedSize() const override
bool GetSequenceNumberFlag() const
Get sequence number flag function.
bool GetNPduNumberFlag() const
Get type of GTP-U message function.
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.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
uint16_t GetLength() const
Get length function.
void Print(std::ostream &os) const override
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.
static TypeId GetTypeId()
Get the type ID.
void SetSequenceNumberFlag(bool sequenceNumberFlag)
Set sequence number flag function.
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 Serialize(Buffer::Iterator start) const override
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:33
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.