Generally, redundant links are used on an Ethernet switching network to provide link backup and enhance network reliability. The use of redundant links, however, may produce loops, causing broadcast storms and rendering the MAC address table unstable. As a result, the communication quality deteriorates, and communication services may be interrupted. The Spanning Tree Protocol (STP) is used to solve these problems. STP prevents loops. Devices running STP discover loops on the network by exchanging information with each other, and block some ports to eliminate loops.
STP refers to STP defined in IEEE 802.1D, the Rapid Spanning Tree Protocol (RSTP) defined in IEEE 802.1w, and the Multiple Spanning Tree Protocol (MSTP) defined in IEEE 802.1s.
Spanning Tree Protocol |
Characteristics |
Application Scenario |
---|---|---|
STP |
User or service traffic does not need to be differentiated, and all VLANs share a spanning tree. |
|
RSTP |
|
|
MSTP |
|
User or service traffic needs to be differentiated and load balanced. Traffic from different VLANs is forwarded through different spanning trees that are independent of each other. |
To implement redundancy on a complex network, network designers tend to deploy multiple physical links between two devices, one of which is the primary link and the others are backup links. Loops may occur, causing broadcast storms or rendering the MAC address table unstable.
After a network designer deploys a network, STP can be deployed on the network to prevent loops. When loops exist on a network, STP blocks a port to eliminate the loops. In Figure 1, SwitchA, SwitchB, SwitchC, and SwitchD running STP exchange STP BPDUs to discover loops on the network and block ports to prune the network into a loop-free tree network. STP prevents infinite looping of packets to ensure packet processing capabilities of switches.
Configure the switching devices on the ring network to work in STP mode.
Configure the root bridge and secondary root bridge.
Configure the path cost of a port so that the port can be blocked.
Enable STP to eliminate loops.
Configure the switching devices on the ring network to work in STP mode.
# Configure SwitchA to work in STP mode.
<HUAWEI> system-view [HUAWEI] sysname SwitchA [SwitchA] stp mode stp
# Configure SwitchB to work in STP mode.
<HUAWEI> system-view [HUAWEI] sysname SwitchB [SwitchB] stp mode stp
# Configure SwitchC to work in STP mode.
<HUAWEI> system-view [HUAWEI] sysname SwitchC [SwitchC] stp mode stp
# Configure SwitchD to work in STP mode.
<HUAWEI> system-view [HUAWEI] sysname SwitchD [SwitchD] stp mode stp
Configure the root bridge and secondary root bridge.
# Configure SwitchA as the root bridge.
[SwitchA] stp root primary
# Configure SwitchD as the secondary root bridge.
[SwitchD] stp root secondary
Configure the path cost of a port so that the port can be blocked.
The path cost range depends on the algorithm. Huawei's proprietary algorithm is used as an example. Set the path costs of the ports to be blocked to 20000.
Switching devices on the same network must use the same algorithm to calculate the path cost of ports.
# Configure SwitchA to use Huawei's proprietary algorithm to calculate the path cost.
[SwitchA] stp pathcost-standard legacy
# Configure SwitchB to use Huawei's proprietary algorithm to calculate the path cost.
[SwitchB] stp pathcost-standard legacy
# Configure SwitchC to use Huawei's proprietary algorithm to calculate the path cost.
[SwitchC] stp pathcost-standard legacy
# Set the path cost of GigabitEthernet0/0/1 on SwitchC to 20000.
[SwitchC] interface gigabitethernet 0/0/1 [SwitchC-GigabitEthernet0/0/1] stp cost 20000 [SwitchC-GigabitEthernet0/0/1] quit
# Configure SwitchD to use Huawei's proprietary algorithm to calculate the path cost.
[SwitchD] stp pathcost-standard legacy
Enable STP to eliminate loops.
Configure the ports connected to PCs as edge ports.
# Configure GigabitEthernet0/0/2 of SwitchB as an edge port.
[SwitchB] interface gigabitethernet 0/0/2 [SwitchB-GigabitEthernet0/0/2] stp edged-port enable [SwitchB-GigabitEthernet0/0/2] quit
(Optional) Configure BPDU protection on SwitchB.
[SwitchB] stp bpdu-protection
# Configure GigabitEthernet0/0/2 of SwitchC as an edge port.
[SwitchC] interface gigabitethernet 0/0/2 [SwitchC-GigabitEthernet0/0/2] stp edged-port enable [SwitchC-GigabitEthernet0/0/2] quit
(Optional) Configure BPDU protection on SwitchC.
[SwitchC] stp bpdu-protection
Enable STP globally on devices.
# Enable STP globally on SwitchA.
[SwitchA] stp enable
# Enable STP globally on SwitchB.
[SwitchB] stp enable
# Enable STP globally on SwitchC.
[SwitchC] stp enable
# Enable STP globally on SwitchD.
[SwitchD] stp enable
After the configuration is complete and the network topology becomes stable, perform the following operations to verify the configuration.
# Run the display stp brief command on SwitchA to view the port status and protection type. The displayed information is as follows:
[SwitchA] display stp brief MSTID Port Role STP State Protection 0 GigabitEthernet0/0/1 DESI FORWARDING NONE 0 GigabitEthernet0/0/2 DESI FORWARDING NONE
After SwitchA is configured as the root bridge, GigabitEthernet0/0/2 and GigabitEthernet0/0/1 connected to SwitchB and SwitchD are selected as designed ports.
# Run the display stp interface gigabitethernet 0/0/1 brief command on SwitchB to check the status of GigabitEthernet0/0/1. The following information is displayed:
[SwitchB] display stp interface gigabitethernet 0/0/1 brief MSTID Port Role STP State Protection 0 GigabitEthernet0/0/1 DESI FORWARDING NONE
GigabitEthernet0/0/1 becomes the designated port and is in FORWARDING state.
# Run the display stp brief command on SwitchC to check the port status.
[SwitchC] display stp brief MSTID Port Role STP State Protection 0 GigabitEthernet0/0/1 ALTE DISCARDING NONE 0 GigabitEthernet0/0/3 ROOT FORWARDING NONE
GigabitEthernet0/0/3 becomes the root port and is in FORWARDING state.
GigabitEthernet0/0/1 becomes the alternate port and is in DISCARDING state.
SwitchA configuration file
# sysname SwitchA # stp mode stp stp instance 0 root primary stp pathcost-standard legacy # return
SwitchB configuration file
# sysname SwitchB # stp mode stp stp bpdu-protection stp pathcost-standard legacy # interface GigabitEthernet0/0/2 stp edged-port enable # return
SwitchC configuration file
# sysname SwitchC # stp mode stp stp bpdu-protection stp pathcost-standard legacy # interface GigabitEthernet0/0/1 stp instance 0 cost 20000 # interface GigabitEthernet0/0/2 stp edged-port enable # return
SwitchD configuration file
#
sysname SwitchD
#
stp mode stp
stp instance 0 root secondary
stp pathcost-standard legacy
#
return