PDA

Bekijk de volledige versie : Uniform division of bandwidth between workstations (solution)



AlexeyA
30-03-2007, 01:30
Task: divide 128 kbit between 5 users providing at least 24 kbit to each user, and full speed at maximum. Besides this, I had to decrease packet loss at internet provider side.

Solution:

Hardware - asus wl-500g Premium with firmware ver 1.9.2.7-7f (2006-11-06) http://oleg.wl500g.info/

Native bandwidth management should be disabled.

----------------------------------
Create /usr/local/sbin
Там создать
-rwxr-xr-x post-firewall
-rwxr-xr-x wshaper

----------------------------------
Content of post-firewall:
#!/bin/sh
/usr/local/sbin/wshaper start vlan0 120 120

----------------------------------
Content of wshaper (original script lies at /sbin)
#/bin/sh
# Wonder Shaper
# please read the README before filling out these values
#
# Set the following values to somewhat less than your actual download
# and uplink speed. In kilobits. Also set the device that is to be shaped.

DOWNLINK=$3
UPLINK=$4
DEV=$2

#echo Please read the documentation in 'README' first
#exit

if [ "$1" = "status" ]
then
# tc -s qdisc ls dev $DEV
tc -s class ls dev $DEV
exit
fi


# clean existing down- and uplink qdiscs, hide errors
tc qdisc del dev $DEV root 2> /dev/null > /dev/null
tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null

if [ "$1" = "stop" ]
then
exit
fi


###### uplink

# install root HTB, point default traffic to 1:99:
tc qdisc add dev $DEV root handle 1: htb default 99

# root class 1
tc class add dev $DEV parent 1: classid 1:1 htb rate 100mbit

# router traffic subslass 2 (router IP=192.168.0.254)
tc class add dev $DEV parent 1:1 classid 1:2 htb rate 100mbit
tc qdisc add dev $DEV parent 1:2 handle 2: sfq perturb 10
tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \
match ip src 192.168.0.254 flowid 1:2

# internet traffic subclass 10
tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
ceil ${UPLINK}kbit

# internet traffic subclasses 11, 12, 13,... for each client IP
tc class add dev $DEV parent 1:10 classid 1:11 htb rate 1kbit \
ceil ${UPLINK}kbit prio 2
tc class add dev $DEV parent 1:10 classid 1:12 htb rate 1kbit \
ceil ${UPLINK}kbit prio 2
tc class add dev $DEV parent 1:10 classid 1:13 htb rate 1kbit \
ceil ${UPLINK}kbit prio 2
tc class add dev $DEV parent 1:10 classid 1:14 htb rate 1kbit \
ceil ${UPLINK}kbit prio 2
tc class add dev $DEV parent 1:10 classid 1:15 htb rate 1kbit \
ceil ${UPLINK}kbit prio 2
tc class add dev $DEV parent 1:10 classid 1:99 htb rate 1kbit \
ceil ${UPLINK}kbit prio 2

# creating quques for each class
tc qdisc add dev $DEV parent 1:11 handle 11: sfq perturb 10
tc qdisc add dev $DEV parent 1:12 handle 12: sfq perturb 10
tc qdisc add dev $DEV parent 1:13 handle 13: sfq perturb 10
tc qdisc add dev $DEV parent 1:14 handle 14: sfq perturb 10
tc qdisc add dev $DEV parent 1:15 handle 15: sfq perturb 10
tc qdisc add dev $DEV parent 1:99 handle 99: sfq perturb 10

#sending traffic from clinet's IP's to classes
tc filter add dev $DEV parent 1: protocol ip prio 20 u32 \
match ip dst 192.168.0.1 flowid 1:11

tc filter add dev $DEV parent 1: protocol ip prio 20 u32 \
match ip dst 192.168.0.2 flowid 1:12

tc filter add dev $DEV parent 1: protocol ip prio 20 u32 \
match ip dst 192.168.0.3 flowid 1:13

tc filter add dev $DEV parent 1: protocol ip prio 20 u32 \
match ip dst 192.168.0.4 flowid 1:14

tc filter add dev $DEV parent 1: protocol ip prio 20 u32 \
match ip dst 192.168.0.5 flowid 1:15

########## downlink #############
# slow downloads down to somewhat less than the real speed to prevent
# queuing at our ISP. Tune to see how high you can set it.
# ISPs tend to have *huge* queues to make sure big downloads are fast
#
# attach ingress policer:

tc qdisc add dev $DEV handle ffff: ingress

# filter *everything* to it (0.0.0.0/0), drop everything that's
# coming in too fast:

tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
0.0.0.0/0 police rate ${DOWNLINK}kbit burst 1k drop flowid :1


----------------------------------
Save settings and restart router:

flashfs save
flashfs commit
flashfs enable
reboot

This script is checked and have already been working fine for a month.