1 diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h
2 index 37b5096a..66da5df9 100644
3 --- a/include/uapi/linux/pkt_sched.h
4 +++ b/include/uapi/linux/pkt_sched.h
5 @@ -934,4 +934,75 @@ enum {
7 #define TCA_CBS_MAX (__TCA_CBS_MAX - 1)
13 + TCA_CAKE_DIFFSERV_MODE,
22 + TCA_CAKE_RAW, // was _ETHERNET
26 + TCA_CAKE_ACK_FILTER,
29 +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
31 +struct tc_cake_traffic_stats {
37 +#define TC_CAKE_MAX_TINS (8)
38 +struct tc_cake_tin_stats {
40 + __u32 threshold_rate;
42 + struct tc_cake_traffic_stats sent;
43 + struct tc_cake_traffic_stats dropped;
44 + struct tc_cake_traffic_stats ecn_marked;
45 + struct tc_cake_traffic_stats backlog;
47 + __u32 way_indirect_hits;
49 + __u32 way_collisions;
50 + __u32 peak_delay_us; /* ~= bulk flow delay */
51 + __u32 avge_delay_us;
52 + __u32 base_delay_us; /* ~= sparse flows delay */
55 + __u16 unresponse_flows;
58 + struct tc_cake_traffic_stats ack_drops;
61 +struct tc_cake_xstats {
63 + __u16 tin_stats_size; /* == sizeof(struct tc_cake_tin_stats) */
64 + __u32 capacity_estimate;
77 + struct tc_cake_tin_stats tin_stats[0]; /* keep last */
81 diff --git a/man/man8/tc-cake.8 b/man/man8/tc-cake.8
83 index 00000000..ff77db8f
85 +++ b/man/man8/tc-cake.8
87 +.TH CAKE 8 "23 November 2017" "iproute2" "Linux"
89 +CAKE \- COMMON Applications Kept Enhanced (CAKE)
166 +.BR ack-filter-aggressive
205 +CAKE (Common Applications Kept Enhanced) is a shaping-capable queue discipline
206 +which uses both AQM and FQ. It combines COBALT, which is an AQM algorithm
207 +combining Codel and BLUE, a shaper which operates in deficit mode, and a variant
208 +of DRR++ for flow isolation. 8-way set-associative hashing is used to virtually
209 +eliminate hash collisions. Priority queuing is available through a simplified
210 +diffserv implementation. Overhead compensation for various encapsulation
211 +schemes is tightly integrated.
213 +All settings are optional; the default settings are chosen to be sensible in
214 +most common deployments. Most people will only need to set the
216 +parameter to get useful results, but reading the
217 +.B Overhead Compensation
220 +sections is strongly encouraged.
222 +.SH SHAPER PARAMETERS
223 +CAKE uses a deficit-mode shaper, which does not exhibit the initial burst
224 +typical of token-bucket shapers. It will automatically burst precisely as much
225 +as required to maintain the configured throughput. As such, it is very
226 +straightforward to configure.
231 + No limit on the bandwidth.
236 + Set the shaper bandwidth. See
238 +or examples below for details of the RATE value.
242 + Automatic capacity estimation based on traffic arriving at this qdisc.
243 +This is most likely to be useful with cellular links, which tend to change
246 +parameter can be used in conjunction to specify an initial estimate. The shaper
247 +will periodically be set to a bandwidth slightly below the estimated rate. This
248 +estimator cannot estimate the bandwidth of links downstream of itself.
250 +.SH OVERHEAD COMPENSATION PARAMETERS
251 +The size of each packet on the wire may differ from that seen by Linux. The
252 +following parameters allow CAKE to compensate for this difference by internally
253 +considering each packet to be bigger than Linux informs it. To assist users who
254 +are not expert network engineers, keywords have been provided to represent a
255 +number of common link technologies.
257 +.SS Manual Overhead Specification
261 + Adds BYTES to the size of each packet. BYTES may be negative; values
262 +between -64 and 256 (inclusive) are accepted.
267 + Rounds each packet (including overhead) up to a minimum length
268 +BYTES. BYTES may not be negative; values between 0 and 256 (inclusive)
273 + Compensates for ATM cell framing, which is normally found on ADSL links.
274 +This is performed after the
276 +parameter above. ATM uses fixed 53-byte cells, each of which can carry 48 bytes
281 + Compensates for PTM encoding, which is normally found on VDSL2 links and
282 +uses a 64b/65b encoding scheme. It is even more efficient to simply
283 +derate the specified shaper bandwidth by a factor of 64/65 or 0.984. See
284 +ITU G.992.3 Annex N and IEEE 802.3 Section 61.3 for details.
288 + Disables ATM and PTM compensation.
290 +.SS Failsafe Overhead Keywords
291 +These two keywords are provided for quick-and-dirty setup. Use them if you
292 +can't be bothered to read the rest of this section.
297 + Turns off all overhead compensation in CAKE. The packet size reported
298 +by Linux will be used directly.
300 + Other overhead keywords may be added after "raw". The effect of this is
301 +to make the overhead compensation operate relative to the reported packet size,
302 +not the underlying IP packet size.
306 + Compensates for more overhead than is likely to occur on any
307 +widely-deployed link technology.
312 +.SS ADSL Overhead Keywords
313 +Most ADSL modems have a way to check which framing scheme is in use. Often this
314 +is also specified in the settings document provided by the ISP. The keywords in
315 +this section are intended to correspond with these sources of information. All
316 +of them implicitly set the
360 +See also the Ethernet Correction Factors section below.
362 +.SS VDSL2 Overhead Keywords
363 +ATM was dropped from VDSL2 in favour of PTM, which is a much more
364 +straightforward framing scheme. Some ISPs retained PPPoE for compatibility with
365 +their existing back-end systems.
373 + PPPoE: 2B PPP + 6B PPPoE +
375 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
377 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
385 + ETHERNET: 6B dest MAC + 6B src MAC + 2B ethertype + 4B Frame Check Sequence +
387 + PTM: 1B Start of Frame (S) + 1B End of Frame (Ck) + 2B TC-CRC (PTM-FCS)
390 +See also the Ethernet Correction Factors section below.
392 +.SS DOCSIS Cable Overhead Keyword
393 +DOCSIS is the universal standard for providing Internet service over cable-TV
396 +In this case, the actual on-wire overhead is less important than the packet size
397 +the head-end equipment uses for shaping and metering. This is specified to be
398 +an Ethernet frame including the CRC (aka FCS).
403 +.B overhead 18 mpu 64 noatm
405 +.SS Ethernet Overhead Keywords
409 + Accounts for Ethernet's preamble, inter-frame gap, and Frame Check
410 +Sequence. Use this keyword when the bottleneck being shaped for is an
411 +actual Ethernet cable.
414 +.B overhead 38 mpu 84 noatm
418 + Adds 4 bytes to the overhead compensation, accounting for an IEEE 802.1Q
419 +VLAN header appended to the Ethernet frame header. NB: Some ISPs use one or
420 +even two of these within PPPoE; this keyword may be repeated as necessary to
423 +.SH ROUND TRIP TIME PARAMETERS
424 +Active Queue Management (AQM) consists of embedding congestion signals in the
425 +packet flow, which receivers use to instruct senders to slow down when the queue
426 +is persistently occupied. CAKE uses ECN signalling when available, and packet
427 +drops otherwise, according to a combination of the Codel and BLUE AQM algorithms
430 +Very short latencies require a very rapid AQM response to adequately control
431 +latency. However, such a rapid response tends to impair throughput when the
432 +actual RTT is relatively long. CAKE allows specifying the RTT it assumes for
433 +tuning various parameters. Actual RTTs within an order of magnitude of this
434 +will generally work well for both throughput and latency management.
436 +At the 'lan' setting and below, the time constants are similar in magnitude to
437 +the jitter in the Linux kernel itself, so congestion might be signalled
438 +prematurely. The flows will then become sparse and total throughput reduced,
439 +leaving little or no back-pressure for the fairness logic to work against. Use
440 +the "metro" setting for local lans unless you have a custom kernel.
445 + Manually specify an RTT.
449 + For extremely high-performance 10GigE+ networks only. Equivalent to
454 + For pure Ethernet (not Wi-Fi) networks, at home or in the office. Don't
455 +use this when shaping for an Internet access link. Equivalent to
460 + For traffic mostly within a single city. Equivalent to
465 + For traffic mostly within a European-sized country. Equivalent to
471 + This is suitable for most Internet traffic. Equivalent to
476 + For Internet traffic with generally above-average latency, such as that
477 +suffered by Australasian residents. Equivalent to
482 + For traffic via geostationary satellites. Equivalent to
487 + So named because Jupiter is about 1 light-hour from Earth. Use this to
488 +(almost) completely disable AQM actions. Equivalent to
491 +.SH FLOW ISOLATION PARAMETERS
492 +With flow isolation enabled, CAKE places packets from different flows into
493 +different queues, each of which carries its own AQM state. Packets from each
494 +queue are then delivered fairly, according to a DRR++ algorithm which minimises
495 +latency for "sparse" flows. CAKE uses a set-associative hashing algorithm to
496 +minimise flow collisions.
498 +These keywords specify whether fairness based on source address, destination
499 +address, individual flows, or any combination of those is desired.
503 + Disables flow isolation; all traffic passes through a single queue for
508 + Flows are defined only by source address. Could be useful on the egress
509 +path of an ISP backhaul.
513 + Flows are defined only by destination address. Could be useful on the
514 +ingress path of an ISP backhaul.
518 + Flows are defined by source-destination host pairs. This is host
519 +isolation, rather than flow isolation.
523 + Flows are defined by the entire 5-tuple of source address, destination
524 +address, transport protocol, source port and destination port. This is the type
525 +of flow isolation performed by SFQ and fq_codel.
529 + Flows are defined by the 5-tuple, and fairness is applied first over
530 +source addresses, then over individual flows. Good for use on egress traffic
531 +from a LAN to the internet, where it'll prevent any one LAN host from
532 +monopolising the uplink, regardless of the number of flows they use.
536 + Flows are defined by the 5-tuple, and fairness is applied first over
537 +destination addresses, then over individual flows. Good for use on ingress
538 +traffic to a LAN from the internet, where it'll prevent any one LAN host from
539 +monopolising the downlink, regardless of the number of flows they use.
544 + Flows are defined by the 5-tuple, and fairness is applied over source
545 +*and* destination addresses intelligently (ie. not merely by host-pairs), and
546 +also over individual flows. Use this if you're not certain whether to use
547 +dual-srchost or dual-dsthost; it'll do both jobs at once, preventing any one
548 +host on *either* side of the link from monopolising it with a large number of
553 + Instructs Cake to perform a NAT lookup before applying flow-isolation
554 +rules, to determine the true addresses and port numbers of the packet, to
555 +improve fairness between hosts "inside" the NAT. This has no practical effect
556 +in "flowblind" or "flows" modes, or if NAT is performed on a different host.
561 + Cake will not perform a NAT lookup. Flow isolation will be performed
562 +using the addresses and port numbers directly visible to the interface Cake is
565 +.SH PRIORITY QUEUE PARAMETERS
566 +CAKE can divide traffic into "tins" based on the Diffserv field. Each tin has
567 +its own independent set of flow-isolation queues, and is serviced based on a WRR
568 +algorithm. To avoid perverse Diffserv marking incentives, tin weights have a
569 +"priority sharing" value when bandwidth used by that tin is below a threshold,
570 +and a lower "bandwidth sharing" value when above. Bandwidth is compared against
571 +the threshold using the same algorithm as the deficit-mode shaper.
573 +Detailed customisation of tin parameters is not provided. The following presets
574 +perform all necessary tuning, relative to the current shaper bandwidth and RTT
579 + Disables priority queuing by placing all traffic in one tin.
583 + Enables legacy interpretation of TOS "Precedence" field. Use of this
584 +preset on the modern Internet is firmly discouraged.
588 + Provides a "Latency-Loss Tradeoff" implementation with five tins:
590 + Low Loss (TOS1, TOS2), 100% threshold, increased Codel target.
592 + Best Effort (general), 100% threshold, normal Codel target & interval.
594 + Low Latency (TOS4, TOS5, VA, EF), 100% threshold, reduced Codel interval.
596 + Bulk (CS1), 6.25% threshold, normal Codel target & interval.
598 + Net Control (CS6, CS7), 6.25% threshold, increased Codel target & interval.
602 + Provides a general-purpose Diffserv implementation with four tins:
604 + Bulk (CS1), 6.25% threshold, generally low priority.
606 + Best Effort (general), 100% threshold.
608 + Video (AF4x, AF3x, CS3, AF2x, CS2, TOS4, TOS1), 50% threshold.
610 + Voice (CS7, CS6, EF, VA, CS5, CS4), 25% threshold.
615 + Provides a simple, general-purpose Diffserv implementation with three tins:
617 + Bulk (CS1), 6.25% threshold, generally low priority.
619 + Best Effort (general), 100% threshold.
621 + Voice (CS7, CS6, EF, VA, TOS4), 25% threshold, reduced Codel interval.
623 +.SH OTHER PARAMETERS
627 + Limit the memory consumed by Cake to LIMIT bytes. Note that this does
628 +not translate directly to queue size (so do not size this based on bandwidth
629 +delay product considerations, but rather on worst case acceptable memory
630 +consumption), as there is some overhead in the data structures containing the
631 +packets, especially for small packets.
633 + By default, the limit is calculated based on the bandwidth and RTT
640 + Traffic entering your diffserv domain is frequently mis-marked in
641 +transit from the perspective of your network, and traffic exiting yours may be
642 +mis-marked from the perspective of the transiting provider.
644 +Apply the wash option to clear all extra diffserv (but not ECN bits), after
645 +priority queuing has taken place.
647 +If you are shaping inbound, and cannot trust the diffserv markings (as is the
648 +case for Comcast Cable, among others), it is best to use a single queue
649 +"besteffort" mode with wash.
652 +# tc qdisc delete root dev eth0
654 +# tc qdisc add root dev eth0 cake bandwidth 9500Kbit pppoe-ptm ether-vlan
656 +# tc -s qdisc show dev eth0
658 +qdisc cake 8007: root refcnt 6 bandwidth 9500Kbit diffserv3 triple-isolate rtt 100.0ms ptm overhead 34 via-ethernet total_overhead 34 hard_header_len 14
659 + Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
660 + backlog 0b 0p requeues 0
661 + memory used: 0b of 4Mb
662 + capacity estimate: 9500Kbit
664 + Bulk Best Effort Voice
666 + thresh 593744bit 9500Kbit 2375Kbit
668 + target 30.6ms 5.0ms 7.6ms
670 + interval 125.6ms 100.0ms 102.6ms
672 + pk_delay 0us 0us 0us
674 + av_delay 0us 0us 0us
676 + sp_delay 0us 0us 0us
705 +# tc -s qdisc show dev eth0
707 +qdisc cake 8007: root refcnt 6 bandwidth 9500Kbit diffserv3 triple-isolate rtt 100.0ms ptm overhead 34 via-ethernet total_overhead 34 hard_header_len 14
708 + Sent 110769306 bytes 313857 pkt (dropped 18, overlimits 741791 requeues 0)
709 + backlog 0b 0p requeues 0
710 + memory used: 110488b of 4Mb
711 + capacity estimate: 9500Kbit
713 + Bulk Best Effort Voice
715 + thresh 593744bit 9500Kbit 2375Kbit
717 + target 30.6ms 5.0ms 7.6ms
719 + interval 125.6ms 100.0ms 102.6ms
721 + pk_delay 16.0ms 545us 15us
723 + av_delay 2.4ms 161us 3us
725 + sp_delay 59us 1us 1us
727 + pkts 32866 195815 85194
729 + bytes 8132614 69517496 33122156
749 + max_len 3028 3012 3028
755 +.BR tc-fq_codel (8),
759 +Cake's principal author is Jonathan Morton, with contributions from
760 +Tony Ambardar, Kevin Darbyshire-Bryant, Toke Høiland-Jørgensen,
761 +Sebastian Moeller, Ryan Mounce, Dean Scarff, Nils Andreas Svee, and Dave Täht.
763 +This manual page was written by Loganaden Velvindron. Please report corrections
764 +to the Linux Networking mailing list <netdev@vger.kernel.org>.
765 diff --git a/tc/Makefile b/tc/Makefile
766 index 3716dd6a..69f50a6b 100644
769 @@ -64,6 +64,7 @@ TCMODULES += em_meta.o
770 TCMODULES += q_mqprio.o
771 TCMODULES += q_codel.o
772 TCMODULES += q_fq_codel.o
773 +TCMODULES += q_cake.o
777 diff --git a/tc/q_cake.c b/tc/q_cake.c
779 index 00000000..44cadb63
783 +/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
785 + * Common Applications Kept Enhanced -- CAKE
787 + * Copyright (C) 2014-2018 Jonathan Morton <chromatix99@gmail.com>
788 + * Copyright (C) 2017-2018 Toke Høiland-Jørgensen <toke@toke.dk>
790 + * Redistribution and use in source and binary forms, with or without
791 + * modification, are permitted provided that the following conditions
793 + * 1. Redistributions of source code must retain the above copyright
794 + * notice, this list of conditions, and the following disclaimer,
795 + * without modification.
796 + * 2. Redistributions in binary form must reproduce the above copyright
797 + * notice, this list of conditions and the following disclaimer in the
798 + * documentation and/or other materials provided with the distribution.
799 + * 3. The names of the authors may not be used to endorse or promote products
800 + * derived from this software without specific prior written permission.
802 + * Alternatively, provided that this notice is retained in full, this
803 + * software may be distributed under the terms of the GNU General
804 + * Public License ("GPL") version 2, in which case the provisions of the
805 + * GPL apply INSTEAD OF those given above.
807 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
808 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
809 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
810 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
811 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
812 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
813 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
814 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
815 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
816 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
817 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
828 +#include <sys/socket.h>
829 +#include <netinet/in.h>
830 +#include <arpa/inet.h>
834 +#include "tc_util.h"
836 +static void explain(void)
839 +"Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
840 +" [ rtt TIME | datacentre | lan | metro | regional |\n"
841 +" internet* | oceanic | satellite | interplanetary ]\n"
842 +" [ besteffort | diffserv8 | diffserv4 | diffserv-llt |\n"
844 +" [ flowblind | srchost | dsthost | hosts | flows |\n"
845 +" dual-srchost | dual-dsthost | triple-isolate* ]\n"
846 +" [ nat | nonat* ]\n"
847 +" [ wash | nowash* ]\n"
848 +" [ ack-filter | ack-filter-aggressive | no-ack-filter* ]\n"
849 +" [ memlimit LIMIT ]\n"
850 +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
851 +" [ mpu N ] [ ingress | egress* ]\n"
852 +" (* marks defaults)\n");
855 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
856 + struct nlmsghdr *n, const char *dev)
859 + unsigned bandwidth = 0;
860 + unsigned interval = 0;
861 + unsigned target = 0;
862 + unsigned diffserv = 0;
863 + unsigned memlimit = 0;
865 + bool overhead_set = false;
866 + bool overhead_override = false;
874 + int ack_filter = -1;
875 + struct rtattr *tail;
878 + if (strcmp(*argv, "bandwidth") == 0) {
880 + if (get_rate(&bandwidth, *argv)) {
881 + fprintf(stderr, "Illegal \"bandwidth\"\n");
886 + } else if (strcmp(*argv, "unlimited") == 0) {
890 + } else if (strcmp(*argv, "autorate_ingress") == 0) {
893 + } else if (strcmp(*argv, "rtt") == 0) {
895 + if (get_time(&interval, *argv)) {
896 + fprintf(stderr, "Illegal \"rtt\"\n");
899 + target = interval / 20;
902 + } else if (strcmp(*argv, "datacentre") == 0) {
905 + } else if (strcmp(*argv, "lan") == 0) {
908 + } else if (strcmp(*argv, "metro") == 0) {
911 + } else if (strcmp(*argv, "regional") == 0) {
914 + } else if (strcmp(*argv, "internet") == 0) {
917 + } else if (strcmp(*argv, "oceanic") == 0) {
920 + } else if (strcmp(*argv, "satellite") == 0) {
921 + interval = 1000000;
923 + } else if (strcmp(*argv, "interplanetary") == 0) {
924 + interval = 1000000000;
927 + } else if (strcmp(*argv, "besteffort") == 0) {
929 + } else if (strcmp(*argv, "precedence") == 0) {
931 + } else if (strcmp(*argv, "diffserv8") == 0) {
933 + } else if (strcmp(*argv, "diffserv4") == 0) {
935 + } else if (strcmp(*argv, "diffserv") == 0) {
937 + } else if (strcmp(*argv, "diffserv-llt") == 0) {
939 + } else if (strcmp(*argv, "diffserv3") == 0) {
942 + } else if (strcmp(*argv, "nowash") == 0) {
944 + } else if (strcmp(*argv, "wash") == 0) {
947 + } else if (strcmp(*argv, "flowblind") == 0) {
949 + } else if (strcmp(*argv, "srchost") == 0) {
951 + } else if (strcmp(*argv, "dsthost") == 0) {
953 + } else if (strcmp(*argv, "hosts") == 0) {
955 + } else if (strcmp(*argv, "flows") == 0) {
957 + } else if (strcmp(*argv, "dual-srchost") == 0) {
959 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
961 + } else if (strcmp(*argv, "triple-isolate") == 0) {
964 + } else if (strcmp(*argv, "nat") == 0) {
966 + } else if (strcmp(*argv, "nonat") == 0) {
969 + } else if (strcmp(*argv, "ptm") == 0) {
971 + } else if (strcmp(*argv, "atm") == 0) {
973 + } else if (strcmp(*argv, "noatm") == 0) {
976 + } else if (strcmp(*argv, "raw") == 0) {
979 + overhead_set = true;
980 + overhead_override = true;
981 + } else if (strcmp(*argv, "conservative") == 0) {
983 + * Deliberately over-estimate overhead:
984 + * one whole ATM cell plus ATM framing.
985 + * A safe choice if the actual overhead is unknown.
989 + overhead_set = true;
991 + /* Various ADSL framing schemes, all over ATM cells */
992 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
995 + overhead_set = true;
996 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
999 + overhead_set = true;
1000 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
1003 + overhead_set = true;
1004 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
1007 + overhead_set = true;
1008 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
1011 + overhead_set = true;
1012 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
1015 + overhead_set = true;
1016 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
1019 + overhead_set = true;
1020 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
1023 + overhead_set = true;
1025 + /* Typical VDSL2 framing schemes, both over PTM */
1026 + /* PTM has 64b/65b coding which absorbs some bandwidth */
1027 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
1028 + /* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
1029 + * + 2B ethertype + 4B Frame Check Sequence
1030 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1031 + * + 2B TC-CRC (PTM-FCS) = 30B
1035 + overhead_set = true;
1036 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
1037 + /* 6B dest MAC + 6B src MAC + 2B ethertype
1038 + * + 4B Frame Check Sequence
1039 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
1040 + * + 2B TC-CRC (PTM-FCS) = 22B
1044 + overhead_set = true;
1046 + } else if (strcmp(*argv, "via-ethernet") == 0) {
1048 + * We used to use this flag to manually compensate for
1049 + * Linux including the Ethernet header on Ethernet-type
1050 + * interfaces, but not on IP-type interfaces.
1052 + * It is no longer needed, because Cake now adjusts for
1053 + * that automatically, and is thus ignored.
1055 + * It would be deleted entirely, but it appears in the
1056 + * stats output when the automatic compensation is
1060 + } else if (strcmp(*argv, "ethernet") == 0) {
1061 + /* ethernet pre-amble & interframe gap & FCS
1062 + * you may need to add vlan tag */
1064 + overhead_set = true;
1067 + /* Additional Ethernet-related overhead used by some ISPs */
1068 + } else if (strcmp(*argv, "ether-vlan") == 0) {
1069 + /* 802.1q VLAN tag - may be repeated */
1071 + overhead_set = true;
1074 + * DOCSIS cable shapers account for Ethernet frame with FCS,
1075 + * but not interframe gap or preamble.
1077 + } else if (strcmp(*argv, "docsis") == 0) {
1080 + overhead_set = true;
1083 + } else if (strcmp(*argv, "overhead") == 0) {
1086 + overhead = strtol(*argv, &p, 10);
1087 + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
1088 + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
1091 + overhead_set = true;
1093 + } else if (strcmp(*argv, "mpu") == 0) {
1096 + mpu = strtol(*argv, &p, 10);
1097 + if(!p || *p || !*argv || mpu < 0 || mpu > 256) {
1098 + fprintf(stderr, "Illegal \"mpu\", valid range is 0 to 256\\n");
1102 + } else if (strcmp(*argv, "ingress") == 0) {
1104 + } else if (strcmp(*argv, "egress") == 0) {
1107 + } else if (strcmp(*argv, "no-ack-filter") == 0) {
1109 + } else if (strcmp(*argv, "ack-filter") == 0) {
1110 + ack_filter = 0x0200;
1111 + } else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
1112 + ack_filter = 0x0600;
1114 + } else if (strcmp(*argv, "memlimit") == 0) {
1116 + if(get_size(&memlimit, *argv)) {
1117 + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
1121 + } else if (strcmp(*argv, "help") == 0) {
1125 + fprintf(stderr, "What is \"%s\"?\n", *argv);
1132 + tail = NLMSG_TAIL(n);
1133 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
1134 + if (bandwidth || unlimited)
1135 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth));
1137 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
1139 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
1140 + if (flowmode != -1)
1141 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
1143 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
1144 + if (overhead_override) {
1145 + unsigned zero = 0;
1146 + addattr_l(n, 1024, TCA_CAKE_RAW, &zero, sizeof(zero));
1149 + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
1151 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
1153 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
1154 + if (autorate != -1)
1155 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
1157 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
1159 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
1161 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
1162 + if (ingress != -1)
1163 + addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
1164 + if (ack_filter != -1)
1165 + addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter, sizeof(ack_filter));
1167 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
1172 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
1174 + struct rtattr *tb[TCA_CAKE_MAX + 1];
1175 + unsigned bandwidth = 0;
1176 + unsigned diffserv = 0;
1177 + unsigned flowmode = 0;
1178 + unsigned interval = 0;
1179 + unsigned memlimit = 0;
1188 + int ack_filter = 0;
1195 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
1197 + if (tb[TCA_CAKE_BASE_RATE] &&
1198 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) {
1199 + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]);
1201 + print_uint(PRINT_JSON, "bandwidth", NULL, bandwidth);
1202 + print_string(PRINT_FP, NULL, "bandwidth %s ", sprint_rate(bandwidth, b1));
1204 + print_string(PRINT_ANY, "bandwidth", "bandwidth %s ", "unlimited");
1206 + if (tb[TCA_CAKE_AUTORATE] &&
1207 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
1208 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
1210 + print_string(PRINT_ANY, "autorate", "autorate_%s ", "ingress");
1212 + print_string(PRINT_ANY, "autorate", "(?autorate?) ", "unknown");
1214 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
1215 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
1216 + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
1217 + switch(diffserv) {
1219 + print_string(PRINT_ANY, "diffserv", "%s ", "besteffort");
1222 + print_string(PRINT_ANY, "diffserv", "%s ", "precedence");
1225 + print_string(PRINT_ANY, "diffserv", "%s ", "diffserv8");
1228 + print_string(PRINT_ANY, "diffserv", "%s ", "diffserv4");
1231 + print_string(PRINT_ANY, "diffserv", "%s ", "diffserv-llt");
1234 + print_string(PRINT_ANY, "diffserv", "%s ", "diffserv3");
1237 + print_string(PRINT_ANY, "diffserv", "(?diffserv?) ", "unknown");
1241 + if (tb[TCA_CAKE_FLOW_MODE] &&
1242 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
1243 + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
1244 + nat = !!(flowmode & 64);
1246 + switch(flowmode) {
1248 + print_string(PRINT_ANY, "flowmode", "%s ", "flowblind");
1251 + print_string(PRINT_ANY, "flowmode", "%s ", "srchost");
1254 + print_string(PRINT_ANY, "flowmode", "%s ", "dsthost");
1257 + print_string(PRINT_ANY, "flowmode", "%s ", "hosts");
1260 + print_string(PRINT_ANY, "flowmode", "%s ", "flows");
1263 + print_string(PRINT_ANY, "flowmode", "%s ", "dual-srchost");
1266 + print_string(PRINT_ANY, "flowmode", "%s ", "dual-dsthost");
1269 + print_string(PRINT_ANY, "flowmode", "%s ", "triple-isolate");
1272 + print_string(PRINT_ANY, "flowmode", "(?flowmode?) ", "unknown");
1277 + print_string(PRINT_FP, NULL, "nat ", NULL);
1278 + print_bool(PRINT_JSON, "nat", NULL, nat);
1280 + if (tb[TCA_CAKE_WASH] &&
1281 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
1282 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
1284 + if (tb[TCA_CAKE_ATM] &&
1285 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
1286 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
1288 + if (tb[TCA_CAKE_OVERHEAD] &&
1289 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__u32)) {
1290 + overhead = rta_getattr_u32(tb[TCA_CAKE_OVERHEAD]);
1292 + if (tb[TCA_CAKE_MPU] &&
1293 + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
1294 + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
1296 + if (tb[TCA_CAKE_INGRESS] &&
1297 + RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
1298 + ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
1300 + if (tb[TCA_CAKE_ACK_FILTER] &&
1301 + RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
1302 + ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
1304 + if (tb[TCA_CAKE_RAW]) {
1307 + if (tb[TCA_CAKE_RTT] &&
1308 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
1309 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
1313 + print_string(PRINT_FP, NULL, "wash ", NULL);
1314 + print_bool(PRINT_JSON, "wash", NULL, wash);
1317 + print_string(PRINT_FP, NULL, "ingress ", NULL);
1318 + print_bool(PRINT_JSON, "ingress", NULL, ingress);
1320 + if (ack_filter == 0x0600)
1321 + print_string(PRINT_ANY, "ack-filter", "ack-filter-%s ", "aggressive");
1322 + else if (ack_filter)
1323 + print_string(PRINT_ANY, "ack-filter", "ack-filter ", "enabled");
1325 + print_string(PRINT_JSON, "ack-filter", NULL, "disabled");
1328 + print_string(PRINT_FP, NULL, "rtt %s ", sprint_time(interval, b2));
1329 + print_uint(PRINT_JSON, "rtt", NULL, interval);
1332 + print_string(PRINT_FP, NULL, "raw ", NULL);
1333 + print_bool(PRINT_JSON, "raw", NULL, raw);
1336 + print_string(PRINT_ANY, "atm", "%s ", "atm");
1337 + else if (atm == 2)
1338 + print_string(PRINT_ANY, "atm", "%s ", "ptm");
1340 + print_string(PRINT_ANY, "atm", "%s ", "noatm");
1342 + print_uint(PRINT_ANY, "overhead", "overhead %d ", overhead);
1345 + print_uint(PRINT_ANY, "mpu", "mpu %d ", mpu);
1348 + print_uint(PRINT_JSON, "memlimit", NULL, memlimit);
1349 + print_string(PRINT_FP, NULL, "memlimit %s", sprint_size(memlimit, b1));
1355 +#define FOR_EACH_TIN(xstats, tst, i) \
1356 + for(tst = xstats->tin_stats, i = 0; \
1357 + i < xstats->tin_cnt; \
1358 + i++, tst = ((void *) xstats->tin_stats) + xstats->tin_stats_size * i)
1360 +static void cake_print_json_tin(struct tc_cake_tin_stats *tst)
1362 + open_json_object(NULL);
1363 + print_uint(PRINT_JSON, "threshold_rate", NULL, tst->threshold_rate);
1364 + print_uint(PRINT_JSON, "target", NULL, tst->target_us);
1365 + print_uint(PRINT_JSON, "interval", NULL, tst->interval_us);
1366 + print_uint(PRINT_JSON, "peak_delay", NULL, tst->peak_delay_us);
1367 + print_uint(PRINT_JSON, "average_delay", NULL, tst->avge_delay_us);
1368 + print_uint(PRINT_JSON, "base_delay", NULL, tst->base_delay_us);
1369 + print_uint(PRINT_JSON, "sent_packets", NULL, tst->sent.packets);
1370 + print_uint(PRINT_JSON, "sent_bytes", NULL, tst->sent.bytes);
1371 + print_uint(PRINT_JSON, "way_indirect_hits", NULL, tst->way_indirect_hits);
1372 + print_uint(PRINT_JSON, "way_misses", NULL, tst->way_misses);
1373 + print_uint(PRINT_JSON, "way_collisions", NULL, tst->way_collisions);
1374 + print_uint(PRINT_JSON, "drops", NULL, tst->dropped.packets);
1375 + print_uint(PRINT_JSON, "ecn_mark", NULL, tst->ecn_marked.packets);
1376 + print_uint(PRINT_JSON, "ack_drops", NULL, tst->ack_drops.packets);
1377 + print_uint(PRINT_JSON, "sparse_flows", NULL, tst->sparse_flows);
1378 + print_uint(PRINT_JSON, "bulk_flows", NULL, tst->bulk_flows);
1379 + print_uint(PRINT_JSON, "unresponsive_flows", NULL, tst->unresponse_flows);
1380 + print_uint(PRINT_JSON, "max_pkt_len", NULL, tst->max_skblen);
1381 + close_json_object();
1384 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
1385 + struct rtattr *xstats)
1387 + struct tc_cake_xstats *stnc;
1388 + struct tc_cake_tin_stats *tst;
1392 + if (xstats == NULL)
1395 + if (RTA_PAYLOAD(xstats) < sizeof(*stnc))
1398 + stnc = RTA_DATA(xstats);
1400 + if (stnc->version < 0x101 ||
1401 + RTA_PAYLOAD(xstats) < (sizeof(struct tc_cake_xstats) +
1402 + stnc->tin_stats_size * stnc->tin_cnt))
1405 + print_uint(PRINT_JSON, "memory_used", NULL, stnc->memory_used);
1406 + print_uint(PRINT_JSON, "memory_limit", NULL, stnc->memory_limit);
1407 + print_uint(PRINT_JSON, "capacity_estimate", NULL, stnc->capacity_estimate);
1409 + print_string(PRINT_FP, NULL, " memory used: %s",
1410 + sprint_size(stnc->memory_used, b1));
1411 + print_string(PRINT_FP, NULL, " of %s\n",
1412 + sprint_size(stnc->memory_limit, b1));
1413 + print_string(PRINT_FP, NULL, " capacity estimate: %s\n",
1414 + sprint_rate(stnc->capacity_estimate, b1));
1416 + print_uint(PRINT_ANY, "min_transport_size", " min/max transport layer size: %10u",
1417 + stnc->min_trnlen);
1418 + print_uint(PRINT_ANY, "max_transport_size", " /%8u\n", stnc->max_trnlen);
1419 + print_uint(PRINT_ANY, "min_adj_size", " min/max overhead-adjusted size: %8u",
1420 + stnc->min_adjlen);
1421 + print_uint(PRINT_ANY, "max_adj_size", " /%8u\n", stnc->max_adjlen);
1422 + print_uint(PRINT_ANY, "avg_hdr_offset", " average transport hdr offset: %10u\n\n",
1423 + stnc->avg_trnoff);
1425 + if (is_json_context()) {
1426 + open_json_array(PRINT_JSON, "tins");
1427 + FOR_EACH_TIN(stnc, tst, i)
1428 + cake_print_json_tin(tst);
1429 + close_json_array(PRINT_JSON, NULL);
1434 + switch(stnc->tin_cnt) {
1436 + fprintf(f, " Bulk Best Effort Voice\n");
1440 + fprintf(f, " Bulk Best Effort Video Voice\n");
1444 + fprintf(f, " Low Loss Best Effort Low Delay Bulk Net Control\n");
1449 + for(i=0; i < stnc->tin_cnt; i++)
1450 + fprintf(f, " Tin %u", i);
1454 + fprintf(f, " thresh ");
1455 + FOR_EACH_TIN(stnc, tst, i)
1456 + fprintf(f, " %12s", sprint_rate(tst->threshold_rate, b1));
1459 + fprintf(f, " target ");
1460 + FOR_EACH_TIN(stnc, tst, i)
1461 + fprintf(f, " %12s", sprint_time(tst->target_us, b1));
1464 + fprintf(f, " interval");
1465 + FOR_EACH_TIN(stnc, tst, i)
1466 + fprintf(f, " %12s", sprint_time(tst->interval_us, b1));
1469 + fprintf(f, " pk_delay");
1470 + FOR_EACH_TIN(stnc, tst, i)
1471 + fprintf(f, " %12s", sprint_time(tst->peak_delay_us, b1));
1474 + fprintf(f, " av_delay");
1475 + FOR_EACH_TIN(stnc, tst, i)
1476 + fprintf(f, " %12s", sprint_time(tst->avge_delay_us, b1));
1479 + fprintf(f, " sp_delay");
1480 + FOR_EACH_TIN(stnc, tst, i)
1481 + fprintf(f, " %12s", sprint_time(tst->base_delay_us, b1));
1484 + fprintf(f, " pkts ");
1485 + FOR_EACH_TIN(stnc, tst, i)
1486 + fprintf(f, " %12u", tst->sent.packets);
1489 + fprintf(f, " bytes ");
1490 + FOR_EACH_TIN(stnc, tst, i)
1491 + fprintf(f, " %12llu", tst->sent.bytes);
1494 + fprintf(f, " way_inds");
1495 + FOR_EACH_TIN(stnc, tst, i)
1496 + fprintf(f, " %12u", tst->way_indirect_hits);
1499 + fprintf(f, " way_miss");
1500 + FOR_EACH_TIN(stnc, tst, i)
1501 + fprintf(f, " %12u", tst->way_misses);
1504 + fprintf(f, " way_cols");
1505 + FOR_EACH_TIN(stnc, tst, i)
1506 + fprintf(f, " %12u", tst->way_collisions);
1509 + fprintf(f, " drops ");
1510 + FOR_EACH_TIN(stnc, tst, i)
1511 + fprintf(f, " %12u", tst->dropped.packets);
1514 + fprintf(f, " marks ");
1515 + FOR_EACH_TIN(stnc, tst, i)
1516 + fprintf(f, " %12u", tst->ecn_marked.packets);
1519 + fprintf(f, " ack_drop");
1520 + FOR_EACH_TIN(stnc, tst, i)
1521 + fprintf(f, " %12u", tst->ack_drops.packets);
1524 + fprintf(f, " sp_flows");
1525 + FOR_EACH_TIN(stnc, tst, i)
1526 + fprintf(f, " %12u", tst->sparse_flows);
1529 + fprintf(f, " bk_flows");
1530 + FOR_EACH_TIN(stnc, tst, i)
1531 + fprintf(f, " %12u", tst->bulk_flows);
1534 + fprintf(f, " un_flows");
1535 + FOR_EACH_TIN(stnc, tst, i)
1536 + fprintf(f, " %12u", tst->unresponse_flows);
1539 + fprintf(f, " max_len ");
1540 + FOR_EACH_TIN(stnc, tst, i)
1541 + fprintf(f, " %12u", tst->max_skblen);
1547 +struct qdisc_util cake_qdisc_util = {
1549 + .parse_qopt = cake_parse_opt,
1550 + .print_qopt = cake_print_opt,
1551 + .print_xstats = cake_print_xstats,