1 .TH CBQ 8 "8 December 2001" "iproute2" "Linux"
3 CBQ \- Class Based Queueing
51 .B ] [ bounded isolated ] [ split
60 Class Based Queueing is a classful qdisc that implements a rich
61 linksharing hierarchy of classes. It contains shaping elements as
62 well as prioritizing capabilities. Shaping is performed using link
63 idle time calculations based on the timing of dequeue events and
64 underlying link bandwidth.
67 Shaping is done using link idle time calculations, and actions taken if
68 these calculations deviate from set limits.
70 When shaping a 10mbit/s connection to 1mbit/s, the link will
71 be idle 90% of the time. If it isn't, it needs to be throttled so that it
72 IS idle 90% of the time.
74 From the kernel's perspective, this is hard to measure, so CBQ instead
75 derives the idle time from the number of microseconds (in fact, jiffies)
76 that elapse between requests from the device driver for more data. Combined
77 with the knowledge of packet sizes, this is used to approximate how full or
80 This is rather circumspect and doesn't always arrive at proper
81 results. For example, what is the actual link speed of an interface
82 that is not really able to transmit the full 100mbit/s of data,
83 perhaps because of a badly implemented driver? A PCMCIA network card
84 will also never achieve 100mbit/s because of the way the bus is
85 designed - again, how do we calculate the idle time?
87 The physical link bandwidth may be ill defined in case of not-quite-real
88 network devices like PPP over Ethernet or PPTP over TCP/IP. The effective
89 bandwidth in that case is probably determined by the efficiency of pipes
90 to userspace - which not defined.
92 During operations, the effective idletime is measured using an
93 exponential weighted moving average (EWMA), which considers recent
94 packets to be exponentially more important than past ones. The Unix
95 loadaverage is calculated in the same way.
97 The calculated idle time is subtracted from the EWMA measured one,
98 the resulting number is called 'avgidle'. A perfectly loaded link has
99 an avgidle of zero: packets arrive exactly at the calculated
102 An overloaded link has a negative avgidle and if it gets too negative,
103 CBQ throttles and is then 'overlimit'.
105 Conversely, an idle link might amass a huge avgidle, which would then
106 allow infinite bandwidths after a few hours of silence. To prevent
107 this, avgidle is capped at
110 If overlimit, in theory, the CBQ could throttle itself for exactly the
111 amount of time that was calculated to pass between packets, and then
112 pass one packet, and throttle again. Due to timer resolution constraints,
113 this may not be feasible, see the
118 Within the one CBQ instance many classes may exist. Each of these classes
119 contains another qdisc, by default
122 When enqueueing a packet, CBQ starts at the root and uses various methods to
123 determine which class should receive the data. If a verdict is reached, this
124 process is repeated for the recipient class which might have further
125 means of classifying traffic to its children, if any.
127 CBQ has the following methods available to classify a packet to any child
131 .B skb->priority class encoding.
132 Can be set from userspace by an application with the
136 .B skb->priority class encoding
137 only applies if the skb->priority holds a major:minor handle of an existing
138 class within this qdisc.
141 tc filters attached to the class.
144 The defmap of a class, as set with the
146 parameters. The defmap may contain instructions for each possible Linux packet
150 Each class also has a
152 Leaf nodes, attached to the bottom of the class hierarchy, have a level of 0.
153 .SH CLASSIFICATION ALGORITHM
155 Classification is a loop, which terminates when a leaf class is found. At any
156 point the loop may jump to the fallback algorithm.
158 The loop consists of the following steps:
161 If the packet is generated locally and has a valid classid encoded within its
163 choose it and terminate.
167 Consult the tc filters, if any, attached to this child. If these return
168 a class which is not a leaf class, restart loop from the class returned.
169 If it is a leaf, choose it and terminate.
172 If the tc filters did not return a class, but did return a classid,
173 try to find a class with that id within this qdisc.
174 Check if the found class is of a lower
176 than the current class. If so, and the returned class is not a leaf node,
177 restart the loop at the found class. If it is a leaf node, terminate.
178 If we found an upward reference to a higher level, enter the fallback
182 If the tc filters did not return a class, nor a valid reference to one,
183 consider the minor number of the reference to be the priority. Retrieve
184 a class from the defmap of this class for the priority. If this did not
185 contain a class, consult the defmap of this class for the
187 class. If this is an upward reference, or no
190 enter the fallback algorithm. If a valid class was found, and it is not a
191 leaf node, restart the loop at this class. If it is a leaf, choose it and
193 neither the priority distilled from the classid, nor the
195 priority yielded a class, enter the fallback algorithm.
197 The fallback algorithm resides outside of the loop and is as follows.
200 Consult the defmap of the class at which the jump to fallback occured. If
201 the defmap contains a class for the
204 of the class (which is related to the TOS field), choose this class and
208 Consult the map for a class for the
210 priority. If found, choose it, and terminate.
213 Choose the class at which break out to the fallback algorithm occured. Terminate.
215 The packet is enqueued to the class which was chosen when either algorithm
216 terminated. It is therefore possible for a packet to be enqueued *not* at a
217 leaf node, but in the middle of the hierarchy.
219 .SH LINK SHARING ALGORITHM
220 When dequeuing for sending to the network device, CBQ decides which of its
221 classes will be allowed to send. It does so with a Weighted Round Robin process
222 in which each class with packets gets a chance to send in turn. The WRR process
223 starts by asking the highest priority classes (lowest numerically -
224 highest semantically) for packets, and will continue to do so until they
225 have no more data to offer, in which case the process repeats for lower
228 .B CERTAINTY ENDS HERE, ANK PLEASE HELP
230 Each class is not allowed to send at length though - they can only dequeue a
231 configurable amount of data during each round.
233 If a class is about to go overlimit, and it is not
235 it will try to borrow avgidle from siblings that are not
237 This process is repeated from the bottom upwards. If a class is unable
238 to borrow enough avgidle to send a packet, it is throttled and not asked
239 for a packet for enough time for the avgidle to increase above zero.
241 .B I REALLY NEED HELP FIGURING THIS OUT. REST OF DOCUMENT IS PRETTY CERTAIN
245 The root qdisc of a CBQ class tree has the following parameters:
248 parent major:minor | root
249 This mandatory parameter determines the place of the CBQ instance, either at the
251 of an interface or within an existing class.
254 Like all other qdiscs, the CBQ can be assigned a handle. Should consist only
255 of a major number, followed by a colon. Optional.
258 For calculations, the average packet size must be known. It is silently capped
259 at a minimum of 2/3 of the interface MTU. Mandatory.
262 To determine the idle time, CBQ must know the bandwidth of your underlying
263 physical interface, or parent qdisc. This is a vital parameter, more about it
267 The cell size determines he granularity of packet transmission time calculations. Has a sensible default.
270 A zero sized packet may still take time to transmit. This value is the lower
271 cap for packet transmission time calculations - packets smaller than this value
272 are still deemed to have this size. Defaults to zero.
275 When CBQ needs to measure the average idle time, it does so using an
276 Exponentially Weighted Moving Average which smoothes out measurements into
277 a moving average. The EWMA LOG determines how much smoothing occurs. Defaults
278 to 5. Lower values imply greater sensitivity. Must be between 0 and 31.
280 A CBQ qdisc does not shape out of its own accord. It only needs to know certain
281 parameters about the underlying link. Actual shaping is done in classes.
284 Classes have a host of parameters to configure their operation.
288 Place of this class within the hierarchy. If attached directly to a qdisc
289 and not to another class, minor can be omitted. Mandatory.
292 Like qdiscs, classes can be named. The major number must be equal to the
293 major number of the qdisc to which it belongs. Optional, but needed if this
294 class is going to have children.
297 When dequeuing to the interface, classes are tried for traffic in a
298 round-robin fashion. Classes with a higher configured qdisc will generally
299 have more traffic to offer during each round, so it makes sense to allow
300 it to dequeue more traffic. All weights under a class are normalized, so
301 only the ratios matter. Defaults to the configured rate, unless the priority
302 of this class is maximal, in which case it is set to 1.
305 Allot specifies how many bytes a qdisc can dequeue
306 during each round of the process. This parameter is weighted using the
307 renormalized class weight described above.
311 In the round-robin process, classes with the lowest priority field are tried
312 for packets first. Mandatory.
316 Maximum rate this class and all its children combined can send at. Mandatory.
320 This is different from the bandwidth specified when creating a CBQ disc. Only
321 used to determine maxidle and offtime, which are only calculated when
322 specifying maxburst or minburst. Mandatory if specifying maxburst or minburst.
326 This number of packets is used to calculate maxidle so that when
327 avgidle is at maxidle, this number of average packets can be burst
328 before avgidle drops to 0. Set it higher to be more tolerant of
329 bursts. You can't set maxidle directly, only via this parameter.
333 As mentioned before, CBQ needs to throttle in case of
334 overlimit. The ideal solution is to do so for exactly the calculated
335 idle time, and pass 1 packet. However, Unix kernels generally have a
336 hard time scheduling events shorter than 10ms, so it is better to
337 throttle for a longer period, and then pass minburst packets in one
338 go, and then sleep minburst times longer.
340 The time to wait is called the offtime. Higher values of minburst lead
341 to more accurate shaping in the long term, but to bigger bursts at
342 millisecond timescales.
346 If avgidle is below 0, we are overlimits and need to wait until
347 avgidle will be big enough to send one packet. To prevent a sudden
348 burst from shutting down the link for a prolonged period of time,
349 avgidle is reset to minidle if it gets too low.
351 Minidle is specified in negative microseconds, so 10 means that
352 avgidle is capped at -10us.
356 Signifies that this class will not borrow bandwidth from its siblings.
359 Means that this class will not borrow bandwidth to its siblings
362 split major:minor & defmap bitmap[/bitmap]
363 If consulting filters attached to a class did not give a verdict,
364 CBQ can also classify based on the packet's priority. There are 16
365 priorities available, numbered from 0 to 15.
367 The defmap specifies which priorities this class wants to receive,
368 specified as a bitmap. The Least Significant Bit corresponds to priority
371 parameter tells CBQ at which class the decision must be made, which should
372 be a (grand)parent of the class you are adding.
374 As an example, 'tc class add ... classid 10:1 cbq .. split 10:0 defmap c0'
375 configures class 10:0 to send packets with priorities 6 and 7 to 10:1.
377 The complimentary configuration would then
378 be: 'tc class add ... classid 10:2 cbq ... split 10:0 defmap 3f'
379 Which would send all packets 0, 1, 2, 3, 4 and 5 to 10:1.
381 estimator interval timeconstant
382 CBQ can measure how much bandwidth each class is using, which tc filters
383 can use to classify packets with. In order to determine the bandwidth
384 it uses a very simple estimator that measures once every
386 microseconds how much traffic has passed. This again is a EWMA, for which
387 the time constant can be specified, also in microseconds. The
389 corresponds to the sluggishness of the measurement or, conversely, to the
390 sensitivity of the average to short bursts. Higher values mean less
398 Sally Floyd and Van Jacobson, "Link-sharing and Resource
399 Management Models for Packet Networks",
400 IEEE/ACM Transactions on Networking, Vol.3, No.4, 1995
404 Sally Floyd, "Notes on CBQ and Guarantee Service", 1995
408 Sally Floyd, "Notes on Class-Based Queueing: Setting
413 Sally Floyd and Michael Speer, "Experimental Results
414 for Class-Based Queueing", 1998, not published.
422 Alexey N. Kuznetsov, <kuznet@ms2.inr.ac.ru>. This manpage maintained by
423 bert hubert <ahu@ds9a.nl>