Skip to main content

VirtualSwitch

Struct VirtualSwitch 

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

In-process learning Layer-2 Ethernet switch linking multiple unkernel-rs VMs.

Implementations§

Source§

impl VirtualSwitch

Source

pub fn new(name: impl Into<String>) -> Arc<Self> ⓘ

Create a new virtual L2 Ethernet switch (e.g. "switch0").

Source

pub fn name(&self) -> &str

Source

pub fn attach_pcap(&self, file: File) -> Result<()>

Attach a pre-opened host file for Wireshark-compatible PCAPng capture of all L2 frames.

Source

pub fn add_port( self: &Arc<Self>, node_name: impl Into<String>, mac: [u8; 6], ip: [u8; 4], raise_irq: Arc<dyn Fn() + Send + Sync>, uplink: Option<Arc<NetStack>>, ) -> Arc<SwitchPort> ⓘ

Register a VM port on this switch and return a NetDevice handle for the guest NIC.

Source

pub fn allocate_identity(index: usize) -> ([u8; 6], [u8; 4])

Deterministically assign a unique guest MAC (52:54:00:00:00:XX) and IPv4 (10.0.2.10+idx).

Simulate unplugging a node’s Ethernet cable (drops all TX/RX frames on that port).

Reconnect a previously cut port cable.

Source

pub fn set_drop_rate(&self, node: &str, pct: u8) -> bool

Configure simulated packet loss (0..=100 percent) on a node’s switch port.

Source

pub fn set_delay_ms(&self, node: &str, ms: u64) -> bool

Configure simulated one-way delivery latency in milliseconds on a node’s switch port.

Source

pub fn port_stats(&self) -> Vec<SwitchPortStats>

Snapshot live per-port statistics and chaos settings.

Source

pub fn mac_table(&self) -> Vec<MacTableEntry>

Snapshot the switch’s learned L2 MAC forwarding table.

Source

pub fn total_frames(&self) -> u64

Total Ethernet frames switched across all ports.

Source

pub fn flush_pcap(&self)

Flush the PCAPng capture file (if attached).

Deliver an uplink NAT reply frame back into a port (recording it in PCAPng and honoring link-cut / drop / delay state).

Auto Trait Implementations§

§

impl !Freeze for VirtualSwitch

§

impl Forget for VirtualSwitch

§

impl Move for VirtualSwitch

§

impl RefUnwindSafe for VirtualSwitch
where Mutex<SwitchInner>: RefUnwindSafe, Atomic<u64>: RefUnwindSafe,

§

impl Send for VirtualSwitch
where RawVecInner: Send, Mutex<SwitchInner>: Send, Atomic<u64>: Send,

§

impl Sync for VirtualSwitch
where RawVecInner: Sync, Mutex<SwitchInner>: Sync, Atomic<u64>: Sync,

§

impl Unpin for VirtualSwitch
where *const u8 is !null: Unpin, Align4<u32>: Unpin, Align1<u8>: Unpin, Arc<dyn Fn() + Send + Sync>: Unpin, Arc<NetStack>: Unpin, I32NotAllOnes: Unpin, Align8<u64>: Unpin,

§

impl UnsafeUnpin for VirtualSwitch
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, Align4<u32>: UnsafeUnpin, Align1<u8>: UnsafeUnpin, PhantomData<PortInner>: UnsafeUnpin, PhantomData<([u8; 6], usize)>: UnsafeUnpin, I32NotAllOnes: UnsafeUnpin, Align8<u64>: UnsafeUnpin,

§

impl UnwindSafe for VirtualSwitch
where RawVecInner: UnwindSafe, Mutex<SwitchInner>: UnwindSafe, Align8<u64>: UnwindSafe,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.