What Is STP?
Introduction
To prevent loops from causing broadcast storms and making the MAC address table unstable, the Spanning Tree Protocol (STP) runs switches when redundant links are used on the network.
STP is a basic feature of datacom products including switches, routers, and WLAN products. This chapter describes STP configurations on Huawei CloudEngine series switches.
Understanding STP
STP, defined by IEEE 802.1D, prevents loops on a local area network (LAN). Switching devices running STP exchange information with one another to discover loops on the network, and then block certain redundant links to eliminate loops. If an active link fails, STP activates a running standby link with the highest priority to ensure network connectivity.
As the scale of LANs continues to grow, STP has become an increasingly important LAN protocol.
Root Bridge, Root Port, and Designated Port
Three elements are involved in trimming a ring network into a tree network: root bridge, root port, and designated port.
- Root bridge: There is only one root bridge on the entire STP network. The root bridge is the logical center, but not necessarily the physical center, of the network. Typically, the root bridge should have high performance and be located at a higher layer of the network. When the network topology changes, the root bridge will be re-elected accordingly. It is recommended that you manually configure the root bridge and secondary root bridge. Configure an optimal core switch as the root bridge to ensure stability of the STP Layer 2 network. Otherwise, new access devices may trigger STP root bridge switching, causing short service interruptions.
- Root port: The root port on an STP device has the smallest path cost to the root bridge and is responsible for forwarding data to the root bridge. Among all STP-capable ports on a device, the port with the smallest root path cost is a root port. An STP device has only one root port, and there is no root port on the root bridge.
- Designated port: The designated port is located on a designated bridge and forwards configuration BPDUs to the device or LAN, as illustrated in Figure 1.
AP1 and AP2 are ports of S1; BP1 and BP2 are ports of S2; CP1 and CP2 are ports of S3.
S1 sends configuration BPDUs to S2 through AP1, so S1 is the designated bridge for S2, and AP1 is the designated port on S1.
In addition, a switching device has a bridge ID (BID) and a port on the switching device has a port ID (PID). A PID is composed of a port priority and a port number. A BID is composed of a bridge priority and a bridge MAC address. On an STP network, the device with the smallest BID acts as the root bridge.
After the root bridge, root port, and designated ports are selected successfully, a tree topology is set up on the entire network. When the topology is stable, only the root port and designated ports forward traffic. The other ports are in Blocking state; they only receive STP BPDUs and do not forward user traffic.
BPDU Format
A BPDU carries the BID, root path cost, and PID. A BPDU is encapsulated in an Ethernet frame. Its destination MAC address is a multicast MAC address, 01-80-C2-00-00-00. The Length or Type field specifies the MAC data length, and is followed by the LLC header and BPDU header. Figure 2 shows the format of an Ethernet frame.
Each bridge actively sends configuration BPDUs during initialization. After the network topology becomes stable, only the root bridge proactively sends configuration BPDUs. Other bridges send configuration BPDUs only after receiving configuration BPDUs from upstream devices. A configuration BPDU is at least 35 bytes long and includes the parameters such as the BID, root path cost, and PID. A bridge processes a received configuration BPDU only if either the sender BID or PID is different from that on the local bridge receive port. If both fields are the same as those on the receive port, the bridge discards the configuration BPDU. Therefore, the bridge does not need to process BPDUs with the same information as the local port.
STP Implementation
STP implementation is as follows:
During network initialization, every device considers itself the root bridge and sets the root ID to its own BID. Then devices exchange configuration BPDUs and compare their root IDs to find the device with the smallest BID, which becomes the root bridge. All the ports on the root bridge are in Forwarding state.
- A non-bridge device selects the port that receives the optimal configuration BPDU as the root port. The root port is in the Forwarding state.
- The device generates a configuration BPDU for each port based on the configuration BPDU on the root port and path cost of the root port. Then the device compares the calculated configuration BPDU with the configuration BPDU received on the port.
If the calculated configuration BPDU is superior, the port is selected as the designated port and periodically sends the calculated configuration BPDU.
If the port's own configuration BPDU is superior, the configuration BPDU on the port is not updated and the port is blocked. Then, the port only receives BPDUs, and does not forward data or send BPDUs.
Configuring STP
For details about the configuration and commands in this section, see "Ethernet Switching Configuration Guide" in the CloudEngine 8800, 7800, 6800, and 5800 Series Switches V200R005C10 Product Documentation.
Configuring Basic STP
- Run the system-view command to enter the system view.
- Run the stp mode stp command to set the working mode of the device to STP.
By default, the working mode of a device is MSTP. MSTP is compatible with STP and RSTP.
- (Optional) Configure the root bridge and secondary root bridge.
- Run the stp root primary command on a device to configure the device as the root bridge.
- Run the stp root secondary command on another device to configure the device as the secondary root bridge.
- (Optional) Run the stp priority priority command to set a priority for the device.
The default priority value of a device is 32768. The value is an integer multiple of 4096, such as 0, 4096 and 8192. A smaller value indicates a higher priority of the device. A device with a higher priority is more likely to be elected as the root bridge. Low-performance devices at lower network layers are not suitable for root bridges, so you need to set low priorities for these devices.
- (Optional) Run the stp pathcost-standard { dot1d-1998 | dot1t | legacy } command to specify a path cost calculation method.
By default, the IEEE 802.1t standard (dot1t) is used to calculate the path cost. All devices on a network must use the same path cost calculation method.
- (Optional) Configure a path cost and a priority for a port.
- Run the interface interface-type interface-number command to enter the view of an interface participating in STP calculation.
- Run the stp cost cost command to set a path cost for the port.
If a network has loops, it is recommended that you set a large path cost for ports with low link rates so that STP blocks these ports.
- Run the stp port priority priority command to set a priority for the port.
The default priority value of a port on a device is 128.
To block a port on a device, set a greater priority value than the default priority value for the port.
- Run the quit command to return to the system view.
- Run the stp enable command to enable STP on a device.
- Run the commit command to submit configurations.
Other STP Configurations
For details about other STP and RSTP configurations, such as the network diameter, timeout interval, timer, and edge port, see "STP/RSTP Configuration" in the CloudEngine 8800, 7800, 6800, and 5800 Series Switches V200R005C10 Product Documentation.
Example for Configuring Basic STP Functions
This section uses the following networking as an example to describe how to configure basic STP functions and verify the configuration result.
- Configure the STP mode on SwitchA and configure SwitchA as the root bridge. In addition, set the path cost calculation method to the Huawei proprietary method.
<SwitchA> system-view [~SwitchA] stp mode stp [*SwitchA] stp root primary [*SwitchA] stp pathcost-standard legacy [*SwitchA] commit
- Configure the STP mode on SwitchB and configure SwitchB as the secondary root bridge. In addition, set the path cost calculation method to the Huawei proprietary method and disable STP on the port connecting to Server2.
<SwitchB> system-view [~SwitchB] stp mode stp [*SwitchB] stp root secondary [*SwitchB] stp pathcost-standard legacy [*SwitchB] interface 10ge 1/0/2 [*SwitchB-10GE1/0/2] stp disable [*SwitchB-10GE1/0/2] commit
- Configure the STP mode on SwitchC and set the path cost calculation method to the Huawei proprietary method. In addition, set the path cost of 10GE1/0/1 to 20000, and disable STP on the port connecting to Server1.
<SwitchC> system-view [~SwitchC] stp mode stp [*SwitchC] stp pathcost-standard legacy [*SwitchC] interface 10ge 1/0/1 [*SwitchC-10GE1/0/1] stp cost 20000 [*SwitchC-10GE1/0/1] quit [*SwitchC] interface 10ge 1/0/2 [*SwitchC-10GE1/0/2] stp disable [*SwitchC-10GE1/0/2] commit
- Configure the STP mode on SwitchD and set the path cost calculation method to the Huawei proprietary method.
<SwitchD> system-view [~SwitchD] stp mode stp [*SwitchD] stp pathcost-standard legacy [*SwitchD] commit
- Enable STP on all devices on the ring network. The following configuration uses SwitchA as an example. Perform the same operations on SwitchB, SwitchC, and SwitchD.
[~SwitchA] stp enable [*SwitchA] commit
- Verify the configuration. After the network becomes stable, run the display stp brief command on SwitchA to check configurations such as the port role and status. SwitchA is used as an example.
[~SwitchA] display stp brief MSTID Port Role STP State Protection Cost Edged 0 10GE1/0/1 DESI forwarding none 2 disable 0 10GE1/0/2 DESI forwarding none 2 disable