# traffic shaping confusion :( [solved]

## Gushy

OK,

I've been going through the adsl bandwidth management howto, the stuff at lartc.org, wondershaper, htbinit and cbqinit, and I'm beginning to feel a bit thick.

I can't figure out how to get either cbq or htb to work.   :Sad: 

Quite simply I have a server with one network card.  I want to throttle all traffic coming out/in of that server if not heading for the local network (10.0.0.x).  

I figured it wouldn't be that difficult, I was wrong.

Can someone give me some pointers??  I even need to be told which to use cbq or htb.  I understand that htb is newer, but is it better for my needs?

----------

## Gushy

just a little more info.

The internet connection is a 512/256 adsl line, so my setup is:

```

Server --->  Switch  ----> adsl router

                  |----> lan pcs

```

----------

## Gushy

update number 2:

This is what I came up with, can anyone tell me if it's ok and will work? or if I really am thick and don't have a clue what I'm doing?  :Wink: 

```

# interface eth0 is 100mbit

tc qdisc add dev eth0 root handle 1: cbq avpkt 1000 bandwidth 100mbit

# class for adsl is 200kbit

tc class add dev eth0 parent 1: classid 1:1 cbq rate 200kbit \

allot 1500 prio 5 bounded isolated 

# class for lan is 99mbit (saving 1mbit for the adsl traffic)

tc class add dev eth0 parent 1: classid 1:2 cbq rate 99mbit \

allot 1500 prio 5 bounded isolated

# shape traffic going out to lan

tc filter add dev eth0 parent 1: protocol ip prio 16 u32 \

match ip dst 10.0.0.0/24 flowid 1:2

# shape traffic going out to adsl

tc filter add dev eth0 parent 1: protocol ip prio 16 u32 \

match ip dst 0.0.0.0/0 flowid 1:1

```

I can't seem to find if all the rules will be processed or if it stops once it gets a match.

----------

## Gushy

I tested it and it seems to work.

Always the damn way, you try and try, you get frustrated and post on the forum, and then you try again and get it to work!!

However it's not quite working...

it's messing with my pings; where as pings worked before, I now get:

```

64 octets from 212.2.21.1: icmp_seq=2 ttl=249 time=3153.1 ms

wrong data byte #0 should be 0x2a but was 0x2727 db 1e 3f dc f1 6 0 

        8 9 a b c d e f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 

        28 29 2a 2b 2c 2d 2e 2f 

```

Can anyway tell me why?

----------

## Gushy

ok I got it all figured in the end.  Don't know what that ping stuff is all about but it's to do with large return times.

I went with HTB in the end, if anyone uses HTB with the vanilla sources make sure you get the new patched tc from http://luxik.cdi.cz/~devik/qos/htb/

In case it helps anyone, here's my script:

```

#!/bin/sh

TC="/usr/sbin/tc"

# interface eth0

$TC qdisc add dev eth0 root handle 1: htb default 20

# class for eth0

$TC class add dev eth0 parent 1: classid 1:1 htb rate 100mbit burst 40k 

# class for adsl

$TC class add dev eth0 parent 1:1 classid 1:20 htb rate 200kbit ceil 200kbit burst 15k

# class for lan

$TC class add dev eth0 parent 1:1 classid 1:10 htb rate 100mbit ceil 100mbit burst 25k

# sfq (stochastic fairness queueing) for adsl

$TC qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10

# sfq (stochastic fairness queueing) for lan

$TC qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10

# filters

U32="$TC filter add dev eth0 protocol ip parent 1:0 prio 1 u32"

# filter for lan

$U32 match ip dst 10.0.0.0/24 flowid 1:10

# filter for adsl

$U32 match ip dst 0.0.0.0/0 flowid 1:20

```

I apologise for using the forum to ramble and help sort out my thinking process.  :Smile: 

----------

## Thrifty

Dont apologize Gushy, it's most appreciated as you ramblings have helped me almost figure out what the hell I am doing.

Mine's a bit more complicated however as we have 1-to-1 NAT operating here and I want to only throttle it by one single IP address.

e.g. I want 10.2.0.1 to be throttle to 40kb/s in/out

I want 192.168.90.0 to not be throttled aty all but also not use any of the 40kb/s being used by 10.2.0.1

so on.

bleh.  It will all click and make sense before too long.

----------

## rshetye

Gushy, you should be proud of yourself. configuring tc from scratch is quite difficult for someone new to tc.

http://www.lartc.ogr/lartc.html

At the bottom there are two ready-to-go scripts

CBQ based script - works well.

http://www.lartc.org/lartc.html#AEN2233

HTB based script - works brilliantly.

http://www.lartc.org/lartc.html#AEN2241

Gentoo also has the following two packages cbqinit and htbinit but I haven't used these or looked into them. I suspect they might be the same scripts as above, but I dont know as yet.

----------

## Gushy

Thanks rshetye.  :Smile:  It was a bit of a struggle.

Thrifty: did you get your script sorted? I meant to have a go at figuring it out for ya but I've been a bit busy; if you're still stuck post it here so we can have a look.

----------

