PcapPlusPlus  21.05
pcpp::GtpV1Layer Class Reference

#include <GtpLayer.h>

Inheritance diagram for pcpp::GtpV1Layer:
pcpp::Layer pcpp::IDataContainer

Classes

class  GtpExtension
 

Public Member Functions

 GtpV1Layer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 GtpV1Layer (GtpV1MessageType messageType, uint32_t teid)
 
 GtpV1Layer (GtpV1MessageType messageType, uint32_t teid, bool setSeqNum, uint16_t seqNum, bool setNpduNum, uint8_t npduNum)
 
gtpv1_headergetHeader () const
 
bool getSequenceNumber (uint16_t &seqNumber) const
 
bool setSequenceNumber (const uint16_t seqNumber)
 
bool getNpduNumber (uint8_t &npduNum) const
 
bool setNpduNumber (const uint8_t npduNum)
 
bool getNextExtensionHeaderType (uint8_t &nextExtType) const
 
GtpExtension getNextExtension () const
 
GtpExtension addExtension (uint8_t extensionType, uint16_t extensionContent)
 
GtpV1MessageType getMessageType () const
 
std::string getMessageTypeAsString () const
 
bool isGTPUMessage () const
 
bool isGTPCMessage () const
 
void parseNextLayer ()
 
size_t getHeaderLen () const
 
void computeCalculateFields ()
 
std::string toString () const
 
OsiModelLayer getOsiModelLayer () const
 
- Public Member Functions inherited from pcpp::Layer
virtual ~Layer ()
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 
uint8_t * getDataPtr (size_t offset=0) const
 

Static Public Member Functions

static bool isGTPv1 (const uint8_t *data, size_t dataSize)
 
static bool isGTPv1Port (uint16_t port)
 

Detailed Description

A class representing the GTP v1 protocol.

Constructor & Destructor Documentation

◆ GtpV1Layer() [1/3]

pcpp::GtpV1Layer::GtpV1Layer ( uint8_t *  data,
size_t  dataLen,
Layer prevLayer,
Packet packet 
)
inline

A constructor that creates the layer from an existing packet raw data

Parameters
[in]dataA pointer to the raw data
[in]dataLenSize of the data in bytes
[in]prevLayerA pointer to the previous layer
[in]packetA pointer to the Packet instance where layer will be stored in

◆ GtpV1Layer() [2/3]

pcpp::GtpV1Layer::GtpV1Layer ( GtpV1MessageType  messageType,
uint32_t  teid 
)

A constructor that creates a new GTPv1 layer and sets the message type and the TEID value

Parameters
[in]messageTypeThe GTPv1 message type to be set in the newly created layer
[in]teidThe TEID value to be set in the newly created layer

◆ GtpV1Layer() [3/3]

pcpp::GtpV1Layer::GtpV1Layer ( GtpV1MessageType  messageType,
uint32_t  teid,
bool  setSeqNum,
uint16_t  seqNum,
bool  setNpduNum,
uint8_t  npduNum 
)

A constructor that creates a new GTPv1 layer and sets various parameters

Parameters
[in]messageTypeThe GTPv1 message type to be set in the newly created layer
[in]teidThe TEID value to be set in the newly created layer
[in]setSeqNumA flag indicating whether to set a sequence number. If set to "false" then the parameter "seqNum" will be ignored
[in]seqNumThe sequence number to be set in the newly created later. If "setSeqNum" is set to false this parameter will be ignored
[in]setNpduNumA flag indicating whether to set the N-PDU number. If set to "false" then the parameter "npduNum" will be ignored
[in]npduNumThe N-PDU number to be set in the newly created later. If "setNpduNum" is set to false this parameter will be ignored

Member Function Documentation

◆ addExtension()

GtpExtension pcpp::GtpV1Layer::addExtension ( uint8_t  extensionType,
uint16_t  extensionContent 
)

Add a GTPv1 header extension. It is assumed that the extension is 4 bytes in legnth and its content is 2 bytes in length. If you need a different content size please reach out to me. This method takes care of extending the layer to make room for the new extension and also sets the relevant flags and fields

Parameters
[in]extensionTypeThe type of the new extension
[in]extensionContentA 2-byte long content
Returns
An object representing the newly added extension. If there was an error adding the extension a null object will be returned (meaning GtpExtension::isNull() will return "true") and a corresponding error message will be written to log

◆ computeCalculateFields()

void pcpp::GtpV1Layer::computeCalculateFields ( )
virtual

Calculate the following fields:

Implements pcpp::Layer.

◆ getHeader()

gtpv1_header* pcpp::GtpV1Layer::getHeader ( ) const
inline
Returns
The GTP v1 common header structure. Notice this points directly to the data, so every change will change the actual packet data

◆ getHeaderLen()

size_t pcpp::GtpV1Layer::getHeaderLen ( ) const
virtual
Returns
The size of the GTP header. For GTP-C packets the size is determined by the value of gtpv1_header::messageLength and for GTP-U the size only includes the GTP header itself (meaning the size of gtpv1_header plus the size of the optional fields such as sequence number, N-PDU or extensions if exist)

Implements pcpp::Layer.

◆ getMessageType()

GtpV1MessageType pcpp::GtpV1Layer::getMessageType ( ) const
Returns
The message type of this GTP packet

◆ getMessageTypeAsString()

std::string pcpp::GtpV1Layer::getMessageTypeAsString ( ) const
Returns
A string representation of the packet's message type

◆ getNextExtension()

GtpExtension pcpp::GtpV1Layer::getNextExtension ( ) const
Returns
An object that represents the next extension header, if exists in the message. If there are no extensions an empty object is returned, meaning an object which GtpExtension::isNull() returns "true"

◆ getNextExtensionHeaderType()

bool pcpp::GtpV1Layer::getNextExtensionHeaderType ( uint8_t &  nextExtType) const

Get the type of the next header extension if exists on the message (extensions are optional in GTP messages)

Parameters
[out]nextExtTypeSet with the next header extension type if exists in layer. Otherwise remains unchanged
Returns
True if the message contains header extensions, in which case nextExtType is set to the next header extension type. If there are no header extensions false is returned and nextExtType remains unchanged

◆ getNpduNumber()

bool pcpp::GtpV1Layer::getNpduNumber ( uint8_t &  npduNum) const

Get the N-PDU number if exists on the message (N-PDU number is an optional field in GTP messages)

Parameters
[out]npduNumSet with the N-PDU number value if exists in the layer. Otherwise remains unchanged
Returns
True if the N-PDU number field exists in layer, in which case npduNum is set with the value. Or false otherwise

◆ getOsiModelLayer()

OsiModelLayer pcpp::GtpV1Layer::getOsiModelLayer ( ) const
inlinevirtual
Returns
The OSI Model layer this protocol belongs to

Implements pcpp::Layer.

◆ getSequenceNumber()

bool pcpp::GtpV1Layer::getSequenceNumber ( uint16_t &  seqNumber) const

Get the sequence number if exists on the message (sequence number is an optional field in GTP messages)

Parameters
[out]seqNumberSet with the sequence number value if exists in the layer. Otherwise remains unchanged
Returns
True if the sequence number field exists in layer, in which case seqNumber is set with the value. Or false otherwise

◆ isGTPCMessage()

bool pcpp::GtpV1Layer::isGTPCMessage ( ) const
Returns
True if this is a GTP-C message, false otherwise

◆ isGTPUMessage()

bool pcpp::GtpV1Layer::isGTPUMessage ( ) const
Returns
True if this is a GTP-U message, false otherwise

◆ isGTPv1()

static bool pcpp::GtpV1Layer::isGTPv1 ( const uint8_t *  data,
size_t  dataSize 
)
static

A static method that takes a byte array and detects whether it is a GTP v1 message

Parameters
[in]dataA byte array
[in]dataSizeThe byte array size (in bytes)
Returns
True if the data is identified as GTP v1 message (GTP-C or GTP-U)

◆ isGTPv1Port()

static bool pcpp::GtpV1Layer::isGTPv1Port ( uint16_t  port)
inlinestatic

A static method that checks whether the port is considered as GTPv1

Parameters
[in]portThe port number to be checked

◆ parseNextLayer()

void pcpp::GtpV1Layer::parseNextLayer ( )
virtual

Identifies the following next layers for GTP-U packets: IPv4Layer, IPv6Layer. Otherwise sets PayloadLayer

Implements pcpp::Layer.

◆ setNpduNumber()

bool pcpp::GtpV1Layer::setNpduNumber ( const uint8_t  npduNum)

Set an N-PDU number

Parameters
[in]npduNumThe N-PDU number to set
Returns
True if the value was set successfully, false otherwise. In case of failure a corresponding error message will be written to log

◆ setSequenceNumber()

bool pcpp::GtpV1Layer::setSequenceNumber ( const uint16_t  seqNumber)

Set a sequence number

Parameters
[in]seqNumberThe sequence number to set
Returns
True if the value was set successfully, false otherwise. In case of failure a corresponding error message will be written to log

◆ toString()

std::string pcpp::GtpV1Layer::toString ( ) const
virtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.