LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 02-16-2004, 06:36 PM   #1
meks
Member
 
Registered: Jul 2003
Location: AT, Upper Austria
Posts: 33

Rep: Reputation: 15
HTB: how to shape the bandwidth the router may consume?


hi there.

i'm currently teaching myself htb but now i'm hitting some wall.
perhaps its my own logic-wall, or perhaps its simply not possible.

i got the following interfaces:
eth0
eth1
eth2
ppp0

only eth1 and eth2 are currently important for the htb qdiscs i want to set up.

there are three clients (192.168.0.1 - .3) connected to eth2. my linux box (.111) routes those clients to eth1 using iptables. eth1 is connected to the internet.

i was able to set up htb to "shape" bandwidth for .1-.3. i did this the following:

--
tc qdisc add dev eth2 root handle 1: htb default 4 r2q 1

tc class add dev eth2 parent 1: classid 1:1 htb prio 0 rate 1Mbit
tc qdisc add dev eth2 parent 1:1 handle 10: sfq perturb 10

tc class add dev eth2 parent 1: classid 1:2 htb prio 1 rate 39Mbit

tc class add dev eth2 parent 1:2 classid 1:21 htb prio 0 rate 9Mbit ceil 9Mbit
tc qdisc add dev eth2 parent 1:21 handle 20: sfq perturb 10

tc class add dev eth2 parent 1:2 classid 1:22 htb prio 1 rate 30Mbit ceil 39Mbit
tc qdisc add dev eth2 parent 1:22 handle 30: sfq perturb 10

tc class add dev eth2 parent 1: classid 1:4 htb prio 2 rate 20kbit
tc qdisc add dev eth2 parent 1:4 handle 40: sfq perturb 10

tc filter add dev eth2 protocol ip parent 1: prio 0 handle 11 fw classid 1:1
tc filter add dev eth2 protocol ip parent 1: prio 0 handle 121 fw classid 1:21
tc filter add dev eth2 protocol ip parent 1: prio 0 handle 122 fw classid 1:22
tc filter add dev eth2 protocol ip parent 1: prio 0 handle 14 fw classid 1:4
--

explanation:
classid 1:1 -> class for local traffic, which will NOT be forwarded to .1-.3.
this class is intended to shape the traffic which is meant to destinate on the router itself (.111).
classid 1:21 -> class for traffic meant to destinate either on .1 or .2
classid 1:22 -> class for traffic meant to destinate on .3
classid 1:4 -> default for unclassified traffic

its better to not concentrate on the rates - this configuration will be used at a lan party, thats because its designed for 40mbit. i'm using tc and iptables to look if htb is working.

since i'm using fw-filters, iptables are used to mark the packets:

--
iptables -t mangle -I INPUT -i eth1 -d 192.168.0.111 -j MARK --set-mark 11

iptables -t mangle -I FORWARD -d 192.168.0.3 -j MARK --set-mark 122

iptables -t mangle -I FORWARD -d 192.168.0.2 -j MARK --set-mark 121
iptables -t mangle -I FORWARD -d 192.168.0.1 -j MARK --set-mark 121
--

ok - thats my config.
and thats the point of this post:

those htb-defs listed above are working fine. those iptables not.

the rules concerning the forward-chain are supposed to be ok.
the input-rule isnt ok at all.

and thats the point, finally
is it actually possible to shape bandwidth on/for a machine where the inet-device is connected to?

i mean, i looked to the kernel packet traveling diagram (kptd) located at docum.org, and i learned that the forward-chain is only processed when a packet has to be forwarded to another client and the input/output chains are only processed when a packet is meant for the router itself.

and thats what i defined the rules for. those packets who should get forwarded will be marked within the forward chain (since the mangle-table will be processed before the nat-table), and those packets who should not be nat'ed (thus stay) will be marked within the input chain:
--
iptables -t mangle -I INPUT -i eth1 -d 192.168.0.111 -j MARK --set-mark 11
--
this rule is (imho) valid, because:
1) the PREROUTING chain is processed before the INPUT chain. this means that the destination for a packet has already been rewritten within the PREROUTING chain (according to the kptd)

2) the interface where the packet "enters" is eth1 - thus the internet.

3) the destination is the router itself - 192.168.0.111.


well...ahm...is it possible to shape not nat'ed bandwidth at all?
i hope you know what i want to do .. its sometimes confusing

thx in advance!
meks.

Last edited by meks; 02-16-2004 at 06:39 PM.
 
Old 04-30-2004, 03:42 PM   #2
frostschutz
Member
 
Registered: Apr 2004
Distribution: Gentoo
Posts: 63

Rep: Reputation: 16
Re: HTB: how to shape the bandwidth the router may consume?

Quote:
Originally posted by meks
there are three clients (192.168.0.1 - .3) connected to eth2. my linux box (.111) routes those clients to eth1 using iptables. eth1 is connected to the internet.

well...ahm...is it possible to shape not nat'ed bandwidth at all?
i hope you know what i want to do .. its sometimes confusing
I had a similar problem; a router with a DSL connections and several machines in the LAN behind it. I use a combination of HTB, PRIO and SFQ to shape, plus an ingress queue. The script itself is available here: http://www.metamorpher.de/ipshape/

Maybe it gives you some good ideas... I read a lot of other peoples scripts and they gave me loads of ideas. :-) I'm not saying it works well - it works okay, I get 200ms pings instead of 2-5s pings with it. It's quite hard to get perfect pings if the line is totally maxed out in both directions.

*** edit
About not nat'ed bandwidth: I'm not really shaping that. It's possible of course for upload bandwidth, since you shape all upload bandwidth on your internet device (in your case eth1). Download bandwidth is much harder to do, unless you're content with a simple ingress limiter.

Since my router does not produce any traffic by itself, it's not that big deal for me. If you find a good solution for this however (like using a virtual net device or natting local connections or something?) I'd be interested.

*** edit
changed the URL

Last edited by frostschutz; 05-02-2004 at 01:18 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTB as a child of another HTB - doesn't work ddaas Linux - Networking 5 07-25-2005 03:21 AM
linux router bandwidth sirrus_linux Linux - Networking 3 04-21-2005 01:43 AM
bandwidth management,htb, r2q?? quantum?? kartheekpn Linux - Networking 1 03-18-2005 12:32 PM
HTB.init and "metropolitan" bandwidth shaping Ghitza Linux - Networking 0 11-23-2004 06:47 PM
using cbq.init to shape bandwidth? shrike_912 Linux - Software 1 10-31-2004 11:24 AM


All times are GMT -5. The time now is 11:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration