Skip to main content

SimNetwork

Struct SimNetwork 

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

Simulated network that intercepts all inter-node communication.

Fully deterministic given the same seed. Supports partitions, drops, latency, jitter, reordering, and message duplication.

Implementations§

Source§

impl SimNetwork

Source

pub fn new(seed: u64) -> Self

Create a new simulated network with the given random seed.

Set the link configuration between two nodes.

Configure all links between the given nodes symmetrically.

Source

pub fn inject_partition(&mut self, a: NodeId, b: NodeId)

Inject a symmetric partition: all messages between a and b are dropped.

Source

pub fn heal_partition(&mut self, a: NodeId, b: NodeId)

Heal a symmetric partition.

Source

pub fn inject_one_way_partition(&mut self, from: NodeId, to: NodeId)

Inject a one-way partition: from→to dropped, to→from delivered.

Source

pub fn heal_one_way_partition(&mut self, from: NodeId, to: NodeId)

Heal a one-way partition.

Source

pub fn heal_all_partitions(&mut self)

Heal all partitions.

Source

pub fn send(&mut self, from: NodeId, to: NodeId, payload: Vec<u8>)

Submit a message into the network.

Source

pub fn tick(&mut self)

Advance by one tick, delivering any due messages.

Source

pub fn drain(&mut self, node_id: NodeId) -> Vec<(NodeId, Vec<u8>)>

Drain delivered messages for a specific node.

Source

pub fn current_tick(&self) -> u64

Current simulation tick.

Source

pub fn in_flight_count(&self) -> usize

Number of messages currently in-flight.

Source

pub fn total_sent(&self) -> u64

Stats: total messages sent.

Source

pub fn total_dropped(&self) -> u64

Stats: total messages dropped.

Source

pub fn total_delivered(&self) -> u64

Stats: total messages delivered.

Source

pub fn total_corrupted(&self) -> u64

Stats: total messages corrupted.

Source

pub fn total_throttled(&self) -> u64

Stats: total messages throttled (delayed due to bandwidth limit).

Source

pub fn partition_pairs(&self) -> Vec<(NodeId, NodeId)>

Get all active partition pairs.

Auto Trait Implementations§

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.