1 --- a/include/linux/pkt_sched.h
2 +++ b/include/linux/pkt_sched.h
3 @@ -850,4 +850,56 @@ struct tc_pie_xstats {
4 __u32 maxq; /* maximum queue size */
5 __u32 ecn_mark; /* packets marked with ecn*/
12 + TCA_CAKE_DIFFSERV_MODE,
22 +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
24 +struct tc_cake_traffic_stats {
30 +#define TC_CAKE_MAX_TINS (8)
31 +struct tc_cake_xstats {
32 + __u16 version; /* == 4, increments when struct extended */
33 + __u8 max_tins; /* == TC_CAKE_MAX_TINS */
34 + __u8 tin_cnt; /* <= TC_CAKE_MAX_TINS */
36 + __u32 threshold_rate [TC_CAKE_MAX_TINS];
37 + __u32 target_us [TC_CAKE_MAX_TINS];
38 + struct tc_cake_traffic_stats sent [TC_CAKE_MAX_TINS];
39 + struct tc_cake_traffic_stats dropped [TC_CAKE_MAX_TINS];
40 + struct tc_cake_traffic_stats ecn_marked[TC_CAKE_MAX_TINS];
41 + struct tc_cake_traffic_stats backlog [TC_CAKE_MAX_TINS];
42 + __u32 interval_us [TC_CAKE_MAX_TINS];
43 + __u32 way_indirect_hits[TC_CAKE_MAX_TINS];
44 + __u32 way_misses [TC_CAKE_MAX_TINS];
45 + __u32 way_collisions [TC_CAKE_MAX_TINS];
46 + __u32 peak_delay_us [TC_CAKE_MAX_TINS]; /* ~= delay to bulk flows */
47 + __u32 avge_delay_us [TC_CAKE_MAX_TINS];
48 + __u32 base_delay_us [TC_CAKE_MAX_TINS]; /* ~= delay to sparse flows */
49 + __u16 sparse_flows [TC_CAKE_MAX_TINS];
50 + __u16 bulk_flows [TC_CAKE_MAX_TINS];
51 + __u16 unresponse_flows [TC_CAKE_MAX_TINS]; /* v4 - was u32 last_len */
52 + __u16 spare [TC_CAKE_MAX_TINS]; /* v4 - split last_len */
53 + __u32 max_skblen [TC_CAKE_MAX_TINS];
54 + __u32 capacity_estimate; /* version 2 */
55 + __u32 memory_limit; /* version 3 */
56 + __u32 memory_used; /* version 3 */
62 @@ -63,6 +63,7 @@ TCMODULES += q_codel.o
63 TCMODULES += q_fq_codel.o
66 +TCMODULES += q_cake.o
74 + * Common Applications Kept Enhanced -- CAKE
76 + * Copyright (C) 2014-2015 Jonathan Morton <chromatix99@gmail.com>
78 + * Redistribution and use in source and binary forms, with or without
79 + * modification, are permitted provided that the following conditions
81 + * 1. Redistributions of source code must retain the above copyright
82 + * notice, this list of conditions, and the following disclaimer,
83 + * without modification.
84 + * 2. Redistributions in binary form must reproduce the above copyright
85 + * notice, this list of conditions and the following disclaimer in the
86 + * documentation and/or other materials provided with the distribution.
87 + * 3. The names of the authors may not be used to endorse or promote products
88 + * derived from this software without specific prior written permission.
90 + * Alternatively, provided that this notice is retained in full, this
91 + * software may be distributed under the terms of the GNU General
92 + * Public License ("GPL") version 2, in which case the provisions of the
93 + * GPL apply INSTEAD OF those given above.
95 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
96 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
97 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
98 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
99 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
100 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
101 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
102 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
103 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
104 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
105 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
116 +#include <sys/socket.h>
117 +#include <netinet/in.h>
118 +#include <arpa/inet.h>
122 +#include "tc_util.h"
124 +static void explain(void)
126 + fprintf(stderr, "Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
127 + " [ rtt TIME | datacentre | lan | metro | regional | internet* | oceanic | satellite | interplanetary ]\n"
128 + " [ besteffort | precedence | diffserv8 | diffserv4* ]\n"
129 + " [ flowblind | srchost | dsthost | hosts | flows* | dual-srchost | dual-dsthost | triple-isolate ]\n"
130 + " [ atm | noatm* ] [ overhead N | conservative | raw* ]\n"
131 + " [ memlimit LIMIT ]\n"
132 + " (* marks defaults)\n");
135 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
136 + struct nlmsghdr *n)
139 + unsigned bandwidth = 0;
140 + unsigned interval = 0;
141 + unsigned target = 0;
142 + unsigned diffserv = 0;
143 + unsigned memlimit = 0;
145 + bool overhead_set = false;
149 + struct rtattr *tail;
152 + if (strcmp(*argv, "bandwidth") == 0) {
154 + if (get_rate(&bandwidth, *argv)) {
155 + fprintf(stderr, "Illegal \"bandwidth\"\n");
160 + } else if (strcmp(*argv, "unlimited") == 0) {
164 + } else if (strcmp(*argv, "autorate_ingress") == 0) {
167 + } else if (strcmp(*argv, "rtt") == 0) {
169 + if (get_time(&interval, *argv)) {
170 + fprintf(stderr, "Illegal \"rtt\"\n");
173 + target = interval / 20;
176 + } else if (strcmp(*argv, "datacentre") == 0) {
179 + } else if (strcmp(*argv, "lan") == 0) {
182 + } else if (strcmp(*argv, "metro") == 0) {
185 + } else if (strcmp(*argv, "regional") == 0) {
188 + } else if (strcmp(*argv, "internet") == 0) {
191 + } else if (strcmp(*argv, "oceanic") == 0) {
194 + } else if (strcmp(*argv, "satellite") == 0) {
195 + interval = 1000000;
197 + } else if (strcmp(*argv, "interplanetary") == 0) {
198 + interval = 3600000000U;
201 + } else if (strcmp(*argv, "besteffort") == 0) {
203 + } else if (strcmp(*argv, "precedence") == 0) {
205 + } else if (strcmp(*argv, "diffserv8") == 0) {
207 + } else if (strcmp(*argv, "diffserv4") == 0) {
209 + } else if (strcmp(*argv, "diffserv") == 0) {
211 + } else if (strcmp(*argv, "diffserv-llt") == 0) {
214 + } else if (strcmp(*argv, "flowblind") == 0) {
216 + } else if (strcmp(*argv, "srchost") == 0) {
218 + } else if (strcmp(*argv, "dsthost") == 0) {
220 + } else if (strcmp(*argv, "hosts") == 0) {
222 + } else if (strcmp(*argv, "flows") == 0) {
224 + } else if (strcmp(*argv, "dual-srchost") == 0) {
226 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
228 + } else if (strcmp(*argv, "triple-isolate") == 0) {
231 + } else if (strcmp(*argv, "atm") == 0) {
233 + } else if (strcmp(*argv, "noatm") == 0) {
236 + } else if (strcmp(*argv, "raw") == 0) {
239 + overhead_set = true;
240 + } else if (strcmp(*argv, "conservative") == 0) {
242 + * Deliberately over-estimate overhead:
243 + * one whole ATM cell plus ATM framing.
244 + * A safe choice if the actual overhead is unknown.
248 + overhead_set = true;
250 + /* Various ADSL framing schemes */
251 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
254 + overhead_set = true;
255 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
258 + overhead_set = true;
259 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
262 + overhead_set = true;
263 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
266 + overhead_set = true;
267 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
270 + overhead_set = true;
271 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
274 + overhead_set = true;
275 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
278 + overhead_set = true;
279 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
282 + overhead_set = true;
284 + /* Typical VDSL2 framing schemes */
285 + /* NB: PTM includes HDLC's 0x7D/7E expansion, adds extra 1/128 */
286 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
289 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
293 + } else if (strcmp(*argv, "via-ethernet") == 0) {
295 + * The above overheads are relative to an IP packet,
296 + * but if the physical interface is Ethernet, Linux
297 + * includes Ethernet framing overhead already.
300 + overhead_set = true;
302 + /* Additional Ethernet-related overheads used by some ISPs */
303 + } else if (strcmp(*argv, "ether-phy") == 0) {
304 + /* ethernet pre-amble & interframe gap 20 bytes
305 + * Linux will have already accounted for MACs & frame type 14 bytes
306 + * you probably want to add an FCS as well*/
308 + overhead_set = true;
309 + } else if (strcmp(*argv, "ether-all") == 0) {
310 + /* ethernet pre-amble & interframe gap & FCS
311 + * Linux will have already accounted for MACs & frame type 14 bytes
312 + * you may need to add vlan tag*/
314 + overhead_set = true;
316 + } else if (strcmp(*argv, "ether-fcs") == 0) {
317 + /* Frame Check Sequence */
318 + /* we ignore the minimum frame size, because IP packets usually meet it */
320 + overhead_set = true;
321 + } else if (strcmp(*argv, "ether-vlan") == 0) {
322 + /* 802.1q VLAN tag - may be repeated */
324 + overhead_set = true;
326 + } else if (strcmp(*argv, "overhead") == 0) {
329 + overhead = strtol(*argv, &p, 10);
330 + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
331 + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
334 + overhead_set = true;
336 + } else if (strcmp(*argv, "memlimit") == 0) {
338 + if(get_size(&memlimit, *argv)) {
339 + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
343 + } else if (strcmp(*argv, "help") == 0) {
347 + fprintf(stderr, "What is \"%s\"?\n", *argv);
354 + tail = NLMSG_TAIL(n);
355 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
356 + if (bandwidth || unlimited)
357 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth));
359 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
361 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
362 + if (flowmode != -1)
363 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
365 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
367 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
369 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
370 + if (autorate != -1)
371 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
373 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
375 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
380 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
382 + struct rtattr *tb[TCA_CAKE_MAX + 1];
383 + unsigned bandwidth = 0;
384 + unsigned diffserv = 0;
385 + unsigned flowmode = 0;
386 + unsigned interval = 0;
387 + unsigned memlimit = 0;
397 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
399 + if (tb[TCA_CAKE_BASE_RATE] &&
400 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) {
401 + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]);
403 + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1));
405 + fprintf(f, "unlimited ");
407 + if (tb[TCA_CAKE_AUTORATE] &&
408 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
409 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
411 + fprintf(f, "autorate_ingress ");
413 + fprintf(f, "(?autorate?) ");
415 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
416 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
417 + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
420 + fprintf(f, "besteffort ");
423 + fprintf(f, "precedence ");
426 + fprintf(f, "diffserv8 ");
429 + fprintf(f, "diffserv4 ");
432 + fprintf(f, "diffserv-llt ");
435 + fprintf(f, "(?diffserv?) ");
439 + if (tb[TCA_CAKE_FLOW_MODE] &&
440 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
441 + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
444 + fprintf(f, "flowblind ");
447 + fprintf(f, "srchost ");
450 + fprintf(f, "dsthost ");
453 + fprintf(f, "hosts ");
456 + fprintf(f, "flows ");
459 + fprintf(f, "dual-srchost ");
462 + fprintf(f, "dual-dsthost ");
465 + fprintf(f, "triple-isolate ");
468 + fprintf(f, "(?flowmode?) ");
472 + if (tb[TCA_CAKE_ATM] &&
473 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
474 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
476 + if (tb[TCA_CAKE_OVERHEAD] &&
477 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__u32)) {
478 + overhead = rta_getattr_u32(tb[TCA_CAKE_OVERHEAD]);
480 + if (tb[TCA_CAKE_RTT] &&
481 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
482 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
486 + fprintf(f, "rtt %s ", sprint_time(interval, b2));
489 + fprintf(f, "atm ");
491 + fprintf(f, "noatm ");
493 + if (overhead || atm)
494 + fprintf(f, "overhead %d ", overhead);
496 + if (!atm && !overhead)
497 + fprintf(f, "raw ");
500 + fprintf(f, "memlimit %s", sprint_size(memlimit, b1));
505 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
506 + struct rtattr *xstats)
508 + /* fq_codel stats format borrowed */
509 + struct tc_fq_codel_xstats *st;
510 + struct tc_cake_xstats *stnc;
514 + if (xstats == NULL)
517 + if (RTA_PAYLOAD(xstats) < sizeof(st->type))
520 + st = RTA_DATA(xstats);
521 + stnc = RTA_DATA(xstats);
523 + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
524 + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
525 + st->qdisc_stats.maxpacket,
526 + st->qdisc_stats.drop_overlimit,
527 + st->qdisc_stats.new_flow_count,
528 + st->qdisc_stats.ecn_mark);
529 + fprintf(f, "\n new_flows_len %u old_flows_len %u",
530 + st->qdisc_stats.new_flows_len,
531 + st->qdisc_stats.old_flows_len);
532 + } else if (st->type == TCA_FQ_CODEL_XSTATS_CLASS && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
533 + fprintf(f, " deficit %d count %u lastcount %u ldelay %s",
534 + st->class_stats.deficit,
535 + st->class_stats.count,
536 + st->class_stats.lastcount,
537 + sprint_time(st->class_stats.ldelay, b1));
538 + if (st->class_stats.dropping) {
539 + fprintf(f, " dropping");
540 + if (st->class_stats.drop_next < 0)
541 + fprintf(f, " drop_next -%s",
542 + sprint_time(-st->class_stats.drop_next, b1));
544 + fprintf(f, " drop_next %s",
545 + sprint_time(st->class_stats.drop_next, b1));
547 + } else if (stnc->version >= 1 && stnc->version < 0xFF
548 + && stnc->max_tins == TC_CAKE_MAX_TINS
549 + && RTA_PAYLOAD(xstats) >= offsetof(struct tc_cake_xstats, capacity_estimate))
553 + if(stnc->version >= 3)
554 + fprintf(f, " memory used: %s of %s\n", sprint_size(stnc->memory_used, b1), sprint_size(stnc->memory_limit, b2));
556 + if(stnc->version >= 2)
557 + fprintf(f, " capacity estimate: %s\n", sprint_rate(stnc->capacity_estimate, b1));
559 + switch(stnc->tin_cnt) {
561 + fprintf(f, " Bulk Best Effort Video Voice\n");
565 + fprintf(f, " Low Loss Best Effort Low Delay Bulk Net Control\n");
570 + for(i=0; i < stnc->tin_cnt; i++)
571 + fprintf(f, " Tin %u", i);
575 + fprintf(f, " thresh ");
576 + for(i=0; i < stnc->tin_cnt; i++)
577 + fprintf(f, "%12s", sprint_rate(stnc->threshold_rate[i], b1));
580 + fprintf(f, " target ");
581 + for(i=0; i < stnc->tin_cnt; i++)
582 + fprintf(f, "%12s", sprint_time(stnc->target_us[i], b1));
585 + fprintf(f, " interval");
586 + for(i=0; i < stnc->tin_cnt; i++)
587 + fprintf(f, "%12s", sprint_time(stnc->interval_us[i], b1));
590 + fprintf(f, " pk_delay");
591 + for(i=0; i < stnc->tin_cnt; i++)
592 + fprintf(f, "%12s", sprint_time(stnc->peak_delay_us[i], b1));
595 + fprintf(f, " av_delay");
596 + for(i=0; i < stnc->tin_cnt; i++)
597 + fprintf(f, "%12s", sprint_time(stnc->avge_delay_us[i], b1));
600 + fprintf(f, " sp_delay");
601 + for(i=0; i < stnc->tin_cnt; i++)
602 + fprintf(f, "%12s", sprint_time(stnc->base_delay_us[i], b1));
605 + fprintf(f, " pkts ");
606 + for(i=0; i < stnc->tin_cnt; i++)
607 + fprintf(f, "%12u", stnc->sent[i].packets);
610 + fprintf(f, " bytes ");
611 + for(i=0; i < stnc->tin_cnt; i++)
612 + fprintf(f, "%12llu", stnc->sent[i].bytes);
615 + fprintf(f, " way_inds");
616 + for(i=0; i < stnc->tin_cnt; i++)
617 + fprintf(f, "%12u", stnc->way_indirect_hits[i]);
620 + fprintf(f, " way_miss");
621 + for(i=0; i < stnc->tin_cnt; i++)
622 + fprintf(f, "%12u", stnc->way_misses[i]);
625 + fprintf(f, " way_cols");
626 + for(i=0; i < stnc->tin_cnt; i++)
627 + fprintf(f, "%12u", stnc->way_collisions[i]);
630 + fprintf(f, " drops ");
631 + for(i=0; i < stnc->tin_cnt; i++)
632 + fprintf(f, "%12u", stnc->dropped[i].packets);
635 + fprintf(f, " marks ");
636 + for(i=0; i < stnc->tin_cnt; i++)
637 + fprintf(f, "%12u", stnc->ecn_marked[i].packets);
640 + fprintf(f, " sp_flows");
641 + for(i=0; i < stnc->tin_cnt; i++)
642 + fprintf(f, "%12u", stnc->sparse_flows[i]);
645 + fprintf(f, " bk_flows");
646 + for(i=0; i < stnc->tin_cnt; i++)
647 + fprintf(f, "%12u", stnc->bulk_flows[i]);
650 + if(stnc->version >= 4) {
651 + fprintf(f, " un_flows");
652 + for(i=0; i < stnc->tin_cnt; i++)
653 + fprintf(f, "%12u", stnc->unresponse_flows[i]);
657 + fprintf(f, " max_len ");
658 + for(i=0; i < stnc->tin_cnt; i++)
659 + fprintf(f, "%12u", stnc->max_skblen[i]);
667 +struct qdisc_util cake_qdisc_util = {
669 + .parse_qopt = cake_parse_opt,
670 + .print_qopt = cake_print_opt,
671 + .print_xstats = cake_print_xstats,