Thatbytes

Mostly Interesting

Network Condition Emulation

I was asked to today if it was possible to add latency and packet loss to a device in order to replicated network problems. After a while googleing i found tc +netem. This allows you do funcy stuff to replicated network problems. If i wanted to add 100ms of latency i could do

1
tc qdisc add dev eth0 root netem delay 100ms

You can also add variation

1
tc qdisc change dev eth0 root netem delay 100ms 10ms

This causes the added delay to be 100ms ± 10ms.

or even better

1
tc qdisc change dev eth0 root netem delay 100ms 10ms 25%

This causes the added delay to be 100ms ± 10ms with the next random element depending 25% on the last one.

If we also wanted to add packet loss we can do

1
tc qdisc change dev eth0 root netem loss 0.1%

This would cause 1 out of 1000 packets to be randomly dropped.

To emulate packet loss “in a row”

1
tc qdisc change dev eth0 root netem loss 0.3% 25%

This will cause 0.3% of packets to be lost, and each successive probability depends by a quarter on the last one.

Comments