Re: Htb, imq and sfq traffic shaping

Linux Advanced Routing and Traffic Control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




You shouldn't point your filters to the sfq qdisc, point then to the leaf classes that have sfq qdiscs as child.


Andre


Ixen Gerthannes wrote:
Hello,
I wrote a simple traffic shaping script (below) that should have allowed me to shape my internet traffic a bit (ppp0 - adsl 128kbit/64kbit; local interface eth0).
The script works only partially - the speed is being limited but too much. Without running this script my download rate is about 10kBytes (with second computer also downloading at about 6kBytes). After running it my download speed decreases to about 1..2kBytes and so the second computer.
Could you tell me what have I done wrong ?

Thank you for replies.
Ixen

--------------
My configuration:
Celeron 450MHz, 256MB RAM
Kernel 2.6.9 patched for imq support (imq devices compiled into kernel)
iptables 1.2.11 (also patched for imq)

Script:
#!/bin/sh

DOWNIF='imq0'
UPIF='imq1'
rc_done="  done"
rc_failed="  failed"

TC='/sbin/tc'
IPTABLES='/usr/sbin/iptables'
IFCONFIG='/sbin/ifconfig'
MODPROBE='/sbin/modprobe'

return=$rc_done

tc_reset ()
{
    # remove old devices if any
    echo "Removing old root qdisc..."
    $TC qdisc del dev $DOWNIF root
    $TC qdisc del dev $UPIF root
}

tc_status ()
{
    echo "========================================"
    echo "[qdisc - $DOWNIF]"
    $TC -s qdisc show dev $DOWNIF
    echo "[qdisc - $UPIF]"
    $TC -s qdisc show dev $UPIF
    echo "----------------------------------------"
    echo
    echo "[class - $DOWNIF]"
    $TC -s class show dev $DOWNIF
    echo "[class - $UPIF]"
    $TC -s class show dev $UPIF
}

tc_showfilter ()
{
echo "[filter - $DOWNIF]"
$TC -s filter show dev $DOWNIF
echo "[filter - $UPIF]"
$TC -s filter show dev $UPIF
}

case "$1" in

start)
echo "Starting traffic shaping..."
tc_reset
# setup imq devices - imq0 for download, imq1 for upload
# $MODPROBE imq numdevs 2


    $IFCONFIG imq0 up
    $IFCONFIG imq1 up

# ROOT DEVICE
echo " Setting root devices for $DOWNIF and $UPIF"
# download
$TC qdisc add dev $DOWNIF root handle 1: htb default 99
$TC qdisc add dev $DOWNIF parent 1: classid 1:10 htb rate 128kbit
# upload
$TC qdisc add dev $UPIF root handle 1: htb default 98
$TC class add dev $UPIF parent 1: classid 1:20 htb rate 64kbit
# ADDRESSES
echo " 192.168.0.30"
# 192.168.0.30
$TC class add dev $DOWNIF parent 1:10 classid 1:1000 htb rate 48kbit ceil 128kbit
$TC qdisc add dev $DOWNIF parent 1:1000 handle 1000 sfq
$TC filter add dev $DOWNIF parent 1:0 protocol ip prio 200 handle 1000 fw classid 1:1000
$TC class add dev $UPIF parent 1:20 classid 1:2000 htb rate 24kbit ceil 64kbit
$TC qdisc add dev $UPIF parent 1:2000 handle 2000 sfq
$TC filter add dev $UPIF parent 1:0 protocol ip prio 200 handle 2000 fw classid 1:2000
$IPTABLES -t mangle -A POSTROUTING -d 192.168.0.30 -j MARK --set-mark 1000
$IPTABLES -t mangle -A POSTROUTING -s 192.168.0.30 -j MARK --set-mark 2000
# 192.168.0.178
echo " 192.168.0.178"
$TC class add dev $DOWNIF parent 1:10 classid 1:1010 htb rate 16kbit ceil 100kbit
$TC qdisc add dev $DOWNIF parent 1:1010 handle 1010 sfq
$TC filter add dev $DOWNIF parent 1:0 protocol ip prio 200 handle 1010 fw classid 1:1010
$TC class add dev $UPIF parent 1:20 classid 1:2010 htb rate 8kbit ceil 60kbit
$TC qdisc add dev $UPIF parent 1:2010 handle 2010 sfq
$TC filter add dev $UPIF parent 1:0 protocol ip prio 200 handle 2010 fw classid 1:2010


    $IPTABLES -t mangle -A POSTROUTING -d 192.168.0.178 -j MARK --set-mark 1010
    $IPTABLES -t mangle -A POSTROUTING -s 192.168.0.178 -j MARK --set-mark 2010

# 192.168.0.55
echo " 192.168.0.55"
$TC class add dev $DOWNIF parent 1:10 classid 1:1020 htb rate 16kbit ceil 100kbit
$TC qdisc add dev $DOWNIF parent 1:1020 handle 1020 sfq
$TC filter add dev $DOWNIF parent 1:0 protocol ip prio 200 handle 1020 fw classid 1:1020
$TC class add dev $UPIF parent 1:20 classid 1:2020 htb rate 8kbit ceil 60kbit
$TC qdisc add dev $UPIF parent 1:2020 handle 2020 sfq
$TC filter add dev $UPIF parent 1:0 protocol ip prio 200 handle 2020 fw classid 1:2020


    $IPTABLES -t mangle -A POSTROUTING -d 192.168.0.55 -j MARK --set-mark 1020
    $IPTABLES -t mangle -A POSTROUTING -s 192.168.0.55 -j MARK --set-mark 2020

# other
echo " other..."
$TC class add dev $DOWNIF parent 1:10 classid 1:99 htb rate 100bit ceil 8kbit
$TC class add dev $UPIF parent 1:20 classid 1:98 htb rate 100bit ceil 8kbit
# route traffic
echo " Traffic redirecting"
# download
$IPTABLES -t mangle -A POSTROUTING -d 192.168.0.0/24 -j IMQ --todev 0
#upload
$IPTABLES -t mangle -A POSTROUTING -s 192.168.0.0/24 -j IMQ --todev 1


tc_status
;;
stop)
echo -n "Stopping traffic shaper..."
tc_reset || return=$rc_failed
echo -e "$return"
;;
restart|reload)
$0 stop && $0 start || return=$rc_failed
;;
stats|status)
tc_status
;;

filter)
tc_showfilter
;;
*)
echo "Usage: $0 {start|stop|restart|stats|filter}"
esac
_______________________________________________
LARTC mailing list / LARTC@xxxxxxxxxxxxxxx
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/





--
-----------------------------------------------------------------------
Confidentiality Notice: This e-mail communication and any attachments may contain confidential and privileged information for the use of the designated recipients named above. If you are not the intended recipient, you are hereby notified that you have received this communication in error and that any review, disclosure, dissemination, distribution or copying of it or its contents is prohibited. If you have received this communication in error, please notify me immediately by replying to this message and deleting it from your computer.


Thank you.
_______________________________________________
LARTC mailing list / LARTC@xxxxxxxxxxxxxxx
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/

[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux