Traffic shaping and emulation of network properties (delay, loss) is very useful when conducting experiments aiming at investigating protocol behavior under specific network conditions. One of the tools that can be used under linux is netem (network emulator).
In order to use netem, you need to install the iproute package.
apt-get install iproute
Given an interface name, network delay (in milliseconds) and packet loss rate (in percentage), all IP packets traveling through the interface will be delayed for the specified amount, and randomly dropped according to the specified packet loss rate. The script requires ifb (Intermediate Functional Block) and operates on outgoing as well as incoming traffic.
#!/bin/sh # usage : ./xxx.sh interface [loss] [delay] # If only the interface name is specified, the script # will remove any previously applied delay and loss emulation if0=$1 loss=$2 delay=$3ms if [ $# -eq 1 ] then echo $# tc qdisc del dev $if0 ingress tc qdisc del dev ifb0 root exit fi modprobe ifb ip link set dev ifb0 up tc qdisc del dev $if0 ingress tc qdisc add dev $if0 ingress tc filter add dev $if0 parent ffff: \ protocol ip u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb0 tc qdisc del dev ifb0 root tc qdisc add dev ifb0 root netem delay $delay loss $loss%
|Labels: howto, performance|