1 --- a/include/linux/pkt_sched.h
2 +++ b/include/linux/pkt_sched.h
3 @@ -852,2 +852,116 @@ enum {
9 + TCA_CAKE_BASE_RATE64,
10 + TCA_CAKE_DIFFSERV_MODE,
19 + TCA_CAKE_RAW, // was _ETHERNET
23 + TCA_CAKE_ACK_FILTER,
27 +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
30 + __TCA_CAKE_STATS_INVALID,
32 + TCA_CAKE_STATS_CAPACITY_ESTIMATE64,
33 + TCA_CAKE_STATS_MEMORY_LIMIT,
34 + TCA_CAKE_STATS_MEMORY_USED,
35 + TCA_CAKE_STATS_AVG_NETOFF,
36 + TCA_CAKE_STATS_MIN_NETLEN,
37 + TCA_CAKE_STATS_MAX_NETLEN,
38 + TCA_CAKE_STATS_MIN_ADJLEN,
39 + TCA_CAKE_STATS_MAX_ADJLEN,
40 + TCA_CAKE_STATS_TIN_STATS,
41 + TCA_CAKE_STATS_DEFICIT,
42 + TCA_CAKE_STATS_COBALT_COUNT,
43 + TCA_CAKE_STATS_DROPPING,
44 + TCA_CAKE_STATS_DROP_NEXT_US,
45 + TCA_CAKE_STATS_P_DROP,
46 + TCA_CAKE_STATS_BLUE_TIMER_US,
47 + __TCA_CAKE_STATS_MAX
49 +#define TCA_CAKE_STATS_MAX (__TCA_CAKE_STATS_MAX - 1)
52 + __TCA_CAKE_TIN_STATS_INVALID,
53 + TCA_CAKE_TIN_STATS_PAD,
54 + TCA_CAKE_TIN_STATS_SENT_PACKETS,
55 + TCA_CAKE_TIN_STATS_SENT_BYTES64,
56 + TCA_CAKE_TIN_STATS_DROPPED_PACKETS,
57 + TCA_CAKE_TIN_STATS_DROPPED_BYTES64,
58 + TCA_CAKE_TIN_STATS_ACKS_DROPPED_PACKETS,
59 + TCA_CAKE_TIN_STATS_ACKS_DROPPED_BYTES64,
60 + TCA_CAKE_TIN_STATS_ECN_MARKED_PACKETS,
61 + TCA_CAKE_TIN_STATS_ECN_MARKED_BYTES64,
62 + TCA_CAKE_TIN_STATS_BACKLOG_PACKETS,
63 + TCA_CAKE_TIN_STATS_BACKLOG_BYTES,
64 + TCA_CAKE_TIN_STATS_THRESHOLD_RATE64,
65 + TCA_CAKE_TIN_STATS_TARGET_US,
66 + TCA_CAKE_TIN_STATS_INTERVAL_US,
67 + TCA_CAKE_TIN_STATS_WAY_INDIRECT_HITS,
68 + TCA_CAKE_TIN_STATS_WAY_MISSES,
69 + TCA_CAKE_TIN_STATS_WAY_COLLISIONS,
70 + TCA_CAKE_TIN_STATS_PEAK_DELAY_US,
71 + TCA_CAKE_TIN_STATS_AVG_DELAY_US,
72 + TCA_CAKE_TIN_STATS_BASE_DELAY_US,
73 + TCA_CAKE_TIN_STATS_SPARSE_FLOWS,
74 + TCA_CAKE_TIN_STATS_BULK_FLOWS,
75 + TCA_CAKE_TIN_STATS_UNRESPONSIVE_FLOWS,
76 + TCA_CAKE_TIN_STATS_MAX_SKBLEN,
77 + TCA_CAKE_TIN_STATS_FLOW_QUANTUM,
78 + __TCA_CAKE_TIN_STATS_MAX
80 +#define TCA_CAKE_TIN_STATS_MAX (__TCA_CAKE_TIN_STATS_MAX - 1)
81 +#define TC_CAKE_MAX_TINS (8)
87 + CAKE_FLOW_HOSTS, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_DST_IP */
89 + CAKE_FLOW_DUAL_SRC, /* = CAKE_FLOW_SRC_IP | CAKE_FLOW_FLOWS */
90 + CAKE_FLOW_DUAL_DST, /* = CAKE_FLOW_DST_IP | CAKE_FLOW_FLOWS */
91 + CAKE_FLOW_TRIPLE, /* = CAKE_FLOW_HOSTS | CAKE_FLOW_FLOWS */
96 + CAKE_DIFFSERV_DIFFSERV3 = 0,
97 + CAKE_DIFFSERV_DIFFSERV4,
98 + CAKE_DIFFSERV_DIFFSERV8,
99 + CAKE_DIFFSERV_BESTEFFORT,
100 + CAKE_DIFFSERV_PRECEDENCE,
107 + CAKE_ACK_AGGRESSIVE,
121 +++ b/man/man8/tc-cake.8
123 +.TH CAKE 8 "23 November 2017" "iproute2" "Linux"
125 +CAKE \- Common Applications Kept Enhanced (CAKE)
127 +.B tc qdisc ... cake
134 +.BR autorate_ingress
200 +.BR ack-filter-aggressive
239 +CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline
240 +which uses both AQM and FQ. It combines COBALT, which is an AQM algorithm
241 +combining Codel and BLUE, a shaper which operates in deficit mode, and a variant
242 +of DRR++ for flow isolation. 8-way set-associative hashing is used to virtually
243 +eliminate hash collisions. Priority queuing is available through a simplified
244 +diffserv implementation. Overhead compensation for various encapsulation
245 +schemes is tightly integrated.
247 +All settings are optional; the default settings are chosen to be sensible in
248 +most common deployments. Most people will only need to set the
250 +parameter to get useful results, but reading the
251 +.B Overhead Compensation
254 +sections is strongly encouraged.
256 +.SH SHAPER PARAMETERS
257 +CAKE uses a deficit-mode shaper, which does not exhibit the initial burst
258 +typical of token-bucket shapers. It will automatically burst precisely as much
259 +as required to maintain the configured throughput. As such, it is very
260 +straightforward to configure.
265 + No limit on the bandwidth.
270 + Set the shaper bandwidth. See
272 +or examples below for details of the RATE value.
276 + Automatic capacity estimation based on traffic arriving at this qdisc.
277 +This is most likely to be useful with cellular links, which tend to change
280 +parameter can be used in conjunction to specify an initial estimate. The shaper
281 +will periodically be set to a bandwidth slightly below the estimated rate. This
282 +estimator cannot estimate the bandwidth of links downstream of itself.
284 +.SH OVERHEAD COMPENSATION PARAMETERS
285 +The size of each packet on the wire may differ from that seen by Linux. The
286 +following parameters allow CAKE to compensate for this difference by internally
287 +considering each packet to be bigger than Linux informs it. To assist users who
288 +are not expert network engineers, keywords have been provided to represent a
289 +number of common link technologies.
291 +.SS Manual Overhead Specification
295 + Adds BYTES to the size of each packet. BYTES may be negative; values
296 +between -64 and 256 (inclusive) are accepted.
301 + Rounds each packet (including overhead) up to a minimum length
302 +BYTES. BYTES may not be negative; values between 0 and 256 (inclusive)
307 + Compensates for ATM cell framing, which is normally found on ADSL links.
308 +This is performed after the
310 +parameter above. ATM uses fixed 53-byte cells, each of which can carry 48 bytes
315 + Compensates for PTM encoding, which is normally found on VDSL2 links and
316 +uses a 64b/65b encoding scheme. It is even more efficient to simply
317 +derate the specified shaper bandwidth by a factor of 64/65 or 0.984. See
318 +ITU G.992.3 Annex N and IEEE 802.3 Section 61.3 for details.
322 + Disables ATM and PTM compensation.
324 +.SS Failsafe Overhead Keywords
325 +These two keywords are provided for quick-and-dirty setup. Use them if you
326 +can't be bothered to read the rest of this section.
331 + Turns off all overhead compensation in CAKE. The packet size reported
332 +by Linux will be used directly.
334 + Other overhead keywords may be added after "raw". The effect of this is
335 +to make the overhead compensation operate relative to the reported packet size,
336 +not the underlying IP packet size.
340 + Compensates for more overhead than is likely to occur on any
341 +widely-deployed link technology.
346 +.SS ADSL Overhead Keywords
347 +Most ADSL modems have a way to check which framing scheme is in use. Often this
348 +is also specified in the settings document provided by the ISP. The keywords in
349 +this section are intended to correspond with these sources of information. All
350 +of them implicitly set the
394 +See also the Ethernet Correction Factors section below.
396 +.SS VDSL2 Overhead Keywords
397 +ATM was dropped from VDSL2 in favour of PTM, which is a much more
398 +straightforward framing scheme. Some ISPs retained PPPoE for compatibility with
399 +their existing back-end systems.
407 + PPPoE: 2B PPP + 6B PPPoE +
409 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
411 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
419 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
421 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
424 +See also the Ethernet Correction Factors section below.
426 +.SS DOCSIS Cable Overhead Keyword
427 +DOCSIS is the universal standard for providing Internet service over cable-TV
430 +In this case, the actual on-wire overhead is less important than the packet size
431 +the head-end equipment uses for shaping and metering. This is specified to be
432 +an Ethernet frame including the CRC (aka FCS).
437 +.B overhead 18 mpu 64 noatm
439 +.SS Ethernet Overhead Keywords
443 + Accounts for Ethernet's preamble, inter-frame gap, and Frame Check
444 +Sequence. Use this keyword when the bottleneck being shaped for is an
445 +actual Ethernet cable.
448 +.B overhead 38 mpu 84 noatm
452 + Adds 4 bytes to the overhead compensation, accounting for an IEEE 802.1Q
453 +VLAN header appended to the Ethernet frame header. NB: Some ISPs use one or
454 +even two of these within PPPoE; this keyword may be repeated as necessary to
457 +.SH ROUND TRIP TIME PARAMETERS
458 +Active Queue Management (AQM) consists of embedding congestion signals in the
459 +packet flow, which receivers use to instruct senders to slow down when the queue
460 +is persistently occupied. CAKE uses ECN signalling when available, and packet
461 +drops otherwise, according to a combination of the Codel and BLUE AQM algorithms
464 +Very short latencies require a very rapid AQM response to adequately control
465 +latency. However, such a rapid response tends to impair throughput when the
466 +actual RTT is relatively long. CAKE allows specifying the RTT it assumes for
467 +tuning various parameters. Actual RTTs within an order of magnitude of this
468 +will generally work well for both throughput and latency management.
470 +At the 'lan' setting and below, the time constants are similar in magnitude to
471 +the jitter in the Linux kernel itself, so congestion might be signalled
472 +prematurely. The flows will then become sparse and total throughput reduced,
473 +leaving little or no back-pressure for the fairness logic to work against. Use
474 +the "metro" setting for local lans unless you have a custom kernel.
479 + Manually specify an RTT.
483 + For extremely high-performance 10GigE+ networks only. Equivalent to
488 + For pure Ethernet (not Wi-Fi) networks, at home or in the office. Don't
489 +use this when shaping for an Internet access link. Equivalent to
494 + For traffic mostly within a single city. Equivalent to
499 + For traffic mostly within a European-sized country. Equivalent to
505 + This is suitable for most Internet traffic. Equivalent to
510 + For Internet traffic with generally above-average latency, such as that
511 +suffered by Australasian residents. Equivalent to
516 + For traffic via geostationary satellites. Equivalent to
521 + So named because Jupiter is about 1 light-hour from Earth. Use this to
522 +(almost) completely disable AQM actions. Equivalent to
525 +.SH FLOW ISOLATION PARAMETERS
526 +With flow isolation enabled, CAKE places packets from different flows into
527 +different queues, each of which carries its own AQM state. Packets from each
528 +queue are then delivered fairly, according to a DRR++ algorithm which minimises
529 +latency for "sparse" flows. CAKE uses a set-associative hashing algorithm to
530 +minimise flow collisions.
532 +These keywords specify whether fairness based on source address, destination
533 +address, individual flows, or any combination of those is desired.
537 + Disables flow isolation; all traffic passes through a single queue for
542 + Flows are defined only by source address. Could be useful on the egress
543 +path of an ISP backhaul.
547 + Flows are defined only by destination address. Could be useful on the
548 +ingress path of an ISP backhaul.
552 + Flows are defined by source-destination host pairs. This is host
553 +isolation, rather than flow isolation.
557 + Flows are defined by the entire 5-tuple of source address, destination
558 +address, transport protocol, source port and destination port. This is the type
559 +of flow isolation performed by SFQ and fq_codel.
563 + Flows are defined by the 5-tuple, and fairness is applied first over
564 +source addresses, then over individual flows. Good for use on egress traffic
565 +from a LAN to the internet, where it'll prevent any one LAN host from
566 +monopolising the uplink, regardless of the number of flows they use.
570 + Flows are defined by the 5-tuple, and fairness is applied first over
571 +destination addresses, then over individual flows. Good for use on ingress
572 +traffic to a LAN from the internet, where it'll prevent any one LAN host from
573 +monopolising the downlink, regardless of the number of flows they use.
578 + Flows are defined by the 5-tuple, and fairness is applied over source
579 +*and* destination addresses intelligently (ie. not merely by host-pairs), and
580 +also over individual flows. Use this if you're not certain whether to use
581 +dual-srchost or dual-dsthost; it'll do both jobs at once, preventing any one
582 +host on *either* side of the link from monopolising it with a large number of
587 + Instructs Cake to perform a NAT lookup before applying flow-isolation
588 +rules, to determine the true addresses and port numbers of the packet, to
589 +improve fairness between hosts "inside" the NAT. This has no practical effect
590 +in "flowblind" or "flows" modes, or if NAT is performed on a different host.
595 + Cake will not perform a NAT lookup. Flow isolation will be performed
596 +using the addresses and port numbers directly visible to the interface Cake is
599 +.SH PRIORITY QUEUE PARAMETERS
600 +CAKE can divide traffic into "tins" based on the Diffserv field. Each tin has
601 +its own independent set of flow-isolation queues, and is serviced based on a WRR
602 +algorithm. To avoid perverse Diffserv marking incentives, tin weights have a
603 +"priority sharing" value when bandwidth used by that tin is below a threshold,
604 +and a lower "bandwidth sharing" value when above. Bandwidth is compared against
605 +the threshold using the same algorithm as the deficit-mode shaper.
607 +Detailed customisation of tin parameters is not provided. The following presets
608 +perform all necessary tuning, relative to the current shaper bandwidth and RTT
613 + Disables priority queuing by placing all traffic in one tin.
617 + Enables legacy interpretation of TOS "Precedence" field. Use of this
618 +preset on the modern Internet is firmly discouraged.
622 + Provides a general-purpose Diffserv implementation with four tins:
624 + Bulk (CS1), 6.25% threshold, generally low priority.
626 + Best Effort (general), 100% threshold.
628 + Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, TOS1), 50% threshold.
630 + Voice (CS7, CS6, EF, VA, CS5, CS4), 25% threshold.
635 + Provides a simple, general-purpose Diffserv implementation with three tins:
637 + Bulk (CS1), 6.25% threshold, generally low priority.
639 + Best Effort (general), 100% threshold.
641 + Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
643 +.SH OTHER PARAMETERS
647 + Limit the memory consumed by Cake to LIMIT bytes. Note that this does
648 +not translate directly to queue size (so do not size this based on bandwidth
649 +delay product considerations, but rather on worst case acceptable memory
650 +consumption), as there is some overhead in the data structures containing the
651 +packets, especially for small packets.
653 + By default, the limit is calculated based on the bandwidth and RTT
660 + Traffic entering your diffserv domain is frequently mis-marked in
661 +transit from the perspective of your network, and traffic exiting yours may be
662 +mis-marked from the perspective of the transiting provider.
664 +Apply the wash option to clear all extra diffserv (but not ECN bits), after
665 +priority queuing has taken place.
667 +If you are shaping inbound, and cannot trust the diffserv markings (as is the
668 +case for Comcast Cable, among others), it is best to use a single queue
669 +"besteffort" mode with wash.
672 +# tc qdisc delete root dev eth0
674 +# tc qdisc add root dev eth0 cake bandwidth 100Mbit ethernet
676 +# tc -s qdisc show dev eth0
678 +qdisc cake 1: dev eth0 root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
679 + Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
680 + backlog 0b 0p requeues 0
681 + memory used: 0b of 5000000b
682 + capacity estimate: 100Mbit
683 + min/max network layer size: 65535 / 0
684 + min/max overhead-adjusted size: 65535 / 0
685 + average network hdr offset: 0
687 + Bulk Best Effort Voice
688 + thresh 6250Kbit 100Mbit 25Mbit
689 + target 5.0ms 5.0ms 5.0ms
690 + interval 100.0ms 100.0ms 100.0ms
691 + pk_delay 0us 0us 0us
692 + av_delay 0us 0us 0us
693 + sp_delay 0us 0us 0us
706 + quantum 300 1514 762
710 +# tc -s qdisc show dev eth0
712 +qdisc cake 1: root refcnt 2 bandwidth 100Mbit diffserv3 triple-isolate rtt 100.0ms noatm overhead 38 mpu 84
713 + Sent 44709231 bytes 31931 pkt (dropped 45, overlimits 93782 requeues 0)
714 + backlog 33308b 22p requeues 0
715 + memory used: 292352b of 5000000b
716 + capacity estimate: 100Mbit
717 + min/max network layer size: 28 / 1500
718 + min/max overhead-adjusted size: 84 / 1538
719 + average network hdr offset: 14
721 + Bulk Best Effort Voice
722 + thresh 6250Kbit 100Mbit 25Mbit
723 + target 5.0ms 5.0ms 5.0ms
724 + interval 100.0ms 100.0ms 100.0ms
725 + pk_delay 8.7ms 6.9ms 5.0ms
726 + av_delay 4.9ms 5.3ms 3.8ms
727 + sp_delay 727us 1.4ms 511us
728 + pkts 2590 21271 8137
729 + bytes 3081804 30302659 11426206
739 + max_len 1514 1514 1514
740 + quantum 300 1514 762
745 +.BR tc-fq_codel (8),
749 +Cake's principal author is Jonathan Morton, with contributions from
750 +Tony Ambardar, Kevin Darbyshire-Bryant, Toke Høiland-Jørgensen,
751 +Sebastian Moeller, Ryan Mounce, Dean Scarff, Nils Andreas Svee, and Dave Täht.
753 +This manual page was written by Loganaden Velvindron. Please report corrections
754 +to the Linux Networking mailing list <netdev@vger.kernel.org>.
757 @@ -64,6 +64,7 @@ TCMODULES += em_meta.o
758 TCMODULES += q_mqprio.o
759 TCMODULES += q_codel.o
760 TCMODULES += q_fq_codel.o
761 +TCMODULES += q_cake.o
768 +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
770 + * Common Applications Kept Enhanced -- CAKE
772 + * Copyright (C) 2014-2018 Jonathan Morton <chromatix99@gmail.com>
773 + * Copyright (C) 2017-2018 Toke Høiland-Jørgensen <toke@toke.dk>
782 +#include <sys/socket.h>
783 +#include <netinet/in.h>
784 +#include <arpa/inet.h>
788 +#include "tc_util.h"
790 +struct cake_preset {
792 + unsigned int target;
793 + unsigned int interval;
796 +static struct cake_preset presets[] = {
797 + {"datacentre", 5, 100},
799 + {"metro", 500, 10000},
800 + {"regional", 1500, 30000},
801 + {"internet", 5000, 100000},
802 + {"oceanic", 15000, 300000},
803 + {"satellite", 50000, 1000000},
804 + {"interplanetary", 50000000, 1000000000},
808 +static struct cake_preset *find_preset(char *argv)
812 + for (i = 0; i < ARRAY_SIZE(presets); i++)
813 + if (!strcmp(argv, presets[i].name))
814 + return &presets[i];
818 +static void explain(void)
821 +"Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
822 +" [ rtt TIME | datacentre | lan | metro | regional |\n"
823 +" internet* | oceanic | satellite | interplanetary ]\n"
824 +" [ besteffort | diffserv8 | diffserv4 | diffserv3* ]\n"
825 +" [ flowblind | srchost | dsthost | hosts | flows |\n"
826 +" dual-srchost | dual-dsthost | triple-isolate* ]\n"
827 +" [ nat | nonat* ]\n"
828 +" [ wash | nowash* ]\n"
829 +" [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
830 +" [ memlimit LIMIT ]\n"
831 +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
832 +" [ mpu N ] [ ingress | egress* ]\n"
833 +" (* marks defaults)\n");
836 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
837 + struct nlmsghdr *n, const char *dev)
840 + __u64 bandwidth = 0;
841 + unsigned interval = 0;
842 + unsigned target = 0;
843 + unsigned diffserv = 0;
844 + unsigned memlimit = 0;
846 + bool overhead_set = false;
847 + bool overhead_override = false;
855 + int ack_filter = -1;
856 + struct rtattr *tail;
857 + struct cake_preset *preset, *preset_set = NULL;
860 + if (strcmp(*argv, "bandwidth") == 0) {
862 + if (get_rate64(&bandwidth, *argv)) {
863 + fprintf(stderr, "Illegal \"bandwidth\"\n");
868 + } else if (strcmp(*argv, "unlimited") == 0) {
872 + } else if (strcmp(*argv, "autorate_ingress") == 0) {
875 + } else if (strcmp(*argv, "rtt") == 0) {
877 + if (get_time(&interval, *argv)) {
878 + fprintf(stderr, "Illegal \"rtt\"\n");
881 + target = interval / 20;
884 + } else if ((preset = find_preset(*argv))) {
886 + duparg(*argv, preset_set->name);
887 + preset_set = preset;
888 + target = preset->target;
889 + interval = preset->interval;
891 + } else if (strcmp(*argv, "besteffort") == 0) {
892 + diffserv = CAKE_DIFFSERV_BESTEFFORT;
893 + } else if (strcmp(*argv, "precedence") == 0) {
894 + diffserv = CAKE_DIFFSERV_PRECEDENCE;
895 + } else if (strcmp(*argv, "diffserv8") == 0) {
896 + diffserv = CAKE_DIFFSERV_DIFFSERV8;
897 + } else if (strcmp(*argv, "diffserv4") == 0) {
898 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
899 + } else if (strcmp(*argv, "diffserv") == 0) {
900 + diffserv = CAKE_DIFFSERV_DIFFSERV4;
901 + } else if (strcmp(*argv, "diffserv3") == 0) {
902 + diffserv = CAKE_DIFFSERV_DIFFSERV3;
904 + } else if (strcmp(*argv, "nowash") == 0) {
906 + } else if (strcmp(*argv, "wash") == 0) {
909 + } else if (strcmp(*argv, "flowblind") == 0) {
910 + flowmode = CAKE_FLOW_NONE;
911 + } else if (strcmp(*argv, "srchost") == 0) {
912 + flowmode = CAKE_FLOW_SRC_IP;
913 + } else if (strcmp(*argv, "dsthost") == 0) {
914 + flowmode = CAKE_FLOW_DST_IP;
915 + } else if (strcmp(*argv, "hosts") == 0) {
916 + flowmode = CAKE_FLOW_HOSTS;
917 + } else if (strcmp(*argv, "flows") == 0) {
918 + flowmode = CAKE_FLOW_FLOWS;
919 + } else if (strcmp(*argv, "dual-srchost") == 0) {
920 + flowmode = CAKE_FLOW_DUAL_SRC;
921 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
922 + flowmode = CAKE_FLOW_DUAL_DST;
923 + } else if (strcmp(*argv, "triple-isolate") == 0) {
924 + flowmode = CAKE_FLOW_TRIPLE;
926 + } else if (strcmp(*argv, "nat") == 0) {
928 + } else if (strcmp(*argv, "nonat") == 0) {
931 + } else if (strcmp(*argv, "ptm") == 0) {
932 + atm = CAKE_ATM_PTM;
933 + } else if (strcmp(*argv, "atm") == 0) {
934 + atm = CAKE_ATM_ATM;
935 + } else if (strcmp(*argv, "noatm") == 0) {
936 + atm = CAKE_ATM_NONE;
938 + } else if (strcmp(*argv, "raw") == 0) {
939 + atm = CAKE_ATM_NONE;
941 + overhead_set = true;
942 + overhead_override = true;
943 + } else if (strcmp(*argv, "conservative") == 0) {
945 + * Deliberately over-estimate overhead:
946 + * one whole ATM cell plus ATM framing.
947 + * A safe choice if the actual overhead is unknown.
949 + atm = CAKE_ATM_ATM;
951 + overhead_set = true;
953 + /* Various ADSL framing schemes, all over ATM cells */
954 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
955 + atm = CAKE_ATM_ATM;
957 + overhead_set = true;
958 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
959 + atm = CAKE_ATM_ATM;
961 + overhead_set = true;
962 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
963 + atm = CAKE_ATM_ATM;
965 + overhead_set = true;
966 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
967 + atm = CAKE_ATM_ATM;
969 + overhead_set = true;
970 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
971 + atm = CAKE_ATM_ATM;
973 + overhead_set = true;
974 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
975 + atm = CAKE_ATM_ATM;
977 + overhead_set = true;
978 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
979 + atm = CAKE_ATM_ATM;
981 + overhead_set = true;
982 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
983 + atm = CAKE_ATM_ATM;
985 + overhead_set = true;
987 + /* Typical VDSL2 framing schemes, both over PTM */
988 + /* PTM has 64b/65b coding which absorbs some bandwidth */
989 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
990 + /* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
991 + * + 2B ethertype + 4B Frame Check Sequence
992 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
993 + * + 2B TC-CRC (PTM-FCS) = 30B
995 + atm = CAKE_ATM_PTM;
997 + overhead_set = true;
998 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
999 + /* 6B dest MAC + 6B src MAC + 2B ethertype
1000 + * + 4B Frame Check Sequence
1001 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1002 + * + 2B TC-CRC (PTM-FCS) = 22B
1004 + atm = CAKE_ATM_PTM;
1006 + overhead_set = true;
1008 + } else if (strcmp(*argv, "via-ethernet") == 0) {
1010 + * We used to use this flag to manually compensate for
1011 + * Linux including the Ethernet header on Ethernet-type
1012 + * interfaces, but not on IP-type interfaces.
1014 + * It is no longer needed, because Cake now adjusts for
1015 + * that automatically, and is thus ignored.
1017 + * It would be deleted entirely, but it appears in the
1018 + * stats output when the automatic compensation is
1022 + } else if (strcmp(*argv, "ethernet") == 0) {
1023 + /* ethernet pre-amble & interframe gap & FCS
1024 + * you may need to add vlan tag */
1026 + overhead_set = true;
1029 + /* Additional Ethernet-related overhead used by some ISPs */
1030 + } else if (strcmp(*argv, "ether-vlan") == 0) {
1031 + /* 802.1q VLAN tag - may be repeated */
1033 + overhead_set = true;
1036 + * DOCSIS cable shapers account for Ethernet frame with FCS,
1037 + * but not interframe gap or preamble.
1039 + } else if (strcmp(*argv, "docsis") == 0) {
1040 + atm = CAKE_ATM_NONE;
1042 + overhead_set = true;
1045 + } else if (strcmp(*argv, "overhead") == 0) {
1048 + overhead = strtol(*argv, &p, 10);
1049 + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
1050 + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
1053 + overhead_set = true;
1055 + } else if (strcmp(*argv, "mpu") == 0) {
1058 + mpu = strtol(*argv, &p, 10);
1059 + if(!p || *p || !*argv || mpu < 0 || mpu > 256) {
1060 + fprintf(stderr, "Illegal \"mpu\", valid range is 0 to 256\\n");
1064 + } else if (strcmp(*argv, "ingress") == 0) {
1066 + } else if (strcmp(*argv, "egress") == 0) {
1069 + } else if (strcmp(*argv, "no-ack-filter") == 0) {
1070 + ack_filter = CAKE_ACK_NONE;
1071 + } else if (strcmp(*argv, "ack-filter") == 0) {
1072 + ack_filter = CAKE_ACK_FILTER;
1073 + } else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
1074 + ack_filter = CAKE_ACK_AGGRESSIVE;
1076 + } else if (strcmp(*argv, "memlimit") == 0) {
1078 + if(get_size(&memlimit, *argv)) {
1079 + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
1083 + } else if (strcmp(*argv, "help") == 0) {
1087 + fprintf(stderr, "What is \"%s\"?\n", *argv);
1094 + tail = NLMSG_TAIL(n);
1095 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
1096 + if (bandwidth || unlimited)
1097 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE64, &bandwidth, sizeof(bandwidth));
1099 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
1101 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
1102 + if (flowmode != -1)
1103 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
1105 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
1106 + if (overhead_override) {
1107 + unsigned zero = 0;
1108 + addattr_l(n, 1024, TCA_CAKE_RAW, &zero, sizeof(zero));
1111 + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
1113 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
1115 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
1116 + if (autorate != -1)
1117 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
1119 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
1121 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
1123 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
1124 + if (ingress != -1)
1125 + addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
1126 + if (ack_filter != -1)
1127 + addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter, sizeof(ack_filter));
1129 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1134 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1136 + struct rtattr *tb[TCA_CAKE_MAX + 1];
1137 + __u64 bandwidth = 0;
1138 + unsigned diffserv = 0;
1139 + unsigned flowmode = 0;
1140 + unsigned interval = 0;
1141 + unsigned memlimit = 0;
1150 + int ack_filter = 0;
1151 + int split_gso = 0;
1158 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
1160 + if (tb[TCA_CAKE_BASE_RATE64] &&
1161 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE64]) >= sizeof(bandwidth)) {
1162 + bandwidth = rta_getattr_u64(tb[TCA_CAKE_BASE_RATE64]);
1164 + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1));
1166 + fprintf(f, "unlimited ");
1168 + if (tb[TCA_CAKE_AUTORATE] &&
1169 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
1170 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
1172 + fprintf(f, "ingress");
1174 + fprintf(f, "unknown");
1176 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
1177 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
1178 + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
1179 + switch(diffserv) {
1180 + case CAKE_DIFFSERV_DIFFSERV3:
1181 + fprintf(f, "diffserv3 ");
1183 + case CAKE_DIFFSERV_DIFFSERV4:
1184 + fprintf(f, "diffserv4 ");
1186 + case CAKE_DIFFSERV_DIFFSERV8:
1187 + fprintf(f, "diffserv8 ");
1189 + case CAKE_DIFFSERV_BESTEFFORT:
1190 + fprintf(f, "besteffort ");
1192 + case CAKE_DIFFSERV_PRECEDENCE:
1193 + fprintf(f, "precedence ");
1196 + fprintf(f, "unknown ");
1200 + if (tb[TCA_CAKE_FLOW_MODE] &&
1201 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
1202 + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
1203 + switch(flowmode) {
1204 + case CAKE_FLOW_NONE:
1205 + fprintf(f, "flowblind ");
1207 + case CAKE_FLOW_SRC_IP:
1208 + fprintf(f, "srchost ");
1210 + case CAKE_FLOW_DST_IP:
1211 + fprintf(f, "dsthost ");
1213 + case CAKE_FLOW_HOSTS:
1214 + fprintf(f, "hosts ");
1216 + case CAKE_FLOW_FLOWS:
1217 + fprintf(f, "flows ");
1219 + case CAKE_FLOW_DUAL_SRC:
1220 + fprintf(f, "dual-srchost ");
1222 + case CAKE_FLOW_DUAL_DST:
1223 + fprintf(f, "dual-dsthost ");
1225 + case CAKE_FLOW_TRIPLE:
1226 + fprintf(f, "triple-isolate ");
1229 + fprintf(f, "unknown ");
1235 + if (tb[TCA_CAKE_NAT] &&
1236 + RTA_PAYLOAD(tb[TCA_CAKE_NAT]) >= sizeof(__u32)) {
1237 + nat = rta_getattr_u32(tb[TCA_CAKE_NAT]);
1241 + fprintf(f, "nat ");
1243 + if (tb[TCA_CAKE_WASH] &&
1244 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
1245 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
1247 + if (tb[TCA_CAKE_ATM] &&
1248 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
1249 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
1251 + if (tb[TCA_CAKE_OVERHEAD] &&
1252 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__s32)) {
1253 + overhead = *(__s32 *) RTA_DATA(tb[TCA_CAKE_OVERHEAD]);
1255 + if (tb[TCA_CAKE_MPU] &&
1256 + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
1257 + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
1259 + if (tb[TCA_CAKE_INGRESS] &&
1260 + RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
1261 + ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
1263 + if (tb[TCA_CAKE_ACK_FILTER] &&
1264 + RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
1265 + ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
1267 + if (tb[TCA_CAKE_SPLIT_GSO] &&
1268 + RTA_PAYLOAD(tb[TCA_CAKE_SPLIT_GSO]) >= sizeof(__u32)) {
1269 + split_gso = rta_getattr_u32(tb[TCA_CAKE_SPLIT_GSO]);
1271 + if (tb[TCA_CAKE_RAW]) {
1274 + if (tb[TCA_CAKE_RTT] &&
1275 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
1276 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
1280 + fprintf(f, "wash ");
1283 + fprintf(f, "ingress ");
1285 + if (ack_filter == CAKE_ACK_AGGRESSIVE)
1286 + fprintf(f, "ack-filter-aggresssive ");
1287 + else if (ack_filter == CAKE_ACK_FILTER)
1288 + fprintf(f, "ack-filter ");
1290 + fprintf(f, "no-ack-filter ");
1293 + fprintf(f, "split-gso ");
1296 + fprintf(f, "rtt %s ", sprint_time(interval, b2));
1299 + fprintf(f, "raw ");
1301 + if (atm == CAKE_ATM_ATM)
1302 + fprintf(f, "atm ");
1303 + else if (atm == CAKE_ATM_PTM)
1304 + fprintf(f, "ptm ");
1306 + fprintf(f, "noatm ");
1308 + fprintf(f, "overhead %d ", overhead);
1311 + fprintf(f, "mpu %u ", mpu);
1314 + fprintf(f, "memlimit %s", sprint_size(memlimit, b1));
1320 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
1321 + struct rtattr *xstats)
1324 + struct rtattr *st[TCA_CAKE_STATS_MAX + 1];
1327 + if (xstats == NULL)
1330 +#define GET_STAT_U32(attr) rta_getattr_u32(st[TCA_CAKE_STATS_ ## attr])
1331 +#define GET_STAT_S32(attr) (*(__s32*)RTA_DATA(st[TCA_CAKE_STATS_ ## attr]))
1332 +#define GET_STAT_U64(attr) rta_getattr_u64(st[TCA_CAKE_STATS_ ## attr])
1334 + parse_rtattr_nested(st, TCA_CAKE_STATS_MAX, xstats);
1336 + if (st[TCA_CAKE_STATS_MEMORY_USED] &&
1337 + st[TCA_CAKE_STATS_MEMORY_LIMIT]) {
1338 + fprintf(f, " memory used: %s",
1339 + sprint_size(GET_STAT_U32(MEMORY_USED), b1));
1341 + fprintf(f, " of %s\n",
1342 + sprint_size(GET_STAT_U32(MEMORY_LIMIT), b1));
1345 + if (st[TCA_CAKE_STATS_CAPACITY_ESTIMATE64]) {
1346 + fprintf(f, " capacity estimate: %s\n",
1347 + sprint_rate(GET_STAT_U64(CAPACITY_ESTIMATE64), b1));
1350 + if (st[TCA_CAKE_STATS_MIN_NETLEN] &&
1351 + st[TCA_CAKE_STATS_MAX_NETLEN]) {
1352 + fprintf(f, " min/max network layer size: %8u",
1353 + GET_STAT_U32(MIN_NETLEN));
1354 + fprintf(f, " /%8u\n", GET_STAT_U32(MAX_NETLEN));
1357 + if (st[TCA_CAKE_STATS_MIN_ADJLEN] &&
1358 + st[TCA_CAKE_STATS_MAX_ADJLEN]) {
1359 + fprintf(f, " min/max overhead-adjusted size: %8u",
1360 + GET_STAT_U32(MIN_ADJLEN));
1361 + fprintf(f, " /%8u\n", GET_STAT_U32(MAX_ADJLEN));
1364 + if (st[TCA_CAKE_STATS_AVG_NETOFF])
1365 + fprintf(f, " average network hdr offset: %8u\n\n",
1366 + GET_STAT_U32(AVG_NETOFF));
1369 + if (st[TCA_CAKE_STATS_DEFICIT])
1370 + fprintf(f, "deficit %u",
1371 + GET_STAT_S32(DEFICIT));
1372 + if (st[TCA_CAKE_STATS_COBALT_COUNT])
1373 + fprintf(f, "count %u",
1374 + GET_STAT_U32(COBALT_COUNT));
1376 + if (st[TCA_CAKE_STATS_DROPPING] && GET_STAT_U32(DROPPING)) {
1377 + fprintf(f, " dropping");
1378 + if (st[TCA_CAKE_STATS_DROP_NEXT_US]) {
1379 + int drop_next = GET_STAT_S32(DROP_NEXT_US);
1380 + if (drop_next < 0) {
1381 + fprintf(f, " drop_next -%s",
1382 + sprint_time(drop_next, b1));
1384 + fprintf(f, " drop_next %s",
1385 + sprint_time(drop_next, b1));
1390 + if (st[TCA_CAKE_STATS_P_DROP]) {
1391 + fprintf(f, " blue_prob %u",
1392 + GET_STAT_U32(P_DROP));
1393 + if (st[TCA_CAKE_STATS_BLUE_TIMER_US]) {
1394 + int blue_timer = GET_STAT_S32(BLUE_TIMER_US);
1395 + if (blue_timer < 0) {
1396 + fprintf(f, " blue_timer -%s",
1397 + sprint_time(blue_timer, b1));
1399 + fprintf(f, " blue_timer %s",
1400 + sprint_time(blue_timer, b1));
1405 +#undef GET_STAT_U32
1406 +#undef GET_STAT_S32
1407 +#undef GET_STAT_U64
1409 + if (st[TCA_CAKE_STATS_TIN_STATS]) {
1410 + struct rtattr *tins[TC_CAKE_MAX_TINS + 1];
1411 + struct rtattr *tstat[TC_CAKE_MAX_TINS][TCA_CAKE_TIN_STATS_MAX + 1];
1414 + parse_rtattr_nested(tins, TC_CAKE_MAX_TINS, st[TCA_CAKE_STATS_TIN_STATS]);
1416 + for (i = 1; i <= TC_CAKE_MAX_TINS && tins[i]; i++) {
1417 + parse_rtattr_nested(tstat[i-1], TCA_CAKE_TIN_STATS_MAX, tins[i]);
1424 + switch(num_tins) {
1426 + fprintf(f, " Bulk Best Effort Voice\n");
1430 + fprintf(f, " Bulk Best Effort Video Voice\n");
1435 + for(i=0; i < num_tins; i++)
1436 + fprintf(f, " Tin %u", i);
1440 +#define GET_TSTAT(i, attr) (tstat[i][TCA_CAKE_TIN_STATS_ ## attr])
1441 +#define PRINT_TSTAT(name, attr, fmts, val) do { \
1442 + if (GET_TSTAT(0, attr)) { \
1443 + fprintf(f, name); \
1444 + for (i = 0; i < num_tins; i++) \
1445 + fprintf(f, " %12" fmts, val); \
1446 + fprintf(f, "\n"); \
1450 +#define SPRINT_TSTAT(pfunc, type, name, attr) PRINT_TSTAT( \
1451 + name, attr, "s", sprint_ ## pfunc( \
1452 + rta_getattr_ ## type(GET_TSTAT(i, attr)), b1))
1454 +#define PRINT_TSTAT_U32(name, attr) PRINT_TSTAT( \
1455 + name, attr, "u", rta_getattr_u32(GET_TSTAT(i, attr)))
1457 +#define PRINT_TSTAT_U64(name, attr) PRINT_TSTAT( \
1458 + name, attr, "llu", rta_getattr_u64(GET_TSTAT(i, attr)))
1460 + SPRINT_TSTAT(rate, u64, " thresh ", THRESHOLD_RATE64);
1461 + SPRINT_TSTAT(time, u32, " target ", TARGET_US);
1462 + SPRINT_TSTAT(time, u32, " interval", INTERVAL_US);
1463 + SPRINT_TSTAT(time, u32, " pk_delay", PEAK_DELAY_US);
1464 + SPRINT_TSTAT(time, u32, " av_delay", AVG_DELAY_US);
1465 + SPRINT_TSTAT(time, u32, " sp_delay", BASE_DELAY_US);
1466 + SPRINT_TSTAT(size, u32, " backlog ", BACKLOG_BYTES);
1468 + PRINT_TSTAT_U32(" pkts ", SENT_PACKETS);
1469 + PRINT_TSTAT_U64(" bytes ", SENT_BYTES64);
1471 + PRINT_TSTAT_U32(" way_inds", WAY_INDIRECT_HITS);
1472 + PRINT_TSTAT_U32(" way_miss", WAY_MISSES);
1473 + PRINT_TSTAT_U32(" way_cols", WAY_COLLISIONS);
1474 + PRINT_TSTAT_U32(" drops ", DROPPED_PACKETS);
1475 + PRINT_TSTAT_U32(" marks ", ECN_MARKED_PACKETS);
1476 + PRINT_TSTAT_U32(" ack_drop", ACKS_DROPPED_PACKETS);
1477 + PRINT_TSTAT_U32(" sp_flows", SPARSE_FLOWS);
1478 + PRINT_TSTAT_U32(" bk_flows", BULK_FLOWS);
1479 + PRINT_TSTAT_U32(" un_flows", UNRESPONSIVE_FLOWS);
1480 + PRINT_TSTAT_U32(" max_len ", MAX_SKBLEN);
1481 + PRINT_TSTAT_U32(" quantum ", FLOW_QUANTUM);
1485 +#undef SPRINT_TSTAT
1486 +#undef PRINT_TSTAT_U32
1487 +#undef PRINT_TSTAT_U64
1492 +struct qdisc_util cake_qdisc_util = {
1494 + .parse_qopt = cake_parse_opt,
1495 + .print_qopt = cake_print_opt,
1496 + .print_xstats = cake_print_xstats,