Sub topic 6
Port roles in the spanning tree
This chapter assumes you already know how a switch learns MAC addresses, how broadcast and unknown-unicast flooding work, and what a VLAN and a trunk are. It also assumes you can read a switch command line. It builds on the root bridge election: once every switch agrees on one root, each switch must decide what to do with each of its ports. That decision is the port role.
Why roles exist
Spanning tree turns a looped physical topology into a loop-free logical tree. To do that, it does not remove links. It assigns each port a role, and the role decides whether the port may forward user traffic.
Every port on a switch that is running 802.1D or 802.1w ends up in exactly one of these roles for each spanning tree instance:
| Role | Where it is found | Forwards user traffic? | Receives BPDUs? |
|---|---|---|---|
| Root port | Every non-root switch, exactly one | Yes | Yes |
| Designated port | One per network segment | Yes | Sends them |
| Alternate port | Non-root switch, backup path to root | No | Yes |
| Backup port | Switch with two ports on one segment | No | Yes |
| Disabled | Shut down or not participating | No | No |
A BPDU is a Bridge Protocol Data Unit, the control message that switches use to describe the topology to each other. Roles are computed from the BPDUs a port sends and receives.
The alternate and backup roles are named in 802.1w (Rapid STP). Classic 802.1D simply calls both of them "non-designated" or "blocking". The logic is the same. Rapid STP gives them names because it uses them to switch over faster.
Root port
The root port is the single port on a non-root switch that has the best path toward the root bridge. The root bridge itself has no root port, because it is already at the root.
"Best path" is measured by root path cost. This is the sum of the port costs along the way, counted on the receiving side of each link. A switch adds the cost of its own receiving port to the cost advertised in the BPDU it receives.
For example, take a switch SW3 with two uplinks. One goes to the root over a Gigabit link, and one goes to another switch over a Fast Ethernet link. The root path cost through the Gigabit link is lower, so that port becomes the root port.
Designated port
A segment is a link, or a shared medium, between ports. Each segment has exactly one designated port. This is the port on that segment with the best path to the root, and it is the one that forwards frames toward the segment and sends BPDUs onto it.
Two points follow from this:
- Every port on the root bridge is a designated port, because the root bridge has the lowest root path cost (zero) on each of its segments.
- On a point-to-point link between two switches, one end is designated and the other end is either a root port or a blocked port.
Alternate and backup ports
A port that is neither root nor designated is blocked. The two blocked roles describe why it is blocked.
An alternate port receives a better BPDU from a different switch. It is a standby path to the root. If the root port fails, the alternate port can take over.
A backup port receives a better BPDU from its own switch, which happens when two ports of one switch connect to the same segment, for example through a hub. It is a standby for a designated port. Backup ports are rare on modern networks, which use point-to-point links.
Worked example
Consider three switches in a triangle. SW1 is the root. Every link is Gigabit Ethernet, and the 802.1D cost for 1 Gbps is 4.
The diagram below shows the result of role selection.
Work through it in order:
- SW1 is the root, so both of its ports are designated.
- SW2 receives a BPDU from SW1 with root path cost 0. Its cost to the root through Gi0/1 is 0 + 4 = 4. Through Gi0/2 (via SW3) it would be 4 + 4 = 8. Gi0/1 is the root port.
- SW3 does the same calculation and picks Gi0/1 as its root port, with cost 4.
- The SW2 to SW3 link needs one designated port. Both ends advertise a root path cost of 4. The tie goes to the lower bridge ID, so if SW2 has the lower bridge ID, SW2 Gi0/2 is designated.
- SW3 Gi0/2 is not a root port and not designated. It receives a better BPDU from another switch, so it is an alternate port and blocks.
The tree now has no loop: SW1 connects to SW2 and SW3, and the SW2-SW3 link carries no user traffic.
How a port decides its role
Role selection compares BPDUs using a fixed order of tie-breakers. The next chapter covers the full procedure. For this chapter, remember the order of the values being compared:
- Lowest root bridge ID
- Lowest root path cost
- Lowest sender bridge ID
- Lowest sender port ID
The root port is chosen by comparing the best BPDUs received on each of the switch's own ports. A designated port is chosen by comparing the BPDU a port would send against the BPDU it receives on that segment. Whichever is better wins the segment.
Seeing roles on a switch
On Cisco IOS, the show spanning-tree command lists the role and state of every port:
show spanning-tree vlan 10A trimmed result for SW3 in the example looks like this:
Interface Role Sts Cost Prio.Nbr Type
------------------- ---- --- --------- -------- --------------------
Gi0/1 Root FWD 4 128.1 P2p
Gi0/2 Altn BLK 4 128.2 P2pThe Role column shows Root, Desg, Altn or Back. The Sts column shows the state: FWD for forwarding, BLK for blocking, and under classic STP also LIS and LRN. The role and the state are separate ideas. The role is the decision, and the state is what the port is doing now. A port can have the right role but not yet be forwarding while a timer runs.
On a Linux bridge, bridge link show lists each port with its state, and ip -d link show br0 shows the bridge settings.
Common errors
- Assuming a blocked port is dead. An alternate port still receives BPDUs. If BPDUs stop arriving, it can change role and start forwarding, which is how a failure is repaired. It is also how a loop appears if BPDUs are lost on a link that is still passing data.
- Expecting every link to forward. In a redundant design, some ports must block. A switch where all uplinks forward is a sign that spanning tree is off or misconfigured.
- Confusing role with state. "Designated" does not mean "forwarding". Under classic STP, a new designated port moves through listening and learning first.
- Counting cost on the wrong side. Root path cost accumulates on the receiving port as BPDUs travel away from the root. Changing the cost on the sending port of a link does not alter the path the neighbor chooses.
- Looking at one VLAN. With per-VLAN spanning tree, roles are per VLAN. A port can be a root port in VLAN 10 and an alternate port in VLAN 20.
Exercise
A non-root switch has two ports on the same segment, connected to a hub, and a third port that leads to the root bridge. Port Gi0/1 and Gi0/2 are on the hub segment, and Gi0/3 goes to the root bridge with the lowest root path cost. Gi0/1 has a lower port ID than Gi0/2. What roles do the three ports take, and why?
Show answer
Gi0/3 is the root port because it has the best path to the root. On the hub segment, the switch's own two ports compete to be the designated port. Both send the same root path cost and the same bridge ID, so the lower port ID breaks the tie. Gi0/1 becomes the designated port. Gi0/2 receives a BPDU from its own switch's Gi0/1, which is a better BPDU from the same bridge, so it becomes a backup port and blocks.
Exercise
In the three-switch triangle from this chapter, the SW1-SW3 link fails. Which port changes role, and what does it become?
Show answer
SW3 Gi0/2, the alternate port, loses nothing but gains a new job. It becomes the root port for SW3, because it is now the only path to the root, with a root path cost of 8 (4 from SW2 plus 4 for the receiving port). SW2 Gi0/2 stays designated and begins forwarding to SW3. Under Rapid STP this takes about a second or less. Under classic 802.1D the port must pass through listening and learning first, which takes roughly 30 seconds, and it may wait for max age to expire first.