Degrade the network your DUT is on, rather than removing it
Drive a MikroTik router as a Lager net. This is the bench’s network fault-injection
tool. It lets a test assert what firmware does when the network degrades — loses
the internet, loses DNS, gets slow — rather than simply disappearing.
Handle
use lager::LagerBox;let lager = LagerBox::from_env()?;let router = lager.router("router1");
pub struct RouterSystemInfo { pub name: Option<String>, // identity pub version: Option<String>, // RouterOS version pub board: Option<String>, pub architecture: Option<String>, pub uptime: Option<String>, // e.g. "1w2d3h" pub cpu_load: Option<i64>, // percent pub free_memory: Option<i64>, // bytes pub total_memory: Option<i64>, pub free_hdd_space: Option<i64>, pub extra: Map<String, Value>, // any other field the router sends}
SecurityProfile
The profile that create_security_profile() creates. A field left None takes the box’s
default: dynamic-keys, wpa2-psk, aes-ccm and empty keys.
Field
Description
name
Profile name
mode
RouterOS mode ("dynamic-keys", "none", …)
authentication_types
"wpa2-psk", "wpa-psk,wpa2-psk", …
unicast_ciphers
"aes-ccm", "tkip,aes-ccm", …
wpa2_pre_shared_key, wpa_pre_shared_key
Passphrases
SecurityProfile::wpa2(name, passphrase) builds a WPA2-PSK profile with the box’s defaults
for the rest.
AccessListEntry
The entry that add_access_list_entry() adds.
Field
Description
mac_address
Client MAC address
authentication
Some(false) rejects the client. The box defaults to true
interface
Limit the entry to one wireless interface
signal_range
RouterOS signal range, for example "-80..120"
Method Reference
connect() -> Result<serde_json::Value>
Verify connectivity by fetching the router’s identity.
system_info() -> Result<RouterSystemInfo>
Structured resource information.
block_internet() -> Result<()>
Drop all forwarded traffic, simulating an internet outage while leaving the local
network — and the DUT’s association to it — intact.
remove_firewall_rules() -> Result<()>
Remove every firewall rule Lager added. This is the undo for block_internet and
anything added through command().
Rules persist on the router until removed. A test that blocks the internet and then
fails without cleaning up leaves the next test running on a broken network. Put
remove_firewall_rules() in a teardown path that runs even on failure.
enable_interface(interface: &str) and disable_interface(interface: &str)
Enable or disable an interface by name — use these when you want the access point to
vanish entirely, rather than to lose routing.
The generic escape hatch: invoke any other router action by name with raw JSON
parameters. Every action this page lists has a typed method, so use this only for an
action a newer box adds.
A read-only GET /rest<path> call, such as "/ip/address"
Examples
Assert firmware retries instead of rebooting when the internet goes away
use lager::LagerBox;use std::time::Duration;let lager = LagerBox::from_env()?;let router = lager.router("router1");let mut uart = lager.uart("uart1")?;router.connect()?;let outcome = (|| -> lager::Result<()> { router.block_internet()?; // The DUT stays on the AP; only routing is gone. let log = uart.wait_for(b"retry", Duration::from_secs(60))?; assert!(!String::from_utf8_lossy(&log).contains("rebooting"), "firmware rebooted instead of retrying"); Ok(())})();router.remove_firewall_rules()?; // always, even if the assertion failedoutcome?;
Squeeze the bandwidth and check an OTA still completes
router.add_bandwidth_limit("192.168.88.50", "256k/256k", None)?;// ... trigger the OTA and wait for it ...router.remove_bandwidth_limits()?;
Supported Hardware
Device
Notes
MikroTik RouterOS devices
Driven over the RouterOS REST API
Notes
This net sends no role hint. A router net can be saved with role router or
the legacy mikrotik. The box verifies a supplied hint exactly, so a hint will fail
against whichever spelling the net does not use. A consequence you will see: a
missing router net reports Net 'router1' not found without naming a role, where
other net types
report Net 'x (role adc)' not found.
Every router action gets a flat 60-second budget, because reboots and reset actions
are slow and a busy router lags.
reboot() returns as soon as the router accepts the command, not when it is back.
Blocking the internet does not disconnect the DUT from WiFi. That distinction is
the entire point of this net type.