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
208 +.BR ack-filter-aggressive
247 +CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline
248 +which uses both AQM and FQ. It combines COBALT, which is an AQM algorithm
249 +combining Codel and BLUE, a shaper which operates in deficit mode, and a variant
250 +of DRR++ for flow isolation. 8-way set-associative hashing is used to virtually
251 +eliminate hash collisions. Priority queuing is available through a simplified
252 +diffserv implementation. Overhead compensation for various encapsulation
253 +schemes is tightly integrated.
255 +All settings are optional; the default settings are chosen to be sensible in
256 +most common deployments. Most people will only need to set the
258 +parameter to get useful results, but reading the
259 +.B Overhead Compensation
262 +sections is strongly encouraged.
264 +.SH SHAPER PARAMETERS
265 +CAKE uses a deficit-mode shaper, which does not exhibit the initial burst
266 +typical of token-bucket shapers. It will automatically burst precisely as much
267 +as required to maintain the configured throughput. As such, it is very
268 +straightforward to configure.
273 + No limit on the bandwidth.
278 + Set the shaper bandwidth. See
280 +or examples below for details of the RATE value.
284 + Automatic capacity estimation based on traffic arriving at this qdisc.
285 +This is most likely to be useful with cellular links, which tend to change
288 +parameter can be used in conjunction to specify an initial estimate. The shaper
289 +will periodically be set to a bandwidth slightly below the estimated rate. This
290 +estimator cannot estimate the bandwidth of links downstream of itself.
292 +.SH OVERHEAD COMPENSATION PARAMETERS
293 +The size of each packet on the wire may differ from that seen by Linux. The
294 +following parameters allow CAKE to compensate for this difference by internally
295 +considering each packet to be bigger than Linux informs it. To assist users who
296 +are not expert network engineers, keywords have been provided to represent a
297 +number of common link technologies.
299 +.SS Manual Overhead Specification
303 + Adds BYTES to the size of each packet. BYTES may be negative; values
304 +between -64 and 256 (inclusive) are accepted.
309 + Rounds each packet (including overhead) up to a minimum length
310 +BYTES. BYTES may not be negative; values between 0 and 256 (inclusive)
315 + Compensates for ATM cell framing, which is normally found on ADSL links.
316 +This is performed after the
318 +parameter above. ATM uses fixed 53-byte cells, each of which can carry 48 bytes
323 + Compensates for PTM encoding, which is normally found on VDSL2 links and
324 +uses a 64b/65b encoding scheme. It is even more efficient to simply
325 +derate the specified shaper bandwidth by a factor of 64/65 or 0.984. See
326 +ITU G.992.3 Annex N and IEEE 802.3 Section 61.3 for details.
330 + Disables ATM and PTM compensation.
332 +.SS Failsafe Overhead Keywords
333 +These two keywords are provided for quick-and-dirty setup. Use them if you
334 +can't be bothered to read the rest of this section.
339 + Turns off all overhead compensation in CAKE. The packet size reported
340 +by Linux will be used directly.
342 + Other overhead keywords may be added after "raw". The effect of this is
343 +to make the overhead compensation operate relative to the reported packet size,
344 +not the underlying IP packet size.
348 + Compensates for more overhead than is likely to occur on any
349 +widely-deployed link technology.
354 +.SS ADSL Overhead Keywords
355 +Most ADSL modems have a way to check which framing scheme is in use. Often this
356 +is also specified in the settings document provided by the ISP. The keywords in
357 +this section are intended to correspond with these sources of information. All
358 +of them implicitly set the
402 +See also the Ethernet Correction Factors section below.
404 +.SS VDSL2 Overhead Keywords
405 +ATM was dropped from VDSL2 in favour of PTM, which is a much more
406 +straightforward framing scheme. Some ISPs retained PPPoE for compatibility with
407 +their existing back-end systems.
415 + PPPoE: 2B PPP + 6B PPPoE +
417 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
419 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
427 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
429 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
432 +See also the Ethernet Correction Factors section below.
434 +.SS DOCSIS Cable Overhead Keyword
435 +DOCSIS is the universal standard for providing Internet service over cable-TV
438 +In this case, the actual on-wire overhead is less important than the packet size
439 +the head-end equipment uses for shaping and metering. This is specified to be
440 +an Ethernet frame including the CRC (aka FCS).
445 +.B overhead 18 mpu 64 noatm
447 +.SS Ethernet Overhead Keywords
451 + Accounts for Ethernet's preamble, inter-frame gap, and Frame Check
452 +Sequence. Use this keyword when the bottleneck being shaped for is an
453 +actual Ethernet cable.
456 +.B overhead 38 mpu 84 noatm
460 + Adds 4 bytes to the overhead compensation, accounting for an IEEE 802.1Q
461 +VLAN header appended to the Ethernet frame header. NB: Some ISPs use one or
462 +even two of these within PPPoE; this keyword may be repeated as necessary to
465 +.SH ROUND TRIP TIME PARAMETERS
466 +Active Queue Management (AQM) consists of embedding congestion signals in the
467 +packet flow, which receivers use to instruct senders to slow down when the queue
468 +is persistently occupied. CAKE uses ECN signalling when available, and packet
469 +drops otherwise, according to a combination of the Codel and BLUE AQM algorithms
472 +Very short latencies require a very rapid AQM response to adequately control
473 +latency. However, such a rapid response tends to impair throughput when the
474 +actual RTT is relatively long. CAKE allows specifying the RTT it assumes for
475 +tuning various parameters. Actual RTTs within an order of magnitude of this
476 +will generally work well for both throughput and latency management.
478 +At the 'lan' setting and below, the time constants are similar in magnitude to
479 +the jitter in the Linux kernel itself, so congestion might be signalled
480 +prematurely. The flows will then become sparse and total throughput reduced,
481 +leaving little or no back-pressure for the fairness logic to work against. Use
482 +the "metro" setting for local lans unless you have a custom kernel.
487 + Manually specify an RTT.
491 + For extremely high-performance 10GigE+ networks only. Equivalent to
496 + For pure Ethernet (not Wi-Fi) networks, at home or in the office. Don't
497 +use this when shaping for an Internet access link. Equivalent to
502 + For traffic mostly within a single city. Equivalent to
507 + For traffic mostly within a European-sized country. Equivalent to
513 + This is suitable for most Internet traffic. Equivalent to
518 + For Internet traffic with generally above-average latency, such as that
519 +suffered by Australasian residents. Equivalent to
524 + For traffic via geostationary satellites. Equivalent to
529 + So named because Jupiter is about 1 light-hour from Earth. Use this to
530 +(almost) completely disable AQM actions. Equivalent to
533 +.SH FLOW ISOLATION PARAMETERS
534 +With flow isolation enabled, CAKE places packets from different flows into
535 +different queues, each of which carries its own AQM state. Packets from each
536 +queue are then delivered fairly, according to a DRR++ algorithm which minimises
537 +latency for "sparse" flows. CAKE uses a set-associative hashing algorithm to
538 +minimise flow collisions.
540 +These keywords specify whether fairness based on source address, destination
541 +address, individual flows, or any combination of those is desired.
545 + Disables flow isolation; all traffic passes through a single queue for
550 + Flows are defined only by source address. Could be useful on the egress
551 +path of an ISP backhaul.
555 + Flows are defined only by destination address. Could be useful on the
556 +ingress path of an ISP backhaul.
560 + Flows are defined by source-destination host pairs. This is host
561 +isolation, rather than flow isolation.
565 + Flows are defined by the entire 5-tuple of source address, destination
566 +address, transport protocol, source port and destination port. This is the type
567 +of flow isolation performed by SFQ and fq_codel.
571 + Flows are defined by the 5-tuple, and fairness is applied first over
572 +source addresses, then over individual flows. Good for use on egress traffic
573 +from a LAN to the internet, where it'll prevent any one LAN host from
574 +monopolising the uplink, regardless of the number of flows they use.
578 + Flows are defined by the 5-tuple, and fairness is applied first over
579 +destination addresses, then over individual flows. Good for use on ingress
580 +traffic to a LAN from the internet, where it'll prevent any one LAN host from
581 +monopolising the downlink, regardless of the number of flows they use.
586 + Flows are defined by the 5-tuple, and fairness is applied over source
587 +*and* destination addresses intelligently (ie. not merely by host-pairs), and
588 +also over individual flows. Use this if you're not certain whether to use
589 +dual-srchost or dual-dsthost; it'll do both jobs at once, preventing any one
590 +host on *either* side of the link from monopolising it with a large number of
595 + Instructs Cake to perform a NAT lookup before applying flow-isolation
596 +rules, to determine the true addresses and port numbers of the packet, to
597 +improve fairness between hosts "inside" the NAT. This has no practical effect
598 +in "flowblind" or "flows" modes, or if NAT is performed on a different host.
603 + Cake will not perform a NAT lookup. Flow isolation will be performed
604 +using the addresses and port numbers directly visible to the interface Cake is
607 +.SH PRIORITY QUEUE PARAMETERS
608 +CAKE can divide traffic into "tins" based on the Diffserv field. Each tin has
609 +its own independent set of flow-isolation queues, and is serviced based on a WRR
610 +algorithm. To avoid perverse Diffserv marking incentives, tin weights have a
611 +"priority sharing" value when bandwidth used by that tin is below a threshold,
612 +and a lower "bandwidth sharing" value when above. Bandwidth is compared against
613 +the threshold using the same algorithm as the deficit-mode shaper.
615 +Detailed customisation of tin parameters is not provided. The following presets
616 +perform all necessary tuning, relative to the current shaper bandwidth and RTT
621 + Disables priority queuing by placing all traffic in one tin.
625 + Enables legacy interpretation of TOS "Precedence" field. Use of this
626 +preset on the modern Internet is firmly discouraged.
630 + Provides a general-purpose Diffserv implementation with four tins:
632 + Bulk (CS1), 6.25% threshold, generally low priority.
634 + Best Effort (general), 100% threshold.
636 + Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, TOS1), 50% threshold.
638 + Voice (CS7, CS6, EF, VA, CS5, CS4), 25% threshold.
643 + Provides a simple, general-purpose Diffserv implementation with three tins:
645 + Bulk (CS1), 6.25% threshold, generally low priority.
647 + Best Effort (general), 100% threshold.
649 + Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
651 +.SH OTHER PARAMETERS
655 + Limit the memory consumed by Cake to LIMIT bytes. Note that this does
656 +not translate directly to queue size (so do not size this based on bandwidth
657 +delay product considerations, but rather on worst case acceptable memory
658 +consumption), as there is some overhead in the data structures containing the
659 +packets, especially for small packets.
661 + By default, the limit is calculated based on the bandwidth and RTT
668 + Traffic entering your diffserv domain is frequently mis-marked in
669 +transit from the perspective of your network, and traffic exiting yours may be
670 +mis-marked from the perspective of the transiting provider.
672 +Apply the wash option to clear all extra diffserv (but not ECN bits), after
673 +priority queuing has taken place.
675 +If you are shaping inbound, and cannot trust the diffserv markings (as is the
676 +case for Comcast Cable, among others), it is best to use a single queue
677 +"besteffort" mode with wash.
683 + This option controls whether CAKE will split General Segmentation
684 +Offload (GSO) super-packets into their on-the-wire components and
685 +dequeue them individually.
688 +Super-packets are created by the networking stack to improve efficiency.
689 +However, because they are larger they take longer to dequeue, which
690 +translates to higher latency for competing flows, especially at lower
691 +bandwidths. CAKE defaults to splitting GSO packets to achieve the lowest
692 +possible latency. At link speeds higher than 10 Gbps, setting the
693 +no-split-gso parameter can increase the maximum achievable throughput by
694 +retaining the full GSO packets.
696 +.SH OVERRIDING CLASSIFICATION WITH TC FILTERS
698 +CAKE supports overriding of its internal classification of packets through the
699 +tc filter mechanism. Packets can be assigned to different priority tins by
702 +field on the skb, and the flow hashing can be overridden by setting the
710 + To assign a priority tin, the major number of the priority field needs
711 +to match the qdisc handle of the cake instance; if it does, the minor number
712 +will be interpreted as the tin index. For example, to classify all ICMP packets
713 +as 'bulk', the following filter can be used:
716 + # tc qdisc replace dev eth0 handle 1: root cake diffserv3
717 + # tc filter add dev eth0 parent 1: protocol ip prio 1 \\
718 + u32 match icmp type 0 0 action skbedit priority 1:1
721 +.B Flow hash override
724 + To override flow hashing, the classid can be set. CAKE will interpret
725 +the major number of the classid as the host hash used in host isolation mode,
726 +and the minor number as the flow hash used for flow-based queueing. One or both
727 +of those can be set, and will be used if the relevant flow isolation parameter
728 +is set (i.e., the major number will be ignored if CAKE is not configured in
729 +hosts mode, and the minor number will be ignored if CAKE is not configured in
733 +This example will assign all ICMP packets to the first queue:
736 + # tc qdisc replace dev eth0 handle 1: root cake
737 + # tc filter add dev eth0 parent 1: protocol ip prio 1 \\
738 + u32 match icmp type 0 0 classid 0:1
741 +If only one of the host and flow overrides is set, CAKE will compute the other
742 +hash from the packet as normal. Note, however, that the host isolation mode
743 +works by assigning a host ID to the flow queue; so if overriding both host and
744 +flow, the same flow cannot have more than one host assigned. In addition, it is
745 +not possible to assign different source and destination host IDs through the
746 +override mechanism; if a host ID is assigned, it will be used as both source and
752 +# tc qdisc delete root dev eth0
754 +# tc qdisc add root dev eth0 cake bandwidth 100Mbit ethernet
756 +# tc -s qdisc show dev eth0
758 +qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
759 + Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
760 + backlog 0b 0p requeues 0
761 + memory used: 0b of 5000000b
762 + capacity estimate: 100Mbit
763 + min/max network layer size: 65535 / 0
764 + min/max overhead-adjusted size: 65535 / 0
765 + average network hdr offset: 0
767 + Bulk Best Effort Voice
768 + thresh 6250Kbit 100Mbit 25Mbit
769 + target 5.0ms 5.0ms 5.0ms
770 + interval 100.0ms 100.0ms 100.0ms
771 + pk_delay 0us 0us 0us
772 + av_delay 0us 0us 0us
773 + sp_delay 0us 0us 0us
786 + quantum 300 1514 762
790 +# tc -s qdisc show dev eth0
792 +qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
793 + Sent 44709231 bytes 31931 pkt (dropped 45, overlimits 93782 requeues 0)
794 + backlog 33308b 22p requeues 0
795 + memory used: 292352b of 5000000b
796 + capacity estimate: 100Mbit
797 + min/max network layer size: 28 / 1500
798 + min/max overhead-adjusted size: 84 / 1538
799 + average network hdr offset: 14
801 + Bulk Best Effort Voice
802 + thresh 6250Kbit 100Mbit 25Mbit
803 + target 5.0ms 5.0ms 5.0ms
804 + interval 100.0ms 100.0ms 100.0ms
805 + pk_delay 8.7ms 6.9ms 5.0ms
806 + av_delay 4.9ms 5.3ms 3.8ms
807 + sp_delay 727us 1.4ms 511us
808 + pkts 2590 21271 8137
809 + bytes 3081804 30302659 11426206
819 + max_len 1514 1514 1514
820 + quantum 300 1514 762
825 +.BR tc-fq_codel (8),
829 +Cake's principal author is Jonathan Morton, with contributions from
830 +Tony Ambardar, Kevin Darbyshire-Bryant, Toke Høiland-Jørgensen,
831 +Sebastian Moeller, Ryan Mounce, Dean Scarff, Nils Andreas Svee, and Dave Täht.
833 +This manual page was written by Loganaden Velvindron. Please report corrections
834 +to the Linux Networking mailing list <netdev@vger.kernel.org>.
837 @@ -795,6 +795,7 @@ was written by Alexey N. Kuznetsov and a
847 @@ -66,6 +66,7 @@ TCMODULES += q_codel.o
848 TCMODULES += q_fq_codel.o
851 +TCMODULES += q_cake.o
853 TCMODULES += q_clsact.o
858 +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
861 + * Common Applications Kept Enhanced -- CAKE
863 + * Copyright (C) 2014-2018 Jonathan Morton <chromatix99@gmail.com>
864 + * Copyright (C) 2017-2018 Toke Høiland-Jørgensen <toke@toke.dk>
873 +#include <sys/socket.h>
874 +#include <netinet/in.h>
875 +#include <arpa/inet.h>
877 +#include <inttypes.h>
880 +#include "tc_util.h"
882 +struct cake_preset {
884 + unsigned int target;
885 + unsigned int interval;
888 +static struct cake_preset presets[] = {
889 + {"datacentre", 5, 100},
891 + {"metro", 500, 10000},
892 + {"regional", 1500, 30000},
893 + {"internet", 5000, 100000},
894 + {"oceanic", 15000, 300000},
895 + {"satellite", 50000, 1000000},
896 + {"interplanetary", 50000000, 1000000000},
899 +static const char * diffserv_names[CAKE_DIFFSERV_MAX] = {
900 + [CAKE_DIFFSERV_DIFFSERV3] = "diffserv3",
901 + [CAKE_DIFFSERV_DIFFSERV4] = "diffserv4",
902 + [CAKE_DIFFSERV_DIFFSERV8] = "diffserv8",
903 + [CAKE_DIFFSERV_BESTEFFORT] = "besteffort",
904 + [CAKE_DIFFSERV_PRECEDENCE] = "precedence",
907 +static const char * flowmode_names[CAKE_FLOW_MAX] = {
908 + [CAKE_FLOW_NONE] = "flowblind",
909 + [CAKE_FLOW_SRC_IP] = "srchost",
910 + [CAKE_FLOW_DST_IP] = "dsthost",
911 + [CAKE_FLOW_HOSTS] = "hosts",
912 + [CAKE_FLOW_FLOWS] = "flows",
913 + [CAKE_FLOW_DUAL_SRC] = "dual-srchost",
914 + [CAKE_FLOW_DUAL_DST] = "dual-dsthost",
915 + [CAKE_FLOW_TRIPLE] = "triple-isolate",
918 +static struct cake_preset *find_preset(char *argv)
922 + for (i = 0; i < ARRAY_SIZE(presets); i++)
923 + if (!strcmp(argv, presets[i].name))
924 + return &presets[i];
928 +static void explain(void)
931 +"Usage: ... cake [ bandwidth RATE | unlimited* | autorate-ingress ]\n"
932 +" [ rtt TIME | datacentre | lan | metro | regional |\n"
933 +" internet* | oceanic | satellite | interplanetary ]\n"
934 +" [ besteffort | diffserv8 | diffserv4 | diffserv3* ]\n"
935 +" [ flowblind | srchost | dsthost | hosts | flows |\n"
936 +" dual-srchost | dual-dsthost | triple-isolate* ]\n"
937 +" [ nat | nonat* ]\n"
938 +" [ wash | nowash* ]\n"
939 +" [ split-gso* | no-split-gso ]\n"
940 +" [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
941 +" [ memlimit LIMIT ]\n"
942 +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
943 +" [ mpu N ] [ ingress | egress* ]\n"
944 +" (* marks defaults)\n");
947 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
948 + struct nlmsghdr *n, const char *dev)
950 + struct cake_preset *preset, *preset_set = NULL;
951 + bool overhead_override = false;
952 + bool overhead_set = false;
953 + unsigned int interval = 0;
954 + unsigned int diffserv = 0;
955 + unsigned int memlimit = 0;
956 + unsigned int target = 0;
957 + __u64 bandwidth = 0;
958 + int ack_filter = -1;
959 + struct rtattr *tail;
960 + int split_gso = -1;
972 + if (strcmp(*argv, "bandwidth") == 0) {
974 + if (get_rate64(&bandwidth, *argv)) {
975 + fprintf(stderr, "Illegal \"bandwidth\"\n");
980 + } else if (strcmp(*argv, "unlimited") == 0) {
984 + } else if (strcmp(*argv, "autorate-ingress") == 0) {
986 + } else if (strcmp(*argv, "rtt") == 0) {
988 + if (get_time(&interval, *argv)) {
989 + fprintf(stderr, "Illegal \"rtt\"\n");
992 + target = interval / 20;
995 + } else if ((preset = find_preset(*argv))) {
997 + duparg(*argv, preset_set->name);
998 + preset_set = preset;
999 + target = preset->target;
1000 + interval = preset->interval;
1001 + } else if (strcmp(*argv, "besteffort") == 0) {
1002 + diffserv = CAKE_DIFFSERV_BESTEFFORT;
1003 + } else if (strcmp(*argv, "precedence") == 0) {
1004 + diffserv = CAKE_DIFFSERV_PRECEDENCE;
1005 + } else if (strcmp(*argv, "diffserv8") == 0) {
1006 + diffserv = CAKE_DIFFSERV_DIFFSERV8;
1007 + } else if (strcmp(*argv, "diffserv4") == 0) {
1008 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
1009 + } else if (strcmp(*argv, "diffserv") == 0) {
1010 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
1011 + } else if (strcmp(*argv, "diffserv3") == 0) {
1012 + diffserv = CAKE_DIFFSERV_DIFFSERV3;
1013 + } else if (strcmp(*argv, "nowash") == 0) {
1015 + } else if (strcmp(*argv, "wash") == 0) {
1017 + } else if (strcmp(*argv, "split-gso") == 0) {
1019 + } else if (strcmp(*argv, "no-split-gso") == 0) {
1021 + } else if (strcmp(*argv, "flowblind") == 0) {
1022 + flowmode = CAKE_FLOW_NONE;
1023 + } else if (strcmp(*argv, "srchost") == 0) {
1024 + flowmode = CAKE_FLOW_SRC_IP;
1025 + } else if (strcmp(*argv, "dsthost") == 0) {
1026 + flowmode = CAKE_FLOW_DST_IP;
1027 + } else if (strcmp(*argv, "hosts") == 0) {
1028 + flowmode = CAKE_FLOW_HOSTS;
1029 + } else if (strcmp(*argv, "flows") == 0) {
1030 + flowmode = CAKE_FLOW_FLOWS;
1031 + } else if (strcmp(*argv, "dual-srchost") == 0) {
1032 + flowmode = CAKE_FLOW_DUAL_SRC;
1033 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
1034 + flowmode = CAKE_FLOW_DUAL_DST;
1035 + } else if (strcmp(*argv, "triple-isolate") == 0) {
1036 + flowmode = CAKE_FLOW_TRIPLE;
1037 + } else if (strcmp(*argv, "nat") == 0) {
1039 + } else if (strcmp(*argv, "nonat") == 0) {
1041 + } else if (strcmp(*argv, "ptm") == 0) {
1042 + atm = CAKE_ATM_PTM;
1043 + } else if (strcmp(*argv, "atm") == 0) {
1044 + atm = CAKE_ATM_ATM;
1045 + } else if (strcmp(*argv, "noatm") == 0) {
1046 + atm = CAKE_ATM_NONE;
1047 + } else if (strcmp(*argv, "raw") == 0) {
1048 + atm = CAKE_ATM_NONE;
1050 + overhead_set = true;
1051 + overhead_override = true;
1052 + } else if (strcmp(*argv, "conservative") == 0) {
1054 + * Deliberately over-estimate overhead:
1055 + * one whole ATM cell plus ATM framing.
1056 + * A safe choice if the actual overhead is unknown.
1058 + atm = CAKE_ATM_ATM;
1060 + overhead_set = true;
1062 + /* Various ADSL framing schemes, all over ATM cells */
1063 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
1064 + atm = CAKE_ATM_ATM;
1066 + overhead_set = true;
1067 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
1068 + atm = CAKE_ATM_ATM;
1070 + overhead_set = true;
1071 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
1072 + atm = CAKE_ATM_ATM;
1074 + overhead_set = true;
1075 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
1076 + atm = CAKE_ATM_ATM;
1078 + overhead_set = true;
1079 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
1080 + atm = CAKE_ATM_ATM;
1082 + overhead_set = true;
1083 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
1084 + atm = CAKE_ATM_ATM;
1086 + overhead_set = true;
1087 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
1088 + atm = CAKE_ATM_ATM;
1090 + overhead_set = true;
1091 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
1092 + atm = CAKE_ATM_ATM;
1094 + overhead_set = true;
1096 + /* Typical VDSL2 framing schemes, both over PTM */
1097 + /* PTM has 64b/65b coding which absorbs some bandwidth */
1098 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
1099 + /* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
1100 + * + 2B ethertype + 4B Frame Check Sequence
1101 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1102 + * + 2B TC-CRC (PTM-FCS) = 30B
1104 + atm = CAKE_ATM_PTM;
1106 + overhead_set = true;
1107 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
1108 + /* 6B dest MAC + 6B src MAC + 2B ethertype
1109 + * + 4B Frame Check Sequence
1110 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1111 + * + 2B TC-CRC (PTM-FCS) = 22B
1113 + atm = CAKE_ATM_PTM;
1115 + overhead_set = true;
1116 + } else if (strcmp(*argv, "via-ethernet") == 0) {
1118 + * We used to use this flag to manually compensate for
1119 + * Linux including the Ethernet header on Ethernet-type
1120 + * interfaces, but not on IP-type interfaces.
1122 + * It is no longer needed, because Cake now adjusts for
1123 + * that automatically, and is thus ignored.
1125 + * It would be deleted entirely, but it appears in the
1126 + * stats output when the automatic compensation is
1129 + } else if (strcmp(*argv, "ethernet") == 0) {
1130 + /* ethernet pre-amble & interframe gap & FCS
1131 + * you may need to add vlan tag
1134 + overhead_set = true;
1137 + /* Additional Ethernet-related overhead used by some ISPs */
1138 + } else if (strcmp(*argv, "ether-vlan") == 0) {
1139 + /* 802.1q VLAN tag - may be repeated */
1141 + overhead_set = true;
1144 + * DOCSIS cable shapers account for Ethernet frame with FCS,
1145 + * but not interframe gap or preamble.
1147 + } else if (strcmp(*argv, "docsis") == 0) {
1148 + atm = CAKE_ATM_NONE;
1150 + overhead_set = true;
1152 + } else if (strcmp(*argv, "overhead") == 0) {
1156 + overhead = strtol(*argv, &p, 10);
1157 + if (!p || *p || !*argv ||
1158 + overhead < -64 || overhead > 256) {
1160 + "Illegal \"overhead\", valid range is -64 to 256\\n");
1163 + overhead_set = true;
1165 + } else if (strcmp(*argv, "mpu") == 0) {
1169 + mpu = strtol(*argv, &p, 10);
1170 + if (!p || *p || !*argv || mpu < 0 || mpu > 256) {
1172 + "Illegal \"mpu\", valid range is 0 to 256\\n");
1175 + } else if (strcmp(*argv, "ingress") == 0) {
1177 + } else if (strcmp(*argv, "egress") == 0) {
1179 + } else if (strcmp(*argv, "no-ack-filter") == 0) {
1180 + ack_filter = CAKE_ACK_NONE;
1181 + } else if (strcmp(*argv, "ack-filter") == 0) {
1182 + ack_filter = CAKE_ACK_FILTER;
1183 + } else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
1184 + ack_filter = CAKE_ACK_AGGRESSIVE;
1185 + } else if (strcmp(*argv, "memlimit") == 0) {
1187 + if (get_size(&memlimit, *argv)) {
1189 + "Illegal value for \"memlimit\": \"%s\"\n", *argv);
1192 + } else if (strcmp(*argv, "help") == 0) {
1196 + fprintf(stderr, "What is \"%s\"?\n", *argv);
1203 + tail = NLMSG_TAIL(n);
1204 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
1205 + if (bandwidth || unlimited)
1206 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE64, &bandwidth,
1207 + sizeof(bandwidth));
1209 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv,
1210 + sizeof(diffserv));
1212 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
1213 + if (flowmode != -1)
1214 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode,
1215 + sizeof(flowmode));
1217 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead,
1218 + sizeof(overhead));
1219 + if (overhead_override) {
1220 + unsigned int zero = 0;
1222 + addattr_l(n, 1024, TCA_CAKE_RAW, &zero, sizeof(zero));
1225 + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
1227 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
1229 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
1230 + if (autorate != -1)
1231 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate,
1232 + sizeof(autorate));
1234 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit,
1235 + sizeof(memlimit));
1237 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
1239 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
1240 + if (split_gso != -1)
1241 + addattr_l(n, 1024, TCA_CAKE_SPLIT_GSO, &split_gso,
1242 + sizeof(split_gso));
1243 + if (ingress != -1)
1244 + addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
1245 + if (ack_filter != -1)
1246 + addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter,
1247 + sizeof(ack_filter));
1249 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1253 +static void cake_print_mode(unsigned int value, unsigned int max,
1254 + const char *key, const char **table)
1256 + if (value < max && table[value]) {
1257 + print_string(PRINT_ANY, key, "%s ", table[value]);
1259 + print_string(PRINT_JSON, key, NULL, "unknown");
1260 + print_string(PRINT_FP, NULL, "(?%s?)", key);
1264 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1266 + struct rtattr *tb[TCA_CAKE_MAX + 1];
1267 + unsigned int interval = 0;
1268 + unsigned int memlimit = 0;
1269 + __u64 bandwidth = 0;
1270 + int ack_filter = 0;
1271 + int split_gso = 0;
1287 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
1289 + if (tb[TCA_CAKE_BASE_RATE64] &&
1290 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE64]) >= sizeof(bandwidth)) {
1291 + bandwidth = rta_getattr_u64(tb[TCA_CAKE_BASE_RATE64]);
1293 + print_uint(PRINT_JSON, "bandwidth", NULL, bandwidth);
1294 + print_string(PRINT_FP, NULL, "bandwidth %s ",
1295 + sprint_rate(bandwidth, b1));
1297 + print_string(PRINT_ANY, "bandwidth", "bandwidth %s ",
1300 + if (tb[TCA_CAKE_AUTORATE] &&
1301 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
1302 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
1303 + if (autorate == 1)
1304 + print_string(PRINT_ANY, "autorate", "%s ",
1305 + "autorate-ingress");
1306 + else if (autorate)
1307 + print_string(PRINT_ANY, "autorate", "(?autorate?) ",
1310 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
1311 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
1312 + cake_print_mode(rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]),
1313 + CAKE_DIFFSERV_MAX, "diffserv", diffserv_names);
1315 + if (tb[TCA_CAKE_FLOW_MODE] &&
1316 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
1317 + cake_print_mode(rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]),
1318 + CAKE_FLOW_MAX, "flowmode", flowmode_names);
1321 + if (tb[TCA_CAKE_NAT] &&
1322 + RTA_PAYLOAD(tb[TCA_CAKE_NAT]) >= sizeof(__u32)) {
1323 + nat = rta_getattr_u32(tb[TCA_CAKE_NAT]);
1327 + print_string(PRINT_FP, NULL, "nat ", NULL);
1328 + print_bool(PRINT_JSON, "nat", NULL, nat);
1330 + if (tb[TCA_CAKE_WASH] &&
1331 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
1332 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
1334 + if (tb[TCA_CAKE_ATM] &&
1335 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
1336 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
1338 + if (tb[TCA_CAKE_OVERHEAD] &&
1339 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__s32)) {
1340 + overhead = *(__s32 *) RTA_DATA(tb[TCA_CAKE_OVERHEAD]);
1342 + if (tb[TCA_CAKE_MPU] &&
1343 + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
1344 + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
1346 + if (tb[TCA_CAKE_INGRESS] &&
1347 + RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
1348 + ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
1350 + if (tb[TCA_CAKE_ACK_FILTER] &&
1351 + RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
1352 + ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
1354 + if (tb[TCA_CAKE_SPLIT_GSO] &&
1355 + RTA_PAYLOAD(tb[TCA_CAKE_SPLIT_GSO]) >= sizeof(__u32)) {
1356 + split_gso = rta_getattr_u32(tb[TCA_CAKE_SPLIT_GSO]);
1358 + if (tb[TCA_CAKE_RAW]) {
1361 + if (tb[TCA_CAKE_RTT] &&
1362 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
1363 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
1367 + print_string(PRINT_FP, NULL, "wash ", NULL);
1368 + print_bool(PRINT_JSON, "wash", NULL, wash);
1371 + print_string(PRINT_FP, NULL, "ingress ", NULL);
1372 + print_bool(PRINT_JSON, "ingress", NULL, ingress);
1374 + if (ack_filter == CAKE_ACK_AGGRESSIVE)
1375 + print_string(PRINT_ANY, "ack-filter", "ack-filter-%s ",
1377 + else if (ack_filter == CAKE_ACK_FILTER)
1378 + print_string(PRINT_ANY, "ack-filter", "ack-filter ", "enabled");
1380 + print_string(PRINT_JSON, "ack-filter", NULL, "disabled");
1383 + print_string(PRINT_FP, NULL, "split-gso ", NULL);
1384 + print_bool(PRINT_JSON, "split_gso", NULL, split_gso);
1387 + print_string(PRINT_FP, NULL, "rtt %s ",
1388 + sprint_time(interval, b2));
1389 + print_uint(PRINT_JSON, "rtt", NULL, interval);
1392 + print_string(PRINT_FP, NULL, "raw ", NULL);
1393 + print_bool(PRINT_JSON, "raw", NULL, raw);
1395 + if (atm == CAKE_ATM_ATM)
1396 + print_string(PRINT_ANY, "atm", "%s ", "atm");
1397 + else if (atm == CAKE_ATM_PTM)
1398 + print_string(PRINT_ANY, "atm", "%s ", "ptm");
1400 + print_string(PRINT_ANY, "atm", "%s ", "noatm");
1402 + print_int(PRINT_ANY, "overhead", "overhead %d ", overhead);
1405 + print_uint(PRINT_ANY, "mpu", "mpu %u ", mpu);
1408 + print_uint(PRINT_JSON, "memlimit", NULL, memlimit);
1409 + print_string(PRINT_FP, NULL, "memlimit %s",
1410 + sprint_size(memlimit, b1));
1416 +static void cake_print_json_tin(struct rtattr **tstat)
1418 +#define PRINT_TSTAT_JSON(type, name, attr) if (tstat[TCA_CAKE_TIN_STATS_ ## attr]) \
1419 + print_u64(PRINT_JSON, name, NULL, \
1420 + rta_getattr_ ## type((struct rtattr *) \
1421 + tstat[TCA_CAKE_TIN_STATS_ ## attr]))
1423 + open_json_object(NULL);
1424 + PRINT_TSTAT_JSON(u64, "threshold_rate", THRESHOLD_RATE64);
1425 + PRINT_TSTAT_JSON(u64, "sent_bytes", SENT_BYTES64);
1426 + PRINT_TSTAT_JSON(u32, "backlog_bytes", BACKLOG_BYTES);
1427 + PRINT_TSTAT_JSON(u32, "target_us", TARGET_US);
1428 + PRINT_TSTAT_JSON(u32, "interval_us", INTERVAL_US);
1429 + PRINT_TSTAT_JSON(u32, "peak_delay_us", PEAK_DELAY_US);
1430 + PRINT_TSTAT_JSON(u32, "avg_delay_us", AVG_DELAY_US);
1431 + PRINT_TSTAT_JSON(u32, "base_delay_us", BASE_DELAY_US);
1432 + PRINT_TSTAT_JSON(u32, "sent_packets", SENT_PACKETS);
1433 + PRINT_TSTAT_JSON(u32, "way_indirect_hits", WAY_INDIRECT_HITS);
1434 + PRINT_TSTAT_JSON(u32, "way_misses", WAY_MISSES);
1435 + PRINT_TSTAT_JSON(u32, "way_collisions", WAY_COLLISIONS);
1436 + PRINT_TSTAT_JSON(u32, "drops", DROPPED_PACKETS);
1437 + PRINT_TSTAT_JSON(u32, "ecn_mark", ECN_MARKED_PACKETS);
1438 + PRINT_TSTAT_JSON(u32, "ack_drops", ACKS_DROPPED_PACKETS);
1439 + PRINT_TSTAT_JSON(u32, "sparse_flows", SPARSE_FLOWS);
1440 + PRINT_TSTAT_JSON(u32, "bulk_flows", BULK_FLOWS);
1441 + PRINT_TSTAT_JSON(u32, "unresponsive_flows", UNRESPONSIVE_FLOWS);
1442 + PRINT_TSTAT_JSON(u32, "max_pkt_len", MAX_SKBLEN);
1443 + PRINT_TSTAT_JSON(u32, "flow_quantum", FLOW_QUANTUM);
1444 + close_json_object();
1446 +#undef PRINT_TSTAT_JSON
1449 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
1450 + struct rtattr *xstats)
1452 + struct rtattr *st[TCA_CAKE_STATS_MAX + 1];
1456 + if (xstats == NULL)
1459 +#define GET_STAT_U32(attr) rta_getattr_u32(st[TCA_CAKE_STATS_ ## attr])
1460 +#define GET_STAT_S32(attr) (*(__s32 *)RTA_DATA(st[TCA_CAKE_STATS_ ## attr]))
1461 +#define GET_STAT_U64(attr) rta_getattr_u64(st[TCA_CAKE_STATS_ ## attr])
1463 + parse_rtattr_nested(st, TCA_CAKE_STATS_MAX, xstats);
1465 + if (st[TCA_CAKE_STATS_MEMORY_USED] &&
1466 + st[TCA_CAKE_STATS_MEMORY_LIMIT]) {
1467 + print_string(PRINT_FP, NULL, " memory used: %s",
1468 + sprint_size(GET_STAT_U32(MEMORY_USED), b1));
1470 + print_string(PRINT_FP, NULL, " of %s\n",
1471 + sprint_size(GET_STAT_U32(MEMORY_LIMIT), b1));
1473 + print_uint(PRINT_JSON, "memory_used", NULL,
1474 + GET_STAT_U32(MEMORY_USED));
1475 + print_uint(PRINT_JSON, "memory_limit", NULL,
1476 + GET_STAT_U32(MEMORY_LIMIT));
1479 + if (st[TCA_CAKE_STATS_CAPACITY_ESTIMATE64]) {
1480 + print_string(PRINT_FP, NULL, " capacity estimate: %s\n",
1481 + sprint_rate(GET_STAT_U64(CAPACITY_ESTIMATE64), b1));
1482 + print_uint(PRINT_JSON, "capacity_estimate", NULL,
1483 + GET_STAT_U64(CAPACITY_ESTIMATE64));
1486 + if (st[TCA_CAKE_STATS_MIN_NETLEN] &&
1487 + st[TCA_CAKE_STATS_MAX_NETLEN]) {
1488 + print_uint(PRINT_ANY, "min_network_size",
1489 + " min/max network layer size: %12u",
1490 + GET_STAT_U32(MIN_NETLEN));
1491 + print_uint(PRINT_ANY, "max_network_size",
1492 + " /%8u\n", GET_STAT_U32(MAX_NETLEN));
1495 + if (st[TCA_CAKE_STATS_MIN_ADJLEN] &&
1496 + st[TCA_CAKE_STATS_MAX_ADJLEN]) {
1497 + print_uint(PRINT_ANY, "min_adj_size",
1498 + " min/max overhead-adjusted size: %8u",
1499 + GET_STAT_U32(MIN_ADJLEN));
1500 + print_uint(PRINT_ANY, "max_adj_size",
1501 + " /%8u\n", GET_STAT_U32(MAX_ADJLEN));
1504 + if (st[TCA_CAKE_STATS_AVG_NETOFF])
1505 + print_uint(PRINT_ANY, "avg_hdr_offset",
1506 + " average network hdr offset: %12u\n\n",
1507 + GET_STAT_U32(AVG_NETOFF));
1510 + if (st[TCA_CAKE_STATS_DEFICIT])
1511 + print_int(PRINT_ANY, "deficit", " deficit %u",
1512 + GET_STAT_S32(DEFICIT));
1513 + if (st[TCA_CAKE_STATS_COBALT_COUNT])
1514 + print_uint(PRINT_ANY, "count", " count %u",
1515 + GET_STAT_U32(COBALT_COUNT));
1517 + if (st[TCA_CAKE_STATS_DROPPING] && GET_STAT_U32(DROPPING)) {
1518 + print_bool(PRINT_ANY, "dropping", " dropping", true);
1519 + if (st[TCA_CAKE_STATS_DROP_NEXT_US]) {
1520 + int drop_next = GET_STAT_S32(DROP_NEXT_US);
1522 + if (drop_next < 0) {
1523 + print_string(PRINT_FP, NULL, " drop_next -%s",
1524 + sprint_time(drop_next, b1));
1526 + print_uint(PRINT_JSON, "drop_next", NULL,
1528 + print_string(PRINT_FP, NULL, " drop_next %s",
1529 + sprint_time(drop_next, b1));
1534 + if (st[TCA_CAKE_STATS_P_DROP]) {
1535 + print_uint(PRINT_ANY, "blue_prob", " blue_prob %u",
1536 + GET_STAT_U32(P_DROP));
1537 + if (st[TCA_CAKE_STATS_BLUE_TIMER_US]) {
1538 + int blue_timer = GET_STAT_S32(BLUE_TIMER_US);
1540 + if (blue_timer < 0) {
1541 + print_string(PRINT_FP, NULL, " blue_timer -%s",
1542 + sprint_time(blue_timer, b1));
1544 + print_uint(PRINT_JSON, "blue_timer", NULL,
1546 + print_string(PRINT_FP, NULL, " blue_timer %s",
1547 + sprint_time(blue_timer, b1));
1552 +#undef GET_STAT_U32
1553 +#undef GET_STAT_S32
1554 +#undef GET_STAT_U64
1556 + if (st[TCA_CAKE_STATS_TIN_STATS]) {
1557 + struct rtattr *tstat[TC_CAKE_MAX_TINS][TCA_CAKE_TIN_STATS_MAX + 1];
1558 + struct rtattr *tins[TC_CAKE_MAX_TINS + 1];
1561 + parse_rtattr_nested(tins, TC_CAKE_MAX_TINS,
1562 + st[TCA_CAKE_STATS_TIN_STATS]);
1564 + for (i = 1; i <= TC_CAKE_MAX_TINS && tins[i]; i++) {
1565 + parse_rtattr_nested(tstat[i-1], TCA_CAKE_TIN_STATS_MAX,
1573 + if (is_json_context()) {
1574 + open_json_array(PRINT_JSON, "tins");
1575 + for (i = 0; i < num_tins; i++)
1576 + cake_print_json_tin(tstat[i]);
1577 + close_json_array(PRINT_JSON, NULL);
1583 + switch (num_tins) {
1585 + fprintf(f, " Bulk Best Effort Voice\n");
1589 + fprintf(f, " Bulk Best Effort Video Voice\n");
1594 + for (i = 0; i < num_tins; i++)
1595 + fprintf(f, " Tin %u", i);
1599 +#define GET_TSTAT(i, attr) (tstat[i][TCA_CAKE_TIN_STATS_ ## attr])
1600 +#define PRINT_TSTAT(name, attr, fmts, val) do { \
1601 + if (GET_TSTAT(0, attr)) { \
1602 + fprintf(f, name); \
1603 + for (i = 0; i < num_tins; i++) \
1604 + fprintf(f, " %12" fmts, val); \
1605 + fprintf(f, "\n"); \
1609 +#define SPRINT_TSTAT(pfunc, type, name, attr) PRINT_TSTAT( \
1610 + name, attr, "s", sprint_ ## pfunc( \
1611 + rta_getattr_ ## type(GET_TSTAT(i, attr)), b1))
1613 +#define PRINT_TSTAT_U32(name, attr) PRINT_TSTAT( \
1614 + name, attr, "u", rta_getattr_u32(GET_TSTAT(i, attr)))
1616 +#define PRINT_TSTAT_U64(name, attr) PRINT_TSTAT( \
1617 + name, attr, "llu", rta_getattr_u64(GET_TSTAT(i, attr)))
1619 + SPRINT_TSTAT(rate, u64, " thresh ", THRESHOLD_RATE64);
1620 + SPRINT_TSTAT(time, u32, " target ", TARGET_US);
1621 + SPRINT_TSTAT(time, u32, " interval", INTERVAL_US);
1622 + SPRINT_TSTAT(time, u32, " pk_delay", PEAK_DELAY_US);
1623 + SPRINT_TSTAT(time, u32, " av_delay", AVG_DELAY_US);
1624 + SPRINT_TSTAT(time, u32, " sp_delay", BASE_DELAY_US);
1625 + SPRINT_TSTAT(size, u32, " backlog ", BACKLOG_BYTES);
1627 + PRINT_TSTAT_U32(" pkts ", SENT_PACKETS);
1628 + PRINT_TSTAT_U64(" bytes ", SENT_BYTES64);
1630 + PRINT_TSTAT_U32(" way_inds", WAY_INDIRECT_HITS);
1631 + PRINT_TSTAT_U32(" way_miss", WAY_MISSES);
1632 + PRINT_TSTAT_U32(" way_cols", WAY_COLLISIONS);
1633 + PRINT_TSTAT_U32(" drops ", DROPPED_PACKETS);
1634 + PRINT_TSTAT_U32(" marks ", ECN_MARKED_PACKETS);
1635 + PRINT_TSTAT_U32(" ack_drop", ACKS_DROPPED_PACKETS);
1636 + PRINT_TSTAT_U32(" sp_flows", SPARSE_FLOWS);
1637 + PRINT_TSTAT_U32(" bk_flows", BULK_FLOWS);
1638 + PRINT_TSTAT_U32(" un_flows", UNRESPONSIVE_FLOWS);
1639 + PRINT_TSTAT_U32(" max_len ", MAX_SKBLEN);
1640 + PRINT_TSTAT_U32(" quantum ", FLOW_QUANTUM);
1644 +#undef SPRINT_TSTAT
1645 +#undef PRINT_TSTAT_U32
1646 +#undef PRINT_TSTAT_U64
1651 +struct qdisc_util cake_qdisc_util = {
1653 + .parse_qopt = cake_parse_opt,
1654 + .print_qopt = cake_print_opt,
1655 + .print_xstats = cake_print_xstats,