Intermediate · Spanning Tree and EtherChannel · topic 26 of 57 · 20 min
Why layer 2 loops are deadly
Explanation
Redundancy: a good idea with a dangerous side effect
If two floor switches each connect to the core with only one cable, one cut cable or one dead port cuts off a whole floor. So network designers add redundancy: extra links, so there is always a second path. In a typical campus, each access switch has two uplinks, one to each of two distribution switches.
The problem is that redundant links form loops: a path that leaves a switch and comes back to it through other switches. At layer 3 (routing) loops are annoying but survivable. At layer 2 (switching) a loop can take down the entire network in seconds.
Reason 1: Ethernet frames have no TTL
An IP packet carries a TTL (time to live) field. Each router reduces it by 1, and when it reaches 0 the packet is thrown away. A routing loop therefore dies out on its own. An Ethernet frame header has nothing like this: a switch can forward the same frame forever, and nothing in the frame ever says "stop".
Reason 2: broadcast storms
Take three switches in a triangle: SW1, SW2 and SW3, each connected to the other two. A PC on SW1 sends one ARP broadcast. SW1 floods it out of every port except the one it came in on, so one copy goes to SW2 and one to SW3. SW2 floods its copy to SW3, and SW3 floods its copy to SW2. Those copies go on to SW1, which floods them again... Every switch keeps copying every broadcast out of every port. Within seconds the links are full, switch CPUs hit 100% and nothing else gets through. This is a broadcast storm.
Reason 3: MAC address table instability
A switch learns where a device lives by looking at the source MAC address of each frame. In a loop, copies of the same frame arrive on different ports, one after another. The switch keeps changing its mind: "PC A is on Gi0/1... no, on Gi0/2... no, on Gi0/1". This is called MAC flapping. Cisco switches log messages such as "Host 0050.7966.6800 in vlan 10 is flapping between port Gi0/1 and port Gi0/2", which is a strong hint that a loop exists.
Reason 4: duplicate frames
A frame for an unknown destination is flooded, just like a broadcast. With a loop, the destination can receive two or more copies of the same frame by different paths. Some applications cope with duplicates; many do not.
The fix: the Spanning Tree Protocol
The Spanning Tree Protocol (STP), standardised as IEEE 802.1D and based on an algorithm designed by Radia Perlman in the 1980s, keeps the redundant cables but logically turns some ports off. Switches exchange small messages called BPDUs (Bridge Protocol Data Units). Using them, they pick one switch as the centre of the network, the root bridge, then work out the best path from every switch to the root, and put every other port that would close a loop into a blocking state. A blocked port is still up and still listens to BPDUs, but it does not forward user frames.
The result is a tree: exactly one active path between any two switches, so no loops. If an active link fails, the switches notice that BPDUs stop arriving or the link goes down, recalculate, and move a blocked port to forwarding. You get the safety of redundancy without the storm.
STP is on by default on Cisco switches. You almost never turn it off; you tune it. The next topics show how the root is elected, how ports change state, how faster versions (RSTP) work and how to protect the tree.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Why layer 2 loops are deadly · 1/6
In this lesson you will learn why extra links between switches can bring a network down, and what spanning tree does about it.
Prefer a video by a teacher? Find free videos on “why spanning tree protocol broadcast storm layer 2 loop explained” on YouTube ↗
In real life: A school lab in Lucknow goes dark
During a computer practical, a student connects a spare patch cable between two wall sockets "to see if it works". Both sockets lead to the same lab switch, which had spanning tree turned off by a previous contractor. Within five seconds every PC in the school loses the network: an ARP broadcast is circling the loop forever. The teacher pulls the cable and everything returns. The school's IT vendor turns STP back on and adds BPDU Guard to the lab ports, so the same mistake now only shuts one port.
Practice (0/2 done)
Why does a broadcast circle a layer 2 loop forever, while an IP packet in a routing loop eventually disappears?
Write has_loop(links) where links is a list of (switch_a, switch_b) cables, for example [("SW1", "SW2"), ("SW2", "SW3")]. Return True if the cables form a loop (including two cables between the same pair of switches), otherwise False. Hint: keep groups of connected switches; a cable between two switches that are already in the same group closes a loop.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Root bridge election, root ports and designated portsSpanning Tree and EtherChannel · same module
- STP port states, RSTP and Rapid PVST+Spanning Tree and EtherChannel · same module
- Protecting spanning tree: PortFast, BPDU Guard, Root Guard and Loop GuardSpanning Tree and EtherChannel · same module
- VLANs: what they are and why we use themSwitching and VLANs
- Network devicesHow networks work
- ARP, the default gateway and pingEthernet, MAC addresses and the Cisco CLI
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What is a broadcast storm?
Answer: Broadcasts copied endlessly around a layer 2 loop until the network is overloaded
In a loop, every switch keeps flooding the same broadcasts, so they multiply until links and CPUs are full.
A switch log keeps saying a host is "flapping between port Gi0/1 and port Gi0/2". What does this suggest?
Answer: A layer 2 loop
MAC flapping means the same source MAC keeps arriving on different ports, a typical sign of a loop.
How does STP stop loops?
Answer: It puts some ports into a blocking state
STP keeps the cables connected but blocks enough ports to leave a loop-free tree.
What does a blocked STP port still do?
Answer: Receives BPDUs
A blocking port keeps listening to BPDUs, so it can take over if the active path fails.
A frame to ffff.ffff.ffff arrives on port 5 of a 24-port switch (all in one VLAN). Where does it go?Related
Answer: All ports except port 5
Broadcasts are flooded out of every port except the incoming one.
Two ports on a switch have the same root path cost. What is compared next?Related
Answer: The neighbour (sender) bridge ID
Next comes the lowest sender bridge ID, then the sender port priority, then the sender port number.
What is the Ethernet broadcast MAC address written in Cisco format?Related
Answer: ffff.ffff.ffff
Broadcast is all ones. 255.255.255.255 is the IPv4 broadcast, not a MAC address.
Which command turns on Cisco's per-VLAN rapid spanning tree?Related
Answer: spanning-tree mode rapid-pvst
spanning-tree mode rapid-pvst enables Rapid PVST+.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 4 more topics in “Spanning Tree and EtherChannel” before its exam: Root bridge election, root ports and designated ports, STP port states, RSTP and Rapid PVST+, Protecting spanning tree: PortFast, BPDU Guard, Root Guard and Loop Guard, EtherChannel: bundling links.
- Module 6 exam: Spanning Tree and EtherChannel · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Routing: static routes and OSPF. 57 topics left in the course before the final exam.