STP - Spanning Tree Protocol¶
pcapkit.protocols.application.stp.protocol holds
STP, the abstract base of the
Spanning Tree Protocol family [*], whose Bridge Protocol Data Units (BPDUs) are
told apart by their Protocol Version Identifier. Each version is a member of its
own:
Version |
Class |
Specification |
BPDUs |
|---|---|---|---|
0 |
IEEE Std 802.1D-2004 clause 9 |
Configuration, 35 octets, and Topology Change Notification (TCN), 4 octets |
|
2 |
IEEE Std 802.1Q-2022 clause 14 |
RST, 36 octets |
|
3 |
IEEE Std 802.1Q-2022 clause 14 |
MST, 102 octets and an MSTI Configuration Message of 16 for each MSTI |
The members share the first four octets alone, the Protocol Identifier, the Protocol
Version Identifier and the BPDU Type, so the base parses no BPDU. LLC address
0x42 is the family’s, as DSAP and SSAP both, so
LLC.__proto__ binds this
base, paired, and it picks the member as IEEE Std 802.1Q-2022 clause 14.4 validates a
BPDU, by _classify(). A BPDU that clause discards is left
Raw behind LLC, and a direct parse of it
raises ProtocolError; so is an SPT BPDU, of
version 4, which the family does not dissect.
The bridge’s control plane computes the active topology rather than relaying frames, so the family is a user of the stack, as a routing protocol is (Protocol Layer Placement). The proprietary per-VLAN variants, which no public specification defines, are not dissected.
Added in version 1.9.0.
- class pcapkit.protocols.application.stp.protocol.STP[_PT: Data, _ST: Schema](file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[source]¶
Bases:
Application[_PT,_ST],Generic[_PT,_ST]This class implements all protocols in the Spanning Tree Protocol family.
Spanning Tree Protocol (
STPv0) [IEEE Std 802.1D-2004]Rapid Spanning Tree Protocol (
RSTP) [IEEE Std 802.1Q-2022]Multiple Spanning Tree Protocol (
MSTP) [IEEE Std 802.1Q-2022]
It is abstract, as
OSPFis, and dispatches on both paths, never giving an instance of this class (#2574). Theversionkeyword names the member, andmake()does not take it; without it, octets give the member_classify()picks, and fields are refused. The Protocol Version Identifier alone does not pick it: a Configuration BPDU is one whatever its version, and an MST BPDU that fails its checks is an RST BPDU, sofrom_data()reads the data model’s class, asLinuxSLL.from_datadoes. See__new__().Note
The subpackage does not track the dispatch tier. STP is dispatched from
LLC.__proto__atBridge_Spanning_Tree_Protocol, since LLC is what carries it.Properties
- abstract property version: Literal[0, 2, 3]¶
Version of the member, the Protocol Version Identifier its BPDUs take.
Methods
- classmethod id()[source]¶
Index ID of the protocol.
IEEE Std 802.1D-2004 names the version 0 protocol
STP, without a version, so the family’s own name doubles as its canonical name, the shapeIGMP.idtakes.
- classmethod from_data(data, /, **kwargs)[source]¶
Create protocol instance from data.
- Parameters:
**kwargs (
Any) – AsProtocol.from_data.
- Return type:
- Returns:
Protocol instance; on this class, an instance of the member whose data model
datais.- Raises:
ProtocolError – If
datais no member’s data model, on this class. Adictis refused: itsprotocol_versiondoes not pick the member, and no key does.
Data Models
- classmethod __index__()[source]¶
Numeral registry index of the protocol.
- Return type:
- Returns:
Numeral registry index of the protocol in the LLC address values, which every member inherits, since no link type, EtherType, protocol number or port names it.
- __length_hint__()[source]¶
Return an estimated length for the object.
The longest member’s fixed part, an MST BPDU with no MSTI, as
OSPF.__length_hint__takes its longest header.- Return type:
- __init__(file=NO_VALUE, length=None, /, *, version=None, layer=None, protocol=None, context=None, **fields)[source]¶
Parse a protocol instance from its octets, or construct one from its fields.
- Overloads:
file (
IO[bytes] |bytes), length (int|None) =..., /, *, version (Literal[0,2,3] |None) =..., layer (str|None) =..., protocol (str|ProtocolBase|Type[ProtocolBase] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =...→None*, version (
Literal[0,2,3] |None) =..., context (ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) =..., **fields (Any) →None
- Parameters:
file (
IO[bytes] |bytes|NoValueType) – Source packet stream; omitted to construct.version (
Literal[0,2,3] |None) – Version of the member,0,2or3: the member__new__()picks, which must be this class’s own.layer (
str|None) – AsProtocol.__init__.protocol (
str|ProtocolBase|Type[ProtocolBase] |None) – AsProtocol.__init__.context (
ContextRegistry|ProtocolContext|Mapping[str,ProtocolContext] |Iterable[ProtocolContext] |None) – AsProtocol.__init__.**fields (
Any) – AsProtocol.__init__.
- Raises:
ProtocolError – If
versionnames no member, or is not this class’s ownversion.
- static __new__(cls, file=NO_VALUE, length=None, /, **kwargs)[source]¶
Create the member a parse or a construction of this class describes.
The
versionkeyword names the member. Without it, the octets give the member_classify()picks, and fields are refused. That member’s__init__then runs with the same arguments. A subclass of this class is created as itself.- Parameters:
- Return type:
- Returns:
An uninitialised instance of the member.
- Raises:
ProtocolError – On this class, if
versionnames no member; if, without it, the octets are a BPDU IEEE Std 802.1Q-2022 clause 14.4 discards; or if fields come without it.
Utilities
- static _member_of_version(version)[source]¶
The member a
versionof0,2or3names.- Parameters:
version (
Any) – Version of the member, as_classify()returns it or theversionkeyword gives it.- Return type:
- Returns:
- Raises:
ProtocolError – For any other
version, or one that is noint, as aboolis even where it equals one.
- classmethod _classify(data)[source]¶
Validate a received BPDU as IEEE Std 802.1Q-2022 clause 14.4 does.
With a Protocol Identifier of zero, a BPDU Type of
0x00and 35 octets or more is a Configuration BPDU, and one of0x80and 4 octets or more a TCN BPDU, whatever the version; with a BPDU Type of0x02, a version of 2 and 36 octets or more is an RST BPDU. A version of 3 or more, with 35 octets or more, is an RST BPDU where_is_mst()fails; where it holds, version 3 is an MST BPDU, and a later version the SPT BPDU of Shortest Path Bridging, version 4, which extends it and which no member reads. Anything else is discarded.
- static _is_mst(data)[source]¶
Whether a BPDU of version 3 or more holds what an MST BPDU does.
It holds 102 octets or more, a Version 1 Length of zero, and a Version 3 Length counting 0 to 64 MSTI Configuration Messages of 16 octets each after the 64 octets every MST BPDU has there (IEEE Std 802.1Q-2022 clause 14.4).
- classmethod _construction_member(fields)[source]¶
The member
from_fields(),from_data()and a call given no file construct.On this class, the member
versionnames; on another, the class itself, whoseversionversionmust be.versionis taken out offields, asmake()does not read it.
- static _rebuilt_version(data, own)[source]¶
The version a rebuild of
datawrites: its own, orownif the capture ended first.A capture that ends before the Protocol Version Identifier leaves it zero, which names no RST or MST BPDU’s version; the rebuild is cut back before the octet, so the version it writes is never read, as for
OSPF._rebuilt_version.
- _check_bpdu(schema, *, types, least=0, most=0xFF)[source]¶
Refuse a BPDU another member reads, or one no member does.
Its Protocol Identifier must be zero, its BPDU Type one of
typesand its Protocol Version Identifier fromleasttomost. A field a header parsed on its own ends before is left to the short read, as its zeros are the cut’s.
- _make_bridge_id(value, *, name)[source]¶
Make a Bridge Identifier.
- Parameters:
- Return type:
- Returns:
Its eight octets.
- Raises:
ProtocolError – If
valueis neither; if its priority is not a multiple of 4096 in0..61440; or if its extension does not fit in 12 bits, or its address is no MAC address.
- _make_port_id(value, *, name)[source]¶
Make a Port Identifier.
- Parameters:
- Return type:
- Returns:
Its two octets, as an integer.
- Raises:
ProtocolError – If
valueis neither; if its priority is not a multiple of 16 in0..240; or if its number does not fit in 12 bits.
- _make_flags(value)[source]¶
Make the flags of an RST or MST BPDU.
- Parameters:
value (
Flags|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, or a flag is noboolor the role does not fit in two bits.
- _make_role_flags(value, *, last, name)[source]¶
Make a flags octet carrying a Port Role, the CIST’s or an MSTI’s.
- static _read_timer(value)[source]¶
Read a timer, in units of 1/256 of a second (IEEE Std 802.1D-2004 clause 9).
- _make_protocol_version(value, *, least, most=0xFF)[source]¶
Check a Protocol Version Identifier this member writes.
- Parameters:
value (
ProtocolVersion|int) – The Protocol Version Identifier.least (
int) – The lowest version this member’s BPDUs take.most (
int) – The highest.
- Return type:
- Returns:
value, as a plainint.- Raises:
ProtocolError – If
valueis no 8-bit code, or is outsideleasttomost.
Data Models¶
- class pcapkit.protocols.application.stp.data.BridgeID(priority, extension, address)[source]¶
Bases:
DataData model for a Bridge Identifier, eight octets (IEEE Std 802.1D-2004 clause 9).
- class pcapkit.protocols.application.stp.data.PortID(priority, number)[source]¶
Bases:
DataData model for a Port Identifier, two octets (IEEE Std 802.1D-2004 clause 9).
- class pcapkit.protocols.application.stp.data.Flags(tc, proposal, role, learning, forwarding, agreement, tc_ack)[source]¶
Bases:
DataData model for the flags of an RST or MST BPDU, octet 5.
Bit 1 is the least significant bit of the octet.
- role: PortRole¶
Port Role, bits 3 and 4; its
0, a Master Port in the MSTI Flags, is Unknown here (IEEE Std 802.1D-2004).
Footnotes