A 1 Gb port costs 4, not 20,000: one short path-cost table for the spanning tree #1600

Merged
jaylouisw merged 1 commit from rev/1116-0400 into main 2026-11-16 05:00:51 +00:00
Owner

What

A port's default spanning-tree path cost: the short method the switch actually defaults to, in one table.

The engine charged the 32-bit costs under a comment that called them the 16-bit ones:

engine/stp.js        DEFAULT_PORT_COST = 20000   // "802.1D short cost for a 1G link"
                     SPEED_COST = {10: 2000000, 100: 200000, 1000: 20000, ...}
engine/simulator.js  speedToCost()  - no row for 100 Mb, 40 Gb as 400

Cisco's short method - the default on Catalyst and NX-OS - charges 10M 100, 100M 19, 1G 4, 10G 2,
25G/40G/100G 1. So a Fast Ethernet cable cost 200,000 (ten times a gigabit) in the election while the file's
own portCost() charged 200, and the 40 Gb row disagreed between the two copies (400 vs 500).

computeStp() built the election from the simulator's copy while portCost() used the library's, so one port
could carry two costs. Both now call costForSpeedMbps() in engine/stp.js; speedToCost was exported and called
nowhere else, so it goes.

The behaviour this changes

show spanning-tree reports roles and states, not costs, so the visible effect is which port blocks. A bridge
with one 100 Mb hop to the root (19) against a five-hop 1 Gb chain (5 x 4 = 20) now roots through the 100 Mb port
and blocks the chain; under the old numbers the chain cost 100,000 against 200,000, so it blocked the faster path
and forwarded the slower one.

Inferred, and said so

A rate with no published row (2.5G, 5G; anything above 100G) takes the next slower documented row's cost, so
every value returned is one the vendor publishes and cost never rises with speed. Asserted as an inference.

Sources

research/stp-path-cost.md: Catalyst 9200 and 9500 Layer 2 config guides 17.2, NX-OS 10.4 Rapid PVST+ (Table 4,
short vs long out to 400G), and the CBS-250/350 CLI guide - the small-business line defaults to long, the one
place "Cisco defaults to short" is not true.

Tests

test/stp-path-cost.test.js (21 assertions): the published rows, interpolation, monotonic rule, the election that
flips, and simulator/library charging the same cost for the same cable at 1 Gb and forced 100 Mb.
test/stp.test.js's "default port cost is 20000" now expects 4.

Full suite: 264 suites, 9,569 assertions, 0 failed. node scripts/syntax-check.js: 334 files OK.

Left unresolved

Port-channel cost (this engine divides by member count; Cisco derives it from the bundle's speed) and per-VLAN
cost/priority (PVST/RPVST adds the VLAN id, so VLAN 1 is 32769). Both are features, not fidelity fixes.

## What A port's default spanning-tree path cost: the short method the switch actually defaults to, in one table. The engine charged the **32-bit** costs under a comment that called them the 16-bit ones: ``` engine/stp.js DEFAULT_PORT_COST = 20000 // "802.1D short cost for a 1G link" SPEED_COST = {10: 2000000, 100: 200000, 1000: 20000, ...} engine/simulator.js speedToCost() - no row for 100 Mb, 40 Gb as 400 ``` Cisco's short method - the default on Catalyst and NX-OS - charges 10M **100**, 100M **19**, 1G **4**, 10G **2**, 25G/40G/100G **1**. So a Fast Ethernet cable cost 200,000 (ten times a gigabit) in the election while the file's own `portCost()` charged 200, and the 40 Gb row disagreed between the two copies (400 vs 500). `computeStp()` built the election from the simulator's copy while `portCost()` used the library's, so one port could carry two costs. Both now call `costForSpeedMbps()` in `engine/stp.js`; `speedToCost` was exported and called nowhere else, so it goes. ## The behaviour this changes `show spanning-tree` reports roles and states, not costs, so the visible effect is *which port blocks*. A bridge with one 100 Mb hop to the root (19) against a five-hop 1 Gb chain (5 x 4 = 20) now roots through the 100 Mb port and blocks the chain; under the old numbers the chain cost 100,000 against 200,000, so it blocked the faster path and forwarded the slower one. ## Inferred, and said so A rate with no published row (2.5G, 5G; anything above 100G) takes the next **slower** documented row's cost, so every value returned is one the vendor publishes and cost never rises with speed. Asserted as an inference. ## Sources `research/stp-path-cost.md`: Catalyst 9200 and 9500 Layer 2 config guides 17.2, NX-OS 10.4 Rapid PVST+ (Table 4, short vs long out to 400G), and the CBS-250/350 CLI guide - the small-business line defaults to **long**, the one place "Cisco defaults to short" is not true. ## Tests `test/stp-path-cost.test.js` (21 assertions): the published rows, interpolation, monotonic rule, the election that flips, and simulator/library charging the same cost for the same cable at 1 Gb and forced 100 Mb. `test/stp.test.js`'s "default port cost is 20000" now expects 4. Full suite: **264 suites, 9,569 assertions, 0 failed**. `node scripts/syntax-check.js`: 334 files OK. ## Left unresolved Port-channel cost (this engine divides by member count; Cisco derives it from the bundle's speed) and per-VLAN cost/priority (PVST/RPVST adds the VLAN id, so VLAN 1 is 32769). Both are features, not fidelity fixes.
A 1 Gb port costs 4, not 20,000: one short path-cost table for the spanning tree
Some checks failed
PR rebase / Rebase onto main and arm auto-merge (pull_request) Failing after 15m7s
CI / Classify the change (pull_request) Failing after 15m13s
CI / Test (Node 18) (pull_request) Has been cancelled
CI / Test (Node 20) (pull_request) Has been cancelled
CI / Test (Node 22) (pull_request) Has been cancelled
CI / Server smoke test (pull_request) Has been cancelled
CI / Docker build (pull_request) Has been cancelled
240d0324ac
`show spanning-tree` reports roles and states, so a wrong path cost is not a wrong number on the page - it is
the wrong port blocked. The engine charged the 32-bit costs under a comment that called them the 16-bit ones,
and it kept two copies of the table that disagreed with each other.

  engine/stp.js        DEFAULT_PORT_COST = 20000   // "802.1D short cost for a 1G link"
                       SPEED_COST = {10: 2000000, 100: 200000, 1000: 20000, ...}
  engine/simulator.js  speedToCost()  - no row for 100 Mb, and 40 Gb as 400

Every number there is the *long* method; Cisco's short method - the default on Catalyst and NX-OS - charges
100 / 19 / 4 / 2 / 1 for 10M / 100M / 1G / 10G / 25G and above. A Fast Ethernet cable therefore cost 200,000
(ten times a gigabit) in the election and 200 in the file's own `portCost()`.

`computeStp()` built the election from the simulator's copy while `portCost()` used the library's, so one port
could carry two costs. Both now call `costForSpeedMbps()` in engine/stp.js: the published table, with a rate
that has no row of its own taking the next slower row's cost (2.5G and 5G cost 4) so every value returned is
one the vendor publishes and cost never rises with speed. `speedToCost` was exported and called nowhere else,
so it goes.

The ring this changes: a bridge with one 100 Mb hop to the root (19) against a five-hop 1 Gb chain
(5 x 4 = 20) roots through the 100 Mb port and blocks the chain. Under the old numbers the chain cost 100,000
against 200,000, so the bridge blocked the faster path and forwarded the slower one.

Sources in research/stp-path-cost.md (Catalyst 9200/9500 L2 guides, NX-OS 10.4 Rapid PVST+, CBS-350 CLI - the
small-business line defaults to long, which is the one place "Cisco defaults to short" is not true).

test/stp-path-cost.test.js pins the published rows, the interpolation, the monotonic rule, the election that
flips, and that the simulator and the library charge the same cost for the same cable at 1 Gb and at a forced
100 Mb. test/stp.test.js's "default port cost is 20000" now expects 4. Full suite: 264 suites, 9,569
assertions, 0 failed.
jaylouisw force-pushed rev/1116-0400 from 240d0324ac
Some checks failed
PR rebase / Rebase onto main and arm auto-merge (pull_request) Failing after 15m7s
CI / Classify the change (pull_request) Failing after 15m13s
CI / Test (Node 18) (pull_request) Has been cancelled
CI / Test (Node 20) (pull_request) Has been cancelled
CI / Test (Node 22) (pull_request) Has been cancelled
CI / Server smoke test (pull_request) Has been cancelled
CI / Docker build (pull_request) Has been cancelled
to f383b4e78f
Some checks failed
PR rebase / Rebase onto main and arm auto-merge (pull_request) Failing after 10m30s
CI / Classify the change (pull_request) Failing after 11m24s
CI / Test (Node 18) (pull_request) Has been cancelled
CI / Test (Node 20) (pull_request) Has been cancelled
CI / Test (Node 22) (pull_request) Has been cancelled
CI / Server smoke test (pull_request) Has been cancelled
CI / Docker build (pull_request) Has been cancelled
2026-11-16 04:56:45 +00:00
Compare
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-16 04:59:17 +00:00
Sign in to join this conversation.
No description provided.