The system provides a Python object for input GTPv2-C packet: alc.gtp2c.
Shown in Table: GTPv2-C API , the alc.gtp2c packet has following attributes to represent the GTPv2-C header fields:
Class attributes | GTPv2-C header field | Access |
---|---|---|
alc.gtp2c.version |
Integer version field in the header |
Read |
alc.gtp2c.pbit |
boolean, true mean 1, false means 0; P bit in the header |
Read |
alc.gtp2c.tbit |
boolean, T bit in the header |
Read |
alc.gtp2c.type |
Integer message type field in the header |
Read |
alc.gtp2c.len |
Integer message length field in the header |
Read |
alc.gtp2c.teid |
Unsigned integer, or None if TEID does not exist |
Read |
alc.gtp2c.seq |
Integer sequence number in the header |
Read |
The following is a list of alc.gtp2c functions:
alc.gtp2c.drop()
The system drops the resulting packet.
alc.gtp2c.getIEList()
The system returns a tuple of 2-element tuple (ie-type, ie-instance). Each 2-element tuple represent one IE instance in the packet. For example: a packet with the following IEs:
type:2, instance: 1
type:2, instance: 1
type:74, instance: 0
The system returns ((2,1),(2,1),(74,0))
alc.gtp2c.get(ie_type, instance_id)
The system returns a tuple of str. Each str is the IE data of specified (ie-type, instance-id). If the IE is a grouped IE, then the str is also the content of whole grouped IE. If the specified (ie_type, instance_id) does not exist, then return (); if the IE length=0, then return ‟” for this IE instance.
alc.gtp2c.set(ie_type, instance_id, ie_tuple)
This function removes all instances of (ie_type, instance_id) and inserts a list of new IE instances. Each element in an ie_tuple is a string, represent one instance of IE to be inserted. For each inserted IE instance, the type is ie_type, the instance is instance_id.
alc.gtp2c.clear(ie_type, instance_id)
This function removes all existing instances of (ie_type, instance-id).
alc.gtp2c.str_to_groupedIE (parent_ie_str)
Parses the parent_ie_str and return a tuple of embedded IEs. Parent_ie_str is a string of data field of parent IE; each element of returned tuple is a tuple of (ie_type, ie_instance, ie_data), which represent one embedded IE. For example, with the following code:
ie_str = alc.gtp2c.get(93,0)[0]
ie_tuple = alc.gtp2c.str_to_groupedIE(ie_str)
The above code parses the first instance of the bearer context with an instance=0. Assume the bearer context looks like that shown in Figure: Bearer context example:
Then, the ie_tuple is
((5,0,’\x05’),(87,5’\x9f\xfe\x50\x02\x25\x0a\xbe\xac\xfe’),(80,0,’\x04\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00’))
An exception is raised if the system cannot parse the parent_ie_str into a ie_tuple.
alc.gtp2c.groupedIE_to_str(grouped_ie_tuple)
Converts the grouped_ie_tuple into a str and return the str (see the description of alc.gtp2c.str_to_groupedIE for the format grouped_ie_tuple). An exception is raised if the conversion fails. The following is an example:
With the previous example packet, the code changes the instance of the embedded F-TEID to 0.
Be aware that the alc.gtp2c.str_to_groupedIE (parent_ie_str) and alc.gtp2c.groupedIE_to_str(grouped_ie_tuple) do not check whether the input parameter is a grouped IE. The user should verify that the input parameter is a grouped IE before using these two functions.