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>
impl<const N: usize, const Q: usize> TcpSimBus<N, Q>
Sourcepub fn new(seed: u64, faults: TcpFaultConfig) -> Self
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.
Sourcepub fn connect(&mut self, from: NodeAddress, to: NodeAddress)
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.
Sourcepub fn disconnect(&mut self, from: NodeAddress, to: NodeAddress)
pub fn disconnect(&mut self, from: NodeAddress, to: NodeAddress)
Closes the connection cleanly from the given node.
pub fn connection_state(&self) -> &TcpConnectionState
pub fn is_connected(&self) -> bool
Sourcepub fn send(&mut self, src: NodeAddress, dst: NodeAddress, data: &[u8]) -> bool
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.
Sourcepub fn tick(&mut self, duration: Duration) -> Vec<Envelope<N>, Q>
pub fn tick(&mut self, duration: Duration) -> Vec<Envelope<N>, Q>
Advances simulation time, delivers due messages, and checks connection-level fault injection.
pub fn now(&self) -> Instant
Sourcepub fn drain_events(&mut self) -> impl Iterator<Item = TcpEvent> + '_
pub fn drain_events(&mut self) -> impl Iterator<Item = TcpEvent> + '_
Drains accumulated TCP events.