Spanning Tree is a protocol that prevents loop formation by detecting redundant links and disabling them until needed. Designers can therefore build redundant links and the protocol will allow one to pass traffic and keep the other in reserve. When the active link fails, the secondary link is enabled quickly.
Understanding the Spanning Tree Protocol
Switches either forward or filter Layer 2 frames. The way they make the forwarding/filtering decision can lead to loops in a network with redundant links. Spanning Tree is a protocol that detects potential loops and breaks them.
A Layer 2 switch is functionally the same thing as a transparent bridge. Transparent bridges:
- Learn MAC (Media Access Control) addresses by looking at the source address of incoming frames. They build a table mapping MAC address to port number.
- Forward broadcasts and multicasts out all ports except the on which they came. (This is called flooding.)
- Forward unknown unicasts out all ports except the one on which they came. An unknown unicast is a message bound for a unicast MAC address that is not in the switch’s table of addresses and ports.
- Do not make any changes to the frames as they forward them.
Spanning Tree must select:
- One root bridge
- One root port per nonroot bridge
- One designated port per network segment
Spanning Tree Election Criteria
Spanning Tree builds paths out from a central point along the fastest available links. It selects path according to the following criteria:
1. Lowest root bridge ID (BID)
2. Lowest path cost to the root
3. Lowest sender bridge ID
4. Lowest sender port ID (PID)
When reading the path selection criteria, remember the following:
- Bridge ID—Bridge priority: Bridge MAC address.
- Bridge priority—2-btye value, 0–65,535 (0–0xFFFF).
- Default priority is 32,768 (0x8000).
- Port ID—Port priority: port number.
- Port priority—A 6-bit value, 0–63, default is 32.
- Path cost—This is the cumulative value of the cost of each link between the bridge and the root. Cost values were updated in 2000 and you should see only new cost values, but both are given in the following table (see Table 3-1). Old and new switches work together.
The STP Election
Spanning Tree builds paths out from a starting point, the “root” of the tree. The first step in selecting paths is to identify this root device. Then, each device selects its best path back to the root, according to the criteria laid out in the previous sections (lowest root BID, lowest cost, lowest advertising BID, lowest port).
Root Bridge Election
Looking at Figure 3-1, first select the root bridge. Assume each switch uses the default priority.
- Switch A BID = 80-00-00-0c-11-11-00-11
- Switch B BID = 80-00-00-0c-26-78-10-10
- Switch C BID = 80-00-00-0c-32-1a-bc-de
- Switch D BID = 80-00-00-0c-81-81-11-22
- Switch E BID = 80-00-00-0c-26-79-22-22
Root Port Election
The root port is the port that leads back to the root. Continuing with Figure 3-1, once A is acknowledged as the root, the remaining bridges sort out their lowest cost path back to the A.
- Switch B—Uses the link to A with a cost of 19 (link speed of 100 Mbps).
- Switch C—The connected link has a cost of 100 (Ethernet), the link through B has a path cost of 38 (two 100 Mbps links), and so B is chosen.
- Switch D—The link through B has a path cost of 119, the path cost through C to A is 119, the path through C then B is 57, so C is chosen.
- Switch E—The lowest path cost is the same for both ports (76 through D to C to B to A). Next check sender BID—sender for both ports is D, so that it does not break the tie. Next check sender Port ID. Assuming default port priority, the PID for 0/1 is lower than the PID for 0/2, so the port on the left is the root port.
Designated Port Election
Designated ports are ports that lead away from the root. Obviously, all ports on the root bridge are designated ports (A-B and A-C in Figure 3-1).
- Segment B-D—B has the lowest path cost to root (19 vs 119), so it is designated for this segment.
- Segment C-D—C has the lowest path cost to the root (100 vs 119), so it is designated for this segment.
- Segment B-C—B has the lowest path cost to the root (19 vs 100), so it is designated for this segment.
- Both segments D-E—D has the lowest cost to the root (57 vs 76), so it is designated for both segments.
Bridge Protocol Data Units (BPDUs)
Switches exchange BPDUs. There are two types of BPDUs:
Configuration and Topology Change (TCN).
Configuration BPDUs are sent every two seconds from the root toward the downstream switches. They:
- Are used during an election.
- Maintain connectivity between switches.
- Send timer information from the root.
TCN BPDUs are sent toward the root when:
- There is a link failure.
- A port starts forwarding, and there is already a designated port.
- The switch receives a TCN from a neighbor.
When a switch receives a TCN BPDU, it acknowledges that with a configuration BPDU that has the TCN Acknowledgment bit set.
When the root bridge receives a TCN, it starts sending configuration BPDUs with the TCN bit set for a period of time equal to max age plus forward delay. Switches that receive this change their MAC table aging time to the Forward Delay time, causing MAC addresses to age faster. The topology change also causes an election of the root bridge, root ports, and designated ports.
BPDU Fields
Some of the fields in the BPDU include:
- Root bridge ID—The BID of the current root.
- Sender’s root path cost—The cost to the root.
- Sender’s bridge ID—Sender’s priority concatenated to MAC.
- Sender’s port ID—The port number, transmitted as final tiebreaker.
- Hello time—Two seconds by default.
- Forward Delay—15 seconds by default.
- Max Age—20 seconds by default.
Spanning Tree Port States
When a port is first activated, it transitions through the following stages shown in Table 3-2.
Designing for Spanning Tree
To optimize data flow in the network, design and configure switches for the following STP roles:
- Primary and secondary root bridges (set priority values)
- Designated and root ports (set port priorities/path cost)
- Enable STP enhancements, such as Root Guard