// HACKER NEWS — CYBERSECURITY
An interactive tour of the spanning tree protocol
This post contains interactive examples. To visualize and interact
with them, you need to leave your RSS reader.
This post contains interactive examples. To visualize and interact
with them, you need to enable JavaScript.
Imagine you rent office space for a three-day event. You quickly set up a few
Ethernet switches and tape some cables on the floor to get everyone online.
Unfortunately, Stan, your clumsiest coworker, kicks out a cable every time he
gets up for coffee. You could add extra cables, but then you’d get a broadcast
storm: Ethernet packets that loop and multiply until nothing else gets through.
That’s where the spanning tree protocol (STP) comes in. STP blocks just enough
of your spare cables to leave a loop-free tree. When Stan strikes again, it
rebuilds the tree in a second, leaving some time for Blobby, your one-person
support crew, to reconnect the cable.1 See for yourself: the diagram
below runs a real STP implementation in your browser!
The sprites for Stan and Blobby come from Craftpix, the coffee
cups from Yanin. ❦
This article is also available as a video, but I advise you to
keep reading here to try the interactive demonstrations.
Designed in the ’80s, the spanning tree protocol has evolved into a “rapid”
flavor (RSTP) and a “VLAN-aware” variation (MSTP).2 Any sound-minded
network engineer knows there are better alternatives, like BGP EVPN VXLAN.
Yet, because any switch speaks it, the venerable spanning tree protocol still
fills a niche.
STP was introduced in IEEE 802.1D-1990. It is still present in
IEEE 802.1D-1998 but was withdrawn in IEEE 802.1D-2004 in favor of
RSTP, introduced in IEEE 802.1w-2001. MSTP was introduced in IEEE 802.1s-2002 and merged into IEEE 802.1Q-2003. Both of them are part
of IEEE 802.1Q-2022 along with SPB—a protocol
I had never heard of until writing this article. ❦
We focus on RSTP: it replaced the original protocol in 2004. To eliminate
network loops, RSTP implements a complex state machine. Timers, link state
changes, and the link-local control frames a bridge receives from its neighbors
drive its transitions. These Ethernet frames are the Bridge Protocol Data
Units (BPDUs). You can watch them in action below: hit the “Start” button.
After some time, the topology converges to a tree: from the root
C11, there is a path to each bridge3 and no loop. In the upper right
corner, the interface displays a tree icon 🌳 followed by the time it took to
reach this state. Cut a link and see how the protocol
finds an alternate path to reach C12 in less than a second. You can stop the
simulation, move it forward step by step, reset it to its initial state, or slow
it down with the “snail” mode 🐌. Don’t worry about all the displayed
information: I explain it later.