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 |
|
Protocol Version Identifier |
3 |
24 |
|
BPDU Type |
4 |
32 |
|
Flags |
5 |
40 |
|
Root Identifier |
13 |
104 |
|
Root Path Cost |
17 |
136 |
|
Bridge Identifier |
25 |
200 |
|
Port Identifier |
27 |
216 |
|
Message Age |
29 |
232 |
|
Max Age |
31 |
248 |
|
Hello Time |
33 |
264 |
|
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]¶
-
This class implements the Spanning Tree Protocol, its Configuration and TCN BPDUs.
Added in version 1.9.0.
Properties
- 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
- 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:
- Return type:
- 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.
typedecides 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.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.payload (
bytes|ProtocolBase|Schema) – Octets past the BPDU.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
typeis 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
- static _read_config_flags(value)[source]¶
Read the flags of a Configuration BPDU.
- Parameters:
value (
int) – The flags octet.- Return type:
- 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:
- Returns:
The flags octet.
- Raises:
ProtocolError – If
valueis neither, a flag is nobool, 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:
SchemaHeader 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.
- version: ProtocolVersion = <EnumField version>¶
Protocol Version Identifier.
- message_age: int | None = <ConditionalField message_age>¶
Message Age, in units of 1/256 of a second.
Auxiliary Functions¶
Data Models¶
- class pcapkit.protocols.application.stpv0.data.STPv0(protocol_version, type)[source]¶
Bases:
ProtocolData 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.
- flags: ConfigFlags¶
Flags, present only for a Configuration BPDU, as are the fields below.