Check the current configuration:
tc qdisc show dev lo
The output should be something like: “qdisc noqueue 0: root refcnt 2”
A link locally using netem:
sudo tc qdisc add dev lo root netem delay <average_delay_in_miliseconds>ms <maximum_average_deviation_in_miliseconds>ms <Pearson_correlation_coefficient_expressed_as_a_percentage>% distribution <uniform|normal|pareto|paretonormal>
where:
qdisc:
Use the default FIFO Queueing DISCipline for the outgoing traffic.
add:
Add a new traffic control rule.
dev lo:
The device affected by the rule. lo means loopback.
root:
The rule will be applied to all the outbound traffic (it’s the root rule of the possible tree of rules).
netem:
Use the network emulator to emulate a WAN.
Example:
Delete the tc rule with:
sudo tc qdisc delete dev lo root netem delay <average_dalay_in_miliseconds>ms <maximum_average_deviation_in_miliseconds>ms <Pearson_correlation_coefficient_expressed_as_a_percentage>% distribution <uniform|normal|pareto|paretonormal>
It is possible to change a working rule with:
sudo tc qdisc change dev lo root netem delay <average_dalay_in_miliseconds>ms <maximum_average_deviation_in_miliseconds>ms <Pearson_correlation_coefficient_expressed_as_a_percentage>% distribution <uniform|normal|pareto|paretonormal>
Lossing packets. For example, a packet loss ratio of \(10\%\) can be configured with tc by running:
sudo tc qdisc add dev lo root netem loss 10%
A bit-rate value can be simulated (locally) with:
sudo tc qdisc add dev lo root handle 1: tbf rate <bit-rate_in_kbps>kbit burst 32kbit limit 32kbit sudo tc qdisc add dev lo parent 1:1 handle 10: netem delay <average_delay_in_miliseconds>ms <maximum_average_deviation_in_miliseconds>ms <Pearson_correlation_coefficient_expressed_as_a_percentage>% distribution <uniform|normal|pareto|paretonormal>
Examples:
Check the current configuration:
tc qdisc show dev lo
The output should be something like:
qdisc noqueue 0: root refcnt 2
Define the rule for bit-rate control (example for \(200\) kbps):
sudo tc qdisc add dev lo root handle 1: tbf rate 200kbit burst 32kbit limit 32kbit
Define the rule for latency control (example for \(100\) ms, \(10\) ms of jitter, and with the next random transmission depending on \(25\)% on the last):
sudo tc qdisc add dev lo parent 1:1 handle 10: netem delay 100ms 10ms 25% distribution normal
After adding these rules, this should be the configuration:
tc qdisc show dev lo
The output should be something like:
qdisc tbf 1: root refcnt 2 rate 200Kbit burst 4Kb lat 0us qdisc netem 10: parent 1:1 limit 1000 delay 100ms 10ms 25%
Recall to delete the rules after they are unnecessary (example to delete the previous rules):
sudo tc qdisc delete dev lo parent 1:1 handle 10: netem delay 100ms 10ms 25% distribution normal sudo tc qdisc delete dev lo root handle 1: tbf rate 200kbit burst 32kbit limit 32kbit
[1] Bert Hubert, Thomas Graf, Greg Maxwell, Remco van Mook, Martijn van Oosterhout, Paul B. Schroeder, Jasper Spaans, and Pedro Larroy. Linux Advanced Routing & Traffic Control. Publisher: Bert Humbert et al., 2012.