ospf: the metric in [110/n] is the path cost, not a literal 0 #1722

Merged
jaylouisw merged 1 commit from rev/1116-2000 into main 2026-11-16 20:21:33 +00:00
Owner

show ip route printed [110/0] for every OSPF route regardless of topology, so the metric column could not distinguish two paths and could not be checked against show ip ospf interface.

Rule (device): brackets read [administrative distance/metric]; for an OSPF route the metric is the distance to the router advertising the network plus that network link's own cost (RFC 2328 §16.1, second stage), with a loopback stub link at cost 0 (§12.4.1). Sources: https://www.cisco.com/E-Learning/bulk/public/tac/cim/cib/using_cisco_ios_software/cmdrefs/show_ip_route.htm, http://cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/15986-admin-distance.pdf, https://www.rfc-editor.org/rfc/rfc2328.txt

Also fixed behind it: a hop was charged as both interfaces' costs summed; RFC 2328 §16.1 prices a path by the costs the sending routers advertise. adjacencyIndex() now builds a directed list from costA/costB, so an asymmetric link costs what each end says it costs.

Changes: engine/ospf.js (directed costs, stubCost()), engine/simulator.js (metric = distance + destination link), engine/device.js (metric on every route row), engine/cli.js (prints [distance/metric]), docs/CLI.md, research/ospf-route-metric.md, and test/ospf-route-metric.test.js; test/ospf.test.js and test/protocol-regression.test.js asserted the old arithmetic and now assert the device's numbers.

Gates: node scripts/syntax-check.js OK (359 files); npm test — 288 suites, 10311 assertions, 0 failed.

`show ip route` printed `[110/0]` for every OSPF route regardless of topology, so the metric column could not distinguish two paths and could not be checked against `show ip ospf interface`. **Rule (device):** brackets read `[administrative distance/metric]`; for an OSPF route the metric is the distance to the router advertising the network plus that network link's own cost (RFC 2328 §16.1, second stage), with a loopback stub link at cost 0 (§12.4.1). Sources: https://www.cisco.com/E-Learning/bulk/public/tac/cim/cib/using_cisco_ios_software/cmdrefs/show_ip_route.htm, http://cisco.com/c/en/us/support/docs/ip/border-gateway-protocol-bgp/15986-admin-distance.pdf, https://www.rfc-editor.org/rfc/rfc2328.txt **Also fixed behind it:** a hop was charged as both interfaces' costs summed; RFC 2328 §16.1 prices a path by the costs the *sending* routers advertise. `adjacencyIndex()` now builds a directed list from `costA`/`costB`, so an asymmetric link costs what each end says it costs. **Changes:** `engine/ospf.js` (directed costs, `stubCost()`), `engine/simulator.js` (metric = distance + destination link), `engine/device.js` (`metric` on every route row), `engine/cli.js` (prints `[distance/metric]`), `docs/CLI.md`, `research/ospf-route-metric.md`, and `test/ospf-route-metric.test.js`; `test/ospf.test.js` and `test/protocol-regression.test.js` asserted the old arithmetic and now assert the device's numbers. **Gates:** `node scripts/syntax-check.js` OK (359 files); `npm test` — 288 suites, 10311 assertions, 0 failed.
ospf: the metric in [110/n] is the path cost, not a literal 0
All checks were successful
CI / Classify the change (pull_request) Successful in 17s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 20s
CI / Server smoke test (pull_request) Successful in 19s
CI / Test (Node 20) (pull_request) Successful in 51s
CI / Test (Node 18) (pull_request) Successful in 58s
CI / Docker build (pull_request) Successful in 28s
CI / Test (Node 22) (pull_request) Successful in 55s
4bedcab002
`show ip route` printed `[110/0]` for every OSPF route whatever the topology, so the one column an
operator compares two OSPF paths by said nothing, and an `O` row could not be checked against the cost
`show ip ospf interface` prints for the same port.

The device prints the protocol's metric there: "the values in brackets use the format [administrative
distance/metric] ... [110/2] means that the route has an administrative distance of 110 and an OSPF
metric of 2" (Cisco, Understand Administrative Distance). For OSPF that metric is the distance to the
router that advertises the network plus the cost of the network link itself (RFC 2328 §16.1, second
stage: "D is equal to the distance from the root to the router vertex ... plus the stub network link's
advertised cost"), and a loopback's stub link costs 0 (§12.4.1).

Printing it honestly needed one more fix behind it: a hop was charged as both interfaces' costs added
together, while RFC 2328 §16.1 prices a path as "the sum of the costs of the path's constituent links
(as advertised in router-LSAs)" - the sender's side only. `adjacencyIndex()` now builds a directed
adjacency list from `costA`/`costB`, so an asymmetric link costs what each end says it costs, and a
route's `cost` carries the full metric.

`Device.routesTable()` puts `metric` on every row (0 for connected, static, BGP and gateway defaults),
`show ip route` prints `[distance/metric]`, and `test/ospf-route-metric.test.js` holds the device's
numbers: [110/2] for a LAN one gigabit hop away, [110/3] for one two hops away, [110/11] once
`ip ospf cost 10` is on the link, [1/0] for a static default.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-16 20:20:52 +00:00
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-16 20:20:58 +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!1722
No description provided.