A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("GtpuHeader");
26 
27 namespace ns3 {
28 
29 /********************************************************
30  * GTP-U-v1 Header
31  ********************************************************/
32 
33 NS_OBJECT_ENSURE_REGISTERED (GtpuHeader)
34  ;
35 
36 TypeId
38 {
39  static TypeId tid =
40  TypeId ("ns3::GtpuHeader")
41  .SetParent<Header> ()
42  .AddConstructor<GtpuHeader> ();
43  return tid;
44 }
46  : m_version (1),
47  m_protocolType (true),
48  m_extensionHeaderFlag (false),
49  m_sequenceNumberFlag (true),
50  m_nPduNumberFlag (true),
51  m_messageType (255),
52  m_length (0),
53  m_teid (0),
54  m_sequenceNumber (0),
55  m_nPduNumber (0),
56  m_nextExtensionType (0)
57 {
58 
59 }
60 
62 {
63 }
64 
65 TypeId
67 {
68  return GetTypeId ();
69 }
70 
71 uint32_t
73 {
74  return 12;
75 }
76 void
78 {
80  uint8_t firstByte = m_version << 5 | m_protocolType << 4 | 0x1 << 3;
82  i.WriteU8 (firstByte);
85  i.WriteHtonU32 (m_teid);
89 
90 }
91 uint32_t
93 {
95  uint8_t firstByte = i.ReadU8 ();
96  m_version = firstByte >> 5 & 0x7;
97  m_protocolType = firstByte >> 4 & 0x1;
98  m_extensionHeaderFlag = firstByte >> 2 & 0x1;
99  m_sequenceNumberFlag = firstByte >> 1 & 0x1;
100  m_nPduNumberFlag = firstByte & 0x1;
101  m_messageType = i.ReadU8 ();
102  m_length = i.ReadNtohU16 ();
103  m_teid = i.ReadNtohU32 ();
105  m_nPduNumber = i.ReadU8 ();
107  return GetSerializedSize ();
108 }
109 void
110 GtpuHeader::Print (std::ostream &os) const
111 {
112  os << " version=" << (uint32_t) m_version << " [";
113  if (m_protocolType)
114  {
115  os << " PT ";
116  }
118  {
119  os << " E ";
120  }
122  {
123  os << " S ";
124  }
125  if (m_nPduNumberFlag)
126  {
127  os << " PN ";
128  }
129  os << "], messageType=" << (uint32_t) m_messageType << ", length=" << (uint32_t) m_length;
130  os << ", teid=" << (uint32_t) m_teid << ", sequenceNumber=" << (uint32_t) m_sequenceNumber;
131  os << ", nPduNumber=" << (uint32_t) m_nPduNumber << ", nextExtensionType=" << (uint32_t) m_nextExtensionType;
132 }
133 
134 bool
136 {
137  return m_extensionHeaderFlag;
138 }
139 
140 uint16_t
142 {
143  return m_length;
144 }
145 
146 uint8_t
148 {
149  return m_messageType;
150 }
151 
152 uint8_t
154 {
155  return m_nPduNumber;
156 }
157 
158 bool
160 {
161  return m_nPduNumberFlag;
162 }
163 
164 uint8_t
166 {
167  return m_nextExtensionType;
168 }
169 
170 bool
172 {
173  return m_protocolType;
174 }
175 
176 uint16_t
178 {
179  return m_sequenceNumber;
180 }
181 
182 bool
184 {
185  return m_sequenceNumberFlag;
186 }
187 
188 uint32_t
190 {
191  return m_teid;
192 }
193 
194 uint8_t
196 {
197  return m_version;
198 }
199 
200 void
201 GtpuHeader::SetExtensionHeaderFlag (bool m_extensionHeaderFlag)
202 {
203  this->m_extensionHeaderFlag = m_extensionHeaderFlag;
204 }
205 
206 void
207 GtpuHeader::SetLength (uint16_t m_length)
208 {
209  this->m_length = m_length;
210 }
211 
212 void
213 GtpuHeader::SetMessageType (uint8_t m_messageType)
214 {
215  this->m_messageType = m_messageType;
216 }
217 
218 void
219 GtpuHeader::SetNPduNumber (uint8_t m_nPduNumber)
220 {
221  this->m_nPduNumber = m_nPduNumber;
222 }
223 
224 void
225 GtpuHeader::SetNPduNumberFlag (bool m_nPduNumberFlag)
226 {
227  this->m_nPduNumberFlag = m_nPduNumberFlag;
228 }
229 
230 void
231 GtpuHeader::SetNextExtensionType (uint8_t m_nextExtensionType)
232 {
233  this->m_nextExtensionType = m_nextExtensionType;
234 }
235 
236 void
237 GtpuHeader::SetProtocolType (bool m_protocolType)
238 {
239  this->m_protocolType = m_protocolType;
240 }
241 
242 void
243 GtpuHeader::SetSequenceNumber (uint16_t m_sequenceNumber)
244 {
245  this->m_sequenceNumber = m_sequenceNumber;
246 }
247 
248 void
249 GtpuHeader::SetSequenceNumberFlag (bool m_sequenceNumberFlag)
250 {
251  this->m_sequenceNumberFlag = m_sequenceNumberFlag;
252 }
253 
254 void
255 GtpuHeader::SetTeid (uint32_t m_teid)
256 {
257  this->m_teid = m_teid;
258 }
259 
260 void
261 GtpuHeader::SetVersion (uint8_t m_version)
262 {
263  // m_version is a uint3_t
264  this->m_version = m_version & 0x7;
265 }
266 
267 bool
269 {
270  if (m_version == b.m_version
276  && m_length == b.m_length
277  && m_teid == b.m_teid
279  && m_nPduNumber == b.m_nPduNumber
281  )
282  {
283  return true;
284  }
285  return false;
286 }
287 
288 } // namespace ns3
289 
Protocol header serialization and deserialization.
Definition: header.h:42
uint16_t GetSequenceNumber() const
bool m_nPduNumberFlag
This flag indicates the presence of a meaningful value of the N-PDU Number field. ...
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual void Serialize(Buffer::Iterator start) const
uint8_t m_nPduNumber
This field is used at the Inter SGSN Routeing Area Update procedure and some inter-system handover pr...
uint8_t GetMessageType() const
void SetVersion(uint8_t m_version)
uint32_t ReadNtohU32(void)
Definition: buffer.h:791
bool m_protocolType
This bit is used as a protocol discriminator between GTP (when PT is '1') and GTP' (when PT is '0')...
iterator in a Buffer instance
Definition: buffer.h:98
NS_LOG_COMPONENT_DEFINE("GtpuHeader")
virtual uint32_t GetSerializedSize(void) const
uint8_t m_messageType
This field indicates the type of GTP-U message.
void SetNPduNumber(uint8_t m_nPduNumber)
void SetExtensionHeaderFlag(bool m_extensionHeaderFlag)
void WriteHtonU16(uint16_t data)
Definition: buffer.h:726
bool GetNPduNumberFlag() const
virtual void Print(std::ostream &os) const
void SetProtocolType(bool m_protocolType)
uint16_t m_sequenceNumber
If Sequence Number field is used for G-PDUs (T-PDUs+headers), an increasing sequence number for T-PDU...
bool m_extensionHeaderFlag
This flag indicates the presence of a meaningful value of the Next Extension Header field...
uint8_t m_version
This field is used to determine the version of the GTPU-U protocol.
bool GetProtocolType() const
uint8_t m_nextExtensionType
This field defines the type of Extension Header that follows this field in the GTP-PDU.
void SetNPduNumberFlag(bool m_nPduNumberFlag)
bool GetExtensionHeaderFlag() const
bool GetSequenceNumberFlag() const
virtual ~GtpuHeader()
uint8_t GetVersion() const
void SetMessageType(uint8_t m_messageType)
void SetTeid(uint32_t m_teid)
bool m_sequenceNumberFlag
This flag indicates the presence of a meaningful value of the Sequence Number field.
uint32_t GetTeid() const
uint16_t m_length
This field indicates the length in octets of the payload, i.e.
void WriteHtonU32(uint32_t data)
Definition: buffer.h:745
static TypeId GetTypeId(void)
bool operator==(const GtpuHeader &b) const
void SetSequenceNumberFlag(bool m_sequenceNumberFlag)
virtual TypeId GetInstanceTypeId(void) const
void WriteU8(uint8_t data)
Definition: buffer.h:690
uint8_t GetNPduNumber() const
uint8_t GetNextExtensionType() const
void SetSequenceNumber(uint16_t m_sequenceNumber)
void SetLength(uint16_t m_length)
uint8_t ReadU8(void)
Definition: buffer.h:819
uint16_t GetLength() const
void SetNextExtensionType(uint8_t m_nextExtensionType)
uint16_t ReadNtohU16(void)
Definition: buffer.h:767
virtual uint32_t Deserialize(Buffer::Iterator start)
uint32_t m_teid
This field unambiguously identifies a tunnel endpoint in the receiving GTP-U protocol entity...
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
Implementation of the GTPv1-U Release 10 as per 3Gpp TS 29.281 document.