Traffic Shaping
Linux
add/remove an emulated latency
cc@Linux:~ % sudo tc qdisc add dev enp1s0 root netem delay 40ms cc@Linux:~ % tc qdisc show dev enp1s0 qdisc netem 8001: root refcnt 2 limit 1000 delay 40ms cc@Linux:~ % cc@Linux:~ % sudo tc qdisc del dev enp1s0 root cc@Linux:~ % tc qdisc show dev enp1s0 qdisc fq_codel 0: root refcnt 2 limit 10240p flows 1024 quantum 1514 target 5ms interval 100ms memory_limit 32Mb ecn drop_batch 64 cc@Linux:~ %
iptable drop every nth packet
## add a rule % sudo iptables -A INPUT -p tcp --dport 5201 -m statistic --mode nth --every 10000 --packet 0 -j DROP ## show current rule cc@r1:~ % sudo iptables -L -vn --line-numbers Chain INPUT (policy ACCEPT 270K packets, 2369M bytes) num pkts bytes target prot opt in out source destination 1 27 158K DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:5201 statistic mode nth every 10000 ## modify current rule cc@r1:~ % sudo iptables -R INPUT 1 -p tcp --dport 5201 -m statistic --mode nth --every 100 --packet 0 -j DROP cc@r1:~ % sudo iptables -L -vn --line-numbers Chain INPUT (policy ACCEPT 17 packets, 1614 bytes) num pkts bytes target prot opt in out source destination 1 0 0 DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:5201 statistic mode nth every 100 ## delete current rule cc@r1:~ % sudo iptables -D INPUT -p tcp --dport 5201 -m statistic --mode nth --every 100 --packet 0 -j DROP