A brief description of the standard Spanning Tree Protocol STP

A brief description of the standard Spanning Tree Protocol STP

Spanning Tree Protocol STP

Why spanning tree is needed

As shown in the network topology above, if there is no spanning tree protocol, at the beginning of network communication, assuming that PC0 sends a data packet to PC1, there is no corresponding MAC address in the MAC address table of switch S2, so ARP flooding will occur (details Refer to the article on the self-learning algorithm of the switch) to send broadcast frames, which are sent to the peer end by the Fa0/1 and Fa0/3 ports of S2.

After S1 and S3 respectively receive the broadcast frame, they forward the broadcast frame according to the same principle. At this time, the network forms a loop, but the switch does not know that this will cause broadcast frames to loop forever in the loop.

As time increases, there will be more and more broadcast frames, and finally a network broadcast storm will be formed and the network will be paralyzed. (For the computing speed of the switch, the time for the network to change from normal to paralyzed is very short)

STP concept

From the above description, we can know that we need a solution to solve this problem, so there is a spanning tree protocol.

Spanning Tree Protocol (English: Spanning Tree Protocol , STP ) is a communication protocol that works at the data link layer in the OSI network model. The basic application is to prevent loops generated by redundant links of switches. Logical topology used to ensure loop-free Ethernet. In this way, the network broadcast storm is avoided, and a large amount of resources of the switch are occupied.

Consistent with the concept of spanning tree in graph theory, the purpose is to break the loop (turn the circular graph into a tree).

STP will block the backup link, which will be activated when the normal line is damaged.

The default STP version on the switch also includes multi-instance spanning tree (MSTP), rapid spanning tree (RSTP), etc. This article only describes the standard version.

The core of the spanning tree protocol is the spanning tree algorithm (Spanning Tree Algorithm, STA ). The STA algorithm process is described below.

Spanning Tree Algorithm STA

The switch is evolved from the bridge, and it also refers to the switch when describing the spanning tree algorithm

STA is roughly divided into three steps:

  • elect root bridge
  • election root port
  • Election of designated ports and blocking of alternate ports

elect root bridge

Election conditions: the one with the smallest bridge ID (BID) is elected

BID consists of the following two parts:

  • priority
  • The base MAC address of the switch

The priority range is 0-61440, the step size is 4096, and the default value is 32768

Seeing this, someone may ask, why is the step size exactly 2 to the 12th power or 4096? This is not a coincidence, because the step size here is the VLAN number (the VLAN number uses 12 bits)

BID comparison method:

  • The smaller the priority value, the smaller the BID
  • If the priority is the same, then compare the MAC addresses, starting from the left side of the MAC address, the smaller the BID, the smaller the value

election root port

The root port (Root Port, RP ) is elected on the non-root bridge (non-root switch), and only one RP can exist on each switch.

The RP is used to receive BPDUs sent by the root bridge and also to forward common traffic.

The RP election first considers the path cost from the BPDU receiving port to the root bridge to be the smallest, and the path cost corresponds to the link bandwidth as follows (this value is not absolute and can be changed on the switch)

link bandwidth cost value
4Mb/s 250
10Mb/s 100
16Mb/s 62
100Mb/s 19
1Gb/s 4
10Gb/s 2

If there are multiple ports with the same cost to the root bridge, the BIDs of the peers are compared , and the local port with the smaller BID of the peer is elected as the RP.

(Note that BID is the opposite end, that is, the port of other switches connected to the port participating in the election, and the port participating in the election is on this switch)

If the BID of the opposite end is also the same, the port ID (PID) of the opposite end is compared, and the local port with the smaller PID of the opposite end is also elected as the RP.

The PID parameters are as follows:

  • Range 0-240
  • step size 16
  • The default value is 128
  • Port number (for example, Fa0/1 is smaller than Fa0/2)

(In fact, there is still a situation where the BID and PID of the peer end are the same. For details, please refer to the STA example section -> other examples -> the case of using a hub)

Election of designated ports and blocking of alternate ports

Select a designated port (Designated Port, DP ) on each network segment . DP is used to forward BPDUs sent by the root bridge, and is also used to forward common traffic.

Note: There can only be one DP on each network segment

The election conditions of DP are as follows:

  • All ports of root bridge are DP
  • The peer port of the root port must be DP (and vice versa)
  • The path cost of the BPDU forwarding port to the root bridge is the smallest
  • The BID of the local end is the smallest

The remaining ports become Alternate Ports (APs) and they will be blocked.

STA example

main example

The network topology is as follows

Follow the steps above

First elect the root bridge

  • The priorities are all 32768, and then compare the MAC addresses. The MAC address of S1 is 00-01-..., which is smaller than other addresses, so S1 is the root bridge.

Then select the root port

  • All links on the path from switch S2 to S1 are 1Gb/s, so the overhead is 4, the total overhead from G0/1 to S1 is 4, the total overhead from G0/2 to S1 is 8, and the total overhead from G0/3 to S1 The total cost of is 12, so the root port of S2 is G0/1.

  • Similarly, the root port of S3 is G0/1, and the root port of S4 is G0/2 (the peer BID of G0/2 is smaller than the peer BID of G0/1, and the cost of the two is the same).

  • The root port of S5 is Fa0/1 (the cost of Fa0/1 is the same as that of Fa0/2, and the peer BID is the same, but the peer of Fa0/1 is Fa0/1 of S4, the port number is small, so the PID is small).

Election of designated ports and blocking of alternate ports

  • S1 is the root bridge, so G0/1 and G0/2 of S1 are designated ports
  • Then according to the second condition, all RP peer ports are DP, then the selected ones are: G0/3 of S3, Fa0/1 of S4

  • The remaining few network segments cannot select DP according to the second condition, and then select according to the third condition, that is, the path with the smallest cost to S1
  • First look at the network segment S4Fa0/2-S5Fa0/2, the cost to S4Fa0/2 is 8, and the cost to S5Fa0/2 is 27, so the Fa0/2 port of S4 wins and is the DP of this network segment
  • Looking at the link S2G0/2-S3G0/2, the cost of these two ports to S1 is the same, but the BID of S3 is smaller than that of S2, so G0/2 of S3 is the DP under this network segment
  • Similarly, G0/3 of S2 is also DP
  • The rest of the ports are AP

other examples

The known conditions are as follows:

  • All link bandwidths are equal (that is, link cost values ​​are the same)
  • S2 BID < S3 BID

Then the RP of S4 in the figure below is shown in the red circle

There is a special case where a hub is used. On S4, the link cost of Fa0/1 and Fa0/2 is the same, and the cost of Fa0/3 is higher than the former two, and the peer BID and peer PID of Fa0/1 and Fa0/2 are the same , at this time the comparison is the PID of the local port, as shown in the figure below

Finish

The above only describes and analyzes the most basic situation of STA. The situation in the actual network is more complicated, such as a bridge (switch) suddenly goes offline, the link is damaged, the switch fails before the spanning tree is generated and needs to be re-elected, etc. .

Guess you like

Origin blog.csdn.net/qq_42759112/article/details/128079471