As a network engineer, I have to spend a lot of time in the lab or test environment on testing concepts, configuration, troubleshooting and so on. This is also true for people whose work environment is related to a network such as developers, DBAs. The problem here is that the lab sometimes so perfect that it cannot emulate the real world flaws like latency, packet loss, re-order or bandwidth limitation. So we need an emulator to test a program or system on a simulated network connection which is faulty or errors prone. This is a valuable tool to make sure your application works when the network has packet loss, jitter or high latency. Loss emulation is a standardized method to simulate a bad network connection using a system on your local LAN. Using the local LAN keeps your testing environment secure and allows full control over the topology.
Every time I have this need, I prefer to use tc.
In short, tc is a queueing discipline for bandwidth management, like shaping, policing, scheduling or dropping. Since there are articles about how to use it from the command line man page, I don’t want to create one more redundancy. I prefer to give some quick useful command to let you understand it. If you think any one of those is interesting, then you can dig the document.
A simulated network that has:
sudo tc qdisc add dev eth0 root netem delay 100ms 40ms 15% loss 0.5% 25% duplicate 1% corrupt 0.1% reorder 5% 50%
remove from config:
sudo tc qdisc del dev eth0 root netem