STPv0 - Spanning Tree Protocol

pcapkit.protocols.application.stpv0.protocol holds STPv0, the extractor for the Configuration and Topology Change Notification (TCN) BPDUs of the Spanning Tree Protocol (STP) [IEEE Std 802.1D-2004 clause 9], laid out as below. A TCN BPDU ends after its BPDU Type.

Octets

Bits

Name

Description

0

0

Protocol Identifier, zero, not kept

2

16

stp.protocol_version

Protocol Version Identifier

3

24

stp.type

BPDU Type

4

32

stp.flags

Flags

5

40

stp.root_id

Root Identifier

13

104

stp.root_path_cost

Root Path Cost

17

136

stp.bridge_id

Bridge Identifier

25

200

stp.port_id

Port Identifier

27

216

stp.message_age

Message Age

29

232

stp.max_age

Max Age

31

248

stp.hello_time

Hello Time

33

264

stp.forward_delay

Forward Delay

IEEE Std 802.1Q-2022 clause 14.4 decodes either BPDU by its type, whatever its Protocol Version Identifier, so the version is kept as captured and checked against none.

Added in version 1.9.0.

class pcapkit.protocols.application.stpv0.protocol.STPv0(file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[source]

Bases: STP[STPv0, STPv0]

This class implements the Spanning Tree Protocol, its Configuration and TCN BPDUs.

Added in version 1.9.0.

Properties

property name: Literal['Spanning Tree Protocol']

Name of current protocol.

property version: Literal[0]

Version of the member, the Protocol Version Identifier its BPDUs take.

property length: Literal[4, 35]

Header length of current protocol, 4 octets for a TCN BPDU and 35 otherwise.

Methods

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['STP']]

Returns:

Index ID of the protocol, narrowed to this member’s canonical name.

read(length=None, **kwargs)[source]

Read a Configuration or TCN BPDU.

Structure of a Configuration BPDU [IEEE Std 802.1D-2004 clause 9]:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      Protocol Identifier      |    Version    |   BPDU Type   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Flags     |                                               |
+-+-+-+-+-+-+-+-+          Root Identifier (8 octets)           +
|                                               |               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+               +
|                  Root Path Cost               |               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+               +
|                     Bridge Identifier (8 octets)              |
+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |        Port Identifier        |  Message Age  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Message Age  |            Max Age            |  Hello Time   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Hello Time   |         Forward Delay         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

STPv0

Returns:

Parsed packet data.

Raises:

ProtocolError – If the Protocol Identifier is not zero, or the BPDU Type is neither a Configuration BPDU’s nor a TCN BPDU’s.

make(*, protocol_version=ProtocolVersion.STP, type=BPDUType.Configuration, flags=None, root_id=None, root_path_cost=None, bridge_id=None, port_id=None, message_age=None, max_age=None, hello_time=None, forward_delay=None, payload=b'', **kwargs)[source]

Make (construct) packet data.

type decides which fields are carried. A Configuration BPDU carries them all, and one the caller leaves out is written as zeros; a TCN BPDU carries none past its BPDU Type, which must be left out.

Parameters:
  • protocol_version (ProtocolVersion | int) – Protocol Version Identifier.

  • type (BPDUType | int) – BPDU Type, a Configuration or a TCN BPDU.

  • flags (ConfigFlags | int | None) – Flags, or the octet.

  • root_id (BridgeID | bytes | None) – Root Identifier, or its eight octets.

  • root_path_cost (int | None) – Root Path Cost.

  • bridge_id (BridgeID | bytes | None) – Bridge Identifier, or its eight octets.

  • port_id (PortID | int | None) – Port Identifier, or its two octets as an integer.

  • message_age (float | None) – Message Age, in seconds.

  • max_age (float | None) – Max Age, in seconds.

  • hello_time (float | None) – Hello Time, in seconds.

  • forward_delay (float | None) – Forward Delay, in seconds.

  • payload (bytes | ProtocolBase | Schema) – Octets past the BPDU.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

STPv0

Returns:

Constructed packet data.

Raises:

ProtocolError – If type is neither BPDU’s, or is a name; if a field is given that a TCN BPDU does not carry; or if a value does not fit its field.

Data Models

__length_hint__()[source]

Return an estimated length for the object, a Configuration BPDU’s.

Return type:

Literal[35]

Utilities

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (STPv0) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

static _read_config_flags(value)[source]

Read the flags of a Configuration BPDU.

Parameters:

value (int) – The flags octet.

Return type:

ConfigFlags

Returns:

Parsed flags.

_make_config_flags(value)[source]

Make the flags of a Configuration BPDU.

Parameters:

value (ConfigFlags | int) – The flags, as their data model or a mapping of its keys, or the octet as an integer.

Return type:

int

Returns:

The flags octet.

Raises:

ProtocolError – If value is neither, a flag is no bool, or the reserved bits do not fit in six.

Header Schemas

class pcapkit.protocols.application.stpv0.schema.STPv0(pid=NO_VALUE, version=NO_VALUE, type=NO_VALUE, flags=NO_VALUE, root_id=NO_VALUE, root_path_cost=NO_VALUE, bridge_id=NO_VALUE, port_id=NO_VALUE, message_age=NO_VALUE, max_age=NO_VALUE, hello_time=NO_VALUE, forward_delay=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for a Configuration BPDU, 35 octets, or a TCN BPDU, 4 octets (IEEE Std 802.1D-2004 clause 9).

Added in version 1.9.0.

pid: int = <UInt16Field pid>

Protocol Identifier, zero.

version: ProtocolVersion = <EnumField version>

Protocol Version Identifier.

type: BPDUType = <EnumField type>

BPDU Type.

flags: int | None = <ConditionalField flags>

Flags.

root_id: bytes | None = <ConditionalField root_id>

Root Identifier.

root_path_cost: int | None = <ConditionalField root_path_cost>

Root Path Cost.

bridge_id: bytes | None = <ConditionalField bridge_id>

Bridge Identifier.

port_id: int | None = <ConditionalField port_id>

Port Identifier.

message_age: int | None = <ConditionalField message_age>

Message Age, in units of 1/256 of a second.

max_age: int | None = <ConditionalField max_age>

Max Age, in units of 1/256 of a second.

hello_time: int | None = <ConditionalField hello_time>

Hello Time, in units of 1/256 of a second.

forward_delay: int | None = <ConditionalField forward_delay>

Forward Delay, in units of 1/256 of a second.

payload: bytes = <PayloadField payload>

Octets past the BPDU, which it does not define.

Auxiliary Functions

pcapkit.protocols.application.stpv0.schema.stp_config_body(packet)[source]

Whether the BPDU is a Configuration BPDU, whose 31 octets follow the BPDU Type.

Parameters:

packet (dict[str, Any]) – The BPDU’s fields unpacked so far.

Return type:

bool

Returns:

Whether its BPDU Type is not a TCN BPDU’s, which ends after it.

Data Models

class pcapkit.protocols.application.stpv0.data.STPv0(protocol_version, type)[source]

Bases: Protocol

Data model for a Configuration or TCN BPDU (IEEE Std 802.1D-2004 clause 9).

Added in version 1.9.0.

protocol_version: ProtocolVersion

Protocol Version Identifier, as captured.

type: BPDUType

BPDU Type.

flags: ConfigFlags

Flags, present only for a Configuration BPDU, as are the fields below.

root_id: BridgeID

Root Identifier.

root_path_cost: int

Root Path Cost.

bridge_id: BridgeID

Bridge Identifier.

port_id: PortID

Port Identifier.

message_age: float

Message Age, in seconds.

max_age: float

Max Age, in seconds.

hello_time: float

Hello Time, in seconds.

forward_delay: float

Forward Delay, in seconds.

class pcapkit.protocols.application.stpv0.data.ConfigFlags(tc, reserved, tc_ack)[source]

Bases: Data

Data model for the flags of a Configuration BPDU, octet 5.

Bit 1 is the least significant bit of the octet.

tc: bool

Topology Change flag, bit 1.

reserved: int

Bits 2 to 7, unused and sent as zero.

tc_ack: bool

Topology Change Acknowledgment flag, bit 8.