Spanning Tree Protocol (STP) is essential protocol in redundant switching topologies. The main purpose of this protocol is preventing switching loops. Frames does not have TTL field, so it’s not possible to discard frames, which loops continuously. There are many implementation of STP (PVST, PVST+, rapid PVST+, RSTP, MSTP), but fundamentals are the same for all of them.
Every redundant switching topology is expose to broadcast storms risk. Every broadcast frame will loop into infinity crating broadcast of unwelcome and very high traffic.
To check, how broadcast storms influence your switch CPU usage disable STP for one of VLANs and send one broadcast frame on this VLAN (ex. arp request):
no spanning-tree vlan 1
STP process step-by-step
First step: choose one RootBridge from all switches
The first step in STP is choosing the RootBridge. It’s the switch with the lowest BridgeID (build from STP priority and switch MAC address) in whole network.
To change BridgeID and have influence on RoodBridge election, you can change STP priority of switch (by default 32768).
Example of changing STP priority for VLAN 1:
(config)# spanning-tree vlan 1 priority ?
Each STP process steps are calculated for each VLAN, so you can choose different priority for different VLANs and have different RootBridge in each VLAN.
Second step: choose root port for each non RootBridge switch
Each non RootBridge switch have to choose one port, which will be named RootPort in STP terminology. If more VLANs exists on switch, RootPort will be chosen for every VLAN separately (except VLANs, where this switch is RootBridge).
RootPort is the port, which will lead frames through the fastest path to the RootBridge. To calculate the best path STP use summary costs to RootBridge for each path.
Cost is the function of Ethernet connection speed:
- 10Gbps = 2 (cost)
- 1Gbps = 4
- 100Mbps = 19
- 10Mbps = 100
If there are two (or more) ports which have the same best path cost to the RootBridge, switch will choose port, which lead to RootBridge through the lowest BridgeID neighbor switch. If the neighbor switches have the same BridgeID (consider two switches connected with two Ethernet cables on different ports) lower STP port priority decide, which port will be seleted as RootPort. If the priority is the same for both ports, the lowest port number will be chosen.
To change interface cost (should be changed on both ends of cable):
(config-if)# spanning-tree cost ?
To change interface STP port priority:
(config-if)# spanning-tree port-priority ?
Every RootPort forward all frames and do not block any traffic.
Third step: choose designated port and blocked ports for each segment
From Ethernet segment perspective, STP have to choose one Designated Port for each segment. This port should lead frames to the RootBridge with the lowest cost (the fastest, best path).
STP choose blocked port role for every port that has not been named yet. This ports do not forward common Ethernet traffic.
STP process take some time and is longer on bigger switched networks. Every port is going through several states (blocking, listening, learning, forwarding) until forwarding frames and this process can take even 50 seconds. This can cause some problems for PCs connected to switch, because only after this period switch gives PC NIC possibility to talk with other devices.
That’s why PortFast, enhancement Cisco technology, gives the possibility to immediately changing PC ports to forward state in STP networks.
(config-if)# spanning-tree portfast
To ensure, that PortFast port will not cause Layer2 loops, enable bpduguard on this port also:
(config-if)# spanning-tree bpduguard enable
If BPDU frame come on this port, port will be disabled preventing possible switching loop.
Switch# show spanning-tree ? Switch# show spanning-tree interface fastethernet 0/1