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.
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.
The generic escape hatch: invoke any other router action by name with raw JSON
parameters. This is how you reach DNS blocking, port blocking, bandwidth limits,
DHCP control, security profiles and access lists. None of these have a typed wrapper
in this crate yet.
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
use serde_json::json;router.command("add_bandwidth_limit", json!({ "target": "192.168.88.50", "max_limit": "256k/256k",}))?;// ... trigger the OTA and wait for it ...router.command("remove_bandwidth_limits", json!({}))?;
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.