Created Thu Aug, 20 2020 at 12:47AM

If you ever want to add simulated latency to a linux/unix based system. Check if tc is available on the system to modify the netem (network emulation) mod settings. I wrote a simple shell script to add latency to a particular IP address and port 22.

#!/bin/sh

if [ ! -z $1 ];then
   echo "sudo tc qdisc del dev eth0 root"
   sudo tc qdisc del dev eth0 root
   echo "sudo tc qdisc add dev eth0 root handle 1: prio priomap 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2"
   sudo tc qdisc add dev eth0 root handle 1: prio priomap 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
   echo "sudo tc qdisc add dev eth0 parent 1:1 handle 10: netem delay 500ms 10ms"
   sudo tc qdisc add dev eth0 parent 1:1 handle 10: netem delay 500ms 10ms
   echo "sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst ${1}/32 match ip dport 22 0xffff flowid  1:1"
   sudo tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst ${1}/32 match ip dport 22 0xffff flowid 1:1
fi

the remove script would look like:

#!/bin/sh

sudo tc -s qdisc
sudo tc qdisc del dev eth0 root