Problem
You want to simulate high latency for a network adapter
Solution
1. Install tc - the Linux Traffic Control utility
# yum install iproute-tc
2. Using ip addr identify the network adapter for which you want to increase latency
3. Having identified the nic, enp0s8 in this example, use the below command to set the latency to 74ms:
# tc qdisc add dev enp0s8 root netem delay 74ms
Verify the setting with:
# tc qdisc show dev enp0s8
qdisc netem 8004: root refcnt 2 limit 1000 delay 74.0ms
qdisc netem 8004: root refcnt 2 limit 1000 delay 74.0ms
# ping 192.168.56.1
PING 192.168.56.1 (192.168.56.1) 56(84) bytes of data.
64 bytes from 192.168.56.1: icmp_seq=1 ttl=128 time=75.0 ms
64 bytes from 192.168.56.1: icmp_seq=2 ttl=128 time=74.4 ms
64 bytes from 192.168.56.1: icmp_seq=3 ttl=128 time=75.3 ms
64 bytes from 192.168.56.1: icmp_seq=4 ttl=128 time=74.4 ms
PING 192.168.56.1 (192.168.56.1) 56(84) bytes of data.
64 bytes from 192.168.56.1: icmp_seq=1 ttl=128 time=75.0 ms
64 bytes from 192.168.56.1: icmp_seq=2 ttl=128 time=74.4 ms
64 bytes from 192.168.56.1: icmp_seq=3 ttl=128 time=75.3 ms
64 bytes from 192.168.56.1: icmp_seq=4 ttl=128 time=74.4 ms
4. To remove the rule, use:
# tc qdisc del dev enp0s8 root
# ping 192.168.56.1
PING 192.168.56.1 (192.168.56.1) 56(84) bytes of data.
64 bytes from 192.168.56.1: icmp_seq=1 ttl=128 time=0.144 ms
64 bytes from 192.168.56.1: icmp_seq=2 ttl=128 time=0.344 ms
PING 192.168.56.1 (192.168.56.1) 56(84) bytes of data.
64 bytes from 192.168.56.1: icmp_seq=1 ttl=128 time=0.144 ms
64 bytes from 192.168.56.1: icmp_seq=2 ttl=128 time=0.344 ms
5. Other useful examples of tc:
# tc qdisc add dev ppp0 root tbf rate 220kbit latency 50ms burst 1540
# tc qdisc add dev ens5 root netem loss 0.1%
# tc qdisc add dev ens5 root netem loss 0.3% 25%
# tc qdisc add dev ens5 root netem loss gemodel 1% 10% 70% 0.1%
6. Usage of the netem option:
Usage: ... netem [ limit PACKETS ]
[ delay TIME [ JITTER [CORRELATION]]]
[ distribution {uniform|normal|pareto|paretonormal} ]
[ corrupt PERCENT [CORRELATION]]
[ duplicate PERCENT [CORRELATION]]
[ loss random PERCENT [CORRELATION]]
[ loss state P13 [P31 [P32 [P23 P14]]]
[ loss gemodel PERCENT [R [1-H [1-K]]]
[ ecn ]
[ reorder PERCENT [CORRELATION] [ gap DISTANCE ]]
[ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]
[ slot MIN_DELAY [MAX_DELAY] [packets MAX_PACKETS] [bytes MAX_BYTES]]
[ slot distribution {uniform|normal|pareto|paretonormal|custom} DELAY JITTER [packets MAX_PACKETS] [bytes MAX_BYTES]]
[ delay TIME [ JITTER [CORRELATION]]]
[ distribution {uniform|normal|pareto|paretonormal} ]
[ corrupt PERCENT [CORRELATION]]
[ duplicate PERCENT [CORRELATION]]
[ loss random PERCENT [CORRELATION]]
[ loss state P13 [P31 [P32 [P23 P14]]]
[ loss gemodel PERCENT [R [1-H [1-K]]]
[ ecn ]
[ reorder PERCENT [CORRELATION] [ gap DISTANCE ]]
[ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]
[ slot MIN_DELAY [MAX_DELAY] [packets MAX_PACKETS] [bytes MAX_BYTES]]
[ slot distribution {uniform|normal|pareto|paretonormal|custom} DELAY JITTER [packets MAX_PACKETS] [bytes MAX_BYTES]]
7. Reference:
No comments:
Post a Comment