Skip to main content

SimNet

Struct SimNet 

Source
pub struct SimNet { /* private fields */ }
Expand description

A simulated network: a virtual clock, a set of nodes, and the datagrams between them.

Implementations§

Source§

impl SimNet

Source

pub fn new(seed: u64) -> Self

A new network with a perfect link and a seeded generator.

Source

pub fn impair(&self, impairment: Impairment)

Sets what the link does to datagrams from now on.

Source

pub fn node(&self, index: u8) -> SimNode<'_>

A handle for the node with the given index, whose address is fd00::<index>.

Source

pub const fn rng(&self) -> &SimRng

The generator the network’s own choices come from, also usable as an Rng.

Source

pub fn sent(&self) -> u32

How many datagrams have been handed to Udp::send_to.

Source

pub fn delivered(&self) -> u32

How many datagrams have been returned from Udp::recv_from.

Source

pub fn dropped(&self) -> u32

How many datagrams the impairment dropped.

Source

pub fn duplicated(&self) -> u32

How many datagrams the impairment duplicated.

Source

pub fn now(&self) -> Instant

The current virtual time.

Source

pub fn advance_to_next_event(&self) -> bool

Moves virtual time to the earliest thing that is waiting — a sleeping task or a datagram in flight — and returns whether there was anything to move to.

false means nothing can make progress: every task is blocked on something that will never happen. That is a deadlock, and in a simulation it is a bug in the code under test rather than a reason to wait longer.

Source

pub fn advance(&self, d: Duration)

Moves virtual time forward by d, delivering anything that becomes due.

Trait Implementations§

Source§

impl Clock for SimNet

Source§

fn utc(&self) -> Option<u64>

Microseconds since the Matter epoch — 2000-01-01 00:00:00 UTC — or None when the node does not know the time.
Source§

fn granularity(&self) -> Granularity

How precise Clock::utc is, as the Time Synchronization cluster’s Granularity enumeration.
Source§

fn set_utc(&self, _micros: u64) -> Result<()>

Sets the current time, if the platform can. A node that cannot returns Err(ErrorCode::Platform); the Time Synchronization cluster reports that honestly rather than pretending the write worked.
Source§

impl Debug for SimNet

Source§

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

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

impl Rng for SimNet

Source§

fn fill(&self, out: &mut [u8]) -> Result<()>

Fills out with random bytes. Read more
Source§

fn next_u32(&self) -> Result<u32>

A random u32.
Source§

fn next_u64(&self) -> Result<u64>

A random u64.
Source§

fn next_u16(&self) -> Result<u16>

A random u16.
Source§

impl Timer for SimNet

Source§

fn now(&self) -> Instant

How long since some fixed point this timer never changes.
Source§

fn sleep_until(&self, deadline: Instant) -> impl Future<Output = ()>

Completes at deadline, or immediately if it has passed.
Source§

fn sleep(&self, duration: Duration) -> impl Future<Output = ()>

Completes after duration.

Auto Trait Implementations§

§

impl !Freeze for SimNet

§

impl !RefUnwindSafe for SimNet

§

impl !Sync for SimNet

§

impl Forget for SimNet

§

impl Move for SimNet

§

impl Send for SimNet

§

impl Unpin for SimNet

§

impl UnsafeUnpin for SimNet

§

impl UnwindSafe for SimNet

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> 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.