LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-23-2007, 09:08 AM   #1
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Rep: Reputation: 16
htb qdisc doesn't shape


I'm trying to setup a simple QOS implementation on my home router running Ubuntu Gutsy (kernel 2.6.22). The complete script is below, I'd like to mention one of the parts that doesn't function as expected.
Code:
tc qdisc add dev ppp0 root handle 3:0 htb default 30
tc class add dev ppp0 parent 3:0 classid 3:1 htb rate 220kbit #for a 256k link
# the default one
tc class add dev ppp0 parent 3:1 classid 3:30 htb rate 10kbit ceil 220kbit burst 6k prio 3
# for p2p traffic
tc class add dv ppp0 parent 3:1  classid 3:50 htb rate 5kbit ceil 6kbit prio 5
# p2p client running on LAN and port 10720 is DNATed to ppp0
tc filter add dev ppp0 parent 3: protocol ip u32 match ip sport 10720   0xff flowid 3:50
Now, consider 2 options: 1)the last line is commented out and 2)the last line is uncommented.
1) p2p traffic gets to the default class 3:30 and shapes accordingly to ceil. No prob here.
2) p2p traffic gets to 3:50 (checked with 'tc -s -d class show dev ppp0', it really does) and consumes all the bandwidth (uploading files)! The ceil of 6 kbytes doesn't matter at all!

Shaping of incoming traffic partly works on eth0 (e.g. ceil really limits) yet listening to a streaming radio becomes impossible when p2p is active. That shouldn't be. Besides, even with no other inbound traffic, p2p is really slow, occupying some 5-10% of the available bandwidth.

Do I get something wrong?

TIA.

Code:
#!/bin/bash

# The scpript for shaping traffic.

## Interfaces
# rates in kilobits.

# Traffic direction
# Against LAN
# 
# LAN interface,
# shaping incoming traffic
LAN=eth0
LAN_BW=1024000 #1 Gbit
# WAN interface,
# shaping outgoing traffic
WAN=eth1
WAN_BW=102400 #100 Mbit
VPN_SERVER=192.168.1.254 # to track inet traffic going through WAN
# Inet interface, established over eth1
# shaping outgoing traffic
INET=ppp0
INET_UP=250
INET_DOWN=250
INET_IP=19.152.13.1

# Cleanup first
tc qdisc del dev $LAN  root    &> /dev/null
tc qdisc del dev $WAN  root    &> /dev/null
tc qdisc del dev $INET root    &> /dev/null
tc qdisc del dev $LAN  ingress &> /dev/null
tc qdisc del dev $WAN  ingress &> /dev/null
tc qdisc del dev $INET ingress &> /dev/null

# Just in case
sleep 2

## Root hierarchy
tc qdisc add dev $LAN  root handle 1:0 htb default 30
tc qdisc add dev $WAN  root handle 2:0 htb default 30
tc qdisc add dev $INET root handle 3:0 htb default 30
# Root classes
tc class add dev $LAN  parent 1:0 classid 1:1 htb rate "$LAN_BW"kbit
tc class add dev $WAN  parent 2:0 classid 2:1 htb rate "$WAN_BW"kbit
tc class add dev $INET parent 3:0 classid 3:1 htb rate "$INET_UP"kbit

#####################
### LAN Unlimited ###
#####################
tc class add dev $LAN  parent 1:1 classid 1:90 htb rate $((LAN_BW - INET_DOWN))kbit ceil "$LAN_BW"kbit prio 10

####################
### Internet #######
####################

# Highest priority: ICMP, SSH, VoIP
tc class add dev $LAN  parent 1:1 classid 1:10 htb rate 10kbit ceil "$INET_DOWN"kbit burst 6k prio 1
tc class add dev $INET parent 3:1 classid 3:10 htb rate 10kbit ceil "$INET_UP"kbit burst 6k prio 1

# High priority: Online Radios
tc class add dev $LAN  parent 1:1 classid 1:20 htb rate 130kbit ceil "$INET_DOWN"kbit burst 6k prio 2
tc class add dev $INET parent 3:1 classid 3:20 htb rate 10kbit ceil "$INET_UP"kbit burst 6k prio 2

# Default: Browsing, etc.
tc class add dev $LAN  parent 1:1  classid 1:30 htb rate 10kbit ceil "$INET_DOWN"kbit burst 6k prio 3
tc class add dev $INET parent 3:1 classid 3:30 htb rate 10kbit ceil "$INET_UP"kbit burst 6k prio 3

# Normal priority: Services running on the box available on the Internet
tc class add dev $INET parent 3:1 classid 3:40 htb rate 10kbit ceil $((9*INET_UP/10))kbit burst 6k prio 4

# Lowest priority:p2p and the like
tc class add dev $LAN  parent 1:1  classid 1:50 htb rate 5kbit ceil $((9*INET_DOWN/10))kbit prio 5
tc class add dev $INET parent 3:1  classid 3:50 htb rate 5kbit ceil $((9*INET_UP/10))kbit prio 5

###########
### WAN ###
###########

# Bandwidth reserved for Inet, overhead taken into account
tc class add dev $WAN parent 2:1 classid 2:10 htb rate $((INET_DOWN*2))kbit prio 1

# Streaming services
tc class add dev $WAN parent 2:1 classid 2:20 htb rate 512kbit ceil "$WAN_BW"kbit prio 2

# Bulk traffic
tc class add dev $WAN parent 2:1 classid 2:30 htb rate 256kbit ceil $((9*WAN_BW/10))kbit prio 3


#############
### Rules ###
#############

#### Inet ###
## :10

# TOS 0x10
tc filter add dev $LAN  parent 1: protocol ip u32 match ip tos 0x10 0xff  flowid 1:10
tc filter add dev $INET parent 3: protocol ip u32 match ip tos 0x10 0xff  flowid 3:10

# ICMP
tc filter add dev $LAN  parent 1: protocol ip u32 match ip protocol 1 0xff flowid 1:10
tc filter add dev $INET parent 3: protocol ip u32 match ip protocol 1 0xff flowid 3:10

#ssh
tc filter add dev $LAN  parent 1: protocol ip u32 match ip sport 22   0xff flowid 1:10
tc filter add dev $INET parent 3: protocol ip u32 match ip dport 22   0xff flowid 3:10


## :20
# streaming
tc filter add dev $LAN  parent 1: protocol ip u32 match ip sport 8000   0xff flowid 1:20
tc filter add dev $INET parent 3: protocol ip u32 match ip dport 8000   0xff flowid 3:20

## :30
# Default one, no rules required

## :40
tc filter add dev $INET parent 3: protocol ip u32 match ip sport 80  0xff flowid 3:40
tc filter add dev $INET parent 3: protocol ip u32 match ip sport 25  0xff flowid 3:40

## :50
# TORRENT
tc filter add dev $LAN  parent 1: protocol ip u32 match ip dport 10720   0xff flowid 1:50
tc filter add dev $INET parent 3: protocol ip u32 match ip sport 10720   0xff flowid 3:50

###########
### WAN ###
###########
tc filter add dev $WAN parent 2: protocol ip u32 match ip dst "$VPN_SERVER"/32 flowid 2:10

# No limits for private subnets => behind WAN
tc filter add dev $LAN parent 1: protocol ip u32 match ip src 192.168.0.0/16 flowid 1:90
tc filter add dev $LAN parent 1: protocol ip u32 match ip src 172.16.0.0/12  flowid 1:90
tc filter add dev $LAN parent 1: protocol ip u32 match ip src 10.0.0.0/8     flowid 1:90

Last edited by GSMD; 12-24-2007 at 08:01 AM.
 
Old 12-24-2007, 08:01 AM   #2
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Original Poster
Rep: Reputation: 16
Updated the first post with a trivial example.
 
Old 12-24-2007, 11:16 AM   #3
esaym
Member
 
Registered: Nov 2006
Distribution: Lots of Debian
Posts: 165

Rep: Reputation: 32
All I can offer right now is my example: http://www.linuxquestions.org/questi...estion-603669/

Are you setting those burst rates yourself? Burst rates are automatically calculated normally internally and trying to force your own rates can sometimes really screw with it.

I haven't got the chance to really look over your script but downstream limiting is very tricky to do. I would try to disable the downstream and only mess with the upstream stuff for now.
 
Old 12-24-2007, 11:54 AM   #4
GSMD
Member
 
Registered: Dec 2005
Distribution: Gentoo
Posts: 87

Original Poster
Rep: Reputation: 16
Thanks, I'll look over your script.
I've tried the whole bunch of variations, setting no burst and shaping upstream only included. That's what I do in the first code snippet.
 
Old 06-19-2008, 06:22 AM   #5
jomen
Senior Member
 
Registered: May 2004
Location: Leipzig/Germany
Distribution: Arch
Posts: 1,687

Rep: Reputation: 55
the key here is setting up the root qdisc correctly:
to be able to reach such low bandwidth as you want you need to initialize it like that:
Code:
tc qdisc add dev $LAN  root handle 1:0 htb default 30 r2q 1
and even then you will not get below the 12 kbit mark

and just an remark - real "shaping" is hardly possible on the incoming traffic - this traffic is just "answers" to "questions" - at least in a home router.

All that is possible is throwing away perfectly good packets which already took up bandwidth - and the need to get them again - only to slow down incoming traffic.
Should not be very useful in most environments I think.
 
  


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
run multiple algorithm qdisc simultaneously (HTB & HFSC) e1605project Linux - Networking 6 06-26-2006 11:52 PM
help with tc qdisc ssoc80 Linux - Networking 0 05-16-2006 06:03 AM
qdisc initiation shrishailnk Linux - Networking 0 04-14-2006 10:16 PM
HTB as a child of another HTB - doesn't work ddaas Linux - Networking 5 07-25-2005 03:21 AM
HTB: how to shape the bandwidth the router may consume? meks Linux - Networking 1 04-30-2004 03:42 PM

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

All times are GMT -5. The time now is 07:26 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