Give the spanning tree a root anybody can choose (#1364) #1365

Merged
jaylouisw merged 1 commit from fix/stp-priority into main 2026-11-10 17:52:24 +00:00
Owner

Give the spanning tree a root anybody can choose. Fixes #1364.

computeStp() has built each bridge with

priority: (dev.config && dev.config.stpPriority) || stpLib.STP_DEFAULT_PRIORITY,

since STP was modelled. config.stpPriority had no writer anywhere — no catalogue spec sets it, no command
sets it, Device.serialize() did not carry it. Every switch in every lab ran 32768, the root was decided by MAC
address alone, and "make this box the root" — the first thing anyone does to a switched network — could not be
done. show spanning-tree did not print the priority either, so the report described a tree without explaining
its shape.

Measured on three CX 6000s in a triangle (s3 lowest MAC, all priorities default):

before:            root s3 priority 32768
spanning-tree priority 4096 on s1 ->  root s1 priority 4096   (s1 has the HIGHEST MAC)
no spanning-tree priority on s1   ->  root s3 priority 32768

Underneath, two more defects:

  • 0 was unreachable. Priority 0 is legal (0–61440 in 4096 steps) and is the best there is; the ||
    above turned it into the default, so a box told "you must be root" read as "you must not".
  • The election named no bridge. runStp() returned root: {priority, mac} — a bridge ID, not a device — so
    nothing downstream could say which switch won, and the first version of the report printed the model label
    (Aruba CX 6000 24G 4SFP+), which is the same string on all three switches.

The command

spanning-tree priority 4096
no spanning-tree priority
  • A value that is not a multiple of 4096, or outside 0–61440, is refused naming the rule and the two nearest valid
    values. Never rounded — rounding elects a root nobody asked for:
    % 4500 is not a valid bridge priority: it must be a multiple of 4096 …; the nearest valid values are 4096 and 8192
  • IOS's per-VLAN spelling is refused with the reason rather than accepted and applied to everything:
    % This device runs one spanning tree, not one per VLAN: use \spanning-tree priority <0-61440>``
  • A device with no bridging ports is told the value is stored but no election runs there.

The report

Spanning tree enabled protocol ieee
  Bridge priority 4096 (this bridge is the root), root bridge s1 priority 4096
Port          Role          State
1/1/1         designated    forwarding

The root is named by hostname, else by the lab's id. With no simulator behind the session the line reads
root bridge not measured (no election has run) — the same distinction show interfaces makes for its counters.

Survives a save

stpPriority is serialized only when set (a switch that never had one does not grow a null in every saved
board), restored on load, and printed by show running-config — so a reloaded lab elects the same root it did
before. test/config-completeness.test.js gains the print declaration the suite demands for a new config key
(56 checks, was 55).

Evidence

test/stp-priority.test.js — 40 checks. Lower priority beats a lower MAC in both directions; 0 wins;
4500 and 65536 are refused with the rule and the nearest valid values; the per-VLAN form is refused and does
not set the device-wide value instead; no restores the MAC winner and refuses when nothing is set; the report
prints the priority in force, claims the root only when it is, and says "not measured" with no simulator; the
priority and the root survive a save; running-config round-trips.

With engine/{cli,simulator,stp,device}.js reverted, 32 of the 40 fail.

npm run syntax — 253 files, all OK. npm test — 185 suites, 7,173 assertions, 0 failed.

Give the spanning tree a root anybody can choose. Fixes #1364. `computeStp()` has built each bridge with ```js priority: (dev.config && dev.config.stpPriority) || stpLib.STP_DEFAULT_PRIORITY, ``` since STP was modelled. `config.stpPriority` had **no writer anywhere** — no catalogue spec sets it, no command sets it, `Device.serialize()` did not carry it. Every switch in every lab ran 32768, the root was decided by MAC address alone, and *"make this box the root"* — the first thing anyone does to a switched network — could not be done. `show spanning-tree` did not print the priority either, so the report described a tree without explaining its shape. Measured on three CX 6000s in a triangle (`s3` lowest MAC, all priorities default): ``` before: root s3 priority 32768 spanning-tree priority 4096 on s1 -> root s1 priority 4096 (s1 has the HIGHEST MAC) no spanning-tree priority on s1 -> root s3 priority 32768 ``` Underneath, two more defects: * **`0` was unreachable.** Priority 0 is legal (`0`–`61440` in 4096 steps) and is the best there is; the `||` above turned it into the default, so a box told "you must be root" read as "you must not". * **The election named no bridge.** `runStp()` returned `root: {priority, mac}` — a bridge ID, not a device — so nothing downstream could say which switch won, and the first version of the report printed the *model label* (`Aruba CX 6000 24G 4SFP+`), which is the same string on all three switches. ## The command ``` spanning-tree priority 4096 no spanning-tree priority ``` * A value that is not a multiple of 4096, or outside 0–61440, is refused naming the rule and the two nearest valid values. **Never rounded** — rounding elects a root nobody asked for: `% 4500 is not a valid bridge priority: it must be a multiple of 4096 …; the nearest valid values are 4096 and 8192` * IOS's per-VLAN spelling is refused with the reason rather than accepted and applied to everything: `% This device runs one spanning tree, not one per VLAN: use \`spanning-tree priority <0-61440>\`` * A device with no bridging ports is told the value is stored but no election runs there. ## The report ``` Spanning tree enabled protocol ieee Bridge priority 4096 (this bridge is the root), root bridge s1 priority 4096 Port Role State 1/1/1 designated forwarding ``` The root is named by hostname, else by the lab's id. With no simulator behind the session the line reads `root bridge not measured (no election has run)` — the same distinction `show interfaces` makes for its counters. ## Survives a save `stpPriority` is serialized **only when set** (a switch that never had one does not grow a `null` in every saved board), restored on load, and printed by `show running-config` — so a reloaded lab elects the same root it did before. `test/config-completeness.test.js` gains the print declaration the suite demands for a new config key (56 checks, was 55). ## Evidence `test/stp-priority.test.js` — **40 checks**. Lower priority beats a lower MAC in both directions; `0` wins; `4500` and `65536` are refused with the rule and the nearest valid values; the per-VLAN form is refused and does not set the device-wide value instead; `no` restores the MAC winner and refuses when nothing is set; the report prints the priority in force, claims the root only when it is, and says "not measured" with no simulator; the priority and the root survive a save; running-config round-trips. With `engine/{cli,simulator,stp,device}.js` reverted, **32 of the 40 fail**. `npm run syntax` — 253 files, all OK. `npm test` — **185 suites, 7,173 assertions, 0 failed**.
Give the spanning tree a root anybody can choose (#1364)
All checks were successful
CI / Classify the change (pull_request) Successful in 10s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 13s
CI / Test (Node 20) (pull_request) Successful in 2m55s
CI / Test (Node 18) (pull_request) Successful in 3m4s
CI / Server smoke test (pull_request) Successful in 30s
CI / Docker build (pull_request) Successful in 50s
CI / Test (Node 22) (pull_request) Successful in 2m38s
f456746b36
computeStp() has built each bridge with

    priority: (dev.config && dev.config.stpPriority) || STP_DEFAULT_PRIORITY

since STP was modelled. config.stpPriority had NO writer anywhere: no catalogue spec sets it, no command
sets it, and Device.serialize() did not carry it. Every switch in every lab therefore ran 32768, the root
was decided by MAC address alone, and 'make this box the root' - the first thing anyone does to a switched
network - could not be done. show spanning-tree did not print the priority either, so the report described
a tree without explaining its shape.

Two defects underneath:

- 0 was unreachable. Priority 0 is legal (0-61440 in 4096 steps) and is the best there is, and the '||'
  above turned it into the default. A box told 'you must be root' read as 'you must not'.
- The election named no bridge. runStp() returned root: {priority, mac} - a bridge ID, not a device - so
  nothing downstream could say which switch won.

Now:

- 'spanning-tree priority <0-61440>' sets it; 'no spanning-tree priority' restores 32768 and says so.
- A value that is not a multiple of 4096, or outside the range, is refused naming the rule and the two
  nearest valid values. Never rounded: rounding elects a root nobody asked for.
- IOS's per-VLAN spelling is refused with the reason rather than accepted and applied to everything. This
  model runs one spanning tree per device; pretending otherwise would be the 'one command changes
  something the operator did not ask about' defect.
- show spanning-tree prints the bridge priority in force, says 'this bridge is the root' when it is, and
  names the root by hostname or lab id - not by the model label, which is the same string on every switch
  of one kind.
- The priority is serialized only when set, restored on load, and printed by show running-config, so a
  reloaded lab elects the same root.
- A device with no bridging ports is told the value is stored but no election runs there.

test/stp-priority.test.js: 40 checks. Lower priority beats a lower MAC in both directions; 0 wins; 4500 and
65536 are refused with the rule and the nearest valid values; the per-VLAN form is refused; no-form
restores the MAC winner; the report names the root and reports 'not measured' with no simulator; the
priority and the root survive a save; running-config round-trips.

With engine/{cli,simulator,stp,device}.js reverted, 32 of the 40 fail.

test/config-completeness.test.js gains the print declaration the suite demands for a new config key
(56 checks, was 55).

Suite: 185 suites, 7,173 assertions, 0 failed. Syntax: 253 files, all OK.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-10 17:52:22 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1365
No description provided.