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>
impl<'r> Router<'r>
Sourcepub fn new(
stack: Stack,
ports: &'r [PortTop<'r>],
lookup: &'r mut dyn PortLookup,
) -> Self
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.
Sourcepub async fn update_time(&self, now_millis: u64) -> Result<u64>
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.
Sourcepub async fn inbound(&self, pkt: &[u8], port: PortId) -> Option<Eid>
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.
Sourcepub fn req(&'r self, eid: Eid) -> RouterAsyncReqChannel<'r>
pub fn req(&'r self, eid: Eid) -> RouterAsyncReqChannel<'r>
Create a AsyncReqChannel
instance.
Sourcepub fn listener(&'r self, typ: MsgType) -> Result<RouterAsyncListener<'r>>
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
.