Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2005
    Posts
    1

    Htb, imq and sfq traffic shaping problem


    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

  2. #2
    Just Joined!
    Join Date
    Sep 2008
    Posts
    1
    I guess that, you need to specify the "perturb"

    for example

    # add main rate limit classes
    tc class add dev $DEV parent 1: classid 1:1 htb rate ${RATEUP}kbit

    # add leaf classes - We grant each class at LEAST it's "fair share" of bandwidth.
    # this way no class will ever be starved by another class. Each
    # class is also permitted to consume all of the available bandwidth
    # if no other classes are in use.
    tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[$RATEUP/7]kbit ceil ${RATEUP}kbit prio 0
    tc class add dev $DEV parent 1:1 classid 1:21 htb rate $[$RATEUP/7]kbit ceil ${RATEUP}kbit prio 1
    tc class add dev $DEV parent 1:1 classid 1:22 htb rate $[$RATEUP/7]kbit ceil ${RATEUP}kbit prio 2
    tc class add dev $DEV parent 1:1 classid 1:23 htb rate $[$RATEUP/7]kbit ceil ${RATEUP}kbit prio 3
    tc class add dev $DEV parent 1:1 classid 1:24 htb rate $[$RATEUP/7]kbit ceil ${RATEUP}kbit prio 4
    tc class add dev $DEV parent 1:1 classid 1:25 htb rate $[$RATEUP/7]kbit ceil ${RATEUP}kbit prio 5
    tc class add dev $DEV parent 1:1 classid 1:26 htb rate $[$RATEUP/7]kbit ceil ${RATEUP}kbit prio 6

    # attach qdisc to leaf classes - here we at SFQ to each priority class. SFQ insures that
    # within each class connections will be treated (almost) fairly.
    tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
    tc qdisc add dev $DEV parent 1:21 handle 21: sfq perturb 10
    tc qdisc add dev $DEV parent 1:22 handle 22: sfq perturb 10
    tc qdisc add dev $DEV parent 1:23 handle 23: sfq perturb 10
    tc qdisc add dev $DEV parent 1:24 handle 24: sfq perturb 10
    tc qdisc add dev $DEV parent 1:25 handle 25: sfq perturb 10
    tc qdisc add dev $DEV parent 1:26 handle 26: sfq perturb 10


    from : ADSL Bandwidth Management HOWTO

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •