Spanning Tree Election Recap
Before we jump into how Spanning Tree determines the root port on a switch, we first need to review where this fits into the STP convergence process.
|Elect root switch||Switch with the lowest Bridge ID (2-byte priority + MAC) is elected as Root.|
|Determine Root Port on each non-root switch||Each non-root switch decides which one port will become the Root Port. The Root Port is the port that receives the superior BPDU among all the ports.|
|Determine designated port for each segment||The designated port is the switch port that forwards the superior BPDU from the Root Bridge across the segment to neighbor switches.|
Step 1: The Root Bridge is elected
One switch is elected to act as the Root Bridge. For a detailed rundown, check out STP BPDUs and Root Bridge Election.
Step 2: Root ports are determined on all non-root bridges
Each non-root bridge is assigned a single root port. More on this shortly.
Step 3: Designated ports are selected
Each segment has a single designated port. Designated ports are chosen from non-root ports that have the lowest path cost to the root bridge.
Path Cost vs. Root Path Cost
We also need to define two confusing terms related to STP costs, Path Cost and Root Path Cost.
STP Path Cost – A local value (not advertised to adjacent switches) assigned to each switch port. Path cost is based on port speed where faster ports have lower path costs.
STP Root Path Cost – A cumulative value based on the additive cost to the Root Bridge. Advertised to downstream switches in each BPDU forwarded from the Root Bridge.
Root Port Decision Process
After the Root Bridge has been elected, the next step is for each non-root switch to select exactly one port that should be used as its Root Port. The Root Port is the port that provides the least-cost path to reach the Root Bridge. Root Ports are determined on non-root switches using the following process.
- The Root Bridge sends Hellos in the form of BPDUs every 2 seconds. The hellos contain the local Root Bridge ID and a Root Port Cost (RPC) set to 0.
- Each non-root switch that receives the root’s Hello BPDUs adds their receiving port’s STP port cost to the Root Port Cost value seen in the Hello. If the Hello BPDU is superior to all other received Hellos (it has the lowest priority), then the port the superior BPDU was received on is selected as the Root Port.
- If the same superior BPDU is received on more than one port, the port with the lowest Root Path Cost is selected as the Root Port.
- After the downstream, non-root switch receives the BPDU on its root port, it forwards the BPDU out its remaining designated ports. Before it goes out, the Root Path Cost is updated. Other Hello BPDUs received on the switch’s non-root ports will be processed, but not forwarded.
Using this process, each non-root switch is able to select a single Root Port because one received Hello BPDU will always be superior to the others. By superior, we mean it contains the lowest Root Bridge ID. The port it was received on stabilizes into the Root Port. The Root port will always provide the lowest cost path (Root Path Cost) to the switch with the lowest Bridge ID (Root Bridge).
It is not uncommon to have multiple paths back to the Root Bridge with the same Root Path Cost, especially in networks that use the same speed 1Gb or 10Gb switch interconnects between all switches. Equal-cost paths will also come into play when two switches have multiple individual connections between the them using the same speed interfaces.
When there are multiple equal-cost paths to the Root Bridge, the following will determine the Root Port:
- Choose the port connected to the neighbor switch with the lowest sender Bridge ID. If there are two different neighbor switches, this will break the tie since the Bridge IDs will be unique.
- If the neighbor Bridge ID is equal (multiple links to the same upstream neighbor), then choose the port connected to the neighbor’s lowest port ID. Note that the tiebreaker is based on the sender’s lowest connected port ID, not the local switch port IDs.
Spanning Tree Path Costs
Spanning Tree Path Costs are determined by port speeds, where higher speed ports are assigned lower cost values by default. Spanning Tree makes forwarding path decisions based these port cost values. That means STP uses the logical shortest path, not necessarily the physically shortest path! Spanning Tree will always choose multiple, higher speed links to the root over even a directly physical connection if the total cost is lower.
It’s a common mistake to associate STP costs to each segment. If you followed the decision process above, you’ll notice that the cost is actually tied to each interface. Good design normally dictates using the same cost values on both ends of a point-to-point link, but understand they can be different.
The default Spanning Tree cost values defined the IEEE has evolved over the years. The early versions were not able to distinguish between 1G and 10G links, so the default cost reference values were gradually increased to accommodate the rapid growth in Ethernet media speeds.
Original IEEE 802.1D Cost
IEEE 802.1D-1998 Cost
IEEE 802.1D-2004 Cost
Cisco switches running PVST or Rapid PVST still use the 802.1D-1998 default cost values. Cisco switches running MST use the latest 802.1D-2004 revision.The 802.1D-2004 default cost reference values can be enabled while running PVST or Rapid PVST by issuing the spanning-tree pathcost method long command from global configuration mode. Otherwise, spanning-tree pathcost method short is configured by default.
Port Cost Configuration
Before we dive into how to modify the default port costs, it is important that you understand that making manual cost changes can have unintended consequences. Changing local port costs on one switch will change the cumulative Root Path Cost for downstream switches and may drastically change the forwarding path in your network. With that disclaimer out of the way, let’s get into it.
In the output below, SW1 shows two equal-cost paths to SW2 over interfaces Gi1/0/22 and Gi1/0/24. Both are assigned a default cost value of 4 with Gi1/0/23 in the forwarding state.
Configuring Port Cost For All VLANs
The interface-level command spanning-tree cost
In the example below, we lower the port cost on interface Gi1/0/24 to 2 for all VLANs. The output shows the interface immediately transition to the listening state, then learning, before becoming the forwarding path to the root.
Configuring Port Cost For Specific VLANs
The interface-level command spanning-tree VLAN
After lowering the port cost on Gi1/0/24 in the previous example, the output shows that it is still forwarding for all VLANs, including VLAN 20.
In the example below, we raise the port cost on interface Gi1/0/24 to 10 for VLAN 20 only.
Now interface Gi1/0/23 is the lower cost path and transitioned to forwarding.
If we look at VLAN 10 on the same port, notice that Gi1/0/24 is still the lowest cost path and is still forwarding.
These examples are to show you the power and forwarding flexibility that can be achieved by properly modifying STP port costs for one or more VLANs. Use caution when performing similar changes in a real network and make sure you understand all the downstream forwarding changes that may result. If the Root Bridge is correctly selected in a sound network design, port costs rarely require manual changes.
Designated Port Decision Process
After the Root Bridge is elected, the Hello BPDUs it sends out every two seconds are forwarded by all connected switches throughout the network. These BPDUs are considered “superior” because they contain the lowest Bridge ID (they must by definition since they are coming from the Root Bridge). This means that every segment on the network will eventually receive the continuous stream of superior Hello BPDUs from the root.
Now to the Designated Port. The switch port on each LAN segment that forwards the superior Hellos onto the segment is considered the Designated Port. In most cases, this is the port on the opposite end of the link as the Root Port for each segment.
Consider the segment between SW2 and SW4 below. Before the Designated Port has been decided, SW4 receives Hello BPDUs from SW3, calculates its own cost to the root using that path, then forwards the Hello BPDU to SW2 with a Root Path Cost of 38. SW2 goes through the same process – receiving its superior Hello BPDU from SW1 (the root), adding its cost using the same path back, then forwarding the BPDU to SW4 with a total Root Path Cost of 100.
SW4’s port will become the Designated Port on the segment since it is sending the “superior” BPDU (its Root Path Cost is lower than SW2’s). After it is decided that SW4’s port is designated, SW4 will continue to send the BPDUs onto the segment while SW2 will stop.
Only designated ports send BPDUs onto a segment (all ports on the Root Bridge are designated). Root Ports and ports in the blocking state do not send BPDUs. If the cost back to the Root Bridge is equal and a Designated Port tiebreaker is required, the neighboring switch with the lowest Bridge ID (priority + MAC) will win.