Struct Router

Source
pub struct Router<'r> { /* private fields */ }
Expand description

An async MCTP stack with routing.

This interfaces between transport ports and MCTP using applications.

Applications can use req() and listener() to obtain instances of the mctp async traits.

Device-provided input handlers feed input MCTP packets to inbound().

For outbound packets each port has queue split into PortTop and PortBottom. Router will feed packets for a port into the top, and device output handlers will read from PortBottom and write out the specific MCTP transport.

update_time() should be called periodically to handle timeouts.

Packets not destined for the local EID will be forwarded out a port determined by the user-provided PortLookup implementation.

Implementations§

Source§

impl<'r> Router<'r>

Source

pub fn new( stack: Stack, ports: &'r [PortTop<'r>], lookup: &'r mut dyn PortLookup, ) -> Self

Create a new Router.

The EID of the provided stack is used to match local destination packets.

ports is a list of transport interfaces for the router. The indices of the ports slice are used as PortId identifiers.

lookup callbacks define the routing table for outbound packets.

Source

pub async fn update_time(&self, now_millis: u64) -> Result<u64>

Called periodically to update the clock and check timeouts.

A suitable interval (milliseconds) for the next call to update_time() will be returned, currently a maximum of 100 ms.

Source

pub async fn inbound(&self, pkt: &[u8], port: PortId) -> Option<Eid>

Provide an incoming packet to the router.

This expects a single MCTP packet, with no transport binding header.

Returns the packet’s MCTP source EID for any valid packet, regardless of whether the packet is handled, forwarded, or dropped.

Source

pub fn req(&'r self, eid: Eid) -> RouterAsyncReqChannel<'r>

Create a AsyncReqChannel instance.

Source

pub fn listener(&'r self, typ: MsgType) -> Result<RouterAsyncListener<'r>>

Create a AsyncListener instance.

Will receive incoming messages with the TO bit set for the given typ.

Source

pub async fn get_eid(&self) -> Eid

Retrieve the EID assigned to the local stack

Source

pub async fn set_eid(&self, eid: Eid) -> Result<()>

Set the EID assigned to the local stack

Auto Trait Implementations§

§

impl<'r> !Freeze for Router<'r>

§

impl<'r> !RefUnwindSafe for Router<'r>

§

impl<'r> Send for Router<'r>

§

impl<'r> Sync for Router<'r>

§

impl<'r> Unpin for Router<'r>

§

impl<'r> !UnwindSafe for Router<'r>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.