A port keeps the address and the neighbour its document states (#1521) #1553

Merged
jaylouisw merged 1 commit from fix/1115-2206 into main 2026-11-15 23:40:17 +00:00
Owner

Fixes #1521

Two facts a port carries were dropped on save, and they are the two an importer needs.

The address. serialize() never wrote interfaces[].mac, and fromJSON() renumbered every port from the
locally-administered base, so a document that stated 00:1b:21:aa:bb:cc came back as an invented
02:00:00:00:00:00.

The neighbour. The per-port lldp record was the reverse fault: written by every save since LLDP existed and
read by nobody, so a reopened board's neighbour table came back empty while the file still listed the neighbours.

What changed

  • Device.serialize() writes mac for physical ports. A subinterface states none: it has no address of its own, it
    borrows its parent's.
  • Device.hydrate() restores a stated address, and only a unicast, non-zero one - Device.statedMac() is the single
    predicate, so the writer, the reader and the load report cannot disagree about what a port can have.
  • Topology._assignMacs() keeps a stated address instead of overwriting it, and holds uniqueness by skipping
    addresses a port on the board already holds, so a device added after a load cannot collide with one the document
    stated. Two ports given one address: the first keeps it, the second gets a free one, reported as
    E_IFACE_DUPLICATE_MAC. An address no port can have is not adopted and is reported as E_IFACE_BAD_MAC.
  • Device.hydrate() restores a per-port lldp record, so a reopened board knows the neighbours its document states
    without announcing again - and a record that names nobody is not restored.

Tests

  • test/port-roundtrip.test.js: 13 new assertions - the document states the address a port has, a stated address is
    what the port comes back with, re-saving is byte-identical, a duplicate is resolved and reported, broadcast and
    nonsense addresses are refused and reported, a device added after the load cannot collide, and a subinterface
    states no address and borrows its parent's.
  • test/neighbours-on-load.test.js: the restore assertions, plus a fix to a check that looked for neighbour rows on
    the device (d.lldp) where nothing is ever written, instead of on its ports - which is how a field no loader
    read survived this long.
  • npm test: 254 suites, 9284 assertions, 0 failures. node scripts/syntax-check.js: 324 files, all OK.
  • Examples regenerated (node examples/build-examples.js): 113 added lines across the four labs, all one mac per
    physical port.

Documented in docs/ARCHITECTURE.md under "A saved board is the lab that was saved".

Fixes #1521 Two facts a port carries were dropped on save, and they are the two an importer needs. **The address.** `serialize()` never wrote `interfaces[].mac`, and `fromJSON()` renumbered every port from the locally-administered base, so a document that stated `00:1b:21:aa:bb:cc` came back as an invented `02:00:00:00:00:00`. **The neighbour.** The per-port `lldp` record was the reverse fault: written by every save since LLDP existed and read by nobody, so a reopened board's neighbour table came back empty while the file still listed the neighbours. ### What changed * `Device.serialize()` writes `mac` for physical ports. A subinterface states none: it has no address of its own, it borrows its parent's. * `Device.hydrate()` restores a stated address, and only a unicast, non-zero one - `Device.statedMac()` is the single predicate, so the writer, the reader and the load report cannot disagree about what a port can have. * `Topology._assignMacs()` keeps a stated address instead of overwriting it, and holds uniqueness by skipping addresses a port on the board already holds, so a device added after a load cannot collide with one the document stated. Two ports given one address: the first keeps it, the second gets a free one, reported as `E_IFACE_DUPLICATE_MAC`. An address no port can have is not adopted and is reported as `E_IFACE_BAD_MAC`. * `Device.hydrate()` restores a per-port `lldp` record, so a reopened board knows the neighbours its document states without announcing again - and a record that names nobody is not restored. ### Tests * `test/port-roundtrip.test.js`: 13 new assertions - the document states the address a port has, a stated address is what the port comes back with, re-saving is byte-identical, a duplicate is resolved and reported, broadcast and nonsense addresses are refused and reported, a device added after the load cannot collide, and a subinterface states no address and borrows its parent's. * `test/neighbours-on-load.test.js`: the restore assertions, plus a fix to a check that looked for neighbour rows on the *device* (`d.lldp`) where nothing is ever written, instead of on its ports - which is how a field no loader read survived this long. * `npm test`: 254 suites, 9284 assertions, 0 failures. `node scripts/syntax-check.js`: 324 files, all OK. * Examples regenerated (`node examples/build-examples.js`): 113 added lines across the four labs, all one `mac` per physical port. Documented in `docs/ARCHITECTURE.md` under "A saved board is the lab that was saved".
A port keeps the address and the neighbour its document states (#1521)
All checks were successful
CI / Classify the change (pull_request) Successful in 13s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 33s
CI / Test (Node 18) (pull_request) Successful in 3m44s
CI / Test (Node 20) (pull_request) Successful in 3m39s
CI / Server smoke test (pull_request) Successful in 46s
CI / Docker build (pull_request) Successful in 26s
CI / Test (Node 22) (pull_request) Successful in 3m33s
22f3095175
Two facts a port carries were dropped on save, and they are the two an importer needs.

`interfaces[].mac` was never written at all: `serialize()` did not carry it and
`fromJSON()` renumbered every port from the locally-administered base, so a
document that stated `00:1b:21:aa:bb:cc` came back as an invented
`02:00:00:00:00:00`. The per-port `lldp` record was the reverse fault - written by
every save since LLDP existed and read by nobody - so a reopened board's
neighbour table came back empty while the file still listed the neighbours.

The address is now written for physical ports (a subinterface has none of its
own, it borrows its parent's) and restored. `_assignMacs` keeps a stated address
instead of overwriting it, and holds uniqueness by skipping addresses a port on
the board already holds, so a device added after a load cannot collide with one
the document stated. Two ports given one address: the first keeps it, the second
is given a free one and the load reports `E_IFACE_DUPLICATE_MAC`. An address no
port can have (broadcast, multicast, all-zero, or a word) is not adopted and is
reported as `E_IFACE_BAD_MAC`.

Tests: `test/port-roundtrip.test.js` gains 13 assertions (stated address
survives, byte-identical re-save, duplicate resolution, bad addresses,
post-load device, subinterface borrowing); `test/neighbours-on-load.test.js`
gains the restore assertions and fixes a check that looked for neighbour rows on
the device instead of on its ports. Examples regenerated.
jaylouisw force-pushed fix/1115-2206 from 22f3095175
All checks were successful
CI / Classify the change (pull_request) Successful in 13s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 33s
CI / Test (Node 18) (pull_request) Successful in 3m44s
CI / Test (Node 20) (pull_request) Successful in 3m39s
CI / Server smoke test (pull_request) Successful in 46s
CI / Docker build (pull_request) Successful in 26s
CI / Test (Node 22) (pull_request) Successful in 3m33s
to 06c693fa21
All checks were successful
CI / Classify the change (pull_request) Successful in 15s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 24s
CI / Test (Node 18) (pull_request) Successful in 3m38s
CI / Test (Node 20) (pull_request) Successful in 3m16s
CI / Server smoke test (pull_request) Successful in 29s
CI / Docker build (pull_request) Successful in 23s
CI / Test (Node 22) (pull_request) Successful in 3m4s
2026-11-15 23:03:02 +00:00
Compare
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-15 23:40:03 +00:00
jaylouisw force-pushed fix/1115-2206 from 06c693fa21
All checks were successful
CI / Classify the change (pull_request) Successful in 15s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 24s
CI / Test (Node 18) (pull_request) Successful in 3m38s
CI / Test (Node 20) (pull_request) Successful in 3m16s
CI / Server smoke test (pull_request) Successful in 29s
CI / Docker build (pull_request) Successful in 23s
CI / Test (Node 22) (pull_request) Successful in 3m4s
to 929b1fcedd
Some checks failed
CI / Classify the change (pull_request) Successful in 12s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 21s
CI / Test (Node 20) (pull_request) Failing after 3m21s
CI / Test (Node 18) (pull_request) Failing after 3m33s
CI / Server smoke test (pull_request) Successful in 32s
CI / Docker build (pull_request) Successful in 22s
CI / Test (Node 22) (pull_request) Failing after 3m14s
2026-11-15 23:40:06 +00:00
Compare
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!1553
No description provided.