iproute2: tc: bump to support kmod-sched-cake
[openwrt/openwrt.git] / package / network / utils / iproute2 / patches / 950-add-cake-to-tc.patch
1 --- a/include/linux/pkt_sched.h
2 +++ b/include/linux/pkt_sched.h
3 @@ -852,2 +852,116 @@ enum {
4 };
5 +/* CAKE */
6 +enum {
7 + TCA_CAKE_UNSPEC,
8 + TCA_CAKE_PAD,
9 + TCA_CAKE_BASE_RATE64,
10 + TCA_CAKE_DIFFSERV_MODE,
11 + TCA_CAKE_ATM,
12 + TCA_CAKE_FLOW_MODE,
13 + TCA_CAKE_OVERHEAD,
14 + TCA_CAKE_RTT,
15 + TCA_CAKE_TARGET,
16 + TCA_CAKE_AUTORATE,
17 + TCA_CAKE_MEMORY,
18 + TCA_CAKE_NAT,
19 + TCA_CAKE_RAW, // was _ETHERNET
20 + TCA_CAKE_WASH,
21 + TCA_CAKE_MPU,
22 + TCA_CAKE_INGRESS,
23 + TCA_CAKE_ACK_FILTER,
24 + TCA_CAKE_SPLIT_GSO,
25 + __TCA_CAKE_MAX
26 +};
27 +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
28 +
29 +enum {
30 + __TCA_CAKE_STATS_INVALID,
31 + TCA_CAKE_STATS_PAD,
32 + TCA_CAKE_STATS_CAPACITY_ESTIMATE64,
33 + TCA_CAKE_STATS_MEMORY_LIMIT,
34 + TCA_CAKE_STATS_MEMORY_USED,
35 + TCA_CAKE_STATS_AVG_NETOFF,
36 + TCA_CAKE_STATS_MIN_NETLEN,
37 + TCA_CAKE_STATS_MAX_NETLEN,
38 + TCA_CAKE_STATS_MIN_ADJLEN,
39 + TCA_CAKE_STATS_MAX_ADJLEN,
40 + TCA_CAKE_STATS_TIN_STATS,
41 + TCA_CAKE_STATS_DEFICIT,
42 + TCA_CAKE_STATS_COBALT_COUNT,
43 + TCA_CAKE_STATS_DROPPING,
44 + TCA_CAKE_STATS_DROP_NEXT_US,
45 + TCA_CAKE_STATS_P_DROP,
46 + TCA_CAKE_STATS_BLUE_TIMER_US,
47 + __TCA_CAKE_STATS_MAX
48 +};
49 +#define TCA_CAKE_STATS_MAX (__TCA_CAKE_STATS_MAX - 1)
50 +
51 +enum {
52 + __TCA_CAKE_TIN_STATS_INVALID,
53 + TCA_CAKE_TIN_STATS_PAD,
54 + TCA_CAKE_TIN_STATS_SENT_PACKETS,
55 + TCA_CAKE_TIN_STATS_SENT_BYTES64,
56 + TCA_CAKE_TIN_STATS_DROPPED_PACKETS,
57 + TCA_CAKE_TIN_STATS_DROPPED_BYTES64,
58 + TCA_CAKE_TIN_STATS_ACKS_DROPPED_PACKETS,
59 + TCA_CAKE_TIN_STATS_ACKS_DROPPED_BYTES64,
60 + TCA_CAKE_TIN_STATS_ECN_MARKED_PACKETS,
61 + TCA_CAKE_TIN_STATS_ECN_MARKED_BYTES64,
62 + TCA_CAKE_TIN_STATS_BACKLOG_PACKETS,
63 + TCA_CAKE_TIN_STATS_BACKLOG_BYTES,
64 + TCA_CAKE_TIN_STATS_THRESHOLD_RATE64,
65 + TCA_CAKE_TIN_STATS_TARGET_US,
66 + TCA_CAKE_TIN_STATS_INTERVAL_US,
67 + TCA_CAKE_TIN_STATS_WAY_INDIRECT_HITS,
68 + TCA_CAKE_TIN_STATS_WAY_MISSES,
69 + TCA_CAKE_TIN_STATS_WAY_COLLISIONS,
70 + TCA_CAKE_TIN_STATS_PEAK_DELAY_US,
71 + TCA_CAKE_TIN_STATS_AVG_DELAY_US,
72 + TCA_CAKE_TIN_STATS_BASE_DELAY_US,
73 + TCA_CAKE_TIN_STATS_SPARSE_FLOWS,
74 + TCA_CAKE_TIN_STATS_BULK_FLOWS,
75 + TCA_CAKE_TIN_STATS_UNRESPONSIVE_FLOWS,
76 + TCA_CAKE_TIN_STATS_MAX_SKBLEN,
77 + TCA_CAKE_TIN_STATS_FLOW_QUANTUM,
78 + __TCA_CAKE_TIN_STATS_MAX
79 +};
80 +#define TCA_CAKE_TIN_STATS_MAX (__TCA_CAKE_TIN_STATS_MAX - 1)
81 +#define TC_CAKE_MAX_TINS (8)
82 +
83 +enum {
84 + CAKE_FLOW_NONE = 0,
85 + CAKE_FLOW_SRC_IP,
86 + CAKE_FLOW_DST_IP,
87 + CAKE_FLOW_HOSTS, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_DST_IP */
88 + CAKE_FLOW_FLOWS,
89 + CAKE_FLOW_DUAL_SRC, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_FLOWS */
90 + CAKE_FLOW_DUAL_DST, /* = CAKE_FLOW_DST_IP | CAKE_FLOW_FLOWS */
91 + CAKE_FLOW_TRIPLE, /* = CAKE_FLOW_HOSTS | CAKE_FLOW_FLOWS */
92 + CAKE_FLOW_MAX,
93 +};
94 +
95 +enum {
96 + CAKE_DIFFSERV_DIFFSERV3 = 0,
97 + CAKE_DIFFSERV_DIFFSERV4,
98 + CAKE_DIFFSERV_DIFFSERV8,
99 + CAKE_DIFFSERV_BESTEFFORT,
100 + CAKE_DIFFSERV_PRECEDENCE,
101 + CAKE_DIFFSERV_MAX
102 +};
103 +
104 +enum {
105 + CAKE_ACK_NONE = 0,
106 + CAKE_ACK_FILTER,
107 + CAKE_ACK_AGGRESSIVE,
108 + CAKE_ACK_MAX
109 +};
110 +
111 +enum {
112 + CAKE_ATM_NONE = 0,
113 + CAKE_ATM_ATM,
114 + CAKE_ATM_PTM,
115 + CAKE_ATM_MAX
116 +};
117 +
118 +
119 #endif
120 --- /dev/null
121 +++ b/man/man8/tc-cake.8
122 @@ -0,0 +1,632 @@
123 +.TH CAKE 8 "23 November 2017" "iproute2" "Linux"
124 +.SH NAME
125 +CAKE \- Common Applications Kept Enhanced (CAKE)
126 +.SH SYNOPSIS
127 +.B tc qdisc ... cake
128 +.br
129 +[
130 +.BR bandwidth
131 +RATE |
132 +.BR unlimited*
133 +|
134 +.BR autorate_ingress
135 +]
136 +.br
137 +[
138 +.BR rtt
139 +TIME |
140 +.BR datacentre
141 +|
142 +.BR lan
143 +|
144 +.BR metro
145 +|
146 +.BR regional
147 +|
148 +.BR internet*
149 +|
150 +.BR oceanic
151 +|
152 +.BR satellite
153 +|
154 +.BR interplanetary
155 +]
156 +.br
157 +[
158 +.BR besteffort
159 +|
160 +.BR diffserv8
161 +|
162 +.BR diffserv4
163 +|
164 +.BR diffserv3*
165 +]
166 +.br
167 +[
168 +.BR flowblind
169 +|
170 +.BR srchost
171 +|
172 +.BR dsthost
173 +|
174 +.BR hosts
175 +|
176 +.BR flows
177 +|
178 +.BR dual-srchost
179 +|
180 +.BR dual-dsthost
181 +|
182 +.BR triple-isolate*
183 +]
184 +.br
185 +[
186 +.BR nat
187 +|
188 +.BR nonat*
189 +]
190 +.br
191 +[
192 +.BR wash
193 +|
194 +.BR nowash*
195 +]
196 +.br
197 +[
198 +.BR ack-filter
199 +|
200 +.BR ack-filter-aggressive
201 +|
202 +.BR no-ack-filter*
203 +]
204 +.br
205 +[
206 +.BR memlimit
207 +LIMIT ]
208 +.br
209 +[
210 +.BR ptm
211 +|
212 +.BR atm
213 +|
214 +.BR noatm*
215 +]
216 +.br
217 +[
218 +.BR overhead
219 +N |
220 +.BR conservative
221 +|
222 +.BR raw*
223 +]
224 +.br
225 +[
226 +.BR mpu
227 +N ]
228 +.br
229 +[
230 +.BR ingress
231 +|
232 +.BR egress*
233 +]
234 +.br
235 +(* marks defaults)
236 +
237 +
238 +.SH DESCRIPTION
239 +CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline
240 +which uses both AQM and FQ. It combines COBALT, which is an AQM algorithm
241 +combining Codel and BLUE, a shaper which operates in deficit mode, and a variant
242 +of DRR++ for flow isolation. 8-way set-associative hashing is used to virtually
243 +eliminate hash collisions. Priority queuing is available through a simplified
244 +diffserv implementation. Overhead compensation for various encapsulation
245 +schemes is tightly integrated.
246 +
247 +All settings are optional; the default settings are chosen to be sensible in
248 +most common deployments. Most people will only need to set the
249 +.B bandwidth
250 +parameter to get useful results, but reading the
251 +.B Overhead Compensation
252 +and
253 +.B Round Trip Time
254 +sections is strongly encouraged.
255 +
256 +.SH SHAPER PARAMETERS
257 +CAKE uses a deficit-mode shaper, which does not exhibit the initial burst
258 +typical of token-bucket shapers. It will automatically burst precisely as much
259 +as required to maintain the configured throughput. As such, it is very
260 +straightforward to configure.
261 +.PP
262 +.B unlimited
263 +(default)
264 +.br
265 + No limit on the bandwidth.
266 +.PP
267 +.B bandwidth
268 +RATE
269 +.br
270 + Set the shaper bandwidth. See
271 +.BR tc(8)
272 +or examples below for details of the RATE value.
273 +.PP
274 +.B autorate_ingress
275 +.br
276 + Automatic capacity estimation based on traffic arriving at this qdisc.
277 +This is most likely to be useful with cellular links, which tend to change
278 +quality randomly. A
279 +.B bandwidth
280 +parameter can be used in conjunction to specify an initial estimate. The shaper
281 +will periodically be set to a bandwidth slightly below the estimated rate. This
282 +estimator cannot estimate the bandwidth of links downstream of itself.
283 +
284 +.SH OVERHEAD COMPENSATION PARAMETERS
285 +The size of each packet on the wire may differ from that seen by Linux. The
286 +following parameters allow CAKE to compensate for this difference by internally
287 +considering each packet to be bigger than Linux informs it. To assist users who
288 +are not expert network engineers, keywords have been provided to represent a
289 +number of common link technologies.
290 +
291 +.SS Manual Overhead Specification
292 +.B overhead
293 +BYTES
294 +.br
295 + Adds BYTES to the size of each packet. BYTES may be negative; values
296 +between -64 and 256 (inclusive) are accepted.
297 +.PP
298 +.B mpu
299 +BYTES
300 +.br
301 + Rounds each packet (including overhead) up to a minimum length
302 +BYTES. BYTES may not be negative; values between 0 and 256 (inclusive)
303 +are accepted.
304 +.PP
305 +.B atm
306 +.br
307 + Compensates for ATM cell framing, which is normally found on ADSL links.
308 +This is performed after the
309 +.B overhead
310 +parameter above. ATM uses fixed 53-byte cells, each of which can carry 48 bytes
311 +payload.
312 +.PP
313 +.B ptm
314 +.br
315 + Compensates for PTM encoding, which is normally found on VDSL2 links and
316 +uses a 64b/65b encoding scheme. It is even more efficient to simply
317 +derate the specified shaper bandwidth by a factor of 64/65 or 0.984. See
318 +ITU G.992.3 Annex N and IEEE 802.3 Section 61.3 for details.
319 +.PP
320 +.B noatm
321 +.br
322 + Disables ATM and PTM compensation.
323 +
324 +.SS Failsafe Overhead Keywords
325 +These two keywords are provided for quick-and-dirty setup. Use them if you
326 +can't be bothered to read the rest of this section.
327 +.PP
328 +.B raw
329 +(default)
330 +.br
331 + Turns off all overhead compensation in CAKE. The packet size reported
332 +by Linux will be used directly.
333 +.PP
334 + Other overhead keywords may be added after "raw". The effect of this is
335 +to make the overhead compensation operate relative to the reported packet size,
336 +not the underlying IP packet size.
337 +.PP
338 +.B conservative
339 +.br
340 + Compensates for more overhead than is likely to occur on any
341 +widely-deployed link technology.
342 +.br
343 + Equivalent to
344 +.B overhead 48 atm.
345 +
346 +.SS ADSL Overhead Keywords
347 +Most ADSL modems have a way to check which framing scheme is in use. Often this
348 +is also specified in the settings document provided by the ISP. The keywords in
349 +this section are intended to correspond with these sources of information. All
350 +of them implicitly set the
351 +.B atm
352 +flag.
353 +.PP
354 +.B pppoa-vcmux
355 +.br
356 + Equivalent to
357 +.B overhead 10 atm
358 +.PP
359 +.B pppoa-llc
360 +.br
361 + Equivalent to
362 +.B overhead 14 atm
363 +.PP
364 +.B pppoe-vcmux
365 +.br
366 + Equivalent to
367 +.B overhead 32 atm
368 +.PP
369 +.B pppoe-llcsnap
370 +.br
371 + Equivalent to
372 +.B overhead 40 atm
373 +.PP
374 +.B bridged-vcmux
375 +.br
376 + Equivalent to
377 +.B overhead 24 atm
378 +.PP
379 +.B bridged-llcsnap
380 +.br
381 + Equivalent to
382 +.B overhead 32 atm
383 +.PP
384 +.B ipoa-vcmux
385 +.br
386 + Equivalent to
387 +.B overhead 8 atm
388 +.PP
389 +.B ipoa-llcsnap
390 +.br
391 + Equivalent to
392 +.B overhead 16 atm
393 +.PP
394 +See also the Ethernet Correction Factors section below.
395 +
396 +.SS VDSL2 Overhead Keywords
397 +ATM was dropped from VDSL2 in favour of PTM, which is a much more
398 +straightforward framing scheme. Some ISPs retained PPPoE for compatibility with
399 +their existing back-end systems.
400 +.PP
401 +.B pppoe-ptm
402 +.br
403 + Equivalent to
404 +.B overhead 30 ptm
405 +
406 +.br
407 + PPPoE: 2B PPP + 6B PPPoE +
408 +.br
409 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
410 +.br
411 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
412 +.br
413 +.PP
414 +.B bridged-ptm
415 +.br
416 + Equivalent to
417 +.B overhead 22 ptm
418 +.br
419 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
420 +.br
421 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
422 +.br
423 +.PP
424 +See also the Ethernet Correction Factors section below.
425 +
426 +.SS DOCSIS Cable Overhead Keyword
427 +DOCSIS is the universal standard for providing Internet service over cable-TV
428 +infrastructure.
429 +
430 +In this case, the actual on-wire overhead is less important than the packet size
431 +the head-end equipment uses for shaping and metering. This is specified to be
432 +an Ethernet frame including the CRC (aka FCS).
433 +.PP
434 +.B docsis
435 +.br
436 + Equivalent to
437 +.B overhead 18 mpu 64 noatm
438 +
439 +.SS Ethernet Overhead Keywords
440 +.PP
441 +.B ethernet
442 +.br
443 + Accounts for Ethernet's preamble, inter-frame gap, and Frame Check
444 +Sequence. Use this keyword when the bottleneck being shaped for is an
445 +actual Ethernet cable.
446 +.br
447 + Equivalent to
448 +.B overhead 38 mpu 84 noatm
449 +.PP
450 +.B ether-vlan
451 +.br
452 + Adds 4 bytes to the overhead compensation, accounting for an IEEE 802.1Q
453 +VLAN header appended to the Ethernet frame header. NB: Some ISPs use one or
454 +even two of these within PPPoE; this keyword may be repeated as necessary to
455 +express this.
456 +
457 +.SH ROUND TRIP TIME PARAMETERS
458 +Active Queue Management (AQM) consists of embedding congestion signals in the
459 +packet flow, which receivers use to instruct senders to slow down when the queue
460 +is persistently occupied. CAKE uses ECN signalling when available, and packet
461 +drops otherwise, according to a combination of the Codel and BLUE AQM algorithms
462 +called COBALT.
463 +
464 +Very short latencies require a very rapid AQM response to adequately control
465 +latency. However, such a rapid response tends to impair throughput when the
466 +actual RTT is relatively long. CAKE allows specifying the RTT it assumes for
467 +tuning various parameters. Actual RTTs within an order of magnitude of this
468 +will generally work well for both throughput and latency management.
469 +
470 +At the 'lan' setting and below, the time constants are similar in magnitude to
471 +the jitter in the Linux kernel itself, so congestion might be signalled
472 +prematurely. The flows will then become sparse and total throughput reduced,
473 +leaving little or no back-pressure for the fairness logic to work against. Use
474 +the "metro" setting for local lans unless you have a custom kernel.
475 +.PP
476 +.B rtt
477 +TIME
478 +.br
479 + Manually specify an RTT.
480 +.PP
481 +.B datacentre
482 +.br
483 + For extremely high-performance 10GigE+ networks only. Equivalent to
484 +.B rtt 100us.
485 +.PP
486 +.B lan
487 +.br
488 + For pure Ethernet (not Wi-Fi) networks, at home or in the office. Don't
489 +use this when shaping for an Internet access link. Equivalent to
490 +.B rtt 1ms.
491 +.PP
492 +.B metro
493 +.br
494 + For traffic mostly within a single city. Equivalent to
495 +.B rtt 10ms.
496 +.PP
497 +.B regional
498 +.br
499 + For traffic mostly within a European-sized country. Equivalent to
500 +.B rtt 30ms.
501 +.PP
502 +.B internet
503 +(default)
504 +.br
505 + This is suitable for most Internet traffic. Equivalent to
506 +.B rtt 100ms.
507 +.PP
508 +.B oceanic
509 +.br
510 + For Internet traffic with generally above-average latency, such as that
511 +suffered by Australasian residents. Equivalent to
512 +.B rtt 300ms.
513 +.PP
514 +.B satellite
515 +.br
516 + For traffic via geostationary satellites. Equivalent to
517 +.B rtt 1000ms.
518 +.PP
519 +.B interplanetary
520 +.br
521 + So named because Jupiter is about 1 light-hour from Earth. Use this to
522 +(almost) completely disable AQM actions. Equivalent to
523 +.B rtt 1000s.
524 +
525 +.SH FLOW ISOLATION PARAMETERS
526 +With flow isolation enabled, CAKE places packets from different flows into
527 +different queues, each of which carries its own AQM state. Packets from each
528 +queue are then delivered fairly, according to a DRR++ algorithm which minimises
529 +latency for "sparse" flows. CAKE uses a set-associative hashing algorithm to
530 +minimise flow collisions.
531 +
532 +These keywords specify whether fairness based on source address, destination
533 +address, individual flows, or any combination of those is desired.
534 +.PP
535 +.B flowblind
536 +.br
537 + Disables flow isolation; all traffic passes through a single queue for
538 +each tin.
539 +.PP
540 +.B srchost
541 +.br
542 + Flows are defined only by source address. Could be useful on the egress
543 +path of an ISP backhaul.
544 +.PP
545 +.B dsthost
546 +.br
547 + Flows are defined only by destination address. Could be useful on the
548 +ingress path of an ISP backhaul.
549 +.PP
550 +.B hosts
551 +.br
552 + Flows are defined by source-destination host pairs. This is host
553 +isolation, rather than flow isolation.
554 +.PP
555 +.B flows
556 +.br
557 + Flows are defined by the entire 5-tuple of source address, destination
558 +address, transport protocol, source port and destination port. This is the type
559 +of flow isolation performed by SFQ and fq_codel.
560 +.PP
561 +.B dual-srchost
562 +.br
563 + Flows are defined by the 5-tuple, and fairness is applied first over
564 +source addresses, then over individual flows. Good for use on egress traffic
565 +from a LAN to the internet, where it'll prevent any one LAN host from
566 +monopolising the uplink, regardless of the number of flows they use.
567 +.PP
568 +.B dual-dsthost
569 +.br
570 + Flows are defined by the 5-tuple, and fairness is applied first over
571 +destination addresses, then over individual flows. Good for use on ingress
572 +traffic to a LAN from the internet, where it'll prevent any one LAN host from
573 +monopolising the downlink, regardless of the number of flows they use.
574 +.PP
575 +.B triple-isolate
576 +(default)
577 +.br
578 + Flows are defined by the 5-tuple, and fairness is applied over source
579 +*and* destination addresses intelligently (ie. not merely by host-pairs), and
580 +also over individual flows. Use this if you're not certain whether to use
581 +dual-srchost or dual-dsthost; it'll do both jobs at once, preventing any one
582 +host on *either* side of the link from monopolising it with a large number of
583 +flows.
584 +.PP
585 +.B nat
586 +.br
587 + Instructs Cake to perform a NAT lookup before applying flow-isolation
588 +rules, to determine the true addresses and port numbers of the packet, to
589 +improve fairness between hosts "inside" the NAT. This has no practical effect
590 +in "flowblind" or "flows" modes, or if NAT is performed on a different host.
591 +.PP
592 +.B nonat
593 +(default)
594 +.br
595 + Cake will not perform a NAT lookup. Flow isolation will be performed
596 +using the addresses and port numbers directly visible to the interface Cake is
597 +attached to.
598 +
599 +.SH PRIORITY QUEUE PARAMETERS
600 +CAKE can divide traffic into "tins" based on the Diffserv field. Each tin has
601 +its own independent set of flow-isolation queues, and is serviced based on a WRR
602 +algorithm. To avoid perverse Diffserv marking incentives, tin weights have a
603 +"priority sharing" value when bandwidth used by that tin is below a threshold,
604 +and a lower "bandwidth sharing" value when above. Bandwidth is compared against
605 +the threshold using the same algorithm as the deficit-mode shaper.
606 +
607 +Detailed customisation of tin parameters is not provided. The following presets
608 +perform all necessary tuning, relative to the current shaper bandwidth and RTT
609 +settings.
610 +.PP
611 +.B besteffort
612 +.br
613 + Disables priority queuing by placing all traffic in one tin.
614 +.PP
615 +.B precedence
616 +.br
617 + Enables legacy interpretation of TOS "Precedence" field. Use of this
618 +preset on the modern Internet is firmly discouraged.
619 +.PP
620 +.B diffserv4
621 +.br
622 + Provides a general-purpose Diffserv implementation with four tins:
623 +.br
624 + Bulk (CS1), 6.25% threshold, generally low priority.
625 +.br
626 + Best Effort (general), 100% threshold.
627 +.br
628 + Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, TOS1), 50% threshold.
629 +.br
630 + Voice (CS7, CS6, EF, VA, CS5, CS4), 25% threshold.
631 +.PP
632 +.B diffserv3
633 +(default)
634 +.br
635 + Provides a simple, general-purpose Diffserv implementation with three tins:
636 +.br
637 + Bulk (CS1), 6.25% threshold, generally low priority.
638 +.br
639 + Best Effort (general), 100% threshold.
640 +.br
641 + Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
642 +
643 +.SH OTHER PARAMETERS
644 +.B memlimit
645 +LIMIT
646 +.br
647 + Limit the memory consumed by Cake to LIMIT bytes. Note that this does
648 +not translate directly to queue size (so do not size this based on bandwidth
649 +delay product considerations, but rather on worst case acceptable memory
650 +consumption), as there is some overhead in the data structures containing the
651 +packets, especially for small packets.
652 +
653 + By default, the limit is calculated based on the bandwidth and RTT
654 +settings.
655 +
656 +.PP
657 +.B wash
658 +
659 +.br
660 + Traffic entering your diffserv domain is frequently mis-marked in
661 +transit from the perspective of your network, and traffic exiting yours may be
662 +mis-marked from the perspective of the transiting provider.
663 +
664 +Apply the wash option to clear all extra diffserv (but not ECN bits), after
665 +priority queuing has taken place.
666 +
667 +If you are shaping inbound, and cannot trust the diffserv markings (as is the
668 +case for Comcast Cable, among others), it is best to use a single queue
669 +"besteffort" mode with wash.
670 +
671 +.SH EXAMPLES
672 +# tc qdisc delete root dev eth0
673 +.br
674 +# tc qdisc add root dev eth0 cake bandwidth 100Mbit ethernet
675 +.br
676 +# tc -s qdisc show dev eth0
677 +.br
678 +qdisc cake 1: dev eth0 root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
679 + Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
680 + backlog 0b 0p requeues 0
681 + memory used: 0b of 5000000b
682 + capacity estimate: 100Mbit
683 + min/max network layer size: 65535 / 0
684 + min/max overhead-adjusted size: 65535 / 0
685 + average network hdr offset: 0
686 +
687 + Bulk Best Effort Voice
688 + thresh 6250Kbit 100Mbit 25Mbit
689 + target 5.0ms 5.0ms 5.0ms
690 + interval 100.0ms 100.0ms 100.0ms
691 + pk_delay 0us 0us 0us
692 + av_delay 0us 0us 0us
693 + sp_delay 0us 0us 0us
694 + pkts 0 0 0
695 + bytes 0 0 0
696 + way_inds 0 0 0
697 + way_miss 0 0 0
698 + way_cols 0 0 0
699 + drops 0 0 0
700 + marks 0 0 0
701 + ack_drop 0 0 0
702 + sp_flows 0 0 0
703 + bk_flows 0 0 0
704 + un_flows 0 0 0
705 + max_len 0 0 0
706 + quantum 300 1514 762
707 +
708 +After some use:
709 +.br
710 +# tc -s qdisc show dev eth0
711 +
712 +qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
713 + Sent 44709231 bytes 31931 pkt (dropped 45, overlimits 93782 requeues 0)
714 + backlog 33308b 22p requeues 0
715 + memory used: 292352b of 5000000b
716 + capacity estimate: 100Mbit
717 + min/max network layer size: 28 / 1500
718 + min/max overhead-adjusted size: 84 / 1538
719 + average network hdr offset: 14
720 +
721 + Bulk Best Effort Voice
722 + thresh 6250Kbit 100Mbit 25Mbit
723 + target 5.0ms 5.0ms 5.0ms
724 + interval 100.0ms 100.0ms 100.0ms
725 + pk_delay 8.7ms 6.9ms 5.0ms
726 + av_delay 4.9ms 5.3ms 3.8ms
727 + sp_delay 727us 1.4ms 511us
728 + pkts 2590 21271 8137
729 + bytes 3081804 30302659 11426206
730 + way_inds 0 46 0
731 + way_miss 3 17 4
732 + way_cols 0 0 0
733 + drops 20 15 10
734 + marks 0 0 0
735 + ack_drop 0 0 0
736 + sp_flows 2 4 1
737 + bk_flows 1 2 1
738 + un_flows 0 0 0
739 + max_len 1514 1514 1514
740 + quantum 300 1514 762
741 +
742 +.SH SEE ALSO
743 +.BR tc (8),
744 +.BR tc-codel (8),
745 +.BR tc-fq_codel (8),
746 +.BR tc-red (8)
747 +
748 +.SH AUTHORS
749 +Cake's principal author is Jonathan Morton, with contributions from
750 +Tony Ambardar, Kevin Darbyshire-Bryant, Toke Høiland-Jørgensen,
751 +Sebastian Moeller, Ryan Mounce, Dean Scarff, Nils Andreas Svee, and Dave Täht.
752 +
753 +This manual page was written by Loganaden Velvindron. Please report corrections
754 +to the Linux Networking mailing list <netdev@vger.kernel.org>.
755 --- a/tc/Makefile
756 +++ b/tc/Makefile
757 @@ -64,6 +64,7 @@ TCMODULES += em_meta.o
758 TCMODULES += q_mqprio.o
759 TCMODULES += q_codel.o
760 TCMODULES += q_fq_codel.o
761 +TCMODULES += q_cake.o
762 TCMODULES += q_fq.o
763 TCMODULES += q_pie.o
764 TCMODULES += q_hhf.o
765 --- /dev/null
766 +++ b/tc/q_cake.c
767 @@ -0,0 +1,730 @@
768 +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
769 +/*
770 + * Common Applications Kept Enhanced -- CAKE
771 + *
772 + * Copyright (C) 2014-2018 Jonathan Morton <chromatix99@gmail.com>
773 + * Copyright (C) 2017-2018 Toke Høiland-Jørgensen <toke@toke.dk>
774 + */
775 +
776 +#include <stddef.h>
777 +#include <stdio.h>
778 +#include <stdlib.h>
779 +#include <unistd.h>
780 +#include <syslog.h>
781 +#include <fcntl.h>
782 +#include <sys/socket.h>
783 +#include <netinet/in.h>
784 +#include <arpa/inet.h>
785 +#include <string.h>
786 +
787 +#include "utils.h"
788 +#include "tc_util.h"
789 +
790 +struct cake_preset {
791 + char *name;
792 + unsigned int target;
793 + unsigned int interval;
794 +};
795 +
796 +static struct cake_preset presets[] = {
797 + {"datacentre", 5, 100},
798 + {"lan", 50, 1000},
799 + {"metro", 500, 10000},
800 + {"regional", 1500, 30000},
801 + {"internet", 5000, 100000},
802 + {"oceanic", 15000, 300000},
803 + {"satellite", 50000, 1000000},
804 + {"interplanetary", 50000000, 1000000000},
805 +};
806 +
807 +
808 +static struct cake_preset *find_preset(char *argv)
809 +{
810 + int i;
811 +
812 + for (i = 0; i < ARRAY_SIZE(presets); i++)
813 + if (!strcmp(argv, presets[i].name))
814 + return &presets[i];
815 + return NULL;
816 +}
817 +
818 +static void explain(void)
819 +{
820 + fprintf(stderr,
821 +"Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
822 +" [ rtt TIME | datacentre | lan | metro | regional |\n"
823 +" internet* | oceanic | satellite | interplanetary ]\n"
824 +" [ besteffort | diffserv8 | diffserv4 | diffserv3* ]\n"
825 +" [ flowblind | srchost | dsthost | hosts | flows |\n"
826 +" dual-srchost | dual-dsthost | triple-isolate* ]\n"
827 +" [ nat | nonat* ]\n"
828 +" [ wash | nowash* ]\n"
829 +" [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
830 +" [ memlimit LIMIT ]\n"
831 +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
832 +" [ mpu N ] [ ingress | egress* ]\n"
833 +" (* marks defaults)\n");
834 +}
835 +
836 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
837 + struct nlmsghdr *n, const char *dev)
838 +{
839 + int unlimited = 0;
840 + __u64 bandwidth = 0;
841 + unsigned interval = 0;
842 + unsigned target = 0;
843 + unsigned diffserv = 0;
844 + unsigned memlimit = 0;
845 + int overhead = 0;
846 + bool overhead_set = false;
847 + bool overhead_override = false;
848 + int mpu = 0;
849 + int flowmode = -1;
850 + int nat = -1;
851 + int atm = -1;
852 + int autorate = -1;
853 + int wash = -1;
854 + int ingress = -1;
855 + int ack_filter = -1;
856 + struct rtattr *tail;
857 + struct cake_preset *preset, *preset_set = NULL;
858 +
859 + while (argc > 0) {
860 + if (strcmp(*argv, "bandwidth") == 0) {
861 + NEXT_ARG();
862 + if (get_rate64(&bandwidth, *argv)) {
863 + fprintf(stderr, "Illegal \"bandwidth\"\n");
864 + return -1;
865 + }
866 + unlimited = 0;
867 + autorate = 0;
868 + } else if (strcmp(*argv, "unlimited") == 0) {
869 + bandwidth = 0;
870 + unlimited = 1;
871 + autorate = 0;
872 + } else if (strcmp(*argv, "autorate_ingress") == 0) {
873 + autorate = 1;
874 +
875 + } else if (strcmp(*argv, "rtt") == 0) {
876 + NEXT_ARG();
877 + if (get_time(&interval, *argv)) {
878 + fprintf(stderr, "Illegal \"rtt\"\n");
879 + return -1;
880 + }
881 + target = interval / 20;
882 + if(!target)
883 + target = 1;
884 + } else if ((preset = find_preset(*argv))) {
885 + if (preset_set)
886 + duparg(*argv, preset_set->name);
887 + preset_set = preset;
888 + target = preset->target;
889 + interval = preset->interval;
890 +
891 + } else if (strcmp(*argv, "besteffort") == 0) {
892 + diffserv = CAKE_DIFFSERV_BESTEFFORT;
893 + } else if (strcmp(*argv, "precedence") == 0) {
894 + diffserv = CAKE_DIFFSERV_PRECEDENCE;
895 + } else if (strcmp(*argv, "diffserv8") == 0) {
896 + diffserv = CAKE_DIFFSERV_DIFFSERV8;
897 + } else if (strcmp(*argv, "diffserv4") == 0) {
898 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
899 + } else if (strcmp(*argv, "diffserv") == 0) {
900 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
901 + } else if (strcmp(*argv, "diffserv3") == 0) {
902 + diffserv = CAKE_DIFFSERV_DIFFSERV3;
903 +
904 + } else if (strcmp(*argv, "nowash") == 0) {
905 + wash = 0;
906 + } else if (strcmp(*argv, "wash") == 0) {
907 + wash = 1;
908 +
909 + } else if (strcmp(*argv, "flowblind") == 0) {
910 + flowmode = CAKE_FLOW_NONE;
911 + } else if (strcmp(*argv, "srchost") == 0) {
912 + flowmode = CAKE_FLOW_SRC_IP;
913 + } else if (strcmp(*argv, "dsthost") == 0) {
914 + flowmode = CAKE_FLOW_DST_IP;
915 + } else if (strcmp(*argv, "hosts") == 0) {
916 + flowmode = CAKE_FLOW_HOSTS;
917 + } else if (strcmp(*argv, "flows") == 0) {
918 + flowmode = CAKE_FLOW_FLOWS;
919 + } else if (strcmp(*argv, "dual-srchost") == 0) {
920 + flowmode = CAKE_FLOW_DUAL_SRC;
921 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
922 + flowmode = CAKE_FLOW_DUAL_DST;
923 + } else if (strcmp(*argv, "triple-isolate") == 0) {
924 + flowmode = CAKE_FLOW_TRIPLE;
925 +
926 + } else if (strcmp(*argv, "nat") == 0) {
927 + nat = 1;
928 + } else if (strcmp(*argv, "nonat") == 0) {
929 + nat = 0;
930 +
931 + } else if (strcmp(*argv, "ptm") == 0) {
932 + atm = CAKE_ATM_PTM;
933 + } else if (strcmp(*argv, "atm") == 0) {
934 + atm = CAKE_ATM_ATM;
935 + } else if (strcmp(*argv, "noatm") == 0) {
936 + atm = CAKE_ATM_NONE;
937 +
938 + } else if (strcmp(*argv, "raw") == 0) {
939 + atm = CAKE_ATM_NONE;
940 + overhead = 0;
941 + overhead_set = true;
942 + overhead_override = true;
943 + } else if (strcmp(*argv, "conservative") == 0) {
944 + /*
945 + * Deliberately over-estimate overhead:
946 + * one whole ATM cell plus ATM framing.
947 + * A safe choice if the actual overhead is unknown.
948 + */
949 + atm = CAKE_ATM_ATM;
950 + overhead = 48;
951 + overhead_set = true;
952 +
953 + /* Various ADSL framing schemes, all over ATM cells */
954 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
955 + atm = CAKE_ATM_ATM;
956 + overhead += 8;
957 + overhead_set = true;
958 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
959 + atm = CAKE_ATM_ATM;
960 + overhead += 16;
961 + overhead_set = true;
962 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
963 + atm = CAKE_ATM_ATM;
964 + overhead += 24;
965 + overhead_set = true;
966 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
967 + atm = CAKE_ATM_ATM;
968 + overhead += 32;
969 + overhead_set = true;
970 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
971 + atm = CAKE_ATM_ATM;
972 + overhead += 10;
973 + overhead_set = true;
974 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
975 + atm = CAKE_ATM_ATM;
976 + overhead += 14;
977 + overhead_set = true;
978 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
979 + atm = CAKE_ATM_ATM;
980 + overhead += 32;
981 + overhead_set = true;
982 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
983 + atm = CAKE_ATM_ATM;
984 + overhead += 40;
985 + overhead_set = true;
986 +
987 + /* Typical VDSL2 framing schemes, both over PTM */
988 + /* PTM has 64b/65b coding which absorbs some bandwidth */
989 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
990 + /* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
991 + * + 2B ethertype + 4B Frame Check Sequence
992 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
993 + * + 2B TC-CRC (PTM-FCS) = 30B
994 + */
995 + atm = CAKE_ATM_PTM;
996 + overhead += 30;
997 + overhead_set = true;
998 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
999 + /* 6B dest MAC + 6B src MAC + 2B ethertype
1000 + * + 4B Frame Check Sequence
1001 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1002 + * + 2B TC-CRC (PTM-FCS) = 22B
1003 + */
1004 + atm = CAKE_ATM_PTM;
1005 + overhead += 22;
1006 + overhead_set = true;
1007 +
1008 + } else if (strcmp(*argv, "via-ethernet") == 0) {
1009 + /*
1010 + * We used to use this flag to manually compensate for
1011 + * Linux including the Ethernet header on Ethernet-type
1012 + * interfaces, but not on IP-type interfaces.
1013 + *
1014 + * It is no longer needed, because Cake now adjusts for
1015 + * that automatically, and is thus ignored.
1016 + *
1017 + * It would be deleted entirely, but it appears in the
1018 + * stats output when the automatic compensation is
1019 + * active.
1020 + */
1021 +
1022 + } else if (strcmp(*argv, "ethernet") == 0) {
1023 + /* ethernet pre-amble & interframe gap & FCS
1024 + * you may need to add vlan tag */
1025 + overhead += 38;
1026 + overhead_set = true;
1027 + mpu = 84;
1028 +
1029 + /* Additional Ethernet-related overhead used by some ISPs */
1030 + } else if (strcmp(*argv, "ether-vlan") == 0) {
1031 + /* 802.1q VLAN tag - may be repeated */
1032 + overhead += 4;
1033 + overhead_set = true;
1034 +
1035 + /*
1036 + * DOCSIS cable shapers account for Ethernet frame with FCS,
1037 + * but not interframe gap or preamble.
1038 + */
1039 + } else if (strcmp(*argv, "docsis") == 0) {
1040 + atm = CAKE_ATM_NONE;
1041 + overhead += 18;
1042 + overhead_set = true;
1043 + mpu = 64;
1044 +
1045 + } else if (strcmp(*argv, "overhead") == 0) {
1046 + char* p = NULL;
1047 + NEXT_ARG();
1048 + overhead = strtol(*argv, &p, 10);
1049 + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
1050 + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
1051 + return -1;
1052 + }
1053 + overhead_set = true;
1054 +
1055 + } else if (strcmp(*argv, "mpu") == 0) {
1056 + char* p = NULL;
1057 + NEXT_ARG();
1058 + mpu = strtol(*argv, &p, 10);
1059 + if(!p || *p || !*argv || mpu < 0 || mpu > 256) {
1060 + fprintf(stderr, "Illegal \"mpu\", valid range is 0 to 256\\n");
1061 + return -1;
1062 + }
1063 +
1064 + } else if (strcmp(*argv, "ingress") == 0) {
1065 + ingress = 1;
1066 + } else if (strcmp(*argv, "egress") == 0) {
1067 + ingress = 0;
1068 +
1069 + } else if (strcmp(*argv, "no-ack-filter") == 0) {
1070 + ack_filter = CAKE_ACK_NONE;
1071 + } else if (strcmp(*argv, "ack-filter") == 0) {
1072 + ack_filter = CAKE_ACK_FILTER;
1073 + } else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
1074 + ack_filter = CAKE_ACK_AGGRESSIVE;
1075 +
1076 + } else if (strcmp(*argv, "memlimit") == 0) {
1077 + NEXT_ARG();
1078 + if(get_size(&memlimit, *argv)) {
1079 + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
1080 + return -1;
1081 + }
1082 +
1083 + } else if (strcmp(*argv, "help") == 0) {
1084 + explain();
1085 + return -1;
1086 + } else {
1087 + fprintf(stderr, "What is \"%s\"?\n", *argv);
1088 + explain();
1089 + return -1;
1090 + }
1091 + argc--; argv++;
1092 + }
1093 +
1094 + tail = NLMSG_TAIL(n);
1095 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
1096 + if (bandwidth || unlimited)
1097 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE64, &bandwidth, sizeof(bandwidth));
1098 + if (diffserv)
1099 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
1100 + if (atm != -1)
1101 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
1102 + if (flowmode != -1)
1103 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
1104 + if (overhead_set)
1105 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
1106 + if (overhead_override) {
1107 + unsigned zero = 0;
1108 + addattr_l(n, 1024, TCA_CAKE_RAW, &zero, sizeof(zero));
1109 + }
1110 + if (mpu > 0)
1111 + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
1112 + if (interval)
1113 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
1114 + if (target)
1115 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
1116 + if (autorate != -1)
1117 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
1118 + if (memlimit)
1119 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
1120 + if (nat != -1)
1121 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
1122 + if (wash != -1)
1123 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
1124 + if (ingress != -1)
1125 + addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
1126 + if (ack_filter != -1)
1127 + addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter, sizeof(ack_filter));
1128 +
1129 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1130 + return 0;
1131 +}
1132 +
1133 +
1134 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1135 +{
1136 + struct rtattr *tb[TCA_CAKE_MAX + 1];
1137 + __u64 bandwidth = 0;
1138 + unsigned diffserv = 0;
1139 + unsigned flowmode = 0;
1140 + unsigned interval = 0;
1141 + unsigned memlimit = 0;
1142 + int overhead = 0;
1143 + int raw = 0;
1144 + int mpu = 0;
1145 + int atm = 0;
1146 + int nat = 0;
1147 + int autorate = 0;
1148 + int wash = 0;
1149 + int ingress = 0;
1150 + int ack_filter = 0;
1151 + int split_gso = 0;
1152 + SPRINT_BUF(b1);
1153 + SPRINT_BUF(b2);
1154 +
1155 + if (opt == NULL)
1156 + return 0;
1157 +
1158 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
1159 +
1160 + if (tb[TCA_CAKE_BASE_RATE64] &&
1161 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE64]) >= sizeof(bandwidth)) {
1162 + bandwidth = rta_getattr_u64(tb[TCA_CAKE_BASE_RATE64]);
1163 + if(bandwidth) {
1164 + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1));
1165 + } else
1166 + fprintf(f, "unlimited ");
1167 + }
1168 + if (tb[TCA_CAKE_AUTORATE] &&
1169 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
1170 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
1171 + if(autorate == 1)
1172 + fprintf(f, "ingress");
1173 + else if(autorate)
1174 + fprintf(f, "unknown");
1175 + }
1176 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
1177 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
1178 + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
1179 + switch(diffserv) {
1180 + case CAKE_DIFFSERV_DIFFSERV3:
1181 + fprintf(f, "diffserv3 ");
1182 + break;
1183 + case CAKE_DIFFSERV_DIFFSERV4:
1184 + fprintf(f, "diffserv4 ");
1185 + break;
1186 + case CAKE_DIFFSERV_DIFFSERV8:
1187 + fprintf(f, "diffserv8 ");
1188 + break;
1189 + case CAKE_DIFFSERV_BESTEFFORT:
1190 + fprintf(f, "besteffort ");
1191 + break;
1192 + case CAKE_DIFFSERV_PRECEDENCE:
1193 + fprintf(f, "precedence ");
1194 + break;
1195 + default:
1196 + fprintf(f, "unknown ");
1197 + break;
1198 + };
1199 + }
1200 + if (tb[TCA_CAKE_FLOW_MODE] &&
1201 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
1202 + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
1203 + switch(flowmode) {
1204 + case CAKE_FLOW_NONE:
1205 + fprintf(f, "flowblind ");
1206 + break;
1207 + case CAKE_FLOW_SRC_IP:
1208 + fprintf(f, "srchost ");
1209 + break;
1210 + case CAKE_FLOW_DST_IP:
1211 + fprintf(f, "dsthost ");
1212 + break;
1213 + case CAKE_FLOW_HOSTS:
1214 + fprintf(f, "hosts ");
1215 + break;
1216 + case CAKE_FLOW_FLOWS:
1217 + fprintf(f, "flows ");
1218 + break;
1219 + case CAKE_FLOW_DUAL_SRC:
1220 + fprintf(f, "dual-srchost ");
1221 + break;
1222 + case CAKE_FLOW_DUAL_DST:
1223 + fprintf(f, "dual-dsthost ");
1224 + break;
1225 + case CAKE_FLOW_TRIPLE:
1226 + fprintf(f, "triple-isolate ");
1227 + break;
1228 + default:
1229 + fprintf(f, "unknown ");
1230 + break;
1231 + };
1232 +
1233 + }
1234 +
1235 + if (tb[TCA_CAKE_NAT] &&
1236 + RTA_PAYLOAD(tb[TCA_CAKE_NAT]) >= sizeof(__u32)) {
1237 + nat = rta_getattr_u32(tb[TCA_CAKE_NAT]);
1238 + }
1239 +
1240 + if(nat)
1241 + fprintf(f, "nat ");
1242 +
1243 + if (tb[TCA_CAKE_WASH] &&
1244 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
1245 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
1246 + }
1247 + if (tb[TCA_CAKE_ATM] &&
1248 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
1249 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
1250 + }
1251 + if (tb[TCA_CAKE_OVERHEAD] &&
1252 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__s32)) {
1253 + overhead = *(__s32 *) RTA_DATA(tb[TCA_CAKE_OVERHEAD]);
1254 + }
1255 + if (tb[TCA_CAKE_MPU] &&
1256 + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
1257 + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
1258 + }
1259 + if (tb[TCA_CAKE_INGRESS] &&
1260 + RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
1261 + ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
1262 + }
1263 + if (tb[TCA_CAKE_ACK_FILTER] &&
1264 + RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
1265 + ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
1266 + }
1267 + if (tb[TCA_CAKE_SPLIT_GSO] &&
1268 + RTA_PAYLOAD(tb[TCA_CAKE_SPLIT_GSO]) >= sizeof(__u32)) {
1269 + split_gso = rta_getattr_u32(tb[TCA_CAKE_SPLIT_GSO]);
1270 + }
1271 + if (tb[TCA_CAKE_RAW]) {
1272 + raw = 1;
1273 + }
1274 + if (tb[TCA_CAKE_RTT] &&
1275 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
1276 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
1277 + }
1278 +
1279 + if (wash)
1280 + fprintf(f, "wash ");
1281 +
1282 + if (ingress)
1283 + fprintf(f, "ingress ");
1284 +
1285 + if (ack_filter == CAKE_ACK_AGGRESSIVE)
1286 + fprintf(f, "ack-filter-aggresssive ");
1287 + else if (ack_filter == CAKE_ACK_FILTER)
1288 + fprintf(f, "ack-filter ");
1289 + else
1290 + fprintf(f, "no-ack-filter ");
1291 +
1292 + if (split_gso)
1293 + fprintf(f, "split-gso ");
1294 +
1295 + if (interval)
1296 + fprintf(f, "rtt %s ", sprint_time(interval, b2));
1297 +
1298 + if (raw)
1299 + fprintf(f, "raw ");
1300 +
1301 + if (atm == CAKE_ATM_ATM)
1302 + fprintf(f, "atm ");
1303 + else if (atm == CAKE_ATM_PTM)
1304 + fprintf(f, "ptm ");
1305 + else if (!raw)
1306 + fprintf(f, "noatm ");
1307 +
1308 + fprintf(f, "overhead %d ", overhead);
1309 +
1310 + if (mpu)
1311 + fprintf(f, "mpu %u ", mpu);
1312 +
1313 + if (memlimit) {
1314 + fprintf(f, "memlimit %s", sprint_size(memlimit, b1));
1315 + }
1316 +
1317 + return 0;
1318 +}
1319 +
1320 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
1321 + struct rtattr *xstats)
1322 +{
1323 + SPRINT_BUF(b1);
1324 + struct rtattr *st[TCA_CAKE_STATS_MAX + 1];
1325 + int i;
1326 +
1327 + if (xstats == NULL)
1328 + return 0;
1329 +
1330 +#define GET_STAT_U32(attr) rta_getattr_u32(st[TCA_CAKE_STATS_ ## attr])
1331 +#define GET_STAT_S32(attr) (*(__s32*)RTA_DATA(st[TCA_CAKE_STATS_ ## attr]))
1332 +#define GET_STAT_U64(attr) rta_getattr_u64(st[TCA_CAKE_STATS_ ## attr])
1333 +
1334 + parse_rtattr_nested(st, TCA_CAKE_STATS_MAX, xstats);
1335 +
1336 + if (st[TCA_CAKE_STATS_MEMORY_USED] &&
1337 + st[TCA_CAKE_STATS_MEMORY_LIMIT]) {
1338 + fprintf(f, " memory used: %s",
1339 + sprint_size(GET_STAT_U32(MEMORY_USED), b1));
1340 +
1341 + fprintf(f, " of %s\n",
1342 + sprint_size(GET_STAT_U32(MEMORY_LIMIT), b1));
1343 + }
1344 +
1345 + if (st[TCA_CAKE_STATS_CAPACITY_ESTIMATE64]) {
1346 + fprintf(f, " capacity estimate: %s\n",
1347 + sprint_rate(GET_STAT_U64(CAPACITY_ESTIMATE64), b1));
1348 + }
1349 +
1350 + if (st[TCA_CAKE_STATS_MIN_NETLEN] &&
1351 + st[TCA_CAKE_STATS_MAX_NETLEN]) {
1352 + fprintf(f, " min/max network layer size: %8u",
1353 + GET_STAT_U32(MIN_NETLEN));
1354 + fprintf(f, " /%8u\n", GET_STAT_U32(MAX_NETLEN));
1355 + }
1356 +
1357 + if (st[TCA_CAKE_STATS_MIN_ADJLEN] &&
1358 + st[TCA_CAKE_STATS_MAX_ADJLEN]) {
1359 + fprintf(f, " min/max overhead-adjusted size: %8u",
1360 + GET_STAT_U32(MIN_ADJLEN));
1361 + fprintf(f, " /%8u\n", GET_STAT_U32(MAX_ADJLEN));
1362 + }
1363 +
1364 + if (st[TCA_CAKE_STATS_AVG_NETOFF])
1365 + fprintf(f, " average network hdr offset: %8u\n\n",
1366 + GET_STAT_U32(AVG_NETOFF));
1367 +
1368 + /* class stats */
1369 + if (st[TCA_CAKE_STATS_DEFICIT])
1370 + fprintf(f, "deficit %u",
1371 + GET_STAT_S32(DEFICIT));
1372 + if (st[TCA_CAKE_STATS_COBALT_COUNT])
1373 + fprintf(f, "count %u",
1374 + GET_STAT_U32(COBALT_COUNT));
1375 +
1376 + if (st[TCA_CAKE_STATS_DROPPING] && GET_STAT_U32(DROPPING)) {
1377 + fprintf(f, " dropping");
1378 + if (st[TCA_CAKE_STATS_DROP_NEXT_US]) {
1379 + int drop_next = GET_STAT_S32(DROP_NEXT_US);
1380 + if (drop_next < 0) {
1381 + fprintf(f, " drop_next -%s",
1382 + sprint_time(drop_next, b1));
1383 + } else {
1384 + fprintf(f, " drop_next %s",
1385 + sprint_time(drop_next, b1));
1386 + }
1387 + }
1388 + }
1389 +
1390 + if (st[TCA_CAKE_STATS_P_DROP]) {
1391 + fprintf(f, " blue_prob %u",
1392 + GET_STAT_U32(P_DROP));
1393 + if (st[TCA_CAKE_STATS_BLUE_TIMER_US]) {
1394 + int blue_timer = GET_STAT_S32(BLUE_TIMER_US);
1395 + if (blue_timer < 0) {
1396 + fprintf(f, " blue_timer -%s",
1397 + sprint_time(blue_timer, b1));
1398 + } else {
1399 + fprintf(f, " blue_timer %s",
1400 + sprint_time(blue_timer, b1));
1401 + }
1402 + }
1403 + }
1404 +
1405 +#undef GET_STAT_U32
1406 +#undef GET_STAT_S32
1407 +#undef GET_STAT_U64
1408 +
1409 + if (st[TCA_CAKE_STATS_TIN_STATS]) {
1410 + struct rtattr *tins[TC_CAKE_MAX_TINS + 1];
1411 + struct rtattr *tstat[TC_CAKE_MAX_TINS][TCA_CAKE_TIN_STATS_MAX + 1];
1412 + int num_tins = 0;
1413 +
1414 + parse_rtattr_nested(tins, TC_CAKE_MAX_TINS, st[TCA_CAKE_STATS_TIN_STATS]);
1415 +
1416 + for (i = 1; i <= TC_CAKE_MAX_TINS && tins[i]; i++) {
1417 + parse_rtattr_nested(tstat[i-1], TCA_CAKE_TIN_STATS_MAX, tins[i]);
1418 + num_tins++;
1419 + }
1420 +
1421 + if (!num_tins)
1422 + return 0;
1423 +
1424 + switch(num_tins) {
1425 + case 3:
1426 + fprintf(f, " Bulk Best Effort Voice\n");
1427 + break;
1428 +
1429 + case 4:
1430 + fprintf(f, " Bulk Best Effort Video Voice\n");
1431 + break;
1432 +
1433 + default:
1434 + fprintf(f, " ");
1435 + for(i=0; i < num_tins; i++)
1436 + fprintf(f, " Tin %u", i);
1437 + fprintf(f, "\n");
1438 + };
1439 +
1440 +#define GET_TSTAT(i, attr) (tstat[i][TCA_CAKE_TIN_STATS_ ## attr])
1441 +#define PRINT_TSTAT(name, attr, fmts, val) do { \
1442 + if (GET_TSTAT(0, attr)) { \
1443 + fprintf(f, name); \
1444 + for (i = 0; i < num_tins; i++) \
1445 + fprintf(f, " %12" fmts, val); \
1446 + fprintf(f, "\n"); \
1447 + } \
1448 + } while (0)
1449 +
1450 +#define SPRINT_TSTAT(pfunc, type, name, attr) PRINT_TSTAT( \
1451 + name, attr, "s", sprint_ ## pfunc( \
1452 + rta_getattr_ ## type(GET_TSTAT(i, attr)), b1))
1453 +
1454 +#define PRINT_TSTAT_U32(name, attr) PRINT_TSTAT( \
1455 + name, attr, "u", rta_getattr_u32(GET_TSTAT(i, attr)))
1456 +
1457 +#define PRINT_TSTAT_U64(name, attr) PRINT_TSTAT( \
1458 + name, attr, "llu", rta_getattr_u64(GET_TSTAT(i, attr)))
1459 +
1460 + SPRINT_TSTAT(rate, u64, " thresh ", THRESHOLD_RATE64);
1461 + SPRINT_TSTAT(time, u32, " target ", TARGET_US);
1462 + SPRINT_TSTAT(time, u32, " interval", INTERVAL_US);
1463 + SPRINT_TSTAT(time, u32, " pk_delay", PEAK_DELAY_US);
1464 + SPRINT_TSTAT(time, u32, " av_delay", AVG_DELAY_US);
1465 + SPRINT_TSTAT(time, u32, " sp_delay", BASE_DELAY_US);
1466 + SPRINT_TSTAT(size, u32, " backlog ", BACKLOG_BYTES);
1467 +
1468 + PRINT_TSTAT_U32(" pkts ", SENT_PACKETS);
1469 + PRINT_TSTAT_U64(" bytes ", SENT_BYTES64);
1470 +
1471 + PRINT_TSTAT_U32(" way_inds", WAY_INDIRECT_HITS);
1472 + PRINT_TSTAT_U32(" way_miss", WAY_MISSES);
1473 + PRINT_TSTAT_U32(" way_cols", WAY_COLLISIONS);
1474 + PRINT_TSTAT_U32(" drops ", DROPPED_PACKETS);
1475 + PRINT_TSTAT_U32(" marks ", ECN_MARKED_PACKETS);
1476 + PRINT_TSTAT_U32(" ack_drop", ACKS_DROPPED_PACKETS);
1477 + PRINT_TSTAT_U32(" sp_flows", SPARSE_FLOWS);
1478 + PRINT_TSTAT_U32(" bk_flows", BULK_FLOWS);
1479 + PRINT_TSTAT_U32(" un_flows", UNRESPONSIVE_FLOWS);
1480 + PRINT_TSTAT_U32(" max_len ", MAX_SKBLEN);
1481 + PRINT_TSTAT_U32(" quantum ", FLOW_QUANTUM);
1482 +
1483 +#undef GET_STAT
1484 +#undef PRINT_TSTAT
1485 +#undef SPRINT_TSTAT
1486 +#undef PRINT_TSTAT_U32
1487 +#undef PRINT_TSTAT_U64
1488 + }
1489 + return 0;
1490 +}
1491 +
1492 +struct qdisc_util cake_qdisc_util = {
1493 + .id = "cake",
1494 + .parse_qopt = cake_parse_opt,
1495 + .print_qopt = cake_print_opt,
1496 + .print_xstats = cake_print_xstats,
1497 +};