pub struct Sim<'a> { /* private fields */ }Expand description
Network simulation
Implementations
sourceimpl<'a> Sim<'a>
impl<'a> Sim<'a>
sourcepub fn client<F>(&mut self, addr: impl ToIpAddr, client: F)where
F: Future<Output = Result> + 'static,
pub fn client<F>(&mut self, addr: impl ToIpAddr, client: F)where
F: Future<Output = Result> + 'static,
Register a client with the simulation.
sourcepub fn host<F, Fut>(&mut self, addr: impl ToIpAddr, host: F)where
F: Fn() -> Fut + 'a,
Fut: Future<Output = ()> + 'static,
pub fn host<F, Fut>(&mut self, addr: impl ToIpAddr, host: F)where
F: Fn() -> Fut + 'a,
Fut: Future<Output = ()> + '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.
sourcepub fn crash(&mut self, addr: impl ToIpAddr)
pub fn crash(&mut self, addr: impl ToIpAddr)
Crash a host. Nothing will be running on the host after this method. You
can use Sim::bounce to start the host up again.
sourcepub fn set_max_message_latency(&self, value: Duration)
pub fn set_max_message_latency(&self, value: Duration)
Set the max message latency
pub fn set_link_max_message_latency(
&self,
a: impl ToIpAddr,
b: impl ToIpAddr,
value: Duration
)
sourcepub fn set_message_latency_curve(&self, value: f64)
pub fn set_message_latency_curve(&self, value: f64)
Set the message latency distribution curve.
Message latency follows an exponential distribution curve. The value
is the lambda argument to the probability function.
pub fn set_fail_rate(&mut self, value: f64)
pub fn set_link_fail_rate(
&mut self,
a: impl ToIpAddr,
b: impl ToIpAddr,
value: f64
)
sourcepub fn run(&mut self) -> Result
pub fn run(&mut self) -> Result
Run the simulation until all clients finish.
For each runtime, we [Rt::tick] it forward, which allows time to
advance just a little bit. In this way, only one runtime is ever active.
The turmoil APIs operate on the active host, and so we remember which
host is active before yielding to user code.
If any client errors, the simulation returns early with that Error.