Hi all,
What is wanctl?
wanctl is a host-side controller that connects to RouterOS and adjusts CAKE queue bandwidth limits every ~2 seconds based on measured congestion.
It assumes CAKE is already configured correctly on RouterOS and operates on top of it by dynamically tuning bandwidth limits within defined bounds.
Optional support exists for multi-WAN traffic steering during severe congestion.
Why this exists
Static CAKE bandwidth limits are always a compromise:
-
Too high → queue growth and latency under load
-
Too low → unused capacity when the link is clean
On variable-rate links (especially DOCSIS), available throughput changes throughout the day, and manual tuning can’t keep up.
wanctl attempts to adapt CAKE bandwidth limits in real time using measured signals instead of fixed values.
How it works (concrete)
Every ~2 seconds, wanctl:
-
Measures RTT to multiple reference hosts (1.1.1.1, 8.8.8.8, 9.9.9.9)
-
Maintains a slow EWMA baseline RTT (updated only when idle)
-
Computes RTT delta = loaded RTT − baseline RTT
-
Evaluates congestion using:
-
RTT delta
-
CAKE drops
-
Queue depth / backlog indicators
-
-
Transitions a state machine
-
Adjusts CAKE queue bandwidth limits accordingly
-
Enforces state-dependent bandwidth floors
Communication with RouterOS is via SSH (API support is optional, depending on config).
State Machine
wanctl uses a four-state congestion model:
delta ≤ 15ms
┌─────────────────────────┐
│ │
▼ 15–45ms │
GREEN ───────────────► YELLOW
▲ │
│ 45–80ms ▼
│ ┌───────────── SOFT_RED
│ │ │
│ │ >80ms ▼
└─────┴───────────────── RED
(recovery requires
sustained GREEN)
State-dependent bandwidth floors
These prevent bandwidth collapse during congestion:
-
GREEN: High floor (e.g. ~550 Mbps)
-
YELLOW: Moderate floor (e.g. ~350 Mbps)
-
SOFT_RED: Aggressive floor (e.g. ~275 Mbps)
-
RED: Emergency floor (e.g. ~200 Mbps)
All thresholds and floors are configurable via YAML.
Real-World Test: Second-by-Second Behavior
The following is actual output from a stress test on a 940/38 Mbps Spectrum DOCSIS connection.
Eight parallel netperf streams were used to induce congestion.
Time State Delta Upload BW RTT Event
────────────────────────────────────────────────────────────────
00:00:37 GREEN/GREEN 2.2ms 38M 26ms Idle baseline
00:00:44 GREEN/GREEN 10.8ms 38M 70ms Load increasing
00:00:52 YELLOW/RED 62.6ms 34M 295ms Congestion detected
00:00:59 YELLOW/RED 60.8ms 31M 79ms Backing off upload
00:01:06 SOFT_RED/RED 47.9ms 28M 21ms Continued reduction
00:01:18 YELLOW/YELLOW 29.3ms 28M 21ms Recovering
00:01:31 YELLOW/YELLOW 17.9ms 28M 22ms Almost recovered
00:01:56 GREEN/GREEN 7.1ms 28M 26ms Fully recovered
Observed behavior:
-
RTT spiked from ~26 ms to ~295 ms under load
-
wanctl reduced upload shaping from 38 Mbps → 28 Mbps (~26%)
-
RTT delta fell back under 10 ms
-
System returned to GREEN without user intervention
-
Bandwidth then recovers gradually while remaining GREEN
The entire event completed in under ~90 seconds.
Production Observations (18 Days)
Single RouterOS rb5009, Spectrum 940/38, wanctl enabled.
Monitoring Period: Dec 11–28, 2025
Control Interval: ~2 seconds
Total Cycles: 231,208
Log Data: ~488 MB
Download state distribution
-
GREEN: 89.3%
-
YELLOW: 7.8%
-
SOFT_RED: 0.7%
-
RED: 2.2%
Mean RTT delta across the period was ~4.7 ms, with p95 ~10.2 ms.
This is observational data from one environment, not a claim of universal results.
Multi-WAN Steering (Optional)
For dual-WAN setups, wanctl can optionally enable policy-based steering of latency-sensitive traffic during severe congestion.
-
Steered: VoIP, gaming, DNS, SSH, interactive traffic
-
Not steered: bulk downloads, streaming, background traffic
Steering uses the same congestion signals with hysteresis to prevent flapping.
What this is / is not
Is:
-
External CAKE bandwidth controller
-
Config-driven and explicit
-
Designed for RouterOS 7.x
-
Intended for power users
Is not:
-
A RouterOS script
-
A replacement for proper queue placement
-
A guarantee of zero bufferbloat
-
Enterprise-grade software
RC status & feedback
This is my first open-source project and a release candidate.
The structure and behavior are stable in my environment, but I’m looking for:
-
Review from RouterOS power users
-
Feedback on thresholds and state logic
-
Edge cases on non-DOCSIS links
-
Bugs I haven’t encountered
Issues and PRs are welcome.
— Kevin