Spanning Tree Protocol and its variations is responsible for elimination loops and ensuring efficiency at layer 2 . Despite was invented 30 years ago and nowadays very often between Access and Distribution layers routing is utilized, it is still good to know how works and what is responsible for.
WHAT DOES STP ?
The idea that stands behind the Spanning Tree protocol is preventing layer 2 loops. Switches for example, send a lot of broadcast traffic. Layer 2 doesn’t use Time To Live mechanism well known from Layer 3, where the packet is being dropped when TTL reach 0. So, if frame can float around endlessly, it consumes switch resources like CPU, RAM and in consequence leads to inefficiency of the network. RSTP blocks all links that may cause loops, so there is only one active path that leads towards the Root Bridge.
THE ROOT BRIDGE
Each switch has its own Bridge Identifier that is increament of 4096. But in case we use PVSTP (per vlan STP) also System ID Extension is being added, what is just a VLAN number.The standard value of BID is 32768. The Bridge ID plays a role during the Root Bridge Election. Root Bridge is a switch that all other switches (Non-Root) have to find the shortest path to. If switches have the same Bridge ID then MAC address is a tie breaker (the lowest wins). The best choice is providing manual election by manipulating the Bridge ID value, relaying on MAC address is not a good choice, because the older switch is, the lower MAC address got. Now, if you compare nowadays switches and switches 10 years old you will come to the right conclusion. The Root Bridge should be the most beefy switch in the topology because has a lot job to do. Only Root Bridge floods the network with BPDUs frames, the remained switches only pass along frames.
WHAT HAPPENS IF THERE IS A CHANGE IN TOPOLOGY ?
If non-Root switch detects changes in topology (by receiving superior BPDUs on different port then Root Port) then sends TCN (Topollogy Change Notification) towards the root bridge, Root Bridge sends back TCA (Topology Change Acknowledgment) and TC (Topology Change) frames that will be sent to all switches in the tree. All swithes will get TC frames on both forwarding and blocked ports! TC information will cause that switches will be able update their MAC address table regarding the appropriate “next hop” entire “tree” will be recalculated.
STP ELECTIONS AND MAKING DECISIONS MECHANISMS
Lowest Bridge ID – when Root Bridge has to be elected
Lowest Path Cost to the Root Bridge – when the switch receives multiple BPDUs, the interface with the lowest cost will be elected as a Root Port
Lowest Sender Bridge ID – when the switch is connected to 2 other switches on the path to Root Bridge and the cost of the paths to the Root Bridge is the same, then the interface connected to the switch with the lowest Bridge ID as the root port will be elected.
Lowest Sender Port ID – when the switch is connected to the other switch with 2 ports and the cost to reach the Root Brdige is the same, it will choose the port with the lower number as the Root Port
The below diagram is cartoonish, I mixed upstream and downstream interfaces 100 Mb and 1Gb in single chassis, it would have never happend in production environment, but it shows very well how STP works
Spanning Tree calculates the best path based on “cost” exactly as OSPF. The cost of particular links is:
As we see STP prefers faster links then number of hops! This is highly visible in case of SW5.
Ports roles in STP:
Root Port – the port that leads to the Root Bridge
Designated Ports – ports that forward traffic, on each link there is only one Designated Port, on the other side we have Alternate Port
Alternate Port – Blocked port, that very quickly may forward frames in case of failure. Alternate port is a counterpart of Non Designated port known from simple STP.