Simple: it calculates the lowest port-priority by looking at the interface number of the upstream switch or bridge. If we have two ports connected to the same upstream bridge then the local port connected to the interface of the upstream bridge having the lowest number will have lower port-priority and thus will be elected as root port assuming that they have equal cost and same bridgeID.
Spanning-tree looks at three things to determine the root port and alternate port and the port-priority is at third place.
- Cost: Lower is better. So the port with the lower cost to reach the root bridge will be elected as root port.
- BridgeID: If the cost is tie, then it will look for the lowest bridgeID upstream.
- Port-Priority: If the upstream bridgeID is the same, meaning that both ports are connected to the same upstream bridge then it will look for the lowest Port-Priority of the upstream bridge.
Now Port-Priority number of the upstream bridge can be found by issuing the following command.
SW1(config)#do show spanning-tree vlan 1 detail VLAN0001 is executing the rstp compatible Spanning Tree protocol Bridge Identifier has priority 32768, sysid 1, address 0051.cf8d.7c01 Configured hello time 2, max age 20, forward delay 15, transmit hold-count 6 Current root has priority 32768, address 0053.cf8d.7c03 Root port is 3 (GigabitEthernet0/2), cost of root path is 4 Topology change flag not set, detected flag not set Number of topology changes 14 last change occurred 00:57:20 ago from GigabitEthernet0/2 Times: hold 1, topology change 35, notification 2 hello 2, max age 20, forward delay 15 Timers: hello 0, topology change 0, notification 0, aging 300 Port 1 (GigabitEthernet0/0) of VLAN0001 is designated forwarding Port path cost 4, Port priority 128, Port Identifier 128.1. Designated root has priority 32768, address 0053.cf8d.7c03 Designated bridge has priority 32769, address 0051.cf8d.7c01 Designated port id is 128.1, designated path cost 4 Timers: message age 0, forward delay 0, hold 0 Number of transitions to forwarding state: 2 Link type is shared by default BPDU: sent 7222, received 34 Port 2 (GigabitEthernet0/1) of VLAN0001 is designated forwarding Port path cost 4, Port priority 128, Port Identifier 128.2. Designated root has priority 32768, address 0053.cf8d.7c03 Designated bridge has priority 32769, address 0051.cf8d.7c01 Designated port id is 128.2, designated path cost 4 Timers: message age 0, forward delay 0, hold 0 Number of transitions to forwarding state: 1
As you can see the upstream Interface Port-Priorities are
Designated port id is 128.1 Designated port id is 128.2
Now in the Port-Priority the value after the . corresponds to the interface number. Since in this case the interface number is Gigabit0/1, so the Port-Priority will become 128.1.
But you can lower it if you want to do some traffic engineering. For example:
SW1(config-if)#spanning-tree vlan 1 port-priority 64
Since 128.1 is lower than 128.2, it will choose port connected to 128.1 as root bridge and will put the other one in blocking state.