An interactive introduction to the spanning tree protocol

vbernat1 pts0 comments

An interactive introduction to the spanning tree protocol

Warning

This post contains interactive examples. To visualize and interact<br>with them, you need to leave your RSS reader.

Warning

This post contains interactive examples. To visualize and interact<br>with them, you need to enable JavaScript.

Imagine you rent office space for a three-day event. You quickly set up a few<br>Ethernet switches and tape some cables on the floor to get everyone online.<br>Unfortunately, Stan, your clumsiest coworker, kicks out a cable every time he<br>gets up for coffee. You could add extra cables, but then you’d get a broadcast<br>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<br>of your spare cables to leave a loop-free tree. When Stan strikes again, it<br>rebuilds the tree in a second, leaving some time for Blobby, your one-person<br>support crew, to reconnect the cable. See for yourself: the diagram below runs a<br>real STP implementation in your browser!

:demo

A1 @0,0 prio=4096<br>A2 @0,1<br>A3 @0,2<br>A4 @0,3

B1 @1,0 prio=8192<br>B2 @1,1<br>B3 @1,2<br>B4 @1,3

C1 @2,0 prio=8192<br>C2 @2,1<br>C3 @2,2<br>C4 @2,3

A1 -- A2 hazard=0<br>A2 -- A3 hazard=0<br>A3 -- A4 hazard=0<br>B1 -- B2<br>B2 -- B3<br>B3 -- B4<br>C1 -- C2 hazard=0<br>C2 -- C3 hazard=0<br>C3 -- C4 hazard=0

A1 -- B1 cost=10<br>B1 -- C1 cost=10<br>A4 -- B4 cost=20<br>B4 -- C4 cost=20

Leo @-0.3,0.7 proto=none icon=👦🏻<br>Mia @-0.3,1.3 proto=none icon=👧🏽<br>Joy @0.3,0.7 proto=none icon=👱🏻‍♀️<br>Roy @0.3,1.3 proto=none icon=👨🏾<br>A2 -- Leo hazard=0 A2:edge<br>A2 -- Mia hazard=0 A2:edge<br>A2 -- Joy hazard=0 A2:edge<br>A2 -- Roy hazard=0 A2:edge

Max @-0.3,1.7 proto=none icon=👨🏽<br>Zoe @-0.3,2.3 proto=none icon=👩🏾<br>Ada @0.3,1.7 proto=none icon=👵🏾<br>Amy @0.3,2.3 proto=none icon=👩🏼<br>A3 -- Max hazard=0 A3:edge<br>A3 -- Zoe hazard=0 A3:edge<br>A3 -- Ada hazard=0 A3:edge<br>A3 -- Amy hazard=0 A3:edge

Eli @0.7,0.7 proto=none icon=👦🏼<br>Jay @0.7,1.3 proto=none icon=👨🏻<br>Kai @1.3,0.7 proto=none icon=🧑🏽<br>Ben @1.3,1.3 proto=none icon=👱🏼<br>B2 -- Eli hazard=0.2 B2:edge<br>B2 -- Jay hazard=0.2 B2:edge<br>B2 -- Kai hazard=0.2 B2:edge<br>B2 -- Ben hazard=0.2 B2:edge

Ava @0.7,1.7 proto=none icon=👩🏻<br>Lea @0.7,2.3 proto=none icon=🧑🏾‍🦱<br>Ivy @1.3,1.7 proto=none icon=🧕🏽<br>Rex @1.3,2.3 proto=none icon=👴🏿<br>B3 -- Ava hazard=0.2 B3:edge<br>B3 -- Lea hazard=0.2 B3:edge<br>B3 -- Ivy hazard=0.2 B3:edge<br>B3 -- Rex hazard=0.2 B3:edge

Ana @1.7,0.7 proto=none icon=👩🏿<br>Eve @1.7,1.3 proto=none icon=👧🏼<br>Abe @2.3,0.7 proto=none icon=🧓🏿<br>Ian @2.3,1.3 proto=none icon=🧔🏾<br>C2 -- Ana hazard=0 C2:edge<br>C2 -- Eve hazard=0 C2:edge<br>C2 -- Abe hazard=0 C2:edge<br>C2 -- Ian hazard=0 C2:edge

Ned @1.7,1.7 proto=none icon=👨🏼‍🦳<br>Lou @1.7,2.3 proto=none icon=🧑🏿<br>Fay @2.3,1.7 proto=none icon=👧🏻<br>Sue @2.3,2.3 proto=none icon=👩🏽‍🦰<br>C3 -- Ned hazard=0 C3:edge<br>C3 -- Lou hazard=0 C3:edge<br>C3 -- Fay hazard=0 C3:edge<br>C3 -- Sue hazard=0 C3:edge

Note

This article is also available as a video, but I advise you to<br>keep reading here to try the interactive demonstrations.

The basics<br>Historical interlude

Electing the root bridge

Assigning roles to ports

Port state transition

Topology change notification

Security

Why RSTP today?<br>How large can a network be?

How fast is RSTP?

About MSTP

About the interactive examples

The basics#

Designed in the ’80s, the spanning tree protocol has evolved into a “rapid”<br>flavor (RSTP) and a “VLAN-aware” variation (MSTP).1 Any sound-minded<br>network engineer knows there are better alternatives, like BGP EVPN VXLAN.<br>Yet, because any switch speaks it, the venerable spanning tree protocol still<br>fills a niche.

STP was introduced in IEEE 802.1D-1990. It is still present in<br>IEEE 802.1D-1998 but was withdrawn in IEEE 802.1D-2004 in favor of<br>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<br>of IEEE 802.1Q-2022 along with SPB—a protocol I had<br>never heard of until writing this article. ❦

We focus on RSTP: it replaced the original protocol in 2004. To eliminate<br>network loops, RSTP implements a complex state machine. Timers, link state<br>changes, and the link-local control frames a bridge receives from its neighbors<br>drive its transitions. These Ethernet frames are the Bridge Protocol Data<br>Units (BPDUs). You can watch them in action below: hit the “Start” button.

:protocol rstp<br>:tx-hold 10

A1 @0,1<br>C11 @1,0 prio=4096 icon=🌳<br>C12 @1,2 prio=4096 icon=🌳<br>C21 @2,0 prio=4096 icon=🌳<br>C22 @2,2 prio=4096 icon=🌳<br>A2 @3,1

H1 @0,0.2 proto=none icon=💻<br>H2 @0,1.8 proto=none icon=🖨️<br>H3 @3,0.2 proto=none icon=📠<br>H4 @3,1.8 proto=none icon=📺

A1 -- C11<br>A1 -- C12<br>A2 -- C21<br>A2 -- C22<br>C11 -- C12<br>C11 -- C21<br>C11 -- C21<br>C11 -- C22<br>C12 -- C21<br>C12 -- C22<br>C21 -- C22<br>A1 -- H1 A1:edge<br>A1 -- H2 A1:edge<br>A2 -- H3 A2:edge<br>A2 -- H4 A2:edge

After some time, the topology converges to a tree: from the root<br>C11, there is a path to each bridge2 and no loop. In the upper right<br>corner, the interface displays a tree icon 🌳 followed by the...

icon hazard proto none edge tree

Related Articles