From: Date: Thu, 24 May 2007 12:24:18 +0000 Subject: RE: [LARTC] tc-htb traffic shaping script Message-Id: <50BD9F2BCFC52840934CBADBBA4481B209758789@aspmail01.ApplicationNet.nl> MIME-Version: 1 Content-Type: multipart/mixed; boundary="----_=_NextPart_001_01C79DFE.73EDD6F0" List-Id: References: <13c1e7670705240346y6f1728cfi37409d8f20153d2d@mail.gmail.com> In-Reply-To: <13c1e7670705240346y6f1728cfi37409d8f20153d2d@mail.gmail.com> To: lartc@vger.kernel.org This is a multi-part message in MIME format. --===============0748351226== Content-class: urn:content-classes:message Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C79DFE.73EDD6F0" This is a multi-part message in MIME format. ------_=_NextPart_001_01C79DFE.73EDD6F0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable 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 =20 =20 #!/bin/bash =20 # 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 # =20 # # Name of the traffic control command. TC=3D/sbin/tc IPTABLES=3D/sbin/iptables =20 # The network interface we're planning on limiting bandwidth. IF1=3Deth1.106 # Interface IF2=3Deth0 # Interface =20 # Download limit (in mega bits) DNLD=3D100mbit # DOWNLOAD Limit =20 # Upload limit (in mega bits) UPLD=3D100mbit # UPLOAD Limit =20 # IP address of the machine we are controlling #IP=3D81.18.0.0/24 #Host IP #IP=3D0.0.0.0/0 #Host IP =20 # Filter options for limiting the intended interface. IN=3D"$TC filter add dev $IF2 protocol ip parent 1:0 prio 1" OUT=3D"$TC filter add dev $IF1 protocol ip parent 2:0 prio 1" =20 start() { =20 # 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 =20 # INBOUND matches on fwmark 106 and gets shaped when it leaves the IF2 interface =20 $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 =20 printf "\n" printf "Shaping traffic incoming on $IF1 =3D=3D> $IF2 to max. $DNLD" =20 # OUTBOUND matches all traffic heading out IF1 gets shaped, no filter needed =20 $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 =20 printf "\n" printf "Shaping traffic incoming on $IF2 =3D=3D> $IF1 to max. = $UPLD\n" =20 # 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. =20 } =20 stop() { =20 # 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 =20 } =20 restart() { =20 # Self-explanatory. stop sleep 1 start =20 } =20 show() { =20 # Display status of traffic control status. # $TC -s qdisc ls dev $IF1 $TC -s qdisc ls dev $IF2 =20 } =20 case "$1" in =20 start) =20 echo -n "Starting bandwidth shaping: " start echo "done" ;; =20 stop) =20 echo -n "Stopping bandwidth shaping: " stop echo "done" ;; =20 restart) =20 echo -n "Restarting bandwidth shaping: " restart echo "done" ;; =20 show) =20 echo "Bandwidth shaping status for $IF2:" show echo "" ;; =20 *) =20 pwd=3D$(pwd) echo "Usage: tc.bash {start|stop|restart|show}" ;; =20 esac =20 exit 0 =20 =20 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 =20 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=20 I am n new bie and need to work on htb. --=20 Regards, M Arman ------_=_NextPart_001_01C79DFE.73EDD6F0 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable

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=3D/sbin/tc

IPTABLES=3D/sbin/iptables

 

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

IF1=3Deth1.106       &n= bsp;    # Interface

IF2=3Deth0        =         # Interface

 

# Download limit (in mega bits)

DNLD=3D100mbit       &n= bsp;  # DOWNLOAD Limit

 

# Upload limit (in mega bits)

UPLD=3D100mbit       &n= bsp;  # UPLOAD Limit

 

# IP address of the machine we are = controlling

#IP=3D81.18.0.0/24      &nbs= p;         #Host IP

#IP=3D0.0.0.0/0       &= nbsp;           #Host IP

 

# Filter options for limiting the intended = interface.

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

OUT=3D"$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 =3D=3D> $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 =3D=3D> $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=3D$(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/proj= ects/cbq.init

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

--
Regards,
M Arman

------_=_NextPart_001_01C79DFE.73EDD6F0-- --===============0748351226== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ LARTC mailing list LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc --===============0748351226==--