STP
What is STP(Spanning Tree Protocol)?
Simply put, the STP protocol was created to solve the loop problem in the network. Its full name is Spanning Tree protocol, which works on the 2nd network layer of the OSI model. Its protocol standard is IEEE802.1D. STP optimizes the ring network structure to a tree network structure by changing some links into a blocking state.
Why We Need STP?
In order to improve the reliability of the structure, there are often multiple physical links between devices. This redundant setting will inevitably lead to loops. In L2 network, loops will generate broadcast storms, which will lead to network bandwidth and processing resources being exhausted and eventually paralyzed. STP protocol solves the problem of continuous forwarding of messages in a ring network.
Basic Concepts of STP
STP changes the ring structure into a tree network structure. There are four terms that need to be understood: root bridge, root port, designated port, and path cost.
For an STP network, there is only one root bridge. Generally, a device with good performance and high network layer is selected as the root bridge. The root bridge is unique, but not immutable, and will change according to the changes in the network topology.
The root port refers to the port with the lowest cost to the root bridge among all STP ports on a device, and is responsible for forwarding data to the root bridge. There is only one root port on a device running the STP protocol.
It should be noted that the root bridge device does not have a root port. Designated ports have different definitions at different levels. For a device, the directly connected port on the device that is directly connected to it and responsible for sending configuration messages is the designated port. For a network, the directly connected port on the device that forwards configuration messages to this network segment is the designated port.
The path cost refers to the cost value of the port, and the root path cost refers to the accumulated path cost in the process of reaching the root bridge.
How does STP work?
When the network is initialized, all devices will consider themselves as the root bridge. By exchanging BPDU messages, the device with the highest priority is selected as the root bridge. If the priorities are consistent, the MAC addresses are compared. Each non-root bridge device will determine the port with the lowest overhead for receiving configuration messages as the root port. If the overhead is the same, the BID will be compared.
The device will designate one of the ports at both ends of each physical path as a designated port based on the port configuration message and the path cost of the root port. At this time, the remaining ports without identities will be blocked. This step is to prevent loops from forming.
After the root bridge, root port and designated port are successfully elected, the entire tree topology is established. After the topology is stable, only the root port and designated port forward traffic, and other non-root and non-designated ports are in a blocking state. They only receive STP protocol packets but do not forward user traffic.
The Application of STP
As shown in the figure below, the Layer 2 ring network is configured with STP to prevent messages from looping endlessly in the network, and a port on Device 1 is blocked.