In most networks larger than your typical SMB switched networks, there will be path redundancy. While most people like the effects of redundancy, the redundancy can cause problems at Layer 2.
If you were to have a network with 2 or more switches inter-connected without Spanning Tree Protocol (STP), you would have switching loops. Why would you have switching loops? Unlike Layer 3 which has “Time to Live” (TTL), Layer 2 broadcasts never time out.
The Spanning Tree Protocol (STP), defined by IEEE 802.1d, prevents switching loops from occurring. It does this by placing ports along the most desirable path into forwarding mode. The ports along less-desirable paths are placed in blocking mode. By doing this a switching loop cannot occur.
If a problem arises with the available path, STP will run the spanning-tree algorithm to recalculate the available path and determine the best path.
Ports along the new best path will be brought out of blocking mode and into forwarding mode, while ports along less-desirable paths are placed in blocking mode. Again, the only path will be available.
How Does Root Bridge Election Work
STP must first determine a root bridge for every Virtual LAN (VLAN). Please note… it needs to do this for EACH VLAN.
When each switch is turned on they all believe they are the “chosen one”. To figure out the “chosen one” they need to hold an election. While we use ballots to vote for people, the switches vote use a thing called “Bridge Protocol Data Units” (BPDU). The Switches continually send BPDUs. Pretty much every other network device does not send BPDUs. Examples of networking devices that DON’T send BPDUs are:
What Does the BPDU Contain?
The BPDU contains 3 main pieces of data. They are:
1 – “Bridge ID”:
- The Bridge ID or BID is a combination of the bridge’s priority and MAC address.
- If it is at the beginning of an election, because the switch believes it’s a the Root Bridge, the BID will be it’s own BID. Once the election is over, all Non-Root Bridges will send.
- The bridge with the lowest BID will be the root bridge.
- The default value is 32768+VLANID for ALL switches
- Typically by default the root bridge with the lowest MAC address will become the root bridge
- Example of a bid: 32768+[VLANID]:00-0b-be-2d-42-61b (Note priority is listed first then the MAC address)
- To find out the MAC address of the switch type: “show version” or “show int vlan 1”
- To find out the priority and Mac address of the switch use the command “show spanning-tree vlan 1”
2 – Cost to Reach Root From this Bridge:
- STP considers the path to have the lowest cost to be the best path.
- Every port is assigned a cost relative to its speed.
- The Higher the speed, the lower the port cost.
3 – BID of the BPDUs Sender:
- This simply identifies which switch sent the BPDU.
When a switch receives a BPDU, the switch compares the root BID contained in the BPDU against it’s own BID.
- If the incoming root bridge BID is lower than that of the switch receiving it. The switch starts announcing that device as the root bridge.
- If the incoming BID is higher than that of the receiver, receiver continues to announce itself as the root. This process continues until EVERY switch has agreed on the root bridge.
Once STP has converged, every port on the switched network will be in either blocking or forwarding mode. There are several intermediate states:
- BLOCKING – Frames are not forwarded, but BPDUs are accepted
- LISTENING – Frames are not forwarded, and the MAC address table is not yet built.
- LEARNING – Frames are not forwarded. Mac Addresses are being learned and the MAC address table is being built.
- FORWARDING – Frame ARE forwarded. Mac Addresses are still being learned.
- DISABLED – Disabled ports cannot accept BPDUs.
Let’s look at a 2 switch setup
Using a straight through cable, I’ve connected port s1/port 23 to s2/port 23. I’ve also connected s1/port 24 to s2/ port 24.
It’s important to note that once STP has converged, one port and one port only will be in a blocking mode. The other 3 will be in forwarding mode. The picture above shows which port is in blocking mode by using a orange dot.
The first thing you should really do is see what VLANs are running on the devices. You do this by running the command:
show vlan brief
Please see the screenshot
As you can see all the ports are on VLAN1.
The next thing you should do is check if you have any trunking ports. Don’t worry if you don’t know what that is right now.
It will most likely come back clean.
Now that we have a fairly clean switch let’s check the SPANNING Tree information. To do this we will need to issue the command:
show spanning-tree VLAN 1
I’m first going to run it on switch “s1”. Here’s an example of the output:
Please note, I’ve made several sections by surrounding them with a particular color.
- Red – This line will only be displayed when the switch has been elected “root bridge”. You can also tell if a switch if the root bridge by comparing the RID and BID. If the RID and BID are the same you will also know that the bridge is the root.
- Orange – The “Root ID(RID)” shows us the BID information for the Root Bridge. The Bridge ID (BID) section shows us the local switch’s BID.
- Blue – This is essentially showing you what ports are connecting to another switch. It also tells you if the port is in Forwarding (FWD) or Blocking Mode (BLK). The cost is also listed here.
- GREEN – Note the Priority is 32768+Sys-id .
Here’s an example of the output on switch “s2”.
Please note, just like “s1” I’ve added some colored areas to help direct your attention:
- RED – It does show the cost needed to get to the “RID”. You can also tell that it is using “FA0/23” to get to it.
- ORANGE – The RID and BID should be different. Because of this you should be able to tell that this is not the “root bridge”.
- GREEN – Based on the RED section you might have guesses that both of these sections should NOT match.
- BLUE – Again this shows us what ports are in use. This switch has on in FWD and BLK mode.
By Default the switch with the lowest BID will be elected. Let’s look at our two switches:
- s1 BID = 32769:0001.6461.D488
- s2 BID = 32769:0002.17CE.CB64
Let’s look at a 3 switch setup
Ok. Let’s look at the setup. Here are 3 Cisco 2960 switches. Each switch has had nothing done to them except the changing of their hostname to reflect the screenshot.
On each switch let’s run the command “show version” to see what the Mac address is off each of the switches and see if we can predict which switch will become the root bridge.
- s1 Mac address = 00D0.FFB0.8961
- s2 Mac address = 00E0.F73A.847B
- s3 Mac address = 000D.BD87.AD9B
What else do we know about this setup without running any other commands?
- It looks like “s3” has the lowest valued Mac address. “s1” is next and “s2” has the highest value. Right away we should know that STP should make “s3” the root bridge.
- We know that the priority of each switch will be the default 32768+1=32769. Because the priority is the same on every switch the priority will have absolutely no effect on this example.
- Because we will only be ports with the speed of 100Mb/sec, all ports will have a STP cost of 19. Because the link between “s2” and “s3” will have the highest STP cost from the root bridge, we know that one of the two ports on this link will be put into blocking mode.
- From the first point we know the “s1” has a lower valued Mac address then “s2”. Because of this we should know that the port on “s2” will be put in BLOCKING mode.This will essentially kill the link between “s2” and “s3” and prevent network loops.
Let’s talk about network segments, Port Roles and Port Status.
How many network segments are in this network? There are 3. Each link between switches is considered it’s own segment.
There are going to be several port roles on the network:
- Root Ports – It’s important to figure out the root ports first. Each nonroot switch considers the port with the least administrative cost between itself and the root switch a Root Port (RP). All Root Ports are in a Forwarding state.
- Designated Ports – Designated ports can never be root ports. The lowest cost STP switch ports are classified as designated Ports.
- Alternative Ports – This port is essentially there waiting for something to happen on the network. If something does happen it can spring to life in a moments notice to provide an alternative path.
All Ports that are Root Ports or Designated Ports will be put in Forwarding mode. Any port in Alternative mode will be put into a BLOCKING state.
How does Port cost effect the STP Topology.
Let’s say we used Gigabit connections in segments 1 and 3. What would happen?
- The cost to go from “s3” to “s2” using top most path would = 4 + 4 = 8.
- The cost to go from “s3” to “s2” using the single bottom path would still be = 19
Because 8 is < 19 STP should recalculate the paths. This is how the network would look:
Notice the ports on the “s2” have now reversed themselves because it’s actually faster to reach “s2” using the top most route.