GTP

The system provides the Python object alc.gtp2c, an instance of alc.gtp2c, to inspect and modify GTPv2 control packets.

Note

For GTP-2c messages, only the pre-provided alc.gtp2c object should be used in scripts; the alc.gtp2c class should not be used directly.

The alc.gtp2c class

Instance Attributes

The GTP-2c header fields are exposed as instance attributes on the object.

Attributes defined on alc.gtp2c

Attribute

Field

Access

Type

version

GTP version field

ro

int

pbit

Piggyback flag

ro

int

tbit

Flag marking if there is a TEID present.

ro

int

type

Type of the GTP message

ro

int

len

Length of the GTP message

ro

int

teid

Tunnel Endpoint Identifier. None if not present

ro

int

seq

Sequence number

ro

int

Methods

drop()

Drops the packet.

getIEList()

Returns a list of IE types that are present in the packet.

  • If there are multiple instances of the same IE, the IE type appears multiple times in the list.

get(type, instance, /)

Returns all values of the IEs with the specified type. The values are returned as the exact bytestrings as they appear in the packet.

  • If the specified option does not exist, the result is an empty tuple: ()

  • If a specific instance has zero length or no values, the corresponding bytestring is an empty bytestring: b””

Parameters
  • type (int) – IE type

  • instance (int) – IE instance

Return type

tuple of bytestrings

set(type, instance, value, /)

Deletes existing IEs with the specified type and instance and inserts new IEs with the specified type, instance, and value. Multiple values can be specified in a tuple, in which case an option is added for each item in the tuple.

Parameters
  • type (int) – IE type

  • instance (int) – IE instance

  • value (bytes|tuple(bytes)) – value of the option; the length is determined automatically from this value

clear(type, instance, /)

Removes all IEs with the specified type.

Parameters
  • type (int) – IE type

  • instance (int) – IE instance

decode_grouped_ie(value)

Decodes the byte representation of a grouped IE to a tuple of IEs.

Defined as a static method.

Parameters

value (bytes) – grouped IE value

Returns

returns a tuple where each element represents an IE. Each IE is represented as a tuple (type, instance, value) with types (int, int, bytes).

encode_grouped_ie(value)

Encodes a tuple of IEs into the byte representation of a grouped IE.

Defined as a static method.

Parameters

value (tuple) – tuple of IEs where each IE is represented as a (type, instance, value) tuple.

Returns

byte representation of the grouped IE

get_pco()

Returns the PCO IE (78) as a alc.Pco object.

The returned object can be modified in-place and is reflected in the resulting GTP packet.

Returns

A alc.Pco object

set_pco(pco)

Accepts a alc.Pco object, encodes it, and uses this as the value for the PCO IE.

Parameters

pco (alc.pco) – alc.Pco object

The alc.Pco class

class alc.Pco(bytes, /)

Creates a new object representing a PCO IE.

Parameters

bytes (bytes) – the bytes representation of the PCO IE.

Instance Attributes

Attributes defined on alc.Pco objects

Attribute

Field

Access

Type

proto

Protocol field

ro

int

length

Length of the embedded protocol

ro

int

Methods

get_container(id, /)

Retrieves the content of all containers with the specified ID.

Parameters

id (int) – ID of the container

Return type

list(bytes)

set_container(id, container, /)

Deletes existing containers of the specified ID and inserts new containers. Multiple containers can be specified in a tuple, in which case a container is added for each entry in the tuple.

Containers of type PAP, CHAP, IPCP, or LCP cannot be modified with this method. See set_pap() and set_chap().

Parameters
  • id (int) – ID of the container

  • container (bytes or tuple(bytes)) – content of the container

clear_container(id, /)

Removes all containers with the specified ID.

Parameters

id (int) – ID of the container

get_pap()

Returns the PAP container as a alc.Pap object.

set_pap(pap, /)

Replaces the existing PAP container with a new one. Multiple PAP objects can be specified in a tuple.

Parameters

pap (alc.Pap or tuple(alc.Pap)) – PAP object

clear_pap()

Removes all PAP containers.

get_chap()

Returns the CHAP container as a alc.Chap object.

set_chap(chap, /)

Replaces the existing CHAP container with a new one. Multiple CHAP objects can be specified in a tuple.

Parameters

chap (alc.Chap or tuple(alc.Chap)) – CHAP object

clear_chap()

Removes all CHAP containers.