STP election principle
STP is a protocol used to eliminate loops in local area networks. In a Layer 2 network, in order to perform link backup and improve network reliability, redundant links are usually used. However, the use of redundant links will cause the physical topology to form a ring, which leads to a Layer 2 loop. The harm of the Layer 2 loop is broadcast storm and mac table shock. Thereby affecting network communication.
In order to solve the problem of layer 2 network loops, the spanning tree protocol (STP: spanning tree protocol) appeared.
Through the STP protocol, loops can be actively discovered through the exchange of information between Layer 2 devices and the loop network can be pruned into an acyclic tree structure by blocking ports.
STP does not affect the link backup while eliminating the loop. When the active path fails, the previously down link will be reactivated to restore network connectivity.
Basic concepts of STP
A root bridge
STP defines a tree network structure, so there must be a unique root (root bridge). It is the logical center of the network, but not necessarily the physical center. The root bridge is not fixed and changes dynamically according to changes in the network topology. The root bridge is the bridge with the smallest BID, and the smallest BID is selected through interactive configuration of BPDU protocol messages.
After the network converges, the root bridge will generate and send configuration BPDUs at a certain time interval. After other devices receive the configuration BPDU, if the priority is higher than its own configuration BPDU, the non-root bridge device will follow the received configuration The information carried in the BPDU updates the configuration BPDU information stored on its STP port, otherwise the configuration BPDU is discarded.
Two measures
STP is calculated based on ID and path cost
id
Divided into BID (bridge id) and PID (port ID)
BID: Bridge ID
The composition of the BID is: a 16-bit bridge priority (bridge priority) and a 48-bit bridge MAC address.
In STP, the device with the smallest BID will be elected as the root bridge (RB)
PID: Port ID
The composition of PID is: 4-bit port priority and 12-bit port number.
PID is only useful for selecting designated ports under certain circumstances.
Pathcost
A port variable. It is the reference value used by STP to select the link. STP calculates the path cost, selects stronger links, blocks redundant links, and prunes the network into a loop-free tree-like network structure.
In an STP network, the path cost from a port to the root bridge is the accumulation of the path costs of the ports on the bridges that it passes through. This value is called the root path cost (ROOT PATH COST)
Three-element election
From ring structure to tree structure, there are three elements: root bridge, root port and designated port.
Root Bridge RB
The bridge with the smallest BID selects the smallest BID through interactive configuration BPDU protocol messages.
Root port RP
The port on the non-root bridge with the smallest path cost to the root bridge, the root port is responsible for forwarding data to the RB. The determination of the RP depends on the root path cost. There is one and only one RP on a non-root bridge, and there is no root port on the root bridge.
Designated port DP
For a device
The designated bridge is directly connected to the local machine and the
designated port of the device responsible for forwarding configuration messages to the local machine is the port through which the designated bridge forwards configuration messages to the local machine.
For a local area network
The designated bridge is the device responsible for forwarding configuration messages to the network segment. The
designated port is the port for the designated bridge to forward configuration messages to the network segment.
For S2, S1 is its designated bridge, and AP1 is the designated port of S2.
For the LAN, if S2 is responsible for forwarding configuration messages to the LAN, then S2 is its designated bridge, and BP2 is its designated port.
All ports of the root bridge are designated ports.
Once the RB, RP, and DP elections are successful, the entire tree topology is established. After the topology is stable, only RP and DP forward traffic, and other ports are in the blocking state. They only receive STP protocol packets and not Forward user traffic.
Four principles of comparison
The four comparison principles of STP: RBID>RPC>Sending device BID>Sending port PID |
Field content | brief introduction |
---|---|---|
Root bridge ID | One and only one | |
Root path cost | The distance from the port sending the configuration BPDU to the root bridge determines the path cost to the root bridge | |
Sending device BID | BID of the device sending the configuration BPDU | |
Send port PID | PID of the port that sent the configuration BPDU |
- Minimum BID: used to elect the root bridge (min)
- Minimum root path cost: used to elect a root port on a non-root bridge, and the path costs from all interfaces of the root bridge to the root bridge are 0
- Minimum sender BID: used to elect the root port on a non-root bridge. When the non-root bridge has two or more ports with the same minimum root path cost, select the port with the smaller sender BID in the received configuration message .
- Minimum PID: used to elect the root port on a non-root bridge. When there are two or more ports with the same minimum root path cost and the same BID on the non-root bridge, the port with the smaller PID is selected.
Five port states
forwarding
The port not only forwards user traffic but also processes BPDU packets. Only the root port or designated port can enter the forwarding state
learning
The device will construct a mac address table based on the received user traffic, but will not forward user traffic. It is a transitional state, and the learning state is added to prevent temporary loops.
listening
After determining the port role, the root bridge, root port, and designated port will be elected. It is also a transitional state.
blocking
The port only receives and processes BPDUs, and does not forward user traffic. The final state of the blocked port.
disabled
The port not only does not process bpdu packets, but also does not forward user traffic. The port status is down.