Christmas Offer - Every Learner Must Check Out - Flat 88% OFF on All Access Pass
00
days
:
00
hours
:
00
minutes
:
00
seconds
PyNet Labs- Network Automation Specialists

Spanning Tree Protocol (STP)

Author : PyNet Labs
Last Modified: February 14, 2024 
Spanning Tree Protocol Featured Image

Introduction

In the complex realm of computer networks, stability and efficiency are paramount. Imagine a scenario where multiple paths connect switches and bridges, forming a web of interconnected devices. While such redundancy promises increased reliability, it can also lead to unforeseen issues, like loops and broadcast storms, causing network outages and performance degradation. Therefore comes the Spanning Tree Protocol (STP), a fundamental mechanism designed to mitigate these problems and ensure seamless communication within networks.

One of the protocols that a network engineer must grasp is spanning-tree, and if you decide to take the Cisco CCNA exam, you will undoubtedly come across it.

In this article, you will learn the basics of spanning tree protocol, including how it works, its various types and states. So, let’s get started and understand what is Spanning Tree Protocol or STP.

What is Spanning Tree Protocol (STP)?

Spanning Tree Protocol (STP) is a Layer 2 network protocol; it is used to stop loops from forming inside a network topology. It was developed to prevent the issues that occur when computers exchange data over redundant channels in a Local Area Network (LAN). Data can become trapped in a loop that circles network segments if traffic flow is not carefully monitored and controlled. This can affect performance and bring traffic to a virtual standstill.

If you have worked with network switches, you must have noticed that when we connect switches, there is some orange colour indication on the links, and then after 15-30 seconds, they turn to green colour. 

Any idea why this happens and what’s the reason behind this? 

The reason behind this mechanism is known as spanning tree protocol which avoids loops when you have multiple links between the switches. 

Let’s understand this by an example, we have three switches, and we’ll connect all these 3 switches. Then we will see the colour states change from orange to green because the ports go through some listening and learning stages, and all the switches do an election process.

spanning tree protocol
spanning tree protocol

As you can see, the port states as well that they are going through listening and learning stages changes in colour as we have seen, but why is this all happening? 

Let’s deep dive into spanning tree protocol now!

Whenever we have multiple links for redundancy or multiple switches which are connected together, STP occurs automatically on the network switches because it takes care of avoiding loops in the network, or we can say that if all the ports are in up or forwarding states, then there will lot of broadcast request generated inside your network. To avoid these kinds of scenarios in the network, Spanning tree protocol is there.

  • STP is an open standard protocol (IEEE 802.1D)
  • STP avoids broadcast storms, database instability, loops, and multiple frame copies.

How many loops are there in the network?

When switches are linearly connected to each other, we have no chance of loops, but when multiple switches are connected, the loop can be there.

  1. Loop Scenario:
spanning tree protocol
  1. Loop Scenario:
spanning tree protocol

Now, let’s see how the spanning tree protocol works.

How Spanning Tree Protocol (STP) Works?

The working of STP is a 3-step process, which is – 

  1. Selection of Root Bridge
  2. Selecting the Root Port
  3. Selecting the designated and non-designated port.

Spanning Tree Protocol works by selecting one of the switches as a head switch, considered as “Root Bridge.” So, what will happen as a result that now all of the frames in the network will only pass through the Root Bridge?

And all redundant/backup paths will be put in a blocking state. So, there will be only one path reach from source to destination. – Hence, there will be no loop.

  1. Selection of Root Bridge

Before understanding the working, let’s understand what exactly this term “Root Bridge” is.

The root bridge is like the head in the L-2 topology and the most important switch, which has all ports in the forwarding state, which is selected by some election process.

So, let’s try to understand the selection of root bridges. For the first time, when we connect multiple switches together, we see that in 30 seconds, the port states change from orange to green. In that case, there is an election process between all the switches. All the switches are exchanging BPDUs (Bridge Protocol Data Unit).

In these BPDUs, all the connected switches exchange information like MAC Address, Priority number, port number, and all the necessary information to select the root bridge. When all the switches have exchanged their BPDUs with each other, the switch with the best (lowest) bridge-id is considered the root bridge.

Bridge-id = Priority + MAC Address 

Note – Default priority value is 32768 on all switches 

Out of all the switches in the network, one is elected as a root bridge, and it becomes the focal point in the network; the rest all the remaining switches are known as non-root bridges.

Let’s see with an example –

We have connected three switches, and we’ll verify the Spanning Tree Protocol of all switches.

spanning tree protocol

As you can see from this image that when all three switches were exchanging the BPDUs with each other. All these are looking for the lowest bridge-id, a combination of “Priority + MAC.”

But in our scenario, we have the same priority value on all the devices, so there is a tie-in priority. So, now MAC will be the second option per the bridge-id concept, so the least MAC Address we have is 0030.A3E3.B975 is now considered our root bridge.

To verify – #show spanning-tree

  1. Selecting the root port:

The nearest port to the root bridge is known as the root port. Every non-root bridge will have one root port. (Shortest path to reach on root bridge) because every non-root bridge will for the best path to reach the root bridge.

We have some default STP port costs –

STP Port Cost Link Type 
100 Ethernet (10 Mbps) 
19 Fast Ethernet (100 Mbps) 
Gig Ethernet (1000 Mbps) 
Gig Link (10 Gbps) 
  1. Selecting the designated and non-designated ports:

Root Port – It’s always in the forwarding state and the best & shortest path to reach the root bridge.

Designated Port – These ports are also in upstate; they always forward the data.

Non-Designated Port – Ports that are in a blocking state.

These are three processes explaining how Spanning Tree Protocol works.

Now, let’s discuss the types of STP.

Types of Spanning Tree Protocol (STP)

There are 5 different types of STP listed below –

  1. STP (802.1D) – The original STP
  2. PVST – Per VLAN STP
  3. PVST+ – Per VLAN STP Plus
  4. RSTP (802.1W) – Rapid STP
  5. MSTP (802.1S) – Multiple STP

Moving on, let’s see various STP Ports.

Spanning Tree Protocol Ports

There are five ports used in STP –

  • Root Port: The shortest path from a non-root switch to the root bridge.
  • Designated port: Provides the best path from a switch to the root bridge, responsible for forwarding network traffic.
  • Blocking port: Put into a “blocking” state to prevent loops, does not forward network traffic but remains in a listening and learning mode.
  • Backup Port: Redundant path to the root bridge, ready to take over forwarding if the designated port fails.
  • Alternate port: Backup path on switches not part of the active topology, transitions to forwarding if a designated port fails.

These are the five ports in STP. Let’s understand Spanning tree port states now.

Spanning Tree Protocol Port States

There are five states through which a switch has to pass in STP.

  1. Disabled – This port does not forward any data, simply the blocked one.
  2. Blocking – This port will not forward frames or learn MAC addresses. It can only receive BPDUs from other switches.
  3. Listening – In this stage, the port will change its state from blocking to listening, where it’ll listen only; no forwarding or sending of BPDUs occurs here.
  4. Learning – The port will listen to the MAC addresses, and it can send and receives the BPDUs.
  5. Forwarding – From the learning stage, it’ll redirect to the forwarding stage.

These are the 5 Spanning Tree Port States.

What are STP Modes?

Before STP modes, we understand the beginning of STP (Spanning Tree Protocol), which Radia Perlman introduced in 1985. After the protocol evolved in many ways and new changes were introduced, the Institute of Electrical and Electronics Engineers (IEEE) organized it.

The following table shows an overview of the most frequently occurring Spanning Tree protocols, but these protocols do not support every bridge and switch. So, there are other spanning tree-inspired protocols that are not mentioned here.

ProtocolIEEE StandardSwitchDescription
Spanning Tree Protocol (STP)IEEE 802.1DstpThe Original STP Version
Rapid STP (RSTP)IEE 802.1wrstpAn evolution of STP 802.1D that addresses the STP Convergence time gap issue with enhanced BPDU exchange
Multiple STP (MSTP)IEEE 802.1smstpA format for mapping multiple VLANs into the same spanning tree to reduce processing on the switch
Per-VLAN Spanning Tree (PVST+)Cisco Protocol based on 802.1DpvstAn 802.1D enhancement that provides a separate STP instance for each VLAN configured in the network
Rapid PVST+Cisco Protocol based on 802.1wrapid-pvstAn 802.1w enhancement that provides a separate STP instance for each VLAN, enabling faster convergence times

The original protocol standards are indicated in the IEEE Standards column, and the IEEE commonly rearranges these standards, making it difficult to track which standard currently includes STP functionality. For example, in the 802.1D-2004 revision, 802.1D was updated to include 802.1w. The 802.1Q standard was launched in 2014 with more functionality than that specified in 801.1D.

The options used to specify the protocol mode when enabling STP on a bridge or switch are shown in the Switch column. To enable STP, a network manager connects to the device and then switches to global configuration mode and runs a command in the following format:

spanning-tree mode <protocol mode>

For example, Follow the below command to start Rapid STP (RSTP) on a switch

spanning-tree mode rstp

When STP is enabled, the manager must select a root bridge to act as the central STP reference point of the network, and the administrator also checks the root port and the specified port. (A root port is a bridge port that sends frames to the root bridge, whereas a specified port sends frames away from the root bridge).

Other terminologies associated with Spanning Tree Protocol

Port-Timer in STP

spanning tree protocol

Hello Timer

It determines how often switches send BPDUs. By default, BPDUs are sent every 2 seconds. 

Forward-Delay Timer

It shows how long a port must spend in both a learning and listening state. 

(Listening to learning = 15 seconds) 
(Learning to forwarding = 15 seconds) 

Max Age Timer

It shows how long a switch will retain BPDU information from a neighbour switch before discarding it.

STP Election Process

Transmission BPDU configurations, including their BIDs with a single switch, began to be considered root bridges. However, if a switch receives a BPDU with a high (low value) BID, then the switch configuration will hinder evolving BPDUs and will instead transfer these larger BPDUs to its neighbouring switches.

When the root bridge is declared, a second election process is initiated to regulate the “root port” selection process. The process will follow the following steps until the root port is elected:

  • A switch port receives more BPDUs from another switch and investigates that switch as the root bridge.
  • The port with the lesser root path is chosen as the root port.
  • If the path cost is the same, the switch selects the port with the lower receiver BID as the chosen root port.
  • If the receiver BID is the same (usually the same switch), the port with the lower manual port number on the receiver switch is selected as the root bridge (as the final tiebreaker).

Frequently Asked Questions

Q1 – What is STP and its types?

STP, or Spanning Tree Protocol, is a network protocol that prevents loops in Ethernet networks. It designates a root bridge and calculates the shortest path to reach other switches, creating a loop-free topology. The main types of STP include Rapid Spanning Tree Protocol (RSTP), Multiple Spanning Tree Protocol (MSTP), Per VLAN spanning tree, Per VLAN spanning tree Plus, and STP (802.1D).

Q2 – What is vlan and STP?

VLAN (Virtual Local Area Network) is a logical segmentation of a network, while STP (Spanning Tree Protocol) is a network protocol that prevents loops in Ethernet networks. VLANs divide a network into separate broadcast domains, providing flexibility in managing network traffic, while STP ensures a loop-free topology by designating a root bridge and blocking redundant paths. Both technologies work together to enhance network performance and maintain stability.

Q3 – What does BPDU stand for?

BPDU stands for Bridge Protocol Data Unit, which is a data message exchanged between network switches in Spanning Tree Protocol (STP) to communicate information about network topology and to prevent loops.

Q4 – What is the purpose of STP?

The purpose of Spanning Tree Protocol (STP) is to prevent loops in Ethernet networks by creating a loop-free logical topology. It achieves this by designating a single switch as the root bridge and calculating the shortest path to reach other switches, while blocking redundant paths. STP ensures network stability, prevents broadcast storms, and enables efficient and reliable communication within the network.

Conclusion

In this blog, we have discussed what is spanning tree protocol, how it works, what are its different types, etc. If you are still with us, you have already learned most things about STP. If you want advanced STP knowledge, you should join PyNet Labs’ CCNP ENCOR training. We hope you liked this article; please share your valuable feedback in the comment box below. Check out the “All Courses” Section to learn more about what PyNet Labs offers. You can also check out what our students say about us by clicking the “Student Review” section.

Recent Blog Post

Leave a Reply

Your email address will not be published. Required fields are marked *

linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram