Warning This post contains interactive examples. To visualize and interact with them, you need to leave your RSS reader. Warning 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! :demo A1 @0,0 prio=4096 A2 @0,1 A3 @0,2 A4 @0,3 B1 @1,0 prio=8192 B2 @1,1 B3 @1,2 B4 @1,3 C1 @2,0 prio=8192 C2 @2,1 C3 @2,2 C4 @2,3 A1 -- A2 hazard=0 A2 -- A3 hazard=0 A3 -- A4 hazard=0 B1 -- B2 B2 -- B3 B3 -- B4 C1 -- C2 hazard=0 C2 -- C3 hazard=0 C3 -- C4 hazard=0 A1 -- B1 cost=10 B1 -- C1 cost=10 A4 -- B4 cost=20 B4 -- C4 cost=20 Leo @-0.3,0.7 proto=none icon=👦🏻 Mia @-0.3,1.3 proto=none icon=👧🏽 Joy @0.3,0.7 proto=none icon=👱🏻♀️ Roy @0.3,1.3 proto=none icon=👨🏾 A2 -- Leo hazard=0 A2:edge A2 -- Mia hazard=0 A2:edge A2 -- Joy hazard=0 A2:edge A2 -- Roy hazard=0 A2:edge Max @-0.3,1.7 proto=none icon=👨🏽 Zoe @-0.3,2.3 proto=none icon=👩🏾 Ada @0.3,1.7 proto=none icon=👵🏾 Amy @0.3,2.3 proto=none icon=👩🏼 A3 -- Max hazard=0 A3:edge A3 -- Zoe hazard=0 A3:edge A3 -- Ada hazard=0 A3:edge A3 -- Amy hazard=0 A3:edge Eli @0.7,0.7 proto=none icon=👦🏼 Jay @0.7,1.3 proto=none icon=👨🏻 Kai @1.3,0.7 proto=none icon=🧑🏽 Ben @1.3,1.3 proto=none icon=👱🏼 B2 -- Eli hazard=0.2 B2:edge B2 -- Jay hazard=0.2 B2:edge B2 -- Kai...

An interactive tour of the spanning tree protocol
Vincent Bernat
18 min readCode
