Slackware Linux trafic shaping dedicated server
last updated 28.11.2004

Slackware Linux 10.0
Kernel 2.4.28
Bridging - OPTIONAL - use this only if you use all these programs on dedicated servers
HTB tool - limit/guarantee upload and download


// Begin disclaimer // I'm not responsible for the way you use this information. It is the description that I have used and it works in the conditions that I have described. If the computer on which you install & configure htb-tools, bridging goes insane or breaks - it's not my responsability. // End disclaimer //

Slackware Linux 10.0   http://www.slackware.com
     Install Slackware Linux - Slackware-HOWTO - in english
     Install Slackware Linux - Slackware-HOWTO - in romanian


Kernel 2.4.28   http://www.kernel.org
     - the default kernel in slackware linux 10.0 can be used, it already has all needed options preselected
     - if you compile from sources, you will need the following options for HTB:

#
# QoS and/or fair queueing
#
CONFIG_NET_SCHED=y
CONFIG_NET_SCH_CBQ=m
CONFIG_NET_SCH_HTB=m
CONFIG_NET_SCH_CSZ=m
CONFIG_NET_SCH_HFSC=m
CONFIG_NET_SCH_PRIO=m
CONFIG_NET_SCH_RED=m
CONFIG_NET_SCH_SFQ=m
CONFIG_NET_SCH_TEQL=m
CONFIG_NET_SCH_TBF=m
CONFIG_NET_SCH_GRED=m
CONFIG_NET_SCH_DELAY=m
CONFIG_NET_SCH_DSMARK=m
CONFIG_NET_SCH_INGRESS=m
CONFIG_NET_QOS=y
CONFIG_NET_ESTIMATOR=y
CONFIG_NET_CLS=y
CONFIG_NET_CLS_TCINDEX=m
CONFIG_NET_CLS_ROUTE4=m
CONFIG_NET_CLS_ROUTE=y
CONFIG_NET_CLS_FW=m
CONFIG_NET_CLS_U32=m
CONFIG_NET_CLS_RSVP=m
CONFIG_NET_CLS_RSVP6=m
CONFIG_NET_CLS_POLICE=y


Linux bridging   http://bridge.sourceforge.net

     - prior to using bridge utilities you need to compile kernel support for bridging:

#
# Appletalk devices
#
...
CONFIG_BRIDGE=y
...

     - download bridging utilities
http://keihanna.dl.sourceforge.net/sourceforge/bridge/bridge-util s-1.0.4.tar.gz

     - before you begin compiling, make sure that the two NICs are properly set, meaning the drivers are loaded and working

     DO NOT SET ANY IP ON THE NICs, DEACTIVATE ANY SCRIPT THAT MIGHT SET IPs ON THE NICs (DHCP) run ifconfig eth0 down and ifconfig eth1 down to make sure there is no active NIC, deactivate even the loopback ifconfig lo down.
     For those who use Slackware comment using # all lines from /etc/rc.d/rc.inet1 to make sure that, on boot, no NIC will be activated.

The IPs will be set after the utilities are compiled/installed.

     - configure; make; make install - these are the commands that need to be ran after extracting the sources;
     - to make it easier to set interfaces as well as the bridge, download this script (rc.bridge) and copy it in /etc/rc.d/ directory;
     - after doing all this, rc.bridge needs to be made executable (chmod +x rc.bridge) and must be executed from /etc/rc.d/rc.local; to accomplish that, add to rc.local the following line which at boot will bring up the bridge :

/etc/rc.d/rc.bridge


HTB tool - http://www.arny.ro/htb/htb_tools-0.2.5.tar.gz
   
      Hierarchical Token Bucket ( HTB ) successfully replaces Class Based Queueing ( CBQ ) due to the precise and easy to understand for everybody way it operates. The diference to CBQ is that bandwidth is allocated to one (or more) class, and the moment when the bandwidth that is allocated to the class is overrun, it can borrow (temporary) bandwidth from other class which does not use all bandwidth. More then that, unlike CBQ, you can allocate several clients to one class. All clients and classes are defined in a configuration file

      Using a series of programs (HTB Tools) you can simplify the configuration and monitoring of bandwidth allocations for both upload and download.
- q_parser reads a configuration file (clients, classes, bandwidth allocations are set in this file) and it generates a script which actually defines the scheduler's behaviour ;
- q_show displays in real-time the bandwidth used/allocated for each class/client set in the configuration file
- q_checkcfg is used for checking the configuration file.

      To better understand how it works, the example will use a 256kbps bandwidth, shared by 4 clients, each client having 48kbps guaranteed, and max 64kbps upload/download (48 kbps CIR, 64 kbps MIR).

      - download the sources htb_tools-0.2.5.tar.gz from http://www.arny.ro/htb/htb_tools-0.2.5.tar.gz

      - extract and compile the sources:

root@slackware:/home/arny# tar -zxvf htb_tools-0.2.5.tar.gz
root@slackware:/home/arny# cd htb_tools-0.2.5
root@slackware:/home/arny/htb_tools-0.2.5# make

        - after compiling you will have the bin files q_parser, q_show and q_checkcfg;

- run make install to install: q_parser, q_show, q_checkcfg, htb, tc in /sbin directory, and configuration files eth0-qos.cfg for upload, eth1-qos.cfg for download, to /etc/htb directory;

- install q_show.php if you want to see real time trafic on the web. This can be done using make install_web command. Detailed configuration/instalation can be found here.

       - the config files from /etc/htb will be checked to be corect:

q_checkcfg /etc/htb/eth0-qos.cfg

Default bandwidth: 8

Class class_1, CIR: 192, MIR: 256
** 4 clients, CIR2: 192, MIR2: 256

1 classes; CIR / MIR = 192 / 256; CIR2 / MIR2 = 192 / 256

q_checkcfg /etc/htb/eth1-qos.cfg

Default bandwidth: 8

Class class_1, CIR: 192, MIR: 256
** 4 clients, CIR2: 192, MIR2: 256

1 classes; CIR / MIR = 192 / 256; CIR2 / MIR2 = 192 / 256
- the config files are syntactically correct

      I've made a script for those who use Slackware Linux. Using this script you can start/stop/monitor alocated/used bandwidth for upload or download or both.
      The script is called rc.htb, needs to have execute permissions and will be copied in /etc/rc.d. In the file you will find each line explained, and also its usage.

      To start the bandwidth policies at boot you need to put in /etc/rc.local this line:

/etc/rc.d/rc.htb start

            - if you wish to limit/guarantee bandwidth only for download the you use:
/etc/rc.d/rc.htb start_eth1

            - if you wish to limit/guarantee the bandwidth only for upload, then you use:

/etc/rc.d/rc.htb start_eth0

The q_show binary alllow you to watch, in real time, the traffic & and the load for each client (download)
       Run:

/etc/rc.d/rc.htb show_eth1

            - you will see the traffic & load
class_1 224.80 2 192 256
 client_1 62.25 1 48 64
 client_2 51.05 1 48 64
 client_3 48.25 1 48 64
 client_4 63.25 1 48 64
_default_ 0 0 0 0

Web q_show
       The idea is simple. First you need to set up a cron job to collect trafic to a file (q_show.log). After that,  the q_show.php script will parse the log file and will output the real time trafic to web. This is done every 60 seconds.

Configuring
      First you need to have a functional http server with php. You need a domain ( ex mydomain.com ) and the default DocumentRoot directory ( /var/www/htdocs/). After you run make, make install, now is time to run make install_web. In /var/www/htdocs/ will be created the webhtb directory where the php script will be installed .

      - add this to crontab (crontab -e): (for details read web/README-en)

*/1 * * * * /sbin/q_show -i eth1 -f /etc/htb/eth1-qos.cfg -1 > /var/www/htdocs/webhtbb/q_show.log

To view the web page with the traffic statistics, type in your browser: http://www.mydomain.com/webhtb/q_show.php
 you should see something like this printscreen.



Documentation:
Install Slackware Linux - Slackware-HOWTO - in english
Install Slackware Linux - Slackware-HOWTO - in romanian

Linux Advanced Routing & Traffic Control HOWTO http://www.lartc.org or http://www.docum.org/;

Bridging HOWTO http://bridge.sourceforge.ne t/howto.html

HTB - tools Implementing Real Time Packet Forwading Policies using HTB.




This document is copyright (c) arny All rights reserved.
Powered by slackware

Page made with Quanta Plus