Repository navigation
Improve Link Status handling and LQA computation - #144
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the Zigbee link-quality and Link Status changes.
No open issues 🎉
What changed in this PR
This PR improves Zigbee neighbor link-quality calculation and Link Status handling, addressing part of the startup routing problem described in #143.
Changes:
- Compute median link quality from available samples without waiting for a full window, including in ZDP neighbor responses.
- Respect Link Status frame address ranges and preserve outgoing costs for empty frames or frames that do not cover the local address.
- Add regression tests for partial sample windows, missing samples, and Link Status frame handling.
| File | Description |
|---|---|
crates/ziggurat-zigbee/src/nwk/neighbors.rs |
Updates median calculation and outgoing-cost handling; adds regression tests. |
crates/ziggurat-driver/src/zigbee_stack/zdp.rs |
Uses the shared median calculation for reported neighbor link quality. |
Review effort: Balanced
The stack starts with an empty sibling table, so an early link status sent within the first period lists only the routers heard so far. A router that has not spoken yet (it waits for its own 15 s period) reads that list as "I do not hear you" and, with zigpy#144, zeroes its cost toward us: it then drops our route requests and cannot carry route replies back to us until our next link status. On the bench this kept 0x0391 on a cost-4 detour after every restart. Debouncer::hold keeps requests from moving a firing before a given time. The periodic link status task holds its debouncer for the first period when the new hold_early_link_status_after_start tunable is on (default). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The stack starts with an empty sibling table, so an early link status sent within the first period lists only the routers heard so far. A router that has not spoken yet (it waits for its own 15 s period) reads that list as "I do not hear you" and, with zigpy#144, zeroes its cost toward us: it then drops our route requests and cannot carry route replies back to us until our next link status. On the bench this kept 0x0391 on a cost-4 detour after every restart. Debouncer::hold keeps requests from moving a firing before a given time. The periodic link status task holds its debouncer for the first period when the new hold_early_link_status_after_start tunable is on (default). Co-Authored-By: Claude Opus 5.5 <[email protected]>
zigpy-review-bot
left a comment
There was a problem hiding this comment.
Post-merge review. Using the samples held for the median matches spec 3.6.3, and the covers_us range check is correct for first, middle and last frames, for the boundary entry two frames share, and for an own address of 0x0000. This PR also fixes a real problem the old code had: zeroing the cost on every first frame made a non-coordinator listed in a later frame see a lost_link every period. One item needs a decision, and there is one small bug that is older than this PR.
1. An empty list now never zeroes the cost (maintainer call)
Skipping empty lists is a deliberate deviation from 3.6.4.4.2. The spec discards a frame whose range does not cover the receiver "unless the link status list was completely empty", so an empty list is processed, and the natural reading is that the receiver is then not found and its outgoing cost is set to 0. It fixes the startup problem described in #143, but nothing bounds it. A neighbor that stops hearing us and has no other router neighbor sends empty lists every period. Each one refreshes last_link_status_timestamp, so age() never ages the link out, the cost stays non-zero, and lost_link never fires. A probe with 100 empty lists at 15 s spacing kept the cost at 1. Details and options are in #154.
2. The first link status from an unknown router counts as two samples (older than this PR)
The receive path buffers every frame's LQI before on_link_status runs. For an unknown sender, on_link_status builds the entry from that buffer and then pushes the same LQI again. With the median now taken from the samples held, one outlier first frame decides the link cost until two more frames arrive. Fix: #153.
Notes, no change asked
age()clears samples only for entries with a non-zero outgoing cost. A router whose link status we heard once but that never listed us keeps its samples, so it stays in our link status after it is gone. That cannot affect routing (its outgoing cost is 0), but it takes up entries. One overheard frame is now enough to be listed.- RouterConnectivity and RouterNeighborSetDiversity count the boundary entry two frames share twice. Nothing reads either field yet.
Verified (6 checks)
- Read the diff and every caller of the removed
TableEntry::lqa():incoming_link_cost(route request/reply costs, broadcast relayer selection),link_status_entries, Mgmt_Lqi_rsp. covers_usprobed for first, middle, last, shared-boundary and first+last frames, own address 0x0000 included.- The new tests test what their names say.
- Probe tests (not committed) for the empty-list case and the aging note.
- Confirmed by a failing test on dev that the first link status from an unknown router counts twice (cost 5 instead of 3).
cargo test --workspace --all-featuresat 34f6e5f: 199 passed.
We had a few defects in how Link Status was handled:
This addresses part of #143