Making a bad internet box


#1

Bad internet box running Althea

If you intend to test Althea you probably want at least one ‘bad internet’ box.

What we’re going to do is install ‘netem’ (network emulator) on a althea router and then use that to make the router drop packets or add latency.

Sadly kmod-netem is a kernel module, which makes installing it against our firmware quite difficult unless build the firmware with it.

Clone the althea firmware repo, and then before you start edit the config for the device your interested in. Replace glb1300 with whatever device config are you working on.

git clone althea-firmware

if you are testing the latest release you’ll need to run this. For specific releases checkout their tag. If you want to test master ignore this next line.

git checkout origin/release
cd althea-firmware
echo "CONFIG_PACKAGE_kmod-netem=y" >> config/glb1300

Next build and install the firmware. If you have the router steup so that your machine can ssh into it this script will login and upload the firmware for you. If not grab the results from build/bin/ and flash however you like.

ansible-playbook -e @profiles/devices/glb1300.yml -e @profiles/management/althea-release.yml build-and-upgrade.yml

Now that the router is flashed with a firmware containing netem it’s time to actually set it up. Login and run the following.

We need to delete the cake qdisk that’s currently in control of the router. After that we can add netem with our own parameters.

tc qdisc del dev eth0
tc qdisc add dev eth0 root netem delay 100ms

So now we’ve added 100ms latency, but what about packet loss or jitter? This adds 100ms of latency ± 10ms of jitter, with 25% packet loss. You can refer here for more examples. A really good test would go even further and use this guide to include duplication, corruption, and out of order packets in testing.

tc qdisc change dev eth0 root netem delay 100ms 10ms 25%

Take note that you must del the default qdisk then add a new one using netem, after that you can change it.

a footnote on interface names:

note that I used eth0 in this example, you can repeat this example on different interfaces, but beware eth0.5 is really the vlan5 of eth0 so you’ll probably just want to edit eth0. This may modify one port or all ports on a device depending on the port layout. The N750 for example only has one port attached to a switch, so loss is always added to every port. Netem only works on outgoing traffic so keep in mind that incoming will always be good unless you put a device running netem north.


#2

Forever reusable general purpose bad internet box

What we’re going to do is install ‘netem’ (network emulator) on a sock openwrt and then we’ll bridge the ports to make two ports pretend as if they are invisible. If you have a device with more ports (like the erx) you can bridge them twice.

flash stock openwrt on your router then plug in the wan port, login via the lan port and run the following using ssh.

opkg update
opkg install kmod-netem
reboot

Next we need to setup the port bridging. Go into the config and isolate ports as needed (you may wish to look at the Althea firmware repo for vlan isolation advice) then use brctl to bridge two ports of your choice.

You may want to look at the Althea /etc/config/network templates in order to isolate ports. You can just copy the Althea template for the device and then bridge the ‘mesh’ ports (denoted rita_portName).

brctl addbr br0
brctl addif br0 ethA 
brctl addif br0 ethB

Now that the router has netem it’s time to actually set it up. Login and run the following.

We need to delete the pfifo_fast qdisk that’s currently in control of the router. After that we can add netem with our own parameters.

tc qdisc del dev br0
tc qdisc add dev bro0 root netem delay 100ms

So now we’ve added 100ms latency, but what about packet loss or jitter? This adds 100ms of latency ± 10ms of jitter, with 25% packet loss. You can refer here for more examples. A really good test would go even further and use this guide to include duplication, corruption, and out of order packets in testing.

tc qdisc change dev br0 root netem delay 100ms 10ms 25%

Take note that you must del the default qdisk then add a new one using netem, after that you can change it.

The bridges and netem commands in this guide are not permanent so you’ll have to run everything from the bridge step down every time you reboot.

a footnote on interface names:

note that I used eth0 in this example, you can repeat this example on different interfaces, but beware eth0.5 is really the vlan5 of eth0 so you’ll probably just want to edit eth0. This may modify one port or all ports on a device depending on the port layout. The N750 for example only has one port attached to a switch, so loss is always added to every port. Netem only works on outgoing traffic so keep in mind that incoming will always be good unless you put a device running netem north.