LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 07-31-2008, 07:55 AM   #1
scuba0
LQ Newbie
 
Registered: Jul 2008
Posts: 3

Rep: Reputation: 0
Problems, Traffic shaping with HTB


Hi.

I've been trying to read up on traffic shaping with HTB. The thing is I have 3 apartments where the UPPER should not have any limits on it. Currently the MIDDLE and LOWER uses a lot of bandwidth and should not get too much access to the little there is to share.

Maybe there should be several queues but it is hard to understand how to script this.

The script:
Code:
#!/bin/sh
# 
# Internet specific
#  Down: 8192kbit/s
#  Up: 768kbit/s
#
TC=/sbin/tc

# Devices
EXTERNAL=eth1		# Internet
UPPER=eth2		# Top floor
MIDDLE=eth3		# Middle floor
LOWER=eth0		# Lower floor

# Rates
DCEIL=7372kbit		# Download rate (90%)
DRATE=737kbit		# Download weight (10% of above)
UCEIL=691kbit		# Upload rate (90%)
URATE=69kbit		# Upload weight (10% of above)

# Start script
start() {
    $TC qdisc add dev $EXTERNAL root handle 1: htb default 60
    $TC class add dev $EXTERNAL parent 1: classid 1:1 htb rate 7372kbit

    $TC class add dev $EXTERNAL parent 1:1 classid 1:10 htb rate 3686kbit ceil 7372kbit prio 0
    $TC class add dev $EXTERNAL parent 1:1 classid 1:11 htb rate 691kbit ceil 691kbit prio 0
    $TC class add dev $EXTERNAL parent 1:1 classid 1:20 htb rate 3686kbit ceil 3686kbit prio 1
    $TC class add dev $EXTERNAL parent 1:1 classid 1:21 htb rate 172kbit ceil 345kbit prio 1
    $TC class add dev $EXTERNAL parent 1:1 classid 1:30 htb rate 1843kbit ceil 3686kbit prio 2
    $TC class add dev $EXTERNAL parent 1:1 classid 1:31 htb rate 172kbit ceil 345kbit prio 2

    $TC qdisc add dev $EXTERNAL parent 1:10 handle 10: sfq perturb 10
    $TC qdisc add dev $EXTERNAL parent 1:11 handle 10: sfq perturb 10
    $TC qdisc add dev $EXTERNAL parent 1:20 handle 20: sfq perturb 10
    $TC qdisc add dev $EXTERNAL parent 1:21 handle 20: sfq perturb 10
    $TC qdisc add dev $EXTERNAL parent 1:30 handle 30: sfq perturb 10
    $TC qdisc add dev $EXTERNAL parent 1:31 handle 30: sfq perturb 10
}

stop() {
	$TC qdisc del dev $EXTERNAL root
#	$TC qdisc del dev $UPPER root
#	$TC qdisc del dev $MIDDLE root
#	$TC qdisc del dev $LOWER root
}

restart() {
	stop
	sleep 1
	start
}

status() {
	echo "Traffic shaping"
	echo ""
	echo $EXTERNAL . ":"
	$TC qdisc show dev $EXTERNAL
	$TC class show dev $EXTERNAL
	$TC filter show dev $EXTERNAL
	echo ""
	echo $UPPER . ":"
	$TC qdisc show dev $UPPER
	$TC class show dev $UPPER
	$TC filter show dev $UPPER
	echo ""
	echo $MIDDLE . ":"
	$TC qdisc show dev $MIDDLE
	$TC class show dev $MIDDLE
	$TC filter show dev $MIDDLE
	echo ""
	echo $LOWER . ":"
	$TC qdisc show dev $LOWER
	$TC class show dev $LOWER
	$TC filter show dev $LOWER
	echo ""
}

case "$1" in
	start)
		echo -n "Starting bandwidth shaping: "
		start
		echo "done"
		;;

 	stop)
		echo -n "Stopping bandwidth shaping: "
 		stop
 		echo "done"
 		;;

	restart)
		echo -n "Restarting bandwidth shaping: "
		restart
		echo "done"
 		;;

	status)
		status
 		;;

	*)
		echo "Usage: /etc/init.d/traffic_shaping.sh {start|stop|restart|status}"
 		;;
esac

exit 0
Notice that I don't use all my variables at this time.

This is my "status" when it is up and running:
Code:
sudo: unable to resolve host server
Traffic shaping

eth1 . :
qdisc htb 1: root r2q 10 default 60 direct_packets_stat 3
qdisc sfq 10: parent 1:10 limit 127p quantum 1514b perturb 10sec 
qdisc sfq 20: parent 1:20 limit 127p quantum 1514b perturb 10sec 
qdisc sfq 30: parent 1:30 limit 127p quantum 1514b perturb 10sec 
class htb 1:11 parent 1:1 prio 0 rate 345000bit ceil 691000bit burst 1599b cburst 1599b 
class htb 1:10 parent 1:1 leaf 10: prio 0 rate 3686Kbit ceil 7372Kbit burst 1599b cburst 1598b 
class htb 1:1 root rate 7372Kbit ceil 7372Kbit burst 1598b cburst 1598b 
class htb 1:31 parent 1:1 prio 2 rate 172000bit ceil 345000bit burst 1599b cburst 1599b 
class htb 1:20 parent 1:1 leaf 20: prio 1 rate 3686Kbit ceil 3686Kbit burst 1599b cburst 1599b 
class htb 1:30 parent 1:1 leaf 30: prio 2 rate 1843Kbit ceil 3686Kbit burst 1599b cburst 1599b 
class htb 1:21 parent 1:1 prio 1 rate 172000bit ceil 345000bit burst 1599b cburst 1599b 

eth2 . :
qdisc pfifo_fast 0: root bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1

eth3 . :
qdisc pfifo_fast 0: root bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1

eth0 . :
qdisc pfifo_fast 0: root bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
The biggest problem is that it is hard to get a grasp over TC and HTB which is why I thought someone here could help guide me or maybe provide a solution to solve why the Internet goes slower with this setup.
 
Old 07-31-2008, 08:24 AM   #2
jomen
Senior Member
 
Registered: May 2004
Location: Leipzig/Germany
Distribution: Arch
Posts: 1,687

Rep: Reputation: 55
I could send you several scripts - versions of what I have done over some time.
Or you could have a look here:
http://wiki.leipzig.freifunk.net/Tra...ochens_Version
It is not shaping but rather prioritizing - but I have a shaping version using htb too.

Your scripts problem seems to be that you set up variables for UPPER, MIDDLE, LOWER - but you never use them.
 
Old 07-31-2008, 10:18 AM   #3
scuba0
LQ Newbie
 
Registered: Jul 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Well the variables might not be applied, still I have lower values for MIDDLE and LOWER than UPPER so it shouldn't matter.

I looked at yours and the one <i>Björn</i> published but still I couldn't figure out when it comes to multiple networks. As I have done I let Iptables mark up and down in the different IP-series as follows:
Code:
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
CLASSIFY   all  --  anywhere             192.168.0.0/24      CLASSIFY set 1:10 
CLASSIFY   all  --  anywhere             192.168.1.0/24      CLASSIFY set 1:20 
CLASSIFY   all  --  anywhere             192.168.2.0/24      CLASSIFY set 1:30 
CLASSIFY   all  --  192.168.0.0/24       anywhere            CLASSIFY set 1:11 
CLASSIFY   all  --  192.168.1.0/24       anywhere            CLASSIFY set 1:21 
CLASSIFY   all  --  192.168.2.0/24       anywhere            CLASSIFY set 1:31
Still, how to set the priorities in order and the correct values with rate, ceil and burst haunts me. But if you have more scripts I would love to see them or if you spotted any errors in my code that would be nice to know too.

Thanks
 
Old 07-31-2008, 10:46 AM   #4
jomen
Senior Member
 
Registered: May 2004
Location: Leipzig/Germany
Distribution: Arch
Posts: 1,687

Rep: Reputation: 55
How you classified was not in your example.

I did not see through the classifying using tc when I wrote that (and still am not) - and I use iptables to identify different kinds of traffic anyway.
So I took the (for me) easy way and used firewall-marks - and used these to assign the packets to their queues.
In the current script are only two priority classes - it is sorted out in the chain "split".
The original version had 3 classes but that was not neccesary for me.

Everything is given priority 4, 5 or 6 - according to the filters.
In "split" it is determined wether the traffic is from an IP or subnet which should get higher priority - and the firewall-marks are re-set to 1,2 or 3 respectively.
According to those marks the traffic is queued then.

Which way to send you files?
 
Old 07-31-2008, 11:21 AM   #5
scuba0
LQ Newbie
 
Registered: Jul 2008
Posts: 3

Original Poster
Rep: Reputation: 0
To tim.kornhammar@gmail.com works just fine.
 
  


Reply



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
Traffic shaping (limiting outgoing bandwidth of all TCP-traffic except FTP/HTTP) ffkodd Linux - Networking 3 10-25-2008 12:09 AM
Traffic shaping with HTB, several questions exscape Linux - Networking 1 05-28-2008 12:10 PM
traffic shaping with htb zsoltrenyi Linux - Software 2 11-12-2004 09:17 AM
shaping scripts - htb.init ... confusion ? :( mikero Linux - Networking 0 02-17-2004 05:05 AM
traffic shaping htb SchwipSchwap Linux - Networking 1 08-28-2003 03:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:34 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration