TSDU#

TSDU (Transport Service Data Unit) Handling#

This module implements parsing and building logic for TSDUs according to §8.1 of the X.225 specification.

Every hand-off between the session layer and the transport layer travels as one TSDU, which - depending on what is being sent - may be built from:

  • One SPDU mapped directly to a TSDU (Category 1)

  • Multiple SPDUs concatenated (Category 0 + Category 2, or multiple Category 2s)

  • In special cases, only a Category 0 SPDU

Concatenation rules (See §6.3.7):

  • Category 0: fine either as a lone TSDU or as the lead-in for one or

    more Category 2 SPDUs concatenated onto it.

  • Category 1: always fills a whole TSDU by itself; never concatenated

    with anything else.

  • Category 2: never forms a TSDU on its own - it only ever shows up

    tacked onto a preceding Category 0 SPDU within the same TSDU.

See also

  • §6.3.7 Concatenation rules

  • §8.1 TSDU structure

  • §8.2 SPDU structure

class icspacket.proto.iso_ses.tsdu.TSDU(*spdus: SPDU)[source]#

TSDU container for one or more concatenated SPDUs. (See X.225, §8.1)

Usage:

>>> tsdu = TSDU.from_octets(data)   # Parse a raw TSDU from bytes
>>> tsdu.build()                    # Encode back to raw bytes
add_spdu(code: int, category: SPDU_Category | None = None) SPDU[source]#

Create a new SPDU and append it to this TSDU.

Parameters:
  • code (int) – The SPDU code (see SPDU_Codes).

  • category (SPDU_Category, optional) – The SPDU category, defaults to False

Returns:

The newly created SPDU object.

Return type:

SPDU

property spdus: list[SPDU]#

List of SPDUs contained in this TSDU.

This property returns a direct reference to the internal list, so it can be iterated over or modified directly.

static from_octets(octets: bytes) TSDU[source]#

Decode a raw TSDU from its octet representation.

Parameters:

octets (bytes) – The raw TSDU data as received from the transport layer.

Raises:

ValueError – If a Category 0 SPDU has a non-zero length, or or if any SPDU length is invalid (extends beyond buffer).

Returns:

A fully parsed TSDU object containing one or more SPDUs.

Return type:

TSDU

build() bytes[source]#

Assemble the TSDU into its raw octet representation.

Returns:

The encoded TSDU, produced by concatenating each SPDU’s octet representation.

Return type:

bytes