PcapPlusPlus  20.08+
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 
258  GtpExtension(const GtpExtension& other);
259 
263  GtpExtension& operator=(const GtpExtension& other);
264 
269  bool isNull() const;
270 
274  uint8_t getExtensionType() const;
275 
280  size_t getTotalLength() const;
281 
286  size_t getContentLength() const;
287 
292  uint8_t* getContent() const;
293 
298  uint8_t getNextExtensionHeaderType() const;
299 
305  GtpExtension getNextExtension() const;
306  }; // GtpExtension
307 
308  virtual ~GtpV1Layer() {}
309 
316  GtpV1Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = GTPv1; }
317 
323  GtpV1Layer(GtpV1MessageType messageType, uint32_t teid);
324 
334  GtpV1Layer(GtpV1MessageType messageType, uint32_t teid, bool setSeqNum, uint16_t seqNum, bool setNpduNum, uint8_t npduNum);
335 
342  static bool isGTPv1(const uint8_t* data, size_t dataSize);
343 
347  gtpv1_header* getHeader() const { return (gtpv1_header*)m_Data; }
348 
355  bool getSequenceNumber(uint16_t& seqNumber) const;
356 
362  bool setSequenceNumber(const uint16_t seqNumber);
363 
370  bool getNpduNumber(uint8_t& npduNum) const;
371 
377  bool setNpduNumber(const uint8_t npduNum);
378 
385  bool getNextExtensionHeaderType(uint8_t& nextExtType) const;
386 
391  GtpExtension getNextExtension() const;
392 
402  GtpExtension addExtension(uint8_t extensionType, uint16_t extensionContent);
403 
407  GtpV1MessageType getMessageType() const;
408 
412  std::string getMessageTypeAsString() const;
413 
417  bool isGTPUMessage() const;
418 
422  bool isGTPCMessage() const;
423 
428  static bool isGTPv1Port(uint16_t port) { return port == 2152 /* GTP-U */ || port == 2123 /* GTP-C */; }
429 
430 
431  // implement abstract methods
432 
436  void parseNextLayer();
437 
444  size_t getHeaderLen() const;
445 
450  void computeCalculateFields();
451 
452  std::string toString() const;
453 
455  };
456 }
457 
458 #endif //PACKETPP_GTP_LAYER
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:233
Definition: GtpLayer.h:153
Definition: GtpLayer.h:79
Definition: GtpLayer.h:111
OsiModelLayer getOsiModelLayer() const
Definition: GtpLayer.h:454
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:316
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:428
Definition: ProtocolType.h:242
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:347
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