Understand and Mitigate Network Loops
Spanning-tree helps you create a loop-free topology in your switched network. The question we should ask ourselves is:
- What causes a loop in a switched network?
We add loops in our network by adding redundancy in our switched network when there are multiple paths between two points in a network, leading to data continuously circulating and potentially causing significant issues such as performance degradation, unexpected port blockages, complete network outages, and device crashes.
When we have a loop, switches will keep forwarding over and over until this happens:
You fix the loop by disconnecting one of the cables.
Your switches will crash because they are overwhelmed with traffic
Ethernet frames don’t have a TTL (Time to Live) field so frames will loop forever
The same thing will occur with “BUM” traffic—broadcast, unknown unicast, and multicast.
BPDU
Switches running spanning-tree exchange information with a special message called the (BPDU) bridge protocol data unit.
Forming the Tree
The path tree formation follows a process that consists of:
Electing the root switch. All the ports on the root will be forwarding.
All non-root switches must find the shortest path to the root switch and elect a root port
All the other ports that receive BDPUs (meaning there is a loop) must go through an election process to be a forwarding or blocking port, breaking the loop.
Root Switch
The root bridge is the switch with the lowest bridge identifier. The bridge identifier consists of priority + MAC address.
Non-Root Switches
All the non-root switches must find the shortest path to the root bridge. So what is the shortest path? Spanning-tree assigns costs to each interface based on the speed. The interface that leads us to the root bridge (lowest cost) is called the root port, which forwards traffic.
All remaining ports on non-root switches must decide if they will be forwarding traffic or blocking this interface to break a loop. Any port that receives BPDUs must go through this election process to find its state.
Tie Decision Process
Whenever spanning-tree has to make a decision, this is the list that it will use.
Lowest cost to root bridge: When the switch receives multiple BPDUs, it will choose the interface with the lowest cost to reach the root bridge as the root port.
Lowest sender bridge ID: When a switch is connected to two other switches that it can use to reach the root bridge, and the cost to reach the root bridge is the same, it will choose the interface connected to the switch with the lowest bridge ID as the root port.
Lowest sender port ID: When the switch has two interfaces connecting to the same switch and the cost to reach the root bridge is the same, it will choose the interface with the lowest number as the root port.
Port Cost Table Based on Interface Speed
Interface Speed | STP Port Cost | Description |
10 Mbps | 100 | Standard Ethernet (Fast Ethernet) |
100 Mbps | 19 | Fast Ethernet |
1 Gbps | 4 | Gigabit Ethernet |
10 Gbps | 2 | 10-Gigabit Ethernet |
25 Gbps | 1 | 25-Gigabit Ethernet (if supported) |
40 Gbps | 1 | 40-Gigabit Ethernet (if supported) |
100 Gbps | 1 | 100-Gigabit Ethernet (if supported) |
Note: The above costs are based on the IEEE 802.1D standard, which is commonly implemented in many network devices. Some modern switches may support higher speeds (like 25 Gbps, 40 Gbps, or 100 Gbps) with the same minimal cost as 10 Gbps.
STP assigns costs to each port to determine the most efficient path for data to traverse the network. Lower costs are preferred, meaning higher-speed links are preferred.
Best Practices to Avoid Network Loops
To maintain network stability and prevent loops, follow these best practices:
Set STP to prioritize core switches: Configure Spanning Tree Protocol settings to prioritize core switches. Properly setting STP priorities ensures that the root switch is the most reliable switch. This setup optimizes data paths and blocks redundant links.
Utilize Loop Prevention: Configure Loop Protection on your switch ports to shut down ports when loops are detected.
Regular Maintenance: Check for and replace bad cables. Poor link negotiation can cause STP priority changes (flapping), leading to persistent connectivity issues.
Hope you enjoy this quick review of STP. There is always more to the scene, but with this in mind, you have the base to debug and interpret the results from an analysis.
See you on the next one!
Subscribe to my newsletter
Read articles from Pedro D directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by