STP is defined in IEEE 802.1D.
BPDUs
STP messages are carried by Bridge Protocol Data Unit (BPDU) frames; BPDUs are multicast to 01:80:c2:00:00:00.
BPDU types:
Configuration – Used for spanning-tree computation
Topology Change Notification (TCN) – Used to announce changes in the network
Configuration BPDUs are sent out every port every two seconds by default.
Root Bridge Election
A root bridge is elected to serve as a common reference point for the topology.
A switch’s bridge ID is composed of two parts:
Bridge priority (2 bytes) – Administratively set; defaults to 32,768 (0x8000)
MAC address (6 bytes) – One of the switch’s MAC addresses
All switches assume they are the root bridge at boot. The actual root bridge is the switch with the lowest bridge ID.
Configuration BPDUs are only generated by the root bridge; all other bridges insert their own sender ID and relay them.
Root Port Election
All non-root switches must designate a single interface as the root port (the port with the best path to the root bridge).
All interfaces are assigned an 8-bit cost derived from their speed.
Port costs:
Bandwidth Cost
4 Mbps 250
10 Mbps 100
16 Mbps 62
45 Mbps 39
100 Mbps 19
155 Mbps 14
622 Mbps 6
1 Gbps 4
10 Gbps 2
The port with the lowest path cost to the root bridge is designated as the root port.
The root path cost noted in a BPDU is incremented by the cost assigned to the port on which it was received.
Designated Port Selection
If multiple switches reside on a segment, the one with the lowest root path cost has the designated port; the other ports will be set to blocking.
Designated port selection process:
1. Lowest root bridge ID
2. Lowest root path cost
3. Lowest sender bridge ID
4. Lowest sender port ID
STP States
Disabled – Shutdown
Blocking – The first state when an interface comes up; only receives BPDUs; indefinite Duration
Listening – Can send and receive BPDUs; able to participate in STP; duration specified by forward delay timer
Learning – Can send and receive BPDUs and learn MAC addresses; duration specified by forward delay timer
Forwarding – Normal operation; indefinite duration
STP Timers
Hello Time – The rate at which configuration BPDUs are advertised by the root bridge (default is 2 seconds)
Forward Delay – Length of time a port spends in both the listening and learning states(default is 15 seconds)
Max Age – Life of the most recent BPDU advertised from the root bridge (default is 20 seconds)
Timers can be individually adjusted manually on the root bridge, or automatically adjusted by modifying the network diameter (number of switch hops which extend from the root).
STP Types
Common Spanning Tree (CST) – Defined in 802.1Q; one tree for all VLANs
Per-VLAN Spanning Tree (PVST) – Cisco proprietary; one tree per VLAN
Per-VLAN Spanning Tree Plus (PVST+) – PVST featuring compatibility with CST BPDUs