Bridges and Impairments
Provium's networking is real Linux bridges with TAP attachments. You declare a topology, the harness realizes it as the VMs boot, and you can mutate it (partition, impair, capture) at runtime.
The exhaustive method reference is on Bridge and Nic.
Declared and realized #
Provium tracks resources in two layers: the resource graph records what a test
has declared (bridges, attachments, partitions, impairments), and the harness
separately realizes that graph on the host, bridge interfaces, TAPs, tc
qdiscs, nft rules, QMP calls, once the backing pieces exist, typically when an
attached VM boots. A call marked graph-state only updates the declared
graph without touching the host: it's recorded and visible to inspection
methods, but on its own it doesn't change anything real.
Wiring up #
local lan = provium:
local a = provium::
local b = provium::
lan: -- atomic; either all attach or none do
a:
b:
-- a can reach b.
a::
bridge:attach takes a single VM or an array (validated atomically, a bad
element fails before anything is recorded). The bare-string form and its
graph-state-only caveat are in the
Bridge reference.
The host-side bridge interface and per-VM TAPs come up the first time any attached VM boots.
Multi-bridge topologies #
local mgmt = provium:
local data = provium:
local a = provium::
local b = provium::
mgmt: -- both VMs on mgmt
data: -- both VMs on data too
-- a:nic("mgmt") and a:nic("data") return separate Nic handles.
local mgmt_nic = a:
local data_nic = a:
Inside the guest, each NIC shows up as a separate interface. The mapping from
bridge name to guest-side interface name (eth0, eth1, …) is determined by
attachment order sorted by bridge name. For portable tests, prefer
vm:nic("mgmt") (by bridge name) over vm:nic("eth0") (by guest-name index).
Partitions #
A partition is a network-layer drop between two specific VMs. Two flavors:
Symmetric #
lan: -- A↔B traffic dropped both ways
lan: -- restore
Symmetric partitions are graph-state, they install drop rules at boot through nft and lift cleanly.
Directional #
lan: -- only A→B dropped; B→A still flows
lan:
Directional partitions install per-TAP nft rules and require both endpoints
to be already attached and booted, otherwise they error with a "call
bridge:attach first" pointer. The (more lenient) unpartition semantics are
in the Bridge reference.
Whole-bridge #
lan: -- every pair partitioned
lan: -- every partition lifted
Inspect #
if lan:
Impairments #
Three knobs: latency, drop rate, bandwidth limit. Each accepts either a scalar (whole-bridge) or a directional table.
Latency #
lan: -- 50 ms one-way to every flow
lan: -- 50 ms recorded for A→B
Implemented as netem qdiscs. A directional impairment is recorded per
(from, to) pair but realized per source: each VM's outbound pairs
collapse into one qdisc chain on its own TAP, taking the worst case across its
pairs, so in practice the {from = a, to = b} latency above delays everything
leaving a, not only its traffic to b. The endpoint attachment check
applies (same as directional partitions).
Drop rate #
lan: -- ~10 % loss, both ways
lan: -- recorded for A→B
Bandwidth limit #
lan: -- 1 Mbit/s, both ways
lan: -- 500 kbit/s leaving A
The number is bits per second, not bytes, matches tc rate Nbit. Two
realization caveats matter when you design a test: the directional form shapes
every packet leaving the source TAP (not only traffic to the named to), and
whole-bridge bandwidth is not enforced while whole-bridge latency/drop is also
set, for combined shaping use the directional form on each source. The full
realization details (TBF and HTB, max(bps) collapse across pairs) are in the
Bridge reference.
Combine directional bandwidth with directional latency / drop on the same source for a complete profile:
lan:
lan:
lan:
Reset #
lan: -- tear down every netem/tbf qdisc, clear every partition
reset is a clean way to go back to "default" without enumerating every
impairment you applied. Isolation, uplink, and L3 routes survive a reset,
they're topology, not impairments.
Inspect #
lan: -- current whole-bridge latency
lan: -- current whole-bridge drop rate
lan: -- current whole-bridge bandwidth cap
These return the last applied whole-bridge value. They don't enumerate per-direction impairments.
Isolation #
Isolation puts one VM behind a hairpin filter, it can't reach any other VM on the bridge, but the bridge stays up:
lan:
local r = a:
-- r:ok() is false; a is isolated
lan:
a::
lan:is_isolated(vm) returns true if the VM is isolated.
NICs #
local nic = a: -- by bridge name
local nic = a: -- by guest-name index
local nic = lan: -- equivalent
The Nic gives you per-NIC capabilities the bridge can't. The ones you'll use most:
nic: -- per-NIC traffic counters, guest's perspective
nic: -- link-down via QMP set_link(false)
nic: -- link-up
disconnect / reconnect drive QMP set_link so the guest sees a real
link-down event. The full method list, the counter field table (and its
guest-perspective mapping), and the graph-state-only bare-string case are in
the Nic reference.
Packet capture #
Two scopes:
Bridge-wide capture #
local cap = lan:
a:
local frames = cap:
local pcap = table.
-- pcap is now standard pcap-format bytes, parseable by tshark, etc.
bridge:capture() returns a Capture stream of
pcap-format bytes. It requires tcpdump on PATH, and a live capture blocks
vm:snapshot() (no half-captured pcap), capability requirements and the
mechanism are in the
Bridge reference.
Per-NIC capture #
local nic = a:
local cap = nic: -- captures only A's TAP, not the whole bridge
Useful when multiple VMs are on the bridge and you only want one VM's perspective.
nic:capture() errors if the VM hasn't been booted yet (the per-VM TAP
doesn't exist):
nic:capture: vm `a` has no TAP on bridge `lan` (not booted?). Call lab:boot() / vm:boot() first.
Uplink (NAT to the outside world) #
lan:
vm::
lan:
enable_uplink installs an nft NAT masquerade rule between the bridge and the
host's default-route interface. Failures (for example no default-route
interface) error with the underlying detail.
L3 routing (preview) #
lan:
bridge:route records the routing intent in the graph but installs no nft
forward rules in v1, cross-bridge IP traffic does not actually flow yet, and
the first call per bridge prints a one-shot warning saying so.
bridge:routes() returns the recorded routes. Plan tests around the
limitation. See the
Bridge reference.
Common patterns #
Test split-brain recovery #
test
Test latency-sensitive code #
test
Test packet loss tolerance #
test
Inspect packet flow with capture #
test
See also #
- Bridge reference: every method on the Bridge userdata.
- Nic reference: per-NIC handle.
- Streams reference: what
bridge:capture()andnic:capture()return.