Skip to main content

SimBus

Struct SimBus 

Source
pub struct SimBus<const N: usize, const Q: usize> { /* private fields */ }
Expand description

The simulation message bus.

Connects all nodes in the simulation. Drives time forward, delivers messages, and injects faults according to FaultConfig.

N - max message payload bytes Q - max messages in-flight simultaneously

Implementations§

Source§

impl<const N: usize, const Q: usize> SimBus<N, Q>

Source

pub fn new(seed: u64, faults: FaultConfig) -> Self

Source

pub fn now(&self) -> Instant

Returns the current simulation time.

Source

pub fn tick(&mut self, duration: Duration) -> Vec<Envelope<N>, Q>

Advances simulation time by duration and returns all messages that are due for delivery at or before the new time.

Source

pub fn send(&mut self, src: NodeAddress, dst: NodeAddress, data: &[u8]) -> bool

Enqueues a message from src to dst with fault injection applied.

Returns true if the message was enqueued, false if it was dropped by fault injection or the queue is full

Source

pub fn faults(&self) -> &FaultConfig

Returns a reference to the current fault config

Source

pub fn set_faults(&mut self, faults: FaultConfig)

Returns the fault config - allows escalating fault severity during a simulation run.

Source

pub fn next_u8(&mut self) -> u8

Returns the RNG seed-derived next value - useful for injecting spontaneous NRCs at the node level.

Source

pub fn chance(&mut self, numerator: u32, denominator: u32) -> bool

Trait Implementations§

Source§

impl<const N: usize, const Q: usize> Debug for SimBus<N, Q>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize, const Q: usize> Freeze for SimBus<N, Q>

§

impl<const N: usize, const Q: usize> RefUnwindSafe for SimBus<N, Q>

§

impl<const N: usize, const Q: usize> Send for SimBus<N, Q>

§

impl<const N: usize, const Q: usize> Sync for SimBus<N, Q>

§

impl<const N: usize, const Q: usize> Unpin for SimBus<N, Q>

§

impl<const N: usize, const Q: usize> UnsafeUnpin for SimBus<N, Q>

§

impl<const N: usize, const Q: usize> UnwindSafe for SimBus<N, Q>

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.