...
I need to shape traffic on Lan1 to 1 Meg Download,(InternetDownstream=2
Meg) and that everyone on that Lan
has the same amount of traffic bandwidth available for download, (1
user=100%, 2 user=50% each 3 users=33,3%....etc)
I read about sfq, and esfq but it seems that I have to write a line for
every user (in my case about 80 users) .
So that it creates for each flow(user/port?) a new Band, right?
Anyone can give me a "example script" for My Case with a bitexplanation.
so I can work with it?
I have a script which does something similar. Assuming you have a /etc/hosts file with all the hosts: (it is somewhat more complicated because it lives between our resnet and the rest of campus and I don't want to shape down traffic going to campus much (if at all))
#/bin/bash
########################################### ### ALL CONFIGURATION SHOULD BE UP HERE ### ###########################################
### bandwidth settings
#daily quota in bytes #QUOTA=1000000000
#total internal bandwidth INTRABANDWIDTH=10mbit #total external bandwidth INTERBANDWIDTH=.4mbit #the difference between intra and inter DIFFBANDWIDTH=8mbit
#bandwidth for the unregistered ips.. probably not much... UNREGISTEREDBW=16kbit
BASEBANDWIDTH=1kbit
#bandwidth for jail #JAILBANDWIDTH=.1mbit #rest of bandwidth (inter-jail) #RESTBANDWIDTH=1mbit
### interfaces and ips
#interface to shape (should probably be one facing world) SHAPEINTERFACE=eth0 #interface to watch (usually the same as SHAPEINTERFACE) WATCHINTERFACE=eth0
LOCALNET=137.22.0.0 LOCALNETNETMASK=16
####################################### ### BEGIN NON-CONFIGURATION SECTION ### #######################################
initqos() { #remove the old qos rules echo tc qdisc del root dev $SHAPEINTERFACE tc qdisc del root dev $SHAPEINTERFACE
#create the root queue
echo tc qdisc add dev $SHAPEINTERFACE root handle 1: htb default 20
tc qdisc add dev $SHAPEINTERFACE root handle 1: htb default 20
#create the root class
echo tc class add dev $SHAPEINTERFACE parent 1: classid 1:1 htb rate $INTRABANDWIDTH burst 15k
tc class add dev $SHAPEINTERFACE parent 1: classid 1:1 htb rate $INTRABANDWIDTH burst 15k
#create the class for the intranet
echo tc class add dev $SHAPEINTERFACE parent 1:1 classid 1:10 htb rate $DIFFBANDWIDTH ceil $INTRABANDWIDTH burst 15k
tc class add dev $SHAPEINTERFACE parent 1:1 classid 1:10 htb rate $DIFFBANDWIDTH ceil $INTRABANDWIDTH burst 15k
#create the "default" class which will include everything else (probably the internet)
echo tc class add dev $SHAPEINTERFACE parent 1:1 classid 1:20 htb rate $INTERBANDWIDTH burst 15k
tc class add dev $SHAPEINTERFACE parent 1:1 classid 1:20 htb rate $INTERBANDWIDTH burst 15k
#add a queue to handle all the local net requests
echo tc qdisc add dev $SHAPEINTERFACE parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $SHAPEINTERFACE parent 1:10 handle 10: sfq perturb 10
#create the filter to pick out the intranet from all the packets
echo tc filter add dev $SHAPEINTERFACE protocol ip parent 1:0 prio 1 u32 \
match ip src $LOCALNET/$LOCALNETNETMASK flowid 1:10
tc filter add dev $SHAPEINTERFACE protocol ip parent 1:0 prio 1 u32 \
match ip src $LOCALNET/$LOCALNETNETMASK flowid 1:10
#add the htb queue to make the good go fast to the internet and the bad go slowly.
echo tc qdisc add dev $SHAPEINTERFACE parent 1:20 htb default 21
tc qdisc add dev $SHAPEINTERFACE parent 1:20 htb default 21
#create the class for the users who have not registered. bad users!
echo tc class add dev $SHAPEINTERFACE parent 1:10 classid 1:21 htb rate $UNREGISTEREDBW ceil $UNREGISTEREDBW burst 15k
tc class add dev $SHAPEINTERFACE parent 1:10 classid 1:21 htb rate $UNREGISTEREDBW ceil $UNREGISTEREDBW burst 15k
#add a queue to handle all the unregistered users
echo tc qdisc add dev $SHAPEINTERFACE parent 1:21 handle 21: sfq perturb 10
tc qdisc add dev $SHAPEINTERFACE parent 1:21 handle 21: sfq perturb 10
#filters for each user will be added farther down...
}
addclass() {
IP=$1 CLASS=$2
#create the class for each user
echo tc class add dev $SHAPEINTERFACE parent 1:10 classid 1:$CLASS htb rate $BASEBANDWIDTH ceil $INTERBANDWIDTH burst 15k
tc class add dev $SHAPEINTERFACE parent 1:10 classid 1:$CLASS htb rate $BASEBANDWIDTH ceil $INTERBANDWIDTH burst 15k
#add a queue for each user
echo tc qdisc add dev $SHAPEINTERFACE parent 1:$CLASS handle $CLASS: sfq perturb 10
tc qdisc add dev $SHAPEINTERFACE parent 1:$CLASS handle $CLASS: sfq perturb 10
#add a filter for each user echo tc filter add dev $SHAPEINTERFACE protocol ip parent 1:0 prio 1 u32 \ match ip dst $IP flowid 1:$CLASS tc filter add dev $SHAPEINTERFACE protocol ip parent 1:0 prio 1 u32 \ match ip dst $IP flowid 1:$CLASS echo tc filter add dev $SHAPEINTERFACE protocol ip parent 1:0 prio 1 u32 \ match ip src $IP flowid 1:$CLASS tc filter add dev $SHAPEINTERFACE protocol ip parent 1:0 prio 1 u32 \ match ip src $IP flowid 1:$CLASS
}
OVERQUOTAIPS=() NUMOVERQUOTA=0
initqos
FILE=/etc/hosts echo $FILE LINES=`cat $FILE | grep -v \# |grep -v 127.0.0.1 | wc -l`
#copy the ipfm file to the web dir
#echo The quota is currently $QUOTA -- compare to the third column of numbers > /var/www/html/curbandwidth.txt
echo The current test does not involve a quota. I may post bandwidth usage soon anyway. > /var/www/html/curbandwidth.txt
#cat $FILE >>/var/www/html/curbandwidth.txt
echo ips registered: $LINES
#loop through the ip addresses that have been observed so far
if [ $LINES -ne 0 ]; then
for x in `seq 1 $LINES`; do
HOSTNAME=`cat $FILE | grep -v \# | grep -v 127.0.0.1 | head -$x | tail -1 | cut -f 1 -d" "`
addclass $HOSTNAME $(($x+21))
done
else
NUMOVERQUOTA=0
fi