LinuxQuestions.org
Review your favorite Linux distribution.
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-25-2013, 05:51 AM   #1
psycroptic
Member
 
Registered: Aug 2011
Location: USA
Distribution: ArchLinux - 3.0 kernel
Posts: 349

Rep: Reputation: Disabled
limiting upload with tc


i have a linux router for a LAN that has an interface named "external" which is the public-facing address. I am trying to set a global max upload rate for a client with local ip 172.16.16.11 to 2mbit, and if the upload link is congested, have it slow down to a minimum of 900kbps.

I do this:

Code:
tc qdisc add dev external root handle 1: htb default 1
tc class add dev external parent 1: classid 1:2 htb rate 905kbit ceil 2.15mbit
and this:

Code:
iptables -t mangle -A POSTROUTING -o external -s 172.16.16.11 -j CLASSIFY --set-class 1:2
Except the client ALWAYS has 900kbps upload - the speed never reaches the ceil value, even when the upload link is free from all other traffic.

Why isn't this working as I think it should? or am i (most likely) misunderstanding this...

thanks
 
Old 08-01-2013, 01:50 PM   #2
baldy3105
Member
 
Registered: Jan 2003
Location: Cambridgeshire, UK
Distribution: Mint (Desktop), Debian (Server)
Posts: 891

Rep: Reputation: 184Reputation: 184
You've got a rate of 905K which is the maximum rate this class and all its children are guaranteed. You have a ceiling rate of 2.15M which is the maximum rate at which a class can send, if its parent has bandwidth to spare.

What you also need to define is the amount of bytes that can be burst at ceil speed, in excess of the configured rate. The docs don't say what the default is if you don't specify it, but if the burst defaults to 0, you would get this behaviour.

Try adding a burst size of 905K and see what that does.
 
Old 08-01-2013, 04:52 PM   #3
psycroptic
Member
 
Registered: Aug 2011
Location: USA
Distribution: ArchLinux - 3.0 kernel
Posts: 349

Original Poster
Rep: Reputation: Disabled
So adding that burst value produced a very strange result when doing a speed test via speedtest.net. The upload test took a very long time to begin, immediately jumped up to 6 megabits (???) and, finally, roughly 75% of the way through the test, dropped down to 900k. WTF??? I have a ~10mbps upload at this site, and nowhere in my rules am i specifying anything about 6 megs...

I gotta say, the man page for tc is sorely lacking, at least on an "understandability" front. I can't even say that I could explain what the "burst" value exactly does....
 
Old 08-02-2013, 01:41 PM   #4
baldy3105
Member
 
Registered: Jan 2003
Location: Cambridgeshire, UK
Distribution: Mint (Desktop), Debian (Server)
Posts: 891

Rep: Reputation: 184Reputation: 184
Actually, reading your post again, htb is not actually the thing you want, it is basically a traffic-shaper. It is unconditional in relation to other traffic.

What you need is cbq. This allows you to manually define traffic classes, then guarantee how much each gets. This means that under congestion conditions bandwidth is allocated as you specify, but under non-congestion conditions either class can use more.

Have a look at the tc cbq man page and see of it makes sense.
 
Old 08-03-2013, 12:36 AM   #5
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Code:
I gotta say, the man page for tc is sorely lacking, at least on an "understandability" front. I can't even say that I could explain what the "burst" value exactly does....
right. much of the linux documentation is still a mish-mash of howtos and half-intelligible man pages.
your issue was not in the burst value, but rather in setting up a container class which would allow for
bandwidth borrowing. try this.

Code:
IF_INET=external

# upload bandwidth limit for interface
BW_MAX=2000

# upload bandwidth limit for 172.16.16.11
BW_CLIENT=900


# first, clear previous settings
tc qdisc del dev ${IF_INET} root

# top-level htb queue discipline; send unclassified data into class 1:10
tc qdisc add dev ${IF_INET} root handle 1: htb default 10

# parent class (wrap everything in this class to allow bandwidth borrowing)
tc class add dev externel parent 1: classid 1:1 htb \
  rate ${BW_MAX}kbit ceil ${BW_MAX}kbit

# two child classes
#

# the default child class
tc class add dev ${IF_INET} parent 1:1 \
  classid 1:10 htb rate $((${BW_MAX} - ${BW_CLIENT}))kbit ceil ${BW_MAX}kbit

# the child class for traffic from 172.16.16.11
tc class add dev ${IF_INET} parent 1:1 \
  classid 1:20 htb rate ${BW_CLIENT}kbit ceil ${BW_MAX}kbit

# classify traffic
tc filter add dev ${IF_INET} parent 1:0 protocol ip prio 1 u32 \
  match ip src 172.16.16.11/32 flowid 1:20
 
Old 08-03-2013, 12:52 AM   #6
psycroptic
Member
 
Registered: Aug 2011
Location: USA
Distribution: ArchLinux - 3.0 kernel
Posts: 349

Original Poster
Rep: Reputation: Disabled
awesome thanks for that script, i'll try messing with that when I get home tonight. one thing, you classified the traffic with tc filter and not iptables; does that make a difference? i wouldn't think so...
 
Old 08-05-2013, 11:37 PM   #7
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
i used tc for the classification because it's easier to keep track of the traffic shaping configuration when everything is in one place. i don't know the pros and cons of using iptables, instead, for the classification. There may be times when classifying with tc is not an option, e.g. I believe (someone please correct me if I'm wrong) that classifying based on the presence of a MARK (which is logical rather than something written in the packet itself) is not possible with tc, but is possible with iptables.
 
Old 08-05-2013, 11:42 PM   #8
psycroptic
Member
 
Registered: Aug 2011
Location: USA
Distribution: ArchLinux - 3.0 kernel
Posts: 349

Original Poster
Rep: Reputation: Disabled
that sounds right, seeing as MARK is an iptables option and, AFAIK, not a native tc option.
 
  


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
Limiting Upload Speed on Fedora 8 njoker555 Linux - Networking 0 01-02-2009 12:19 PM
limiting upload band with p2p apps assasukasse Linux - Networking 1 04-17-2007 09:40 PM
Limiting WebDDAV upload dominant Linux - Newbie 0 07-26-2004 07:52 AM
limiting upload with CBQ orko Linux - Networking 3 11-28-2003 03:46 PM
limiting upload on certain port keevitaja Linux - Networking 1 02-26-2003 02:50 PM

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

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