smoltcp::phy

Struct 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>

Source§

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

Source§

type TxToken<'a> = TxToken<'a, <D as Device>::TxToken<'a>> where Self: '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> Freeze for FaultInjector<D>
where D: Freeze,

§

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§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

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

Performs the conversion.
§

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

§

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

The type returned in the event of a conversion error.
§

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

Performs the conversion.