1 --- a/include/uapi/linux/pkt_sched.h
2 +++ b/include/uapi/linux/pkt_sched.h
3 @@ -934,4 +934,75 @@ enum {
5 #define TCA_CBS_MAX (__TCA_CBS_MAX - 1)
11 + TCA_CAKE_DIFFSERV_MODE,
20 + TCA_CAKE_RAW, // was _ETHERNET
24 + TCA_CAKE_ACK_FILTER,
27 +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
29 +struct tc_cake_traffic_stats {
35 +#define TC_CAKE_MAX_TINS (8)
36 +struct tc_cake_tin_stats {
38 + __u32 threshold_rate;
40 + struct tc_cake_traffic_stats sent;
41 + struct tc_cake_traffic_stats dropped;
42 + struct tc_cake_traffic_stats ecn_marked;
43 + struct tc_cake_traffic_stats backlog;
45 + __u32 way_indirect_hits;
47 + __u32 way_collisions;
48 + __u32 peak_delay_us; /* ~= bulk flow delay */
49 + __u32 avge_delay_us;
50 + __u32 base_delay_us; /* ~= sparse flows delay */
53 + __u16 unresponse_flows;
56 + struct tc_cake_traffic_stats ack_drops;
59 +struct tc_cake_xstats {
61 + __u16 tin_stats_size; /* == sizeof(struct tc_cake_tin_stats) */
62 + __u32 capacity_estimate;
75 + struct tc_cake_tin_stats tin_stats[0]; /* keep last */
80 +++ b/man/man8/tc-cake.8
82 +.TH CAKE 8 "23 November 2017" "iproute2" "Linux"
84 +CAKE \- COMMON Applications Kept Enhanced (CAKE)
161 +.BR ack-filter-aggressive
200 +CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline
201 +which uses both AQM and FQ. It combines COBALT, which is an AQM algorithm
202 +combining Codel and BLUE, a shaper which operates in deficit mode, and a variant
203 +of DRR++ for flow isolation. 8-way set-associative hashing is used to virtually
204 +eliminate hash collisions. Priority queuing is available through a simplified
205 +diffserv implementation. Overhead compensation for various encapsulation
206 +schemes is tightly integrated.
208 +All settings are optional; the default settings are chosen to be sensible in
209 +most common deployments. Most people will only need to set the
211 +parameter to get useful results, but reading the
212 +.B Overhead Compensation
215 +sections is strongly encouraged.
217 +.SH SHAPER PARAMETERS
218 +CAKE uses a deficit-mode shaper, which does not exhibit the initial burst
219 +typical of token-bucket shapers. It will automatically burst precisely as much
220 +as required to maintain the configured throughput. As such, it is very
221 +straightforward to configure.
226 + No limit on the bandwidth.
231 + Set the shaper bandwidth. See
233 +or examples below for details of the RATE value.
237 + Automatic capacity estimation based on traffic arriving at this qdisc.
238 +This is most likely to be useful with cellular links, which tend to change
241 +parameter can be used in conjunction to specify an initial estimate. The shaper
242 +will periodically be set to a bandwidth slightly below the estimated rate. This
243 +estimator cannot estimate the bandwidth of links downstream of itself.
245 +.SH OVERHEAD COMPENSATION PARAMETERS
246 +The size of each packet on the wire may differ from that seen by Linux. The
247 +following parameters allow CAKE to compensate for this difference by internally
248 +considering each packet to be bigger than Linux informs it. To assist users who
249 +are not expert network engineers, keywords have been provided to represent a
250 +number of common link technologies.
252 +.SS Manual Overhead Specification
256 + Adds BYTES to the size of each packet. BYTES may be negative; values
257 +between -64 and 256 (inclusive) are accepted.
262 + Rounds each packet (including overhead) up to a minimum length
263 +BYTES. BYTES may not be negative; values between 0 and 256 (inclusive)
268 + Compensates for ATM cell framing, which is normally found on ADSL links.
269 +This is performed after the
271 +parameter above. ATM uses fixed 53-byte cells, each of which can carry 48 bytes
276 + Compensates for PTM encoding, which is normally found on VDSL2 links and
277 +uses a 64b/65b encoding scheme. It is even more efficient to simply
278 +derate the specified shaper bandwidth by a factor of 64/65 or 0.984. See
279 +ITU G.992.3 Annex N and IEEE 802.3 Section 61.3 for details.
283 + Disables ATM and PTM compensation.
285 +.SS Failsafe Overhead Keywords
286 +These two keywords are provided for quick-and-dirty setup. Use them if you
287 +can't be bothered to read the rest of this section.
292 + Turns off all overhead compensation in CAKE. The packet size reported
293 +by Linux will be used directly.
295 + Other overhead keywords may be added after "raw". The effect of this is
296 +to make the overhead compensation operate relative to the reported packet size,
297 +not the underlying IP packet size.
301 + Compensates for more overhead than is likely to occur on any
302 +widely-deployed link technology.
307 +.SS ADSL Overhead Keywords
308 +Most ADSL modems have a way to check which framing scheme is in use. Often this
309 +is also specified in the settings document provided by the ISP. The keywords in
310 +this section are intended to correspond with these sources of information. All
311 +of them implicitly set the
355 +See also the Ethernet Correction Factors section below.
357 +.SS VDSL2 Overhead Keywords
358 +ATM was dropped from VDSL2 in favour of PTM, which is a much more
359 +straightforward framing scheme. Some ISPs retained PPPoE for compatibility with
360 +their existing back-end systems.
368 + PPPoE: 2B PPP + 6B PPPoE +
370 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
372 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
380 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
382 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
385 +See also the Ethernet Correction Factors section below.
387 +.SS DOCSIS Cable Overhead Keyword
388 +DOCSIS is the universal standard for providing Internet service over cable-TV
391 +In this case, the actual on-wire overhead is less important than the packet size
392 +the head-end equipment uses for shaping and metering. This is specified to be
393 +an Ethernet frame including the CRC (aka FCS).
398 +.B overhead 18 mpu 64 noatm
400 +.SS Ethernet Overhead Keywords
404 + Accounts for Ethernet's preamble, inter-frame gap, and Frame Check
405 +Sequence. Use this keyword when the bottleneck being shaped for is an
406 +actual Ethernet cable.
409 +.B overhead 38 mpu 84 noatm
413 + Adds 4 bytes to the overhead compensation, accounting for an IEEE 802.1Q
414 +VLAN header appended to the Ethernet frame header. NB: Some ISPs use one or
415 +even two of these within PPPoE; this keyword may be repeated as necessary to
418 +.SH ROUND TRIP TIME PARAMETERS
419 +Active Queue Management (AQM) consists of embedding congestion signals in the
420 +packet flow, which receivers use to instruct senders to slow down when the queue
421 +is persistently occupied. CAKE uses ECN signalling when available, and packet
422 +drops otherwise, according to a combination of the Codel and BLUE AQM algorithms
425 +Very short latencies require a very rapid AQM response to adequately control
426 +latency. However, such a rapid response tends to impair throughput when the
427 +actual RTT is relatively long. CAKE allows specifying the RTT it assumes for
428 +tuning various parameters. Actual RTTs within an order of magnitude of this
429 +will generally work well for both throughput and latency management.
431 +At the 'lan' setting and below, the time constants are similar in magnitude to
432 +the jitter in the Linux kernel itself, so congestion might be signalled
433 +prematurely. The flows will then become sparse and total throughput reduced,
434 +leaving little or no back-pressure for the fairness logic to work against. Use
435 +the "metro" setting for local lans unless you have a custom kernel.
440 + Manually specify an RTT.
444 + For extremely high-performance 10GigE+ networks only. Equivalent to
449 + For pure Ethernet (not Wi-Fi) networks, at home or in the office. Don't
450 +use this when shaping for an Internet access link. Equivalent to
455 + For traffic mostly within a single city. Equivalent to
460 + For traffic mostly within a European-sized country. Equivalent to
466 + This is suitable for most Internet traffic. Equivalent to
471 + For Internet traffic with generally above-average latency, such as that
472 +suffered by Australasian residents. Equivalent to
477 + For traffic via geostationary satellites. Equivalent to
482 + So named because Jupiter is about 1 light-hour from Earth. Use this to
483 +(almost) completely disable AQM actions. Equivalent to
486 +.SH FLOW ISOLATION PARAMETERS
487 +With flow isolation enabled, CAKE places packets from different flows into
488 +different queues, each of which carries its own AQM state. Packets from each
489 +queue are then delivered fairly, according to a DRR++ algorithm which minimises
490 +latency for "sparse" flows. CAKE uses a set-associative hashing algorithm to
491 +minimise flow collisions.
493 +These keywords specify whether fairness based on source address, destination
494 +address, individual flows, or any combination of those is desired.
498 + Disables flow isolation; all traffic passes through a single queue for
503 + Flows are defined only by source address. Could be useful on the egress
504 +path of an ISP backhaul.
508 + Flows are defined only by destination address. Could be useful on the
509 +ingress path of an ISP backhaul.
513 + Flows are defined by source-destination host pairs. This is host
514 +isolation, rather than flow isolation.
518 + Flows are defined by the entire 5-tuple of source address, destination
519 +address, transport protocol, source port and destination port. This is the type
520 +of flow isolation performed by SFQ and fq_codel.
524 + Flows are defined by the 5-tuple, and fairness is applied first over
525 +source addresses, then over individual flows. Good for use on egress traffic
526 +from a LAN to the internet, where it'll prevent any one LAN host from
527 +monopolising the uplink, regardless of the number of flows they use.
531 + Flows are defined by the 5-tuple, and fairness is applied first over
532 +destination addresses, then over individual flows. Good for use on ingress
533 +traffic to a LAN from the internet, where it'll prevent any one LAN host from
534 +monopolising the downlink, regardless of the number of flows they use.
539 + Flows are defined by the 5-tuple, and fairness is applied over source
540 +*and* destination addresses intelligently (ie. not merely by host-pairs), and
541 +also over individual flows. Use this if you're not certain whether to use
542 +dual-srchost or dual-dsthost; it'll do both jobs at once, preventing any one
543 +host on *either* side of the link from monopolising it with a large number of
548 + Instructs Cake to perform a NAT lookup before applying flow-isolation
549 +rules, to determine the true addresses and port numbers of the packet, to
550 +improve fairness between hosts "inside" the NAT. This has no practical effect
551 +in "flowblind" or "flows" modes, or if NAT is performed on a different host.
556 + Cake will not perform a NAT lookup. Flow isolation will be performed
557 +using the addresses and port numbers directly visible to the interface Cake is
560 +.SH PRIORITY QUEUE PARAMETERS
561 +CAKE can divide traffic into "tins" based on the Diffserv field. Each tin has
562 +its own independent set of flow-isolation queues, and is serviced based on a WRR
563 +algorithm. To avoid perverse Diffserv marking incentives, tin weights have a
564 +"priority sharing" value when bandwidth used by that tin is below a threshold,
565 +and a lower "bandwidth sharing" value when above. Bandwidth is compared against
566 +the threshold using the same algorithm as the deficit-mode shaper.
568 +Detailed customisation of tin parameters is not provided. The following presets
569 +perform all necessary tuning, relative to the current shaper bandwidth and RTT
574 + Disables priority queuing by placing all traffic in one tin.
578 + Enables legacy interpretation of TOS "Precedence" field. Use of this
579 +preset on the modern Internet is firmly discouraged.
583 + Provides a "Latency-Loss Tradeoff" implementation with five tins:
585 + Low Loss (TOS1, TOS2), 100% threshold, increased Codel target.
587 + Best Effort (general), 100% threshold, normal Codel target & interval.
589 + Low Latency (TOS4, TOS5, VA, EF), 100% threshold, reduced Codel interval.
591 + Bulk (CS1), 6.25% threshold, normal Codel target & interval.
593 + Net Control (CS6, CS7), 6.25% threshold, increased Codel target & interval.
597 + Provides a general-purpose Diffserv implementation with four tins:
599 + Bulk (CS1), 6.25% threshold, generally low priority.
601 + Best Effort (general), 100% threshold.
603 + Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, TOS1), 50% threshold.
605 + Voice (CS7, CS6, EF, VA, CS5, CS4), 25% threshold.
610 + Provides a simple, general-purpose Diffserv implementation with three tins:
612 + Bulk (CS1), 6.25% threshold, generally low priority.
614 + Best Effort (general), 100% threshold.
616 + Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
618 +.SH OTHER PARAMETERS
622 + Limit the memory consumed by Cake to LIMIT bytes. Note that this does
623 +not translate directly to queue size (so do not size this based on bandwidth
624 +delay product considerations, but rather on worst case acceptable memory
625 +consumption), as there is some overhead in the data structures containing the
626 +packets, especially for small packets.
628 + By default, the limit is calculated based on the bandwidth and RTT
635 + Traffic entering your diffserv domain is frequently mis-marked in
636 +transit from the perspective of your network, and traffic exiting yours may be
637 +mis-marked from the perspective of the transiting provider.
639 +Apply the wash option to clear all extra diffserv (but not ECN bits), after
640 +priority queuing has taken place.
642 +If you are shaping inbound, and cannot trust the diffserv markings (as is the
643 +case for Comcast Cable, among others), it is best to use a single queue
644 +"besteffort" mode with wash.
647 +# tc qdisc delete root dev eth0
649 +# tc qdisc add root dev eth0 cake bandwidth 9500Kbit pppoe-ptm ether-vlan
651 +# tc -s qdisc show dev eth0
653 +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
654 + Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
655 + backlog 0b 0p requeues 0
656 + memory used: 0b of 4Mb
657 + capacity estimate: 9500Kbit
659 + Bulk Best Effort Voice
661 + thresh 593744bit 9500Kbit 2375Kbit
663 + target 30.6ms 5.0ms 7.6ms
665 + interval 125.6ms 100.0ms 102.6ms
667 + pk_delay 0us 0us 0us
669 + av_delay 0us 0us 0us
671 + sp_delay 0us 0us 0us
700 +# tc -s qdisc show dev eth0
702 +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
703 + Sent 110769306 bytes 313857 pkt (dropped 18, overlimits 741791 requeues 0)
704 + backlog 0b 0p requeues 0
705 + memory used: 110488b of 4Mb
706 + capacity estimate: 9500Kbit
708 + Bulk Best Effort Voice
710 + thresh 593744bit 9500Kbit 2375Kbit
712 + target 30.6ms 5.0ms 7.6ms
714 + interval 125.6ms 100.0ms 102.6ms
716 + pk_delay 16.0ms 545us 15us
718 + av_delay 2.4ms 161us 3us
720 + sp_delay 59us 1us 1us
722 + pkts 32866 195815 85194
724 + bytes 8132614 69517496 33122156
744 + max_len 3028 3012 3028
750 +.BR tc-fq_codel (8),
754 +Cake's principal author is Jonathan Morton, with contributions from
755 +Tony Ambardar, Kevin Darbyshire-Bryant, Toke Høiland-Jørgensen,
756 +Sebastian Moeller, Ryan Mounce, Dean Scarff, Nils Andreas Svee, and Dave Täht.
758 +This manual page was written by Loganaden Velvindron. Please report corrections
759 +to the Linux Networking mailing list <netdev@vger.kernel.org>.
762 @@ -64,6 +64,7 @@ TCMODULES += em_meta.o
763 TCMODULES += q_mqprio.o
764 TCMODULES += q_codel.o
765 TCMODULES += q_fq_codel.o
766 +TCMODULES += q_cake.o
773 +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
775 + * Common Applications Kept Enhanced -- CAKE
777 + * Copyright (C) 2014-2018 Jonathan Morton <chromatix99@gmail.com>
778 + * Copyright (C) 2017-2018 Toke Høiland-Jørgensen <toke@toke.dk>
780 + * Redistribution and use in source and binary forms, with or without
781 + * modification, are permitted provided that the following conditions
783 + * 1. Redistributions of source code must retain the above copyright
784 + * notice, this list of conditions, and the following disclaimer,
785 + * without modification.
786 + * 2. Redistributions in binary form must reproduce the above copyright
787 + * notice, this list of conditions and the following disclaimer in the
788 + * documentation and/or other materials provided with the distribution.
789 + * 3. The names of the authors may not be used to endorse or promote products
790 + * derived from this software without specific prior written permission.
792 + * Alternatively, provided that this notice is retained in full, this
793 + * software may be distributed under the terms of the GNU General
794 + * Public License ("GPL") version 2, in which case the provisions of the
795 + * GPL apply INSTEAD OF those given above.
797 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
798 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
799 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
800 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
801 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
802 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
803 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
804 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
805 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
806 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
807 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
818 +#include <sys/socket.h>
819 +#include <netinet/in.h>
820 +#include <arpa/inet.h>
824 +#include "tc_util.h"
826 +static void explain(void)
829 +"Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
830 +" [ rtt TIME | datacentre | lan | metro | regional |\n"
831 +" internet* | oceanic | satellite | interplanetary ]\n"
832 +" [ besteffort | diffserv8 | diffserv4 | diffserv-llt |\n"
834 +" [ flowblind | srchost | dsthost | hosts | flows |\n"
835 +" dual-srchost | dual-dsthost | triple-isolate* ]\n"
836 +" [ nat | nonat* ]\n"
837 +" [ wash | nowash* ]\n"
838 +" [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
839 +" [ memlimit LIMIT ]\n"
840 +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
841 +" [ mpu N ] [ ingress | egress* ]\n"
842 +" (* marks defaults)\n");
845 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
846 + struct nlmsghdr *n, const char *dev)
849 + unsigned bandwidth = 0;
850 + unsigned interval = 0;
851 + unsigned target = 0;
852 + unsigned diffserv = 0;
853 + unsigned memlimit = 0;
855 + bool overhead_set = false;
856 + bool overhead_override = false;
864 + int ack_filter = -1;
865 + struct rtattr *tail;
868 + if (strcmp(*argv, "bandwidth") == 0) {
870 + if (get_rate(&bandwidth, *argv)) {
871 + fprintf(stderr, "Illegal \"bandwidth\"\n");
876 + } else if (strcmp(*argv, "unlimited") == 0) {
880 + } else if (strcmp(*argv, "autorate_ingress") == 0) {
883 + } else if (strcmp(*argv, "rtt") == 0) {
885 + if (get_time(&interval, *argv)) {
886 + fprintf(stderr, "Illegal \"rtt\"\n");
889 + target = interval / 20;
892 + } else if (strcmp(*argv, "datacentre") == 0) {
895 + } else if (strcmp(*argv, "lan") == 0) {
898 + } else if (strcmp(*argv, "metro") == 0) {
901 + } else if (strcmp(*argv, "regional") == 0) {
904 + } else if (strcmp(*argv, "internet") == 0) {
907 + } else if (strcmp(*argv, "oceanic") == 0) {
910 + } else if (strcmp(*argv, "satellite") == 0) {
911 + interval = 1000000;
913 + } else if (strcmp(*argv, "interplanetary") == 0) {
914 + interval = 1000000000;
917 + } else if (strcmp(*argv, "besteffort") == 0) {
919 + } else if (strcmp(*argv, "precedence") == 0) {
921 + } else if (strcmp(*argv, "diffserv8") == 0) {
923 + } else if (strcmp(*argv, "diffserv4") == 0) {
925 + } else if (strcmp(*argv, "diffserv") == 0) {
927 + } else if (strcmp(*argv, "diffserv-llt") == 0) {
929 + } else if (strcmp(*argv, "diffserv3") == 0) {
932 + } else if (strcmp(*argv, "nowash") == 0) {
934 + } else if (strcmp(*argv, "wash") == 0) {
937 + } else if (strcmp(*argv, "flowblind") == 0) {
939 + } else if (strcmp(*argv, "srchost") == 0) {
941 + } else if (strcmp(*argv, "dsthost") == 0) {
943 + } else if (strcmp(*argv, "hosts") == 0) {
945 + } else if (strcmp(*argv, "flows") == 0) {
947 + } else if (strcmp(*argv, "dual-srchost") == 0) {
949 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
951 + } else if (strcmp(*argv, "triple-isolate") == 0) {
954 + } else if (strcmp(*argv, "nat") == 0) {
956 + } else if (strcmp(*argv, "nonat") == 0) {
959 + } else if (strcmp(*argv, "ptm") == 0) {
961 + } else if (strcmp(*argv, "atm") == 0) {
963 + } else if (strcmp(*argv, "noatm") == 0) {
966 + } else if (strcmp(*argv, "raw") == 0) {
969 + overhead_set = true;
970 + overhead_override = true;
971 + } else if (strcmp(*argv, "conservative") == 0) {
973 + * Deliberately over-estimate overhead:
974 + * one whole ATM cell plus ATM framing.
975 + * A safe choice if the actual overhead is unknown.
979 + overhead_set = true;
981 + /* Various ADSL framing schemes, all over ATM cells */
982 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
985 + overhead_set = true;
986 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
989 + overhead_set = true;
990 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
993 + overhead_set = true;
994 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
997 + overhead_set = true;
998 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
1001 + overhead_set = true;
1002 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
1005 + overhead_set = true;
1006 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
1009 + overhead_set = true;
1010 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
1013 + overhead_set = true;
1015 + /* Typical VDSL2 framing schemes, both over PTM */
1016 + /* PTM has 64b/65b coding which absorbs some bandwidth */
1017 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
1018 + /* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
1019 + * + 2B ethertype + 4B Frame Check Sequence
1020 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1021 + * + 2B TC-CRC (PTM-FCS) = 30B
1025 + overhead_set = true;
1026 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
1027 + /* 6B dest MAC + 6B src MAC + 2B ethertype
1028 + * + 4B Frame Check Sequence
1029 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1030 + * + 2B TC-CRC (PTM-FCS) = 22B
1034 + overhead_set = true;
1036 + } else if (strcmp(*argv, "via-ethernet") == 0) {
1038 + * We used to use this flag to manually compensate for
1039 + * Linux including the Ethernet header on Ethernet-type
1040 + * interfaces, but not on IP-type interfaces.
1042 + * It is no longer needed, because Cake now adjusts for
1043 + * that automatically, and is thus ignored.
1045 + * It would be deleted entirely, but it appears in the
1046 + * stats output when the automatic compensation is
1050 + } else if (strcmp(*argv, "ethernet") == 0) {
1051 + /* ethernet pre-amble & interframe gap & FCS
1052 + * you may need to add vlan tag */
1054 + overhead_set = true;
1057 + /* Additional Ethernet-related overhead used by some ISPs */
1058 + } else if (strcmp(*argv, "ether-vlan") == 0) {
1059 + /* 802.1q VLAN tag - may be repeated */
1061 + overhead_set = true;
1064 + * DOCSIS cable shapers account for Ethernet frame with FCS,
1065 + * but not interframe gap or preamble.
1067 + } else if (strcmp(*argv, "docsis") == 0) {
1070 + overhead_set = true;
1073 + } else if (strcmp(*argv, "overhead") == 0) {
1076 + overhead = strtol(*argv, &p, 10);
1077 + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
1078 + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
1081 + overhead_set = true;
1083 + } else if (strcmp(*argv, "mpu") == 0) {
1086 + mpu = strtol(*argv, &p, 10);
1087 + if(!p || *p || !*argv || mpu < 0 || mpu > 256) {
1088 + fprintf(stderr, "Illegal \"mpu\", valid range is 0 to 256\\n");
1092 + } else if (strcmp(*argv, "ingress") == 0) {
1094 + } else if (strcmp(*argv, "egress") == 0) {
1097 + } else if (strcmp(*argv, "no-ack-filter") == 0) {
1099 + } else if (strcmp(*argv, "ack-filter") == 0) {
1100 + ack_filter = 0x0200;
1101 + } else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
1102 + ack_filter = 0x0600;
1104 + } else if (strcmp(*argv, "memlimit") == 0) {
1106 + if(get_size(&memlimit, *argv)) {
1107 + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
1111 + } else if (strcmp(*argv, "help") == 0) {
1115 + fprintf(stderr, "What is \"%s\"?\n", *argv);
1122 + tail = NLMSG_TAIL(n);
1123 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
1124 + if (bandwidth || unlimited)
1125 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth));
1127 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
1129 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
1130 + if (flowmode != -1)
1131 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
1133 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
1134 + if (overhead_override) {
1135 + unsigned zero = 0;
1136 + addattr_l(n, 1024, TCA_CAKE_RAW, &zero, sizeof(zero));
1139 + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
1141 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
1143 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
1144 + if (autorate != -1)
1145 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
1147 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
1149 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
1151 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
1152 + if (ingress != -1)
1153 + addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
1154 + if (ack_filter != -1)
1155 + addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter, sizeof(ack_filter));
1157 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1162 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1164 + struct rtattr *tb[TCA_CAKE_MAX + 1];
1165 + unsigned bandwidth = 0;
1166 + unsigned diffserv = 0;
1167 + unsigned flowmode = 0;
1168 + unsigned interval = 0;
1169 + unsigned memlimit = 0;
1178 + int ack_filter = 0;
1185 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
1187 + if (tb[TCA_CAKE_BASE_RATE] &&
1188 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) {
1189 + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]);
1191 + print_uint(PRINT_JSON, "bandwidth", NULL, bandwidth);
1192 + print_string(PRINT_FP, NULL, "bandwidth %s ", sprint_rate(bandwidth, b1));
1194 + print_string(PRINT_ANY, "bandwidth", "bandwidth %s ", "unlimited");
1196 + if (tb[TCA_CAKE_AUTORATE] &&
1197 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
1198 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
1200 + print_string(PRINT_ANY, "autorate", "autorate_%s ", "ingress");
1202 + print_string(PRINT_ANY, "autorate", "(?autorate?) ", "unknown");
1204 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
1205 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
1206 + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
1207 + switch(diffserv) {
1209 + print_string(PRINT_ANY, "diffserv", "%s ", "besteffort");
1212 + print_string(PRINT_ANY, "diffserv", "%s ", "precedence");
1215 + print_string(PRINT_ANY, "diffserv", "%s ", "diffserv8");
1218 + print_string(PRINT_ANY, "diffserv", "%s ", "diffserv4");
1221 + print_string(PRINT_ANY, "diffserv", "%s ", "diffserv-llt");
1224 + print_string(PRINT_ANY, "diffserv", "%s ", "diffserv3");
1227 + print_string(PRINT_ANY, "diffserv", "(?diffserv?) ", "unknown");
1231 + if (tb[TCA_CAKE_FLOW_MODE] &&
1232 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
1233 + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
1234 + nat = !!(flowmode & 64);
1236 + switch(flowmode) {
1238 + print_string(PRINT_ANY, "flowmode", "%s ", "flowblind");
1241 + print_string(PRINT_ANY, "flowmode", "%s ", "srchost");
1244 + print_string(PRINT_ANY, "flowmode", "%s ", "dsthost");
1247 + print_string(PRINT_ANY, "flowmode", "%s ", "hosts");
1250 + print_string(PRINT_ANY, "flowmode", "%s ", "flows");
1253 + print_string(PRINT_ANY, "flowmode", "%s ", "dual-srchost");
1256 + print_string(PRINT_ANY, "flowmode", "%s ", "dual-dsthost");
1259 + print_string(PRINT_ANY, "flowmode", "%s ", "triple-isolate");
1262 + print_string(PRINT_ANY, "flowmode", "(?flowmode?) ", "unknown");
1267 + print_string(PRINT_FP, NULL, "nat ", NULL);
1268 + print_bool(PRINT_JSON, "nat", NULL, nat);
1270 + if (tb[TCA_CAKE_WASH] &&
1271 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
1272 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
1274 + if (tb[TCA_CAKE_ATM] &&
1275 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
1276 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
1278 + if (tb[TCA_CAKE_OVERHEAD] &&
1279 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__u32)) {
1280 + overhead = rta_getattr_u32(tb[TCA_CAKE_OVERHEAD]);
1282 + if (tb[TCA_CAKE_MPU] &&
1283 + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
1284 + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
1286 + if (tb[TCA_CAKE_INGRESS] &&
1287 + RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
1288 + ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
1290 + if (tb[TCA_CAKE_ACK_FILTER] &&
1291 + RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
1292 + ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
1294 + if (tb[TCA_CAKE_RAW]) {
1297 + if (tb[TCA_CAKE_RTT] &&
1298 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
1299 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
1303 + print_string(PRINT_FP, NULL, "wash ", NULL);
1304 + print_bool(PRINT_JSON, "wash", NULL, wash);
1307 + print_string(PRINT_FP, NULL, "ingress ", NULL);
1308 + print_bool(PRINT_JSON, "ingress", NULL, ingress);
1310 + if (ack_filter == 0x0600)
1311 + print_string(PRINT_ANY, "ack-filter", "ack-filter-%s ", "aggressive");
1312 + else if (ack_filter)
1313 + print_string(PRINT_ANY, "ack-filter", "ack-filter ", "enabled");
1315 + print_string(PRINT_JSON, "ack-filter", NULL, "disabled");
1318 + print_string(PRINT_FP, NULL, "rtt %s ", sprint_time(interval, b2));
1319 + print_uint(PRINT_JSON, "rtt", NULL, interval);
1322 + print_string(PRINT_FP, NULL, "raw ", NULL);
1323 + print_bool(PRINT_JSON, "raw", NULL, raw);
1326 + print_string(PRINT_ANY, "atm", "%s ", "atm");
1327 + else if (atm == 2)
1328 + print_string(PRINT_ANY, "atm", "%s ", "ptm");
1330 + print_string(PRINT_ANY, "atm", "%s ", "noatm");
1332 + print_uint(PRINT_ANY, "overhead", "overhead %d ", overhead);
1335 + print_uint(PRINT_ANY, "mpu", "mpu %d ", mpu);
1338 + print_uint(PRINT_JSON, "memlimit", NULL, memlimit);
1339 + print_string(PRINT_FP, NULL, "memlimit %s", sprint_size(memlimit, b1));
1345 +#define FOR_EACH_TIN(xstats, tst, i) \
1346 + for(tst = xstats->tin_stats, i = 0; \
1347 + i < xstats->tin_cnt; \
1348 + i++, tst = ((void *) xstats->tin_stats) + xstats->tin_stats_size * i)
1350 +static void cake_print_json_tin(struct tc_cake_tin_stats *tst)
1352 + open_json_object(NULL);
1353 + print_uint(PRINT_JSON, "threshold_rate", NULL, tst->threshold_rate);
1354 + print_uint(PRINT_JSON, "target", NULL, tst->target_us);
1355 + print_uint(PRINT_JSON, "interval", NULL, tst->interval_us);
1356 + print_uint(PRINT_JSON, "peak_delay", NULL, tst->peak_delay_us);
1357 + print_uint(PRINT_JSON, "average_delay", NULL, tst->avge_delay_us);
1358 + print_uint(PRINT_JSON, "base_delay", NULL, tst->base_delay_us);
1359 + print_uint(PRINT_JSON, "sent_packets", NULL, tst->sent.packets);
1360 + print_uint(PRINT_JSON, "sent_bytes", NULL, tst->sent.bytes);
1361 + print_uint(PRINT_JSON, "way_indirect_hits", NULL, tst->way_indirect_hits);
1362 + print_uint(PRINT_JSON, "way_misses", NULL, tst->way_misses);
1363 + print_uint(PRINT_JSON, "way_collisions", NULL, tst->way_collisions);
1364 + print_uint(PRINT_JSON, "drops", NULL, tst->dropped.packets);
1365 + print_uint(PRINT_JSON, "ecn_mark", NULL, tst->ecn_marked.packets);
1366 + print_uint(PRINT_JSON, "ack_drops", NULL, tst->ack_drops.packets);
1367 + print_uint(PRINT_JSON, "sparse_flows", NULL, tst->sparse_flows);
1368 + print_uint(PRINT_JSON, "bulk_flows", NULL, tst->bulk_flows);
1369 + print_uint(PRINT_JSON, "unresponsive_flows", NULL, tst->unresponse_flows);
1370 + print_uint(PRINT_JSON, "max_pkt_len", NULL, tst->max_skblen);
1371 + close_json_object();
1374 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
1375 + struct rtattr *xstats)
1377 + struct tc_cake_xstats *stnc;
1378 + struct tc_cake_tin_stats *tst;
1382 + if (xstats == NULL)
1385 + if (RTA_PAYLOAD(xstats) < sizeof(*stnc))
1388 + stnc = RTA_DATA(xstats);
1390 + if (stnc->version < 0x101 ||
1391 + RTA_PAYLOAD(xstats) < (sizeof(struct tc_cake_xstats) +
1392 + stnc->tin_stats_size * stnc->tin_cnt))
1395 + print_uint(PRINT_JSON, "memory_used", NULL, stnc->memory_used);
1396 + print_uint(PRINT_JSON, "memory_limit", NULL, stnc->memory_limit);
1397 + print_uint(PRINT_JSON, "capacity_estimate", NULL, stnc->capacity_estimate);
1399 + print_string(PRINT_FP, NULL, " memory used: %s",
1400 + sprint_size(stnc->memory_used, b1));
1401 + print_string(PRINT_FP, NULL, " of %s\n",
1402 + sprint_size(stnc->memory_limit, b1));
1403 + print_string(PRINT_FP, NULL, " capacity estimate: %s\n",
1404 + sprint_rate(stnc->capacity_estimate, b1));
1406 + print_uint(PRINT_ANY, "min_transport_size", " min/max transport layer size: %10u",
1407 + stnc->min_trnlen);
1408 + print_uint(PRINT_ANY, "max_transport_size", " /%8u\n", stnc->max_trnlen);
1409 + print_uint(PRINT_ANY, "min_adj_size", " min/max overhead-adjusted size: %8u",
1410 + stnc->min_adjlen);
1411 + print_uint(PRINT_ANY, "max_adj_size", " /%8u\n", stnc->max_adjlen);
1412 + print_uint(PRINT_ANY, "avg_hdr_offset", " average transport hdr offset: %10u\n\n",
1413 + stnc->avg_trnoff);
1415 + if (is_json_context()) {
1416 + open_json_array(PRINT_JSON, "tins");
1417 + FOR_EACH_TIN(stnc, tst, i)
1418 + cake_print_json_tin(tst);
1419 + close_json_array(PRINT_JSON, NULL);
1424 + switch(stnc->tin_cnt) {
1426 + fprintf(f, " Bulk Best Effort Voice\n");
1430 + fprintf(f, " Bulk Best Effort Video Voice\n");
1434 + fprintf(f, " Low Loss Best Effort Low Delay Bulk Net Control\n");
1439 + for(i=0; i < stnc->tin_cnt; i++)
1440 + fprintf(f, " Tin %u", i);
1444 + fprintf(f, " thresh ");
1445 + FOR_EACH_TIN(stnc, tst, i)
1446 + fprintf(f, " %12s", sprint_rate(tst->threshold_rate, b1));
1449 + fprintf(f, " target ");
1450 + FOR_EACH_TIN(stnc, tst, i)
1451 + fprintf(f, " %12s", sprint_time(tst->target_us, b1));
1454 + fprintf(f, " interval");
1455 + FOR_EACH_TIN(stnc, tst, i)
1456 + fprintf(f, " %12s", sprint_time(tst->interval_us, b1));
1459 + fprintf(f, " pk_delay");
1460 + FOR_EACH_TIN(stnc, tst, i)
1461 + fprintf(f, " %12s", sprint_time(tst->peak_delay_us, b1));
1464 + fprintf(f, " av_delay");
1465 + FOR_EACH_TIN(stnc, tst, i)
1466 + fprintf(f, " %12s", sprint_time(tst->avge_delay_us, b1));
1469 + fprintf(f, " sp_delay");
1470 + FOR_EACH_TIN(stnc, tst, i)
1471 + fprintf(f, " %12s", sprint_time(tst->base_delay_us, b1));
1474 + fprintf(f, " pkts ");
1475 + FOR_EACH_TIN(stnc, tst, i)
1476 + fprintf(f, " %12u", tst->sent.packets);
1479 + fprintf(f, " bytes ");
1480 + FOR_EACH_TIN(stnc, tst, i)
1481 + fprintf(f, " %12llu", tst->sent.bytes);
1484 + fprintf(f, " way_inds");
1485 + FOR_EACH_TIN(stnc, tst, i)
1486 + fprintf(f, " %12u", tst->way_indirect_hits);
1489 + fprintf(f, " way_miss");
1490 + FOR_EACH_TIN(stnc, tst, i)
1491 + fprintf(f, " %12u", tst->way_misses);
1494 + fprintf(f, " way_cols");
1495 + FOR_EACH_TIN(stnc, tst, i)
1496 + fprintf(f, " %12u", tst->way_collisions);
1499 + fprintf(f, " drops ");
1500 + FOR_EACH_TIN(stnc, tst, i)
1501 + fprintf(f, " %12u", tst->dropped.packets);
1504 + fprintf(f, " marks ");
1505 + FOR_EACH_TIN(stnc, tst, i)
1506 + fprintf(f, " %12u", tst->ecn_marked.packets);
1509 + fprintf(f, " ack_drop");
1510 + FOR_EACH_TIN(stnc, tst, i)
1511 + fprintf(f, " %12u", tst->ack_drops.packets);
1514 + fprintf(f, " sp_flows");
1515 + FOR_EACH_TIN(stnc, tst, i)
1516 + fprintf(f, " %12u", tst->sparse_flows);
1519 + fprintf(f, " bk_flows");
1520 + FOR_EACH_TIN(stnc, tst, i)
1521 + fprintf(f, " %12u", tst->bulk_flows);
1524 + fprintf(f, " un_flows");
1525 + FOR_EACH_TIN(stnc, tst, i)
1526 + fprintf(f, " %12u", tst->unresponse_flows);
1529 + fprintf(f, " max_len ");
1530 + FOR_EACH_TIN(stnc, tst, i)
1531 + fprintf(f, " %12u", tst->max_skblen);
1537 +struct qdisc_util cake_qdisc_util = {
1539 + .parse_qopt = cake_parse_opt,
1540 + .print_qopt = cake_print_opt,
1541 + .print_xstats = cake_print_xstats,