Classful qdisc updated

This commit is contained in:
Federico Bolelli 2016-01-18 10:08:58 +01:00 committed by Natale Patriciello
parent 46d0a794dc
commit c1374527e7
10 changed files with 29867 additions and 4 deletions

View File

@ -17,7 +17,7 @@
This HOWTO is likely available at the following address:
http://tldp.org/HOWTO/Traffic-Control-HOWTO/
-->
<!-- conventions used in this documentation....
@ -47,6 +47,9 @@
<section id="qc-htb">
<title>HTB, Hierarchical Token Bucket</title>
<para>
HTB is meant as a more understandable and intuitive replacement for the CBQ (<link linkend="qc-cbq">see chapter 7.4</link>) qdisc in Linux. Both CBQ and HTB help you to control the use of the outbound bandwidth on a given link. Both allow you to use one physical link to simulate several slower links and to send different kinds oftraffic on different simulated links. In both cases, you have to specify how to divide the physical link into simulated links and how to decide which simulated link to use for a given packet to be sent.
</para>
<para>
&sch_htb; uses the concepts of tokens and buckets
along with the class-based system and &linux-filter;s to allow for
@ -235,6 +238,12 @@ TC HTB version 3.3
<imageobject>
<imagedata fileref="images/htb-borrow.jpg" format="JPG"/>
</imageobject>
<textobject>
<phrase>Figure 11: FIFO qdisc</phrase>
</textobject>
<caption>
<para><command>Figure 11:</command> <emphasis>Hierarchical Token Bucket (HTB)</emphasis></para>
</caption>
</mediaobject>
<para>
Note in this diagram that there are several &sch_htb; root classes.
@ -337,13 +346,64 @@ TC HTB version 3.3
<term>&param-prio;</term>
<listitem>
<para>
In the round-robin process, classes with the lowest priority field are tried for packets first. Mandatory field.
</para>
</listitem>
</varlistentry>
<varlistentry id="vl-qc-htb-params-parent">
<term>&param-prio;</term>
<listitem>
<para>
Place of this class within the hierarchy. If attached directly to a qdisc and not to another class, minor can be omitted. Mandatory field.
</para>
</listitem>
</varlistentry>
<varlistentry id="vl-qc-htb-params-classid">
<term>&param-prio;</term>
<listitem>
<para>
Like qdiscs, classes can be named. The major number must be equal to the major number of the qdisc to which it belongs. Optional, but needed if this class is going to have children.
</para>
</listitem>
</varlistentry>
</variablelist>
<para>
</para>
</section>
<section id="qc-htb-params-root">
<title>HTB root parameters</title>
<para>
The root of a HTB qdisc class tree has the following parameters:
</para>
<variablelist id="vl-qc-htb-params-root">
<varlistentry id="vl-qc-htb-params-root-parent">
<term><constant>parent major:minor | root</constant></term>
<listitem>
<para>
This mandatory parameter determines the place of the HTB instance, either at the root of an interface or within an existing class.
</para>
</listitem>
</varlistentry>
<varlistentry id="vl-qc-htb-params-root-handle">
<term><constant>handle major:</constant></term>
<listitem>
<para>
Like all other qdiscs, the HTB can be assigned a handle. Should consist only of a major number, followed by a colon. Optional, but very useful if classes will be generated within this qdisc.
</para>
</listitem>
</varlistentry>
<varlistentry id="vl-qc-htb-params-root-default">
<term><constant>default minor-id</constant></term>
<listitem>
<para>
Unclassified traffic gets sent to the class with this minor-id.
</para>
</listitem>
</varlistentry>
</variablelist>
</section>
<section id="qc-htb-rules">
<title>Rules</title>
<para>
@ -427,6 +487,31 @@ TC HTB version 3.3
<para>
</para>
</section>
<section id="qc-htb-classification">
<title>Classification</title>
<para>
Like see before, within the one HTB instance many classes may exist. Each of these classes contains another qdisc, by default <link linkend="qs-fifo">tc-pfifo</link>.When enqueueing a packet, HTB starts at the root and uses various methods to determine which class should receive the data. In the absence of uncommon configuration options, the process is rather easy. At each node we look for an instruction, and then go to the class the instruction refers us to. If the class found is a barren leaf-node (without children), we enqueue the packet there. If it is not yet a leaf node, we do the whole thing over again starting from that node.
</para>
<para>
The following actions are performed, in order at each node we visit, until one sends us to another node, or terminates the process.
</para>
<itemizedlist>
<listitem>
<para>
Consult filters attached to the class. If sent to a leafnode, we are done. Otherwise, restart.
</para>
</listitem>
<listitem>
<para>
If none of the above returned with an instruction, enqueue at this node.
</para>
</listitem>
</itemizedlist>
<para>
This algorithm makes sure that a packet always ends up somewhere, even while you are busy building your configuration.
</para>
</section>
</section>
<section id="qc-hfsc">
@ -452,21 +537,422 @@ TC HTB version 3.3
is ready to dequeue a packet, the first class is checked for a packet.
If there's a packet, it gets dequeued. If there's no packet, then the
next class is checked, until the queuing mechanism has no more classes
to check.
to check. PRIO is a scheduler and never delays packets - it is a work-conserving qdisc, though the qdiscs contained in the classes may not be
</para>
<section id="qc-prio-algorithm">
<title>Algorithm</title>
<para>
On creation with 'tc qdisc add', a fixed number of bands is created. Each band is a class, although is not possible to add classes with 'tc qdisc add', the number of bands to be created must instead be specified on the command line attaching PRIO to its root.
</para>
<para>
This section will be completed at a later date.
When dequeueing, band 0 is tried first and only if it did not deliver a packet does PRIO try band 1, and so onwards. Maximum reliability packets should therefore go to band 0, minimum delay to band 1 and the rest to band 2.
</para>
<para>
As the PRIO qdisc itself will have minor number 0, band 0 is actually major:1, band 1 is major:2, etc. For major, substitute the major number assigned to the qdisc on 'tc qdisc add' with the handle parameter.
</para>
</section>
<section id="qc-prio-synopsis">
<title>Synopsis</title>
<programlisting>
$ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands bands ] [ priomap band band band... ] [ estimator interval timeconstant ]
</programlisting>
</section>
<section id="qc-prio-classification">
<title>Classification</title>
<para>
Three methods are available to PRIO to determine in which band a packet will be enqueued.
</para>
<itemizedlist>
<listitem>
<para>
<emphasis>From userspace:</emphasis> a process with sufficient privileges can encode the destination class directly with SO_PRIORITY.
</para>
</listitem>
<listitem>
<para>
<emphasis>with a tc filter:</emphasis> a tc filter attached to the root qdisc can point traffic directly to a class
</para>
</listitem>
<listitem>
<para>
<emphasis>with the priomap:</emphasis> based on the packet priority, which in turn is derived from the Type of Service assigned to the packet.
</para>
</listitem>
</itemizedlist>
<para>
Only the priomap is specific to this qdisc.
</para>
</section>
<section id="qc-prio-parameters">
<title>Parameters</title>
<itemizedlist>
<listitem>
<para>
<emphasis>bands:</emphasis> number of bands. If changed from the default of 3, priomap must be updated as well.
</para>
</listitem>
<listitem>
<para>
<emphasis>priomap:</emphasis> a tc filter attached to the root qdisc can point traffic directly to a class
</para>
</listitem>
</itemizedlist>
<para>
<emphasis>priomap</emphasis> determines how packet priorities, as assigned by the kernel, map to bands. Mapping occurs based on the TOS octet of the packet, which looks like this:
</para>
<mediaobject id="parameters1">
<imageobject>
<imagedata fileref="images/parameters1.eps" format="EPS"/>
</imageobject>
<imageobject>
<imagedata fileref="images/parameters1.png" format="PNG"/>
</imageobject>
<imageobject>
<imagedata fileref="images/parameters1.jpg" format="JPG"/>
</imageobject>
</mediaobject>
<para>
The four TOS bits (the 'TOS field') are defined as:
</para>
<mediaobject id="parameters2">
<imageobject>
<imagedata fileref="images/parameters2.eps" format="EPS"/>
</imageobject>
<imageobject>
<imagedata fileref="images/parameters2.png" format="PNG"/>
</imageobject>
<imageobject>
<imagedata fileref="images/parameters2.jpg" format="JPG"/>
</imageobject>
</mediaobject>
<para>
As there is 1 bit to the right of these four bits, the actual value of the TOS field is double the value of the TOS bits. Tcpdump -v -v shows you the value of the entire TOS field, not just the four bits. It is the value you see in the first column of this table:
</para>
<mediaobject id="parameters3">
<imageobject>
<imagedata fileref="images/parameters3.eps" format="EPS"/>
</imageobject>
<imageobject>
<imagedata fileref="images/parameters3.png" format="PNG"/>
</imageobject>
<imageobject>
<imagedata fileref="images/parameters3.jpg" format="JPG"/>
</imageobject>
</mediaobject>
<para>
The second column contains the value of the relevant four TOS bits, followed by their translated meaning. For example, 15 stands for a packet wanting Minimal Monetary Cost, Maximum Reliability, Maximum Throughput AND Minimum Delay.
</para>
<para>
The fourth column lists the way the Linux kernel interprets the TOS bits, by showing to which Priority they are mapped.
</para>
<para>
The last column shows the result of the default priomap. On the command line, the default priomap looks like this:
</para>
<para>
1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
</para>
<para>
This means that priority 4, for example, gets mapped to band number 1. The priomap also allows you to list higher priorities (> 7) which do not correspond to TOS mappings, but which are set by other means.
</para>
</section>
<section id="qc-prio-classes">
<title>Classes</title>
<para>
PRIO classes cannot be configured further - they are automatically created when the PRIO qdisc is attached. Each class however can contain yet a further qdisc.
</para>
</section>
<section id="qc-prio-bugs">
<title>Bugs</title>
<para>
Large amounts of traffic in the lower bands can cause starvation of higher bands. Can be prevented by attaching a shaper to these bands to make sure they cannot dominate the link.
</para>
</section>
</section>
<section id="qc-cbq">
<title>&sch_cbq;, Class Based Queuing</title>
<para>
CBQ is the classic implementation (also called venerable) of a traffic
control system. This section will be completed at a later date.
control system. Class Based Queueing is a classful qdisc that implements a rich linksharing hierarchy of classes. It contains shaping elements as well as prioritizing capabilities. Shaping is performed using link idle time calculations based on the timing of dequeue events and underlying link bandwidth.
</para>
<section id="qc-cbq-shaping">
<title>Shaping Algorithm</title>
<para>
Shaping is done using link idle time calculations, and actions taken if these calculations deviate from set limits.
</para>
<para>
When shaping a 10mbit/s connection to 1mbit/s, the link will be idle 90% of the time. If it isn't, it needs to be throttled so that it is idle 90% of the time.
</para>
<para>
From the kernel's perspective, this is hard to measure, so CBQ instead derives the idle time from the number of microseconds that elapse between requests from the device driver for more data. Combined with the knowledge of packet sizes, this is used to approximate how full or empty the link is.
</para>
<para>
This is rather circumspect and doesn't always arrive at proper results. The physical link bandwidth may be ill defined in case of not-quite-real network devices like PPP over Ethernet or PPTP over TCP/IP. The effective bandwidth in that case is probably determined by the efficiency of pipes to userspace - which not defined.
</para>
<para>
During operations, the effective idletime is measured using an exponential weighted moving average (EWMA), which considers recent packets to be exponentially more important than past ones. The Unix loadaverage is calculated in the same way.
</para>
<para>
The calculated idle time is subtracted from the EWMA measured one, the resulting number is called 'avgidle'. A perfectly loaded link has an avgidle of zero: packets arrive exactly at the calculated interval.
</para>
<para>
An overloaded link has a negative avgidle and if it gets too negative, CBQ throttles and is then 'overlimit'. Conversely, an idle link might amass a huge avgidle, which would then allow infinite bandwidths after a few hours of silence. To prevent this, avgidle is capped at maxidle.
</para>
<para>
If overlimit, in theory, the CBQ could throttle itself for exactly the amount of time that was calculated to pass between packets, and then pass one packet, and throttle again. Due to timer resolution constraints, this may not be feasible, see the minburst parameter below.
</para>
</section>
<section id="qc-cbq-classification">
<title>Classification</title>
<para>
Within the one CBQ instance many classes may exist. Each of these classes contains another qdisc, by default <link linkend="qs-fifo">tc-pfifo</link>.
</para>
<para>
When enqueueing a packet, CBQ starts at the root and uses various methods to determine which class should receive the data. If a verdict is reached, this process is repeated for the recipient class which might have further means of classifying traffic to its children, if any. CBQ has the following methods available to classify a packet to any child classes.
</para>
<itemizedlist>
<listitem>
<para>
skb>priority class encoding. Can be set from userspace by an application with the SO_PRIORITY setsockopt. The skb->priority class encoding only applies if the skb->priority holds a major:minor handle of an existing class within this qdisc.
</para>
</listitem>
<listitem>
<para>
<emphasis> tc filters attached to the class. </emphasis>
</para>
</listitem>
<listitem>
<para>
<emphasis>The defmap of a class</emphasis>, as set with the split and defmap parameters. The defmap may contain instructions for each possible Linux packet priority.
</para>
</listitem>
</itemizedlist>
<para>
Each class also has a level. Leaf nodes, attached to the bottom of theclass hierarchy, have a level of 0.
</para>
</section>
<section id="qc-cbq-classification-algorithm">
<title>Classification Algorithm</title>
<para>
Classification is a loop, which terminates when a leaf class is found. At any point the loop may jump to the fallback algorithm. The loop consists of the following steps:
</para>
<itemizedlist>
<listitem>
<para>
If the packet is generated locally and has a valid classid encoded within its skb->priority, choose it and terminate.
</para>
</listitem>
<listitem>
<para>
Consult the tc filters, if any, attached to this child. If these return a class which is not a leaf class, restart loop from he class returned. If it is a leaf, choose it and terminate.
</para>
</listitem>
<listitem>
<para>
If the tc filters did not return a class, but did return a classid, try to find a class with that id within this qdisc. Checkif the found class is of a lower level than the current class. If so, and the returned class is not a leaf node, restart the loop at the found class. If it is a leaf node, terminate. If we found an upward reference to a higher level, enter the fallback algorithm.
</para>
</listitem>
<listitem>
<para>
If the tc filters did not return a class, nor a valid reference to one, consider the minor number of the reference to be the priority. Retrieve a class from the defmap of this class for the priority. If this did not contain a class, consult the defmap of this class for the BEST_EFFORT class. If this is an upward reference, or no BEST_EFFORT class was defined, enter the fallback algorithm. If a valid class was found, and it is not a leaf node, restart the loop at this class. If it is a leaf, choose it and terminate. If neither the priority distilled from the classid, nor the BEST_EFFORT priority yielded a class, enter the fallback algorithm.
</para>
</listitem>
</itemizedlist>
<para>
The fallback algorithm resides outside of the loop and is as follows.
</para>
<itemizedlist>
<listitem>
<para>
Consult the defmap of the class at which the jump to fallback occured. If the defmap contains a class for the priority of the class (which is related to the TOS field), choose this class and terminate.
</para>
</listitem>
<listitem>
<para>
Consult the map for a class for the BEST_EFFORT priority. If found, choose it, and terminate.
</para>
</listitem>
<listitem>
<para>
Choose the class at which break out to the fallback algorithm occurred. Terminate.
</para>
</listitem>
</itemizedlist>
<para>
The packet is enqueued to the class which was chosen when either algorithm terminated. It is therefore possible for a packet to be enqueued not at a leaf node, but in the middle of the hierarchy.
</para>
</section>
<section id="qc-cbq-link">
<title>Link Sharing Algorithm</title>
<para>
When dequeuing for sending to the network device, CBQ decides which of its classes will be allowed to send. It does so with a Weighted Round Robin process in which each class with packets gets a chance to send in turn. The WRR process starts by asking the highest priority classes (lowest numerically - highest semantically) for packets, and will continue to do so until they have no more data to offer, in which case the process repeats for lower priorities.
</para>
<para>
Each class is not allowed to send at length though, they can only dequeue a configurable amount of data during each round.
</para>
<para>
If a class is about to go overlimit, and it is not bounded it will try to borrow avgidle from siblings that are not isolated. This process is repeated from the bottom upwards. If a class is unable to borrow enough avgidle to send a packet, it is throttled and not asked for a packet for enough time for the avgidle to increase above zero.
</para>
</section>
<section id="qc-cbq-root-params">
<title>Root Parameters</title>
<para>
The root qdisc of a CBQ class tree has the following parameters:
</para>
<itemizedlist>
<listitem>
<para>
<emphasis>parent major:minor | root:</emphasis> this mandatory parameter determines the place of the CBQ instance, either at the root of an interface or within an existing class.
</para>
</listitem>
<listitem>
<para>
<emphasis>handle major:</emphasis> like all other qdiscs, the CBQ can be assigned a handle. Should consist only of a major number, followed by a colon. This parameter is optional.
</para>
</listitem>
<listitem>
<para>
<emphasis>avpkt bytes:</emphasis> for calculations, the average packet size must be known. It is silently capped at a minimum of 2/3 of the interface MTU. This parameter is Mandatory.
</para>
</listitem>
<listitem>
<para>
<emphasis>bandwidth rate:</emphasis> to determine the idle time, CBQ must know the bandwidth of your underlying physical interface, or parent qdisc. This is a vital parameter, more about it later. This parameter is Mandatory.
</para>
</listitem>
<listitem>
<para>
<emphasis>cell:</emphasis> the cell size determines the granularity of packet transmission time calculations. Has a sensible default.
</para>
</listitem>
<listitem>
<para>
<emphasis>mpu:</emphasis> a zero sized packet may still take time to transmit. This value is the lower cap for packet transmission time calculations - packets smaller than this value are still deemed to have this size. Defaults to zero.
</para>
</listitem>
<listitem>
<para>
<emphasis>ewma log:</emphasis> when CBQ needs to measure the average idle time, it does so using an Exponentially Weighted Moving Average which smooths out measurements into a moving average. The EWMA LOG determines how much smoothing occurs. Defaults to 5. Lower values imply greater sensitivity. Must be between 0 and 31.
</para>
</listitem>
</itemizedlist>
<para>
A CBQ qdisc does not shape out of its own accord. It only needs to know certain parameters about the underlying link. Actual shaping is done in classes.
</para>
</section>
<section id="qc-cbq-class-params">
<title>Class Parameters</title>
<para>
Classes have a lot of parameters to configure their operation.
</para>
<itemizedlist>
<listitem>
<para>
<emphasis>parent major:minor:</emphasis> place of this class within the hierarchy. If attached directly to a qdisc and not to another class, minor can be omitted. This parameter is mandatory.
</para>
</listitem>
<listitem>
<para>
<emphasis>classid major:minor:</emphasis> like qdiscs, classes can be named. The major number must be equal to the major number of the qdisc to which it belongs. Optional, but needed if this class is going to have children.
</para>
</listitem>
<listitem>
<para>
<emphasis>weight weight:</emphasis> when dequeuing to the interface, classes are tried for traffic in a round-robin fashion. Classes with a higher configured qdisc will generally have more traffic to offer during each round, so it makes sense to allow it to dequeue more traffic. All weights under a class are normalized, so only the ratios matter. Defaults to the configured rate, unless the priority of this class is maximal, in which case it is set to 1.
</para>
</listitem>
<listitem>
<para>
<emphasis>allot bytes:</emphasis> allot specifies how many bytes a qdisc can dequeue during each round of the process. This parameter is weighted using the renormalized class weight described above.
</para>
</listitem>
<listitem>
<para>
<emphasis>priority priority:</emphasis> in the round-robin process, classes with the lowest priority field are tried for packets first. This parameter is mandatory.
</para>
</listitem>
<listitem>
<para>
<emphasis>rate rate:</emphasis> maximum rate this class and all its children combined can sendat. This parameter is mandatory.
</para>
</listitem>
<listitem>
<para>
<emphasis>bandwidth rate:</emphasis> this is different from the bandwidth specified when creating a CBQ disc. Only used to determine maxidle and offtime, which are only calculated when specifying maxburst or minburst. Mandatory if specifying maxburst or minburst.
</para>
</listitem>
<listitem>
<para>
<emphasis>maxburst:</emphasis> this number of packets is used to calculate maxidle so that when avgidle is at maxidle, this number of average packets can be burst before avgidle drops to 0. Set it higher to be more tolerant of bursts. You can't set maxidle directly, only via this parameter.
</para>
</listitem>
<listitem>
<para>
<emphasis>minburst:</emphasis> as mentioned before, CBQ needs to throttle in case of overlimit. The ideal solution is to do so for exactly the calculated idle time, and pass 1 packet. However, Unix kernels generally have a hard time scheduling events shorter than 10ms, so it is better to throttle for a longer period, and then pass minburst packets in one go, and then sleep minburst times longer. The time to wait is called the offtime. Higher values of minburst lead to more accurate shaping in the long term, but to bigger bursts at millisecond timescales.
</para>
</listitem>
<listitem>
<para>
<emphasis>minidle:</emphasis> if avgidle is below 0, we are overlimits and need to wait until avgidle will be big enough to send one packet. To prevent a sudden burst from shutting down the link for a prolonged period of time, avgidle is reset to minidle if it gets too low. Minidle is specified in negative microseconds, so 10 means that avgidle is capped at -10us.
</para>
</listitem>
<listitem>
<para>
<emphasis>bounded:</emphasis> signifies that this class will not borrow bandwidth from its siblings.
</para>
</listitem>
<listitem>
<para>
<emphasis>isolated:</emphasis> means that this class will not borrow bandwidth to its siblings
</para>
</listitem>
<listitem>
<para>
<emphasis>split major:minor and defmap bitmap[/bitmap]:</emphasis> if consulting filters attached to a class did not give a verdict, CBQ can also classify based on the packet's priority. There are 16 priorities available, numbered from 0 to 15. The defmap specifies which priorities this class wants to receive, specified as a bitmap. The Least Significant Bit corresponds to priority zero. The split parameter tells CBQ at which class the decision must be made, which should be a (grand)parent of the class you are adding.
</para>
<para>
As an example, 'tc class add ... classid 10:1 cbq .. split 10:0 defmap c0' configures class 10:0 to send packets with priorities 6 and 7 to 10:1.
</para>
<para>
The complimentary configuration would then be: 'tc class add ... classid 10:2 cbq ... split 10:0 defmap 3f' Which would send all packets 0, 1, 2, 3, 4 and 5 to 10:1.
</para>
</listitem>
<listitem>
<para>
<emphasis>estimator interval timeconstant:</emphasis> CBQ can measure how much bandwidth each class is using, which tc filters can use to classify packets with. In order to determine the bandwidth it uses a very simple estimator that measures once every interval microseconds how much traffic has passed. This again is a EWMA, for which the time constant can be specified, also in microseconds. The time constant corresponds to the sluggishness of the measurement or, conversely, to the sensitivity of the average to short bursts. Higher values mean less sensitivity.
</para>
</listitem>
</itemizedlist>
</section>
</section>
<section id="qc-wrr">
<title>WRR, Wheighted Round Robin</title>
<para>
This qdisc is not included in the standard kernels.
</para>
<para>
The WRR qdisc distributes bandwidth between its classes using the weighted round robin scheme. That is, like the CBQ qdisc it contains classes into which arbitrary qdiscs can be plugged. All classes which have sufficient demand will get bandwidth proportional to the weights associated with the classes. The weights can be set manually using the tc program. But they can also be made automatically decreasing for classes transferring much data.
</para>
<para>
The qdisc has a built-in classifier which assigns packets coming from or sent to different machines to different classes. Either the MAC or IP and either source or destination addresses can be used. The MAC address can only be used when the Linux box is acting as an ethernet bridge, however. The classes are automatically assigned to machines based on the packets seen.
</para>
<para>
The qdisc can be very useful at sites where a lot of unrelated individuals share an Internet connection. A set of scripts setting up a relevant behavior for such a site is a central part of the WRR distribution.
</para>
</section>
</section>

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB