-
Notifications
You must be signed in to change notification settings - Fork 2
/
latencyswitch.sh
executable file
·47 lines (39 loc) · 1.16 KB
/
latencyswitch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
prev=0
start_dir="$(pwd)"
ourpid="$$"
main_loop() {
iface="$1"
prefix="$2"
while read line; do
if [ "$line" = "bench-quit" ]; then
>&2 echo umount "${start_dir}/smb"
for i in $(seq 0 10); do
if >&2 umount "${start_dir}/smb"; then
>&2 pkill -P "$ourpid" > /dev/null
fi
sleep 0.5
done
>&2 umount -l "${start_dir}/smb"
>&2 pkill -P "$ourpid" > /dev/null
break
fi
>&2 echo "${line}ms"
if [ "$prev" -ne "0" ]; then
echo "$prefix" tc qdisc del dev $iface root netem
fi
if [ "$line" -ne "0" ]; then
echo "$prefix" tc qdisc add dev $iface root netem delay "${line}ms"
fi
prev="$line"
done
}
socat - TCP-LISTEN:12345,fork,reuseaddr | \
if [ "$1" = "vagrant" ]; then
cd vagrant
main_loop "$2" "sudo" | sudo -u "$SUDO_USER" vagrant ssh
elif [ "$1" = "docker" ]; then
main_loop "$2" "" | sudo -u "$SUDO_USER" docker exec -i "$3" /bin/sh
else
main_loop "$2" "" | sudo -u "$SUDO_USER" /bin/sh
fi