Friday, January 30, 2009

Simulating Network Delay Using Linux

In a previous blog post I documented how to create a router using Linux:
http://purefinity.blogspot.com/2008/10/making-linux-router-or-gateway.html

Now that we have that setup, we can use it to emulate WAN latency using netem. If you're running a 2.6 kernel you should already have it installed.

Keep in mind that this only works for outbound traffic, so choose your network interface accordingly.

To add 100ms to all outbound traffic on eth0
tc qdisc add dev eth0 root netem delay 100ms

To check status
tc -s qdisc

To remove the delay from eth0
tc qdisc del dev eth0 root

You can also use netem to simulate packet loss, variable delay and rate control. For more information on netem:
http://www.linuxfoundation.org/en/Net:Netem

If you're looking for an easy to use tool to test throughput and latency that is more sophisticated than ping, I recommend QCheck. You can install it on two Windows machines and test between those two points, or install QCheck on a Windows machine and an Ixia Endpoint on a Linux machine. Both QCheck and the Endpoint were available for free at the time this article was written.
http://www.ixchariot.com/downloads.html

I would like to note that my first choice to emulate network latency was to use tcmon from the Windows resource kit, but I quickly found the tool to be poorly documented, unsupported on Windows Server 2003, and only provided rate control on Windows XP. It's sad when a command line tool for Linux is simpler and easier to use than a GUI tool from Microsoft.