STP Objective
Spanning Tree Protocol (STP) protects Layer 2 broadcast domains from broadcast storms by selectively setting links to standby mode to prevent loops. In standby mode, these links temporarily stop transferring user data. After the topology changes, so that the data transfer is made possible, the links are automatically re-activated.
Network Loops occur when there are alternate routes between hosts. These loops cause Layer 2 switches to forward traffic across the network infinitely, reducing network efficiency. STP provides a unique path between endpoints on a network. These paths eliminate the possibility of network loops. STP is typically configured when there are redundant links to a host to prevent network loop.
The device supports the following Spanning Tree Protocol versions:
- PVST+: Runs an instance of STP for each VLAN, allowing for load balancing across VLANs.
- Rapid PVST+(RPVST) — An extension of RSTP, Detects network topologies to provide faster convergence for each VLAN of the spanning tree.
- Multiple STP (MSTP) — MSTP is based on RSTP. It detects Layer 2 loops, and attempts to mitigate them by preventing the involved port from transmitting traffic. Maps multiple VLANs into a single spanning tree instance to optimize redundant paths.
MSTP solves this problem by enabling several STP instances, so that it is possible to detect and mitigate loops separately in each instance. This enables a port to be blocked for one or more STP instances but non-blocked for other STP instances. If different VLANs are associated with different STP instances, then their traffic will be relayed based on the STP port state of their associated MST instances. This results to better bandwidth utilization.
STP Port Roles
- Root Port (RP): The port on a switch that has the best path to the Root Bridge.
- Designated Port (DP): The port that forwards traffic toward the segment’s best path.
- Blocked Port: Port kept in standby to prevent loops. i.e; non-designated port
- Alternate/Backup Port: (In RSTP) Fast failover ports.
STP Port States (802.1D)
- Blocking – Port doesn’t forward traffic or learn MAC addresses.
- Listening – Preparing to participate in STP.
- Learning – Learns MAC addresses but does not forward data.
- Forwarding – Forwards traffic normally.
- Disabled – Administratively down.
- RSTP Simplifies to:
- Discarding
- Learning
- Forwarding
More Key Concepts -
Root Bridge: The central reference point in the network. All path calculations are made with respect to this switch.
Bridge Protocol Data Units (BPDUs): Frames used to exchange STP information between switches.
Portfast: When the switchport failed to transite due to unavoidale circumstances in STP, it will be holding on the listenting and learning states for 30 seconds. Portfast feature enabling the forwarding state immediately.
BPDU Guard: BPDU guard prevents a port from receiving BPDUs. If the port still receives a BPDU, it is put in the error-disabled state as a protective measure. BPDU Guard has two configuration options: globally (spanning-tree portfast bpduguard default) and per interface (spanning-tree bpduguard enable).
BPDU Filter: BPDU Filter prevents specified ports from sending or receiving BPDUs. Two methods to configure this feature: globally (spanning-tree portfast bpdufilter default) and per interface (spanning-tree bpdufilter enable).
How STP Works in Cisco Switches
Step 1 – Root Bridge Election
- Switch with lowest Bridge ID becomes Root.
- If priorities are equal → lowest MAC address wins.
Step 2 – Path Cost Calculation
- STP assigns cost values to each link based on speed:
- 10 Mbps → Cost 100
- 100 Mbps → Cost 19
- 1 Gbps → Cost 4
- 10 Gbps → Cost 2
N:B: The path with lowest total cost to the Root Bridge is preferred.
Step 3 – Port Role Assignment
- Root Bridge: All ports are Designated Ports.
- Non-root switches: One port becomes Root Port (closest to Root), others may be Designated or Blocked.
Step 4 – Loop Prevention
- Any redundant port not on the best path is placed into a blocking or discarding state.
Basic Configuration of STP on Switch
Step-01: STP configuration to Switch -
spanning-tree mode rapid-pvst
spanning-tree portfast default
spanning-tree portfast bpduguard default
spanning-tree vlan 13,64 priority 4096
"or"
spanning-tree vlan 13 root primary
spanning-tree vlan 64 root secondary
to access switchport (only edge port) -
interface FastEthernet0/1
switchport access vlan 13
switchport mode access
spanning-tree portfast
spanning-tree bpduguard enable
N:B: Configuring priorities for root bridge election, and setting up PortFast and BPDU Guard for edge ports. Remember, Portfast should be configured only on edge ports connecting to end devices. If PortFast is enabled on an interface connecting to another switch, a temporary STP loop could be created.
to trunk switchport -
interface FastEthernet0/24
switchport trunk allowed vlan 13,64
switchport mode trunk
Step 2. Root Guard configuration to switchport (Optional) -
interface FastEthernet0/20
spanning-tree guard root
N:B: The Root Guard feature is responsible for verifying if the port on which it was enabled is a designated port. If the port with enabled Root Guard receives a superior BPDU, it goes to a Listening state (for STP) or discarding state (for RSTP and MSTP).
Example -
Objectives -
1. Set the STP mode as PVST, RPVST, MSTP.
2. Set the priority for the root bridge election.
3. Configure PortFast (for edge ports)
4. Enable BPDU Guard (to protect edge ports)
5. Verify the STP configuration.
6. Root Guard Configuration for a specific Interface. (If required).
Step-01: VLAN Configuration
Switch(config)#vlan 100
Switch(config-vlan)#name ICT
Switch(config-vlan)#vlan 200
Switch(config-vlan)#name HR
Switch(config-vlan)#vlan 99
Switch(config-vlan)#name MGMT
Switch(config)#interface range fastEthernet 0/1-20
Switch(config-if-range)#switchport mode trunk
Switch(config-if-range)#switchport trunk allowed vlan 99,100,200
Switch(config-if-range)#shutdown
Switch(config)#interface range fastEthernet 0/1-7
Switch(config-if-range)#no shutdown
//Configure Access port at Access Layer switches
Switch(config)#interface fastEthernet 0/24
Switch(config-if)#no shutdown
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan <id>
Step-02: STP Global Configuration
Switch(config)#spanning-tree mode rapid-pvst
Switch(config)#spanning-tree vlan 99,100,200 priority 4096
''Alt"
Switch(config)#spanning-tree vlan 99,100 priority 4096
Switch(config)#spanning-tree vlan 200 priority 8192
"Alt"
Switch(config)#spanning-tree vlan 99,100 root primary
Switch(config)#spanning-tree vlan 200 root secondary
//if required configure portfast and bpduguard globally
Switch(config)#spanning-tree portfast default
Switch(config)#spanning-tree portfast bpduguard default
Step-03: Portfast and BPDUGUARD Configure on Edge Port
Switch(config)#interface fastEthernet 0/24
Switch(config-if)#spanning-tree portfast
Switch(config-if)#spanning-tree bpduguard enable
Step-04: Verify the STP Configuration
a. Show the Logical status on Switch
Switch#show spanning-tree summary
Switch#show spanning-tree active
b. Some Example by doing physical connectivity UP and Down manually.
Following below pictures mention that -
1. If an Uplink down from S1 to A4, another link will be up automatically from S2 to A4 switches. will be pinging Router to A4 (VLAN200 PC).
2. Two link down from S1 to S2 and A4 respectively, will be pinging Router to A4 (VLAN200 PC).
3. Four Uplinks down from S1 to S2, A1, A3, A4 respectively, pinging will be continuing from Router to others Endpoint Devices (PCs) uninterruptedly.
4. Finally, Stop the S1 switch and the rest of the connection will be activating instantly.
Example of STP Configuration -