Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Working principle and algorithm of spanning Tree Protocol (STP)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Spanning Tree Protocol (STP)

I. Overview of STP

1. Generation of switch network loop

As shown in the figure above, PC1 and PC2 are connected through a switch, and in the initial state of the network, the communication process between PC1 and PC2 is as follows.

1) at the beginning of network communication, there is no MAC address of PC2 in the ARP entry of PC1. According to the principle of ARP, PC1 will first send an ARP broadcast request (the MAC address of the request PC2) to the switch SW1.

2) when the blocking SW1 receives the broadcast request from the ARP, according to the forwarding principle of the switch, the SW1 switch forwards the broadcast frame out all ports except the receiving port (that is, the broadcast will be forwarded to SW2 and SW3 from F0Uniq1 and F0UniP2, respectively).

3). After SW2 receives the broadcast frame, it also forwards the broadcast frame from the port F0swap 2 and the port connected to PC2 according to the forwarding principle of the switch. similarly, after SW3 receives the broadcast frame, it forwards it from port F0max 2.

4) the SW2 forwards the broadcast frame sent from the SW3 from F0ram2 port and the port connected to the PC2. Similarly, when SW3 receives the broadcast frame sent from the SW2, it forwards it from the F0amp1 port.

5), SW1 receives broadcast frames from SW2 and SW3 respectively, then forwards the broadcast frames received from SW2 to SW3, and forwards the broadcast frames received from SW3 to SW2.

SW1, SW2, and SW3 forward broadcast frames to each other, creating a loop in the network that is not known to the switches, which causes the broadcast frame to loop forever in the loop, as shown in the following figure:

In the actual network environment, the situation is much more complicated. When the broadcast frame passes through the switch, the switch generates the broadcast frame exponentially (all ports except the broadcast frame received by the switch forward the broadcast frame). There will be more and more such broadcast frames. Finally, a broadcast storm was formed, which led to the paralysis of the network.

However, the ring-shaped physical lines can provide companies with backup favorite South Road and enhance the reliability of the network, so there is a solution, on the one hand, to ensure the reliability of the network, on the other hand, it can also prevent the occurrence of broadcast storms.

STP (spanning Tree Protocol): not to break the physical loop, but to logically break the loop to prevent broadcast storms.

1.2. introduction to STP

STP (spanning Tree Protocol): is to change a ring structure into a tree structure. STP protocol is used to talk about the physical existence of loops in the network, through an algorithm, logically block some ports to generate a logical tree structure.

Logically disconnect the loop to prevent broadcast storms.

When the line fails, the blocking interface is activated to restore communication and act as a backup line.

The communication process after three switches logically disconnect a port using STP, as shown below

When the link between SW1 and SW2 fails, logically blocked ports are automatically opened, as shown below:

Second, the working principle of STP

1. Spanning tree algorithm

The spanning tree algorithm can be summarized into the following three steps:

1) Select the root bridge (boot bridge)

2), select the root port (root ports)

3), select designated port (designated ports)

1) the algorithm for selecting the root bridge

The root bridge is selected on the basis of the bridge ID, which is an 8-byte field and its composition diagram is shown in the following figure

The decimal number of the first 2 bytes becomes the bridge priority, and the last 6 bytes are the MAC address of the bridge.

The bridge priority is the decimal number used to measure the priority of the bridge in the spanning tree algorithm. The range of values is 0mm 65535, and the default value is 32768.

The MAC address in the bridge ID is the MAC address of the switch itself, which can be viewed using show ver.

The switch displays the address of the MAC as follows:

According to the definition of spanning tree algorithm, the ID value of the switch bridge is the lowest, and the one with low priority is chosen as the root bridge; in the case of the same priority, the one with low MAC address is the root bridge.

2), select the root port

The root port exists on a non-root bridge, and you need to select a root port on each non-root bridge.

When you select a root port, the order is as follows:

A. the lowest root path cost to the root bridge

B. The ID of the directly connected bridge is minimum.

C, Port ID minimum

The relationship between bandwidth and path cost

Link bandwidth (Mbps)

Path cost

ten

one hundred

sixteen

sixty-two

forty-five

thirty-nine

one hundred

nineteen

one hundred and fifty five

fourteen

six hundred and twenty two

six

one thousand

four

10000

two

Port ID is a 2-byte STP parameter consisting of a 1-byte port priority and a 1-byte port number.

Port priority is a configurable STP parameter. On IOS-based switches, the decimal value of port priority ranges from 0 to 255, with a default value of 128. 8.

The port number Catalyst is used to enumerate the numeric identifiers of each port. 256ports can be supported on IOS-based switches. The port number is not the port number, but if the port number is low, the port number is also low.

When STP selects the root port, it first compares the root path cost of the switch port, and the root path cost is low. When the cost of blocking the root path is the same, compare the bridge ID value of the connected switch, select the root port with the lowest bridge ID value; when the bridge ID is the same, compare the port ID value and choose the smaller root port. (note: when comparing port ID values, you are comparing the received port ID values of the opposite end)

3), select the designated port

In order to eliminate the possibility of loop formation, STP makes the final calculation and selects a designated port on each network segment.

The order of selecting designated ports is as follows:

A. The cost of the root path is low.

B. The bridge ID of the switch is low.

C, the port ID value is low.

When STP selects a designated port, it first compares the lowest cost of the root path in the upper port of the same network segment, that is, the port closest to the root bridge is used as the designated port. In addition, the interfaces on the root bridge are designated ports because the root path of the port on the root bridge becomes 0. (note: unlike selecting the root port, when comparing the port ID value, you compare its own port ID value.)

Spanning tree algorithm verification:

View SW1 spanning tree status

View SW2 spanning tree status

View SW3 spanning tree status

2. Bridge Protocol data Unit (BPDU)

BPDU (bridge protocol data unit) is used to exchange bridge ID, root path cost and other information between switches. The BPDU frame uses a STP multicast address (01-80-c2-00-00-00) as one of its destination addresses, enabling it to reach adjacent switches in the STP listening state.

BPDU messages are sent to all switch ports every 2s so that the switch can exchange the latest topology information and quickly identify and detect loops.

2.1.Two types of BPDU

Configure BPDU for spanning tree calculation.

Topology change Notification (topology change notification,TCN), BPDU is used to advertise changes in the network topology

2.2, BPDU newspaper text field

BPDU includes root bridge ID, root path cost, send bridge ID, port ID, timer and so on. The functions of several key fields of BPDU are explained as follows.

Root bridge ID: consists of a 2-byte priority and a 6-byte bridge MAC address. This information combination indicates the device ID that has been selected as the root bridge

Root path cost: indicates how far this BPDU is transmitted from the root bridge and how much it costs. The value of this field determines which ports will be forwarded and which ports will be blocked.

Send bridge ID: this is to send the BPDU bridge information, which consists of the priority of the bridge and the MAC address of the bridge.

Port ID: consists of one byte of port priority and one byte of port number.

Timer: used to describe how long it will take for the spanning tree to complete each of its functions. These features include message aging time, maximum aging time, access time, and forwarding delay.

2.3.The process of selecting root bridge by using BPDU in STP

When a switch starts for the first time, assume that it is the root bridge and fill in its own bridge ID in the root bridge field in the BPDU message, as follows:

After receiving the BPDU from other switches, compare the bridge ID and select the smaller one to add to the root bridge ID

When all the switches in the network receive all the BPDU and compare them, the only root bridge can be selected.

3. Convergence of STP

In the process of STP operation, each port of the switch must go through several states.

The five STP states of the switch port are listed below

Shape state

Way of use

Forward (Forwarding)

Send / receive user data

Learning (Learning)

Build a bridge table

Intercept (Listening)

Build an "active" topology

Blocking (Blocking)

Only receive BPDU

Disable (Disabled)

Forced shutdown

The STP port status is described in detail as follows:

Disabled (disabled): an administrator shuts down or a network failure causes the port to be in the Disabled state, which is not part of the normal STP state.

Blocking (blocking): after a port is initialized, a port can neither accept or send data nor add MAC addresses to its address table. In contrast, such a port is only allowed to receive BPDU messages so that information from other neighboring switches can be heard. In addition, after the designated port is selected, the non-designated port is also in a blocking state.

Listening (snooping): if a switch thinks that a port can be selected as a root port or a designated port, it will change the Blocking state of the port to the Listening state, and in the Listening state, the port still cannot receive or send data frames. However, in order to add the port to the spanning tree topology process, he is allowed to receive or send BPDU messages. Because the port can advertise the port's information by sending BPDU messages to other switches, the port may eventually be allowed to become a root port or a designated port. If the port loses its root port or designated port status, it returns to the Disabled state.

Learning (Learning): a port will change to Learning state after a period of time in Listening state. The port can still send and receive BPDU messages as before. However, the switch can learn the new MAC address and add the changed address to the address table of the switch. Because of this, the switch can be silent for a certain period of time before processing information about the address table.

Forwarding (forwarding): download in Learning state after a period of learning and forwarding, the port is transferred to Forwarding state. In the Forwarding state, the port can not only send and receive data frames, but also add the mobile phone MAC address table to his address table, and also send and receive BPDU messages. In the regenerated tree topology, the port becomes a fully functional switch port.

STP uses three timing methods to ensure the normal convergence of a network.

A, Hello time: the interval between the configuration BPDU messages sent by the bridge. The access time value configured in the root bridge switch determines the access time of all non-follower switches because these switches only relay them when they receive configuration BPDU messages from the root bridge. However, all switches have a locally configured access time, which is used to determine when to resend the TCN BPDU (Topology change Alert) message. The default access time specified in the IEEE 902.1d standard is 2s.

B, forwarding delay: the time interval that a switch port spends in the Listening and Learning states, and its default value is 15s.

C, maximum aging time: the maximum time that the switch stores the BPDU message before it is discarded. When performing a STP, each switch port keeps a copy of the "best" BPDU backup it has heard. If the source BPDU loses contact with the switch port, the switch notifies the network of a topology change after the maximum aging time. The default value for maximum aging time is 20s.

Both snooping and learning are transitional states implemented by spanning tree to force ports to wait for all BPDU from other switches. A typical port transition is as follows.

III. The relationship between STP and VLAN

The main relationships between spanning tree and vlan are as follows:

A, CST of IEEE (Common Spanning Tree, universal spanning tree).

B, PVST of Cisco (Per vlan spanning Tree, each vlan spanning tree).

C, PVST+ of Cisco (Per vlan spanning Tree Plus, each enhanced vlan spanning tree).

D, MST of IEEE (Multiple spanning Tree, multiple spanning trees).

CST: regardless of VLAN, run STP on a switch basis (the entire switching network generates a STP instance), so after STP calculation, if a port is blocked, vlan3 will not be able to communicate.

As shown below:

PVST:Cisco proprietary protocol to run a separate spanning tree instance for each vlan (one spanning tree instance per vlan). As shown below:

PVST optimizes the location of the root bridge, providing a final path for all vlan (because the topology of the vlan is different).

The main disadvantages of PVST are as follows:

In order to maintain the spanning tree generated by each vlan, the utilization of the switch, such as the CPU load, is higher.

In order to support the BPDU of each vlan, more trunk link bandwidth is needed.

PVST is not compatible with IEEE's CST and cannot interoperate with switches from other manufacturers.

In order to interoperate with switches from other manufacturers, Cisco developed PVST+. PVST+ allows information from CST to be passed to PVST so that other vendors can run spanning tree implementations on vlan for interoperability. As shown below:

PVST+ generates a spanning tree instance for each vlan.

IV. Configuration commands of PVST+

Enable spanning tree command

Switch (config) # spanning-tree vlan vlan-list

Specify the root bridge

Switch (config) # spanning-tree vlan vlan-list priority Bridge-priority

Switch (config) # spanning-tree vlan vlan-list root {primary | secondary}

Modify port cost

Switch (config-if) # spanning-tree vlan vlan-list cost cost

Modify port priority

Switch (config-if) # spanning-tree vlan vlan-list port-priority priority

Configure the port as a speed port

Switch (config-if) # spanning-tree portfast

For example:

Use the following command to specify the root bridge

Switch (config) # spanning-tree vlan 2 priority 4096

Or use the following command to specify the root bridge

Switch (config) # spanning-tree vlan 2 root primary

Use the following command to modify the cost and priority of port F0amp 1

Switch (config-if) # spanning-tree vlan 2 cost 10

Switch (config-if) # spanning-tree vlan 2 port-priority 96

View the configuration of the spanning tree using the following command

Switch#show spanning-tree

Use the following command to view the spanning tree details of a vlan

Switch#show spanning-tree vlan 2

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report