Add delay on packet using TC
netem provides Network Emulation functionality for testing protocols by emulating the properties of wide area networks. The current version emulates variable delay, loss, duplication and re-ordering.
TC(Traffic Control) is a Linux command to configure the Linux kernel's Network scheduler to show and manipulate Network traffic control settings.
Traffic Control consists of the following:
SHAPING
SCHEDULING
POLICING
Processing of traffic is controlled by three kinds of objects: qdiscs, classes and filters
By issuing the following command, packets with source IP address 192.168.10.109/32 and source port 59734 and 52049 is delayed 2000ms on eth0
sudo tc qdisc add dev eth0 root handle 1: prio
sudo tc qdisc add dev eth0 parent 1:3 handle 30: netem delay 2000ms
sudo tc filter add dev eth0 protocol ip parent 1:0 prio 3 \
u32 match ip src 192.168.10.109/32 match ip sport 59734 0xffff flowid 1:3
sudo tc filter add dev eth0 protocol ip parent 1:0 prio 3 \
u32 match ip sport 52049 0xffff flowid 1:3
References:
NETEM-LinuxFoundation
TC WIKI
Linux man page