-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdummynet.sh
More file actions
executable file
·159 lines (146 loc) · 3.02 KB
/
dummynet.sh
File metadata and controls
executable file
·159 lines (146 loc) · 3.02 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/sh
# network link conditioner
# tested on MacOSX 10.8 & FreeeBSD 9.1
IIF="en0"
UP_BW="0"
UP_DELAY="0"
UP_PACKETLOSS="0.0"
DOWN_BW="0"
DOWN_DELAY="0"
DOWN_PACKETLOSS="0.0"
usage()
{
cat << EOF
usage: $0 options
OPTIONS:
-b bandwith (kbps)
-d delay (ms)
-l packet loss (%, 0.0-1.0)
-n profile number
-i profile list
-f flush pipes
EOF
}
fail()
{
echo 'exec failed!'
exit 1
}
flush()
{
sudo ipfw -q delete 45678
sudo ipfw -q delete 45679
sudo ipfw -f pipe flush || fail
}
info()
{
echo '(1) 3G, Good (↓ 850kbps, 100ms, 0.00 / ↑ 420kbps, 100ms, 0.00)'
echo '(2) 3G, Average (↓ 780kbps, 100ms, 0.00 / ↑ 330kbps, 100ms, 0.00)'
echo '(3) 3G, Lossy (↓ 780kbps, 100ms, 0.01 / ↑ 330kbps, 100ms, 0.00)'
echo '(4) Edge, Good (↓ 250kbps, 350ms, 0.00 / ↑ 200kbps, 370ms, 0.00)'
echo '(5) Edge, Average (↓ 240kbps, 400ms, 0.00 / ↑ 200kbps, 440ms, 0.00)'
echo '(6) Edge, Lossy (↓ 240kbps, 400ms, 0.01 / ↑ 200kbps, 440ms, 0.00)'
}
select_profile()
{
case $1 in
1)
DOWN_BW="850"
DOWN_DELAY="100"
DOWN_PAKETLOSS="0.0"
UP_BW="420"
UP_DELAY="100"
UP_PAKETLOSS="0.0"
;;
2)
DOWN_BW="780"
DOWN_DELAY="100"
DOWN_PAKETLOSS="0.0"
UP_BW="330"
UP_DELAY="100"
UP_PAKETLOSS="0.0"
;;
3)
DOWN_BW="780"
DOWN_DELAY="100"
DOWN_PAKETLOSS="0.01"
UP_BW="330"
UP_DELAY="100"
UP_PAKETLOSS="0.0"
;;
4)
DOWN_BW="250"
DOWN_DELAY="350"
DOWN_PAKETLOSS="0.0"
UP_BW="200"
UP_DELAY="370"
UP_PAKETLOSS="0.0"
;;
5)
DOWN_BW="240"
DOWN_DELAY="400"
DOWN_PAKETLOSS="0.0"
UP_BW="200"
UP_DELAY="440"
UP_PAKETLOSS="0.0"
;;
6)
DOWN_BW="240"
DOWN_DELAY="400"
DOWN_PAKETLOSS="0.01"
UP_BW="200"
UP_DELAY="440"
UP_PAKETLOSS="0.0"
;;
*)
echo 'error: unknown profile'
exit 1
;;
esac
}
configure()
{
sudo ipfw pipe 1 config bw ${DOWN_BW}Kbit/s delay ${DOWN_DELAY}ms plr ${DOWN_PAKETLOSS} || fail
sudo ipfw pipe 2 config bw ${UP_BW}Kbit/s delay ${UP_DELAY}ms plr ${UP_PAKETLOSS} || fail
sudo ipfw -q add 45678 pipe 1 ip from any to any in via $IIF || fail
sudo ipfw -q add 45679 pipe 2 ip from any to any out via $IIF || fail
}
if [ $# -eq 0 ]; then
usage
exit
fi
while getopts "b:d:l:n:fih?" OPTION
do
case $OPTION in
b)
UP_BW="$OPTARG"
DOWN_BW="$OPTARG"
;;
d)
UP_DELAY="$OPTARG"
DOWN_DELAY="$OPTARG"
;;
l)
UP_PAKETLOSS="$OPTARG"
DOWN_PAKETLOSS="$OPTARG"
;;
n)
select_profile "$OPTARG"
;;
i)
info
exit
;;
f)
flush
exit
;;
*)
usage
exit
;;
esac
done
flush
configure
echo 'done.'