Struct Sim

Source
pub struct Sim<'a> { /* private fields */ }
Expand description

A handle for interacting with the simulation.

Implementations§

Source§

impl<'a> Sim<'a>

Source

pub fn elapsed(&self) -> Duration

How much logical time has elapsed since the simulation started.

Source

pub fn since_epoch(&self) -> Duration

The logical duration from UNIX_EPOCH until now.

On creation the simulation picks a SystemTime and calculates the duration since the epoch. Each run() invocation moves logical time forward the configured tick duration.

Source

pub fn client<F>(&mut self, addr: impl ToIpAddr, client: F)
where F: Future<Output = Result> + 'static,

Register a client with the simulation.

Source

pub fn host<F, Fut>(&mut self, addr: impl ToIpAddr, host: F)
where F: Fn() -> Fut + 'a, Fut: Future<Output = Result> + 'static,

Register a host with the simulation.

This method takes a Fn that builds a future, as opposed to Sim::client which just takes a future. The reason for this is we might restart the host, and so need to be able to call the future multiple times.

Source

pub fn crash(&mut self, addrs: impl ToIpAddrs)

Crashes the resolved hosts. Nothing will be running on the matched hosts after this method. You can use Sim::bounce to start the hosts up again.

Source

pub fn bounce(&mut self, addrs: impl ToIpAddrs)

Bounces the resolved hosts. The software is restarted.

Source

pub fn is_host_running(&mut self, addr: impl ToIpAddr) -> bool

Check whether a host has software running.

Source

pub fn lookup(&self, addr: impl ToIpAddr) -> IpAddr

Lookup an IP address by host name.

Source

pub fn reverse_lookup(&self, addr: IpAddr) -> Option<String>

Perform a reverse DNS lookup, returning the hostname if the entry exists.

Source

pub fn hold(&self, a: impl ToIpAddrs, b: impl ToIpAddrs)

Hold messages between two hosts, or sets of hosts, until release is called.

Source

pub fn repair(&self, a: impl ToIpAddrs, b: impl ToIpAddrs)

Repair the connection between two hosts, or sets of hosts, resulting in messages to be delivered.

Source

pub fn repair_oneway(&self, from: impl ToIpAddrs, to: impl ToIpAddrs)

Repair the connection between two hosts, or sets of hosts, removing the effect of a previous Self::partition_oneway.

Combining this feature with Self::hold is presently not supported.

Source

pub fn release(&self, a: impl ToIpAddrs, b: impl ToIpAddrs)

The opposite of hold. All held messages are immediately delivered.

Source

pub fn partition(&self, a: impl ToIpAddrs, b: impl ToIpAddrs)

Partition two hosts, or sets of hosts, resulting in all messages sent between them to be dropped.

Source

pub fn partition_oneway(&self, from: impl ToIpAddrs, to: impl ToIpAddrs)

Partition two hosts, or sets of hosts, such that messages can not be sent from ‘from’ to ‘to’, while not affecting the ability for them to be delivered in the other direction.

Partitioning first from->to, then to->from, will stop all messages, similarly to a single call to Self::partition.

Combining this feature with Self::hold is presently not supported.

Source

pub fn reverse_lookup_pair(&self, pair: (IpAddr, IpAddr)) -> (String, String)

Resolve host names for an IpAddr pair.

Useful when interacting with network links.

Source

pub fn lookup_many(&self, addr: impl ToIpAddrs) -> Vec<IpAddr>

Lookup IP addresses for resolved hosts.

Source

pub fn set_max_message_latency(&self, value: Duration)

Set the max message latency for all links.

Set the message latency for any links matching a and b.

This sets the min and max to the same value eliminating any variance in latency.

Set the max message latency for any links matching a and b.

Source

pub fn set_message_latency_curve(&self, value: f64)

Set the message latency distribution curve for all links.

Message latency follows an exponential distribution curve. The value is the lambda argument to the probability function.

Source

pub fn set_fail_rate(&mut self, value: f64)

Access a LinksIter to introspect inflight messages between hosts.

Source

pub fn run(&mut self) -> Result

Run the simulation until all client hosts have completed.

Executes a simple event loop that calls step each iteration, returning early if any host software errors.

Source

pub fn step(&mut self) -> Result<bool>

Step the simulation.

Runs each host in the simulation a fixed duration configured by tick_duration in the builder.

The simulated network also steps, processing in flight messages, and delivering them to their destination if appropriate.

Returns whether or not all clients have completed.

Auto Trait Implementations§

§

impl<'a> !Freeze for Sim<'a>

§

impl<'a> !RefUnwindSafe for Sim<'a>

§

impl<'a> !Send for Sim<'a>

§

impl<'a> !Sync for Sim<'a>

§

impl<'a> Unpin for Sim<'a>

§

impl<'a> !UnwindSafe for Sim<'a>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more