Sub topic 1
Why redundant switch links create loops
Ethernet switches flood frames they cannot place, and Ethernet frames carry no hop counter. Together these two facts make a redundant switch topology dangerous. This chapter shows how a loop forms, what it does to the network, and why Spanning Tree Protocol (STP) exists. Later chapters cover how STP works.
Prerequisites
This chapter assumes you already know the following:
- How a switch learns source MAC addresses and forwards frames using its MAC address table.
- The difference between unicast, broadcast, and unknown-unicast frames, and that a switch floods broadcast and unknown-unicast frames out of every port except the one they arrived on.
- Basic VLAN and trunk concepts. A VLAN is one broadcast domain, and a trunk carries several VLANs between switches.
- How to read a switch command-line interface.
Why you want redundant links
A single link between two switches is a single point of failure. If the cable, the port, or the transceiver fails, every host behind that link loses connectivity. Network designers therefore connect each access switch to two upstream switches, and often connect the upstream switches to each other.
Redundancy is the right design goal. The problem is that a plain Layer 2 network cannot use redundant links safely without extra help.
Why Ethernet has no built-in protection
IP packets have a Time To Live (TTL) field. Each router decrements it, and a router drops the packet when it reaches zero. A packet caught in a routing loop therefore dies after a bounded number of hops.
An Ethernet frame has no equivalent field. The frame header holds a destination MAC, a source MAC, an optional VLAN tag, a type, the payload, and a checksum. Nothing counts hops, and switches do not change the frame as they forward it. If a frame can travel in a circle, it will do so for as long as the loop exists.
The second factor is flooding. A switch forwards a broadcast out of every port in the VLAN except the ingress port. Each switch in the loop therefore sends the frame onward, and also sends a copy to every other neighbor.
How a loop forms
Consider three switches, SW1, SW2, and SW3, connected in a triangle. Host A connects to SW1.
- Host A sends an ARP request. The destination MAC is
ff:ff:ff:ff:ff:ff. - SW1 receives it on the host port and floods it out of both uplinks, toward SW2 and toward SW3.
- SW2 receives its copy from SW1 and floods it out of every other port. That includes the link to SW3.
- SW3 receives its copy from SW1 and floods it out of every other port. That includes the link to SW2.
- SW2 and SW3 each receive a second copy from the other and flood it again. Those copies reach SW1, which floods them again.
Each copy keeps circulating in both directions around the triangle. Because each pass through a switch also produces copies on other ports, the number of frames grows with every lap.
The three symptoms of a loop
A Layer 2 loop shows up in three related ways.
Broadcast storm
Looping broadcasts multiply and consume link bandwidth. Switches forward frames in hardware, so the loop can saturate links within seconds. Legitimate traffic competes with the looping copies and is delayed or dropped.
MAC table instability
A switch learns from the source MAC address of each frame it receives. When the same frame arrives on two different ports, the switch keeps moving the entry for that source MAC between those ports. This is called MAC flapping.
While the entry points to the wrong port, unicast frames for that host are sent in the wrong direction. Hosts appear to be unreachable, or reachable only intermittently.
High CPU and device failure
Some of the looping traffic must be handled by the switch CPU. Examples are broadcasts addressed to the switch's own management IP, and frames that trigger MAC learning events. CPU use climbs, management sessions become sluggish, and control protocols can time out. At the extreme, the switch becomes unreachable and must be disconnected or power-cycled to recover.
Unknown unicast and multicast also loop
Broadcasts are not the only traffic that loops. Any frame a switch floods can circulate:
- Unknown-unicast frames, when the destination MAC is not in the table.
- Multicast frames, when the switch has no snooping state to limit them.
Even a quiet network contains this traffic. A loop needs only one such frame to start.
A loop can start from a single patch cable
Loops are not always part of the design. Common causes include:
- A user plugging both ends of a patch cable into the same switch, or into two wall ports on a small unmanaged switch.
- An unmanaged switch or hub connected to two ports of a managed switch.
- A new uplink added during a maintenance window without checking the existing topology.
- A misconfigured trunk or an incorrectly bundled link, where one side is a port channel and the other side is not.
These are all reasons to keep loop prevention enabled even on networks that were designed without loops.
The core idea behind STP
Redundant links are needed for resilience, but a loop is harmful only if frames can use all the links at once. STP resolves this conflict.
STP lets switches agree on a loop-free logical topology, called a spanning tree, built on top of the physical topology. Some ports are placed in a blocking condition so they do not forward user traffic. The physical link remains in place. If an active link fails, STP recalculates and a blocked port can take over.
In the triangle example, STP blocks one port, for instance the port on SW3 facing SW2. Every switch can still reach every other switch, but no frame can complete a circle.
What STP must solve
To build this tree, the switches need to answer several questions without a central controller:
- Which switch is the reference point for the whole tree? This is the root bridge.
- For each switch, which single path leads toward the root?
- For each link, which side forwards frames?
- What happens when a link or switch fails?
The next chapters answer these in order. Switches exchange small control messages for this purpose, and the next chapter introduces them.
Where to see the effects
On Cisco IOS, the following commands help you recognize loop symptoms. The syntax is shown here only as a preview, and later chapters explain the output.
! Look for rapidly increasing counters on one interface
show interfaces GigabitEthernet0/1 | include broadcasts|input rate
! Look for the same MAC moving between ports
show mac address-table address aaaa.bbbb.cccc
! Look for MAC flapping messages in the log
show logging | include MACFLAP|HOST_FLAPOn Linux, you can watch the same kind of behavior on a bridge:
# Per-port traffic counters on the bridge ports
ip -s link show dev eth0
ip -s link show dev eth1
# Forwarding database entries; repeated changes of port for one MAC suggest a loop
bridge fdb show br br0Quick comparison with routed loops
| Property | Layer 2 loop | Layer 3 routing loop |
|---|---|---|
| Hop limit in header | None | TTL, decremented per router |
| Packet lifetime | Unbounded | Ends when TTL reaches zero |
| Effect of flooding | Copies multiply | Packets are forwarded, not flooded |
| Typical result | Storm within seconds | Wasted bandwidth, then drop |
| Prevention | STP and related features | Routing protocol design |
Summary
Redundant switch links are necessary for resilience, but they create loops because Ethernet has no hop limit and switches flood broadcast, multicast, and unknown-unicast frames. A loop causes broadcast storms, MAC table flapping, and CPU exhaustion. STP keeps the redundancy and removes the loop by blocking selected ports, so that the active topology is a tree.
Exercise
Three switches are connected in a triangle with no loop prevention. A host on SW1 sends one broadcast frame. Explain why the frame never stops circulating, and name two other symptoms you would expect to see besides high link utilization.
Show answer
Ethernet frames have no TTL or hop counter, and each switch floods a broadcast out of every port except the one it arrived on. Each copy therefore keeps travelling around the triangle, and each pass creates more copies. Two other symptoms are MAC address table flapping, where the same source MAC keeps moving between ports because it arrives from different directions, and high switch CPU use, which can make management access slow or impossible.
Exercise
A colleague says that a network with redundant links is safe from loops as long as only unicast traffic is used between known hosts. Is this correct? Give one reason.
Show answer
No. Unicast frames are flooded when the destination MAC is not in the MAC table, for example after the entry ages out or the table is flushed. Flooded unknown-unicast frames can circulate in a loop just like broadcasts. Multicast frames can loop in the same way.