HOWTO: Bandiwdth control/limiting/prioritising with wondershaper and dsl_qos_queue

Soldato
Joined
18 Oct 2002
Posts
3,984
Location
Cheshire
HOWTO: Bandwidth control/limiting/prioritising with wondershaper and dsl_qos_queue

Linux Traffic shaping / Bandwidth control for newbies mini-HOWTO

Author: Lostie 18/11/2002.
Version 1.00

Prefeace:
Yes I know there are other HOWTO's out there covering similar things, but this HOWTO is written for people who just want to get up and working with the minimum of hassle, and Linux newbies :)

What this can do for you!
This will optimise your connection so that uploading will not affect download speeds and vice-versa. Preserves low latency during a download or an upload (or even both at the same time!) - this means websurfing at good speeds and even online gaming is now possible. The more bandwidth you have the better this will work, even though I've heard of people on 64K ISDN getting great results.

What you will need:
1. A PC with Linux installed. I use Slackware 8.1 (www.slackware.com) with kernel 2.4.19 - so that is what this HOWTO assumes you are using. It will work with any modern distribution, in rare cases a few tweaks may be needed. The PC spec doesn't really matter (486DX+ recommended), but 16mb of RAM or more is a good idea. YOU MUST ALREADY HAVE BOTH YOUR NETWORK CARD AND INTERNET CONNECTION UP AND RUNNING ALREADY. You must also be the ROOT user.
2. One network card (unless your Linux PC is your ONLY PC and you won't be using any others), and an internet device ie. a PPP 56k modem connection, PPP ISDN, PCI/USB ADSL/cable modem, etc. You may instead have a second network card which connects to an ADSL router or cable modem.

Recompiling the kernel:
Re-compiling the kernel is the first thing you need to do. If you've installed Slackware 8.1 it will come with kernel 2.4.18 - this is fine.
1. Type cd /usr/src/linux <enter>.
2. Type make menuconfig (or make xconfig if you are in x-windows).

I'll now go through the options you need to enable.

1. Under Networking options in the MAIN menu, enable the following (do not build ANYTHING as modules unless specified):
Packet socket, Network packet filtering (replaces ipchains), Unix domain sockets, TCP/IP networking, IP: multicasting, IP: advanced router, IP: policy routing, IP: use netfilter MARK value as routing key, IP: fast network address translation, IP: use TOS value as routing key.

2. Under the IP: Netfilter Configuration SUBMENU, enable the following:
Connection tracking (required for masq/NAT), FTP protocol support, IRC protocol support, Userspace queueing via NETLINK (EXPERIMENTAL), IP tables support (required for filtering/masq/NAT), netfilter MARK match support, Multiple port match support, TOS match support, LENGTH match support, Packet filtering, REJECT target support, Full NAT, Packet mangling, TOS target support, MARK target support.

3. Go back to the Networking options MAIN menu, and in the QoS and/or fair queueing SUBMENU, enable the following:
QoS and/or fair queueing, CBQ packet scheduler, The simplest PRIO pseudoscheduler, SFQ queue, Diffserv field marker, Ingress Qdisc, QoS support, Rate estimator, Packet classifier API, TC index classifier, Routing table based classifier, Firewall based classifier, U32 classifier, Special RSVP classifier, Traffic policing (needed for in/egress).

Then exit and SAVE your new kernel configuration.
Next, type the following:
make dep; make bzImage <enter>
This may take some time as your new kernel is being built. After that, you need to replace your old kernel with the new one, so backup your old kernel first with a command like mv /boot/vmlinuz /boot/vmlinuz.old then put in the new one with a command like cd arch/i386/boot; cp bzImage /boot/vmlinuz. Both those commands work fine on Slackware 8.1, you may need to modify them slightly for your distribution.
Next you need to tell LILO that there's a new kernel, so type liloconfig <enter> and re-configure it again.
Then reboot, and fingers crossed your new kernel should boot up and you can log in :D If it doesn't, you probably did something wrong at the lilo config stage, anyway troubleshooting is beyond the scope of this document, sorry ;)

Wondershaper and/or dsl_qos_queue:
dsl_qos_queue: http://www.sonicspike.net/software/download/dsl_qos_queue-0.5.tar.gz
wondershaper: http://lartc.org/wondershaper/wondershaper-1.1a.tar.gz

For wonderhsaper, you will need to get and install iproute2: http://lartc.org/wondershaper/iproute2-2.4.7-now-ss010824.tar.gz

dsl_qos_queue is optimised for ADSL (but will work fine with other connections), it is a userspace daemon that controls upstream bandwidth. It does this much better than wondershaper does.

wondershaper is an upstream/downstream bandwidth control script.

I personally use both, dsl_qos_queue for upstream and wondershaper for downstream.

Configuring dsl_qos_queue:
You'll need to edit dsl_qos_queue.c first with your favourite editor. Scroll down and you'll see some configuration variables - change the "Default queueing device" from eth0 to whatever your internet device is eg. ppp0, eth1, usb0) - mine is eth1. Set "Rate Cap" to your downstream bandwidth minus a bit.
For example mine is about 30 kiloBYTES/sec download speed (256kiloBITS), so I set it to 28 - which is 28672 bytes (28 x 1024) - as dsl_qos_queue is measured in BYTES/sec.
You also need to comment out a bit of code starting from line 298, comment it out so it looks like this:

/* rval=system("modprobe ip_queue");
if (WEXITSTATUS(rval)!=0)
{
printf("Unable to install ip_queue module.\n");
exit(1);
}*/

Save that and exit, then you need to edit the ipt_rules file. Just change line 5 to the device name of your internet device - same as we did above. Save and exit.

Then type make <enter> and you'll have a dsl_qos_queue file you can run! Copy it to /bin for easier execution (cp dsl_qos_queue /bin). Then all you need to do is type
./ipt_rules install
./dsl_qos_queue -d

and it's running! If you get ANY errors except the following, please ask someone:
iptables v1.2.6a: unknown protocol `ipv6-crypt' specified
Try `iptables -h' or 'iptables --help' for more information.


Upload a large file somewhere and ping some site at the same time to test it.
You can change the device name and the cap rate by specifying options to dsl_qos_queue - type ./dsl_qos_queue -h for more information. You can also change the priority of different ports/protocols/IP addresses, just edit ipt_install.

If you want to stop dsl_qos_queue from running, type the following:
./ipt_rules
killall -9 dsl_qos_queue


Configuring wondershaper:
First of all, put the wondershaper script in /bin for easy execution/editing. Make sure it's executable (Command to make it executable: chmod +x /bin/wshaper). Then edit it, change the uplink and downlink values to your upstream and downstream speeds minus 30-50 or so - it's measured in kilobits. My ADSL line is 512k down, 256k up, so mine are set up 470 (down) and 500 (up). The only reason my up is set so high is because I have dsl_qos_queue handling all upstream bandwidth, setting it so high means wondershaper doesn't touch it :) If I used wondershaper alone, I would have set it to 220. Experiment with these values when you've got it up and running.
Next you need to edit the DEV to your internet device, see the dsl_qos_queue section on how to do this (mine is eth1).
Next you need to comment out 2 lines in the script, that tell you to read the README file :) They are lines 27 and 28, put a hash (#) at the start of each line. Then save and exit.
Then just run wshaper, and it's done ! To remove it, just type wshaper stop.



This FAQ is constantly being updated, any questions or problems please post in this thread, thanks!
 
Last edited:
Associate
Joined
18 Oct 2002
Posts
445
Location
Bath, UK
Originally posted by Shak
Will do siree, and a full credit to you :)

Thanks :)

Shak

Talking of homes for how-to's, I'm looking for people to write how-to's for LinuxUK, you mind if I put your how-to's up until they have their new home shak?
 
Associate
Joined
19 Oct 2002
Posts
100
Location
Nottingham
Very nice lostie. I have most of next monday and tuesday off and i'll be setting it up on my smothie then :D

I've wanted to do this for ages, i'm sick of my interactive trafic going to pot.

ty
 
Soldato
OP
Joined
18 Oct 2002
Posts
3,984
Location
Cheshire
Y'all better post your success stories here :D
And any problems/queries encountered - just post, I've been playing with it for quite a while now.
 
Associate
Joined
19 Oct 2002
Posts
100
Location
Nottingham
Originally posted by Ben
You can't make a new kernel on your smoothie, BUT, the kernel configuration is in the 0.9.9 sourcekit from http://us0.download.smoothwall.org/archive/source/0.9.9/

so you could compile it on another box :)
I think I'm gonna try this.

I'm running version 2b2 tho and the same file iisn't availible. The configuration maybe the same? or availible somwhere else?
 

Ben

Ben

Associate
Joined
18 Oct 2002
Posts
2,328
Location
Kent
Originally posted by Warfish
I'm running version 2b2 tho and the same file iisn't availible. The configuration maybe the same? or availible somwhere else?


Yeah, I'm using 2b2 too. The config file gave a starting point at least.

I now have a disk with the right stuff to run wshaper. And a kernel that seems to work for me, with the exception of ISDN (I can't test other connections unfortunately)

By chance, do you not use ISDN?
(at the moment ISDN segfaults when modprobed :()


If you want an image of the disk then I can put it up, bar ISDN working. (and maybe other things)

I have it as a seperate option in lilo on my smoothie, so with testing it, if it bails out I can go back to the standard one and everything works fine :)
 
Associate
Joined
19 Oct 2002
Posts
100
Location
Nottingham
I'm on adsl, dont know why ISDN wouldn't be working, you must be missing an option or sunnit.

Wonder why they aint put the kernel options on the site :rolleyes:, its still in beta so what can we expect.

I dont think i have a disk drive on my smoothwall box, lol
 

Ben

Ben

Associate
Joined
18 Oct 2002
Posts
2,328
Location
Kent
Yeah, it's annoying. Maybe I should ask on the GPL list or go into their chatroom to see if I can get it.

I think you can do file transfers over SSH somehow. There was windows clients posted to the list, but I don't know how from a Linux box.

If you want to have what I've got so far, then I've uploaded it here

I think I'll do images once i'm done ;) It fits quite snugly onto a disk as it is hehe.
 
Back
Top Bottom