What is STP (Spanning Tree Protocol) ? Quick Introduction

To improve network reliability, redundant links are often used in switched networks. However, a redundant link will bring a loop risk to the switching network, and cause problems such as broadcast storms and unstable MAC address tables, thereby affecting the communication quality of users. Spanning Tree Protocol (STP) is a data link layer protocol run by switches and used to solve loop problems in switching networks.

Why STP

1. Broadcast Storm

Consider a possible scenario:

The three switches SWA, SWB, and SWC are connected together as shown in the figure below. Assuming that host A wants to send data to host B, it will first send an ARP request to obtain the MAC address of host B. However, because the Request packet of ARP belongs to a broadcast frame, when SWB receives the broadcast frame sent by host A, it will send the broadcast frame to all ports; when SWA receives the broadcast frame sent by SWB, it will also send the broadcast frame. to all ports; and so on. At this time, broadcast frames are sent and received cyclically in SWA, SWB, and SWC, which consumes switch resources and causes service paralysis.

2. MAC Address Oscillation

When SWB receives the broadcast frame sent by host A for the first time, the source MAC address is: 00-05-06-07-08-AA, and the source port is G0/0/3. Because the broadcast frame is sent and received cyclically among the three switches, when the SWC sends the broadcast frame to the SWB, the MAC address of the broadcast frame received by the SWB remains unchanged, namely: 00-05-06-07-08-AA. However, the source port at this time has become the G0/0/2 port of the SWC. This is called MAC address oscillation.

How STP works

Imagine how to eliminate loops in a network with loops. One choice is to cut one of the lines who causes the loop. But we cannot cut it physically, there is no way for the two devices to achieve link backup in the event of a failure in the network. How can we not only eliminate loops in a looped network, but also implement link backup? Obviously, there is no way to achieve this in the physical state. (Because it is impossible to monitor network failures by manually plugging and unplugging network cables) But we can imagine that if at the logical level, the network keeps one of the ports in a blocked state under normal operation, and when the network fails, Keep the port in the forwarding state and return to normal. Complete link backup. In this way, loops can be eliminated and link backup can be achieved.

This is the basic principle of the STP protocol: in a switched network with a physical loop, the switch automatically generates a working topology without loops by running the STP protocol. The loop-free working topology also becomes an STP tree. When the network topology changes, the STP tree will also automatically change accordingly. In short, the physical topology with loops improves the reliability of network connections, while the working topology without loops avoids broadcast storms and MAC address table flapping. This is the essence of STP.

STP Terminologies

  • Bridge : Early switches generally only had two forwarding ports, so the switches at that time were often called “bridges”, or simply “bridges”. Later, the term “bridge” has been used to this day, but it does not refer to a switch with only two forwarding ports, but generally refers to a switch with any number of ports. The terms “bridge” and “switch” are currently used interchangeably.
  • Bridge MAC Address: We know that a bridge has multiple forwarding ports, and each port has a MAC address. Usually, we take the MAC address of the port with the smallest port number as the MAC address of the entire bridge.
  • Bridge Identifier, BID: The bridge ID of a bridge (switch) consists of two parts, namely: bridge priority + bridge MAC address; the value of bridge priority can be set manually, and the default value is 0x8000 (equivalent to in decimal 32768). The value range is 0~65535.
  • Port Identifier, PID: The port ID of a port of a bridge (switch) consists of two parts, namely: port priority + port number; the value of port priority can be set manually. Devices from different manufacturers may occupy different bytes for the two parts.
  • BPDU (Bridge Protocol Data Unit): The payload data of the protocol frame.

STP Workflow

  1. Elect Root Bridge: Election of a root bridge in a switched network.
  2. Elect Root Port: A root port is elected on each non-root bridge.
  3. Elect Designated Port: A designated port is elected for each network segment.
  4. Block Non-designed Ports: Block all remaining non-root, non-designated ports on the switch.

Elect Root Bridge

The root bridge is the root node of the STP tree. To generate a lesson STP tree, we must first determine a root bridge. When switches running the STP protocol (referred to as STP switches) exchange STP protocol frames with each other, the payload data of these protocol frames is called a BPDU (Bridge Protocol Data Unit, bridge protocol data unit). After the initial startup of the STP switch, it will consider itself as the root bridge. And it announces itself as the root bridge in BPDUs sent to other switches. When the switch receives BPDUs sent by other devices from the network, it will compare the BID of the root bridge specified in the BPDU with its own BID. The switch will continuously exchange BPDUs and compare them until it finally elects a switch with the smallest BID value as the root bridge.

Elect Root Port

After the root bridge is elected, other switches that have not become root bridges become non-root bridges (or non-root switches). A non-root bridge device may have multiple ports connected to the network. In order to ensure that the working path from a non-root bridge device to the root bridge is optimal and unique, the ports of the non-root bridge device must be selected. A port called “root port” will be elected, and the root port is used as the port for packet exchange between the non-root bridge device and the root bridge device. There can only be at most one root port on a non-root bridge device.

Non-root bridge elects a root port based on the root path cost, peer BID, peer PID, and local PID of the port. In a network running the STP protocol, we refer to the cumulative path cost from a port of a switch to the root bridge (that is, the sum of the path costs of all links from the port to the root bridge) as the Root Path Cost (RPC). The path cost of a link is related to the port rate. The higher the port forwarding rate, the smaller the path cost. The corresponding relationship between port rate and path cost is shown in the following table:

Elect Designated Port

The root port ensures the uniqueness and optimality of the working path between the switch and the root bridge. To prevent the existence of working loops, the working path between each network segment and the root bridge in the network must also be unique and optimal. When a network segment has two or more paths leading to the root bridge, the switch connected to the network segment must determine a unique designated port. The designated port is also determined by comparing the RPCs, and the port with the smaller RPC will become the designated port. If the RPCs are the same, you need to compare BIDs, PIDs, etc.

Block Non-designed Ports

After the root ports and designated ports are determined, all remaining non-root ports and non-designated ports on the switch are collectively referred to as spare ports. STP will logically block these ports. The so-called logical blocking means that these spare ports cannot forward the frames generated and sent by the terminal computer. These frames are also called user data frames. However, the alternate port can accept and process STP protocol frames. The root port and designated port can not only send and receive STP protocol frames, but also forward user data frames.

Leave a Comment

Your email address will not be published.