A saved lab forgets every DHCP lease, and without a clock the view calls the survivors active #1465

Closed
opened 2026-11-12 03:04:51 +00:00 by jaylouisw · 0 comments
Owner
save a lab where two hosts hold DHCP leases, then reopen it

r1> show ip dhcp binding
IP address      Client identifier / MAC       Pool              Expires in
% no leases: nothing has asked this server for an address yet

Cause

The leases live on the topology (topo.dhcpStates, aliased by the simulator) — exactly the state the document is meant to carry. Topology.serialize() writes 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 re-issued the same addresses 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 — and the summary subtracted the lapsed count from the total and called the rest active, a claim about time the engine had explicitly declined to make:

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

What should be true

  1. The document carries the leases: 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.
  2. The codec lives with the module that owns the shape (engine/dhcp.js): two Maps that JSON cannot write become one list of leases, and come back as two Maps rebuilt from that one list — so a document can never restore a MAC map and an address map that disagree. An entry naming a device not on the board is skipped; one address keeps one holder, which is the rule the running server applies.
  3. Without a clock the view states no lease state: the column reads no clock, and the summary counts bindings, not states — 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 rows read 60s and lapsed (address free) again, unchanged.

Evidence: test/dhcp-leases-survive-save.test.js, 32 checks. Reverting engine/ fails 12.

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.

Also probed this iteration and found honest, so nothing was changed for them: show running-config replay across all four checked-in example labs (19 devices, no drift), an incomplete ip dhcp pool (kept deliberately, reported by show ip dhcp pool as In use: no - <reason>, and the exit message is a statement about the pool rather than a refusal), and two pools with overlapping ranges (the first match wins consistently; no address is handed to two clients).

``` save a lab where two hosts hold DHCP leases, then reopen it r1> show ip dhcp binding IP address Client identifier / MAC Pool Expires in % no leases: nothing has asked this server for an address yet ``` ### Cause The leases live on the topology (`topo.dhcpStates`, aliased by the simulator) — exactly the state the document is meant to carry. `Topology.serialize()` writes 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 re-issued the same addresses 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 — and the summary subtracted the lapsed count from the total and called the rest *active*, a claim about time the engine had explicitly declined to make: ``` 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 ``` ### What should be true 1. **The document carries the leases**: `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. 2. **The codec lives with the module that owns the shape** (`engine/dhcp.js`): two Maps that JSON cannot write become one list of leases, and come back as two Maps rebuilt from that one list — so a document can never restore a MAC map and an address map that disagree. An entry naming a device not on the board is skipped; one address keeps one holder, which is the rule the running server applies. 3. **Without a clock the view states no lease state**: the column reads `no clock`, and the summary counts bindings, not states — `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 rows read `60s` and `lapsed (address free)` again, unchanged. Evidence: `test/dhcp-leases-survive-save.test.js`, 32 checks. Reverting `engine/` fails 12. 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. Also probed this iteration and found honest, so nothing was changed for them: `show running-config` replay across all four checked-in example labs (19 devices, no drift), an incomplete `ip dhcp pool` (kept deliberately, reported by `show ip dhcp pool` as `In use: no - <reason>`, and the exit message is a statement about the pool rather than a refusal), and two pools with overlapping ranges (the first match wins consistently; no address is handed to two clients).
Sign in to join this conversation.
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#1465
No description provided.