STP protocol (Spanning Tree Protocol)

1. Overview of STP protocol

Spanning tree protocol (spanning tree protocol) is a communication protocol that works on the second layer (data link layer) in the OSI network model. It is run by switches. The basic application is to prevent redundant links of switches from being generated. Loops are used to ensure a loop-free logical topology in the Ethernet, thereby avoiding broadcast storms and occupying a large amount of switch resources.

The working principle of the spanning tree protocol: if there are two or more links to the root bridge in any switch, the spanning tree protocol will cut off one of them according to the algorithm, and only keep one, so as to ensure that there is only one single link between any two switches. Active link, because the generated topology is very similar to the tree structure with the switch as the trunk, so it is the spanning tree protocol.

The working process of STP is as follows: In a switching network with physical loops, the switch automatically generates a working topology without loops by running the STP protocol. The loopless working topology also becomes an STP tree. When the network topology changes, the STP tree will automatically change accordingly. In short, the looped physical topology improves the reliability of the network connection, while the loopless topology The working topology avoids broadcast storms and MAC address table shocks. This is the essence of STP.

Before learning the STP tree, you need to understand a few basic terms: bridge, bridge MAC address, bridge ID, port ID

Bridge : Early switches generally only had two forwarding ports, so switches at that time were often called "bridges". Later, the term "bridge" has been used to this day, but it does not refer to switches with only two forwarding ports, Generally refers to a switch with any number of ports. Currently, the terms "bridge" and "switch" can be used interchangeably.

Bridge MAC address : We know that a bridge has multiple forwarding ports, and each port has a MAC address. Usually, we use the MAC address of the port with the smallest port number as the MAC address of the entire bridge.

Bridge ID (BID): The bridge ID of a bridge (switch) consists of two parts, namely: bridge priority + MAC address of the bridge; the value of bridge priority can be set manually, the default is 0x8000 (equivalent to 32768 in decimal), The value range is 0~65535.

Port ID (PID) : A port ID of a bridge (switch) consists of two parts, namely: port priority + port number; the value of port priority can be set manually. The number of bytes occupied by the second part of the equipment of different manufacturers may be different.

 

The generation process of the STP tree is : first elect the root bridge, then determine the root port and the designated port, and finally block the standby port.

1. Election Root Bridge

        The root bridge is the root node of the STP tree. To generate an STP tree, a root bridge must first be determined. 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 BPUD (Bridge Protocol Data Unit). After the initial startup of the STP switch, it will consider itself as the root bridge, and declare itself as the root bridge when sending to other switches. When the switch receives BPUD from other devices in the network, it will compare the root bridge BID specified in the BPUD. With its own BID, the switch continuously exchanges BPUD and compares them until a switch with the smallest BID value is elected as the root bridge.

 As shown in the figure, switches S1, S2, and S3 all use the default bridge priority of 32768. Obviously, S1 has the smallest BID, so S1 is finally elected as the root bridge.

2. Determine the root port

        After the root bridge is determined, other switches that do not become the root bridge become non-root bridges. 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 Optimum and unique, a port called the "root port" must be determined from the ports of the non-root bridge device, and the root port is used as the port for the non-root bridge device to exchange packets with the root bridge device . There can be at most one root port on a non-root bridge device.

The non-root bridge elects the root port based on the port's root path cost, peer BID, peer PID, and local PID. In a network running the STP protocol, we call the cumulative path cost from a port of a switch to the root bridge (J is the sum of the path costs of all links passing through the port to the root path) as the root path cost of this port (Root Path Cost, RPC), the path cost of the link is related to the port rate, the higher the port forwarding rate, the smaller the path cost.

Example 1: Election of root port based on RPC

 As shown in the figure, it is assumed that S1 has been selected as the root bridge, and now S3 needs to determine the removal port from port 1 and port 2. Obviously, the RPC of port 2 of S3 is 20 000; the RPC of port 1 of S3 is 200 000+20 000=22 0000, and the switch will determine the port with the smallest RPC as its root port, so S3 will determine port 2 is its own root port, similarly, S2 determines its own 1 port as the root port.

Example 2: Elect the root port based on the peer BID

 However, in practical applications, the RPC on a non-root bridge device may be the same, as shown in the figure, it is assumed that S1 has been selected as the root bridge. For S4, the RPCs from port 1 and port 2 to the root bridge are the same. In this case, the root port needs to be elected according to the peer BID. For S4, its peer BID is also the BID of S2 and the BID of S3. After comparison, assuming that the BID of S2 is smaller, port 1 is the root port of S4; otherwise, port 2 is the root port of S4.

Example 3: Elect the root port based on the peer PID

 As shown in the figure, the RPC of the non-root bridge and the peer BID of the two devices are the same in this connection mode. In this case, the root port needs to be elected according to the peer PID. For S2, its peer PIDs are Root's GE0/0/1 port and GE0/0/2 port. Assuming that Root's port priority is 128, then Root's port numbers are 1 and 2. Obviously, the PID of GE 0/0/1 of Root is smaller, so the GE 0/0/1 port of the S2 device connected to it is selected as the root port.

Example 4: Elect the root port based on the local PID

 As shown in the figure, the two devices are connected through a HUB. In this way, the RPC, peer BID, and peer PID of the non-root bridge are all the same. In this case, the root port needs to be elected according to the local PID. Assuming that the port priority of S2 is 128, it is obvious that the PID of port 1 is smaller. Therefore, port 1 of S2 is selected as the root port.

3. Determine the designated port

The root port ensures the uniqueness and optimality of the working path between the switch and the root bridge. In order 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 RPCs, and the port with the smaller RPC will become the designated port. If the RPCs are the same, you need to compare the BID, PID, etc.

 

As shown in the figure, assume that S1 has been elected as the root bridge, and assume that the costs of all links are equal. Obviously, S2 determines GE 0/0/1 as its own root port, and S3 also determines GE 0/0/1 as its own root port. On the network segment between S1 and S2, and between S1 and S3, it is obvious that Ethernet 0/0/1 and Ethernet 0/0/2 are designated ports. In the network segment between S2 and S3, since the RPCs of the two ports are the same, it is necessary to compare the BIDs of S2 and S3 at this time; assuming that the BID of S2 is smaller than the BID of S3, then the GE 0/ Port 0/2 is elected as the designated port for this network segment.

Note: Through the above examples, it is not difficult to find a rule: all ports on the root bridge are designated ports.
4. Block the backup port

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

 As shown in the figure, once the standby port is logically blocked, the generation process of the STP tree (loop-free working topology) is completed.

Guess you like

Origin blog.csdn.net/weixin_60067160/article/details/125871101