1 --- a/include/linux/pkt_sched.h
2 +++ b/include/linux/pkt_sched.h
3 @@ -877,4 +877,55 @@ 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; /* == 3, 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 + __u32 last_skblen [TC_CAKE_MAX_TINS]; /* skb_headlen */
52 + __u32 max_skblen [TC_CAKE_MAX_TINS];
53 + __u32 capacity_estimate; /* version 2 */
54 + __u32 memory_limit; /* version 3 */
55 + __u32 memory_used; /* version 3 */
61 @@ -64,6 +64,7 @@ TCMODULES += q_codel.o
62 TCMODULES += q_fq_codel.o
65 +TCMODULES += q_cake.o
73 + * Common Applications Kept Enhanced -- CAKE
75 + * Copyright (C) 2014-2015 Jonathan Morton <chromatix99@gmail.com>
77 + * Redistribution and use in source and binary forms, with or without
78 + * modification, are permitted provided that the following conditions
80 + * 1. Redistributions of source code must retain the above copyright
81 + * notice, this list of conditions, and the following disclaimer,
82 + * without modification.
83 + * 2. Redistributions in binary form must reproduce the above copyright
84 + * notice, this list of conditions and the following disclaimer in the
85 + * documentation and/or other materials provided with the distribution.
86 + * 3. The names of the authors may not be used to endorse or promote products
87 + * derived from this software without specific prior written permission.
89 + * Alternatively, provided that this notice is retained in full, this
90 + * software may be distributed under the terms of the GNU General
91 + * Public License ("GPL") version 2, in which case the provisions of the
92 + * GPL apply INSTEAD OF those given above.
94 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
95 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
96 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
97 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
98 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
99 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
100 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
101 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
102 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
103 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
104 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
115 +#include <sys/socket.h>
116 +#include <netinet/in.h>
117 +#include <arpa/inet.h>
121 +#include "tc_util.h"
123 +static void explain(void)
125 + fprintf(stderr, "Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
126 + " [ rtt TIME | datacentre | lan | metro | regional | internet* | oceanic | satellite | interplanetary ]\n"
127 + " [ besteffort | precedence | diffserv8 | diffserv4* ]\n"
128 + " [ flowblind | srchost | dsthost | hosts | flows* | dual-srchost | dual-dsthost | triple-isolate ]\n"
129 + " [ atm | noatm* ] [ overhead N | conservative | raw* ]\n"
130 + " [ memlimit LIMIT ]\n"
131 + " (* marks defaults)\n");
134 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
135 + struct nlmsghdr *n)
138 + unsigned bandwidth = 0;
139 + unsigned interval = 0;
140 + unsigned target = 0;
141 + unsigned diffserv = 0;
142 + unsigned memlimit = 0;
144 + bool overhead_set = false;
148 + struct rtattr *tail;
151 + if (strcmp(*argv, "bandwidth") == 0) {
153 + if (get_rate(&bandwidth, *argv)) {
154 + fprintf(stderr, "Illegal \"bandwidth\"\n");
159 + } else if (strcmp(*argv, "unlimited") == 0) {
163 + } else if (strcmp(*argv, "autorate_ingress") == 0) {
166 + } else if (strcmp(*argv, "rtt") == 0) {
168 + if (get_time(&interval, *argv)) {
169 + fprintf(stderr, "Illegal \"rtt\"\n");
172 + target = interval / 20;
175 + } else if (strcmp(*argv, "datacentre") == 0) {
178 + } else if (strcmp(*argv, "lan") == 0) {
181 + } else if (strcmp(*argv, "metro") == 0) {
184 + } else if (strcmp(*argv, "regional") == 0) {
187 + } else if (strcmp(*argv, "internet") == 0) {
190 + } else if (strcmp(*argv, "oceanic") == 0) {
193 + } else if (strcmp(*argv, "satellite") == 0) {
194 + interval = 1000000;
196 + } else if (strcmp(*argv, "interplanetary") == 0) {
197 + interval = 3600000000U;
200 + } else if (strcmp(*argv, "besteffort") == 0) {
202 + } else if (strcmp(*argv, "precedence") == 0) {
204 + } else if (strcmp(*argv, "diffserv8") == 0) {
206 + } else if (strcmp(*argv, "diffserv4") == 0) {
208 + } else if (strcmp(*argv, "diffserv") == 0) {
210 + } else if (strcmp(*argv, "diffserv-llt") == 0) {
213 + } else if (strcmp(*argv, "flowblind") == 0) {
215 + } else if (strcmp(*argv, "srchost") == 0) {
217 + } else if (strcmp(*argv, "dsthost") == 0) {
219 + } else if (strcmp(*argv, "hosts") == 0) {
221 + } else if (strcmp(*argv, "flows") == 0) {
223 + } else if (strcmp(*argv, "dual-srchost") == 0) {
225 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
227 + } else if (strcmp(*argv, "triple-isolate") == 0) {
230 + } else if (strcmp(*argv, "atm") == 0) {
232 + } else if (strcmp(*argv, "noatm") == 0) {
235 + } else if (strcmp(*argv, "raw") == 0) {
238 + overhead_set = true;
239 + } else if (strcmp(*argv, "conservative") == 0) {
241 + * Deliberately over-estimate overhead:
242 + * one whole ATM cell plus ATM framing.
243 + * A safe choice if the actual overhead is unknown.
247 + overhead_set = true;
249 + /* Various ADSL framing schemes */
250 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
253 + overhead_set = true;
254 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
257 + overhead_set = true;
258 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
261 + overhead_set = true;
262 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
265 + overhead_set = true;
266 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
269 + overhead_set = true;
270 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
273 + overhead_set = true;
274 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
277 + overhead_set = true;
278 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
281 + overhead_set = true;
283 + /* Typical VDSL2 framing schemes */
284 + /* NB: PTM includes HDLC's 0x7D/7E expansion, adds extra 1/128 */
285 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
288 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
292 + } else if (strcmp(*argv, "via-ethernet") == 0) {
294 + * The above overheads are relative to an IP packet,
295 + * but if the physical interface is Ethernet, Linux
296 + * includes Ethernet framing overhead already.
299 + overhead_set = true;
301 + /* Additional Ethernet-related overheads used by some ISPs */
302 + } else if (strcmp(*argv, "ether-phy") == 0) {
303 + /* ethernet pre-amble & interframe gap 20 bytes
304 + * Linux will have already accounted for MACs & frame type 14 bytes
305 + * you probably want to add an FCS as well*/
307 + overhead_set = true;
308 + } else if (strcmp(*argv, "ether-all") == 0) {
309 + /* ethernet pre-amble & interframe gap & FCS
310 + * Linux will have already accounted for MACs & frame type 14 bytes
311 + * you may need to add vlan tag*/
313 + overhead_set = true;
315 + } else if (strcmp(*argv, "ether-fcs") == 0) {
316 + /* Frame Check Sequence */
317 + /* we ignore the minimum frame size, because IP packets usually meet it */
319 + overhead_set = true;
320 + } else if (strcmp(*argv, "ether-vlan") == 0) {
321 + /* 802.1q VLAN tag - may be repeated */
323 + overhead_set = true;
325 + } else if (strcmp(*argv, "overhead") == 0) {
328 + overhead = strtol(*argv, &p, 10);
329 + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
330 + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
333 + overhead_set = true;
335 + } else if (strcmp(*argv, "memlimit") == 0) {
337 + if(get_size(&memlimit, *argv)) {
338 + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
342 + } else if (strcmp(*argv, "help") == 0) {
346 + fprintf(stderr, "What is \"%s\"?\n", *argv);
353 + tail = NLMSG_TAIL(n);
354 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
355 + if (bandwidth || unlimited)
356 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth));
358 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
360 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
361 + if (flowmode != -1)
362 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
364 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
366 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
368 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
369 + if (autorate != -1)
370 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
372 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
374 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
379 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
381 + struct rtattr *tb[TCA_CAKE_MAX + 1];
382 + unsigned bandwidth = 0;
383 + unsigned diffserv = 0;
384 + unsigned flowmode = 0;
385 + unsigned interval = 0;
386 + unsigned memlimit = 0;
396 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
398 + if (tb[TCA_CAKE_BASE_RATE] &&
399 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) {
400 + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]);
402 + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1));
404 + fprintf(f, "unlimited ");
406 + if (tb[TCA_CAKE_AUTORATE] &&
407 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
408 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
410 + fprintf(f, "autorate_ingress ");
412 + fprintf(f, "(?autorate?) ");
414 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
415 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
416 + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
419 + fprintf(f, "besteffort ");
422 + fprintf(f, "precedence ");
425 + fprintf(f, "diffserv8 ");
428 + fprintf(f, "diffserv4 ");
431 + fprintf(f, "diffserv-llt ");
434 + fprintf(f, "(?diffserv?) ");
438 + if (tb[TCA_CAKE_FLOW_MODE] &&
439 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
440 + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
443 + fprintf(f, "flowblind ");
446 + fprintf(f, "srchost ");
449 + fprintf(f, "dsthost ");
452 + fprintf(f, "hosts ");
455 + fprintf(f, "flows ");
458 + fprintf(f, "dual-srchost ");
461 + fprintf(f, "dual-dsthost ");
464 + fprintf(f, "triple-isolate ");
467 + fprintf(f, "(?flowmode?) ");
471 + if (tb[TCA_CAKE_ATM] &&
472 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
473 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
475 + if (tb[TCA_CAKE_OVERHEAD] &&
476 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__u32)) {
477 + overhead = rta_getattr_u32(tb[TCA_CAKE_OVERHEAD]);
479 + if (tb[TCA_CAKE_RTT] &&
480 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
481 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
485 + fprintf(f, "rtt %s ", sprint_time(interval, b2));
488 + fprintf(f, "atm ");
490 + fprintf(f, "noatm ");
492 + if (overhead || atm)
493 + fprintf(f, "overhead %d ", overhead);
495 + if (!atm && !overhead)
496 + fprintf(f, "raw ");
499 + fprintf(f, "memlimit %s", sprint_size(memlimit, b1));
504 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
505 + struct rtattr *xstats)
507 + /* fq_codel stats format borrowed */
508 + struct tc_fq_codel_xstats *st;
509 + struct tc_cake_xstats *stnc;
513 + if (xstats == NULL)
516 + if (RTA_PAYLOAD(xstats) < sizeof(st->type))
519 + st = RTA_DATA(xstats);
520 + stnc = RTA_DATA(xstats);
522 + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
523 + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
524 + st->qdisc_stats.maxpacket,
525 + st->qdisc_stats.drop_overlimit,
526 + st->qdisc_stats.new_flow_count,
527 + st->qdisc_stats.ecn_mark);
528 + fprintf(f, "\n new_flows_len %u old_flows_len %u",
529 + st->qdisc_stats.new_flows_len,
530 + st->qdisc_stats.old_flows_len);
531 + } else if (st->type == TCA_FQ_CODEL_XSTATS_CLASS && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
532 + fprintf(f, " deficit %d count %u lastcount %u ldelay %s",
533 + st->class_stats.deficit,
534 + st->class_stats.count,
535 + st->class_stats.lastcount,
536 + sprint_time(st->class_stats.ldelay, b1));
537 + if (st->class_stats.dropping) {
538 + fprintf(f, " dropping");
539 + if (st->class_stats.drop_next < 0)
540 + fprintf(f, " drop_next -%s",
541 + sprint_time(-st->class_stats.drop_next, b1));
543 + fprintf(f, " drop_next %s",
544 + sprint_time(st->class_stats.drop_next, b1));
546 + } else if (stnc->version >= 1 && stnc->version < 0xFF
547 + && stnc->max_tins == TC_CAKE_MAX_TINS
548 + && RTA_PAYLOAD(xstats) >= offsetof(struct tc_cake_xstats, capacity_estimate))
552 + if(stnc->version >= 3)
553 + fprintf(f, " memory used: %s of %s\n", sprint_size(stnc->memory_used, b1), sprint_size(stnc->memory_limit, b2));
555 + if(stnc->version >= 2)
556 + fprintf(f, " capacity estimate: %s\n", sprint_rate(stnc->capacity_estimate, b1));
558 + switch(stnc->tin_cnt) {
560 + fprintf(f, " Bulk Best Effort Video Voice\n");
564 + fprintf(f, " Low Loss Best Effort Low Delay Bulk Net Control\n");
569 + for(i=0; i < stnc->tin_cnt; i++)
570 + fprintf(f, " Tin %u", i);
574 + fprintf(f, " thresh ");
575 + for(i=0; i < stnc->tin_cnt; i++)
576 + fprintf(f, "%12s", sprint_rate(stnc->threshold_rate[i], b1));
579 + fprintf(f, " target ");
580 + for(i=0; i < stnc->tin_cnt; i++)
581 + fprintf(f, "%12s", sprint_time(stnc->target_us[i], b1));
584 + fprintf(f, " interval");
585 + for(i=0; i < stnc->tin_cnt; i++)
586 + fprintf(f, "%12s", sprint_time(stnc->interval_us[i], b1));
589 + fprintf(f, " pk_delay");
590 + for(i=0; i < stnc->tin_cnt; i++)
591 + fprintf(f, "%12s", sprint_time(stnc->peak_delay_us[i], b1));
594 + fprintf(f, " av_delay");
595 + for(i=0; i < stnc->tin_cnt; i++)
596 + fprintf(f, "%12s", sprint_time(stnc->avge_delay_us[i], b1));
599 + fprintf(f, " sp_delay");
600 + for(i=0; i < stnc->tin_cnt; i++)
601 + fprintf(f, "%12s", sprint_time(stnc->base_delay_us[i], b1));
604 + fprintf(f, " pkts ");
605 + for(i=0; i < stnc->tin_cnt; i++)
606 + fprintf(f, "%12u", stnc->sent[i].packets);
609 + fprintf(f, " bytes ");
610 + for(i=0; i < stnc->tin_cnt; i++)
611 + fprintf(f, "%12llu", stnc->sent[i].bytes);
614 + fprintf(f, " way_inds");
615 + for(i=0; i < stnc->tin_cnt; i++)
616 + fprintf(f, "%12u", stnc->way_indirect_hits[i]);
619 + fprintf(f, " way_miss");
620 + for(i=0; i < stnc->tin_cnt; i++)
621 + fprintf(f, "%12u", stnc->way_misses[i]);
624 + fprintf(f, " way_cols");
625 + for(i=0; i < stnc->tin_cnt; i++)
626 + fprintf(f, "%12u", stnc->way_collisions[i]);
629 + fprintf(f, " drops ");
630 + for(i=0; i < stnc->tin_cnt; i++)
631 + fprintf(f, "%12u", stnc->dropped[i].packets);
634 + fprintf(f, " marks ");
635 + for(i=0; i < stnc->tin_cnt; i++)
636 + fprintf(f, "%12u", stnc->ecn_marked[i].packets);
639 + fprintf(f, " sp_flows");
640 + for(i=0; i < stnc->tin_cnt; i++)
641 + fprintf(f, "%12u", stnc->sparse_flows[i]);
644 + fprintf(f, " bk_flows");
645 + for(i=0; i < stnc->tin_cnt; i++)
646 + fprintf(f, "%12u", stnc->bulk_flows[i]);
649 + fprintf(f, " last_len");
650 + for(i=0; i < stnc->tin_cnt; i++)
651 + fprintf(f, "%12u", stnc->last_skblen[i]);
654 + fprintf(f, " max_len ");
655 + for(i=0; i < stnc->tin_cnt; i++)
656 + fprintf(f, "%12u", stnc->max_skblen[i]);
664 +struct qdisc_util cake_qdisc_util = {
666 + .parse_qopt = cake_parse_opt,
667 + .print_qopt = cake_print_opt,
668 + .print_xstats = cake_print_xstats,