PcapPlusPlus  23.09
GtpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_GTP_LAYER
2 #define PACKETPP_GTP_LAYER
3 
4 #include "Layer.h"
5 
7 
8 
13 namespace pcpp
14 {
15 
16 #pragma pack(push, 1)
17 
21  struct gtpv1_header
22  {
23 #if (BYTE_ORDER == LITTLE_ENDIAN)
24 
25  uint8_t npduNumberFlag:1,
31  reserved:1,
33  protocolType:1,
35  version:3;
36 #else
37 
38  uint8_t version:3,
40  protocolType:1,
42  reserved:1,
49 #endif
50 
51  uint8_t messageType;
52 
54  uint16_t messageLength;
55 
57  uint32_t teid;
58  };
59 
60 #pragma pack(pop)
61 
67  {
206  };
207 
208 
213  class GtpV1Layer : public Layer
214  {
215  private:
216  struct gtpv1_header_extra
217  {
218  uint16_t sequenceNumber;
219  uint8_t npduNumber;
220  uint8_t nextExtensionHeader;
221  };
222 
223  gtpv1_header_extra* getHeaderExtra() const;
224 
225  void init(GtpV1MessageType messageType, uint32_t teid, bool setSeqNum, uint16_t seqNum, bool setNpduNum, uint8_t npduNum);
226 
227  public:
228 
234  {
235  friend class GtpV1Layer;
236 
237  private:
238  uint8_t* m_Data;
239  size_t m_DataLen;
240  uint8_t m_ExtType;
241 
242  GtpExtension(uint8_t* data, size_t dataLen, uint8_t type);
243 
244  void setNextHeaderType(uint8_t nextHeaderType);
245 
246  static GtpExtension createGtpExtension(uint8_t* data, size_t dataLen, uint8_t extType, uint16_t content);
247 
248  public:
249 
253  GtpExtension();
254 
259  GtpExtension(const GtpExtension& other);
260 
266  GtpExtension& operator=(const GtpExtension& other);
267 
272  bool isNull() const;
273 
277  uint8_t getExtensionType() const;
278 
283  size_t getTotalLength() const;
284 
289  size_t getContentLength() const;
290 
295  uint8_t* getContent() const;
296 
301  uint8_t getNextExtensionHeaderType() const;
302 
308  GtpExtension getNextExtension() const;
309  }; // GtpExtension
310 
311  virtual ~GtpV1Layer() {}
312 
319  GtpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = GTPv1; }
320 
326  GtpV1Layer(GtpV1MessageType messageType, uint32_t teid);
327 
337  GtpV1Layer(GtpV1MessageType messageType, uint32_t teid, bool setSeqNum, uint16_t seqNum, bool setNpduNum, uint8_t npduNum);
338 
345  static bool isGTPv1(const uint8_t* data, size_t dataSize);
346 
350  gtpv1_header* getHeader() const { return (gtpv1_header*)m_Data; }
351 
358  bool getSequenceNumber(uint16_t& seqNumber) const;
359 
365  bool setSequenceNumber(const uint16_t seqNumber);
366 
373  bool getNpduNumber(uint8_t& npduNum) const;
374 
380  bool setNpduNumber(const uint8_t npduNum);
381 
388  bool getNextExtensionHeaderType(uint8_t& nextExtType) const;
389 
394  GtpExtension getNextExtension() const;
395 
405  GtpExtension addExtension(uint8_t extensionType, uint16_t extensionContent);
406 
410  GtpV1MessageType getMessageType() const;
411 
415  std::string getMessageTypeAsString() const;
416 
420  bool isGTPUMessage() const;
421 
425  bool isGTPCMessage() const;
426 
432  static bool isGTPv1Port(uint16_t port) { return port == 2152 /* GTP-U */ || port == 2123 /* GTP-C */; }
433 
434 
435  // implement abstract methods
436 
440  void parseNextLayer();
441 
448  size_t getHeaderLen() const;
449 
454  void computeCalculateFields();
455 
456  std::string toString() const;
457 
459  };
460 }
461 
462 #endif //PACKETPP_GTP_LAYER
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
Definition: GtpLayer.h:153
Definition: GtpLayer.h:79
Definition: GtpLayer.h:111
OsiModelLayer getOsiModelLayer() const
Definition: GtpLayer.h:458
Definition: GtpLayer.h:91
uint32_t teid
Definition: GtpLayer.h:57
Definition: GtpLayer.h:135
Definition: GtpLayer.h:89
Definition: GtpLayer.h:117
Definition: GtpLayer.h:141
Definition: GtpLayer.h:73
Definition: GtpLayer.h:69
Definition: GtpLayer.h:201
Definition: GtpLayer.h:197
Definition: GtpLayer.h:149
Definition: Layer.h:70
Definition: GtpLayer.h:93
Definition: GtpLayer.h:137
Definition: GtpLayer.h:127
Definition: Packet.h:26
Definition: GtpLayer.h:193
Definition: GtpLayer.h:85
Definition: GtpLayer.h:183
Definition: GtpLayer.h:155
uint8_t protocolType
Definition: GtpLayer.h:25
Definition: GtpLayer.h:199
GtpV1Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: GtpLayer.h:319
Definition: GtpLayer.h:75
Definition: GtpLayer.h:187
Definition: GtpLayer.h:175
Definition: GtpLayer.h:203
Definition: GtpLayer.h:123
Definition: GtpLayer.h:81
Definition: GtpLayer.h:99
Definition: GtpLayer.h:103
const ProtocolType GTPv1
Definition: ProtocolType.h:213
Definition: GtpLayer.h:151
GtpV1MessageType
Definition: GtpLayer.h:66
Definition: GtpLayer.h:189
uint8_t sequenceNumberFlag
Definition: GtpLayer.h:25
Definition: GtpLayer.h:205
Definition: GtpLayer.h:115
static bool isGTPv1Port(uint16_t port)
Definition: GtpLayer.h:432
Definition: ProtocolType.h:342
Definition: GtpLayer.h:213
Definition: GtpLayer.h:185
uint16_t messageLength
Definition: GtpLayer.h:54
Definition: GtpLayer.h:179
Definition: GtpLayer.h:181
Definition: GtpLayer.h:101
Definition: GtpLayer.h:119
Definition: GtpLayer.h:139
Definition: GtpLayer.h:157
Definition: GtpLayer.h:77
Definition: GtpLayer.h:195
Definition: GtpLayer.h:87
Definition: GtpLayer.h:21
Definition: GtpLayer.h:83
gtpv1_header * getHeader() const
Definition: GtpLayer.h:350
uint8_t messageType
Definition: GtpLayer.h:51
Definition: GtpLayer.h:129
Definition: GtpLayer.h:113
Definition: GtpLayer.h:125
uint8_t version
Definition: GtpLayer.h:25
Definition: GtpLayer.h:177
Definition: GtpLayer.h:121
uint8_t reserved
Definition: GtpLayer.h:25
Definition: GtpLayer.h:133
Definition: GtpLayer.h:71
uint8_t extensionHeaderFlag
Definition: GtpLayer.h:25
Definition: GtpLayer.h:131
uint8_t npduNumberFlag
Definition: GtpLayer.h:25
Definition: GtpLayer.h:191
Definition: GtpLayer.h:143
Definition: GtpLayer.h:233