1 --- a/include/uapi/linux/pkt_sched.h
2 +++ b/include/uapi/linux/pkt_sched.h
3 @@ -934,4 +934,118 @@ enum {
5 #define TCA_CBS_MAX (__TCA_CBS_MAX - 1)
11 + TCA_CAKE_BASE_RATE64,
12 + TCA_CAKE_DIFFSERV_MODE,
21 + TCA_CAKE_RAW, // was _ETHERNET
25 + TCA_CAKE_ACK_FILTER,
29 +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
32 + __TCA_CAKE_STATS_INVALID,
34 + TCA_CAKE_STATS_CAPACITY_ESTIMATE64,
35 + TCA_CAKE_STATS_MEMORY_LIMIT,
36 + TCA_CAKE_STATS_MEMORY_USED,
37 + TCA_CAKE_STATS_AVG_NETOFF,
38 + TCA_CAKE_STATS_MIN_NETLEN,
39 + TCA_CAKE_STATS_MAX_NETLEN,
40 + TCA_CAKE_STATS_MIN_ADJLEN,
41 + TCA_CAKE_STATS_MAX_ADJLEN,
42 + TCA_CAKE_STATS_TIN_STATS,
43 + TCA_CAKE_STATS_DEFICIT,
44 + TCA_CAKE_STATS_COBALT_COUNT,
45 + TCA_CAKE_STATS_DROPPING,
46 + TCA_CAKE_STATS_DROP_NEXT_US,
47 + TCA_CAKE_STATS_P_DROP,
48 + TCA_CAKE_STATS_BLUE_TIMER_US,
49 + __TCA_CAKE_STATS_MAX
51 +#define TCA_CAKE_STATS_MAX (__TCA_CAKE_STATS_MAX - 1)
54 + __TCA_CAKE_TIN_STATS_INVALID,
55 + TCA_CAKE_TIN_STATS_PAD,
56 + TCA_CAKE_TIN_STATS_SENT_PACKETS,
57 + TCA_CAKE_TIN_STATS_SENT_BYTES64,
58 + TCA_CAKE_TIN_STATS_DROPPED_PACKETS,
59 + TCA_CAKE_TIN_STATS_DROPPED_BYTES64,
60 + TCA_CAKE_TIN_STATS_ACKS_DROPPED_PACKETS,
61 + TCA_CAKE_TIN_STATS_ACKS_DROPPED_BYTES64,
62 + TCA_CAKE_TIN_STATS_ECN_MARKED_PACKETS,
63 + TCA_CAKE_TIN_STATS_ECN_MARKED_BYTES64,
64 + TCA_CAKE_TIN_STATS_BACKLOG_PACKETS,
65 + TCA_CAKE_TIN_STATS_BACKLOG_BYTES,
66 + TCA_CAKE_TIN_STATS_THRESHOLD_RATE64,
67 + TCA_CAKE_TIN_STATS_TARGET_US,
68 + TCA_CAKE_TIN_STATS_INTERVAL_US,
69 + TCA_CAKE_TIN_STATS_WAY_INDIRECT_HITS,
70 + TCA_CAKE_TIN_STATS_WAY_MISSES,
71 + TCA_CAKE_TIN_STATS_WAY_COLLISIONS,
72 + TCA_CAKE_TIN_STATS_PEAK_DELAY_US,
73 + TCA_CAKE_TIN_STATS_AVG_DELAY_US,
74 + TCA_CAKE_TIN_STATS_BASE_DELAY_US,
75 + TCA_CAKE_TIN_STATS_SPARSE_FLOWS,
76 + TCA_CAKE_TIN_STATS_BULK_FLOWS,
77 + TCA_CAKE_TIN_STATS_UNRESPONSIVE_FLOWS,
78 + TCA_CAKE_TIN_STATS_MAX_SKBLEN,
79 + TCA_CAKE_TIN_STATS_FLOW_QUANTUM,
80 + __TCA_CAKE_TIN_STATS_MAX
82 +#define TCA_CAKE_TIN_STATS_MAX (__TCA_CAKE_TIN_STATS_MAX - 1)
83 +#define TC_CAKE_MAX_TINS (8)
89 + CAKE_FLOW_HOSTS, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_DST_IP */
91 + CAKE_FLOW_DUAL_SRC, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_FLOWS */
92 + CAKE_FLOW_DUAL_DST, /* = CAKE_FLOW_DST_IP | CAKE_FLOW_FLOWS */
93 + CAKE_FLOW_TRIPLE, /* = CAKE_FLOW_HOSTS | CAKE_FLOW_FLOWS */
98 + CAKE_DIFFSERV_DIFFSERV3 = 0,
99 + CAKE_DIFFSERV_DIFFSERV4,
100 + CAKE_DIFFSERV_DIFFSERV8,
101 + CAKE_DIFFSERV_BESTEFFORT,
102 + CAKE_DIFFSERV_PRECEDENCE,
109 + CAKE_ACK_AGGRESSIVE,
123 +++ b/man/man8/tc-cake.8
125 +.TH CAKE 8 "19 July 2018" "iproute2" "Linux"
127 +CAKE \- Common Applications Kept Enhanced (CAKE)
129 +.B tc qdisc ... cake
136 +.BR autorate-ingress
202 +.BR ack-filter-aggressive
241 +CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline
242 +which uses both AQM and FQ. It combines COBALT, which is an AQM algorithm
243 +combining Codel and BLUE, a shaper which operates in deficit mode, and a variant
244 +of DRR++ for flow isolation. 8-way set-associative hashing is used to virtually
245 +eliminate hash collisions. Priority queuing is available through a simplified
246 +diffserv implementation. Overhead compensation for various encapsulation
247 +schemes is tightly integrated.
249 +All settings are optional; the default settings are chosen to be sensible in
250 +most common deployments. Most people will only need to set the
252 +parameter to get useful results, but reading the
253 +.B Overhead Compensation
256 +sections is strongly encouraged.
258 +.SH SHAPER PARAMETERS
259 +CAKE uses a deficit-mode shaper, which does not exhibit the initial burst
260 +typical of token-bucket shapers. It will automatically burst precisely as much
261 +as required to maintain the configured throughput. As such, it is very
262 +straightforward to configure.
267 + No limit on the bandwidth.
272 + Set the shaper bandwidth. See
274 +or examples below for details of the RATE value.
278 + Automatic capacity estimation based on traffic arriving at this qdisc.
279 +This is most likely to be useful with cellular links, which tend to change
282 +parameter can be used in conjunction to specify an initial estimate. The shaper
283 +will periodically be set to a bandwidth slightly below the estimated rate. This
284 +estimator cannot estimate the bandwidth of links downstream of itself.
286 +.SH OVERHEAD COMPENSATION PARAMETERS
287 +The size of each packet on the wire may differ from that seen by Linux. The
288 +following parameters allow CAKE to compensate for this difference by internally
289 +considering each packet to be bigger than Linux informs it. To assist users who
290 +are not expert network engineers, keywords have been provided to represent a
291 +number of common link technologies.
293 +.SS Manual Overhead Specification
297 + Adds BYTES to the size of each packet. BYTES may be negative; values
298 +between -64 and 256 (inclusive) are accepted.
303 + Rounds each packet (including overhead) up to a minimum length
304 +BYTES. BYTES may not be negative; values between 0 and 256 (inclusive)
309 + Compensates for ATM cell framing, which is normally found on ADSL links.
310 +This is performed after the
312 +parameter above. ATM uses fixed 53-byte cells, each of which can carry 48 bytes
317 + Compensates for PTM encoding, which is normally found on VDSL2 links and
318 +uses a 64b/65b encoding scheme. It is even more efficient to simply
319 +derate the specified shaper bandwidth by a factor of 64/65 or 0.984. See
320 +ITU G.992.3 Annex N and IEEE 802.3 Section 61.3 for details.
324 + Disables ATM and PTM compensation.
326 +.SS Failsafe Overhead Keywords
327 +These two keywords are provided for quick-and-dirty setup. Use them if you
328 +can't be bothered to read the rest of this section.
333 + Turns off all overhead compensation in CAKE. The packet size reported
334 +by Linux will be used directly.
336 + Other overhead keywords may be added after "raw". The effect of this is
337 +to make the overhead compensation operate relative to the reported packet size,
338 +not the underlying IP packet size.
342 + Compensates for more overhead than is likely to occur on any
343 +widely-deployed link technology.
348 +.SS ADSL Overhead Keywords
349 +Most ADSL modems have a way to check which framing scheme is in use. Often this
350 +is also specified in the settings document provided by the ISP. The keywords in
351 +this section are intended to correspond with these sources of information. All
352 +of them implicitly set the
396 +See also the Ethernet Correction Factors section below.
398 +.SS VDSL2 Overhead Keywords
399 +ATM was dropped from VDSL2 in favour of PTM, which is a much more
400 +straightforward framing scheme. Some ISPs retained PPPoE for compatibility with
401 +their existing back-end systems.
409 + PPPoE: 2B PPP + 6B PPPoE +
411 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
413 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
421 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
423 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
426 +See also the Ethernet Correction Factors section below.
428 +.SS DOCSIS Cable Overhead Keyword
429 +DOCSIS is the universal standard for providing Internet service over cable-TV
432 +In this case, the actual on-wire overhead is less important than the packet size
433 +the head-end equipment uses for shaping and metering. This is specified to be
434 +an Ethernet frame including the CRC (aka FCS).
439 +.B overhead 18 mpu 64 noatm
441 +.SS Ethernet Overhead Keywords
445 + Accounts for Ethernet's preamble, inter-frame gap, and Frame Check
446 +Sequence. Use this keyword when the bottleneck being shaped for is an
447 +actual Ethernet cable.
450 +.B overhead 38 mpu 84 noatm
454 + Adds 4 bytes to the overhead compensation, accounting for an IEEE 802.1Q
455 +VLAN header appended to the Ethernet frame header. NB: Some ISPs use one or
456 +even two of these within PPPoE; this keyword may be repeated as necessary to
459 +.SH ROUND TRIP TIME PARAMETERS
460 +Active Queue Management (AQM) consists of embedding congestion signals in the
461 +packet flow, which receivers use to instruct senders to slow down when the queue
462 +is persistently occupied. CAKE uses ECN signalling when available, and packet
463 +drops otherwise, according to a combination of the Codel and BLUE AQM algorithms
466 +Very short latencies require a very rapid AQM response to adequately control
467 +latency. However, such a rapid response tends to impair throughput when the
468 +actual RTT is relatively long. CAKE allows specifying the RTT it assumes for
469 +tuning various parameters. Actual RTTs within an order of magnitude of this
470 +will generally work well for both throughput and latency management.
472 +At the 'lan' setting and below, the time constants are similar in magnitude to
473 +the jitter in the Linux kernel itself, so congestion might be signalled
474 +prematurely. The flows will then become sparse and total throughput reduced,
475 +leaving little or no back-pressure for the fairness logic to work against. Use
476 +the "metro" setting for local lans unless you have a custom kernel.
481 + Manually specify an RTT.
485 + For extremely high-performance 10GigE+ networks only. Equivalent to
490 + For pure Ethernet (not Wi-Fi) networks, at home or in the office. Don't
491 +use this when shaping for an Internet access link. Equivalent to
496 + For traffic mostly within a single city. Equivalent to
501 + For traffic mostly within a European-sized country. Equivalent to
507 + This is suitable for most Internet traffic. Equivalent to
512 + For Internet traffic with generally above-average latency, such as that
513 +suffered by Australasian residents. Equivalent to
518 + For traffic via geostationary satellites. Equivalent to
523 + So named because Jupiter is about 1 light-hour from Earth. Use this to
524 +(almost) completely disable AQM actions. Equivalent to
527 +.SH FLOW ISOLATION PARAMETERS
528 +With flow isolation enabled, CAKE places packets from different flows into
529 +different queues, each of which carries its own AQM state. Packets from each
530 +queue are then delivered fairly, according to a DRR++ algorithm which minimises
531 +latency for "sparse" flows. CAKE uses a set-associative hashing algorithm to
532 +minimise flow collisions.
534 +These keywords specify whether fairness based on source address, destination
535 +address, individual flows, or any combination of those is desired.
539 + Disables flow isolation; all traffic passes through a single queue for
544 + Flows are defined only by source address. Could be useful on the egress
545 +path of an ISP backhaul.
549 + Flows are defined only by destination address. Could be useful on the
550 +ingress path of an ISP backhaul.
554 + Flows are defined by source-destination host pairs. This is host
555 +isolation, rather than flow isolation.
559 + Flows are defined by the entire 5-tuple of source address, destination
560 +address, transport protocol, source port and destination port. This is the type
561 +of flow isolation performed by SFQ and fq_codel.
565 + Flows are defined by the 5-tuple, and fairness is applied first over
566 +source addresses, then over individual flows. Good for use on egress traffic
567 +from a LAN to the internet, where it'll prevent any one LAN host from
568 +monopolising the uplink, regardless of the number of flows they use.
572 + Flows are defined by the 5-tuple, and fairness is applied first over
573 +destination addresses, then over individual flows. Good for use on ingress
574 +traffic to a LAN from the internet, where it'll prevent any one LAN host from
575 +monopolising the downlink, regardless of the number of flows they use.
580 + Flows are defined by the 5-tuple, and fairness is applied over source
581 +*and* destination addresses intelligently (ie. not merely by host-pairs), and
582 +also over individual flows. Use this if you're not certain whether to use
583 +dual-srchost or dual-dsthost; it'll do both jobs at once, preventing any one
584 +host on *either* side of the link from monopolising it with a large number of
589 + Instructs Cake to perform a NAT lookup before applying flow-isolation
590 +rules, to determine the true addresses and port numbers of the packet, to
591 +improve fairness between hosts "inside" the NAT. This has no practical effect
592 +in "flowblind" or "flows" modes, or if NAT is performed on a different host.
597 + Cake will not perform a NAT lookup. Flow isolation will be performed
598 +using the addresses and port numbers directly visible to the interface Cake is
601 +.SH PRIORITY QUEUE PARAMETERS
602 +CAKE can divide traffic into "tins" based on the Diffserv field. Each tin has
603 +its own independent set of flow-isolation queues, and is serviced based on a WRR
604 +algorithm. To avoid perverse Diffserv marking incentives, tin weights have a
605 +"priority sharing" value when bandwidth used by that tin is below a threshold,
606 +and a lower "bandwidth sharing" value when above. Bandwidth is compared against
607 +the threshold using the same algorithm as the deficit-mode shaper.
609 +Detailed customisation of tin parameters is not provided. The following presets
610 +perform all necessary tuning, relative to the current shaper bandwidth and RTT
615 + Disables priority queuing by placing all traffic in one tin.
619 + Enables legacy interpretation of TOS "Precedence" field. Use of this
620 +preset on the modern Internet is firmly discouraged.
624 + Provides a general-purpose Diffserv implementation with four tins:
626 + Bulk (CS1), 6.25% threshold, generally low priority.
628 + Best Effort (general), 100% threshold.
630 + Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, TOS1), 50% threshold.
632 + Voice (CS7, CS6, EF, VA, CS5, CS4), 25% threshold.
637 + Provides a simple, general-purpose Diffserv implementation with three tins:
639 + Bulk (CS1), 6.25% threshold, generally low priority.
641 + Best Effort (general), 100% threshold.
643 + Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
645 +.SH OTHER PARAMETERS
649 + Limit the memory consumed by Cake to LIMIT bytes. Note that this does
650 +not translate directly to queue size (so do not size this based on bandwidth
651 +delay product considerations, but rather on worst case acceptable memory
652 +consumption), as there is some overhead in the data structures containing the
653 +packets, especially for small packets.
655 + By default, the limit is calculated based on the bandwidth and RTT
662 + Traffic entering your diffserv domain is frequently mis-marked in
663 +transit from the perspective of your network, and traffic exiting yours may be
664 +mis-marked from the perspective of the transiting provider.
666 +Apply the wash option to clear all extra diffserv (but not ECN bits), after
667 +priority queuing has taken place.
669 +If you are shaping inbound, and cannot trust the diffserv markings (as is the
670 +case for Comcast Cable, among others), it is best to use a single queue
671 +"besteffort" mode with wash.
674 +# tc qdisc delete root dev eth0
676 +# tc qdisc add root dev eth0 cake bandwidth 100Mbit ethernet
678 +# tc -s qdisc show dev eth0
680 +qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
681 + Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
682 + backlog 0b 0p requeues 0
683 + memory used: 0b of 5000000b
684 + capacity estimate: 100Mbit
685 + min/max network layer size: 65535 / 0
686 + min/max overhead-adjusted size: 65535 / 0
687 + average network hdr offset: 0
689 + Bulk Best Effort Voice
690 + thresh 6250Kbit 100Mbit 25Mbit
691 + target 5.0ms 5.0ms 5.0ms
692 + interval 100.0ms 100.0ms 100.0ms
693 + pk_delay 0us 0us 0us
694 + av_delay 0us 0us 0us
695 + sp_delay 0us 0us 0us
708 + quantum 300 1514 762
712 +# tc -s qdisc show dev eth0
714 +qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
715 + Sent 44709231 bytes 31931 pkt (dropped 45, overlimits 93782 requeues 0)
716 + backlog 33308b 22p requeues 0
717 + memory used: 292352b of 5000000b
718 + capacity estimate: 100Mbit
719 + min/max network layer size: 28 / 1500
720 + min/max overhead-adjusted size: 84 / 1538
721 + average network hdr offset: 14
723 + Bulk Best Effort Voice
724 + thresh 6250Kbit 100Mbit 25Mbit
725 + target 5.0ms 5.0ms 5.0ms
726 + interval 100.0ms 100.0ms 100.0ms
727 + pk_delay 8.7ms 6.9ms 5.0ms
728 + av_delay 4.9ms 5.3ms 3.8ms
729 + sp_delay 727us 1.4ms 511us
730 + pkts 2590 21271 8137
731 + bytes 3081804 30302659 11426206
741 + max_len 1514 1514 1514
742 + quantum 300 1514 762
747 +.BR tc-fq_codel (8),
751 +Cake's principal author is Jonathan Morton, with contributions from
752 +Tony Ambardar, Kevin Darbyshire-Bryant, Toke Høiland-Jørgensen,
753 +Sebastian Moeller, Ryan Mounce, Dean Scarff, Nils Andreas Svee, and Dave Täht.
755 +This manual page was written by Loganaden Velvindron. Please report corrections
756 +to the Linux Networking mailing list <netdev@vger.kernel.org>.
759 @@ -795,6 +795,7 @@ was written by Alexey N. Kuznetsov and a
769 @@ -66,6 +66,7 @@ TCMODULES += q_codel.o
770 TCMODULES += q_fq_codel.o
773 +TCMODULES += q_cake.o
775 TCMODULES += q_clsact.o
780 +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
783 + * Common Applications Kept Enhanced -- CAKE
785 + * Copyright (C) 2014-2018 Jonathan Morton <chromatix99@gmail.com>
786 + * Copyright (C) 2017-2018 Toke Høiland-Jørgensen <toke@toke.dk>
795 +#include <sys/socket.h>
796 +#include <netinet/in.h>
797 +#include <arpa/inet.h>
799 +#include <inttypes.h>
802 +#include "tc_util.h"
804 +struct cake_preset {
806 + unsigned int target;
807 + unsigned int interval;
810 +static struct cake_preset presets[] = {
811 + {"datacentre", 5, 100},
813 + {"metro", 500, 10000},
814 + {"regional", 1500, 30000},
815 + {"internet", 5000, 100000},
816 + {"oceanic", 15000, 300000},
817 + {"satellite", 50000, 1000000},
818 + {"interplanetary", 50000000, 1000000000},
821 +static const char * diffserv_names[CAKE_DIFFSERV_MAX] = {
822 + [CAKE_DIFFSERV_DIFFSERV3] = "diffserv3",
823 + [CAKE_DIFFSERV_DIFFSERV4] = "diffserv4",
824 + [CAKE_DIFFSERV_DIFFSERV8] = "diffserv8",
825 + [CAKE_DIFFSERV_BESTEFFORT] = "besteffort",
826 + [CAKE_DIFFSERV_PRECEDENCE] = "precedence",
829 +static const char * flowmode_names[CAKE_FLOW_MAX] = {
830 + [CAKE_FLOW_NONE] = "flowblind",
831 + [CAKE_FLOW_SRC_IP] = "srchost",
832 + [CAKE_FLOW_DST_IP] = "dsthost",
833 + [CAKE_FLOW_HOSTS] = "hosts",
834 + [CAKE_FLOW_FLOWS] = "flows",
835 + [CAKE_FLOW_DUAL_SRC] = "dual-srchost",
836 + [CAKE_FLOW_DUAL_DST] = "dual-dsthost",
837 + [CAKE_FLOW_TRIPLE] = "triple-isolate",
840 +static struct cake_preset *find_preset(char *argv)
844 + for (i = 0; i < ARRAY_SIZE(presets); i++)
845 + if (!strcmp(argv, presets[i].name))
846 + return &presets[i];
850 +static void explain(void)
853 +"Usage: ... cake [ bandwidth RATE | unlimited* | autorate-ingress ]\n"
854 +" [ rtt TIME | datacentre | lan | metro | regional |\n"
855 +" internet* | oceanic | satellite | interplanetary ]\n"
856 +" [ besteffort | diffserv8 | diffserv4 | diffserv3* ]\n"
857 +" [ flowblind | srchost | dsthost | hosts | flows |\n"
858 +" dual-srchost | dual-dsthost | triple-isolate* ]\n"
859 +" [ nat | nonat* ]\n"
860 +" [ wash | nowash* ]\n"
861 +" [ split-gso* | no-split-gso ]\n"
862 +" [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
863 +" [ memlimit LIMIT ]\n"
864 +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
865 +" [ mpu N ] [ ingress | egress* ]\n"
866 +" (* marks defaults)\n");
869 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
870 + struct nlmsghdr *n, const char *dev)
872 + struct cake_preset *preset, *preset_set = NULL;
873 + bool overhead_override = false;
874 + bool overhead_set = false;
875 + unsigned int interval = 0;
876 + unsigned int diffserv = 0;
877 + unsigned int memlimit = 0;
878 + unsigned int target = 0;
879 + __u64 bandwidth = 0;
880 + int ack_filter = -1;
881 + struct rtattr *tail;
891 + int split_gso = -1;
894 + if (strcmp(*argv, "bandwidth") == 0) {
896 + if (get_rate64(&bandwidth, *argv)) {
897 + fprintf(stderr, "Illegal \"bandwidth\"\n");
902 + } else if (strcmp(*argv, "unlimited") == 0) {
906 + } else if (strcmp(*argv, "autorate-ingress") == 0) {
908 + } else if (strcmp(*argv, "rtt") == 0) {
910 + if (get_time(&interval, *argv)) {
911 + fprintf(stderr, "Illegal \"rtt\"\n");
914 + target = interval / 20;
917 + } else if ((preset = find_preset(*argv))) {
919 + duparg(*argv, preset_set->name);
920 + preset_set = preset;
921 + target = preset->target;
922 + interval = preset->interval;
923 + } else if (strcmp(*argv, "besteffort") == 0) {
924 + diffserv = CAKE_DIFFSERV_BESTEFFORT;
925 + } else if (strcmp(*argv, "precedence") == 0) {
926 + diffserv = CAKE_DIFFSERV_PRECEDENCE;
927 + } else if (strcmp(*argv, "diffserv8") == 0) {
928 + diffserv = CAKE_DIFFSERV_DIFFSERV8;
929 + } else if (strcmp(*argv, "diffserv4") == 0) {
930 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
931 + } else if (strcmp(*argv, "diffserv") == 0) {
932 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
933 + } else if (strcmp(*argv, "diffserv3") == 0) {
934 + diffserv = CAKE_DIFFSERV_DIFFSERV3;
935 + } else if (strcmp(*argv, "nowash") == 0) {
937 + } else if (strcmp(*argv, "wash") == 0) {
939 + } else if (strcmp(*argv, "split-gso") == 0) {
941 + } else if (strcmp(*argv, "no-split-gso") == 0) {
943 + } else if (strcmp(*argv, "flowblind") == 0) {
944 + flowmode = CAKE_FLOW_NONE;
945 + } else if (strcmp(*argv, "srchost") == 0) {
946 + flowmode = CAKE_FLOW_SRC_IP;
947 + } else if (strcmp(*argv, "dsthost") == 0) {
948 + flowmode = CAKE_FLOW_DST_IP;
949 + } else if (strcmp(*argv, "hosts") == 0) {
950 + flowmode = CAKE_FLOW_HOSTS;
951 + } else if (strcmp(*argv, "flows") == 0) {
952 + flowmode = CAKE_FLOW_FLOWS;
953 + } else if (strcmp(*argv, "dual-srchost") == 0) {
954 + flowmode = CAKE_FLOW_DUAL_SRC;
955 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
956 + flowmode = CAKE_FLOW_DUAL_DST;
957 + } else if (strcmp(*argv, "triple-isolate") == 0) {
958 + flowmode = CAKE_FLOW_TRIPLE;
959 + } else if (strcmp(*argv, "nat") == 0) {
961 + } else if (strcmp(*argv, "nonat") == 0) {
963 + } else if (strcmp(*argv, "ptm") == 0) {
964 + atm = CAKE_ATM_PTM;
965 + } else if (strcmp(*argv, "atm") == 0) {
966 + atm = CAKE_ATM_ATM;
967 + } else if (strcmp(*argv, "noatm") == 0) {
968 + atm = CAKE_ATM_NONE;
969 + } else if (strcmp(*argv, "raw") == 0) {
970 + atm = CAKE_ATM_NONE;
972 + overhead_set = true;
973 + overhead_override = true;
974 + } else if (strcmp(*argv, "conservative") == 0) {
976 + * Deliberately over-estimate overhead:
977 + * one whole ATM cell plus ATM framing.
978 + * A safe choice if the actual overhead is unknown.
980 + atm = CAKE_ATM_ATM;
982 + overhead_set = true;
984 + /* Various ADSL framing schemes, all over ATM cells */
985 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
986 + atm = CAKE_ATM_ATM;
988 + overhead_set = true;
989 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
990 + atm = CAKE_ATM_ATM;
992 + overhead_set = true;
993 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
994 + atm = CAKE_ATM_ATM;
996 + overhead_set = true;
997 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
998 + atm = CAKE_ATM_ATM;
1000 + overhead_set = true;
1001 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
1002 + atm = CAKE_ATM_ATM;
1004 + overhead_set = true;
1005 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
1006 + atm = CAKE_ATM_ATM;
1008 + overhead_set = true;
1009 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
1010 + atm = CAKE_ATM_ATM;
1012 + overhead_set = true;
1013 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
1014 + atm = CAKE_ATM_ATM;
1016 + overhead_set = true;
1018 + /* Typical VDSL2 framing schemes, both over PTM */
1019 + /* PTM has 64b/65b coding which absorbs some bandwidth */
1020 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
1021 + /* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
1022 + * + 2B ethertype + 4B Frame Check Sequence
1023 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1024 + * + 2B TC-CRC (PTM-FCS) = 30B
1026 + atm = CAKE_ATM_PTM;
1028 + overhead_set = true;
1029 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
1030 + /* 6B dest MAC + 6B src MAC + 2B ethertype
1031 + * + 4B Frame Check Sequence
1032 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1033 + * + 2B TC-CRC (PTM-FCS) = 22B
1035 + atm = CAKE_ATM_PTM;
1037 + overhead_set = true;
1038 + } else if (strcmp(*argv, "via-ethernet") == 0) {
1040 + * We used to use this flag to manually compensate for
1041 + * Linux including the Ethernet header on Ethernet-type
1042 + * interfaces, but not on IP-type interfaces.
1044 + * It is no longer needed, because Cake now adjusts for
1045 + * that automatically, and is thus ignored.
1047 + * It would be deleted entirely, but it appears in the
1048 + * stats output when the automatic compensation is
1051 + } else if (strcmp(*argv, "ethernet") == 0) {
1052 + /* ethernet pre-amble & interframe gap & FCS
1053 + * you may need to add vlan tag
1056 + overhead_set = true;
1059 + /* Additional Ethernet-related overhead used by some ISPs */
1060 + } else if (strcmp(*argv, "ether-vlan") == 0) {
1061 + /* 802.1q VLAN tag - may be repeated */
1063 + overhead_set = true;
1066 + * DOCSIS cable shapers account for Ethernet frame with FCS,
1067 + * but not interframe gap or preamble.
1069 + } else if (strcmp(*argv, "docsis") == 0) {
1070 + atm = CAKE_ATM_NONE;
1072 + overhead_set = true;
1074 + } else if (strcmp(*argv, "overhead") == 0) {
1078 + overhead = strtol(*argv, &p, 10);
1079 + if (!p || *p || !*argv ||
1080 + overhead < -64 || overhead > 256) {
1082 + "Illegal \"overhead\", valid range is -64 to 256\\n");
1085 + overhead_set = true;
1087 + } else if (strcmp(*argv, "mpu") == 0) {
1091 + mpu = strtol(*argv, &p, 10);
1092 + if (!p || *p || !*argv || mpu < 0 || mpu > 256) {
1094 + "Illegal \"mpu\", valid range is 0 to 256\\n");
1097 + } else if (strcmp(*argv, "ingress") == 0) {
1099 + } else if (strcmp(*argv, "egress") == 0) {
1101 + } else if (strcmp(*argv, "no-ack-filter") == 0) {
1102 + ack_filter = CAKE_ACK_NONE;
1103 + } else if (strcmp(*argv, "ack-filter") == 0) {
1104 + ack_filter = CAKE_ACK_FILTER;
1105 + } else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
1106 + ack_filter = CAKE_ACK_AGGRESSIVE;
1107 + } else if (strcmp(*argv, "memlimit") == 0) {
1109 + if (get_size(&memlimit, *argv)) {
1111 + "Illegal value for \"memlimit\": \"%s\"\n", *argv);
1114 + } else if (strcmp(*argv, "help") == 0) {
1118 + fprintf(stderr, "What is \"%s\"?\n", *argv);
1125 + tail = NLMSG_TAIL(n);
1126 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
1127 + if (bandwidth || unlimited)
1128 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE64, &bandwidth,
1129 + sizeof(bandwidth));
1131 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv,
1132 + sizeof(diffserv));
1134 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
1135 + if (flowmode != -1)
1136 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode,
1137 + sizeof(flowmode));
1139 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead,
1140 + sizeof(overhead));
1141 + if (overhead_override) {
1142 + unsigned int zero = 0;
1144 + addattr_l(n, 1024, TCA_CAKE_RAW, &zero, sizeof(zero));
1147 + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
1149 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
1151 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
1152 + if (autorate != -1)
1153 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate,
1154 + sizeof(autorate));
1156 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit,
1157 + sizeof(memlimit));
1159 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
1161 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
1162 + if (split_gso != -1)
1163 + addattr_l(n, 1024, TCA_CAKE_SPLIT_GSO, &split_gso,
1164 + sizeof(split_gso));
1165 + if (ingress != -1)
1166 + addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
1167 + if (ack_filter != -1)
1168 + addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter,
1169 + sizeof(ack_filter));
1171 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1175 +static void cake_print_mode(unsigned int value, unsigned int max,
1176 + const char *key, const char **table)
1178 + if (value < max && table[value]) {
1179 + print_string(PRINT_ANY, key, "%s ", table[value]);
1181 + print_string(PRINT_JSON, key, NULL, "unknown");
1182 + print_string(PRINT_FP, NULL, "(?%s?)", key);
1186 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1188 + struct rtattr *tb[TCA_CAKE_MAX + 1];
1189 + unsigned int interval = 0;
1190 + unsigned int memlimit = 0;
1191 + __u64 bandwidth = 0;
1192 + int ack_filter = 0;
1193 + int split_gso = 0;
1209 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
1211 + if (tb[TCA_CAKE_BASE_RATE64] &&
1212 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE64]) >= sizeof(bandwidth)) {
1213 + bandwidth = rta_getattr_u64(tb[TCA_CAKE_BASE_RATE64]);
1215 + print_uint(PRINT_JSON, "bandwidth", NULL, bandwidth);
1216 + print_string(PRINT_FP, NULL, "bandwidth %s ",
1217 + sprint_rate(bandwidth, b1));
1219 + print_string(PRINT_ANY, "bandwidth", "bandwidth %s ",
1222 + if (tb[TCA_CAKE_AUTORATE] &&
1223 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
1224 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
1225 + if (autorate == 1)
1226 + print_string(PRINT_ANY, "autorate", "%s ",
1227 + "autorate-ingress");
1228 + else if (autorate)
1229 + print_string(PRINT_ANY, "autorate", "(?autorate?) ",
1232 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
1233 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
1234 + cake_print_mode(rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]),
1235 + CAKE_DIFFSERV_MAX, "diffserv", diffserv_names);
1237 + if (tb[TCA_CAKE_FLOW_MODE] &&
1238 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
1239 + cake_print_mode(rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]),
1240 + CAKE_FLOW_MAX, "flowmode", flowmode_names);
1243 + if (tb[TCA_CAKE_NAT] &&
1244 + RTA_PAYLOAD(tb[TCA_CAKE_NAT]) >= sizeof(__u32)) {
1245 + nat = rta_getattr_u32(tb[TCA_CAKE_NAT]);
1249 + print_string(PRINT_FP, NULL, "nat ", NULL);
1250 + print_bool(PRINT_JSON, "nat", NULL, nat);
1252 + if (tb[TCA_CAKE_WASH] &&
1253 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
1254 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
1256 + if (tb[TCA_CAKE_ATM] &&
1257 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
1258 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
1260 + if (tb[TCA_CAKE_OVERHEAD] &&
1261 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__s32)) {
1262 + overhead = *(__s32 *) RTA_DATA(tb[TCA_CAKE_OVERHEAD]);
1264 + if (tb[TCA_CAKE_MPU] &&
1265 + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
1266 + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
1268 + if (tb[TCA_CAKE_INGRESS] &&
1269 + RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
1270 + ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
1272 + if (tb[TCA_CAKE_ACK_FILTER] &&
1273 + RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
1274 + ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
1276 + if (tb[TCA_CAKE_SPLIT_GSO] &&
1277 + RTA_PAYLOAD(tb[TCA_CAKE_SPLIT_GSO]) >= sizeof(__u32)) {
1278 + split_gso = rta_getattr_u32(tb[TCA_CAKE_SPLIT_GSO]);
1280 + if (tb[TCA_CAKE_RAW]) {
1283 + if (tb[TCA_CAKE_RTT] &&
1284 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
1285 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
1289 + print_string(PRINT_FP, NULL, "wash ", NULL);
1290 + print_bool(PRINT_JSON, "wash", NULL, wash);
1293 + print_string(PRINT_FP, NULL, "ingress ", NULL);
1294 + print_bool(PRINT_JSON, "ingress", NULL, ingress);
1296 + if (ack_filter == CAKE_ACK_AGGRESSIVE)
1297 + print_string(PRINT_ANY, "ack-filter", "ack-filter-%s ",
1299 + else if (ack_filter == CAKE_ACK_FILTER)
1300 + print_string(PRINT_ANY, "ack-filter", "ack-filter ", "enabled");
1302 + print_string(PRINT_JSON, "ack-filter", NULL, "disabled");
1305 + print_string(PRINT_FP, NULL, "split-gso ", NULL);
1306 + print_bool(PRINT_JSON, "split_gso", NULL, split_gso);
1309 + print_string(PRINT_FP, NULL, "rtt %s ",
1310 + sprint_time(interval, b2));
1311 + print_uint(PRINT_JSON, "rtt", NULL, interval);
1314 + print_string(PRINT_FP, NULL, "raw ", NULL);
1315 + print_bool(PRINT_JSON, "raw", NULL, raw);
1317 + if (atm == CAKE_ATM_ATM)
1318 + print_string(PRINT_ANY, "atm", "%s ", "atm");
1319 + else if (atm == CAKE_ATM_PTM)
1320 + print_string(PRINT_ANY, "atm", "%s ", "ptm");
1322 + print_string(PRINT_ANY, "atm", "%s ", "noatm");
1324 + print_int(PRINT_ANY, "overhead", "overhead %d ", overhead);
1327 + print_uint(PRINT_ANY, "mpu", "mpu %u ", mpu);
1330 + print_uint(PRINT_JSON, "memlimit", NULL, memlimit);
1331 + print_string(PRINT_FP, NULL, "memlimit %s",
1332 + sprint_size(memlimit, b1));
1338 +static void cake_print_json_tin(struct rtattr **tstat)
1340 +#define PRINT_TSTAT_JSON(type, name, attr) if (tstat[TCA_CAKE_TIN_STATS_ ## attr]) \
1341 + print_u64(PRINT_JSON, name, NULL, \
1342 + rta_getattr_ ## type((struct rtattr *) \
1343 + tstat[TCA_CAKE_TIN_STATS_ ## attr]))
1345 + open_json_object(NULL);
1346 + PRINT_TSTAT_JSON(u64, "threshold_rate", THRESHOLD_RATE64);
1347 + PRINT_TSTAT_JSON(u64, "sent_bytes", SENT_BYTES64);
1348 + PRINT_TSTAT_JSON(u32, "backlog_bytes", BACKLOG_BYTES);
1349 + PRINT_TSTAT_JSON(u32, "target_us", TARGET_US);
1350 + PRINT_TSTAT_JSON(u32, "interval_us", INTERVAL_US);
1351 + PRINT_TSTAT_JSON(u32, "peak_delay_us", PEAK_DELAY_US);
1352 + PRINT_TSTAT_JSON(u32, "avg_delay_us", AVG_DELAY_US);
1353 + PRINT_TSTAT_JSON(u32, "base_delay_us", BASE_DELAY_US);
1354 + PRINT_TSTAT_JSON(u32, "sent_packets", SENT_PACKETS);
1355 + PRINT_TSTAT_JSON(u32, "way_indirect_hits", WAY_INDIRECT_HITS);
1356 + PRINT_TSTAT_JSON(u32, "way_misses", WAY_MISSES);
1357 + PRINT_TSTAT_JSON(u32, "way_collisions", WAY_COLLISIONS);
1358 + PRINT_TSTAT_JSON(u32, "drops", DROPPED_PACKETS);
1359 + PRINT_TSTAT_JSON(u32, "ecn_mark", ECN_MARKED_PACKETS);
1360 + PRINT_TSTAT_JSON(u32, "ack_drops", ACKS_DROPPED_PACKETS);
1361 + PRINT_TSTAT_JSON(u32, "sparse_flows", SPARSE_FLOWS);
1362 + PRINT_TSTAT_JSON(u32, "bulk_flows", BULK_FLOWS);
1363 + PRINT_TSTAT_JSON(u32, "unresponsive_flows", UNRESPONSIVE_FLOWS);
1364 + PRINT_TSTAT_JSON(u32, "max_pkt_len", MAX_SKBLEN);
1365 + PRINT_TSTAT_JSON(u32, "flow_quantum", FLOW_QUANTUM);
1366 + close_json_object();
1368 +#undef PRINT_TSTAT_JSON
1371 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
1372 + struct rtattr *xstats)
1374 + struct rtattr *st[TCA_CAKE_STATS_MAX + 1];
1378 + if (xstats == NULL)
1381 +#define GET_STAT_U32(attr) rta_getattr_u32(st[TCA_CAKE_STATS_ ## attr])
1382 +#define GET_STAT_S32(attr) (*(__s32 *)RTA_DATA(st[TCA_CAKE_STATS_ ## attr]))
1383 +#define GET_STAT_U64(attr) rta_getattr_u64(st[TCA_CAKE_STATS_ ## attr])
1385 + parse_rtattr_nested(st, TCA_CAKE_STATS_MAX, xstats);
1387 + if (st[TCA_CAKE_STATS_MEMORY_USED] &&
1388 + st[TCA_CAKE_STATS_MEMORY_LIMIT]) {
1389 + print_string(PRINT_FP, NULL, " memory used: %s",
1390 + sprint_size(GET_STAT_U32(MEMORY_USED), b1));
1392 + print_string(PRINT_FP, NULL, " of %s\n",
1393 + sprint_size(GET_STAT_U32(MEMORY_LIMIT), b1));
1395 + print_uint(PRINT_JSON, "memory_used", NULL,
1396 + GET_STAT_U32(MEMORY_USED));
1397 + print_uint(PRINT_JSON, "memory_limit", NULL,
1398 + GET_STAT_U32(MEMORY_LIMIT));
1401 + if (st[TCA_CAKE_STATS_CAPACITY_ESTIMATE64]) {
1402 + print_string(PRINT_FP, NULL, " capacity estimate: %s\n",
1403 + sprint_rate(GET_STAT_U64(CAPACITY_ESTIMATE64), b1));
1404 + print_uint(PRINT_JSON, "capacity_estimate", NULL,
1405 + GET_STAT_U64(CAPACITY_ESTIMATE64));
1408 + if (st[TCA_CAKE_STATS_MIN_NETLEN] &&
1409 + st[TCA_CAKE_STATS_MAX_NETLEN]) {
1410 + print_uint(PRINT_ANY, "min_network_size",
1411 + " min/max network layer size: %12u",
1412 + GET_STAT_U32(MIN_NETLEN));
1413 + print_uint(PRINT_ANY, "max_network_size",
1414 + " /%8u\n", GET_STAT_U32(MAX_NETLEN));
1417 + if (st[TCA_CAKE_STATS_MIN_ADJLEN] &&
1418 + st[TCA_CAKE_STATS_MAX_ADJLEN]) {
1419 + print_uint(PRINT_ANY, "min_adj_size",
1420 + " min/max overhead-adjusted size: %8u",
1421 + GET_STAT_U32(MIN_ADJLEN));
1422 + print_uint(PRINT_ANY, "max_adj_size",
1423 + " /%8u\n", GET_STAT_U32(MAX_ADJLEN));
1426 + if (st[TCA_CAKE_STATS_AVG_NETOFF])
1427 + print_uint(PRINT_ANY, "avg_hdr_offset",
1428 + " average network hdr offset: %12u\n\n",
1429 + GET_STAT_U32(AVG_NETOFF));
1432 + if (st[TCA_CAKE_STATS_DEFICIT])
1433 + print_int(PRINT_ANY, "deficit", " deficit %u",
1434 + GET_STAT_S32(DEFICIT));
1435 + if (st[TCA_CAKE_STATS_COBALT_COUNT])
1436 + print_uint(PRINT_ANY, "count", " count %u",
1437 + GET_STAT_U32(COBALT_COUNT));
1439 + if (st[TCA_CAKE_STATS_DROPPING] && GET_STAT_U32(DROPPING)) {
1440 + print_bool(PRINT_ANY, "dropping", " dropping", true);
1441 + if (st[TCA_CAKE_STATS_DROP_NEXT_US]) {
1442 + int drop_next = GET_STAT_S32(DROP_NEXT_US);
1444 + if (drop_next < 0) {
1445 + print_string(PRINT_FP, NULL, " drop_next -%s",
1446 + sprint_time(drop_next, b1));
1448 + print_uint(PRINT_JSON, "drop_next", NULL,
1450 + print_string(PRINT_FP, NULL, " drop_next %s",
1451 + sprint_time(drop_next, b1));
1456 + if (st[TCA_CAKE_STATS_P_DROP]) {
1457 + print_uint(PRINT_ANY, "blue_prob", " blue_prob %u",
1458 + GET_STAT_U32(P_DROP));
1459 + if (st[TCA_CAKE_STATS_BLUE_TIMER_US]) {
1460 + int blue_timer = GET_STAT_S32(BLUE_TIMER_US);
1462 + if (blue_timer < 0) {
1463 + print_string(PRINT_FP, NULL, " blue_timer -%s",
1464 + sprint_time(blue_timer, b1));
1466 + print_uint(PRINT_JSON, "blue_timer", NULL,
1468 + print_string(PRINT_FP, NULL, " blue_timer %s",
1469 + sprint_time(blue_timer, b1));
1474 +#undef GET_STAT_U32
1475 +#undef GET_STAT_S32
1476 +#undef GET_STAT_U64
1478 + if (st[TCA_CAKE_STATS_TIN_STATS]) {
1479 + struct rtattr *tstat[TC_CAKE_MAX_TINS][TCA_CAKE_TIN_STATS_MAX + 1];
1480 + struct rtattr *tins[TC_CAKE_MAX_TINS + 1];
1483 + parse_rtattr_nested(tins, TC_CAKE_MAX_TINS,
1484 + st[TCA_CAKE_STATS_TIN_STATS]);
1486 + for (i = 1; i <= TC_CAKE_MAX_TINS && tins[i]; i++) {
1487 + parse_rtattr_nested(tstat[i-1], TCA_CAKE_TIN_STATS_MAX,
1495 + if (is_json_context()) {
1496 + open_json_array(PRINT_JSON, "tins");
1497 + for (i = 0; i < num_tins; i++)
1498 + cake_print_json_tin(tstat[i]);
1499 + close_json_array(PRINT_JSON, NULL);
1505 + switch (num_tins) {
1507 + fprintf(f, " Bulk Best Effort Voice\n");
1511 + fprintf(f, " Bulk Best Effort Video Voice\n");
1516 + for (i = 0; i < num_tins; i++)
1517 + fprintf(f, " Tin %u", i);
1521 +#define GET_TSTAT(i, attr) (tstat[i][TCA_CAKE_TIN_STATS_ ## attr])
1522 +#define PRINT_TSTAT(name, attr, fmts, val) do { \
1523 + if (GET_TSTAT(0, attr)) { \
1524 + fprintf(f, name); \
1525 + for (i = 0; i < num_tins; i++) \
1526 + fprintf(f, " %12" fmts, val); \
1527 + fprintf(f, "\n"); \
1531 +#define SPRINT_TSTAT(pfunc, type, name, attr) PRINT_TSTAT( \
1532 + name, attr, "s", sprint_ ## pfunc( \
1533 + rta_getattr_ ## type(GET_TSTAT(i, attr)), b1))
1535 +#define PRINT_TSTAT_U32(name, attr) PRINT_TSTAT( \
1536 + name, attr, "u", rta_getattr_u32(GET_TSTAT(i, attr)))
1538 +#define PRINT_TSTAT_U64(name, attr) PRINT_TSTAT( \
1539 + name, attr, "llu", rta_getattr_u64(GET_TSTAT(i, attr)))
1541 + SPRINT_TSTAT(rate, u64, " thresh ", THRESHOLD_RATE64);
1542 + SPRINT_TSTAT(time, u32, " target ", TARGET_US);
1543 + SPRINT_TSTAT(time, u32, " interval", INTERVAL_US);
1544 + SPRINT_TSTAT(time, u32, " pk_delay", PEAK_DELAY_US);
1545 + SPRINT_TSTAT(time, u32, " av_delay", AVG_DELAY_US);
1546 + SPRINT_TSTAT(time, u32, " sp_delay", BASE_DELAY_US);
1547 + SPRINT_TSTAT(size, u32, " backlog ", BACKLOG_BYTES);
1549 + PRINT_TSTAT_U32(" pkts ", SENT_PACKETS);
1550 + PRINT_TSTAT_U64(" bytes ", SENT_BYTES64);
1552 + PRINT_TSTAT_U32(" way_inds", WAY_INDIRECT_HITS);
1553 + PRINT_TSTAT_U32(" way_miss", WAY_MISSES);
1554 + PRINT_TSTAT_U32(" way_cols", WAY_COLLISIONS);
1555 + PRINT_TSTAT_U32(" drops ", DROPPED_PACKETS);
1556 + PRINT_TSTAT_U32(" marks ", ECN_MARKED_PACKETS);
1557 + PRINT_TSTAT_U32(" ack_drop", ACKS_DROPPED_PACKETS);
1558 + PRINT_TSTAT_U32(" sp_flows", SPARSE_FLOWS);
1559 + PRINT_TSTAT_U32(" bk_flows", BULK_FLOWS);
1560 + PRINT_TSTAT_U32(" un_flows", UNRESPONSIVE_FLOWS);
1561 + PRINT_TSTAT_U32(" max_len ", MAX_SKBLEN);
1562 + PRINT_TSTAT_U32(" quantum ", FLOW_QUANTUM);
1566 +#undef SPRINT_TSTAT
1567 +#undef PRINT_TSTAT_U32
1568 +#undef PRINT_TSTAT_U64
1573 +struct qdisc_util cake_qdisc_util = {
1575 + .parse_qopt = cake_parse_opt,
1576 + .print_qopt = cake_print_opt,
1577 + .print_xstats = cake_print_xstats,