How spanning tree protocol works


How Spanning-Tree works? | NetworkAcademy.io

Spanning-Tree is based on an algorithm invented by Radia Perlman in 1985 and was published in a paper called "An Algorithm for Distributed Computation of a Spanning Tree in an Extended LAN".  The algorithm creates a loop-free topology by selecting a single root bridge and then all other switches calculate a single least-cost path to the root.

I think that I shall never see
A graph more lovely than a tree.


A tree whose crucial property
Is loop-free connectivity.


A tree which must be sure to span
So packets can reach every LAN.


First the root must be selected.
By ID it is elected.


Least cost paths from root are traced.
In the tree these paths are placed.


A mesh is made by folks like me
Then bridges find a spanning tree.

The Spanning-Tree algorithm performs a couple of steps to make sure that the topology is loop-free and Ethernet is going to work correctly:

  1. Electing a Root Bridge - The very first thing that STP does is to elect a Root Bridge. This is the most important switch in the topology. It will be the root of the loop-free tree. 
  2. Finding looped topologies - Once the Root Bridge is elected, it starts sending Spanning-Tree messages called BPDU. Based on these messages the switches find the looped parts of the topology. 
  3. Setup port roles - After the looped part of the topology is identified, each switch places as many switch ports as needed in order to ensure that the topology is loop-free.
  4. Re-converge around failures - The switches continue to exchange messages in order to keep track of links and adjacent switches' availability. If a link or a switch goes down, the switches execute step 2 and step 3 again to make sure the new topology is loop-free.

NOTE  The term Bridge appears a lot in the context of Spanning-Tree because the protocol was created in times when switches had not even existed and local networks were using devices called bridges. That is why most protocol terms like Bridge-Priority and Bridge-ID are not Switch-Priority and Switch-ID. However, in the context of STP, both terms are really synonymous and interchangeable.

This is a simplified summary of the STP algorithm. Let's now look at each step in more detail. 

Root Bridge Election

Switches elect a Root Bridge based on a value called Bridge ID. The switch that has the lowest BID value is elected the Root Bridge of the topology. BID is not a single value, but it is composed of two different value types.

BID = (Priority + VLAN number) : (System MAC address)

The first portion of the BID value is configurable and is used by network administrators to set up a particular switch as a Root Bridge.

The second part of the BID value is only used when there is a tie, meaning when there are at least two switches that have the same priority value. This typically happens when all switches are left with their default values, therefore all switches have a priority of 32768. In this case, the election process is decided by choosing the switch with the lowest Systems MAC address. 

When a switch boots up, it does not know the BID values of all other switches in the topology. Thus it elects itself as the Root Bridge of the topology. Once it receives a BPDU with a Root BID value lower than its own, it immediately stops advertising itself as root and starts forwarding the superior Root Bridge value. 

Figure 1. Root-Bridge Election process step 1

Let's look at the example in figure 1. It shows three switches with default configurations that have been connected in a triangle and just powered on. The Spanning-Tree process starts with all switches electing and advertising themselves as Root Bridge of the topology.  In the BPDU messages, they put their own BID value and the BID of the root bridge known to them at the moment. Each switch is basically saying "I am the Root".

Figure 2. Root-Bridge Election process step 2

Let's now look at the example in figure 2 and see what happens when they exchange the first BPDU messages. SW2 receives two BPDU messages, one from SW1 and one from SW3.

  • The BPDU from SW1 says that the Root Bridge has a value of 32769:0000.0000.0001.  When SW2 compares this value to the Root Bridge value known to him at the moment 32769:0000.0000.0002 - it is obviously lower. A BPDU message that has a lower Root BID value than your own is called a Superior BPDU. Once SW2 gets this superior message, it stops advertising itself as root and starts forward this Superior BPDU downstream to all other switches. Downstream means that it stops sending BPDUs toward the Root but only to other bridges.
  • The BPDU received from SW3 has a Root-BID value of 32769:0000.0000.0003.  When SW2 compares this to the Root Bridge value known to him at the moment 32769:0000.0000.0002 - it is obviously higher. A BPDU message that has the same or higher Root BID value than your own is called an Inferior BPDU. Once SW2 gets this inferior message, it discards it.

At the end of this process, all switches within the topology must agree that there is only one Root Bridge and it is the same from the perspective of each bridge.

Detecting Loops

Once the Root election is completed, the switches start identifying loops. A switch understands that there is a loop when it receives BPDUs from the Root-Bridge on more than one interface.  

If a switch receives Superior BPDUs on more than one port, there must be a loop and that port must be placed in Blocking State.

A key to correctly understand how this works is to understand what Superior BPDU is. A Superior BPDU has one of the following properties in that order:

  1. Lower cost to the Root Bridge.
  2. Lower neighbor bridge ID.
  3. Lower neighbor port priority.
  4. Lower neighbor internal port number.

Let's leave this process here and not dive into more details for now. In the next section, we are going to deep dive into this process and will do many labs and examples.

Figure 3. Detecting Loops between three switches

Setting up the port roles

Once the topology is converged and each switch has placed its ports in the correct roles, BPDUs are still exchanged in order to track the link availability. If any switch detects a topology change, all switches re-calculate their port roles in order to create another loop-free topology.

Figure 4. Spanning-Tree Port Roles

There are three main port roles as shown in the example in figure 4.

Table 1. Spanning-Tree port roles
Port Roles Description
Root Port

The root port represents the best path towards the Root Bridge. The switch must be receiving BPDUs with the lowest cost to the root on this port.

The switch does not send BPDUs via this port.

The switch learns MAC addresses on this port.

Designated Port

A port that points away from the root (downstream port).

BPDUs are being sent out this port.

The switch learns MAC addresses on this port.

Blocked Port The switch does not learn MAC addresses on this port. The port does not forward any Ethernet traffic.

Let's leave this here as well. We are going to be talking a lot more about each of the roles in the next lessons. 

STP – Spanning Tree Protocol Explained

ByLawrence Williams

Hours

Updated

What is STP?

STP is a link management protocol designed to support redundant links that stops switching loops in the STP network. It is a Layer 2 protocol that runs on bridges and switches, which should be enabled on the switch interfaces. IEEE standardized STP protocols as IEE 802.1D. The full form of STP is Spanning Tree Protocol.

In this networking tutorial, you will learn:

  • What is STP?
  • Why do we need STP?
  • How STP works?
  • Types of STP:
  • Criteria for Spanning Tree:
  • Stage of STP Protocol
  • Important terms used in Spanning Tree Protocol
  • Bridge Protocol Data Units (BPDU)
  • Differences between STP and RSTP

Why do we need STP?

Here is some situation when Spanning Tree Protocol is important:

  • The reliability (fault tolerance) of the network is increase exponentially by the introduction of redundancy.
  • Switches flood traffic out all ports, when the traffic needs to be sent to a destination that is not yet known.
  • Broadcast and multicast traffic is forwarded out to every port, apart from the port on which the traffic arrived.
  • The Spanning-Tree Protocol is used to create a loop-free logical topology from a physical topology that has loops.

How STP works? Example

Spanning trees use an algorithm to search for the redundant links in the LAN and select the best paths. It is mainly used to put all links in either forwarding or blocking.

After this process, all the links without a redundant link is likely to be in the forwarding state. The redundant links that were not as good as the selected links would be blocking. Spanning Tree never uses multiple links to the same destination. There is no load-sharing feature with Spanning Tree.

Types of STP:

Here, are different types of Spanning Tree Protocols:

Standard Description Abbreviation
IEEE 802. 1D. Loop Prevention
Auto-reconfig of tree in case of any changes
Slow convergence (up to 50 bps)
STP
IEEE 802. 1w Rapid Spanning Tree Protocol
  • Improved STP with fasterconvergence
  • Backward compatible with STP
RSTP
IEEE 802. 1Q Virtual LAN
Defining 1 common spanning tree for all VLANs
CST
Cisco
Proprietary
Per VLAN Spanning Tree
  • 1STP instance per VLAN
  • PVST + is an improved variant of PVST
PVRST+ orR-PVST+
Cisco
Proprietary
Per VLAN Rapid Spanning Tree PVRST+ orR-PVST+
IEEE 802.1s Multiple Spanning Tree protocol
Multiple instances of VLAN mapped to 1 STP.
MSTP orMl STP

Criteria for Spanning Tree:

The three criteria for Spanning Tree loop helps to decide that interface are of the forwarding state are:

  • All interfaces on the root bridgeshould be put in a forwarding state.
  • For other bridges that are not the root bridge, the port which is closest to the root bridge is put in a forwarding state.
  • The bridge with the lowest admin distance to the root bridge is known as the designated bridge.

Stage of STP Protocol

Four stages of Spanning-Tree Port states are:

Stages of STP

Blocking State

Block state is a non-designated port, and it is never participating in frame forwarding. Its time limit is 20 sec or unlimited. An interface always enters the blocking state when you enable STP.

Listening State

The listening state is the first state. It is an interface that is entered after the blocking state. The interface helps you to determine that the interface that should participate in frame forwarding.

The listening state performs the following functions:

  • Discards frames received on the port
  • Does not learn addresses
  • Receives BPDUs

Learning State

Learning state helps to prepare for participating in frame forwarding. The interface allows us to enter the learning state from the listening slate.

Learning state performs the following functions:

  • Discards frames received on the port
  • Receives BPDUs
  • Learns addresses

Forwarding State:

An interface in the forwarding state form the forward frames. This interface enters the forwarding state from the learning state which performs the following functions:

  • Receives and forwards frames which is received on the port
  • Learns addresses
  • Receives BPDUs

Disabled State

This state does not participate in the Spanning Tree loop because the port is administratively disabled, and its timing is also unlimited.

A disabled interface performs the following functions:

  • Discards frames received on the port
  • Does not learn addresses
  • Does not receive BPDUs

Important terms used in Spanning Tree Protocol

Here are some important terms used

Bridge:

Bridge is an important component of VTP, which connects two or more LAN segments.

Root Bridge (RB):

It is the bridge that offers an interconnection point for all segments. All the bridges in a LAN have a path to the root. STP allows you to select the root bridge automatically. However, if the STP network admin wants, he or she can change the RB according to the network.

Non-Root Bridge (NRB):

A noon-root Bridge is any bridge that is not the root bridge.

Root Port (RP):

The root port is a port that leads towards the Root Bridge.

Designated Port (DP):

Every LAN segment has 1 Designated Port. Every bridge also receives the frames from DP and forwards them through its RP towards the Root Bridge.

Port ID:

The port ID helps you to decide the root port. It consists of a configurable 1-byte priority value and a unique port number of each bridge.

Path Cost (PC):

Path Cost, which is also known called PC, helps to decide the best topology with regard to forwarding speed. STP uses the concept of Path Cost.

Designated Ports

A designated port is a disabled port, and it is blocked by a network admin. This port can’t send a packet to another switch. It is also not a populated MAC address on the MAC table.

Non-Designated Ports

A non-Designated port is a switch port that is blocked. It is also known as a blocked port, or sometimes an alternate port. It cannot forward packets to the next switch. It also does not populate the MAC address in the MAC table.

RSTP:

Rapid Spanning Tree Protocol (RSTP) is a network protocol that ensures a loop-free topology for Ethernet networks.

Bridge Protocol Data Units (BPDU)

The Spanning Tree Protocol requires a STP network device to exchange messages to help from a loop-free logic topology. These messages are called BPDUS ( Bridge Protocol Data Units). Each network device sends BPDUs, which helps to exchange topology information.

BPDUS helps switches to do the following:

  • Select a single switch which will act as the root of the spanning tree
  • BPDUS also helps to calculate the shortest path from itself to the root switch, which is designated one of the switches as the closest to one to the Root for each LAN segment.
  • Select one of its ports as a root port (if it is a no switch)
  • Pickup the port that are part of the spanning tree algorithm called designated ports.
  • Blocks the non-designated ports.

Configuration BPDU

It is a unique bridge ID of the root device in the network topology. It acts as a bridge ID of the transmitting bridge, an identifier of the transmitting port.

Topology Change Notification (TCN) BPDU

One network device is selected as the root bridge. The shortest distance to the root bridge should be calculated for each network device based on the path cost.

A designated bridge for every LAN segment is selected. This is also the network device closest to the root bridge, so it should be forwarded to the root. This is the port that provides the best path from the bridge to any root bridge.

Differences between STP and RSTP

STP RSTP
In STP, the bridge only sends out a BPDU when reviewed on their RP (root protocol) from RB (the root bridge). RSTP enable the switch to send out BPDU in every hello time.
STP includes two port types: Root Port and Designated Port RSTP method includes additional port, Alternate Port ,and Backup Ports.

Summary:

STP Protocol is defined as a link management protocol designed to support redundant links that stops switching loops in the STP network.

State Description Process BPDUs Learn MAC
Inti Initialization of a port. NO NO
Disabled Administrative state which doesn’t participate in STP standard operations. NO No
Blocking The port doesn’t forward Ethernet frames. Yes (receive and process only BPDUS) No
Listening Computation of loop-free topology is carried out in this STP state. The port is assigned its role. Yes (Send and received BPDUS) NO
Learning It is an additional state to delay Ethernet frames’ forwarding, which helps you avoid flooding the network. Yes Yes (popular MAC address table)
Forwarding Normal operation of forwarding Ethernet frames. Yes Yes

How does the spanning tree protocol (STP) work?

STP, which stands for Spanning Tree Protocol, is a network layer protocol that helps in building a loop-free logical topology for Ethernet networks. Many improved versions of STP have continued to hit the market over time, bringing new enhancements to this protocol:

  • STP/802.1D (original STP)
  • PVST+ (Cisco enhancements to STP, adding feature per VLAN)
  • RSTP/802.1 W (improved STP with much faster convergence)
  • Fast PVST+ (RSTP enhancement at Cisco, add per VLAN feature)

You can see that Cisco has made a lot of improvements in this area. Let's go back to the basics and look at the reason why STP was needed in the first place.

Before we look at the need for STP, let's take a quick look at how layer 2 works when it needs to know the address of a particular host.

When a switch receives a packet, but it does not have the destination MAC address in its table, it broadcasts messages to all nodes except those from which it receives. If you would like to know more about this, please refer to this article on ARP.

Scenario 1: Broadcast storm

Let's look at the scenario below:

Suppose there are three switches in the network as shown above. All switches are connected to each other. Switch B sends a broadcast, and Switch A and Switch C receive it. They don't find the address and rebroadcast the message.

Switch B again receives the relayed message from Switch A and Switch C. Thinking of this broadcast as a new broadcast, Switch B retransmits the same messages that were previously relayed. Thus, a broadcast storm takes place. This continues until the ports fail or the switch fails.

Scenario 2: duplicate packets

Consider the same network architecture as in the scenario above. There is a slight twist here. This time switch C is connected to the destination host that switch B was looking for. Now what?

Switch B will be broadcast again. The translation also reaches Switch C and Switch A. Switch C examines the packet and delivers the packet to the destination host.

However, on the other parallel side, switch A also checked its table and could not find the destination host. So it also broadcast the message and switch C received the same packet again. So it looks at the packet and delivers it to the destination host again.

What is the problem here? Can you guess without reading further?

The biggest problem here is double delivery and wasted bandwidth.

Now let's figure out the solution for Scenario 2. One of the best and easiest solutions would be to disconnect switch B from switch C so that there is no duplication of packets. Because, in any case, switch A will forward the packet to switch C if the destination host is not found in the list of switch A. Now it looks something like this:0003

If you look at the definition again, you now know why STP was invented in the first place.

Although we found a solution, we are still not sure if blocking the connection between B and C was more beneficial, or blocking the same between switch B and A. Let's look at all this in more detail.

Which port to block in STP?

STP performs a series of simple steps that help STP solve many problems, including blocking a port. But, before that, here are some terms that you might find useful:

Root Bridge

Like "Root" in the tree structure, Root Bridge is the main switch or bridge in the graph, where different nodes represent all other bridges. The root bridge manages the spanning tree topology.

Designated Bridge

The Designated Bridge is the switch closest to the Root Bridge through which frames will be forwarded to the Root Bridge.

Alternate bridge

This is an alternate path to the root switch, but it is different from the path to the root bridge.

Backup bridge

This is the backup path to the segment, although there will be another existing path.

Ports that are disabled.

The following are the various states that a switch port can be in at any given time:

Forwarding port

A port that is fully operational.

Learning port

A port that does not forward frames but learns MAC addresses.

Listening port

A port that does not forward frames or learn MAC addresses.

Dropping a port

A port that is not transmitting any data.

Let's take a look at how STP works and decide which switch, bridge, and port should be in which state:

  • The first step is to select the root bridge (the method of selecting the root bridge was discussed later in this article).
  • Ports in the root bridge are placed in the forwarding state.
  • The ports in the designated bridges connecting the root bridge are called root ports.
  • The remaining links on the assigned bridge select the assigned ports.
  • The remaining ports have been placed in the blocking state.

Here is a very nice example from Wikipedia.

RP: Root Port
DP: Designated Port
BP: Blocked Port

In general, the whole process may look simpler, but the behind-the-scenes algorithm is complicated. The larger the network, the more time it takes the algorithm to put everything in its place.

Spanning Tree Protocol Operation

The following set of operations is in progress.

Root Bridge Definition

Let's think about this scenario from the beginning. Let's assume that the network is created from scratch. All switches that are part of the network, when powered on, they all claim to be the root bridge.

To confirm assertion, all switches must broadcast their Bridge Identifier (BID) using BPDUs (Bridge Protocol Data Units). The general bridge ID is 8 bytes, of which 2 bytes are reserved for the bridge priority and the remaining 6 bytes are reserved for the MAC address.

The bridge ID is a combination of bridge priority and MAC address. Behind the scenes, the BID is a concatenated version of bridge priority and switch/bridge MAC address. By default, each bridge will have a bridge ID of 32768, and each bridge ID will be a multiple of 4096.

How is the root bridge determined?

After broadcasting to each bridge, the bridge with the minimum BID becomes the root bridge. If the bridge priority is the same in both cases, the lowest Mac address will be the winner.

Example:

Let's say there is a link between two bridges with BID:

Bridge A: 32768.df56.6765.7876 and,
Bridge B: 32768.df56.6765.7875 90 002 here by the root bridge? If you guessed that this is Bridge B, then you were right.

Graphical example:

Let's see how these individual switches respond to BPDUs:

The moment all switches are powered up, all switches, as mentioned earlier, announce that they are the root bridge by sending their bridge ID in the welcome package.

Switch 1:

When Switch 1 receives hello BPDUs from Switch 2 and Switch 3, it compares the bridge ID values. In this situation, Switch 1 has the lowest BID. Thus, switch 1 discards the hello packets received from the other switches and continues to advertise itself as the root bridge.

Switch 2:

Here Switch 2 receives hello BPDUs from both switches, i.e. Switch 1 and Switch 3. Let's see how Switch 2 responds to both BPDUs.

When Switch 2 receives a packet from Switch 1, it compares the BIDs and, of course, the Hello BPDU from Switch 1 replaces its BID. So Switch 2 changes its BID to Switch 1. When it also receives a BPDU from Switch 3, it will compare the values ​​and keep dropping the BPDU from Switch 3. from switch 2. So it changes its BID to that of switch 2. But when it additionally receives a BPDU from switch 1, it changes it back to switch 1.

At this point, all switches have received each other's BPDUs and have agreed that Switch 1 has the lowest BID and is therefore a suitable candidate for the network's root bridge.

Once the root bridge is determined, Switch 2 and Switch 3 begin organizing their respective links into root ports and designated ports, as discussed at the beginning of this article.

But choosing a root bridge is not the end of the game. This is just the beginning. And the game follows: -

Determining the least cost route to the root bridge

If you know about spanning tree from graph theory, can you explain why we are talking about calculating the least cost route to the root bridge.

In graph theory, a spanning tree is a subset of a graph. A spanning tree allows you to cover all the vertices of the graph with the minimum possible number of edges. Therefore, the spanning tree does not have a loop, and furthermore, it cannot be turned off either.

The Spanning Tree protocol exploits the fact that, like Spanning Tree from graph theory, this network protocol can calculate the least cost path from any node to the root bridge.

Thus, after determining the root bridge, each node begins to determine the lowest cost of the root bridge in order to optimize the entire network.

As a first step, the Root Bridge sends a stream of BPDUs to all other switches. The root cost is determined by summing the cost of the segments along the path that it took the BPDU packet to travel from the root bridge to the node.

Can you guess the root port for Switch 3 in the picture above?

Although it may seem that Switch 3 is directly connected to the Root Bridge, and this should be its path, but if we calculate the link cost, it turns out that the next flow is the best for Switch 3 to send data to the Root Bridge.

Root Bridge -> Switch 2 -> Switch 4 -> Switch 3

Can you guess why? According to the table above, here are the expenses.

Switch 3 on Root Bridge is directly 100 due to its 10Mbps link. But if we calculate the path as above, it will be (19 + 19 +4 = 42).

Thus, in each of the non-root bridges, the port that receives the lowest cost BPDU becomes the root port of that bridge.

Next, all links connected against the root port are marked as the designated port. Blocked ports are also defined. Once everything is marked and corrected; the network will have a fully optimized version of the spanning tree protocol.

There may be other conditions. In the case of a large network, the cost of the link will include the link. In this case, the network cost is calculated as part of Advanced STP. Advanced STP also talks about what happens if the connection fails.

How useful is the publication?

Click on a star to rate!

Average rating / 5. Number of ratings:

No ratings yet. Rate first.

Related articles:

90,000 STP protocol - SPANNING TREE PROTOCOL PROTOCOL

Content

  • 1 broadcast storm
  • 2 Protocol STP
  • 3 place STP protocol in the OSI 9000 9000 4 Model
      9000 4. 1 stages
    • 4.2 STP Messages
    • 4.3 Root Switch Selection
    • 4.4 Root Switch Video
    • 4.5 Shortest Path Calculation
  • 5 Port status in STP
  • 6 STP evolution

Let's consider whether Ethernet allows ring connection between switches. For example, there are 4 switches in a network and they are connected by 4 cables so that a ring is formed. The question is, can such a network work? Unfortunately, such a network cannot work, because a broadcast storm occurs in it.

Broadcast storm

Consider how a broadcast storm is formed. Suppose a frame arrives at the upper left port of switch 1. And switch 1 does not know where to send this frame and it does not have a corresponding entry in the switching table. In this case, switch 1 sends the frame to all ports, except from where this frame came from.

Computers that are connected to the switch ports will see that this frame is not for them and will simply drop them. And the two ports in the picture below are connected to other switches and the frame through these ports will be transmitted to other switches 2 and 3.

Suppose that switches 2 and 3 also do not have entries about the recipient address of this frame in the switching table. Therefore, they are forced to transmit this frame to all ports.

As in the previous step, computers will discard frames that are not intended for them, and the frame will be transmitted through the connection to switch 4.

Switch 4 will receive two copies of the same frame. Unfortunately, the switch has no way to determine whether these are two copies or whether these are two different frames with the same source and destination addresses. Therefore, each frame will also be transmitted to all ports.

In addition, frame 1 will be sent to switch 3, and frame 2 will be sent to switch 2. Thus, frames will go around and be transmitted to all ports.

After a while there will be a lot of such frames and the network will be inoperable. This situation is called a broadcast storm, and it makes an Ethernet ring connection impossible.

STP

Spanning Tree Protocol or sometimes called Spanning Tree Protocol. The STP protocol allows you to disable some connections between switches at the software level so that a ring does not form.

A spanning tree, or spanning tree, as it is more commonly called in mathematics, is a cycle-free subgraph containing all the vertices of the original graph. The spanning tree contains all our original commutators, but there are cycles in it, i.e. Ethernet in this configuration will definitely work.

STP is defined in the IEEE 802.1D standard. Thanks to this protocol, you can create multiple connections between switches. This improves the reliability of the network. If for some reason one connection drops, another connection can be used.

Another advantage of STP is that it protects against accidental errors in the ethernet configuration. Of course, no one wants their entire ethernet network to stop if they mistakenly plug a cable into the wrong switch and accidentally create a ring. The STP protocol protects against this situation.

Place of STP in the OSI model

In the open systems interconnection model, the STP protocol is at the link layer, it is implemented on switches.

How STP works

Let's see how STP works. In the example with 4 switches, one of the connections (between switch 3 and 4) will be disabled at the software level.

There is a cable between the switches, but it is not used for data transmission. Thus, a broadcast storm will not occur. In case one of the existing connections breaks.

STP can automatically enable a blocked connection and the Switch can still send data to the network.

STP protocol steps

The STP protocol has three steps. The first step is to select the root switch. At the second stage, the shortest paths from all switches in the network to the root switch are calculated. At stage 3, all other connections are disabled, except for the shortest ones.

The STP protocol was invented by Radi Perlman and wrote a poem on how the protocol works.

STP messages

To implement STP, switches exchange messages called Bridge Protocol Data Units (BPDUs). The STP protocol was developed in the 80s, so instead of the term switch, the term bridge is used, which was more popular at that time.

These messages are sent by all switches in the network that support the STP protocol every 2 seconds.

The STP group MAC address is used as the destination address. All Ethernet switches that support STP receive and process frames that arrive at this multicast address (01:80:S2:00:00:00).

Root switch selection

Let's take a closer look at how STP works. The first step is to select the root switch. The selection is made by ID, the switch with the minimum ID is selected as the root switch.

Switches currently use their MAC address as the ID, but you can change the ID value manually to select the most powerful switch in your network as the root, rather than the switch that happens to have the smallest MAC address.

Let's assume that switches in our network use simple, integer numbers as identifiers. Switch 1 has ID 4, switch 2 has BID=2 and so on, see the picture below. Switch 4 with ID 1 will be selected as the protocol root.

How is the root switch selected? At the first stage, the switches do not know anything about the rest of the network, respectively, each switch considers itself to be the root switch and sends a message to all its neighbors that it is the root switch. Switch 1 will send such messages to switches 2 and 3, and switches 2 and 3 will send a message to switches 1 and 4. After receiving a message from their neighbors, switches compare the message ID with their own ID.

For example, switch 2 will receive a message from switches with BID=4 and BID=1. He will understand that from his neighbors and himself, the switch with the minimum ID is switch 4.

And at the next stage, the switches will send messages not with their number, but with the minimum number of the root switch, which they learned from their neighbors.

For example, switches 2 and 3 received a message from the fourth one, which is less than their ID, and broadcast that now the root switch is switch number 4 BID=1. Switch 1 received a message from switches 2 and 3, it chose the minimum value of BID=2 and now broadcasts that the root switch, in its opinion, is switch number 2.

In the next step, the information that the root switch is switch number 4 reaches 1 switch in our network, and now all switches consider that the root switch is switch 4 with BID=1. This completes the selection of the root switch.

Root Switch Video

Calculating Shortest Paths

Now we need to calculate the shortest paths from all switches to the root switch. The length of the path between the switches is determined depending on two parameters:

  • number of intermediate switches;
  • connection speed between intermediate switches.

Calculation of paths to the root switch is implemented according to a scheme similar to the choice of the root switch. All switches send an STP control message to all ports with a distance from them to the root switch.

The distance between switches is defined in the IEEE 802.1D standard. Suppose we have a connection with 1 Gbps switches, in this case we use the number 4 as the distance value, as in the table below.

In the first step, the switches that are connected directly to the root switch determine the connection speed with this switch and choose the appropriate distance value.

In our case, the 1 Gbps connection speed of the distance value is 4. This shortest distance to the root switch is then broadcast to the fourth switch. The 4-way switch takes this value of 4, determines the connection speed with these switches 1 Gbps distance 4 and the total distance 8. Now we know the distance from all ports to the root switch.

The next task is to disconnect one of the connections so that there is no ring. According to the rules of the STP protocol, if we have two paths to the root switch, we must choose the path with the minimum distance, and disable the other path. But in our example, there are two paths with the same distance of 8. In this case, the path with the larger port value is disabled.

If ports are numbered from left to right, the port on the right will be disabled.

This completes the work of the STP protocol, we have a spanning tree. All four switches are interconnected and there is no cycle. If one of the connections breaks, then now we will have one path with a distance of 8.

Therefore, we have every right to turn it off and use it for data transfer.

Port status in STP

If we use the STP protocol, then when the device is connected to the switch, we cannot immediately start transferring data, because there may be another switch and a new connection can lead to the creation of a ring. To avoid this problem, switches that support the STP protocol use several port modes.

  • At the first stage, when the cable is just connected to the switch port, the port operates in Listening mode - the port processes the control message of the STP protocol, but does not transmit any data.
  • At the second stage, which is called Learning, the port receives data, but does not transmit it anywhere. From the received frames, the sender addresses are extracted and used to create the switching table.
  • There are two options for the next step. If it turns out that a computer or a switch is connected to the port without forming a ring, then the port switches to the Forwarding state - the port receives and transmits data, and also receives and transmits a control message to the STP protocol.
  • But if it turns out that a switch is connected to the port and a ring has formed, then the port goes into the Blocking state - the port is blocked at the software level so that there is no ring.
  • In addition, the administrator has the ability to forcibly disable the port by setting it to the Disabled state. In this case, data will not be transmitted regardless of what is connected to the port of the computer, switch, whether there is a ring or not.

STP development

In the STP protocol, the transition from the state when you just plugged in the cable to the Forwarding state takes quite a long time, approximately 30 seconds. In the 80s, when the protocol was being developed, this was acceptable. But now networks have become much larger and change more often, so waiting 30 seconds for STP to work is no longer possible.

Therefore, a new variant of the STP protocol was proposed, which is called RSTP (Rapid Spanning Tree Protocol) - a fast spanning tree protocol.


Learn more