/[projects]/trafficcontrol/trafficcontrol.sh
ViewVC logotype

Contents of /trafficcontrol/trafficcontrol.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 110 - (show annotations) (download) (as text)
Thu Oct 9 07:49:03 2008 UTC (15 years, 7 months ago) by torben
File MIME type: application/x-sh
File size: 860 byte(s)
Added first version of traffic control scripts.

1 #!/bin/bash
2
3 IF0=eth0
4 IF1=eth2
5
6 function clear_tc()
7 {
8 tc qdisc del dev $IF0 root 2>/dev/null >/dev/null
9 tc qdisc del dev $IF1 root 2>/dev/null >/dev/null
10 }
11
12 if [ "$1" == "clear" ] ; then
13 clear_tc
14 exit
15 fi
16
17
18 if [ $# -lt "3" ] ; then
19 echo "Usage: $0 <bandwidth> <delay> <delay-variation> [packet-loss]"
20 echo "eg.: $0 2mbit 100ms 10ms"
21 echo "eg.: $0 56kbit 100ms 10ms 0.8%"
22 echo ""
23 echo "or: $0 clear"
24 exit
25 fi
26
27 DIST="distribution normal"
28
29 if [ $3 == "0ms" ] ; then
30 DIST=""
31 fi
32
33
34 clear_tc
35
36 tc qdisc add dev $IF0 root handle 1: tbf rate $1 buffer 100000 limit 300000
37 tc qdisc add dev $IF0 parent 1:1 handle 2: netem delay $2 $3 $DIST
38
39 tc qdisc add dev $IF1 root handle 1: tbf rate $1 buffer 100000 limit 300000
40
41 if [ $# == "4" ] ; then
42 #packetloss fails if the simulated bandwidth is to small
43 tc qdisc add dev $IF1 parent 1:1 netem loss $4
44 fi
45
46 tc qdisc

  ViewVC Help
Powered by ViewVC 1.1.20