Skip to content
Feb 25

Net: Spanning Tree Protocol

MT
Mindli Team

AI-Generated Content

Net: Spanning Tree Protocol

In any switched network with redundant paths for resilience, a critical danger lurks: Layer 2 loops. Without a control mechanism, broadcast, multicast, and unknown unicast frames circulate indefinitely, creating broadcast storms that cripple network bandwidth and CPU resources. The Spanning Tree Protocol (STP) is the foundational solution to this problem, dynamically computing a single, loop-free logical path through a physically redundant network. Understanding STP is essential for designing robust, self-healing network infrastructures.

The Core Problem: Layer 2 Loops and Broadcast Storms

Ethernet switches operate at Layer 2 of the OSI model, using MAC addresses to forward frames. Unlike routers, which use protocols to make intelligent path decisions, a basic switch will flood frames out all ports except the ingress port if the destination MAC address is not in its MAC address table. This behavior, combined with physical redundancy, creates a catastrophic loop. A single broadcast frame can be forwarded endlessly between switches, multiplying with each pass until the network is saturated. This is a broadcast storm. STP's sole purpose is to prevent these loops by logically disabling redundant paths, while keeping them physically connected to provide backup in case of a failure.

STP Operation: Building a Loop-Free Tree

STP, defined in the IEEE 802.1D standard, creates a loop-free topology by constructing a spanning tree—a graph that connects all switches without any cycles. It achieves this through a consistent, multi-step process.

1. Root Bridge Election Every STP domain must have a single root bridge (or root switch), which acts as the reference point for all path calculations. The election is based on two values in the Bridge Protocol Data Units (BPDUs) that switches exchange: Bridge Priority and MAC Address. The switch with the lowest Bridge Priority becomes the root. If there's a tie, the switch with the lowest MAC address wins. You can influence this by manually configuring a switch's priority to ensure a core or powerful switch becomes the root.

2. Root Port Selection on Non-Root Bridges Once the root is elected, every other switch must determine its best path to the root bridge. The port on each non-root switch that provides the lowest root path cost to the root becomes its root port. Path cost is an accumulated value based on link bandwidth; lower is better. For example, a 1 Gbps link has a cost of 4, while a 100 Mbps link has a cost of 19 (using revised IEEE costs). The switch calculates the cost by adding the cost of each link along the path, as advertised in BPDUs from the root.

3. Designated Port Election per Segment For each network segment (link between two switches, or a switch and a segment of devices), STP selects one designated port. This is the port responsible for forwarding traffic toward the root bridge on that segment. The switch with the lower root path cost to the root gets its connected port elected as the designated port. If the root path costs are equal, the switch with the lower Bridge ID wins. The root bridge has all its ports in the designated role.

4. Blocking Redundant Paths Any port that is neither a root port nor a designated port is placed into a blocking state. It does not forward user data frames, thus breaking the loop. It still listens to BPDUs to monitor the network topology. The collection of all root and designated ports forms the active, loop-free spanning tree.

STP Port States and Convergence Time

STP ports do not transition directly from blocking to forwarding. They move through a series of states to prevent temporary loops during topology changes:

  • Blocking: No data forwarding, listens for BPDUs.
  • Listening: Builds active topology, no data forwarding, sends/receives BPDUs.
  • Learning: Populates MAC address table, no data forwarding.
  • Forwarding: Normal operation, forwards data.

The time to move from blocking to forwarding is the convergence time. Traditional 802.1D STP uses timers (Forward Delay, typically 15 seconds each for Listening and Learning) resulting in a slow convergence of 30 to 50 seconds. This delay can be unacceptable for modern networks, which led to the development of enhanced protocols.

Evolution: RSTP and MSTP

Rapid Spanning Tree Protocol (RSTP – IEEE 802.1w) was designed to address the slow convergence of STP. RSTP introduces new port roles (Alternate and Backup) and port states (Discarding, Learning, Forwarding). Its key improvements are:

  • Rapid Transition to Forwarding: Uses a proposal/agreement handshake between switches to bypass timer delays on point-to-point links, allowing near-instantaneous forwarding.
  • No Timer-Based Waiting: Convergence is typically sub-second, as it relies on physical link changes and BPDU timeouts rather than long timers.

Multiple Spanning Tree Protocol (MSTP – IEEE 802.1s) builds upon RSTP. It allows you to map multiple VLANs into a reduced number of MST instances, each with its own spanning tree topology. This enables load balancing of traffic across different redundant links (e.g., one tree forwards traffic for VLANs 10-20 on Link A, while another tree forwards VLANs 30-40 on Link B), a capability lacking in the single-instance STP/RSTP.

Designing Redundant Switched Networks

When designing a network with STP, follow these principles:

  1. Manually Set the Root Bridge: Always configure a primary and secondary root bridge by adjusting bridge priorities. This prevents an undesirable, low-capacity switch from being elected root.
  2. Use RSTP or MSTP: Avoid classic 802.1D STP in all new designs. Use RSTP for simplicity and fast convergence in smaller networks. Use MSTP in larger, VLAN-rich environments to utilize all available uplinks.
  3. Understand Your Physical Topology: The logical STP topology is dictated by the physical cabling and root placement. A hierarchical design (Core -> Distribution -> Access) simplifies STP operation and troubleshooting.
  4. Plan for Link Utilization: With MSTP, design your VLAN-to-instance mappings to evenly distribute traffic across available redundant paths.

Common Pitfalls

Pitfall 1: Unplanned Root Bridge Election Letting switches auto-elect the root based on default priority (32768) and MAC address often places the root on an access-layer switch with poor uplink capacity, causing suboptimal data paths.

  • Correction: Always statically configure the root and secondary root on core or distribution layer switches using the spanning-tree vlan [id] root primary and root secondary commands or by setting explicit priorities.

Pitfall 2: Misunderstanding PortFast on Access Ports Applying the PortFast feature (which bypasses listening/learning states) to a port connected to another switch can create a bridging loop, as that port will go straight to forwarding.

  • Correction: Enable PortFast only on ports connected to end devices like PCs, servers, or printers. On Cisco switches, also enable BPDU Guard on these ports, which will err-disable the port if a switch BPDU is received, preventing a loop.

Pitfall 3: Ignoring UplinkFast/BackboneFast in Legacy STP In networks still running classic STP, not using complementary features like UplinkFast (for access switches) and BackboneFast (for faster convergence on indirect link failures) leads to unnecessarily long outages.

  • Correction: The definitive correction is to migrate to RSTP/MSTP. If stuck with STP, ensure UplinkFast is enabled on access-layer switches and BackboneFast is enabled on all switches.

Pitfall 4: Incorrect MST Region Configuration For MSTP to work, all switches must have the same MST configuration name, revision number, and VLAN-to-instance mapping. Mismatches cause switches to treat each other as being in separate STP domains, potentially creating loops.

  • Correction: Carefully plan and consistently apply the MST region configuration (spanning-tree mst configuration) across all switches in the desired region.

Summary

  • STP's primary function is to prevent Layer 2 loops and the resulting broadcast storms by logically disabling redundant paths in a switched network.
  • It operates by electing a single root bridge, having each switch select a root port for its best path to the root, and electing designated ports on each segment, with all other ports blocked.
  • Classic 802.1D STP has slow convergence (30-50 seconds) due to timer-based port state transitions, making it unsuitable for modern networks.
  • RSTP (802.1w) provides dramatically faster convergence, often under one second, through a proposal/agreement handshake and simplified states.
  • MSTP (802.1s) extends RSTP by allowing multiple spanning tree instances, enabling load balancing of VLAN traffic across different redundant links for efficient network design.

Write better notes with AI

Mindli helps you capture, organize, and master any subject with AI-powered summaries and flashcards.