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