traffic control of tc in linux and netem
tc qdisc Linux Traffic Control or tc
Test |
|
---|
| |
| tc qdisc change dev eth0 root netem loss 10% delay 100ms alpine:~# tc qdisc show qdisc netem 8003: dev eth0 root refcnt 2 limit 1000 delay 100ms loss 10%
|
| sudo -i for i in {1..10}; do echo "Ping attempt $i:"; ping -c 100 -f -q 8.8.8.8; echo -e "\n"; done |
Result | |
on Alpine |
|
---|
|
|
add package | apk update apk add iproute2 |
| apk for alpine based on busybox |
kernel module |
|
---|
load | modprobe sch_netem modprobe cls_u32 |
check | lsmod | grep netem |
permanent | Not needed !!! |
---|
create file | vi /etc/local.d/netem.start tc qdisc change dev eth0 root netem xxxxxxxx |
| chmod +x /etc/local.d/netem.start rc-update add local |
latency |
|
---|
+ 100 ms | tc qdisc add dev eth0 root netem delay 100ms |
remote it | tc qdisc del dev eth0 root |
packet loss |
|
---|
+ 10% | tc qdisc add dev eth0 root netem loss 10% |
| tc qdisc change dev eth0 root netem loss 10% |
| tc qdisc del dev eth0 root |
duplication |
|
---|
| sudo tc qdisc add dev eth0 root netem duplicate 10% |
|
|
reordering |
|
---|
| sudo tc qdisc add dev eth0 root netem reorder 25% 50% |
| reorder 25% : Specifies that 25% of packets will be reordered.50% : Correlation value, meaning that once reordering starts, there is a 50% chance it continues.
|
show |
|
---|
| alpine:~# tc qdisc show qdisc noqueue 0: dev lo root refcnt 2 qdisc netem 8001: dev eth0 root refcnt 2 limit 1000 loss 10% qdisc pfifo_fast 0: dev eth1 root refcnt 2 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 |
| qdisc netem 8001: dev eth0 root refcnt 2 limit 1000 loss 10%
qdisc netem : A qdisc implementing network emulation. This is commonly used to simulate network conditions like delay, loss, duplication, or reordering.8001: : A unique handle identifying this qdisc.dev eth0 : Applied to the eth0 interface.root : This is the root qdisc for the eth0 interface.refcnt 2 : Two users or instances depend on this qdisc.limit 1000 : Specifies the maximum number of packets that can be queued.loss 10% : Simulates a 10% packet loss rate on traffic passing through eth0 .
|
| qdisc pfifo_fast 0: dev eth1 root refcnt 2 bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
qdisc pfifo_fast : A default qdisc for many Linux setups, implementing a priority FIFO (First In, First Out) queue.0: : A handle identifying this qdisc.dev eth1 : Applied to the eth1 interface.root : This is the root qdisc for the eth1 interface.refcnt 2 : Two users or instances rely on this qdisc.bands 3 : Traffic is divided into 3 bands (queues), each with a different priority. ( Band 0=HightP, 1=MPriority and 2=LowP )priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 :- Defines how packets are classified into these bands based on their Type of Service (ToS) field.
- Lower-priority packets are placed in higher-numbered bands, and higher-priority packets (like VoIP) are placed in lower-numbered bands.
Each number corresponds to a ToS value (0–7) and maps it to one of the priority bands: 0 : Band 1 (lower priority)1 : Band 2 (medium priority)2 : Band 2 (medium priority)3 : Band 2 (medium priority)4 : Band 1 (lower priority)5 : Band 2 (medium priority)6 : Band 0 (high priority)7 : Band 0 (high priority)
|