ADSL-Bandwidth-Management-HOWTO.pdf

(40 KB) Pobierz
ADSL Bandwidth Management HOWTO
ADSL Bandwidth Management HOWTO
Dan Singletary
dvsing@sonicspike.net
Revision History
Revision 1.2 2002−09−26 Revised by: ds
Added link to new Email Discussion List. Added small teaser to caveat section regarding new and improved
QoS for Linux designed specifically for ADSL to be released soon.
Revision 1.1 2002−08−26 Revised by: ds
A few corrections (Thanks to the many that pointed them out!). Added informational caveat to
implementation section.
Revision 1.0
2002−08−21
Revised by: ds
Better control over bandwidth, more theory, updated for 2.4 kernels
Revision 0.1
2001−08−06
Revised by: ds
Initial publication
This document describes how to configure a Linux router to more effectively manage outbound traffic on an
ADSL modem or other device with similar bandwidth properties (cable modem, ISDN, etc). Emphasis is
placed on lowering the latency for interactive traffic even when the upstream and/or downstream bandwidth is
fully saturated.
107878974.003.png
ADSL Bandwidth Management HOWTO
Table of Contents
1. Introduction. ....................................................................................................................................................1
1.1. New Versions of This Documen. .....................................................................................................1
1.2. Email Discussion List. ......................................................................................................................1
1.3. Disclaimer. ........................................................................................................................................1
1.4. Copyright and License. .....................................................................................................................1
1.5. Feedback and corrections. .................................................................................................................1
2. Background .....................................................................................................................................................2
2.1. Prerequisites. .....................................................................................................................................2
2.2. Layout. ..............................................................................................................................................2
2.3. Packet Queues. ..................................................................................................................................3
2.3.1. The Upstream. .........................................................................................................................3
2.3.2. The Downstream. ....................................................................................................................3
3. How it Works. ..................................................................................................................................................5
3.1. Throttling Outbound Traffic with Linux HTB. .................................................................................5
3.2. Priority Queuing with HTB. .............................................................................................................5
3.3. Classifying Outbound Packets with iptables. ...................................................................................6
3.4. A few more tweaks.... .......................................................................................................................6
3.5. Attempting to Throttle Inbound Traffic. ...........................................................................................7
3.5.1. Why Inbound Traffic Limiting isn't all That Good. ................................................................7
4. Implementation. ..............................................................................................................................................8
4.1. Caveats. .............................................................................................................................................8
4.2. Script: myshaper. ..............................................................................................................................8
5. Testing the New Queue. ................................................................................................................................14
6. OK It Works!! Now What?. .........................................................................................................................15
i
107878974.004.png
1. Introduction
The purpose of this document is to suggest a way to manage outbound traffic on an ADSL (or cable modem)
connection to the Internet. The problem is that many ADSL lines are limited in the neighborhood of 128kbps
for upstream data transfer. Aggravating this problem is the packet queue in the ADSL modem which can take
2 to 3 seconds to empty when full. Together this means that when the upstream bandwidth is fully saturated it
can take up to 3 seconds for any other packets to get out to the Internet. This can cripple interactive
applications such as telnet and multi−player games.
1.1. New Versions of This Document
You can always view the latest version of this document on the World Wide Web at the URL:
New versions of this document will also be uploaded to various Linux WWW and FTP sites, including the
LDP home page a t http://www.tldp.org .
1.2. Email Discussion List
For questions and update information regarding ADSL Bandwidth Management please subscribe to the ADSL
1.3. Disclaimer
Neither the author nor the distributors, or any other contributor of this HOWTO are in any way responsible for
physical, financial, moral or any other type of damage incurred by following the suggestions in this text.
1.4. Copyright and License
This document is copyright 2002 by Dan Singletary, and is released under the terms of the GNU Free
Documentation License, which is hereby incorporated by reference.
1.5. Feedback and corrections
If you have questions or comments about this document, please feel free to contact the author at
1. Introduction
1
107878974.005.png
2. Background
2.1. Prerequisites
The method outlined in this document should work in other Linux configurations however it remains untested
in any configuration but the following:
· 2.4.18−5 Kernel with QoS Support fully enabled (modules OK) and including the following kernel
patches (which may eventually be included in later kernels):
Red Hat Linux 7.3
·
¨
Note: it has been reported that kernels since version 2.4.18−3 shipped with Mandrake (8.1,
8.2) have already been patched for HTB.
¨
·
iptables v1.2.6a or later (version of iptables distributed with Red Hat 7.3 is missing the length
module)
Note: Previous versions of this document specified a method of bandwidth control that involved patching
the existing sch_prio queue. It was found later that this patch was entirely unnecessary. Regardless, the
newer methods outlined in this document will give you better results (although at the writing of this
document 2 kernel patches are now necessary. :) Happy patching.)
2.2. Layout
In order to keep things simple, all references to network devices and configuration in this document will be
with respect to the following network layout diagram:
<−− 128kbit/s −−−−−−−−−−−−−− <−− 10Mbit −−>
Internet <−−−−−−−−−−−−−−−−−−−−> | ADSL Modem | <−−−−−−−−−−−−−−−−−−−−
1.5Mbit/s −−> −−−−−−−−−−−−−− |
| eth0
V
−−−−−−−−−−−−−−−−−
| |
| Linux Router |
| |
−−−−−−−−−−−−−−−−−
| .. | eth1..ethN
| |
V V
Local Network
2. Background
2
107878974.006.png 107878974.001.png
ADSL Bandwidth Management HOWTO
2.3. Packet Queues
Packet queues are buckets that hold data for a network device when it can't be immediately sent. Most packet
queues use a FIFO (first in, first out) discipline unless they've been specially configured to do otherwise. What
this means is that when the packet queue for a device is completely full, the packet most recently placed in the
queue will be sent over the device only after all the other packets in the queue at that time have been sent.
2.3.1. The Upstream
With an ADSL modem, bandwidth is asymmetric with 1.5Mbit/s typical downstream and 128kbit/sec typical
upstream. Although this is the line speed, the interface between the Linux Router PC and the ADSL modem is
typically at or above 10Mbit/s. If the interface to the Local Network is also 10Mbit/s, there will typically be
NO QUEUING at the router when packets are sent from the Local Network to the Internet. Packets are sent
out eth0 as fast as they are received from the Local Network. Instead, packets are queued at the ADSL modem
since they are arriving at 10Mbit/s and only being sent at 128kbit/s. Eventually the packet queue at the ADSL
modem will become full and any more packets sent to it will be silently dropped. TCP is designed to handle
this and will adjust it's transmit window size accordingly to take full advantage of the available bandwidth.
While packet queues combined with TCP result in the most effective use of bandwidth, large FIFO queues can
increase the latency for interactive traffic.
Another type of queue that is somewhat like FIFO is an n−band priority queue. However, instead of having
just one queue that packets line up in, the n−band priority queue has n FIFO queues which packets are placed
in by their classification. Each queue has a priority and packets are always dequeued from the highest priority
queue that contains packets. Using this discipline FTP packets can be placed in a lower priority queue than
telnet packets so that even during an FTP upload, a single telnet packet will jump the queue and be sent
immediately.
This document has been revised to use a new queue in linux called the Hierarchical Token Bucket (HTB). The
HTB queue is much like the n−band queue described above, but it has the capability to limit the rate of traffic
in each class. In addition to this, it has the ability to set up classes of traffic beneath other classes creating a
hierarchy of classes. Fully describing HTB is beyond the scope of this document, but more information can be
2.3.2. The Downstream
Traffic coming inbound on your ADSL modem is queued in much the same way as outbound traffic, however
the queue resides at your ISP. Because of this, you probably don't have direct control of how packets are
queued or which types of traffic get preferential treatment. The only way to keep your latency low here is to
make sure that people don't send you data too fast. Unfortunately, there's no way to directly control the speed
at which packets arrive, but since a majority of your traffic is most likely TCP, there are some ways to slow
down the senders:
·
Intentionally drop inbound packets − TCP is designed to take full advantage of the available
bandwidth while also avoiding congestion of the link. This means that during a bulk data transfer TCP
will send more and more data until eventually a packet is dropped. TCP detects this and reduces it's
transmission window. This cycle continues throughout the transfer and assures data is moved as
quickly as possible.
·
Manipulate the advertised receive window − During a TCP transfer, the receiver sends back a
2. Background
3
107878974.002.png
Zgłoś jeśli naruszono regulamin