Hi.
I've been trying to read up on traffic shaping with HTB. The thing is I have 3 apartments where the UPPER should not have any limits on it. Currently the MIDDLE and LOWER uses a lot of bandwidth and should not get too much access to the little there is to share.
Maybe there should be several queues but it is hard to understand how to script this.
The script:
Code:
#!/bin/sh
#
# Internet specific
# Down: 8192kbit/s
# Up: 768kbit/s
#
TC=/sbin/tc
# Devices
EXTERNAL=eth1 # Internet
UPPER=eth2 # Top floor
MIDDLE=eth3 # Middle floor
LOWER=eth0 # Lower floor
# Rates
DCEIL=7372kbit # Download rate (90%)
DRATE=737kbit # Download weight (10% of above)
UCEIL=691kbit # Upload rate (90%)
URATE=69kbit # Upload weight (10% of above)
# Start script
start() {
$TC qdisc add dev $EXTERNAL root handle 1: htb default 60
$TC class add dev $EXTERNAL parent 1: classid 1:1 htb rate 7372kbit
$TC class add dev $EXTERNAL parent 1:1 classid 1:10 htb rate 3686kbit ceil 7372kbit prio 0
$TC class add dev $EXTERNAL parent 1:1 classid 1:11 htb rate 691kbit ceil 691kbit prio 0
$TC class add dev $EXTERNAL parent 1:1 classid 1:20 htb rate 3686kbit ceil 3686kbit prio 1
$TC class add dev $EXTERNAL parent 1:1 classid 1:21 htb rate 172kbit ceil 345kbit prio 1
$TC class add dev $EXTERNAL parent 1:1 classid 1:30 htb rate 1843kbit ceil 3686kbit prio 2
$TC class add dev $EXTERNAL parent 1:1 classid 1:31 htb rate 172kbit ceil 345kbit prio 2
$TC qdisc add dev $EXTERNAL parent 1:10 handle 10: sfq perturb 10
$TC qdisc add dev $EXTERNAL parent 1:11 handle 10: sfq perturb 10
$TC qdisc add dev $EXTERNAL parent 1:20 handle 20: sfq perturb 10
$TC qdisc add dev $EXTERNAL parent 1:21 handle 20: sfq perturb 10
$TC qdisc add dev $EXTERNAL parent 1:30 handle 30: sfq perturb 10
$TC qdisc add dev $EXTERNAL parent 1:31 handle 30: sfq perturb 10
}
stop() {
$TC qdisc del dev $EXTERNAL root
# $TC qdisc del dev $UPPER root
# $TC qdisc del dev $MIDDLE root
# $TC qdisc del dev $LOWER root
}
restart() {
stop
sleep 1
start
}
status() {
echo "Traffic shaping"
echo ""
echo $EXTERNAL . ":"
$TC qdisc show dev $EXTERNAL
$TC class show dev $EXTERNAL
$TC filter show dev $EXTERNAL
echo ""
echo $UPPER . ":"
$TC qdisc show dev $UPPER
$TC class show dev $UPPER
$TC filter show dev $UPPER
echo ""
echo $MIDDLE . ":"
$TC qdisc show dev $MIDDLE
$TC class show dev $MIDDLE
$TC filter show dev $MIDDLE
echo ""
echo $LOWER . ":"
$TC qdisc show dev $LOWER
$TC class show dev $LOWER
$TC filter show dev $LOWER
echo ""
}
case "$1" in
start)
echo -n "Starting bandwidth shaping: "
start
echo "done"
;;
stop)
echo -n "Stopping bandwidth shaping: "
stop
echo "done"
;;
restart)
echo -n "Restarting bandwidth shaping: "
restart
echo "done"
;;
status)
status
;;
*)
echo "Usage: /etc/init.d/traffic_shaping.sh {start|stop|restart|status}"
;;
esac
exit 0
Notice that I don't use all my variables at this time.
This is my "status" when it is up and running:
Code:
sudo: unable to resolve host server
Traffic shaping
eth1 . :
qdisc htb 1: root r2q 10 default 60 direct_packets_stat 3
qdisc sfq 10: parent 1:10 limit 127p quantum 1514b perturb 10sec
qdisc sfq 20: parent 1:20 limit 127p quantum 1514b perturb 10sec
qdisc sfq 30: parent 1:30 limit 127p quantum 1514b perturb 10sec
class htb 1:11 parent 1:1 prio 0 rate 345000bit ceil 691000bit burst 1599b cburst 1599b
class htb 1:10 parent 1:1 leaf 10: prio 0 rate 3686Kbit ceil 7372Kbit burst 1599b cburst 1598b
class htb 1:1 root rate 7372Kbit ceil 7372Kbit burst 1598b cburst 1598b
class htb 1:31 parent 1:1 prio 2 rate 172000bit ceil 345000bit burst 1599b cburst 1599b
class htb 1:20 parent 1:1 leaf 20: prio 1 rate 3686Kbit ceil 3686Kbit burst 1599b cburst 1599b
class htb 1:30 parent 1:1 leaf 30: prio 2 rate 1843Kbit ceil 3686Kbit burst 1599b cburst 1599b
class htb 1:21 parent 1:1 prio 1 rate 172000bit ceil 345000bit burst 1599b cburst 1599b
eth2 . :
qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
eth3 . :
qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
eth0 . :
qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
The biggest problem is that it is hard to get a grasp over TC and HTB which is why I thought someone here could help guide me or maybe provide a solution to solve why the Internet goes slower with this setup.