dotfiles/bin/bw

36 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2019-09-05 13:12:31 +01:00
#!/usr/bin/env bash
unlimit() {
2019-09-05 13:58:45 +01:00
tc qdisc del dev lo root
2019-09-05 13:12:31 +01:00
}
limit() {
if [ "$1" = "5Mbps" ]; then
2019-09-05 13:58:45 +01:00
tc qdisc del dev lo root
tc qdisc add dev lo handle 1: root htb default 11
tc class add dev lo parent 1:1 classid 1:11 htb rate 5000kbit
tc qdisc add dev lo parent 1:11 handle 10: netem delay 38ms loss 0.09%
2019-09-05 13:12:31 +01:00
elif [ "$1" = "10Mbps" ]; then
2019-09-05 13:58:45 +01:00
tc qdisc del dev lo root
tc qdisc add dev lo handle 1: root htb default 11
tc class add dev lo parent 1:1 classid 1:11 htb rate 10000kbit
tc qdisc add dev lo parent 1:11 handle 10: netem delay 32ms loss 0.09%
2019-09-05 13:12:31 +01:00
elif [ "$1" = "20Mbps" ]; then
2019-09-05 13:58:45 +01:00
tc qdisc del dev lo root
tc qdisc add dev lo handle 1: root htb default 11
tc class add dev lo parent 1:1 classid 1:11 htb rate 20000kbit
tc qdisc add dev lo parent 1:11 handle 10: netem delay 25ms loss 0.09%
2019-09-05 13:12:31 +01:00
else
echo -e >&2 "\x1B[31;1merror:\x1B[0m preset $1 not found"
exit 1
fi
}
if [ $# -eq 0 ]; then
echo -e >&2 "\x1B[31;1merror:\x1B[0m expecting command"
exit 1
else
"$@"
fi