Wednesday, May 25, 2011

Network Emulation and Artificial Delay/Packet Loss/etc

Network emulation has always been a major issue for researchers. Let's say you are implementing a system/application and you want to know how does it cope with network "stressing".

Or you may want to provide various information about the QoS of a protocol or application.



Back in the days Linux programmers used netfilter hooks (in the Linux Kernel network stack) to intervene with the kernel packet forwarding procedure. They afterwards dropped manually some packets to emulate a packet loss.

In the 2.6 Linux Kernel major release a new tool was added. Netem .

NetEm (Network Emulator) is a handy networking tool that emulates variable delay, loss, duplication and re-ordering.


If you are using a 2.6 distribution, odds are that the netem kernel component is already installed.

How Do I Use It


netem is invoked through the cli tool tc

  • Add delay


This command adds a fixed amount of delay on all packets sent by eth0 interface

.

We can also "randomize" the delay by adding a random deviation from our initial delay.

The delay now is 100+= 10ms

There is also a distribution model to match the delay of real WAN's


  • Induce artificial packet loss


>We often want to measure how our application handles lost packets. TCP is pretty much handled by more lower system operations, but UDP is often used to transmit live data such as streaming and QoS is mostly application-dependent . One way to stress test is this:


This causes a 0.3% of outgoing packets to be dropped (that's 3 out of 1000 packets).

Netem also handles Packet duplication, corruption (introduced in 2.6.16 kernel), reordering and can also be used for rate control.

1 comment: