Struct smoltcp::phy::FaultInjector

source ·
pub struct FaultInjector<D: Device> { /* private fields */ }
Expand description

A fault injector device.

A fault injector is a device that alters packets traversing through it to simulate adverse network conditions (such as random packet loss or corruption), or software or hardware limitations (such as a limited number or size of usable network buffers).

Implementations§

source§

impl<D: Device> FaultInjector<D>

source

pub fn new(inner: D, seed: u32) -> FaultInjector<D>

Create a fault injector device, using the given random number generator seed.

source

pub fn into_inner(self) -> D

Return the underlying device, consuming the fault injector.

source

pub fn corrupt_chance(&self) -> u8

Return the probability of corrupting a packet, in percents.

source

pub fn drop_chance(&self) -> u8

Return the probability of dropping a packet, in percents.

source

pub fn max_packet_size(&self) -> usize

Return the maximum packet size, in octets.

source

pub fn max_tx_rate(&self) -> u64

Return the maximum packet transmission rate, in packets per second.

source

pub fn max_rx_rate(&self) -> u64

Return the maximum packet reception rate, in packets per second.

source

pub fn bucket_interval(&self) -> Duration

Return the interval for packet rate limiting, in milliseconds.

source

pub fn set_corrupt_chance(&mut self, pct: u8)

Set the probability of corrupting a packet, in percents.

Panics

This function panics if the probability is not between 0% and 100%.

source

pub fn set_drop_chance(&mut self, pct: u8)

Set the probability of dropping a packet, in percents.

Panics

This function panics if the probability is not between 0% and 100%.

source

pub fn set_max_packet_size(&mut self, size: usize)

Set the maximum packet size, in octets.

source

pub fn set_max_tx_rate(&mut self, rate: u64)

Set the maximum packet transmission rate, in packets per interval.

source

pub fn set_max_rx_rate(&mut self, rate: u64)

Set the maximum packet reception rate, in packets per interval.

source

pub fn set_bucket_interval(&mut self, interval: Duration)

Set the interval for packet rate limiting, in milliseconds.

Trait Implementations§

source§

impl<D: Debug + Device> Debug for FaultInjector<D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<D: Device> Device for FaultInjector<D>

§

type RxToken<'a>
where
Self: 'a
= RxToken<'a>

§

type TxToken<'a>
where
Self: 'a
= TxToken<'a, <D as Device>::TxToken<'a>>

source§

fn capabilities(&self) -> DeviceCapabilities

Get a description of device capabilities.
source§

fn receive(
&mut self,
timestamp: Instant
) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>

Construct a token pair consisting of one receive token and one transmit token. Read more
source§

fn transmit(&mut self, timestamp: Instant) -> Option<Self::TxToken<'_>>

Construct a transmit token. Read more

Auto Trait Implementations§

§

impl<D> RefUnwindSafe for FaultInjector<D>where
D: RefUnwindSafe,

§

impl<D> Send for FaultInjector<D>where
D: Send,

§

impl<D> Sync for FaultInjector<D>where
D: Sync,

§

impl<D> Unpin for FaultInjector<D>where
D: Unpin,

§

impl<D> UnwindSafe for FaultInjector<D>where
D: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · 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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.