LARTC
[Top] [All Lists]

Re: [LARTC] tc-htb traffic shaping script

To: "beere@vertis.nl" <beere@vertis.nl>, lartc@mailman.ds9a.nl
Subject: Re: [LARTC] tc-htb traffic shaping script
From: "Marco Aurelio" <marco.casaroli@gmail.com>
Date: Thu, 24 May 2007 13:57:14 -0300
Delivered-to: sp-com-lists@consult.net
Delivered-to: lartc-list@securepoint.com
Delivered-to: lartc@outpost.ds9a.nl
Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=cVK3faa5h2jt39PP2BbQq/+tle8820Ubjd84+NVgfU2moESw0CiuxPFkmneoHTO5mivUNEIfdrRWZ0u1Gry4L5YwiuVAma4nLVDXqjy8Y9lo8a8vIRgxvU6XsoiJvJFDrzFsgLEotiHFDDYHfW6F7dAM2pcIWzjD5MqgG5GuzaU=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PpMydsqiWeD68UHy9LIIwWlFKJ5DSjMtG9eTqFNvYz7o7Svi7VbL6g3ErVBP+OGBXD7nQiBQI7uqbE78e+JN7IAyf4AErZ0q8pfxqYtCJybu+1MO9oOJPVVr6VrlhQTmkioQw5EpnAszdCszfMSDZIRyq7pYWsztwI6GLGnTC5Y=
In-reply-to: <50BD9F2BCFC52840934CBADBBA4481B209758789@aspmail01.ApplicationNet.nl>
List-archive: <http://mailman.ds9a.nl/pipermail/lartc>
List-help: <mailto:lartc-request@mailman.ds9a.nl?subject=help>
List-id: "Mailinglist of the Linux Advanced Routing &amp; Traffic Control project" <lartc.mailman.ds9a.nl>
List-post: <mailto:lartc@mailman.ds9a.nl>
List-subscribe: <http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc>, <mailto:lartc-request@mailman.ds9a.nl?subject=subscribe>
List-unsubscribe: <http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc>, <mailto:lartc-request@mailman.ds9a.nl?subject=unsubscribe>
References: <13c1e7670705240346y6f1728cfi37409d8f20153d2d@mail.gmail.com> <50BD9F2BCFC52840934CBADBBA4481B209758789@aspmail01.ApplicationNet.nl>
Sender: lartc-bounces@mailman.ds9a.nl
http://lartc.org/wondershaper/

On 5/24/07, beere@vertis.nl <beere@vertis.nl> wrote:




I can send you mine, it's a modified version of one I found somewhere on the
net to be able to limit bandwith on a linux router. I did no cleaning up or
anything





#!/bin/bash



#  tc uses the following units when passed as a parameter.

#  kbps: Kilobytes per second

#  mbps: Megabytes per second

#  kbit: Kilobits per second

#  mbit: Megabits per second

#  bps: Bytes per second

#       Amounts of data can be specified in:

#       kb or k: Kilobytes

#       mb or m: Megabytes

#       mbit: Megabits

#       kbit: Kilobits

#  To get the byte figure from bits, divide the number by 8 bit

#



#

# Name of the traffic control command.

TC=/sbin/tc

IPTABLES=/sbin/iptables



# The network interface we're planning on limiting bandwidth.

IF1=eth1.106            # Interface

IF2=eth0                # Interface



# Download limit (in mega bits)

DNLD=100mbit          # DOWNLOAD Limit



# Upload limit (in mega bits)

UPLD=100mbit          # UPLOAD Limit



# IP address of the machine we are controlling

#IP=81.18.0.0/24                #Host IP

#IP=0.0.0.0/0                   #Host IP



# Filter options for limiting the intended interface.

IN="$TC filter add dev $IF2 protocol ip parent 1:0 prio 1"

OUT="$TC filter add dev $IF1 protocol ip parent 2:0 prio 1"



start() {



# All traffic originating from IF1 gets marked

    $IPTABLES -t mangle -D PREROUTING -i $IF1 -j MARK --set-mark 106
>/dev/null 2>&1

    $IPTABLES -t mangle -A PREROUTING -i $IF1 -j MARK --set-mark 106



# INBOUND matches on fwmark 106 and gets shaped when it leaves the IF2
interface



    $TC qdisc add dev $IF2 root handle 1: htb default 30

    $TC class add dev $IF2 parent 1: classid 1:1 htb rate $DNLD

    $IN handle 106 fw flowid 1:1



    printf "\n"

    printf "Shaping traffic incoming on $IF1 ==> $IF2 to max. $DNLD"



# OUTBOUND matches all traffic heading out IF1 gets shaped, no filter needed



    $TC qdisc add dev $IF1 root handle 2: htb default 1

    $TC class add dev $IF1 parent 2: classid 2:1 htb rate $UPLD

#    $OUT u32 match ip src $IP flowid 2:1



    printf "\n"

    printf "Shaping traffic incoming on $IF2 ==> $IF1 to max. $UPLD\n"



# The first line creates the root qdisc, and the next line

# creates a child qdiscs that respectively are used to shape download

# and upload bandwidth. The third line defines a filter if required.



}



stop() {



# Stop the bandwidth shaping.

    $TC qdisc del dev $IF1 root

    $TC qdisc del dev $IF2 root

    $IPTABLES -t mangle -D PREROUTING -i $IF1 -j MARK --set-mark 106



}



restart() {



# Self-explanatory.

    stop

    sleep 1

    start



}



show() {



# Display status of traffic control status.

#    $TC -s qdisc ls dev $IF1

    $TC -s qdisc ls dev $IF2



}



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"

    ;;



  show)



    echo "Bandwidth shaping status for $IF2:"

    show

    echo ""

    ;;



  *)



    pwd=$(pwd)

    echo "Usage: tc.bash {start|stop|restart|show}"

    ;;



esac



exit 0






From: lartc-bounces@mailman.ds9a.nl [mailto:lartc-bounces@mailman.ds9a.nl]
On Behalf Of Arman
 Sent: donderdag 24 mei 2007 12:46
 To: lartc@mailman.ds9a.nl
 Subject: [LARTC] tc-htb traffic shaping script




Hi,

    Is there any tested good HTB script for traffic shaping available like
as that of CBQ available at.

      http://freshmeat.net/projects/cbq.init

    I am n new bie and need to work on htb.

 --
 Regards,
 M Arman
_______________________________________________
LARTC mailing list
LARTC@mailman.ds9a.nl
http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc




--
Marco
_______________________________________________
LARTC mailing list
LARTC@mailman.ds9a.nl
http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc

<Prev in Thread] Current Thread [Next in Thread>