I’m playing with simulating large delays and throttling bandwidth to emulate less than ideal Wide Area Network (WAN) links on my network(s) at home. This is mainly to support my remote radio project where I’m starting to look at operating a radio across the Internet… rather than driving over to my friend’s house every time I want to test the system it’s much easier if I can simulate the Internet link with a test network and some WAN emulation!
<insert simple diagram of test networks connected via routers and WAN emulator>
A very low cost and (potentially) simple way of introducing network delays, jitter, losses and bandwidth limits is to run OpenWRT firmware on a spare router and configure it using the “tc” command and a feature called “netem” which is included in the Linux kernel within OpenWRT. I’ve installed OpenWRT 15 on a spare Western Digital MyNet n750 router but I’ve also acquired a dinky little GL-inet AR-300M mini router that comes with OpenWRT installed from the factory.
There are a few web pages that describe some basic tc commands to get you going with packet delays and a few others have published scripts to provide a slicker interface but I struggled to get these working for a long time until I stumbled upon a solution… hopefully this bit may help someone from going round in circles like I did.
The basic command to begin a 100ms delay on the eth0 interface goes like this:
tc qdisc add dev eth0 root netem delay 100ms
…and the antidote (to delete any such delay you may have already running) goes like:
tc qdisc del dev eth0 root
…but every time I tried it (or any variation guided by many many websites) I kept getting this error message:
root@GL-AR300M:~# tc qdisc add dev eth0 root netem delay 100ms RTNETLINK answers: No such file or directory
For me at least, this was the fix… entering “modprobe sch_netem” (i.e. explicitly loading the netem module) kicks netem into action and from then on it behaves as described on all the websites I’d read:
root@GL-AR300M:~# tc qdisc add dev eth0 root netem delay 100ms 10ms 25% RTNETLINK answers: No such file or directory root@GL-AR300M:~# modprobe sch_netem root@GL-AR300M:~# tc qdisc add dev eth0 root netem delay 100ms 10ms 25% root@GL-AR300M:~# tc -s qdisc qdisc netem 8001: dev eth0 root refcnt 2 limit 1000 delay 100.0ms 10.0ms 25% Sent 2996 bytes 15 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0
The “tc -s qdisc” command is just run to show that there is now a netem process (8001) running… Success!! I can now introduce packet delays into traffic passing through the OpenWRT mini router.
Next steps are to do as others have done and build a script to make the implementation a bit slicker…