diff --git a/LDP/howto/docbook/Traffic-Control-HOWTO/classful-qdiscs.xml b/LDP/howto/docbook/Traffic-Control-HOWTO/classful-qdiscs.xml index 509e8820..b302b076 100644 --- a/LDP/howto/docbook/Traffic-Control-HOWTO/classful-qdiscs.xml +++ b/LDP/howto/docbook/Traffic-Control-HOWTO/classful-qdiscs.xml @@ -11,9 +11,6 @@ Documentation License (GFDL) through The Linux Documentation Project (TLDP). - This was initially authored while Martin A. Brown worked for - SecurePipe, Inc. - This HOWTO is likely available at the following address: http://tldp.org/HOWTO/Traffic-Control-HOWTO/ @@ -408,7 +405,8 @@ TC HTB version 3.3 Rules Below are some general guidelines to using &sch_htb; culled from - &url-docum.org; and the &url-lartc-mailinglist;. These rules are + &url-docum.org; and the &url-new-lartc-mailinglist-archive; (see also the + &url-old-lartc-mailinglist-archive;). These rules are simply a recommendation for beginners to maximize the benefit of &sch_htb; until gaining a better understanding of the practical application of &sch_htb;. @@ -542,10 +540,16 @@ TC HTB version 3.3
Algorithm - 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. + 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 class add. The number of bands + to be created is fixed at the creation of the qdisc itself. - 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. + When dequeueing packets, band 0 is always checked first. If it + has no packet to dequeue, then &sch_prio; will 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. 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. @@ -555,31 +559,37 @@ TC HTB version 3.3
Synopsis -$ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands bands ] [ priomap band band band... ] [ estimator interval time‐constant ] +$ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands bands ] [ priomap band band band... ] [ estimator interval time‐constant ]
Classification - Three methods are available to PRIO to determine in which band a packet will be enqueued. + Three methods are available to determine the target band in which a packet will be enqueued. - - - From userspace: a process with sufficient privileges can encode the destination class directly with SO_PRIORITY. - - - - - with a tc filter: a tc filter attached to the root qdisc can point traffic directly to a class - - - - - with the priomap: based on the packet priority, which in turn is derived from the Type of Service assigned to the packet. - - + + + From userspace, a process with + sufficient privileges can encode the destination class + directly with SO_PRIORITY. + + + + + Programmatically, a tc filter + attached to the root qdisc can point any traffic directly to a + class. + + + + + And, typically, with reference to the priomap, a packet's + priority, is derived from the Type of Service + (ToS) assigned to the packet. + + Only the priomap is specific to this qdisc. @@ -587,66 +597,228 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b
- Parameters - + Configurable parameters + + + bands - bands: number of bands. If changed from the default of 3, priomap must be updated as well. + total number of distinct bands. If changed from the default of 3, priomap must be updated as well. + + + priomap - priomap: a tc filter attached to the root qdisc can point traffic directly to a class + a tc filter attached to the root qdisc can point traffic directly to a class - + + - priomap 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: + The priomap specifies how this qdisc determines + how a packet maps to a specific band. Mapping occurs based on the + value of the ToS octet of a packet. - - - - - - - - - - - + + 0 1 2 3 4 5 6 7 ++-----+-----+-----+-----+-----+-----+-----+-----+ +| PRECEDENCE | ToS | MBZ | RFC 791 ++-----+-----+-----+-----+-----+-----+-----+-----+ + + 0 1 2 3 4 5 6 7 ++-----+-----+-----+-----+-----+-----+-----+-----+ +| DiffServ Code Point (DSCP) | (unused) | RFC 2474 ++-----+-----+-----+-----+-----+-----+-----+-----+ + - The four TOS bits (the 'TOS field') are defined as: + The four ToS bits from the (the 'ToS field') are defined slightly + differently in RFC 791 and RFC 2474. The later RFC supersedes the + definitions of the former, but not all software, systems and + terminology have caught up to that change. So, often packet + analysis programs will still refer to Type of Service (ToS) instead + of DiffServ Code Point (DSCP). - - - - - - - - - - - + + <ulink url="https://tools.ietf.org/rfc/rfc791.txt">RFC 791</ulink> interpretation of IP ToS header + + + + Binary + Decimal + Meaning + + + + + 1000 + 8 + Minimize delay (md) + + + 0100 + 4 + Maximize throughput (mt) + + + 0010 + 2 + Maximize reliability (mr) + + + 0001 + 1 + Minimize monetary cost (mmc) + + + 0000 + 0 + Normal Service + + + +
- 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: + 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. + Running 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: - - - - - - - - - - - + + Mapping ToS value to priomap band + + + + ToS Field + ToS Bits + Meaning + Linux Priority + Band + + + + + 0x0 + 0 + Normal Service + 0 Best Effort + 1 + + + 0x2 + 1 + Minimize Monetary Cost (mmc) + 1 Filler + 2 + + + 0x4 + 2 + Maximize Reliability (mr) + 0 Best Effort + 1 + + + 0x6 + 3 + mmc+mr + 0 Best Effort + 1 + + + 0x8 + 4 + Maximize Throughput (mt) + 2 Bulk + 2 + + + 0xa + 5 + mmc+mt + 2 Bulk + 2 + + + 0xc + 6 + mr+mt + 2 Bulk + 2 + + + 0xe + 7 + mmc+mr+mt + 2 Bulk + 2 + + + 0x10 + 8 + Minimize Delay (md) + 6 Interactive + 0 + + + 0x12 + 9 + mmc+md + 6 Interactive + 0 + + + 0x14 + 10 + mr+md + 6 Interactive + 0 + + + 0x16 + 11 + mmc+mr+md + 6 Interactive + 0 + + + 0x18 + 12 + mt+md + 4 Int. Bulk + 1 + + + 0x1a + 13 + mmc+mt+md + 4 Int. Bulk + 1 + + + 0x1c + 14 + mr+mt+md + 4 Int. Bulk + 1 + + + 0x1e + 15 + mmc+mr+mt+md + 4 Int. Bulk + 1 + + + +
- 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. + 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. - The fourth column lists the way the Linux kernel interprets the TOS bits, by showing to which Priority they are mapped. + The fourth column lists the way the Linux kernel interprets the ToS bits, by showing to which Priority they are mapped. The last column shows the result of the default priomap. On the command line, the default priomap looks like this: @@ -655,7 +827,7 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 - 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. + 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.
@@ -676,10 +848,15 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b
- &sch_cbq;, Class Based Queuing + &sch_cbq;, Class Based Queuing (<acronym>CBQ</acronym>) - CBQ is the classic implementation (also called venerable) of a traffic - 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. + Class Based Queuing (CBQ) is the classic + implementation (also called venerable) of a traffic control system. CBQ + is a classful qdisc that implements a rich link sharing hierarchy of + classes. It contains shaping elements as well as prioritizing + capabilities. Shaping is performed by calculating link idle time + based on the timing of dequeue events and knowledge of the underlying + link layer bandwidth.
@@ -688,16 +865,16 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b Shaping is done using link idle time calculations, and actions taken if these calculations deviate from set limits. - 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. + 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. - 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. + From the kernel's perspective, this is hard to measure, so CBQ instead computes 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. - 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. + 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. - 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. + During operations, the effective idletime is measured using an exponential weighted moving average (EWMA). This calculation of activity against idleness values recent packets exponentially more than predecessors. The EWMA is an effective calculation to deal with the problem that a system is either active or inactive. For example, the Unix system load average is calculated in the same way. 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. @@ -714,7 +891,7 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b
Classification - Within the one CBQ instance many classes may exist. Each of these classes contains another qdisc, by default tc-pfifo. + Under one installed CBQ qdisc many classes may exist. Each of these classes contains another qdisc, by default tc-pfifo. 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. @@ -732,7 +909,7 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b - The defmap of a class, as set with the split and defmap parameters. The defmap may contain instructions for each possible Linux packet priority. + The defmap of a class, as set with the split and defmap parameters. The defmap may contain instructions for each possible Linux packet priority. @@ -749,7 +926,7 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b - If the packet is generated locally and has a valid classid encoded within its skb->priority, choose it and terminate. + If the packet is generated locally and has a valid classid encoded within its skb->priority, choose it and terminate. @@ -774,7 +951,7 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b - 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. + 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. @@ -811,43 +988,84 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b The root qdisc of a CBQ class tree has the following parameters: - + + + parent root | major:minor - parent major:minor | root: this mandatory parameter determines the place of the CBQ instance, either at the root of an interface or within an existing class. + this mandatory parameter determines the place of the CBQ + instance, either at the root of an interface or within an + existing class. + + + handle major: - handle major: 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. + 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. + + + avpkt bytes - avpkt bytes: 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. + 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. + + + bandwidth rate - bandwidth rate: 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. + underlying available bandwidth; to determine the idle time, + CBQ must know the bandwidth of your A) desired target + bandwidth, B) underlying physical interface or C) parent + qdisc. This is a vital parameter, more about it later. This + parameter is mandatory. + + + cell size - cell: the cell size determines the granularity of packet transmission time calculations. Has a sensible default. + the cell size determines the granularity of packet + transmission time calculations. Must be an integral power of + 2, defaults to 8. + + + mpu bytes - mpu: 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. + 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 0. + + + ewma log - ewma log: 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. + CBQ calculates idleness using an Exponentially Weighted Moving + Average (EWMA) which smooths out + measurements easily accommodating short bursts. The + log value determines how much + smoothing occurs. Lower values imply greater sensitivity. + Must be between 0 and 31. Defaults to 5. - + + 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. @@ -858,67 +1076,150 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b Classes have a lot of parameters to configure their operation. - + + + parent major:minor - parent major:minor: 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. + 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. + + + classid major:minor - classid major:minor: 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. + 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. + + + weight weightvalue - weight weight: 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. + when dequeuing to the lower layer, 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. + + + allot bytes - allot bytes: 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. + 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. + + + priority priovalue - priority priority: in the round-robin process, classes with the lowest priority field are tried for packets first. This parameter is mandatory. + in the round-robin process, classes with the lowest priority + field are tried for packets first. This parameter is + mandatory. + + + rate bitrate - rate rate: maximum rate this class and all its children combined can sendat. This parameter is mandatory. + maximum aggregated rate at which this class (children + inclusive) can transmit. The bitrate is specified using the + tc way of specifying rates (e.g. + '1544kbit'). This parameter is mandatory. + + + bandwidth bitrate - bandwidth rate: 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. + this is different from the bandwidth specified when creating a + parent CBQ qdisc. The CBQ class + bandwidth parameter is only used to + determine maxidle and offtime, which, in turn, are only + calculated when specifying maxburst or minburst. Thus, this + parameter is only required if specifying + maxburst or + minburst. + + + maxburst packetcount + - maxburst: 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. + 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. + + + minburst packetcount - minburst: 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. + 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. + + + minidle microseconds + - minidle: 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. + minidle: 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. + + + bounded | borrow + - bounded: signifies that this class will not borrow bandwidth from its siblings. + identifies a borrowing policy. Either the class will try + to borrow bandwidth from its siblings + or it will consider itself bounded. + Mutually exclusive. + + + isolated | sharing - isolated: means that this class will not borrow bandwidth to its siblings + identifies a sharing policy. Either the class will engage + in a sharing policy toward its + siblings or it will consider itself + isolated. Mutually exclusive. + + + split major:minor and defmap bitmap[/bitmap]: 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. @@ -930,12 +1231,16 @@ $ tc qdisc ... dev dev ( parent classid | root) [ handle major: ] prio [bands b 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. + + + estimator interval timeconstant: 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. - + +