This post has been originally published on LinkedIn.
This post follows up on my previous post of learning STP concepts again.
Electing a Root Switch
Only one switch can be the root of the spanning tree, and it is the focal point of the Layer 2 network. The root switch is selected through a deterministic election process.
Each switch begins its STP logic by creating and sending a Hello BPDU, claiming itself to be the root switch. If a switch hears a superior BPDU, it stops claiming the root switch role. It will no longer originate and send its own Hello BPDUs. Instead, the switch starts forwarding the superior BPDUs received from the superior switch. Eventually, all the switches agree on the superior candidate, which then wins the election and becomes the root switch. The root switch is the only switch to originate Hello BPDUs — the other switches forward the BPDUs down the STP tree.
In other words, the STP topology is an inverted tree with the root switch at the top and the Hello BPDUs “flowing down” to the non-root switches.
The root switch is the switch with the lowest bridge ID. The bridge ID has a fixed format, which has actually changed with the evolution of STP.
The original IEEE 802.1D bridge ID held two fields:
- the Priority field (2 bytes), which is a configurable numeric value to affect the results of the STP election process
- the System ID field (6 bytes), which is the switch’s MAC address; it was included as a tiebreaker, because a MAC address should be unique to the switch
The format of the original 802.1D bridge ID has been redefined in amendment 802.1t and since then integrated into 802.1D-2004. The format was changed mainly because of the advent of new flavors of STP, such as PVST+, which support multiple spanning trees.
Previously, a different MAC address was used for each VLAN when creating the old-style bridge IDs. This consumed a large number of reserved MAC addresses in each switch.
The new bridge ID format steals 12 bits from the Priority field to extend the System ID field to contain the VLAN ID. With this format, a switch can use a single MAC address and still be able to build unique bridge IDs for each VLAN.
The use of the System ID Extension field is also called MAC address reduction, because of the need of many fewer reserved MAC addresses on each switch.
The new bridge ID has the following format:
- Priority (4 bits), which is a configurable value (only in increments of 4,096) to influence the STP root switch election
- System ID Extension (12 bits), which holds the VLAN ID
- System ID / MAC Address (6 bytes), which uniquely identifies the switch
In summary, the root switch is the switch with the lowest bridge ID. The bridge ID is evaluated from left to right, by first comparing the bridge priority value and then looking at the MAC address. If the bridge priority values are equal, the switch with the lowest MAC address will become the root switch.
This section explains why the STP bridge priority value can be adjusted only in increments of 4,096 at the binary level.
Because of the bridge priority bit positions, valid values are in the range of 0 to 61,440 in increments of 4,096. With the use of 4 bits, 16 unique values can be created. Possible values are (0), 4096, 8192, 12288, 16384, 20480, 24576, 28672, 32768, 36864, 40960, 45056, 49152, 53248, 57344, and 61440. All other values are rejected.
NOTE: I’ve placed 0 in brackets because it should be a valid value, but some sources suggest that it is not.
Command Reference, Cisco IOS Release 15.2(2)E (Catalyst 3750-X and 3560-X Switches):
I could not test and verify this information at this moment.
The numbers make more sense through an example. Let’s look at bridge priority 8192 and VLAN ID 46.
The bit sequence for the bridge priority of 8192 is 0 0 1 0.
After adding the leading zeros, VLAN ID 46 becomes a bit sequence of 0 0 0 0 0 0 1 0 1 1 1 0.
Once these are put together, the whole string of bits is 0 0 1 0 0 0 0 0 0 0 1 0 1 1 1 0.
After converting this to decimal, the final bridge priority value is 8238.