Add files for swift over UDP.
[swifty.git] / src / libswift_udp / mfold / netem.default.sh
1 #!/bin/bash
2 # Sets HTB/Netem parameters for the server interfaces. netroot script
3 # must be run before this.
4
5 if [ ! $EMIF ] ; then
6     exit
7 fi
8
9 if [ ! $SWFTPORT ]; then
10     echo No swift port defined!
11     exit 1
12 fi
13
14 if [ ! $EMLOSS ]; then
15     EMLOSS=0%
16 fi
17
18 if [ ! $EMDELAY ]; then
19     EMDELAY=10ms
20 fi
21
22 if [ ! $EMBW ]; then
23     EMBW=10mbit
24 fi
25
26 if [ ! $EMJTTR ]; then
27     EMJTTR=0ms
28 fi
29
30 # ingress params
31 if [ ! $EMLOSS_IN ]; then
32     EMLOSS_IN=$EMLOSS
33 fi
34
35 if [ ! $EMDELAY_IN ]; then
36     EMDELAY_IN=$EMDELAY
37 fi
38
39 # zero delay in lo may affect htb performance accuracy (?)
40 if [ $EMDELAY_IN == 0ms ]; then
41     EMDELAY_LO_IN=0.1ms
42 else
43     EMDELAY_LO_IN=$EMDELAY_IN
44 fi
45
46 if [ ! $EMBW_IN ]; then
47     EMBW_IN=$EMBW
48 fi
49
50 if [ ! $EMJTTR_IN ]; then
51     EMJTTR_IN=$EMJTTR
52 fi
53
54 # egress params
55 if [ ! $EMLOSS_OUT ]; then
56     EMLOSS_OUT=$EMLOSS
57 fi
58
59 if [ ! $EMDELAY_OUT ]; then
60     EMDELAY_OUT=$EMDELAY
61 fi
62
63 if [ ! $EMBW_OUT ]; then
64     EMBW_OUT=$EMBW
65 fi
66
67 if [ ! $EMJTTR_OUT ]; then
68     EMJTTR_OUT=$EMJTTR
69 fi
70
71 TC="sudo tc "
72
73 CLASSID=$(($SWFTPORT - 9900))
74 HANDLEID=1$CLASSID
75
76 # ingress config
77 echo adding htb class 1:$CLASSID with rate $EMBW_IN to ifb0
78 $TC class add dev ifb0 parent 1: classid 1:$CLASSID htb rate $EMBW_IN || exit 2
79 echo adding filter for destination port $SWFTPORT for to ifb0
80 $TC filter add dev ifb0 protocol ip prio 1 handle ::$CLASSID u32 \
81     match ip dport $SWFTPORT 0xffff flowid 1:$CLASSID || exit 3
82 echo adding downlink netem handle $HANDLEID for $EMDELAY_IN, $EMLOSS_IN to ifb0
83 $TC qdisc add dev ifb0 parent 1:$CLASSID handle $HANDLEID \
84     netem delay $EMDELAY_IN $EMJTTR_IN 25% loss $EMLOSS_IN || exit 4
85
86 echo adding htb class 1:$CLASSID with rate $EMBW_IN to lo
87 $TC class add dev lo parent 1: classid 1:$CLASSID htb rate $EMBW_IN || exit 5
88 echo adding filter for destination port $SWFTPORT for to lo
89 $TC filter add dev lo protocol ip prio 1 handle ::$CLASSID u32 \
90     match ip dport $SWFTPORT 0xffff flowid 1:$CLASSID || exit 6
91 echo adding downlink netem handle $HANDLEID for $EMDELAY_LO_IN, $EMLOSS_IN to lo
92 $TC qdisc add dev lo parent 1:$CLASSID handle $HANDLEID \
93     netem delay $EMDELAY_LO_IN $EMJTTR_IN 25% loss $EMLOSS_IN || exit 7
94
95 #egress config
96 echo adding htb class 1:$CLASSID with rate $EMBW_OUT to $EMIF
97 $TC class add dev $EMIF parent 1: classid 1:$CLASSID htb rate $EMBW_OUT || exit 8
98 echo adding filter for source port $SWFTPORT for to $EMIF
99 $TC filter add dev $EMIF protocol ip prio 1 handle ::$CLASSID u32 \
100     match ip sport $SWFTPORT 0xffff flowid 1:$CLASSID || exit 9
101 echo adding uplink netem handle $HANDLEID for $EMDELAY_OUT, $EMLOSS_OUT to $EMIF
102 $TC qdisc add dev $EMIF parent 1:$CLASSID handle $HANDLEID \
103     netem delay $EMDELAY_OUT $EMJTTR_OUT 25% loss $EMLOSS_OUT || exit 10