Thursday, April 30, 2015

Introduction to Spanning Tree Protocol (STP)

The Spanning Tree Protocol (STP) is a protocol that builds a logical loop-free topology for Ethernet networks. The basic function of STP is to prevent bridge loops. Spanning tree also allows a network design to include spare (redundant) links to provide automatic backup paths if an active link fails. This is done without the danger of bridge loops, or the need for manual enabling or disabling of these backup links, leaving a single active path between any two nodes. 

Spanning-Tree Protocol implements the 802.1D IEEE algorithm by exchanging BPDU messages with other switches to detect loops, and then removes the loop by shutting down selected bridge interfaces. This algorithm guarantees that there is one and only one active path between two network devices.

When you plugged in a cable into the switch port the led above the interface will glow in orange and after a while become green. In this moment spanning tree is determining the state of the interface.

Spanning Tree 802.1W – reduced the number of port states from 5 to 3 by replacing Disabled, Blocking & Listening to Discarding which we will look into the upcoming post.

In the below mentioned diagram we have two switches. The communication from "Computer 1" to "Server 1" is interrupted when the cable between the two switches are broken.  

These switches are connected to each other with a single cable so there is a single point of failure. To get rid of this single point of failure we will add another cable as shown in the below mentioned diagram.

With the extra cable we now have redundancy. Unfortunately redundancy also adds loop into our topology. Why do we have a loop in the scenario above? Let me describe it to you:

1. Computer A sends an ARP request because it’s looking for the MAC address of Server 1. An ARP request is a broadcast frame.
2. Switch A will forward this broadcast frame on all it interfaces, except the interface where it received the frame on (Gi 0/24).
3. Switch B will receive both broadcast frames. (i.e. on Gi 0/1 & Gi 0/2 on Switch B) Now what does Switch B do with those broadcast frames?
4. It will forward it out of every interface except the interface where it received the frame on.
5. This means that the frame that was received on interface Gi0/1 will be forwarded on Interface Gi0/2.
6. The frame that was received on Interface Gi 0/2 will be forwarded on Interface Gi 0/1.

Do you see where this is going? We have a loop! Both switches will keep 
forwarding over and over again until the following happens:

You fix the loop by disconnecting one of the cables.
Enable STP on your switches.

Otherwise One of your switches will crash because they are overburdened with traffic as Ethernet frames don’t have a TTL (Time to Live) value so they will loop around forever. Besides ARP requests there are many frames that are broadcasted.

Spanning-tree will help us to create a loop-free topology by blocking certain interfaces. Let’s take a look how spanning-tree works!

In the above mentioned example we have three switches (Switch A, B & C) with redundancy, this also means we have a loop.

Note: I have simplified the MAC addresses for better understanding

Switch A: MAC AAAA
Switch B: MAC BBBB
Switch C: MAC CCCC

When Spanning tree is enabled, all switches will send a BPDU (Bridge Protocol Data Unit) frame to each other. In this BPDU there are two pieces of information that spanning-tree requires:

MAC address

The MAC address and the priority together make up the Bridge ID & The BPDU is sent between switches as shown in the following picture, The Switch with the lowest Bridge ID is elected as a Root Bridge.

Spanning-tree always requires the Bridge ID to elect a Root Bridge & Path Cost to the Root Bridge is required for its calculation to avoid the loop.

Interfaces and their default cost:

•  10 Mbit = Cost 100
•  100 Mbit = Cost 19
•  1000 Mbit = Cost 4

First of all spanning tree will elect a Root Bridge; this Root-Bridge will be the one that has the best “Bridge ID”. The switch with the lowest bridge ID is the best one

By default the priority is 32768 but we can change this value if we want.
In our example switch A will become the root bridge! Since the priority is the same on all switches the tiebreaker will be the MAC address. Switch A has the lowest MAC address thus the best bridge ID and will become the root bridge.

Switch A has been elected as the Root Bridge and the interfaces Gi 0/1 & Gi 0/2 are designated ports & marked with the symbol “D”The ports on our root bridge are always designated which means they are in a forwarding state.

Since we have elected our Root Bridge, next step for all “Non-Root Bridges" Switch B & Switch C will have to find the shortest path cost to the Root Bridge! The shortest path to the Root Bridge is called “Root port” & marked with the symbol "R". 

The Port Gi 0/1 on Switch B & Gi 0/2 on Switch C is marked as the Root Port "R" as it has the shortest path cost "4" to reach the Root Bridge. 

At this stage we still have a loop, we need to shut down a port between switch B and C to break the loop. So which port STP going to shut down? The one on switch B or the one on switch C?

Since both switches have the same priority but the MAC address of switch B is lower, this means that switch B will “Win this Battle”. Switch C is our loser here. Which means it will have to block its port, effectively breaking our loop!

If you look at the link between switch B and switch C you can see the interface Gi 0/3 of switch C says “ND” (Non Designated). An Non Designated port is blocked! . By shutting down this interface we have solved our loop problem.

Leave your comment below


  1. Replies
    1. Great Article Cloud Computing Projects

      Networking Projects

      Final Year Projects for CSE

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!. Jupiter tree company in florida

  3. It is a fantastic post – immense clear and easy to understand. I am also holding out for the sharks too that made me laugh
    Best digital wallet for bitcoin | Digital wallet bitcoin

  4. It is a fantastic post – immense clear and easy to understand. I am also holding out for the sharks too that made me laugh
    Digital asset exchange | cryptocurrency exchange | Best cryptocurrency exchange website

  5. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them
    Blockchain token | Blockchain token exchange

  6. Your content is nothing short of brilliant in many ways. I think this is engaging and eye-opening material. Thank you so much for caring about your content and your readers.

  7. The essayist, through this blog, has earned regard from numerous for all the correct reasons.
    Hobby Plants

  8. Super-Duper site! I am Loving it!! Will come back again, Im taking your feed also, Thanks. buy gradual instagram likes paypal

  9. Such massive archives of actionable instructions also operate within the banyan trees of your nervous system. biodiversity

  10. Thank you for this blog. I have read this and it gives more useful info to me.
    statistics for data science tutorial
    hacking tutorial tips and tricks