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