Skip to main content

Module codec

Module codec 

Source
Expand description

GTP codec — GTPv1-C/GTPv1-U (3GPP TS 29.060) and GTPv2-C (3GPP TS 29.274).

Pure: no I/O, no state, no LLM. mod.rs owns the sockets and actions.rs owns the model’s vocabulary; everything that turns bytes into structure and back lives here so the literal-byte tests in tests/server/gtp/codec_test.rs can pin it without a running server.

§The two rules this file exists to get right

  1. The GTPv1 E/S/PN flags are all-or-nothing. If any of the extension-header, sequence-number or N-PDU-number flags is set, all four optional octets are present (2 sequence, 1 N-PDU, 1 next-extension-header) and each field is only meaningful when its own flag is set. Implementations routinely assume only the flagged field appears, which desynchronises every subsequent byte. See GtpV1Header::optional_present.
  2. GTPv1 information elements below type 128 are fixed-length (TV), 128 and above are variable-length (TLV) with a two-octet length. A decoder that assumes TLV throughout misreads a Cause IE as a length prefix. See v1_fixed_ie_len.

GTPv2-C has neither problem: its header length is decided by one flag (T) and every IE is TLIV. It is implemented here because both versions share UDP 2123 and a node has to tell them apart from the first three bits anyway.

Structs§

CauseName
A cause the model can name, with its code in each version.
ExtensionHeader
One GTPv1 extension header (TS 29.060 §6.1).
GtpV1Header
GTPv1 header (TS 29.060 §6).
GtpV1Ie
GtpV1Message
A decoded GTPv1 datagram.
GtpV2Header
GTPv2-C header (TS 29.274 §5.1).
GtpV2Ie
GtpV2Message
InnerIp
The decoded header of the user packet a G-PDU carries.

Enums§

DecodeError
EncodeError
A value the encoder refuses to put on the wire.
GtpVersion
Which GTP version a datagram announced in its first three bits.

Constants§

CAUSES
GTPC_PORT
GTP-C signalling port (TS 29.060 §4.1, TS 29.274 §4.1). Above 1023.
GTPU_PORT
GTP-U user-plane port (TS 29.060 §4.1). Above 1023.
MAX_APN_LABEL_LEN
Longest DNS label an APN may carry, in octets (TS 23.003 §9.1, RFC 1035 §2.3.4).
MAX_GPDU_PAYLOAD_LEN
Largest T-PDU this server will put inside a G-PDU, in octets.
V1_CREATE_PDP_CONTEXT_REQUEST
V1_CREATE_PDP_CONTEXT_RESPONSE
V1_DELETE_PDP_CONTEXT_REQUEST
V1_DELETE_PDP_CONTEXT_RESPONSE
V1_ECHO_REQUEST
V1_ECHO_RESPONSE
V1_END_MARKER
V1_ERROR_INDICATION
V1_G_PDU
V1_IE_ACCESS_POINT_NAME
V1_IE_CAUSE
V1_IE_CHARGING_ID
V1_IE_END_USER_ADDRESS
V1_IE_GSN_ADDRESS
V1_IE_IMEISV
V1_IE_IMSI
V1_IE_MSISDN
V1_IE_MS_TIME_ZONE
V1_IE_NSAPI
V1_IE_PROTOCOL_CONFIG_OPTIONS
V1_IE_QOS_PROFILE
V1_IE_RAT_TYPE
V1_IE_RECOVERY
V1_IE_REORDERING_REQUIRED
V1_IE_SELECTION_MODE
V1_IE_TEARDOWN_IND
V1_IE_TEID_CONTROL_PLANE
V1_IE_TEID_DATA_I
V1_IE_USER_LOCATION_INFO
V1_MAX_SEQUENCE
Largest sequence number a GTPv1 header can carry: the field is 16 bits (TS 29.060 §6).
V1_SUPPORTED_EXTENSION_HEADERS_NOTIFICATION
V1_UPDATE_PDP_CONTEXT_REQUEST
V1_UPDATE_PDP_CONTEXT_RESPONSE
V1_VERSION_NOT_SUPPORTED
V2_CREATE_SESSION_REQUEST
V2_CREATE_SESSION_RESPONSE
V2_DELETE_SESSION_REQUEST
V2_DELETE_SESSION_RESPONSE
V2_ECHO_REQUEST
V2_ECHO_RESPONSE
V2_IE_APN
V2_IE_APN_RESTRICTION
V2_IE_BEARER_CONTEXT
V2_IE_CAUSE
V2_IE_EBI
V2_IE_FTEID
V2_IE_IMSI
V2_IE_MSISDN
V2_IE_PAA
V2_IE_PCO
V2_IE_RAT_TYPE
V2_IE_RECOVERY
V2_IE_ULI
V2_MAX_SEQUENCE
Largest sequence number a GTPv2 header can carry: the field is 24 bits (TS 29.274 §5.1).
V2_MODIFY_BEARER_REQUEST
V2_MODIFY_BEARER_RESPONSE

Functions§

cause_accepts
Does this numeric cause value grant something?
cause_by_name
Look a cause up by name, tolerating the spellings a model actually produces: "Request accepted", "REQUEST_ACCEPTED", "request-accepted".
cause_names
Every cause name the model may use, for error messages and documentation.
decode_apn
Decode a labelled APN back to dotted form. Returns None if the labels do not tile the buffer exactly, which means it was not an APN.
decode_end_user_address
Decode a GTPv1 End User Address. Returns (pdp_type, address); the address is None for the “give me a dynamic one” form a UE sends in a Create PDP Context Request.
decode_fteid
Decode an F-TEID. Returns (interface_type, teid, address).
decode_inner_ip
Decode the header of an encapsulated user IP packet. None when it is not IP at all.
decode_paa
Decode a GTPv2-C PAA. Returns (pdn_type, address).
decode_tbcd
Decode TBCD back to digits, stopping at the 0xF filler.
encode_apn
Encode an APN as DNS-style labels: one length octet per label, no trailing root label (TS 23.003 §9.1, TS 29.060 §7.7.30).
encode_end_user_address
GTPv1 End User Address (IE 128) for an IETF-allocated PDP address.
encode_fteid
GTPv2-C Fully Qualified TEID (IE 87), TS 29.274 §8.22.
encode_paa
GTPv2-C PDN Address Allocation (IE 79). PDN type 1 = IPv4, 2 = IPv6, 3 = IPv4v6.
encode_pco_dns
Protocol Configuration Options carrying DNS server addresses in the network-to-MS direction (TS 24.008 §10.5.6.3; GTPv1 IE 132, GTPv2 IE 78).
encode_tbcd
Encode decimal digits as TBCD (telephony BCD): two digits per octet, low nibble first, odd counts padded with the filler 0xF. Used for IMSI, MSISDN and IMEI.
encode_v1_ies
Serialise information elements. Fixed types emit no length; 128+ emit a two-octet length.
encode_v2_grouped
Serialise IEs for use as the value of a grouped GTPv2 IE.
find_all_v1
Every IE of a type, in order.
find_v1
First IE of a type, if present.
ip_protocol_name
parse_v1_ies
Parse a GTPv1-C message body into information elements.
parse_v2_grouped
Parse the inner IEs of a grouped GTPv2 IE (Bearer Context and friends).
peek_version
The version bits of a datagram, without decoding anything else.
rat_type_name
Radio access technology name (TS 29.060 §7.7.50 / TS 29.274 §8.17). The two specifications number these differently, so the version has to be passed in.
v1_fixed_ie_len
Length in octets of the value of a GTPv1 fixed-length (TV) information element.
v1_ie_name
Human name for the GTPv1 IEs this server surfaces. Unknown types are reported by number.
v1_message_name
Human name for a GTPv1 message type, for logs and event data.
v2_ie_name
Human name for the GTPv2-C IEs this server surfaces.
v2_message_name
Human name for a GTPv2-C message type.