pub struct DeviceTable { /* private fields */ }Expand description
Thread-safe device discovery table.
Keyed by device instance number (the instance part of the DEVICE object identifier). Ordinary I-Am refreshes update a row, while a conflicting complete endpoint claim leaves the first authoritative row unchanged.
§Address-space invariant
A row is routed when it carries routed-source identity (source_network
and source_address, per Clause 6.2.2 the original source SNET/SADR); its
mac_address is then only the immediate-hop router, shared by every peer
behind that router. A row is local only when it is unambiguously local:
both routing fields are None. A row with exactly one routing field set is
malformed; it counts as neither local nor routable and matches no secondary
lookup until a complete I-Am refreshes it.
§Capability provenance
Each row records whether its segmentation_supported is authoritative
(I-Am ingestion via upsert_with_result, explicit
upsert, or add_routed_device) or a legacy
placeholder (add_device). Provenance lives in the same table entry as
the device data, so it stays coherent across insert, update, purge, and
clear: any replacement of an instance replaces its provenance with it.
Implementations§
Source§impl DeviceTable
impl DeviceTable
Sourcepub fn upsert(&mut self, device: DiscoveredDevice)
pub fn upsert(&mut self, device: DiscoveredDevice)
Insert or update a discovered device.
The row’s segmentation_supported is treated as authoritative
capability (explicit configuration); see PeerSegmentation.
This explicit administrative path replaces any row with the same
instance regardless of endpoint identity.
The table is capped at 4096 entries. If the table is full and the device is not already present, the new entry is silently dropped.
Sourcepub fn all(&self) -> Vec<DiscoveredDevice>
pub fn all(&self) -> Vec<DiscoveredDevice>
Get all discovered devices as a snapshot.
Sourcepub fn get(&self, instance: u32) -> Option<&DiscoveredDevice>
pub fn get(&self, instance: u32) -> Option<&DiscoveredDevice>
Look up a device by instance number.
Sourcepub fn get_by_mac(&self, mac: &[u8]) -> Option<&DiscoveredDevice>
pub fn get_by_mac(&self, mac: &[u8]) -> Option<&DiscoveredDevice>
Look up a local device by its MAC address.
Only unambiguously local rows (no source_network/source_address)
are considered: a routed row’s mac_address is the router it was
heard through, not the remote device’s identity, so a lookup of the
router’s own address must never select a peer behind it (Clause 6.2.2).
The table is keyed by device instance, so two local rows can share one
MAC until the stale purge; the freshest last_seen wins, mirroring
DeviceTable::get_by_network_address.
Sourcepub fn get_by_network_address(
&self,
network: u16,
address: &[u8],
) -> Option<&DiscoveredDevice>
pub fn get_by_network_address( &self, network: u16, address: &[u8], ) -> Option<&DiscoveredDevice>
Look up a routed device by its remote network number and MAC address.
A routed device’s mac_address holds the router it was heard through,
which every device behind that router shares; its own identity is the
SNET/SADR of the NPDU that carried its I-Am, stored as
source_network and source_address.
The table is keyed by device instance, so two rows can share one
SNET/SADR (a re-commissioned instance survives until the stale purge).
The freshest last_seen wins: it holds what the device most recently
advertised.
Sourcepub fn purge_stale(&mut self, max_age: Duration)
pub fn purge_stale(&mut self, max_age: Duration)
Remove entries whose last_seen is older than max_age.