RSTP - Rapid Spanning Tree Protocol

pcapkit.protocols.application.rstp.protocol holds RSTP, the extractor for the RST BPDU of the Rapid Spanning Tree Protocol (RSTP) [IEEE Std 802.1Q-2022 clause 14], laid out as the Configuration BPDU with a Version 1 Length after it:

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

35

280

stp.version_1_length

Version 1 Length, zero

IEEE Std 802.1Q-2022 clause 14.4 decodes a BPDU of BPDU Type 0x02 and version 2 as an RST BPDU, and one of version 3 or more too, where it does not hold what an MST BPDU does; such a BPDU of 35 octets ends before its Version 1 Length. Its flags carry the Port Role and the Proposal, Learning, Forwarding and Agreement flags beside the Topology Change ones.

Added in version 1.9.0.

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

Bases: STP[RSTP, RSTP]

This class implements the Rapid Spanning Tree Protocol, its RST BPDU.

Added in version 1.9.0.

Properties

property name: Literal['Rapid Spanning Tree Protocol']

Name of current protocol.

property version: Literal[2]

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

property length: Literal[35, 36]

Header length of current protocol, 36 octets or 35 without a Version 1 Length.

Methods

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['RSTP']]

Returns:

Index ID of the protocol, narrowed to this member.

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

Read an RST BPDU.

Structure of an RST BPDU [IEEE Std 802.1Q-2022 clause 14]:

 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         | Version 1 Len |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

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

Return type:

RSTP

Returns:

Parsed packet data.

Raises:

ProtocolError – If the Protocol Identifier is not zero, the BPDU Type is not 0x02, or the version is below 2; or if the BPDU holds what an MST BPDU does, as an MST or an SPT BPDU does.

make(*, protocol_version=ProtocolVersion.RSTP, flags=0, root_id=bytes(8), root_path_cost=0, bridge_id=bytes(8), port_id=0, message_age=0, max_age=0, hello_time=0, forward_delay=0, version_1_length=0, payload=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
  • protocol_version (ProtocolVersion | int) – Protocol Version Identifier, 2 or more.

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

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

  • root_path_cost (int) – Root Path Cost.

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

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

  • 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.

  • version_1_length (int | None) – Version 1 Length; None to end the BPDU before it, at 35 octets, which only a version of 3 or more may.

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

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

Return type:

RSTP

Returns:

Constructed packet data.

Raises:

ProtocolError – If protocol_version is below 2, or is 2 without a version_1_length; if the BPDU and payload would hold what an MST BPDU does; or if a value does not fit its field.

Data Models

__length_hint__()[source]

Return an estimated length for the object.

Return type:

Literal[36]

Utilities

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (RSTP) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

Header Schemas

class pcapkit.protocols.application.rstp.schema.RSTP(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, version_1_length=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for an RST BPDU, 36 octets (IEEE Std 802.1Q-2022 clause 14).

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 = <UInt8Field flags>

Flags.

root_id: bytes = <BytesField root_id>

Root Identifier.

root_path_cost: int = <UInt32Field root_path_cost>

Root Path Cost.

bridge_id: bytes = <BytesField bridge_id>

Bridge Identifier.

port_id: int = <UInt16Field port_id>

Port Identifier.

message_age: int = <UInt16Field message_age>

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

max_age: int = <UInt16Field max_age>

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

hello_time: int = <UInt16Field hello_time>

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

forward_delay: int = <UInt16Field forward_delay>

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

version_1_length: int | None = <ConditionalField version_1_length>

Version 1 Length, zero.

payload: bytes = <PayloadField payload>

Octets past the BPDU, which it does not define.

Auxiliary Functions

pcapkit.protocols.application.rstp.schema.rstp_version_1_length(packet)[source]

Whether the RST BPDU carries its Version 1 Length, the 36th octet.

Parameters:

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

Return type:

bool

Returns:

Whether its version is 2; else, on packing, whether it is given, and on unpacking, whether octets are left, as IEEE Std 802.1Q-2022 clause 14.4 decodes a BPDU of version 3 or more and 35 octets as an RST BPDU.

Data Models

class pcapkit.protocols.application.rstp.data.RSTP(protocol_version, type, flags, root_id, root_path_cost, bridge_id, port_id, message_age, max_age, hello_time, forward_delay, version_1_length)[source]

Bases: Protocol

Data model for an RST BPDU (IEEE Std 802.1Q-2022 clause 14).

Added in version 1.9.0.

protocol_version: ProtocolVersion

Protocol Version Identifier as captured, 2, or 3 or more for a BPDU that IEEE Std 802.1Q-2022 clause 14.4 decodes as an RST BPDU.

type: BPDUType

BPDU Type.

flags: Flags

Flags.

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.

version_1_length: int | None

Version 1 Length; None for a BPDU of version 3 or more that ends before it.