Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to automatically shape bandwidth-hungry TCP connections corresponding to the already transmitted data.

A summary would be : "The first Mbit is transferred at full bandwidth, then it gradually drops to 1% of the bandwidth when it reaches 10Mbit, and stays there".

An example is better than 1k words :

 b-w  ^
      |        .         .
100%  | ********         .
      |        . *       .
      |        .    *    .
      |        .       * .
  1%  |        .         .********
      +----------------------------> Data transfered.
         1Mbit .         . 10Mbit

I know that a full traffic shaping would be better, since it would allow bursting and use of leftover bandwidth, but the idea is specifically to automatically limit big data transfers without any further configuration.

How would I implement this on a linux host ?

Update: It isn't immediately obvious, but the data meter counts both ways (upload & download) as I purposefully didn't precise download or upload.

share|improve this question
2  
You forgot to ask a question. You also forgot to tell us how you wanted to do this. (In a firewall? On a host? In a router?) –  David Schwartz Dec 19 '11 at 13:09
    
@DavidSchwartz thx. Updated the question. Sorry. –  Steve Schnepp Dec 19 '11 at 13:22

1 Answer 1

up vote 2 down vote accepted

The HTB qdisc implements the concept of bursts which is a bit of what you want - it sends at full hardware rate up to the amount of data specified in the "burst" parameter. To get a gradual decrease you would need to nest HTB classes, and probably you would not want to do it too excessively as it greatly increases the complexity of the setup. But the Linux traffic shaping engine itself is stateless, it just acts upon packets, not connections. Using tc filters alone, you can only differentiate packets based on IP/TCP headers.

So if you need to classify differently based on connections, the most straightforward approach would probably be using the iptables "--connbytes" match and a packet mark (-j MARK target) to shove a connection's packets into the right queue (fast/slowdown)

See the wordy section on bandwidth management of the LARTC howto and / or the comprehensive "Open source bandwidth solutions" whitepaper for more insight.

Furthermore, if you need to shape upstream as well as downstream, take a look at the implementation of the virtual IMQ interface - it has been designed specifically for this purpose.

share|improve this answer
    
How would I automatically reclassify the TCP connection to another class after a certain amount of data was transfered ? –  Steve Schnepp Dec 19 '11 at 16:03
    
@SteveSchnepp I think there's an iptables match rule that can measure the byte offset into a TCP stream. –  Alnitak Dec 19 '11 at 16:15
1  
I think the most straightforward way would be using the iptables "--connbytes" match and a packet mark (-j MARK target) to shove a connection's packets into the right queue (fast/slowdown) if you need a per-connection-approach. I forgot to mention a paper on the topic of bandwidth control - "Open source bandwidth solutions" is worth reading if you are not yet familiar with the topic. –  the-wabbit Dec 19 '11 at 16:28
1  
@SteveSchnepp no, I was thinking of the --connbytes option that @syneticon-dj just mentioned. –  Alnitak Dec 19 '11 at 16:29
1  
BTW: as per your edit, if you need to shape upstream as well as downstream, take a look at the implementation of the virtual IMQ interface - it has been designed specifically for this purpose. –  the-wabbit Dec 19 '11 at 16:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.