pub struct VirtualSwitch { /* private fields */ }Expand description
In-process learning Layer-2 Ethernet switch linking multiple unkernel-rs VMs.
Implementations§
Source§impl VirtualSwitch
impl VirtualSwitch
Sourcepub fn new(name: impl Into<String>) -> Arc<Self> ⓘ
pub fn new(name: impl Into<String>) -> Arc<Self> ⓘ
Create a new virtual L2 Ethernet switch (e.g. "switch0").
pub fn name(&self) -> &str
Sourcepub fn attach_pcap(&self, file: File) -> Result<()>
pub fn attach_pcap(&self, file: File) -> Result<()>
Attach a pre-opened host file for Wireshark-compatible PCAPng capture of all L2 frames.
Sourcepub 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> ⓘ
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.
Sourcepub fn allocate_identity(index: usize) -> ([u8; 6], [u8; 4])
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).
Sourcepub fn cut_link(&self, node: &str) -> bool
pub fn cut_link(&self, node: &str) -> bool
Simulate unplugging a node’s Ethernet cable (drops all TX/RX frames on that port).
Sourcepub fn reconnect_link(&self, node: &str) -> bool
pub fn reconnect_link(&self, node: &str) -> bool
Reconnect a previously cut port cable.
Sourcepub fn set_drop_rate(&self, node: &str, pct: u8) -> bool
pub fn set_drop_rate(&self, node: &str, pct: u8) -> bool
Configure simulated packet loss (0..=100 percent) on a node’s switch port.
Sourcepub fn set_delay_ms(&self, node: &str, ms: u64) -> bool
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.
Sourcepub fn port_stats(&self) -> Vec<SwitchPortStats>
pub fn port_stats(&self) -> Vec<SwitchPortStats>
Snapshot live per-port statistics and chaos settings.
Sourcepub fn mac_table(&self) -> Vec<MacTableEntry>
pub fn mac_table(&self) -> Vec<MacTableEntry>
Snapshot the switch’s learned L2 MAC forwarding table.
Sourcepub fn total_frames(&self) -> u64
pub fn total_frames(&self) -> u64
Total Ethernet frames switched across all ports.
Sourcepub fn flush_pcap(&self)
pub fn flush_pcap(&self)
Flush the PCAPng capture file (if attached).
Auto Trait Implementations§
impl !Freeze for VirtualSwitch
impl Forget for VirtualSwitch
impl Move for VirtualSwitch
impl RefUnwindSafe for VirtualSwitch
impl Send for VirtualSwitch
impl Sync for VirtualSwitch
impl Unpin for VirtualSwitch
impl UnsafeUnpin for VirtualSwitchwhere
*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
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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