@@ -16,41 +16,59 @@ switches (``switch1``–``switch7``) interconnected with redundant links, and tw
1616hosts (``host1 `` and ``host2 ``) attached to ``switch6 `` and ``switch5 ``
1717respectively.
1818
19- .. figure :: media/LoopNetwork .png
19+ .. figure :: media/SwitchNetwork .png
2020 :align: center
2121
2222About STP
2323~~~~~~~~~
2424
25- STP (IEEE 802.1D-1998) builds a spanning tree over a bridged network to ensure
26- a loop-free topology. The protocol works as follows:
27-
28- 1. **Root bridge election **: The switch with the lowest bridge ID (priority +
29- MAC address) becomes the root bridge. By default all switches have the same
30- priority (32768), so the one with the lowest MAC address wins.
31-
32- 2. **Root port selection **: Each non-root switch selects the port with the
33- lowest path cost to the root as its *root port *.
34-
35- 3. **Designated port selection **: On each network segment, one port is elected
36- *designated port * (the one with the lowest path cost to the root). If the
37- segment has another switch port that is neither a root port nor the designated
38- port, that port is put in *blocking * state to eliminate the redundant path.
39-
40- 4. **Port states **: STP ports transition through *Blocking → Listening →
41- Learning → Forwarding *, with each transition taking ``forwardDelay `` seconds
42- (default 15 s). The total convergence time is therefore approximately 30–50 s.
25+ The Spanning Tree Protocol (STP, IEEE 802.1D-1998) eliminates loops by
26+ computing a *spanning tree * of the network — a subset of links that connects
27+ all switches without forming any cycles. In graph theory, a *spanning tree * of
28+ a connected graph is a tree that includes every node but only enough edges to
29+ keep it connected (exactly *N−1 * edges for *N * nodes). Ports on links that are
30+ not part of the spanning tree are placed in a *blocking * state, effectively
31+ deactivating those links for data traffic while keeping them available as
32+ backups.
33+
34+ STP achieves this through a distributed algorithm. Switches exchange *Bridge
35+ Protocol Data Units * (BPDUs) to share topology information and collectively
36+ agree on the tree structure. The algorithm works in the following phases:
37+
38+ **1. Root bridge election. ** All switches start by assuming they are the root.
39+ Each switch sends BPDUs containing its own *bridge ID * — a value composed of a
40+ configurable *bridge priority * (default 32768) and the switch's MAC address.
41+ When a switch receives a BPDU with a lower bridge ID than its own, it accepts
42+ the sender's root claim and stops claiming to be root itself. Eventually, the
43+ switch with the numerically lowest bridge ID wins the election and becomes the
44+ *root bridge *. The root bridge is the root of the spanning tree; all paths in
45+ the tree lead toward it.
46+
47+ **2. Root port selection. ** Each non-root switch must determine which of its
48+ ports provides the best (lowest-cost) path toward the root bridge. STP assigns
49+ a *path cost * to each port based on its link speed (e.g. 4 for 1 Gbps in the
50+ revised cost table, or 19 for 100 Mbps in the original). Each BPDU carries a
51+ *root path cost * field — the total cost from the sending switch to the root.
52+ When a switch receives a BPDU, it adds the receiving port's own cost to the
53+ advertised root path cost. The port with the lowest total cost to the root
54+ becomes the switch's *root port *. Ties are broken by lowest upstream bridge ID,
55+ then by lowest upstream port ID.
56+
57+ **3. Designated port selection. ** For each network segment (link between two
58+ switches), one port must be elected as the *designated port * — the port
59+ responsible for forwarding frames toward the root on that segment. The switch
60+ that can offer the lowest root path cost on that segment wins. Ties are
61+ broken by bridge ID, then port ID. The root bridge's ports are always
62+ designated (cost = 0).
63+
64+ **4. Blocking redundant ports. ** Any port that is neither a root port nor a
65+ designated port is placed in *blocking * state — it does not forward data
66+ frames, breaking the loop. These blocked ports continue to receive BPDUs so
67+ they can react if the topology changes.
4368
4469In INET, STP is implemented by the :ned: `Stp ` module, which is enabled per
4570switch via the ``hasStp = true `` and ``spanningTreeProtocol = "Stp" `` parameters.
4671
47- .. note ::
48- INET's :ned: `Stp ` implementation does not distinguish Blocking and Listening
49- as separate internal states. Instead, it uses a single ``DISCARDING `` state
50- (borrowed from RSTP) that covers both, transitioning directly to ``LEARNING ``
51- and then ``FORWARDING ``. As a result, the visualization will display
52- *Discarding * rather than *Blocking * or *Listening * during convergence.
53-
5472Configuration
5573~~~~~~~~~~~~~
5674
@@ -67,11 +85,41 @@ as labels on each switch interface.
6785
6886Traffic from ``host2 `` to ``host1 `` starts at t=60s, after STP has converged.
6987
88+ Observing the Simulation
89+ ~~~~~~~~~~~~~~~~~~~~~~~~
90+
91+ When running the simulation in Qtenv, several visual cues help you follow the
92+ STP algorithm:
93+
94+ - **Packet names ** reflect the BPDU type. Periodic hello BPDUs are named
95+ ``stp-hello ``; topology change notifications are ``stp-tcn ``.
96+ - **Port labels ** on each switch interface show the port role and state as a
97+ short code, e.g. ``R/F `` (Root/Forwarding), ``D/F `` (Designated/Forwarding),
98+ ``D/N `` (Designated/Listening), ``D/L `` (Designated/Learning),
99+ ``-/B `` (unassigned/Blocking).
100+ - **Root path cost ** is displayed above each switch icon: ``cost: 0 `` for
101+ the root bridge, ``cost: 19 `` for a switch one hop away over a 100 Mbps link,
102+ etc.
103+ - **Link colors **: black for Forwarding ports, gray for
104+ Blocking/Listening/Learning.
105+ - **Root bridge ** is highlighted in cyan with an exclamation mark icon overlay.
106+ - **Inspecting state variables **: double-click on a switch's ``stp `` submodule
107+ in Qtenv to inspect internal variables such as ``bridgeAddress ``,
108+ ``rootAddress ``, ``rootPathCost ``, ``isRoot ``, and per-port data (in the
109+ interface table).
110+
70111Results
71112~~~~~~~
72113
73114After the simulation starts, STP BPDUs (Bridge Protocol Data Units) are exchanged
74- between switches. After approximately 50 s, the spanning tree has converged:
115+ between switches. The following video shows the BPDU traffic during the early
116+ phase of convergence:
117+
118+ .. video_noloop :: media/step2arrows2.mp4
119+ :width: 100%
120+ :align: center
121+
122+ After approximately 35 s, the spanning tree has converged:
75123
76124- **Root bridge **: ``switch1 `` (lowest MAC address ``AAAAAA000001 ``)
77125- **Blocked ports **: the ports creating redundant paths are blocked (shown in gray)
@@ -80,13 +128,21 @@ between switches. After approximately 50 s, the spanning tree has converged:
80128.. figure :: media/step2result.png
81129 :align: center
82130
131+ The following video shows the full convergence process in real time. Observe how
132+ port states transition from Blocking through Listening and Learning to
133+ Forwarding over approximately 36 s:
134+
135+ .. video_noloop :: media/step2convergence_realtime2.mp4
136+ :width: 100%
137+ :align: center
138+
83139After convergence (t=60s), ``host2 `` begins sending frames to ``host1 `` and
84140receives replies, confirming that the tree provides full connectivity while
85141remaining loop-free.
86142
87- .. video :: media/step2result .mp4
88- :width: 100%
89- :align: center
143+ .. video_noloop :: media/step2arrows4 .mp4
144+ :width: 100%
145+ :align: center
90146
91147Sources:
92148:download: `omnetpp.ini <../omnetpp.ini >`,
0 commit comments