Skip to main content

DeviceTable

Struct DeviceTable 

Source
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

Source

pub fn new() -> Self

Create an empty table.

Source

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.

Source

pub fn all(&self) -> Vec<DiscoveredDevice>

Get all discovered devices as a snapshot.

Source

pub fn get(&self, instance: u32) -> Option<&DiscoveredDevice>

Look up a device by instance number.

Source

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.

Source

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.

Source

pub fn clear(&mut self)

Clear all entries.

Source

pub fn len(&self) -> usize

Number of discovered devices.

Source

pub fn is_empty(&self) -> bool

Whether the table is empty.

Source

pub fn purge_stale(&mut self, max_age: Duration)

Remove entries whose last_seen is older than max_age.

Trait Implementations§

Source§

impl Debug for DeviceTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DeviceTable

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more