-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup-network
41 lines (33 loc) · 1020 Bytes
/
setup-network
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
#!/bin/bash
case "$1" in
status)
tc -s qdisc ls dev lo
tc class show dev lo
;;
on)
if [ -z "$2" ] ; then
echo "Usage: $0 on [#ms latency] [optional max Mbps]"
exit 1
fi
# cribbed from http://serverfault.com/questions/507658/limit-incoming-and-outgoing-bandwidth-and-latency-in-linux
if [ ! -z "$3" ] ; then
sudo tc qdisc add dev lo handle 1: root htb default 11
sudo tc class add dev lo parent 1: classid 1:1 htb rate 1000Mbps
sudo tc class add dev lo parent 1:1 classid 1:11 htb rate "$3"Mbit
sudo tc qdisc add dev lo parent 1:11 handle 10: netem delay "$2"ms limit 100000
else
sudo tc qdisc add dev lo handle 1: root netem delay "$2"ms limit 100000
fi
;;
off)
sudo tc qdisc del dev lo root
;;
*)
echo "Use this script to add latency or bandwidth limit to the loopback device"
echo
echo "Usage:"
echo " $0 status"
echo " $0 on [#ms latency] [max Mpbs]"
echo " $0 off"
exit 1
esac