-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshape.sh
executable file
·86 lines (67 loc) · 2.16 KB
/
shape.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
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
#!/bin/bash
export LC_NUMERIC=en_US.UTF-8
if [ "$#" -ne 1 ]; then
echo "Usage: ./shape <shaping file> "
exit
fi
input_file=$1
SINK=130.37.199.8 # fs0.das5.cs.vu.nl
mapfile -t list < $input_file
#tc_adapter=wlp59s0 #wifi
# tc_adapter=enx106530c1958e #eth
tc_adapter=eth0 #eth
#tc_adapter=eno1 #server eth
TIMESTAMP=$(sleepenh 0)
# sudo tc qdisc add dev $tc_adapter root tbf rate 10mbit latency 25ms burst 3000
# Use HTB
#iperf3 -c netmsys.org -p 10001 -t 1000 &
#iperf3 -c fs0.das5.cs.vu.nl -p 10004 -t 300 &
#iperf3 -c 130.83.163.233 -p 10001 -t 1000 &
SECONDS=20
function init() {
# echo "Initiatilizing..."
tc qdisc add dev $tc_adapter root handle 1: htb
tc class add dev $tc_adapter parent 1: classid 1:10 htb rate 100Mbit
tc filter add dev $tc_adapter protocol ip parent 1: prio 1 u32 match ip dst ${SINK} flowid 1:10
}
function clear() {
# echo "Clearing..."
tc qdisc del dev $tc_adapter root
}
function stop() {
# echo "Stoping..."
clear
exit
}
function change_bw() {
# echo "Changing bw to $1..."
tc class change dev $tc_adapter parent 1: classid 1:10 htb rate "$1"Mbit
}
trap "stop" SIGHUP SIGINT SIGTERM
clear
init
while true
do
for item in ${list[@]}
do
if [ -z "${item//[$'\t\r\n ']}" ] #skip empty var
then
continue
fi
#sudo tc class change dev $tc_adapter parent 1: classid 1:11 htb rate "${item//[$'\t\r\n ']}"mbit
# sudo tc qdisc change dev $tc_adapter root tbf rate "${item//[$'\t\r\n ']}"mbit latency 25ms burst 3000
# Adjust bandwidth
# tc class change dev $tc_adapter parent 1: classid 1:10 htb rate "${item//[$'\t\r\n ']}"mbit burst 3000
change_bw "${item//[$'\t\r\n ']}"
# Adjust latency
# tc qdisc add dev $tc_adapter parent 1:10 handle 10: netem delay 10ms
#date +"B | %H:%M:%S.%N | $(printf "%.3f" ${item//[$'\t\r\n ']}) mbit"
duration=$SECONDS
# echo -n "$(printf "%.3f " ${item//[$'\t\r\n ']})"
TIMESTAMP=$(sleepenh $TIMESTAMP $duration)
done
done
t=$(sleepenh $t 3)
#echo "shaping completed, removing qdisc"
# tc qdisc del dev $tc_adapter root
stop