STP Spanning Tree Protocol Working Principle

STP Spanning Tree Protocol Working Principle

In a complex network, loops are inevitable. In addition, due to the need for redundancy and backup, network designers tend to deploy multiple physical links between devices, one of which is the main link and the other links are backup. This will inevitably lead to loops. Loops will cause broadcast storms, which will eventually lead to the exhaustion of the entire network resources and the network paralysis and unavailability. Loops will also cause MAC address table oscillations, resulting in the destruction of MAC address table entries. In order to break the loop, the data link layer protocol STP is used. Let's take a look at how STP breaks it.

How STP works

The essence of STP is to logically block one of the ends to break the loop. So what mechanism does it use to select which port is blocked? The spanning tree algorithm can be summarized into the following three steps:

1. Select the root bridge

Each switch has a unique bridge ID (BID), and the switch with the smallest BID value is the root switch. Because BID (8 bytes) = bridge priority (2 bytes) + bridge MAC (6 bytes), a switch can be made the root switch by adjusting the priority.

2. Select the root port

After the root bridge is selected, other non-root bridges select a port closest to the root bridge as the root port.

The root port is selected based on the following:

  • The port on the switch with the lowest total path cost to the root bridge
  • If the costs to reach the root bridge are the same, the bridge IDs of the superior senders are compared and the port corresponding to the smallest sender bridge ID is selected.
  • If the sender bridge ID is also the same, then compare the sender port ID. The port ID consists of the port priority (8 bits) and the port number (8 bits). If the port priorities are the same, the one with the smallest port number is selected.

Link Speed ​​and Path Cost

3. Select the specified port

Each network segment selects a designated port, and all ports of the root bridge are designated ports.

The basis for selecting a non-root bridge designated port is as follows:

  • The path cost to the root bridge is the lowest
  • The bridge where the port is located has the smallest ID
  • Port value is smaller

After the above three steps, the root bridge, root port and designated port are all selected. The remaining ones are non-designated ports, which are also the ports that will be logically blocked by the STP protocol.

The following is a simple case to give a deeper understanding of the working process of STP.

The topology shown in the figure above consists of three Huawei S5700s, with the default priority of 32768 and the same bandwidth of 1000Mbps. Huawei switches have STP enabled by default.

Based on the knowledge points above, it is quickly determined that SW1 is the root switch. Since the priorities are the same, SW1 has the smallest MAC address, so it is called the root port. Verify this by executing the following command on the switch:

  1. [SW3]display stp

What are the root ports?

The port closest to switch SW2 and switch SW1 is selected as the root port. As can be seen from the topology above, under the same bandwidth, GE0/0/1 port of SW2 is closest to SW1, so it is the root port. Similarly, GE0/0/2 port of SW3 is the root port. You can verify it on the switch with the following command

  1. display stp brief

What are the designated ports?

The cost from GE0/0/3 of SW2 and SW3 to the root port is the same. The SW3 switch port with a smaller BID is selected as the designated port. Therefore, GE0/0/3 of SW3 is the designated port, and GE0/0/3 of SW2 is the blocked port.

With the above knowledge, we can achieve the desired effect by controlling some variable values. For example, to make SW3 the root switch, we can lower the priority of SW3 (it must be a multiple of 4096). Execute the following command

  1. [SW3]stp priority 4096

We can also modify the port priority, link cost and other parameters to achieve the desired effect. The specific commands are as follows:

  1. #Modify the port cost value
  2. [SW2-GigabitEthernet0/0/1]stp cost 1000
  3. # By modifying the port priority
  4. [SW2-GigabitEthernet0/0/1]stp port priority 32

<<:  Interpretation of the financial reports of the three major operators in the first three quarters: cold winter is coming, warm spring is still far away

>>:  Understand in one article: website, URL, domain name, IP address, DNS, domain name resolution

Recommend

Huawei obtains the world's first PUE test certificate for micro-module products

The 4th Data Center Infrastructure Summit was suc...

The role of 5G in education: enabling distance learning and virtual labs

In an era of rapid technological change, 5G is mo...

Digital currency: Don’t be fooled by the “blockchain” cover

Since the beginning of this year, the digital cur...

Let’s talk about gRPC that you don’t know today

Hello everyone, I am Zhibeijun. It is the last da...

How fast is 5G? How does the 5G network work?

[[257849]] 4G LTE has been providing ultra-fast d...

7 New Year's Resolutions for the Internet of Things

The beginning of a new year is often a time for p...