Blame man/man8/tc-cbq-details.8

Packit Service 3880ab
.TH CBQ 8 "8 December 2001" "iproute2" "Linux"
Packit Service 3880ab
.SH NAME
Packit Service 3880ab
CBQ \- Class Based Queueing
Packit Service 3880ab
.SH SYNOPSIS
Packit Service 3880ab
.B tc qdisc ... dev
Packit Service 3880ab
dev
Packit Service 3880ab
.B  ( parent
Packit Service 3880ab
classid
Packit Service 3880ab
.B | root) [ handle
Packit Service 3880ab
major:
Packit Service 3880ab
.B ] cbq avpkt
Packit Service 3880ab
bytes
Packit Service 3880ab
.B bandwidth
Packit Service 3880ab
rate
Packit Service 3880ab
.B [ cell
Packit Service 3880ab
bytes
Packit Service 3880ab
.B ] [ ewma
Packit Service 3880ab
log
Packit Service 3880ab
.B ] [ mpu
Packit Service 3880ab
bytes
Packit Service 3880ab
.B ]
Packit Service 3880ab
Packit Service 3880ab
.B tc class ... dev
Packit Service 3880ab
dev
Packit Service 3880ab
.B parent
Packit Service 3880ab
major:[minor]
Packit Service 3880ab
.B [ classid
Packit Service 3880ab
major:minor
Packit Service 3880ab
.B ] cbq allot
Packit Service 3880ab
bytes
Packit Service 3880ab
.B [ bandwidth
Packit Service 3880ab
rate
Packit Service 3880ab
.B ] [ rate
Packit Service 3880ab
rate
Packit Service 3880ab
.B ] prio
Packit Service 3880ab
priority
Packit Service 3880ab
.B [ weight
Packit Service 3880ab
weight
Packit Service 3880ab
.B ] [ minburst
Packit Service 3880ab
packets
Packit Service 3880ab
.B ] [ maxburst
Packit Service 3880ab
packets
Packit Service 3880ab
.B ] [ ewma
Packit Service 3880ab
log
Packit Service 3880ab
.B ] [ cell
Packit Service 3880ab
bytes
Packit Service 3880ab
.B ] avpkt
Packit Service 3880ab
bytes
Packit Service 3880ab
.B [ mpu
Packit Service 3880ab
bytes
Packit Service 3880ab
.B ] [ bounded isolated ] [ split
Packit Service 3880ab
handle
Packit Service 3880ab
.B & defmap
Packit Service 3880ab
defmap
Packit Service 3880ab
.B ] [ estimator
Packit Service 3880ab
interval timeconstant
Packit Service 3880ab
.B ]
Packit Service 3880ab
Packit Service 3880ab
.SH DESCRIPTION
Packit Service 3880ab
Class Based Queueing is a classful qdisc that implements a rich
Packit Service 3880ab
linksharing hierarchy of classes. It contains shaping elements as
Packit Service 3880ab
well as prioritizing capabilities. Shaping is performed using link
Packit Service 3880ab
idle time calculations based on the timing of dequeue events and
Packit Service 3880ab
underlying link bandwidth.
Packit Service 3880ab
Packit Service 3880ab
.SH SHAPING ALGORITHM
Packit Service 3880ab
Shaping is done using link idle time calculations, and actions taken if
Packit Service 3880ab
these calculations deviate from set limits.
Packit Service 3880ab
Packit Service 3880ab
When shaping a 10mbit/s connection to 1mbit/s, the link will
Packit Service 3880ab
be idle 90% of the time. If it isn't, it needs to be throttled so that it
Packit Service 3880ab
IS idle 90% of the time.
Packit Service 3880ab
Packit Service 3880ab
From the kernel's perspective, this is hard to measure, so CBQ instead
Packit Service 3880ab
derives the idle time from the number of microseconds (in fact, jiffies)
Packit Service 3880ab
that elapse between  requests from the device driver for more data. Combined
Packit Service 3880ab
with the  knowledge of packet sizes, this is used to approximate how full or
Packit Service 3880ab
empty the link is.
Packit Service 3880ab
Packit Service 3880ab
This is rather circumspect and doesn't always arrive at proper
Packit Service 3880ab
results. For example, what is the actual link speed of an interface
Packit Service 3880ab
that is not really able to transmit the full 100mbit/s of data,
Packit Service 3880ab
perhaps because of a badly implemented driver? A PCMCIA network card
Packit Service 3880ab
will also never achieve 100mbit/s because of the way the bus is
Packit Service 3880ab
designed - again, how do we calculate the idle time?
Packit Service 3880ab
Packit Service 3880ab
The physical link bandwidth may be ill defined in case of not-quite-real
Packit Service 3880ab
network devices like PPP over Ethernet or PPTP over TCP/IP. The effective
Packit Service 3880ab
bandwidth in that case is probably determined by the efficiency of pipes
Packit Service 3880ab
to userspace - which not defined.
Packit Service 3880ab
Packit Service 3880ab
During operations, the effective idletime is measured using an
Packit Service 3880ab
exponential weighted moving average (EWMA), which considers recent
Packit Service 3880ab
packets to be exponentially more important than past ones. The Unix
Packit Service 3880ab
loadaverage is calculated in the same way.
Packit Service 3880ab
Packit Service 3880ab
The calculated idle time is subtracted from the EWMA measured one,
Packit Service 3880ab
the resulting number is called 'avgidle'. A perfectly loaded link has
Packit Service 3880ab
an avgidle of zero: packets arrive exactly at the calculated
Packit Service 3880ab
interval.
Packit Service 3880ab
Packit Service 3880ab
An overloaded link has a negative avgidle and if it gets too negative,
Packit Service 3880ab
CBQ throttles and is then 'overlimit'.
Packit Service 3880ab
Packit Service 3880ab
Conversely, an idle link might amass a huge avgidle, which would then
Packit Service 3880ab
allow infinite bandwidths after a few hours of silence. To prevent
Packit Service 3880ab
this, avgidle is capped at
Packit Service 3880ab
.B maxidle.
Packit Service 3880ab
Packit Service 3880ab
If overlimit, in theory, the CBQ could throttle itself for exactly the
Packit Service 3880ab
amount of time that was calculated to pass between packets, and then
Packit Service 3880ab
pass one packet, and throttle again. Due to timer resolution constraints,
Packit Service 3880ab
this may not be feasible, see the
Packit Service 3880ab
.B minburst
Packit Service 3880ab
parameter below.
Packit Service 3880ab
Packit Service 3880ab
.SH CLASSIFICATION
Packit Service 3880ab
Within the one CBQ instance many classes may exist. Each of these classes
Packit Service 3880ab
contains another qdisc, by default
Packit Service 3880ab
.BR tc-pfifo (8).
Packit Service 3880ab
Packit Service 3880ab
When enqueueing a packet, CBQ starts at the root and uses various methods to
Packit Service 3880ab
determine which class should receive the data. If a verdict is reached, this
Packit Service 3880ab
process is repeated for the recipient class which might have further
Packit Service 3880ab
means of classifying traffic to its children, if any.
Packit Service 3880ab
Packit Service 3880ab
CBQ has the following methods available to classify a packet to any child
Packit Service 3880ab
classes.
Packit Service 3880ab
.TP
Packit Service 3880ab
(i)
Packit Service 3880ab
.B skb->priority class encoding.
Packit Service 3880ab
Can be set from userspace by an application with the
Packit Service 3880ab
.B SO_PRIORITY
Packit Service 3880ab
setsockopt.
Packit Service 3880ab
The
Packit Service 3880ab
.B skb->priority class encoding
Packit Service 3880ab
only applies if the skb->priority holds a major:minor handle of an existing
Packit Service 3880ab
class within  this qdisc.
Packit Service 3880ab
.TP
Packit Service 3880ab
(ii)
Packit Service 3880ab
tc filters attached to the class.
Packit Service 3880ab
.TP
Packit Service 3880ab
(iii)
Packit Service 3880ab
The defmap of a class, as set with the
Packit Service 3880ab
.B split & defmap
Packit Service 3880ab
parameters. The defmap may contain instructions for each possible Linux packet
Packit Service 3880ab
priority.
Packit Service 3880ab
Packit Service 3880ab
.P
Packit Service 3880ab
Each class also has a
Packit Service 3880ab
.B level.
Packit Service 3880ab
Leaf nodes, attached to the bottom of the class hierarchy, have a level of 0.
Packit Service 3880ab
.SH CLASSIFICATION ALGORITHM
Packit Service 3880ab
Packit Service 3880ab
Classification is a loop, which terminates when a leaf class is found. At any
Packit Service 3880ab
point the loop may jump to the fallback algorithm.
Packit Service 3880ab
Packit Service 3880ab
The loop consists of the following steps:
Packit Service 3880ab
.TP
Packit Service 3880ab
(i)
Packit Service 3880ab
If the packet is generated locally and has a valid classid encoded within its
Packit Service 3880ab
.B skb->priority,
Packit Service 3880ab
choose it and terminate.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
(ii)
Packit Service 3880ab
Consult the tc filters, if any, attached to this child. If these return
Packit Service 3880ab
a class which is not a leaf class, restart loop from the class returned.
Packit Service 3880ab
If it is a leaf, choose it and terminate.
Packit Service 3880ab
.TP
Packit Service 3880ab
(iii)
Packit Service 3880ab
If the tc filters did not return a class, but did return a classid,
Packit Service 3880ab
try to find a class with that id within this qdisc.
Packit Service 3880ab
Check if the found class is of a lower
Packit Service 3880ab
.B level
Packit Service 3880ab
than the current class. If so, and the returned class is not a leaf node,
Packit Service 3880ab
restart the loop at the found class. If it is a leaf node, terminate.
Packit Service 3880ab
If we found an upward reference to a higher level, enter the fallback
Packit Service 3880ab
algorithm.
Packit Service 3880ab
.TP
Packit Service 3880ab
(iv)
Packit Service 3880ab
If the tc filters did not return a class, nor a valid reference to one,
Packit Service 3880ab
consider the minor number of the reference to be the priority. Retrieve
Packit Service 3880ab
a class from the defmap of this class for the priority. If this did not
Packit Service 3880ab
contain a class, consult the defmap of this class for the
Packit Service 3880ab
.B BEST_EFFORT
Packit Service 3880ab
class. If this is an upward reference, or no
Packit Service 3880ab
.B BEST_EFFORT
Packit Service 3880ab
class was defined,
Packit Service 3880ab
enter the fallback algorithm. If a valid class was found, and it is not a
Packit Service 3880ab
leaf node, restart the loop at this class. If it is a leaf, choose it and
Packit Service 3880ab
terminate. If
Packit Service 3880ab
neither the priority distilled from the classid, nor the
Packit Service 3880ab
.B BEST_EFFORT
Packit Service 3880ab
priority yielded a class, enter the fallback algorithm.
Packit Service 3880ab
.P
Packit Service 3880ab
The fallback algorithm resides outside of the loop and is as follows.
Packit Service 3880ab
.TP
Packit Service 3880ab
(i)
Packit Service 3880ab
Consult the defmap of the class at which the jump to fallback occurred. If
Packit Service 3880ab
the defmap contains a class for the
Packit Service 3880ab
.B
Packit Service 3880ab
priority
Packit Service 3880ab
of the class (which is related to the TOS field), choose this class and
Packit Service 3880ab
terminate.
Packit Service 3880ab
.TP
Packit Service 3880ab
(ii)
Packit Service 3880ab
Consult the map for a class for the
Packit Service 3880ab
.B BEST_EFFORT
Packit Service 3880ab
priority. If found, choose it, and terminate.
Packit Service 3880ab
.TP
Packit Service 3880ab
(iii)
Packit Service 3880ab
Choose the class at which break out to the fallback algorithm occurred. Terminate.
Packit Service 3880ab
.P
Packit Service 3880ab
The packet is enqueued to the class which was chosen when either algorithm
Packit Service 3880ab
terminated. It is therefore possible for a packet to be enqueued *not* at a
Packit Service 3880ab
leaf node, but in the middle of the hierarchy.
Packit Service 3880ab
Packit Service 3880ab
.SH LINK SHARING ALGORITHM
Packit Service 3880ab
When dequeuing for sending to the network device, CBQ decides which of its
Packit Service 3880ab
classes will be allowed to send. It does so with a Weighted Round Robin process
Packit Service 3880ab
in which each class with packets gets a chance to send in turn. The WRR process
Packit Service 3880ab
starts by asking the highest priority classes (lowest numerically -
Packit Service 3880ab
highest semantically) for packets, and will continue to do so until they
Packit Service 3880ab
have no more data to offer, in which case the process repeats for lower
Packit Service 3880ab
priorities.
Packit Service 3880ab
Packit Service 3880ab
.B CERTAINTY ENDS HERE, ANK PLEASE HELP
Packit Service 3880ab
Packit Service 3880ab
Each class is not allowed to send at length though - they can only dequeue a
Packit Service 3880ab
configurable amount of data during each round.
Packit Service 3880ab
Packit Service 3880ab
If a class is about to go overlimit, and it is not
Packit Service 3880ab
.B bounded
Packit Service 3880ab
it will try to borrow avgidle from siblings that are not
Packit Service 3880ab
.B isolated.
Packit Service 3880ab
This process is repeated from the bottom upwards. If a class is unable
Packit Service 3880ab
to borrow enough avgidle to send a packet, it is throttled and not asked
Packit Service 3880ab
for a packet for enough time for the avgidle to increase above zero.
Packit Service 3880ab
Packit Service 3880ab
.B I REALLY NEED HELP FIGURING THIS OUT. REST OF DOCUMENT IS PRETTY CERTAIN
Packit Service 3880ab
.B AGAIN.
Packit Service 3880ab
Packit Service 3880ab
.SH QDISC
Packit Service 3880ab
The root qdisc of a CBQ class tree has the following parameters:
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
parent major:minor | root
Packit Service 3880ab
This mandatory parameter determines the place of the CBQ instance, either at the
Packit Service 3880ab
.B root
Packit Service 3880ab
of an interface or within an existing class.
Packit Service 3880ab
.TP
Packit Service 3880ab
handle major:
Packit Service 3880ab
Like all other qdiscs, the CBQ can be assigned a handle. Should consist only
Packit Service 3880ab
of a major number, followed by a colon. Optional.
Packit Service 3880ab
.TP
Packit Service 3880ab
avpkt bytes
Packit Service 3880ab
For calculations, the average packet size must be known. It is silently capped
Packit Service 3880ab
at a minimum of 2/3 of the interface MTU. Mandatory.
Packit Service 3880ab
.TP
Packit Service 3880ab
bandwidth rate
Packit Service 3880ab
To determine the idle time, CBQ must know the bandwidth of your underlying
Packit Service 3880ab
physical interface, or parent qdisc. This is a vital parameter, more about it
Packit Service 3880ab
later. Mandatory.
Packit Service 3880ab
.TP
Packit Service 3880ab
cell
Packit Service 3880ab
The cell size determines he granularity of packet transmission time calculations. Has a sensible default.
Packit Service 3880ab
.TP
Packit Service 3880ab
mpu
Packit Service 3880ab
A zero sized packet may still take time to transmit. This value is the lower
Packit Service 3880ab
cap for packet transmission time calculations - packets smaller than this value
Packit Service 3880ab
are still deemed to have this size. Defaults to zero.
Packit Service 3880ab
.TP
Packit Service 3880ab
ewma log
Packit Service 3880ab
When CBQ needs to measure the average idle time, it does so using an
Packit Service 3880ab
Exponentially Weighted Moving Average which smooths out measurements into
Packit Service 3880ab
a moving average. The EWMA LOG determines how much smoothing occurs. Defaults
Packit Service 3880ab
to 5. Lower values imply greater sensitivity. Must be between 0 and 31.
Packit Service 3880ab
.P
Packit Service 3880ab
A CBQ qdisc does not shape out of its own accord. It only needs to know certain
Packit Service 3880ab
parameters about the underlying link. Actual shaping is done in classes.
Packit Service 3880ab
Packit Service 3880ab
.SH CLASSES
Packit Service 3880ab
Classes have a host of parameters to configure their operation.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
parent major:minor
Packit Service 3880ab
Place of this class within the hierarchy. If attached directly to a qdisc
Packit Service 3880ab
and not to another class, minor can be omitted. Mandatory.
Packit Service 3880ab
.TP
Packit Service 3880ab
classid major:minor
Packit Service 3880ab
Like qdiscs, classes can be named. The major number must be equal to the
Packit Service 3880ab
major number of the qdisc to which it belongs. Optional, but needed if this
Packit Service 3880ab
class is going to have children.
Packit Service 3880ab
.TP
Packit Service 3880ab
weight weight
Packit Service 3880ab
When dequeuing to the interface, classes are tried for traffic in a
Packit Service 3880ab
round-robin fashion. Classes with a higher configured qdisc will generally
Packit Service 3880ab
have more traffic to offer during each round, so it makes sense to allow
Packit Service 3880ab
it to dequeue more traffic. All weights under a class are normalized, so
Packit Service 3880ab
only the ratios matter. Defaults to the configured rate, unless the priority
Packit Service 3880ab
of this class is maximal, in which case it is set to 1.
Packit Service 3880ab
.TP
Packit Service 3880ab
allot bytes
Packit Service 3880ab
Allot specifies how many bytes a qdisc can dequeue
Packit Service 3880ab
during each round of the process. This parameter is weighted using the
Packit Service 3880ab
renormalized class weight described above.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
priority priority
Packit Service 3880ab
In the round-robin process, classes with the lowest priority field are tried
Packit Service 3880ab
for packets first. Mandatory.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
rate rate
Packit Service 3880ab
Maximum rate this class and all its children combined can send at. Mandatory.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
bandwidth rate
Packit Service 3880ab
This is different from the bandwidth specified when creating a CBQ disc. Only
Packit Service 3880ab
used to determine maxidle and offtime, which are only calculated when
Packit Service 3880ab
specifying maxburst or minburst. Mandatory if specifying maxburst or minburst.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
maxburst
Packit Service 3880ab
This number of packets is used to calculate maxidle so that when
Packit Service 3880ab
avgidle is at maxidle, this number of average packets can be burst
Packit Service 3880ab
before avgidle drops to 0. Set it higher to be more tolerant of
Packit Service 3880ab
bursts. You can't set maxidle directly, only via this parameter.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
minburst
Packit Service 3880ab
As mentioned before, CBQ needs to throttle in case of
Packit Service 3880ab
overlimit. The ideal solution is to do so for exactly the calculated
Packit Service 3880ab
idle time, and pass 1 packet. However, Unix kernels generally have a
Packit Service 3880ab
hard time scheduling events shorter than 10ms, so it is better to
Packit Service 3880ab
throttle for a longer period, and then pass minburst packets in one
Packit Service 3880ab
go, and then sleep minburst times longer.
Packit Service 3880ab
Packit Service 3880ab
The time to wait is called the offtime. Higher values of minburst lead
Packit Service 3880ab
to more accurate shaping in the long term, but to bigger bursts at
Packit Service 3880ab
millisecond timescales.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
minidle
Packit Service 3880ab
If avgidle is below 0, we are overlimits and need to wait until
Packit Service 3880ab
avgidle will be big enough to send one packet. To prevent a sudden
Packit Service 3880ab
burst from shutting down the link for a prolonged period of time,
Packit Service 3880ab
avgidle is reset to minidle if it gets too low.
Packit Service 3880ab
Packit Service 3880ab
Minidle is specified in negative microseconds, so 10 means that
Packit Service 3880ab
avgidle is capped at -10us.
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
bounded
Packit Service 3880ab
Signifies that this class will not borrow bandwidth from its siblings.
Packit Service 3880ab
.TP
Packit Service 3880ab
isolated
Packit Service 3880ab
Means that this class will not borrow bandwidth to its siblings
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
split major:minor & defmap bitmap[/bitmap]
Packit Service 3880ab
If consulting filters attached to a class did not give a verdict,
Packit Service 3880ab
CBQ can also classify based on the packet's priority. There are 16
Packit Service 3880ab
priorities available, numbered from 0 to 15.
Packit Service 3880ab
Packit Service 3880ab
The defmap specifies which priorities this class wants to receive,
Packit Service 3880ab
specified as a bitmap. The Least Significant Bit corresponds to priority
Packit Service 3880ab
zero. The
Packit Service 3880ab
.B split
Packit Service 3880ab
parameter tells CBQ at which class the decision must be made, which should
Packit Service 3880ab
be a (grand)parent of the class you are adding.
Packit Service 3880ab
Packit Service 3880ab
As an example, 'tc class add ... classid 10:1 cbq .. split 10:0 defmap c0'
Packit Service 3880ab
configures class 10:0 to send packets with priorities 6 and 7 to 10:1.
Packit Service 3880ab
Packit Service 3880ab
The complimentary configuration would then
Packit Service 3880ab
be: 'tc class add ... classid 10:2 cbq ... split 10:0 defmap 3f'
Packit Service 3880ab
Which would send all packets 0, 1, 2, 3, 4 and 5 to 10:1.
Packit Service 3880ab
.TP
Packit Service 3880ab
estimator interval timeconstant
Packit Service 3880ab
CBQ can measure how much bandwidth each class is using, which tc filters
Packit Service 3880ab
can use to classify packets with. In order to determine the bandwidth
Packit Service 3880ab
it uses a very simple estimator that measures once every
Packit Service 3880ab
.B interval
Packit Service 3880ab
microseconds how much traffic has passed. This again is a EWMA, for which
Packit Service 3880ab
the time constant can be specified, also in microseconds. The
Packit Service 3880ab
.B time constant
Packit Service 3880ab
corresponds to the sluggishness of the measurement or, conversely, to the
Packit Service 3880ab
sensitivity of the average to short bursts. Higher values mean less
Packit Service 3880ab
sensitivity.
Packit Service 3880ab
Packit Service 3880ab
Packit Service 3880ab
Packit Service 3880ab
.SH SOURCES
Packit Service 3880ab
.TP
Packit Service 3880ab
o
Packit Service 3880ab
Sally Floyd and Van Jacobson, "Link-sharing and Resource
Packit Service 3880ab
Management Models for Packet Networks",
Packit Service 3880ab
IEEE/ACM Transactions on Networking, Vol.3, No.4, 1995
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
o
Packit Service 3880ab
Sally Floyd, "Notes on CBQ and Guarantee Service", 1995
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
o
Packit Service 3880ab
Sally Floyd, "Notes on Class-Based Queueing: Setting
Packit Service 3880ab
Parameters", 1996
Packit Service 3880ab
Packit Service 3880ab
.TP
Packit Service 3880ab
o
Packit Service 3880ab
Sally Floyd and Michael Speer, "Experimental Results
Packit Service 3880ab
for Class-Based Queueing", 1998, not published.
Packit Service 3880ab
Packit Service 3880ab
Packit Service 3880ab
Packit Service 3880ab
.SH SEE ALSO
Packit Service 3880ab
.BR tc (8)
Packit Service 3880ab
Packit Service 3880ab
.SH AUTHOR
Packit Service 3880ab
Alexey N. Kuznetsov, <kuznet@ms2.inr.ac.ru>. This manpage maintained by
Packit Service 3880ab
bert hubert <ahu@ds9a.nl>