Layer 2 loops are a common and serious problem in network environments, especially in local area networks (LANs), where they typically occur when they are connected between switch devices. When there are multiple redundant paths in the network, data frames may loop indefinitely in the network, a situation known as a Layer 2 loop.
The effects of the Layer 2 loop
- Broadcast Storm: A Layer 2 loop causes broadcast packets to propagate unrestricted across the network, forming a broadcast storm. Broadcast storms can consume a large amount of network bandwidth and in severe cases, cause network downfall.
- The MAC address table is unstable: The switch uses the MAC address table to record the physical address and port information of the device. Layer 2 loops cause frequent refreshes of MAC address tables, and the switch cannot learn and record MAC addresses correctly, affecting the normal forwarding of data frames.
- Degraded network performance: Layer 2 loops can lead to increased network latency, increased packet loss rates, and significant degradation of network performance.
- Device resource exhaustion: Broadcast storms and frequent MAC address table updates consume the switch's CPU and memory resources, which can lead to device overload and downtime.
Causes of Layer 2 loops
Layer 2 loops often occur due to redundant paths in the network design that are not effectively managed and controlled.
1. Redundant links: In order to improve the reliability and redundancy of the network, multiple redundant links are usually configured in the network. However, if these redundant links are not configured with proper loop protection protocols, loops can occur.
2. Misconfiguration: Layer 2 loops can also occur if the network administrator misoperates or neglects the configuration of the loop protection mechanism when configuring the switch. For example, multiple ports of two switches are incorrectly connected or the spanning tree protocol is misconfigured.
3. Changes in network topology: Dynamic changes in network topology, such as plugging and unplugging network cables, adding new devices or links, may cause short-lived Layer 2 loops. If the network is not configured with a fast-closing loop protection mechanism, the loop may have a long-term impact on the network.
4. Loop protection mechanism failure: Even if a loop protection mechanism, such as spanning tree protocol (STP), is configured, these mechanisms may fail in some cases, such as improper configuration of spanning tree protocol, miscalculation of spanning tree algorithm, etc.
Case Study:
Suppose that in a simple LAN, there are two switches, Switch A and Switch B. To improve network redundancy, the administrator connects Switch A and Switch B with two network cables to form a redundant link.
In this case, if no loop protection mechanism is configured, the data frames between Switch A and Switch B may loop indefinitely in these two redundant links, thus forming a Layer 2 loop. This can lead to a series of problems, such as broadcast storms, unstable MAC address tables, and degraded network performance.
A solution for Layer 2 loops
To prevent and solve Layer 2 loops, a variety of loop protection protocols and technologies are often configured in the network.
1. Spanning Tree Protocol (STP): Spanning Tree Protocol (STP) is a classic loop protection protocol that uses a spanning tree algorithm to create a loop-free logical topology in a network. STP automatically identifies and blocks redundant paths to ensure that there are no Layer 2 loops in the network.
2. Rapid Spanning Tree Protocol (RSTP): The Rapid Spanning Tree Protocol (RSTP) is an enhanced version of STP that provides faster convergence and higher reliability. RSTP can recalculate the spanning tree more quickly when the network topology changes, reducing the network interruption time.
3. Multiple Spanning Tree Protocol (MSTP): The Multiple Spanning Tree Protocol (MSTP) further improves the spanning tree protocol by allowing the creation of multiple spanning tree instances in a single network. Each instance can run independently of other instances, effectively sharing the network load and improving network utilization and reliability.
4. Rapid Ring Protection Protocol (RRPP): The Rapid Ring Protection Protocol (RRPP) is a fast loop protection protocol designed for metro networks, which can quickly restore the normal operation of the network when a loop occurs. The main features of RRPP are fast convergence, simple configuration, and high reliability.
5. Smart Ethernet Protection Protocol (SEP): Smart Ethernet Protection (SEP) is an Ethernet ring protection protocol independently developed by Huawei that provides fast loop protection and recovery capabilities. SEP is easy to configure and manage, making it suitable for various enterprise network environments.
6. Smart Link: Smart Link is a link protection protocol that configures active/standby links to achieve fast switchover and prevent the generation of Layer 2 loops. The main advantages of Smart Link are link redundancy and high availability.
7. Ethernet Ring Protection Switching (ERPS): Ethernet Ring Protection Switching (ERPS) is a standard Ethernet ring protection protocol with fast convergence and high reliability. ERP can provide fast loop protection and recovery capabilities in ring networks, and is widely used in metro and enterprise networks.
By properly configuring the above loop protection protocols and technologies, the Layer 2 loop problem can be effectively prevented and solved, and the high availability and stability of the network can be ensured.
Let's take a closer look at these protocols.
Spanning Tree Protocol (STP)
Spanning Tree Protocol (STP) is a network protocol designed by Radia Perlman in 1985 to prevent loops in Ethernet switching networks. STP uses a spanning tree algorithm to create a loop-free logical topology in the network, thereby preventing data frames from looping indefinitely in the network.
How STP works is based on the following key steps:
- Selection of Root Bridge: In an STP network, all switches are compared by Bridge ID, and the switch with the lowest Bridge ID is selected as the Root Bridge. The bridge ID consists of the Bridge Priority and the MAC address of the switch.
- Path Selection: All non-root bridges select the best path based on the path cost to reach the root bridge. The path cost is usually determined based on the link speed, and the higher the link speed, the lower the path cost.
- Port Role Determination: Each switch's port is labeled as a Root Port, Designated Port, or Blocking Port based on its role in the spanning tree. The root port is the best path to the root bridge, and the specified port is the only active path in each segment of the network.
- Port State Transition: STP port states include Blocking, Listening, Learning, and Forwarding. A blocking port does not forward data frames, while the listening and learning state is used for spanning tree convergence, and the forwarding port is responsible for normal data forwarding.
The following is an example of a basic STP configuration:
# 启用STP
stp enable
# 设置交换机的桥优先级
stp priority 4096
# 在指定端口启用STP
interface GigabitEthernet0/0/1
stp enable
Rapid Spanning Tree Protocol (RSTP)
The Rapid Spanning Tree Protocol (RSTP) is an enhanced version of STP and is defined by the IEEE 802.1w standard. RSTP significantly reduces the outage time when the network topology changes by introducing a faster convergence mechanism.
Improvements to RSTP
- Fast port forwarding: RSTP introduces new port states and roles that allow certain ports to quickly enter the forwarding state under certain conditions, resulting in faster convergence.
- Point-to-point connections: RSTP assumes that there are point-to-point connections between ports, allowing for faster detection of link failures and recalculation of spanning trees.
- Protocol Message Optimization: RSTP uses a more efficient BPDU (Bridge Protocol Data Unit) messaging mechanism, which further improves the protocol's response speed.
The following is an example of a basic configuration of RSTP:
# 启用RSTP
stp mode rstp
# 设置交换机的桥优先级
stp priority 4096
# 在指定端口启用RSTP
interface GigabitEthernet0/0/1
stp enable
Multiple Spanning Tree Protocol (MSTP)
Multiple Spanning Tree Protocol (MSTP) is a spanning tree protocol defined by the IEEE 802.1s standard to solve the problem of spanning tree load in large-scale networks. MSTP provides higher network utilization and reliability by creating multiple spanning tree instances in a single network.
How MSTP works
- MST Region: MSTP divides the network into multiple MST Regions, and switches in each region share the same MST configuration.
- Instance mapping: MSTP allows the creation of multiple spanning tree instances (MSTIs) within a region, each of which can run independently of the others and be mapped to different VLANs.
- Inter-region bridging: MSTP bridges between different regions through the Common Spanning Tree (CST) to ensure a loop-free topology of the entire network.
The following is an example of a basic configuration of MSTP:
# 启用MSTP
stp mode mstp
# 配置MST区域
stp region-name region1
# 映射VLAN到生成树实例
stp instance 1 vlan 10
stp instance 2 vlan 20
# 设置生成树实例的优先级
stp instance 1 priority 4096
stp instance 2 priority 8192
# 在指定端口启用MSTP
interface GigabitEthernet0/0/1
stp enable
Fast Ring Protection Protocol (RRPP)
The Rapid Ring Protection Protocol (RRPP) is a fast loop protection protocol designed for metro networks, which can quickly restore the normal operation of the network when a loop occurs. The main features of RRPP are fast convergence, simple configuration, and high reliability.
How RRPP works
- RRPP Domains and Levels: An RRPP network consists of an RRPP domain and an RRPP level. Each RRPP domain can contain one or more RRPP levels.
- Active/standby link: RRPP implements fast switchover by configuring the active/standby link to ensure that the standby link can quickly take over traffic and restore normal network operation if the primary link fails.
- Loop detection and recovery: RRPP monitors the presence of loops in the network, and when loops are detected, it immediately switches to the standby link and notifies other devices in the network to make corresponding adjustments.
The following is an example of a basic RRPP configuration:
# 配置RRPP域
rrpp domain 1
rrpp level 1
# 启用RRPP并配置主备链路
interface GigabitEthernet0/0/1
rrpp enable
rrpp primary-port
interface GigabitEthernet0/0/2
rrpp enable
rrpp secondary-port
Smart Ethernet Protection Protocol (SEP)
Smart Ethernet Protection (SEP) is an Ethernet ring network protection protocol developed by Huawei that provides fast loop protection and recovery capabilities. SEP is easy to configure and manage, making it suitable for various enterprise network environments.
How SEP works
- Active and standby ports: SEP configures the active and standby ports to ensure that if the primary port fails, the standby port can quickly take over traffic and restore normal network operation.
- Loop detection and recovery: SEP monitors the presence of loops in the network, and when loops are detected, it immediately switches to the standby port and notifies other devices on the network to make corresponding adjustments.
The following is an example of a basic SEP configuration:
# 配置SEP
interface GigabitEthernet0/0/1
sep enable
sep primary-port
interface GigabitEthernet0/0/2
sep enable
sep secondary-port
Smart Link
Smart Link is a link protection protocol that configures active/standby links to achieve fast switchover and prevent the generation of Layer 2 loops. The main advantages of Smart Link are link redundancy and high availability.
How Smart Link works
- Active/standby links: Smart Link configures active/standby links to ensure that if the primary link fails, the standby link can quickly take over traffic and restore normal network operation.
- Handover mechanism: Smart Link uses a fast handover mechanism to ensure that when a primary link failure is detected, the standby link can take over traffic in milliseconds, reducing network outage time.
The following is an example of the basic configuration of Smart Link:
# 配置Smart Link
smart-link group 1
primary-port GigabitEthernet0/0/1
secondary-port GigabitEthernet0/0/2
enable
Ethernet Ring Protection Switching (ERPS)
Ethernet Ring Protection Switching (ERPS) is a standard Ethernet ring protection protocol with fast convergence and high reliability. ERP can provide fast loop protection and recovery capabilities in ring networks, and is widely used in metro and enterprise networks.
How ERP works
- Ring network structure: ERP provides redundant paths through the ring network structure to ensure that if any link fails, traffic can continue to be transmitted through other paths.
- Fast convergence: ERP uses a fast convergence mechanism to ensure that the normal operation of the network can be quickly restored when loops occur, reducing the network interruption time.
The following is an example of a basic ERP configuration:
# 配置ERPS域
erps domain 1
erps ring-id 1
# 配置主节点端口和子节点端口
interface GigabitEthernet0/0/1
erps enable
erps ring 1 port master
interface GigabitEthernet0/0/2
erps enable
erps ring 1 port slave
# 启用ERPS保护
erps enable
Loop detection technology of Huawei switches
In addition to the above-mentioned loop protection protocols, Huawei switches also support a variety of loop detection technologies, including loop detection and loopback detection. These technologies can proactively detect loops in the network and notify administrators or take automatic action to prevent the impact of loops.
Loop Detection
Loop Detection is a technology used to detect network loops. It tells if there is a loop in the network by sending test frames to the network and checking whether those frames are returned.
Loop Detection的工作原理
- Test Frame Sending: The switch periodically sends test frames to every port in the network.
- Loop detection: If the test frame is returned to the transmit port through the loop, the switch determines that there is a loop on the port.
- Alarm and handling: Once a loop is detected, the switch can take a variety of actions, such as sending an alarm message to the administrator or automatically disabling the port where the loop is present.
Here's an example of a basic configuration for Loop Detection:
# 启用Loop Detection
loop-detection enable
# 配置检测周期(单位:秒)
loop-detection interval 10
# 在指定端口启用Loop Detection
interface GigabitEthernet0/0/1
loop-detection enable
Loopback Detection
Loopback Detection is similar to Loop Detection, but it is more focused on detecting the presence of loopback paths in the network. Loopback paths can be caused by network topology changes or misconfigurations, causing data frames to loop through the network.
Loopback Detection的工作原理
- 检测帧发送:交换机向每个端口发送Loopback Detection帧。
- Loopback detection: If the detection frame is returned to the sending port through the loopback path, the switch determines that there is a loopback on the port.
- Alarm and handling: When loopbacks are detected, the switch can take action, such as sending an alarm message or automatically disabling ports with loopbacks.
The following is an example of a basic configuration for Loopback Detection:
# 启用Loopback Detection
loopback-detection enable
# 配置检测周期(单位:秒)
loopback-detection interval 10
# 在指定端口启用Loopback Detection
interface GigabitEthernet0/0/1
loopback-detection enable
Configuration examples and case studies
In the actual network environment, the rational configuration of loop protection protocols and detection technologies is the key to ensure the stable operation of the network. The following is a case study to detail how to configure these technologies on Huawei switches to solve the Layer 2 loop.
Suppose an enterprise's network topology is as follows:
- Core Switch: Connects to multiple access switches
- Access Switch: A terminal device that connects to each office
- To improve redundancy, there are multiple redundant links between the core switch and the access switch
To prevent Layer 2 loops, the enterprise decides to configure the following loop protection and detection technologies on the core and access switches:
- Configure MSTP on the core switch to ensure that multiple spanning tree instances can effectively share the network load
- Configure RRPP on the access switch to ensure that the normal operation of the network is quickly restored
- 在所有交换机上启用Loop Detection和Loopback Detection,以主动检测和防止环路
1. Core switch configuration
# 启用MSTP
stp mode mstp
# 配置MST区域
stp region-name company_region
# 映射VLAN到生成树实例
stp instance 1 vlan 10
stp instance 2 vlan 20
# 设置生成树实例的优先级
stp instance 1 priority 4096
stp instance 2 priority 8192
# 启用环路检测技术
loop-detection enable
loopback-detection enable
2. Access Switch Configuration (Take Access Switch A as an Example)
# 配置RRPP域
rrpp domain 1
rrpp level 1
# 启用RRPP并配置主备链路
interface GigabitEthernet0/0/1
rrpp enable
rrpp primary-port
interface GigabitEthernet0/0/2
rrpp enable
rrpp secondary-port
# 启用环路检测技术
loop-detection enable
loopback-detection enable
Through the above configurations, the enterprise network can be quickly detected and restored in the event of a loop, ensuring high availability and stability of the network.
summary
Name of the technology | Full name | Key features: | Applicable scenarios | Key features: |
STP | Spanning Tree Protocol | Prevent network loops | General enterprise networking | The convergence speed is slow, and the standard is widely used |
RSTP | Rapid Spanning Tree Protocol | Quickly prevent network loops | General enterprise networking | The convergence speed is faster than that of STP |
MSTP | Multiple Spanning Tree Protocol | Multi-instance spanning tree, load balancing | Large enterprise and carrier networks | Multiple spanning tree instances and load balancing are supported |
Public relations | Rapid Ring Protection Protocol | Fast ring protection | Metro | Fast convergence for ring network structures |
SEP | Smart Ethernet Protection | Fast loop protection | Enterprise networking | The configuration is simple and exclusive to Huawei |
Smart Link | Smart Link | Fast link protection | Enterprise networking | Fast switching, link redundancy |
ERPS | Ethernet Ring Protection Switching | Standard ring protection | Metro and enterprise networks | Fast convergence, standard protocol |
Loop Detection | Loop Detection | Detect network loops | All kinds of network environments | Active detection loops for easy configuration |
Loopback Detection | Loopback Detection | Detect loopback paths | All kinds of network environments | Active detection loopback, easy to configure |
When configuring these technologies, we recommend that you select appropriate technologies and parameters based on the actual network topology and business requirements, and regularly check and optimize the configurations to ensure their normal operation. At the same time, update the device firmware in a timely manner to maintain the security and stability of the network. The above measures can effectively improve network reliability and reduce the risks and impacts caused by Layer 2 loops.