Spanning Tree Port Cost Configuration and Pathcost Method
Table of Contents
Jump to section:
- • What is STP cost?
- • What is pathcost method?
- • How to configure STP cost?
- • How to configure PVST cost for different VLANs?
- • How to configure MST cost for different instances?
- • STP path cost calculation with Port-Channel interface
- • Configuring pathcost method long and interoperation
- • Download section
- What is STP cost? ‹
- What is pathcost method? ‹
- How to configure STP cost? ‹
- How to configure PVST cost for different VLANs? ‹
- How to configure MST cost for different instances? ‹
- STP path cost calculation with Port-Channel interface ‹
- Configuring pathcost method long and interoperation ‹
- Download section ‹
What is STP cost?
The Spanning Tree Protocol (STP) assigns a cost to every interface depending on its speed. A higher speed means a lower STP cost. Switches assign an interface cost in order to find and agree on the best path to reach the root bridge. When presented with multiple paths a switch prefers a lower cost path to reach the root bridge. This way a tree topology can emerge with the root bridge at its center.
Switches learn about the cost to reach the root bridge from BPDUs. A Bridge Protocol Data Unit (BPDU) is an STP control plane message exchanged in a Layer-2 switched network to create a loop-free topology. There is a field in the BPDU called Root Path Cost which is incremented by each switch that forwards a BPDU originated by the root bridge. The Root Path Cost is the sum of all the port costs along the way to reach the root bridge. The following packet capture shows a BPDU with the Root Path Cost field.
What is pathcost method?
STP cost is independent of the protocol mode being used, whether STP, RSTP or MST. There are however two options to represent the cost value. The interface cost can be determined with either a 16-bit or a 32-bit value. The 16-bit value is called short pathcost method. The 32-bit value is called long pathcost method. These two variants of cost can be used for any STP mode. By default, a short pathcost method assigns the following values:
| Interface | Cost |
|---|---|
| 10 Gbps | 2 |
| 1 Gbps | 4 |
| 100 Mbps | 19 |
Compared to the short method, a long pathcost method provides more possible values when assigning costs. This is especially useful when determining the cost of links above 10 Gbps. By default, a long pathcost method provides the following values:
| Interface | Cost |
|---|---|
| 10 Gbps | 2000 |
| 1 Gbps | 20000 |
| 100 Mbps | 200000 |
How to configure STP cost?
In the following example scenario SW2 is the STP root bridge. SW3 and SW4 use STP cost to manually assign which interface gets chosen as the root port. VLAN 10 and VLAN 20 are configured in this topology, and only these VLANs are allowed on the trunk links connecting the switches. The spanning tree cost configuration on the interfaces applies to both VLANs at the same time, thus creating a single topology.
Configuration:
SW1
SW1#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to SW3 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW4 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run | sec ^spanning spanning-tree mode pvst spanning-tree extend system-id spanning-tree pathcost method long spanning-tree vlan 1,10,20 priority 28672
SW2
SW2#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to SW4 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW3 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run | sec ^spanning spanning-tree mode pvst spanning-tree extend system-id spanning-tree pathcost method long spanning-tree vlan 1,10,20 priority 24576
SW3
SW3#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to Host1 ** switchport access vlan 10 switchport mode access negotiation auto SW3#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree cost 100 SW3#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree cost 50 SW3#show run | sec ^spanning spanning-tree mode pvst spanning-tree extend system-id spanning-tree pathcost method long
SW4
SW4#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to Host2 ** switchport access vlan 10 switchport mode access negotiation auto SW4#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree cost 50 SW4#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree cost 100 SW4#show run | sec ^spanning spanning-tree mode pvst spanning-tree extend system-id spanning-tree pathcost method long
SW3#show spanning-tree interface Gi0/1 Vlan Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- VLAN0010 Altn BLK 100 128.2 P2p « Higher cost link is in blocking state for both VLANs VLAN0020 Altn BLK 100 128.2 P2p SW3#show spanning-tree interface Gi0/2 Vlan Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- VLAN0010 Root FWD 50 128.3 P2p VLAN0020 Root FWD 50 128.3 P2p Host1:~$ ping 192.168.1.2 -c 3 PING 192.168.1.2 (192.168.1.2): 56 data bytes 64 bytes from 192.168.1.2: seq=0 ttl=42 time=2.989 ms 64 bytes from 192.168.1.2: seq=1 ttl=42 time=3.477 ms 64 bytes from 192.168.1.2: seq=2 ttl=42 time=3.516 ms --- 192.168.1.2 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 2.989/3.327/3.516 ms
How to configure PVST cost for different VLANs?
In this example scenario separate STP topologies are created for VLAN 10 and VLAN 20 using Per VLAN Spanning Tree (PVST). This is achieved by assigning different cost values for each VLAN on the trunk interfaces of SW3 and SW4. Also, SW1 is the root bridge for VLAN 10, and SW2 is the root bridge for VLAN 20. With this method the traffic in both VLANs is evenly distributed in the network.
Configuration:
SW1
SW1#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to SW3 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW4 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run | sec ^spanning spanning-tree mode pvst spanning-tree extend system-id spanning-tree pathcost method long spanning-tree vlan 10 priority 20480 spanning-tree vlan 20 priority 28672
SW2
SW2#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to SW4 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW3 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run | sec ^spanning spanning-tree mode pvst spanning-tree extend system-id spanning-tree pathcost method long spanning-tree vlan 10 priority 28672 spanning-tree vlan 20 priority 24576
SW3
SW3#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to Host1 ** switchport access vlan 10 switchport mode access negotiation auto SW3#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree vlan 10 cost 50 spanning-tree vlan 20 cost 100 SW3#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree vlan 10 cost 100 spanning-tree vlan 20 cost 50 SW3#show run | sec ^spanning spanning-tree mode pvst spanning-tree extend system-id spanning-tree pathcost method long
SW4
SW4#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to Host2 ** switchport access vlan 20 switchport mode access negotiation auto SW4#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree vlan 10 cost 50 spanning-tree vlan 20 cost 100 SW4#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree vlan 10 cost 100 spanning-tree vlan 20 cost 50 SW4#show run | sec ^spanning spanning-tree mode pvst spanning-tree extend system-id spanning-tree pathcost method long
SW3#show spanning-tree int Gi0/1 Vlan Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- VLAN0010 Root FWD 50 128.2 P2p « Different VLANs have different cost assigned on same interfaces VLAN0020 Desg FWD 100 128.2 P2p SW3#show spanning-tree int Gi0/2 Vlan Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- VLAN0010 Desg FWD 100 128.3 P2p VLAN0020 Root FWD 50 128.3 P2p SW1#show spanning-tree root Root Hello Max Fwd Vlan Root ID Cost Time Age Dly Root Port ---------------- -------------------- --------- ----- --- --- ------------ VLAN0001 32769 5254.001a.3bfe 0 2 20 15 VLAN0010 20490 5254.001a.3bfe 0 2 20 15 « SW1 is root for VLAN10 VLAN0020 24596 5254.0002.099c 20000 2 20 15 Gi0/2 SW2#show spanning-tree root Root Hello Max Fwd Vlan Root ID Cost Time Age Dly Root Port ---------------- -------------------- --------- ----- --- --- ------------ VLAN0001 32769 5254.0002.099c 0 2 20 15 VLAN0010 20490 5254.001a.3bfe 20000 2 20 15 Gi0/2 VLAN0020 24596 5254.0002.099c 0 2 20 15 « SW2 is root for VLAN20
How to configure MST cost for different instances?
In the following example topology Multiple Spanning Tree (MST) is configured with one region and two instances. VLAN 10 is assigned to instance 1, and VLAN 20 is assigned to instance 2. Thus, MST converges in two topologies with SW1 being the root bridge for instance 1, and SW2 the root bridge for instance 2. Note that MST also converges in the Internal Spanning Tree (IST) which is MST instance 0.
Configuration:
SW1
SW1#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to SW3 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW4 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW1#show run | sec ^spanning spanning-tree mode mst spanning-tree extend system-id spanning-tree pathcost method long spanning-tree mst configuration name EXAMPLE-MST revision 1 instance 1 vlan 10 instance 2 vlan 20 spanning-tree mst 1 priority 24576 spanning-tree mst 2 priority 28672
SW2
SW2#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to SW4 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW3 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto SW2#show run | sec ^spanning spanning-tree mode mst spanning-tree extend system-id spanning-tree pathcost method long spanning-tree mst configuration name EXAMPLE-MST revision 1 instance 1 vlan 10 instance 2 vlan 20 spanning-tree mst 1 priority 28672 spanning-tree mst 2 priority 24576
SW3
SW3#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to Host1 ** switchport access vlan 10 switchport mode access negotiation auto SW3#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree mst 1 cost 50 spanning-tree mst 2 cost 100 SW3#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree mst 1 cost 100 spanning-tree mst 2 cost 50 SW3#show run | sec ^spanning spanning-tree mode mst spanning-tree extend system-id spanning-tree pathcost method long spanning-tree mst configuration name EXAMPLE-MST revision 1 instance 1 vlan 10 instance 2 vlan 20
SW4
SW4#show run int Gi0/0 | sec int interface GigabitEthernet0/0 description ** to Host2 ** switchport access vlan 20 switchport mode access negotiation auto SW4#show run int Gi0/1 | sec int interface GigabitEthernet0/1 description ** to SW2 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree mst 1 cost 100 spanning-tree mst 2 cost 50 SW4#show run int Gi0/2 | sec int interface GigabitEthernet0/2 description ** to SW1 ** switchport trunk allowed vlan 10,20 switchport trunk encapsulation dot1q switchport mode trunk negotiation auto spanning-tree mst 1 cost 50 spanning-tree mst 2 cost 100 SW4#show run | sec ^spanning spanning-tree mode mst spanning-tree extend system-id spanning-tree pathcost method long spanning-tree mst configuration name EXAMPLE-MST revision 1 instance 1 vlan 10 instance 2 vlan 20
SW3#show spanning-tree interface Gi0/1 Mst Instance Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- MST0 Desg FWD 20000 128.2 P2p MST1 Root FWD 50 128.2 P2p « Two MST instances have different cost assigned MST2 Desg FWD 100 128.2 P2p SW3#show spanning-tree interface Gi0/2 Mst Instance Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- MST0 Root FWD 20000 128.3 P2p MST1 Desg FWD 100 128.3 P2p MST2 Root FWD 50 128.3 P2p SW1#show spanning-tree root Root Hello Max Fwd MST Instance Root ID Cost Time Age Dly Root Port ---------------- -------------------- --------- ----- --- --- ------------ MST0 32768 5254.0002.099c 0 2 20 15 Gi0/2 MST1 24577 5254.001a.3bfe 0 2 20 15 « SW1 is root bridge for MST instance 1 MST2 24578 5254.0002.099c 20000 2 20 15 Gi0/2 SW2#show spanning-tree root Root Hello Max Fwd MST Instance Root ID Cost Time Age Dly Root Port ---------------- -------------------- --------- ----- --- --- ------------ MST0 32768 5254.0002.099c 0 2 20 15 MST1 24577 5254.001a.3bfe 20000 2 20 15 Gi0/2 MST2 24578 5254.0002.099c 0 2 20 15 « SW2 is root bridge for MST instance 2
STP path cost calculation with Port-Channel interface
STP uses the speed of an interface to assign a port cost value. The path cost to the root bridge is calculated by adding up the port cost values of the interfaces along the way. Pathcost method short is used in the following sample topology. By default, a 1 Gbps interface has a cost of 4. A 2 Gbps PortChannel interface has a default STP cost of 3.
SW2#show spanning-tree root Root Hello Max Fwd Vlan Root ID Cost Time Age Dly Root Port ---------------- -------------------- --------- ----- --- --- ------------ VLAN0001 24577 5254.000d.955a 3 2 20 15 Po1 « Port-channel on SW2, STP cost 3 VLAN0010 24586 5254.000d.955a 3 2 20 15 Po1 VLAN0020 24596 5254.000d.955a 3 2 20 15 Po1 SW8#show spanning-tree pathcost method Spanning tree default pathcost method used is short « Pathcost method short on SW8 SW8#show spanning-tree root Root Hello Max Fwd Vlan Root ID Cost Time Age Dly Root Port ---------------- -------------------- --------- ----- --- --- ------------ VLAN0001 24577 5254.000d.955a 11 2 20 15 Gi0/1 « Path cost to root bridge is 11 VLAN0010 24586 5254.000d.955a 11 2 20 15 Gi0/1 SW8#show spanning-tree interface Gi0/1 Vlan Role Sts Cost Prio.Nbr Type ------------------- ---- --- --------- -------- -------------------------------- VLAN0001 Root FWD 4 128.2 P2p « 1 Gbps interface cost is 4 VLAN0010 Root FWD 4 128.2 P2p
Configuring pathcost method long and interoperation
Selecting the pathcost method "long" allows for a more refined STP cost assignment and including unique value calculations for links above 10 Gbps. The pathcost method long uses a 32-bit STP cost value, in contrast to the 16-bit value used with the "short" pathcost method.
When the STP pathcost method long is configured on SW8, an assigned speed of 100 Mbps on interface Gi0/1 (towards SW5) is automatically given a cost value of 200000. As a result, a new root port is selected. The new root port on SW8 becomes Gi0/0 (towards SW4), which has a statically configured cost of 20, and a root path cost of 27. It is a best practice to choose either long or short pathcost method throughout a Layer-2 switched network to avoid such a scenario.