Skip to main content

TcpSimBus

Struct TcpSimBus 

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

A TCP-aware simulation bus.

Wraps SimBus for message delivery and adds connection state tracking and TCP-level fault injection on top. The bus owns the connection state - nodes request connections and observe events but do not track TCP state themselves.

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

Implementations§

Source§

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

Source

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

Creates a new TcpSimBus.

seed - seeds both the message bus RNG and the TCP fault RNG. The TCP RNG uses seed.wrapping_add(1) so the two RNGs produce independent sequences from the same seed.

Source

pub fn connect(&mut self, from: NodeAddress, to: NodeAddress)

Requests a TCP connection from from to to.

The connection may be established, refused, or timeout depending on the TcpFaultConfig. The outcome appears as a TcpEvent on the next tick.

Source

pub fn disconnect(&mut self, from: NodeAddress, to: NodeAddress)

Closes the connection cleanly from the given node.

Source

pub fn connection_state(&self) -> &TcpConnectionState

Source

pub fn is_connected(&self) -> bool

Source

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

Enqueues a message - rejected if the connection is not established.

Returns true if the message was accepted, false if rejected due to connection state or message-level fault injection.

Source

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

Advances simulation time, delivers due messages, and checks connection-level fault injection.

Source

pub fn now(&self) -> Instant

Source

pub fn drain_events(&mut self) -> impl Iterator<Item = TcpEvent> + '_

Drains accumulated TCP events.

Source

pub fn set_connect_timeout(&mut self, timeout: Duration)

Source

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

Source

pub fn inner_mut(&mut self) -> &mut SimBus<N, Q>

Trait Implementations§

Source§

impl<const N: usize, const Q: usize> Debug for TcpSimBus<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 TcpSimBus<N, Q>

§

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

§

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

§

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

§

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

§

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

§

impl<const N: usize, const Q: usize> UnwindSafe for TcpSimBus<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.