spanning_tree - dwilson2547/wiki_demo GitHub Wiki
- 1. What is Spanning Tree Protocol (STP)?
- 2. Why STP is Needed
- 3. How STP Works
- 4. Example: STP in Action
- 5. STP Timers
- 6. Rapid Spanning Tree Protocol (RSTP)
- 7. Multiple Spanning Tree Protocol (MSTP)
- 8. STP Configuration (Cisco Example)
- 9. Troubleshooting STP
- 10. Best Practices
- 11. STP vs. RSTP vs. MSTP
- 12. Real-World Example
- 13. Limitations of STP
- 14. Modern Alternatives
- 15. Summary
Spanning Tree Protocol (STP) is a Layer 2 (Data Link Layer) network protocol designed to prevent loops in Ethernet networks. Loops can cause broadcast storms, MAC address table instability, and network outages. STP ensures a loop-free topology by dynamically blocking redundant paths while maintaining connectivity.
STP is defined in the IEEE 802.1D standard.
- Loop Prevention: Redundant paths in a network can create loops, leading to infinite traffic replication.
- Network Stability: STP ensures only one active path exists between any two devices, preventing broadcast storms.
- Redundancy: Allows for backup paths that activate if the primary path fails.
- Bridge Protocol Data Units (BPDUs): STP uses BPDUs to exchange information between switches.
- Root Bridge: The central reference point for STP calculations. All paths are calculated from the root bridge.
- Port States: STP assigns ports to specific states to prevent loops.
- Cost: Each link has a cost based on bandwidth (e.g., 10 Mbps = 100, 100 Mbps = 19, 1 Gbps = 4).
STP ports transition through several states:
State | Description |
---|---|
Blocking | Port does not forward frames but listens to BPDUs. Prevents loops. |
Listening | Port listens to BPDUs to ensure no loops exist before transitioning to learning. |
Learning | Port prepares to forward frames by learning MAC addresses but does not forward traffic yet. |
Forwarding | Port forwards frames and processes BPDUs. |
Disabled | Port is administratively shut down. |
-
Elect the Root Bridge:
- The switch with the lowest Bridge ID (BID) becomes the root bridge.
- BID = Priority (default: 32768) + MAC address.
- Example: A switch with priority
32768
and MAC00:1A:2B:3C:4D:5E
has a BID of32768.001A2B3C4D5E
.
-
Determine Root Ports:
- Each non-root switch selects a root port, which is the port with the lowest path cost to the root bridge.
- Path Cost = Sum of the costs of all links along the path.
-
Elect Designated Ports:
- For each network segment, the switch with the lowest path cost to the root bridge becomes the designated switch.
- The port on the designated switch that connects to the segment becomes the designated port.
-
Block Redundant Ports:
- All non-root, non-designated ports are placed in the blocking state to prevent loops.
[Switch A]
/ | \
[Switch B] [Switch C] [Switch D]
- Switch A is elected as the root bridge (lowest BID).
- Switch B, C, and D calculate their root ports based on path cost.
- Switch B and Switch C have a direct link to Switch A, so their connected ports become root ports.
- Switch D has two paths to Switch A: one via Switch B and one via Switch C. The path with the lower cost is chosen as the root port, and the other port is blocked.
STP uses three timers to manage the protocol:
Timer | Default Value | Purpose |
---|---|---|
Hello Timer | 2 seconds | Interval at which BPDUs are sent. |
Forward Delay | 15 seconds | Time spent in the listening and learning states before transitioning to forwarding. |
Max Age | 20 seconds | Maximum time a BPDU can be stored before it is discarded. |
- IEEE 802.1w: An evolution of STP that provides faster convergence.
-
Key Improvements:
- Faster State Transitions: Ports transition directly from blocking to forwarding.
- New Port Roles: Introduces alternate and backup ports for quicker failover.
- No Listening/Learning States: Ports are either discarding, learning, or forwarding.
- IEEE 802.1s: Allows multiple STP instances to run on a single network, enabling load balancing across redundant paths.
- Use Case: Large networks with multiple VLANs.
Switch(config)# spanning-tree mode pvst
- Enables Per-VLAN Spanning Tree (PVST), which runs a separate STP instance for each VLAN.
Switch(config)# spanning-tree vlan 1 priority 24576
- Sets the bridge priority to
24576
for VLAN 1, increasing the chance of this switch becoming the root bridge.
Switch(config-if)# spanning-tree cost 100
- Manually sets the port cost to
100
.
Switch(config-if)# spanning-tree port-priority 64
- Sets the port priority to
64
, influencing which port becomes the designated port.
Switch(config)# spanning-tree mode rapid-pvst
- Enables Rapid PVST+, which is Cisco’s implementation of RSTP.
- STP Loops: Caused by misconfigured or failed STP.
- Slow Convergence: Delays in transitioning ports to forwarding state.
- Root Bridge Misplacement: Suboptimal root bridge location can cause inefficient paths.
-
Check STP Status:
Switch# show spanning-tree
-
View BPDU Information:
Switch# show spanning-tree detail
-
Debug STP Events:
Switch# debug spanning-tree events
- Root Bridge Placement: Place the root bridge at the core of the network for optimal performance.
-
PortFast: Enable PortFast on ports connected to end devices (e.g., servers, workstations) to bypass the listening/learning states.
Switch(config-if)# spanning-tree portfast
-
BPDU Guard: Enable BPDU Guard to shut down ports that receive BPDUs unexpectedly, preventing loops.
Switch(config-if)# spanning-tree bpduguard enable
-
Loop Guard: Use Loop Guard to prevent loops caused by unidirectional link failures.
Switch(config)# spanning-tree loopguard default
Feature | STP (802.1D) | RSTP (802.1w) | MSTP (802.1s) |
---|---|---|---|
Convergence Time | Slow (30-50 seconds) | Fast (sub-second) | Fast (sub-second) |
Port States | Blocking, Listening, Learning, Forwarding | Discarding, Learning, Forwarding | Discarding, Learning, Forwarding |
Port Roles | Root, Designated, Blocked | Root, Designated, Alternate, Backup | Root, Designated, Alternate, Backup |
VLAN Support | One instance per VLAN (PVST+) | One instance per VLAN (Rapid PVST+) | Multiple instances for load balancing |
In a corporate network:
- Core Switch is the root bridge.
- Distribution Switches connect to the core and aggregate traffic from access switches.
- Access Switches connect end devices (e.g., computers, printers).
- STP ensures that if a link fails, traffic is rerouted without creating loops.
- Convergence Time: Traditional STP can take up to 50 seconds to converge, which is slow for modern networks.
- Complexity: Managing STP in large networks can be complex.
- Single Point of Failure: If the root bridge fails, the network must reconverge, which can cause temporary disruptions.
- EtherChannel: Bundles multiple physical links into a single logical link, providing redundancy without STP.
- Shortest Path Bridging (SPB): IEEE 802.1aq standard that provides faster convergence and better scalability than STP.
- STP prevents loops in Ethernet networks by dynamically blocking redundant paths.
- RSTP and MSTP improve convergence time and scalability.
- Best practices like PortFast, BPDU Guard, and Loop Guard enhance STP reliability and security.
- Modern networks often use EtherChannel or SPB to overcome STP limitations.