PcapPlusPlus  Next
pcpp::GtpV2Layer Class Reference

#include <GtpLayer.h>

Inheritance diagram for pcpp::GtpV2Layer:
pcpp::Layer pcpp::IDataContainer

Public Member Functions

 GtpV2Layer (uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
 
 GtpV2Layer (GtpV2MessageType messageType, uint32_t sequenceNumber, bool setTeid=false, uint32_t teid=0, bool setMessagePriority=false, std::bitset< 4 > messagePriority=0)
 
GtpV2MessageType getMessageType () const
 
void setMessageType (const GtpV2MessageType &type)
 
uint16_t getMessageLength () const
 
bool isPiggybacking () const
 
std::pair< bool, uint32_t > getTeid () const
 
void setTeid (uint32_t teid)
 
void unsetTeid ()
 
uint32_t getSequenceNumber () const
 
void setSequenceNumber (uint32_t sequenceNumber)
 
std::pair< bool, uint8_t > getMessagePriority () const
 
void setMessagePriority (const std::bitset< 4 > &messagePriority)
 
void unsetMessagePriority ()
 
GtpV2InformationElement getFirstInformationElement () const
 
GtpV2InformationElement getNextInformationElement (GtpV2InformationElement infoElement) const
 
GtpV2InformationElement getInformationElement (GtpV2InformationElement::Type infoElementType) const
 
size_t getInformationElementCount () const
 
GtpV2InformationElement addInformationElement (const GtpV2InformationElementBuilder &infoElementBuilder)
 
GtpV2InformationElement addInformationElementAfter (const GtpV2InformationElementBuilder &infoElementBuilder, GtpV2InformationElement::Type infoElementType)
 
bool removeInformationElement (GtpV2InformationElement::Type infoElementType)
 
bool removeAllInformationElements ()
 
void parseNextLayer () override
 
size_t getHeaderLen () const override
 
void computeCalculateFields () override
 
std::string toString () const override
 
OsiModelLayer getOsiModelLayer () const override
 
- Public Member Functions inherited from pcpp::Layer
 ~Layer () override
 
LayergetNextLayer () const
 
LayergetPrevLayer () const
 
ProtocolType getProtocol () const
 
bool isMemberOfProtocolFamily (ProtocolTypeFamily protocolTypeFamily) 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 override
 

Static Public Member Functions

static bool isGTPv2Port (uint16_t port)
 
static bool isDataValid (const uint8_t *data, size_t dataSize)
 

Detailed Description

A class representing the GTPv2 defined in 3GPP TS 29.274

Constructor & Destructor Documentation

◆ GtpV2Layer() [1/2]

pcpp::GtpV2Layer::GtpV2Layer ( 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

◆ GtpV2Layer() [2/2]

pcpp::GtpV2Layer::GtpV2Layer ( GtpV2MessageType  messageType,
uint32_t  sequenceNumber,
bool  setTeid = false,
uint32_t  teid = 0,
bool  setMessagePriority = false,
std::bitset< 4 >  messagePriority = 0 
)

A constructor that creates a new GTPv2 message

Parameters
messageTypeGTPv2 message type
sequenceNumberMessage sequence number
setTeidWhether or not to set Tunnel Endpoint Identifier in this message
teidTunnel Endpoint Identifier value. Only used if setTeid is set to true
setMessagePriorityWhether or not to set Message Priority in this message
messagePriorityMessage Priority. Only used if setMessagePriority to true

Member Function Documentation

◆ addInformationElement()

GtpV2InformationElement pcpp::GtpV2Layer::addInformationElement ( const GtpV2InformationElementBuilder infoElementBuilder)

Add a new Information Element (IE) at the end of the layer

Parameters
[in]infoElementBuilderA GtpV2InformationElementBuilder object that contains the requested IE data to add
Returns
A GtpV2InformationElement object containing the newly added IE data or logical null (GtpV2InformationElement::isNull() == true) if addition failed

◆ addInformationElementAfter()

GtpV2InformationElement pcpp::GtpV2Layer::addInformationElementAfter ( const GtpV2InformationElementBuilder infoElementBuilder,
GtpV2InformationElement::Type  infoElementType 
)

Add a new Information Element (IE) after an existing one

Parameters
[in]infoElementBuilderA GtpV2InformationElementBuilder object that contains the requested IE data to add
[in]infoElementTypeThe IE type which the newly added option will come after
Returns
A GtpV2InformationElement object containing the newly added IE data or logical null (GtpV2InformationElement::isNull() == true) if addition failed

◆ computeCalculateFields()

void pcpp::GtpV2Layer::computeCalculateFields ( )
overridevirtual

Computes the piggybacking flag by checking if the next layer is also a GTPv2 message

Implements pcpp::Layer.

◆ getFirstInformationElement()

GtpV2InformationElement pcpp::GtpV2Layer::getFirstInformationElement ( ) const
Returns
The first GTPv2 Information Element (IE). If there are no IEs the returned value will contain a logical null (GtpV2InformationElement::isNull() == true)

◆ getHeaderLen()

size_t pcpp::GtpV2Layer::getHeaderLen ( ) const
overridevirtual
Returns
The size of the GTPv2 header including its Information Elements (IE)

Implements pcpp::Layer.

◆ getInformationElement()

GtpV2InformationElement pcpp::GtpV2Layer::getInformationElement ( GtpV2InformationElement::Type  infoElementType) const

Get a GTPv2 Information Element (IE) by type

Parameters
[in]infoElementTypeGTPv2 Information Element (IE) type
Returns
A GtpV2InformationElement object containing the first IE that matches this type, or logical null (GtpV2InformationElement::isNull() == true) if no such IE found

◆ getInformationElementCount()

size_t pcpp::GtpV2Layer::getInformationElementCount ( ) const
Returns
The number of GTPv2 Information Elements (IEs) in this layer

◆ getMessageLength()

uint16_t pcpp::GtpV2Layer::getMessageLength ( ) const
Returns
The message length as set in the layer. Note it is different from getHeaderLen() because the later refers to the entire layers length, and this property excludes the mandatory part of the GTP-C header (the first 4 octets)

◆ getMessagePriority()

std::pair<bool, uint8_t> pcpp::GtpV2Layer::getMessagePriority ( ) const

Get the Message Property if exists

Returns
A pair of 2 values; the first value states whether Message Priority exists, and if it's true the second value contains the Message Priority value

◆ getMessageType()

GtpV2MessageType pcpp::GtpV2Layer::getMessageType ( ) const
Returns
The message type

◆ getNextInformationElement()

GtpV2InformationElement pcpp::GtpV2Layer::getNextInformationElement ( GtpV2InformationElement  infoElement) const

Get the GTPv2 Information Element (IE) that comes after a given IE. If the given IE was the last one, the returned value will contain a logical null (GtpV2InformationElement::isNull() == true)

Parameters
[in]infoElementA given GTPv2 Information Element
Returns
A GtpV2InformationElement object containing the IE that comes next, or logical null if the given IE: (1) is the last one; (2) contains a logical null or (3) doesn't belong to this packet

◆ getOsiModelLayer()

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

Implements pcpp::Layer.

◆ getSequenceNumber()

uint32_t pcpp::GtpV2Layer::getSequenceNumber ( ) const
Returns
The sequence number

◆ getTeid()

std::pair<bool, uint32_t> pcpp::GtpV2Layer::getTeid ( ) const

Get the Tunnel Endpoint Identifier (TEID) if exists

Returns
A pair of 2 values; the first value states whether TEID exists, and if it's true the second value contains the TEID value

◆ isDataValid()

static bool pcpp::GtpV2Layer::isDataValid ( const uint8_t *  data,
size_t  dataSize 
)
static

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

Parameters
[in]dataA byte array
[in]dataSizeThe byte array size (in bytes)
Returns
True if the data is identified as GTPv2 message

◆ isGTPv2Port()

static bool pcpp::GtpV2Layer::isGTPv2Port ( uint16_t  port)
inlinestatic

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

Parameters
[in]portThe port number to be checked
Returns
True if the port matches those associated with the GTPv2 protocol

◆ isPiggybacking()

bool pcpp::GtpV2Layer::isPiggybacking ( ) const
Returns
True if there is another GTPv2 message piggybacking on this message (will appear as another GtpV2Layer after this layer)

◆ parseNextLayer()

void pcpp::GtpV2Layer::parseNextLayer ( )
overridevirtual

Identifies if the next layer is GTPv2 piggyback. Otherwise sets PayloadLayer

Implements pcpp::Layer.

◆ removeAllInformationElements()

bool pcpp::GtpV2Layer::removeAllInformationElements ( )

Remove all Information Elements (IE) in this layer

Returns
True if all IEs were successfully removed or false if removal failed for some reason

◆ removeInformationElement()

bool pcpp::GtpV2Layer::removeInformationElement ( GtpV2InformationElement::Type  infoElementType)

Remove an existing Information Element (IE) from the layer

Parameters
[in]infoElementTypeThe IE type to remove
Returns
True if the IE was successfully removed or false if type wasn't found or if removal failed

◆ setMessagePriority()

void pcpp::GtpV2Layer::setMessagePriority ( const std::bitset< 4 > &  messagePriority)

Set Message Priority

Parameters
messagePriorityThe Message Priority value to set

◆ setMessageType()

void pcpp::GtpV2Layer::setMessageType ( const GtpV2MessageType type)

Set message type

Parameters
typeThe message type to set

◆ setSequenceNumber()

void pcpp::GtpV2Layer::setSequenceNumber ( uint32_t  sequenceNumber)

Set the sequence number

Parameters
sequenceNumberThe sequence number value to set

◆ setTeid()

void pcpp::GtpV2Layer::setTeid ( uint32_t  teid)

Set Tunnel Endpoint Identifier (TEID)

Parameters
teidThe TEID value to set

◆ toString()

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

Implements pcpp::Layer.

◆ unsetMessagePriority()

void pcpp::GtpV2Layer::unsetMessagePriority ( )

Unset Message Priority if exists in the layer (otherwise does nothing)

◆ unsetTeid()

void pcpp::GtpV2Layer::unsetTeid ( )

Unset Tunnel Endpoint Identifier (TEID) if exists in the layer (otherwise does nothing)