16

How does STP/RSTP determine which bridge is the root bridge, and how are paths to the root bridge selected?

  • Is the OP referring to single instance RSTP per 802.1w standard or per-vlan RSTP such as Cisco's extension which can yield multiple root bridges through separate spanning-tree instances? – generalnetworkerror May 20 '13 at 8:10
  • I'm referring to STP/RSTP, not MSTP or PVSTP, although they would work much the same, only on a per vlan (or group thereof). – nos May 20 '13 at 13:22
25

Not sure how much you know about switching and spanning tree but basically when starting out all switches claim that they are the root. All switches send BPDUs (Bridge Protocol Data Unit) which contain a priority and the BID (Bridge ID).

The BID is 8 bytes long. 6 bytes is used for the MAC address of the bridge. 12 bits is used to indicate the VLAN, this is called extended system ID. 4 bits are used to set the priority. Lower priority means it is preferred compared to a higher. The priority is set in multiples of 4096.

If there is a tie in priority then the lowest MAC address will determine which bridge becomes the root.

To select the path to the root the cost to the root is calculated. As the BPDU travels from the root downstream the cost is increased INBOUND. 802.1D-1998 (legacy STP) had a cost of 19 for a FastEthernet interface. The newer standard 802.1D-2004 defines a cost of 200000 for FastEthernet.

If there is a tie in cost then choose the BPDU that came from the switch with lowest BID. If that is a tie as well (multiple links to same switch) port ID comes into play. The port ID is from the upstream switch as well and consists of a port priority and port ID which identifies the interface. The default port priority is 128.

There is a lot to spanning tree but these are the basic steps.

| improve this answer | |
  • The bridge priority (16 bits) is set in multiples of 4096 because it consists of another bridge priority (leftmost 4 bits) and the extended system ID (rightmost 12 bits). So the 4 bits bridge priority actually starts at the 13th bit counting from the right, and 4096 = 2^12. – user1534664 Sep 15 '15 at 2:07
13

You're asking about STP theory:

https://en.wikipedia.org/wiki/Spanning_Tree_Protocol

But the basic idea is that each switch has a Bridge ID which is a combination of its priority and its MAC address. By default, all switches use 32768 as their priority so by default the switch with the lowest MAC will act as the Root Bridge. You can manipulate this by adjusting the priorities, since the default Root Bridge is likely not the one you want to act as Root. You would decide which switch to use as root based on your layer 2 designs and where you anticipate layer 2 traffic to travel most.

The cost of the path to root is the sum of the link costs between the port in question and the relevant port on the root bridge. The faster the link, the lower the cost. So ten hops to root over 1GBPS links would give a port cost of 40 (4+4+4+4+4+4+4+4+4+4), while a single 10MBPS link would be 100. So the root port would be the one that connects to the 1GBPS links.

You can also manipulate the STP paths and roots per vlan. The link above will get you started. It can be as complex as you want it to be.

| improve this answer | |
3

So as to not repeat the answers here and to present an alternative view toward a best practice, the question should be "How do I predetermine the root bridge so there's a deterministic view of the network ahead of troubleshooting?"

Set your aggregation or distribution switches as root by splitting your vlans between a primary and secondary switch. Usually odd number vlans get set on one switch as root and even numbered vlans as secondary, then the opposite on the other switch.

Sw1:
spanning-tree vlan 1,3,5,7 root primary
spanning-tree vlan 2,4,6,8 root secondary

Sw2:
spanning-tree vlan 1,3,5,7 root secondary
spanning-tree vlan 2,4,6,8 root primary
| improve this answer | |
  • Your answer only relates if they are using PVST+ or MST with the instances mapped as indicated, not to STP/CST or RSTP as indicated by the OP in which case it can create issues. It is also simplistic in assuming that you only have two root bridges in your L2, however is a good example of how to keep troubleshooting simple if you can do it this way (many networks have grown/evolved to the point of multiple root bridges, and the even/odd doesn't work in a traffic flow sense without reconfiguring VLANs across the network). – YLearn May 18 '13 at 12:58
  • Given that a Cisco spanning-tree mode rapid-pvst config shows "Spanning tree enabled protocol rstp" with show spanning-tree, how can you be sure by RSTP that the OP didn't intend Cisco's Rapid PVST? I admit my response was focused on a Cisco "rapid-pvst" config. Could you also explain the issues you indicated could be created? – generalnetworkerror May 19 '13 at 1:25
  • You could be correct, but since the OP specifically STP (aka CST) and RSTP, it would seem to indicate standard spanning tree implementations. As to issues, with STP/CST and RSTP (without Cisco's added PVST+ modification to RSTP), you can only have one topology, so having two different root bridges for different sets of VLANs would result in inconsistent forwarding states in the network. – YLearn May 19 '13 at 2:38
  • Nearly all vendors have a per vlan implementation of RSTP. – netdad May 20 '13 at 4:26
  • One caveat to this is that, on Layer-3 switches, HSRP/VRRP primaries must match the STP primaries, else you are asking for trouble, Also, root primary/secondary is not really deterministic. The command will change the STP priority to a specific switch-dependent value, but not guarantee that the switch is either the primary or secondary since a switch with an even lower priority could already exist or be added later. – Ron Maupin Apr 13 '15 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.