Skip to main content

Table

Struct Table 

Source
pub struct Table<const R: usize, const H: usize> { /* private fields */ }
Expand description

A routing table of up to R routes and H hold-down records.

A full table refuses a new network: add_direct and add_learned return false, and learn and apply_claim return LearnRefusal::Full. Routes it holds can still be refreshed, moved and removed. A router keeps its route cap at or below R, so the cap, which it counts, is met first.

A Route is a copy of a row, so a route changes only through the table’s calls, each of which keeps its rules: add_direct and add_learned install one; learn and apply_claim learn one, with flap detection and convergence; mark_busy, mark_available and mark_unreachable set its state; touch notes its use; and remove and purge_stale take it out. None of them makes a learned route direct, or a direct one learned, except by replacing it.

new is a const fn whose result is all zero bits, so a table can live in a zero-initialized static (.bss).

Implementations§

Source§

impl<const R: usize, const H: usize> Table<R, H>

Source

pub fn apply_claim( &mut self, network: u16, port: PortId, next_hop: Mac, now: Instant, timing: &Timing, ) -> Learned

Apply a learning claim from an I-Am-Router or an Init-RT-Ack entry: network is reachable through the router at next_hop on port.

Under Convergence::Standard it is learn, and any pending claim for the network is dropped without counting. Under Convergence::Hardened, a claim that would move a learned route to another port is held until a second claim for the same network and port arrives within Timing::corroboration, inclusive; the second supplies the next hop. A claim for another port takes the pending slot over, and one past the window starts it again. The held route keeps forwarding as it was.

Source

pub fn learn( &mut self, network: u16, port: PortId, next_hop: Mac, now: Instant, ) -> Learned

Install or refresh a learned route at once, with flap detection.

A move to another port sets last_seen and the move time to now, clears last_used, any mark, the pending claim and the hold-down, and counts the move toward the flap warning when it comes within 60 s of the last. A new network or a refresh through the same port is add_learned.

Source

pub fn expire_pending( &mut self, now: Instant, timing: &Timing, expired: impl FnMut(u16), ) -> usize

Drop every pending claim older than Timing::corroboration at now, calling expired with each network in ascending order, and return how many. Each counts as expired. A claim is dropped and counted before its call, so an expired that panics leaves the table consistent.

Source

pub fn pending(&self, network: u16) -> Option<Pending>

The claim pending for network under hardened convergence.

Source

pub fn pending_count(&self) -> usize

How many claims are pending: at most one per learned route.

Source

pub fn apply_management_update( &mut self, network: u16, port: PortId, next_hop: Mac, now: Instant, ) -> bool

Apply one Initialize-Routing-Table entry with a nonzero Port ID: install network as a learned route through next_hop on port, replacing any learned route it had or adding a new one, at once and without corroboration (Clause 6.4.7). A direct route, network 0 and 0xFFFF are left alone. false when nothing was installed.

Source

pub fn apply_management_removal(&mut self, network: u16) -> bool

Apply one Initialize-Routing-Table entry with Port ID 0: delete the network’s learned route. Direct routes stay. true only when a route was removed.

Source§

impl<const R: usize, const H: usize> Table<R, H>

Source

pub fn apply_reject( &mut self, network: u16, port: PortId, reason: RejectMessageReason, now: Instant, timing: &Timing, ) -> RejectEffect

Apply what a received reject says about the route to network, arriving on port with reason (Clause 6.6.3.5). Relaying the reject is the router’s business, not the table’s.

Reason 1 marks a learned route unreachable. Reason 2 marks it busy for Timing::busy_for, unless it is unreachable or still busy: a repeat never extends the deadline. Any other reason leaves a learned route as it is (RejectEffect::Kept, counted in ClaimCounters::reject_kept), since the clause changes the table for those two only. A reject that would change nothing, or one within Timing::hold_down of the last change applied from the same port, is ignored and counted, and moves neither the window nor the deadline. Direct routes never change.

Source§

impl<const R: usize, const H: usize> Table<R, H>

Source

pub const CAPACITY: usize = R

How many routes it can hold.

Source

pub const fn new() -> Table<R, H>

An empty table with standard convergence: all zero bits.

Source

pub const fn set_convergence(&mut self, convergence: Convergence)

Choose the convergence mode for later claims. Routes stay; a pending claim waits for its next claim or the sweep, as before. It is a const fn, so a table in a static can start hardened.

Source

pub const fn convergence(&self) -> Convergence

The convergence mode.

Source

pub const fn claim_counters(&self) -> ClaimCounters

The claim counts so far.

Source

pub const fn len(&self) -> usize

How many routes it holds.

Source

pub const fn is_empty(&self) -> bool

Whether it holds none.

Source

pub const fn is_full(&self) -> bool

Whether a new network has no room.

Source

pub fn lookup(&self, network: u16) -> Option<Route>

The route to network.

Source

pub fn remove(&mut self, network: u16) -> Option<Route>

Remove the route to network, with its pending claim and its hold-down records.

Source

pub fn routes(&self) -> impl Iterator<Item = (u16, &Route)> + Clone

Every route, in ascending network order. This and the other listings can be cloned, so a writer can count before it writes.

Source

pub fn networks(&self) -> impl Iterator<Item = u16> + Clone

Every network, in ascending order.

Source

pub fn networks_on_port( &self, port: PortId, ) -> impl Iterator<Item = u16> + Clone

The networks reached through port, in ascending order.

Source

pub fn networks_not_on_port( &self, port: PortId, ) -> impl Iterator<Item = u16> + Clone

The networks reached through any port but port, in ascending order.

Source

pub fn add_direct(&mut self, network: u16, port: PortId) -> bool

Install a directly attached network on port, replacing whatever route it had and clearing its records. Network 0 and 0xFFFF are ignored. false when nothing was installed.

Source

pub fn add_learned( &mut self, network: u16, port: PortId, next_hop: Mac, now: Instant, ) -> bool

Install or refresh a learned route at once, without corroboration or flap detection: a management write, or a call on the table itself.

It sets last_seen, keeps last_used on a refresh through the same port and clears it otherwise, clears any mark, and re-arms the hold-down. A direct route, network 0 and 0xFFFF are left alone. false when nothing was installed.

Source

pub fn mark_busy(&mut self, network: u16, deadline: Instant)

Mark a learned route busy until deadline, unless it is unreachable: congestion never revives a failed route. Direct routes are never marked, and neither timestamp moves.

Source

pub fn mark_available(&mut self, network: u16)

Make a learned route reachable, lifting a busy or unreachable mark. Direct routes and timestamps are untouched.

Source

pub fn mark_busy_via_peer( &mut self, port: PortId, peer: &[u8], deadline: Instant, ) -> usize

mark_busy every route served via the router at peer on port, as a Router-Busy from it that lists no network asks, and return how many were marked. Unreachable routes stay unreachable.

Source

pub fn mark_available_via_peer(&mut self, port: PortId, peer: &[u8]) -> usize

mark_available every route served via the router at peer on port, as a Router-Available from it that lists no network asks, and return how many there were.

Source

pub fn mark_unreachable(&mut self, network: u16)

Mark a learned route unreachable, keeping it in the table. Direct routes are untouched.

Source

pub fn is_served_via_peer( &self, network: u16, port: PortId, peer: &[u8], ) -> bool

Whether network is served by the router at peer on port: a learned route through that port to that next router. This is the scope of a flow-control message from peer, whose own list, when it has one, is intersected with it.

Source

pub fn routes_served_via_peer<'t>( &'t self, port: PortId, peer: &'t [u8], ) -> impl Iterator<Item = u16> + Clone + 't

The networks is_served_via_peer holds for, in ascending order: the scope of a flow-control message from peer that lists none.

Source

pub fn clear_expired_busy(&mut self, now: Instant) -> usize

Clear every busy mark whose deadline has come, returning how many.

Source

pub fn effective_reachability( &self, network: u16, now: Instant, ) -> Option<Reachability>

The reachability of network at now: a busy mark reads Reachable from its deadline on, whether or not the sweep has run.

Source

pub fn touch(&mut self, network: u16, now: Instant)

Note that a learned route carried traffic now. Only last_used moves, so traffic never keeps a route alive.

Source

pub fn purge_stale( &mut self, now: Instant, max_age: Duration, purged: impl FnMut(u16), ) -> usize

Remove every learned route last confirmed more than max_age before now, calling purged with each network in ascending order, and return how many. Direct routes never age.

Every call comes before anything is removed, so a purged that panics leaves the table as it was.

Trait Implementations§

Source§

impl<const R: usize, const H: usize> Clone for Table<R, H>

Source§

fn clone(&self) -> Table<R, H>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const R: usize, const H: usize> Debug for Table<R, H>

The routes and holds stored, not the unused storage.

Source§

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

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

impl<const R: usize, const H: usize> Default for Table<R, H>

Source§

fn default() -> Table<R, H>

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

Auto Trait Implementations§

§

impl<const R: usize, const H: usize> Freeze for Table<R, H>
where [Slot; R]: Freeze, Holds<H>: Freeze,

§

impl<const R: usize, const H: usize> RefUnwindSafe for Table<R, H>
where [Slot; R]: RefUnwindSafe, Holds<H>: RefUnwindSafe,

§

impl<const R: usize, const H: usize> Send for Table<R, H>
where [Slot; R]: Send, Holds<H>: Send,

§

impl<const R: usize, const H: usize> Sync for Table<R, H>
where [Slot; R]: Sync, Holds<H>: Sync,

§

impl<const R: usize, const H: usize> Unpin for Table<R, H>
where [Slot; R]: Unpin, Holds<H>: Unpin,

§

impl<const R: usize, const H: usize> UnsafeUnpin for Table<R, H>
where [Slot; R]: UnsafeUnpin, Holds<H>: UnsafeUnpin,

§

impl<const R: usize, const H: usize> UnwindSafe for Table<R, H>
where [Slot; R]: UnwindSafe, Holds<H>: UnwindSafe,

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<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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<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