A saved lab forgot who was holding which address #1466

Merged
jaylouisw merged 1 commit from fix/dhcp-leases-survive into main 2026-11-12 03:05:09 +00:00
Owner

Closes #1465

save a lab where two hosts hold DHCP leases, then reopen it

r1> show ip dhcp binding
% no leases: nothing has asked this server for an address yet

The leases live on the topology (topo.dhcpStates, aliased by the simulator) — exactly the state the document carries. Topology.serialize() wrote the flows for that reason (#1435) and never wrote the leases, so a server that had answered two hosts reopened claiming nobody had ever asked. And because dhcp.leaseTable() only states a lease's state when asked at an instant, the view — with no clock — called every row active anyway:

10.0.0.100  02:00:00:00:02:00  LAN  -
2 active binding(s); the lease clock runs from the instant the lease was granted

The change

  • leases travel in the document — dhcp: { <deviceId>: { leases: [...] } }, written only when a device holds one, so a board without a DHCP server produces byte-identical documents and the checked-in examples are untouched;
  • the codec lives in engine/dhcp.js, the module that owns the lease state's shape: two Maps become one list of leases and come back as two Maps rebuilt from that list, so a document can never restore a MAC map and an address map that disagree. An entry naming a device that is not on the board is skipped; one address keeps one holder, the rule the running server applies;
  • without a clock the view states no lease state — the column reads no clock and the summary counts bindings:
    10.0.0.100  02:00:00:00:02:00  LAN  no clock
    2 binding(s); no clock is set, so none is lapsed or active yet - the expiry is counted from the instant each lease was granted
    
    With a clock the same rows read 60s and lapsed (address free) again, word for word as before.

Evidence

test/dhcp-leases-survive-save.test.js, 32 checks: the document's lease records matching the bindings the server reported; no dhcp block on a board with no leases; a reopened lab holding its bindings before anything is run and no longer claiming nobody asked; no clock with no active/lapsed claim, then 2 active binding(s) at the granting instant and 0 active binding(s), 2 lapsed past expiry; the codec keeping one holder per address, dropping entries with no address or no holder, and decoding nothing to an empty state rather than a crash; a ghost server skipped; the checked-in examples carrying no dhcp block.

Reverting engine/ fails 12/32.

Neighbours green: dhcp 134, dhcp-bindings 51, dhcp-pool-undo 51, state-payload-complete 16, flows-survive-save-load 16, spec-survives-load 32, examples-generated 21.

Docs: docs/ARCHITECTURE.md § "A saved lab forgot who was holding which address".

Closes #1465 ``` save a lab where two hosts hold DHCP leases, then reopen it r1> show ip dhcp binding % no leases: nothing has asked this server for an address yet ``` The leases live on the topology (`topo.dhcpStates`, aliased by the simulator) — exactly the state the document carries. `Topology.serialize()` wrote the **flows** for that reason (#1435) and never wrote the **leases**, so a server that had answered two hosts reopened claiming nobody had ever asked. And because `dhcp.leaseTable()` only states a lease's state when asked at an instant, the view — with no clock — called every row *active* anyway: ``` 10.0.0.100 02:00:00:00:02:00 LAN - 2 active binding(s); the lease clock runs from the instant the lease was granted ``` ### The change * **leases travel in the document** — `dhcp: { <deviceId>: { leases: [...] } }`, written only when a device holds one, so a board without a DHCP server produces byte-identical documents and the checked-in examples are untouched; * **the codec lives in `engine/dhcp.js`**, the module that owns the lease state's shape: two Maps become one list of leases and come back as two Maps rebuilt from that list, so a document can never restore a MAC map and an address map that disagree. An entry naming a device that is not on the board is skipped; one address keeps one holder, the rule the running server applies; * **without a clock the view states no lease state** — the column reads `no clock` and the summary counts bindings: ``` 10.0.0.100 02:00:00:00:02:00 LAN no clock 2 binding(s); no clock is set, so none is lapsed or active yet - the expiry is counted from the instant each lease was granted ``` With a clock the same rows read `60s` and `lapsed (address free)` again, word for word as before. ### Evidence `test/dhcp-leases-survive-save.test.js`, **32 checks**: the document's lease records matching the bindings the server reported; no `dhcp` block on a board with no leases; a reopened lab holding its bindings before anything is run and no longer claiming nobody asked; `no clock` with no active/lapsed claim, then `2 active binding(s)` at the granting instant and `0 active binding(s), 2 lapsed` past expiry; the codec keeping one holder per address, dropping entries with no address or no holder, and decoding nothing to an empty state rather than a crash; a ghost server skipped; the checked-in examples carrying no `dhcp` block. Reverting `engine/` fails 12/32. Neighbours green: `dhcp` 134, `dhcp-bindings` 51, `dhcp-pool-undo` 51, `state-payload-complete` 16, `flows-survive-save-load` 16, `spec-survives-load` 32, `examples-generated` 21. Docs: `docs/ARCHITECTURE.md` § *"A saved lab forgot who was holding which address"*.
A saved lab forgot who was holding which address (#1465)
All checks were successful
CI / Classify the change (pull_request) Successful in 12s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 13s
CI / Test (Node 20) (pull_request) Successful in 3m11s
CI / Test (Node 18) (pull_request) Successful in 3m19s
CI / Server smoke test (pull_request) Successful in 27s
CI / Docker build (pull_request) Successful in 49s
CI / Test (Node 22) (pull_request) Successful in 2m47s
8719f11bb0
save a lab where two hosts hold DHCP leases, reopen it

  r1> show ip dhcp binding
  % no leases: nothing has asked this server for an address yet

The leases live on the topology (topo.dhcpStates, aliased by the simulator) -
exactly the state the document is meant to carry. Topology.serialize() wrote the
flows for that reason (#1435) and never wrote the leases, so a server that had
answered two hosts reopened claiming nobody had ever asked, and handed the same
addresses out again as if they were new.

The same shape of mistake sat in the view. A lease's state is a fact about time,
and dhcp.leaseTable() only states it when asked at an instant - without one, rows
carry no state at all. The summary then subtracted the lapsed count from the
total and called the remainder active: a claim about time the engine had
explicitly declined to make.

  * the document carries the leases, under dhcp: { <deviceId>: { leases } },
    written only when a device holds one, so a board without a DHCP server
    produces byte-identical documents and the checked-in examples are untouched;
  * the codec lives in engine/dhcp.js, the module that owns the lease state's
    shape: two Maps become one list of leases and come back as two Maps rebuilt
    from that list, so a document can never restore a MAC map and an address map
    that disagree. An entry naming a device that is not on the board is skipped,
    and one address keeps one holder - the rule the running server applies;
  * without a clock the view states no lease state: the column reads 'no clock'
    and the summary counts bindings, not states. With a clock the rows read 60s
    and 'lapsed (address free)' again, word for word as before.

Evidence: test/dhcp-leases-survive-save.test.js, 32 checks; reverting engine/
fails 12. Suite 233 suites, 8737 assertions, 0 failed.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-12 03:05:06 +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!1466
No description provided.