AutoNetOps

Cover Image for Understand and Mitigate Network Loops

Understand and Mitigate Network Loops

·

4 min read

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.

BPDU fields

STP pcap

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.

💡
Keep in mind that switches only make decisions on the BPDUs that they receive! They have no idea what the topology looks like. The only thing they do know is on which interface they received the best BPDU. The best BPDU is the one with the shortest path to the root bridge

Tie Decision Process

Whenever spanning-tree has to make a decision, this is the list that it will use.

port state tie breaker

  1. 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.

  2. 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.

  3. 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 SpeedSTP Port CostDescription
10 Mbps100Standard Ethernet (Fast Ethernet)
100 Mbps19Fast Ethernet
1 Gbps4Gigabit Ethernet
10 Gbps210-Gigabit Ethernet
25 Gbps125-Gigabit Ethernet (if supported)
40 Gbps140-Gigabit Ethernet (if supported)
100 Gbps1100-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:

  1. 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.

  2. Utilize Loop Prevention: Configure Loop Protection on your switch ports to shut down ports when loops are detected.

  3. 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!