Simulating Delay and Packet Loss

When using a Wifi network at home for voice telephony everything’s great and shiny as long as there is enough bandwidth for the call. But when you are stuck on a Wifi connected to a slow DSL line that has only little uplink capacity and someone else on the network starts uploading cat images, things get ugly quickly. Recently I was looking into how to simulate delay and packet loss to find out how a voice call sounds over Wifi and to my surprise this is actually quite easy to do, even if you don’t have a slow DSL line available.

The only thing that’s needed is a Linux box with root and shell access between the Wifi and the backhaul. A Raspberry Pi acting as a Wifi hotspot, for example, will do the trick. On the box, delay and packet loss can be generated with a few simple commands:

Packet Loss

# use 'add' the first time and 'change' for 
# subsequent tc commands
sudo tc qdisc add dev eth0 root netem loss 0%

# 30% packet loss
sudo tc qdisc change dev eth0 root netem loss 30%

Delay

# 500ms delay
sudo tc qdisc change dev eth0 root netem delay 500ms 20ms distribution normal

# Delay AND Loss (must be in one line as setting 
# each one individually deletes the previous setting

sudo tc qdisc change dev eth0 root netem delay 1000ms 20ms distribution normal loss 30%

While delay itself has no impact on the sound quality, a delay of 1000ms significantly impacts a conversation as responses from the other end take quite some time to arrive. On the packet loss side, 10% are hardly noticeable with some codecs, which I found quite interesting. After that, things deteriorate quickly, however. When 30% of the speech packets are lost it’s pretty difficult to understand the other end.

Also interesting to note is how an SSH session behaves when delay and packet loss are introduced on a line.

For more details on the commands have a look here.