Detailed explanation of STP Spanning Tree Protocol: basic concepts, related terms

2025.04.10
In this issue, we will share with you the detailed Q&A about the Spanning Tree Protocol.

1. Basic Introduction to the Spanning Tree Protocol

1. Definition and Purpose of the Spanning Tree

In order to perform link backup and improve network reliability in Ethernet switching networks, redundant links are usually used. However, the use of redundant links will cause loops in the switching network, causing broadcast storms and MAC address table instability and other fault phenomena, resulting in poor user communication quality or even communication interruption.

In order to solve the loop problem in the switching network, the spanning tree protocol STP (Spanning Tree Protocol) was proposed. The evolution of the spanning tree protocol is as follows:


In the spanning tree protocol, MSTP is compatible with RSTP and STP, and RSTP is compatible with STP. The comparison of the three spanning tree protocols is shown in the following table.

As shown in the figure above, the STP protocol is deployed in the network, and the loop in the network is discovered through mutual interaction information, and a certain port is selectively blocked, and finally the ring network structure is pruned into a tree network structure without loops, thereby preventing packets from continuously proliferating and infinitely circulating in the ring network, and avoiding the device from receiving the same packet repeatedly, resulting in a decrease in processing capacity.

2. Detailed explanation of the STP mechanism principle
1. STP related concepts
The basic concepts of STP are as follows:



Purpose of the Spanning Tree Protocol:

After deploying the Spanning Tree Protocol in an Ethernet switching network, if a loop occurs in the network, the Spanning Tree Protocol can achieve the following through topological operations:

Eliminate loops: Eliminate possible network communication loops by blocking redundant links.

Link backup: When the currently active path fails, activate the redundant backup link to restore network connectivity.

2. Application scenarios of the Spanning Tree Protocol
In a complex network, network planners generally tend to deploy multiple physical links between devices due to the need for redundant backup, one of which is the primary link and the other links are backups. This will inevitably form a ring network. If there is a loop in the network, it may cause broadcast storms and damage the MAC table entries.
PID: Port ID. PID consists of two parts, the upper 4 bits are the port priority, and the lower 12 bits are the port number.

② Path Cost describes the "goodness" of the port connected to the network. The port type and bandwidth determine the path cost of the port. The root path cost of the root switch is zero. After receiving the BPDU, other switches add the root path cost in the message to the receiving port path cost to get the "root path cost" of the port. The root path cost reflects the "distance" of a port to the root switch.

(1) A root bridge

The tree-shaped network structure must have a tree root, so STP introduced the concept of root bridge.

For an STP network, there is only one root bridge in the entire network. It is the logical center of the entire network, but not necessarily the physical center.
(2) Two metrics

The generation calculation of the spanning tree is based on two basic metrics: ID and path overhead.

① ID, which is further divided into: BID (Bridge ID) and PID (Port ID).

BID: Bridge ID. The IEEE 802.1D standard stipulates that BID is composed of bridge priority and bridge MAC address. The BID bridge priority occupies the upper 16 bits (the default is 32768, which must be an integer multiple of 4096, ranging from 0-61440), and the remaining lower 48 bits are the MAC address. In an STP network, the device with the smallest bridge ID will be selected as the root bridge.

(3) Three-element selection

From a ring network topology to a tree structure, there are generally three elements: root bridge, root port, and designated port.
If the root bridge ID and root path overhead are equal, the smaller the sending device BID, the better.
If the root bridge ID, root path overhead and sending device BID are equal, the smaller the sending port PID, the better.
Remember that all priority comparisons in the spanning tree protocol are "slightly preferred"!

(5) Five port states

The port states on devices running the STP protocol are shown in the following table:

2. STP packet format
There are two types of STP packets:
Select a switch with the smallest (best) bridge ID as the root bridge
Each non-root switch selects a root port (Root Port RP), which is the port with the smallest path overhead to the root bridge
Each switching segment selects a forwarding port other than the root port - the designated port (Designated Port DP) to transmit configuration BPDU
Block other (non-root non-designated port) ports, which do not forward business traffic but continue to receive and listen to BPDU
(4) Four comparison principles
STP election has four comparison principles, which constitute the message priority vector: {root bridge ID, root path overhead, transmission device BID, transmission port PID }, that is, the configuration BPDU packet comparison is as follows:

First compare the root bridge ID, the smaller the better
If the root bridge ID is equal, the smaller the root path overhead is, the better
Configuration BPDU: The BPDU packets usually refer to configuration BPDU, which is a heartbeat message. As long as the port enables STP, the configuration BPDU will be sent from the specified port according to the time interval specified by the Hello Time timer.
TCN BPDU: It is sent only when the device detects that the network topology has changed. It means that when the downstream topology changes, the topology change notification is sent to the upstream until the root node
3. STP configuration BPDU
STP configuration BPDU packets are encapsulated in Ethernet data frames, with the following characteristics:

The destination MAC is multicast MAC: 01-80-C2-00-00-00, the Length/Type field is the MAC data length, followed by the LLC header, and the LLC is followed by the BPDU packet header.

Please note that most network applications now use Ethernet V2 format, while BPDU between switches is encapsulated in IEEE802.3 LLC format. The comparison of the two is shown in the figure below.
During the initialization process, each bridge will actively send configuration BPDU. However, after the network topology is stable, only the root bridge actively sends configuration BPDU, and other bridges will trigger the sending of their own configuration BPDU after receiving the configuration BPDU from the upstream.

The length of the configuration BPDU must be at least 35 bytes, mainly carrying four parameters (root bridge ID, root path overhead, sending bridge ID, sending port ID) and three timers (Hello time, Forwarding delay, MAXage).

STP has three timers that affect the port status and network convergence:
(1) Hello time

The interval at which the root switch sends configuration BPDUs, the default value is 2s

The interval at which the switch that senses topology changes sends TCNs

(2) Forwaring delay: The time that the port stays in the listening or learning state, the default value is 15s

(3) MAXage: The aging time of the configuration BPDU cached by the switch, the default value is 20s

The basic format of the STP configuration BPDU packet is shown in the figure below:
Parameter table details:

4. STP TCN BPDU
TCN BPDU refers to sending topology change notifications to the upstream when the downstream topology changes, until the root node. TCN BPDU is generated in the following two situations (the STP/RSTP/MSTP mechanisms are all the same):

The port status changes to the Forwarding status.

The designated port receives the TCN BPDU, copies the TCN BPDU and sends it to the root bridge.

The content of STP TCN BPDU is relatively simple, with only the first three fields listed in Table 1: protocol number, version and type, and a total length of only 4 bytes, as follows:
Field Description:

Protocol Identifier: The protocol number is 0
Protocol Version Identifier: The protocol version number is 0, indicating STP (2 is RSTP, 3 is MSTP)
BPDU Type: The type field is a fixed value of 0x80, indicating TCN BPDU