Jump to content

Bandwidth throttling?


Steve Scrimpshire
 Share

Recommended Posts

I read this topic and went and looked at the URL and tried what was suggested there using this script (the cbq one) and just changing the lines mentioned in the tutorial. This caused everything to timeout. So, I went back into the script and changed this line:

tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit

 

to this:

 

tc qdisc add dev $DEV root handle 1: cbq avpkt 576 bandwidth 45kbit

 

I'm on dialup sharing my connection (ppp0) through eth0 with a WinXP box downstairs. What I'm attempting to do is to stop the downloading of MP3s from downstairs hogging so much bandwidth and slowing me down. Am I doing the right thing?

Link to comment
Share on other sites

I've tried and tried. Can't get it to work. All I want to do is to lower the amount of bandwidth that my downstairs computer can use.

 

dialup modem -> Upstairs -> eth0 -> Downstairs

 

It really shouldn't be that hard. I'm using iptables and QoS is compiled into the kernel.

Link to comment
Share on other sites

First of all, why didn't you follow up the other thread? I'd have been able to answer sooner if you didn't start a new thread. (from an ex-mod to another ex-mod)

 

OK, you have almost the same setup I have:

 

INTERNET <--ippp0/1 (ISDN)--> [Downstairs PC] <--eth0--> [upstairs PC]

 

So I hacked the script mentioned in the original thread (I'm still hacking it since is experimental and I haven't touched most of the origninal stuff), to allow me not only to control the internet interface (ippp0) but also to control the bandwith of the LAN interface, so when my brother is kazaaing upstairs I'm able to limit his bandwith. :evil:

 

Here is the script (it is experimental but is working the way I want, though I don't understand much of the tc stuff used):

 

#! /bin/bash

# ----------------------------------------------------------------------------

# PROGRAM:  tuic

# VERSION:  $Id: tuic,v 1.5 2003/05/10 17:47:04 aru Exp aru $  

# PURPOSE:  <The Ultimate Internet Connection> Optimiza la Conexion a Internet

# DATE:     25-04-2003

# AUTHOR:   aru <catactttc@nospammail.net>

#

# USAGE:    tuic [-v] [-h] [-D dev] -d int -u int

#           tuic -C dev

#           Options:

#               -d  Downlink Speed in Kbits (int).

#               -u  Uplink Speed in Kbits (int).

#               -D  Device (ippp0, eth0,...); default ippp0.

#               -C  Device (ippp0, eth0,...); no default is set.

#               -v  Shows version and exits.

#               -h  Shows this help.

#

# FILES:    /var/lock/subsys/ipppd_{64,128} Lock File of the isdn system.

#

# LICENSE:  This program is free software; you can redistribute it and/or 

#           modify it under the terms of the GNU General Public License as 

#           published by the Free Software Foundation; either version 2, 

#           or (at your option) any later version.

#

# NOTES:    The Ultimate Setup For Your Internet Connection At Home.

#           Sacado de: http://lartc.org/howto/lartc.cookbook.ultimate-tc.html

#           gracias a: http://www.linuxjournal.com/article.php?sid=6825

#           The values used should be somewhat less than your actual download

#           and uplink speed. In kilobits

#           To see loaded values run:

#               /sbin/tc [filter|class|qdisc] show dev ippp0

#

# HISTORY:

# $Log: tuic,v $

# Revision 1.5  2003/05/10 17:47:04  aru

#

# Revision 1.4  2003/05/06 17:41:06  aru

# Añadidio control sobre cualquier interfaz de red (ippp0, eth0...)

# Añadida la posibilidad de "limpiar" las reglas mediante -C interfaz

#

# 05-05-2003  Prototiped to handle different ISDN speeds.

# 24-04-2003  First version; script "tuic" release

# ----------------------------------------------------------------------------



PROGRAM=${0##*/} 

VER="$Revision: 1.5 $" # RCS version



# Script Vars ----------------------------------------------------------------

# ----------------------------------------------------------------------------

DEV=ippp0 # ISDN



# Velocidades por defecto (Kilobits)

v64_DOWNLINK=56   # Single ISDN _

v64_UPLINK=50     # Single ISDN /

v128_DOWNLINK=112 # Double ISDN _

v128_UPLINK=100   # Double ISDN /



# Defaults:

DOWNLINK=${v64_DOWNLINK}

UPLINK=${v64_UPLINK}



LOCK_DIR=/var/lock/subsys

v64_LOCK_FILE=${LOCK_FILE}/ipppd_64

v128_LOCK_FILE=${LOCK_FILE}/ipppd_128



# Functions ------------------------------------------------------------------

# ----------------------------------------------------------------------------

usage () {

   # Shows the program usage striped from the script-head comments.

   sed -n "

       /^# PURPOSE:  / {s/// p;}

       /^# USAGE/,/^#$/ {s/ USAGE:  /Usage:/; s/^[# ]{1,12}// p;}

       " ${0}

}



error () {

   # -> error "description"

   echo -e "${@:-$(usage)}" >&2

   exit 1

}



showVer () { echo "$PROGRAM, ver: $(echo $VER | sed 's/.*: (.*)$/1/')"; }





cleanQDiscs () {

   # clean existing down- and uplink qdiscs, hide errors

# Uso-> cleanQDiscs DEVICENAME

   tc qdisc del dev ${1} root    &> /dev/null

   tc qdisc del dev ${1} ingress &> /dev/null

}



# Main -----------------------------------------------------------------------

# ----------------------------------------------------------------------------

# command line default options:

cmdl_opts=$#

if [ $cmdl_opts -eq 0 ]; then

   # codigo para saber a que velocidad vamos:

   lockfile="$(/bin/ls ${LOCK_FILE})"

   case "$lockfile" in

       ${v128_LOCK_FILE}) 

           DOWNLINK=${v128_DOWNLINK}

           UPLINK=${v128_UPLINK}

          ;;

       ${v64_LOCK_FILE}|*) : # Use the defaults

          ;;

   esac

else

   while getopts ":vhd:u:D:C:" option; do

   case ${option} in

       v) showVer && exit 0;; # Shows the version number

       h) showVer && usage && exit 0;; # help.

       d) DOWNLINK=${OPTARG};; # definido por el usuario

       u) UPLINK=${OPTARG};; # definido por el usuario

       C) cleanQDiscs ${OPTARG}; exit $?;; # Limpia las reglas del dev especificado

       D) DEV=${OPTARG};; # definido por el usuario

       *) error;;

   esac

   done

fi



# Setting all the stuff ------------------------------------------------------

# ----------------------------------------------------------------------------

# clean existing down- and uplink qdiscs, hide errors

cleanQDiscs $DEV



###### uplink

# install root CBQ

tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 10mbit



# shape everything at $UPLINK speed - this prevents huge queues in your

# DSL modem which destroy latency:

# main class

tc class add dev $DEV parent 1: classid 1:1 cbq rate ${UPLINK}kbit 

allot 1500 prio 5 bounded isolated



# high prio class 1:10:

tc class add dev $DEV parent 1:1 classid 1:10 cbq rate ${UPLINK}kbit 

  allot 1600 prio 1 avpkt 1000



# bulk and default class 1:20 - gets slightly less traffic,

#  and a lower priority: #(*) (cambiar el $[9* por algo mas bajo)

tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $((9*${UPLINK}/10))kbit 

  allot 1600 prio 2 avpkt 1000



# both get Stochastic Fairness:

tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10

tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10



# start filters

# TOS Minimum Delay (ssh, NOT scp) in 1:10:

tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 

     match ip tos 0x10 0xff  flowid 1:10



# ICMP (ip protocol 1) in the interactive class 1:10 so we

# can do measurements & impress our friends:

tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 

match ip protocol 1 0xff flowid 1:10



# To speed up downloads while an upload is going on, put ACK packets in

# the interactive class:

tc filter add dev $DEV parent 1: protocol ip prio 12 u32 

  match ip protocol 6 0xff 

  match u8 0x05 0x0f at 0 

  match u16 0x0000 0xffc0 at 2 

  match u8 0x10 0xff at 33 

  flowid 1:10



# rest is 'non-interactive' ie 'bulk' and ends up in 1:20

tc filter add dev $DEV parent 1: protocol ip prio 13 u32 

  match ip dst 0.0.0.0/0 flowid 1:20



########## downlink #############

# slow downloads down to somewhat less than the real speed  to prevent

# queuing at our ISP. Tune to see how high you can set it.

# ISPs tend to have *huge* queues to make sure big downloads are fast

#

# attach ingress policer:

tc qdisc add dev $DEV handle ffff: ingress



# filter *everything* to it (0.0.0.0/0), drop everything that's

# coming in too fast: #(*) Recomiendan usar $[9*${DOWNLINK}/10]kbit y 2k en el burst

tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src 

  0.0.0.0/0 police rate $((9*${DOWNLINK}/10))kbit burst 6k drop flowid :1

 

How to use it:

 

If I want to run it how it was meant to be originally (over the ippp0 connection and with the default values written in the script), I just do:

~# tuic

And the script itself manages to diference from a SINGLE ISDN connection an a DOUBLE ISDN connection.

 

If I want to change the upload and download values, I do:

~# tuic -d <download value in Kbits> -u <upload value in Kbits>

 

If I want to limit the bandwith of the eth0 interface, I do:

~# tuic -D eth0 -d <download value in Kbits> -u <upload value in Kbits>

 

If I want to restore (clean) the original bandwith of any of the devices I just run "tuic -C device_name", for example:

~# tuic -C eth0

 

HTH, and sorry for the comments in spanish inside the script; also notice that some/many things in the script (such as LOCKS) work only on my particular network setup.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...