STP principle and configuration

STP protocol overview

The Spanning Tree Protocol (STP) solves the loop problem in link redundancy.

STP eliminates loops by blocking ports and can achieve the purpose of link backup. This kind of congestion is a logical congestion. Service messages cannot be forwarded, but protocol messages can be forwarded.

STP determines the port to be blocked by sending a BPDU (Bridge Protocol Date Unit) bridge protocol data unit

IEEE 802.3 frame format

Insert picture description here
The destination MAC is a multicast MAC address, and only the switch will receive the multicast address.
The Type value is 0x03.

STP working process

Insert picture description here

The election is divided into four steps

1. Elect a root bridge (Root Bridge)
2. Each non-root switch elects a root port (R: Root port)
3. Each network segment elects a designated port (D: Designated port)
4. Block non-root, Non-designated port (A: Alternative Port)

Every election step

1. Root Bridge Election

Bridge ID: compare priority (0~65536, default 32768, the smaller the value, the higher the priority) + compare MAC

2. Root port election

Root port: According to cost (link cost), the lower the cost, the higher the priority, and it is elected as the root port. The cost is the same, compare switch priority, mac address, etc.

3. Designated port election

Choose a designated port for each link, and each interface of the root switch is a D interface.

4. Blocking the port

After election of designated ports, non-root and non-designated ports in the switch are blocked ports.

Temporary loop problem

In order to avoid temporary loop problems, you need to wait for a while before port A enters port D. A->Listening->Learning->D, each state is 15 seconds by default, for a total of 30 seconds.

Port state transition

Insert picture description here
Disabled: The port is closed.
Blocking: Port A
Forwarding: Port R and Port D
Listening: BPDU packets can be forwarded. But it cannot forward user traffic.
Learning: The MAC address table can be constructed based on the received user traffic, but the user traffic is not forwarded.

Experiment overview

Generally, in order to improve network reliability during networking, redundant links (multiple links are interconnected) are usually used in switching networks. Although redundant links improve network reliability, they also bring loops and loops. It will cause broadcast storms and the instability of the MAC address table, thereby affecting communication quality problems and business interruption, which can improve reliability while solving loop problems.

Experimental background

The company network consists of the R&D department and the sales department. The two departments are separated using VLAN technology. The R&D department has VLAN id 10 and the sales department VLAN id 20. In order to achieve link redundancy, the three switches are interconnected and STP spanning tree is used The protocol eliminates loops in the network.

Laboratory equipment:

Equipment type Quantity
Layer 3 switch (S3700) 3
PC 6

Experiment content:

  1. Configure pc's ip, mask, gateway according to topology
  2. Create a VLAN on the switch, and divide the switch port into the corresponding VLAN
  3. Configure stp mode, configure SW1 as the root bridge, and SW2 as the backup root bridge

Network topology

Insert picture description here

Switch SW1 configuration

<Huawei>undo terminal monitor 
<Huawei>system-view 
[Huawei]sysname SW1
[SW1]vlan batch 10 20
[SW1]interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1]port link-type trunk 
[SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan all
[SW1-GigabitEthernet0/0/1]quit
[SW1]interface GigabitEthernet 0/0/2
[SW1-GigabitEthernet0/0/2]port link-type trunk 
[SW1-GigabitEthernet0/0/2]port trunk allow-pass vlan all
[SW1-GigabitEthernet0/0/2]quit
[SW1]interface GigabitEthernet 0/0/4
[SW1-GigabitEthernet0/0/4]port link-type access 
[SW1-GigabitEthernet0/0/4]port default vlan 10
[SW1-GigabitEthernet0/0/4]quit
[SW1]interface GigabitEthernet 0/0/3
[SW1-GigabitEthernet0/0/3]port link-type access 
[SW1-GigabitEthernet0/0/3]port default vlan 20
[SW1-GigabitEthernet0/0/3]quit
[SW1]interface vlanif10
[SW1-Vlanif10]ip address 192.168.1.1 24
[SW1-Vlanif10]quit
[SW1]interface vlanif20
[SW1-Vlanif20]ip address 192.168.2.1 24
[SW1-Vlanif20]quit

     STP配置
[SW1]stp mode stp //stp模式
[SW1]stp root primary //设置交换机为根交换机
[S1]stp enable  //使能stp

    与pc相连的端口可以去除stp
[SW1]interface GigabitEthernet 0/0/3
[SW1-GigabitEthernet0/0/3]stp disable 
[S1-GigabitEthernet0/0/3]quit
[S1]interface GigabitEthernet 0/0/4
[S1-GigabitEthernet0/0/4]stp disable 

Switch LSW2 configuration

<Huawei>undo terminal monitor 
<Huawei>system-view 
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname SW2
[SW2]vlan batch 10 20
[SW2]interface Ethernet 0/0/3
[SW2-Ethernet0/0/3]port link-type access 
[SW2-Ethernet0/0/3]port default vlan 10
[SW2-Ethernet0/0/3]quit
[SW2]interface Ethernet 0/0/5
[SW2-Ethernet0/0/5]port link-type access 
[SW2-Ethernet0/0/5]port default vlan 20
[SW2-Ethernet0/0/5]quit
[SW2]interface Ethernet 0/0/1
[SW2-Ethernet0/0/1]port link-type trunk 
[SW2-Ethernet0/0/1]port trunk allow-pass vlan all
[SW2-Ethernet0/0/1]quit
[SW2]interface Ethernet 0/0/2
[SW2-Ethernet0/0/2]port link-type trunk 
[SW2-Ethernet0/0/2]port trunk allow-pass vlan all
[SW2]interface vlanif10
[SW2-Vlanif10]ip address 192.168.1.1 24

STP配置:
[SW2]stp mode stp
[SW2]stp root secondary  //配置SW2为备份根桥
[SW2]stp enable  //使能stp
去除pc相连的stp

[SW2]inter e0/0/3
[SW2-Ethernet0/0/3]stp disable 
[SW2-Ethernet0/0/3]quit
[SW2]inter e0/0/5
[SW2-Ethernet0/0/5]stp disable 
[SW2-Ethernet0/0/5]quit

Switch 3 configuration

<Huawei>undo terminal monitor
<Huawei>system-view 
[Huawei]sysname SW3
[Huawei]vlan batch 10 20
[SW3]interface Ethernet 0/0/4
[SW3-Ethernet0/0/4]port link-type access 
[SW3-Ethernet0/0/4]port default vlan 10
[SW3-Ethernet0/0/4]quit
[SW3]interface Ethernet 0/0/3
[SW3-Ethernet0/0/3]port link-type access 
[SW3-Ethernet0/0/3]port default vlan 20
[SW3-Ethernet0/0/3]quit 
[SW3]interface Ethernet0/0/1
[SW3-Ethernet0/0/1]port link-type trunk 
[SW3-Ethernet0/0/1]port trunk allow-pass vlan all
[SW3-Ethernet0/0/1]quit
[SW3]interface Ethernet 0/0/2
[SW3-Ethernet0/0/2]port link-type trunk 
[SW3-Ethernet0/0/2]port trunk allow-pass vlan all
[SW3]interface vlanif10
[SW3-Vlanif10]ip address 192.168.1.1 24
[SW3]interface vlanif20
[SW3-Vlanif20]ip address 192.168.2.1 24

   SW3配置STP:
[S3]stp mode stp
[S3]interface Ethernet 0/0/1
[S3-Ethernet0/0/1]stp cost 20000  //SW3 E0/0/1为阻塞端口,将它的端口开销值增大
[S3]stp enable  //设备使能全局STP
去除与pc相连的stp
[S3]int e0/0/3
[S3-Ethernet0/0/3]stp disable 
[S3-Ethernet0/0/3]quit	
[S3]int e0/0/4
[S3-Ethernet0/0/4]stp disable 
[S3-Ethernet0/0/4]quit

View stp configuration information

[S1]display stp brief 
 MSTID  Port                        Role  STP State     Protection
    0    GigabitEthernet0/0/1        DESI  FORWARDING      NONE
    0    GigabitEthernet0/0/2        DESI  FORWARDING      NONE

Insert picture description here
After SW1 is configured as the root bridge, the ports GigabitEthernet0/0/1 and GigabitEthernet0/0/2 connected to SW2 and SW3 are elected as designated ports in the spanning tree calculation.

[SW2]display stp brief 
 MSTID       Port                     Role    STP State   Protection
    0       Ethernet0/0/1             DESI  FORWARDING      NONE
    0       Ethernet0/0/2             ROOT  FORWARDING      NONE

Port Ethernet0/0/1 becomes the designated port in the spanning tree election and is in the Forwarding state.

[S3]display stp brief 
 MSTID  Port                        Role  STP State     Protection
 0    Ethernet0/0/1               ALTE  DISCARDING      NONE
 0    Ethernet0/0/2               ROOT  FORWARDING      NONE

Port Ethernet0/0/1 becomes the alternate port in the spanning tree election and is in the DISCARDING blocking state.
Port Ethernet0/0/2 becomes the root port in the spanning tree election and is in the FORWARDING state.

Guess you like

Origin blog.csdn.net/qq_39689711/article/details/103222106