iproute2: support latest cake & restore DSCP washing
[openwrt/openwrt.git] / package / network / utils / iproute2 / patches / 950-add-cake-to-tc.patch
1 diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h
2 index 8d2530d..028b83c 100644
3 --- a/include/linux/pkt_sched.h
4 +++ b/include/linux/pkt_sched.h
5 @@ -850,4 +850,59 @@ struct tc_pie_xstats {
6 __u32 maxq; /* maximum queue size */
7 __u32 ecn_mark; /* packets marked with ecn*/
8 };
9 +
10 +/* CAKE */
11 +enum {
12 + TCA_CAKE_UNSPEC,
13 + TCA_CAKE_BASE_RATE,
14 + TCA_CAKE_DIFFSERV_MODE,
15 + TCA_CAKE_ATM,
16 + TCA_CAKE_FLOW_MODE,
17 + TCA_CAKE_OVERHEAD,
18 + TCA_CAKE_RTT,
19 + TCA_CAKE_TARGET,
20 + TCA_CAKE_AUTORATE,
21 + TCA_CAKE_MEMORY,
22 + TCA_CAKE_NAT,
23 + TCA_CAKE_ETHERNET,
24 + TCA_CAKE_WASH,
25 + __TCA_CAKE_MAX
26 +};
27 +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1)
28 +
29 +struct tc_cake_traffic_stats {
30 + __u32 packets;
31 + __u32 link_ms;
32 + __u64 bytes;
33 +};
34 +
35 +#define TC_CAKE_MAX_TINS (8)
36 +struct tc_cake_xstats {
37 + __u16 version; /* == 4, increments when struct extended */
38 + __u8 max_tins; /* == TC_CAKE_MAX_TINS */
39 + __u8 tin_cnt; /* <= TC_CAKE_MAX_TINS */
40 +
41 + __u32 threshold_rate [TC_CAKE_MAX_TINS];
42 + __u32 target_us [TC_CAKE_MAX_TINS];
43 + struct tc_cake_traffic_stats sent [TC_CAKE_MAX_TINS];
44 + struct tc_cake_traffic_stats dropped [TC_CAKE_MAX_TINS];
45 + struct tc_cake_traffic_stats ecn_marked[TC_CAKE_MAX_TINS];
46 + struct tc_cake_traffic_stats backlog [TC_CAKE_MAX_TINS];
47 + __u32 interval_us [TC_CAKE_MAX_TINS];
48 + __u32 way_indirect_hits[TC_CAKE_MAX_TINS];
49 + __u32 way_misses [TC_CAKE_MAX_TINS];
50 + __u32 way_collisions [TC_CAKE_MAX_TINS];
51 + __u32 peak_delay_us [TC_CAKE_MAX_TINS]; /* ~= delay to bulk flows */
52 + __u32 avge_delay_us [TC_CAKE_MAX_TINS];
53 + __u32 base_delay_us [TC_CAKE_MAX_TINS]; /* ~= delay to sparse flows */
54 + __u16 sparse_flows [TC_CAKE_MAX_TINS];
55 + __u16 bulk_flows [TC_CAKE_MAX_TINS];
56 + __u16 unresponse_flows [TC_CAKE_MAX_TINS]; /* v4 - was u32 last_len */
57 + __u16 spare [TC_CAKE_MAX_TINS]; /* v4 - split last_len */
58 + __u32 max_skblen [TC_CAKE_MAX_TINS];
59 + __u32 capacity_estimate; /* version 2 */
60 + __u32 memory_limit; /* version 3 */
61 + __u32 memory_used; /* version 3 */
62 +};
63 +
64 #endif
65 diff --git a/tc/Makefile b/tc/Makefile
66 index 56acbaa..d421b8e 100644
67 --- a/tc/Makefile
68 +++ b/tc/Makefile
69 @@ -63,6 +63,7 @@ TCMODULES += q_codel.o
70 TCMODULES += q_fq_codel.o
71 TCMODULES += q_fq.o
72 TCMODULES += q_pie.o
73 +TCMODULES += q_cake.o
74 TCMODULES += q_hhf.o
75 TCMODULES += e_bpf.o
76
77 diff --git a/tc/q_cake.c b/tc/q_cake.c
78 new file mode 100644
79 index 0000000..14e5aab
80 --- /dev/null
81 +++ b/tc/q_cake.c
82 @@ -0,0 +1,654 @@
83 +/*
84 + * Common Applications Kept Enhanced -- CAKE
85 + *
86 + * Copyright (C) 2014-2015 Jonathan Morton <chromatix99@gmail.com>
87 + *
88 + * Redistribution and use in source and binary forms, with or without
89 + * modification, are permitted provided that the following conditions
90 + * are met:
91 + * 1. Redistributions of source code must retain the above copyright
92 + * notice, this list of conditions, and the following disclaimer,
93 + * without modification.
94 + * 2. Redistributions in binary form must reproduce the above copyright
95 + * notice, this list of conditions and the following disclaimer in the
96 + * documentation and/or other materials provided with the distribution.
97 + * 3. The names of the authors may not be used to endorse or promote products
98 + * derived from this software without specific prior written permission.
99 + *
100 + * Alternatively, provided that this notice is retained in full, this
101 + * software may be distributed under the terms of the GNU General
102 + * Public License ("GPL") version 2, in which case the provisions of the
103 + * GPL apply INSTEAD OF those given above.
104 + *
105 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
106 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
107 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
108 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
109 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
110 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
111 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
112 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
113 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
114 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
115 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
116 + * DAMAGE.
117 + *
118 + */
119 +
120 +#include <stddef.h>
121 +#include <stdio.h>
122 +#include <stdlib.h>
123 +#include <unistd.h>
124 +#include <syslog.h>
125 +#include <fcntl.h>
126 +#include <sys/socket.h>
127 +#include <netinet/in.h>
128 +#include <arpa/inet.h>
129 +#include <string.h>
130 +
131 +#include "utils.h"
132 +#include "tc_util.h"
133 +
134 +static void explain(void)
135 +{
136 + fprintf(stderr, "Usage: ... cake [ bandwidth RATE | unlimited* | autorate_ingress ]\n"
137 + " [ rtt TIME | datacentre | lan | metro | regional | internet* | oceanic | satellite | interplanetary ]\n"
138 + " [ besteffort | precedence | diffserv8 | diffserv4* ]\n"
139 + " [ flowblind | srchost | dsthost | hosts | flows* | dual-srchost | dual-dsthost | triple-isolate ] [ nat | nonat* ]\n"
140 + " [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
141 + " [ wash | nowash* ]\n"
142 + " [ memlimit LIMIT ]\n"
143 + " (* marks defaults)\n");
144 +}
145 +
146 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
147 + struct nlmsghdr *n)
148 +{
149 + int unlimited = 0;
150 + unsigned bandwidth = 0;
151 + unsigned interval = 0;
152 + unsigned target = 0;
153 + unsigned diffserv = 0;
154 + unsigned memlimit = 0;
155 + int overhead = 0;
156 + bool overhead_set = false;
157 + bool overhead_override = false;
158 + int wash = -1;
159 + int flowmode = -1;
160 + int nat = -1;
161 + int atm = -1;
162 + int autorate = -1;
163 + struct rtattr *tail;
164 +
165 + while (argc > 0) {
166 + if (strcmp(*argv, "bandwidth") == 0) {
167 + NEXT_ARG();
168 + if (get_rate(&bandwidth, *argv)) {
169 + fprintf(stderr, "Illegal \"bandwidth\"\n");
170 + return -1;
171 + }
172 + unlimited = 0;
173 + autorate = 0;
174 + } else if (strcmp(*argv, "unlimited") == 0) {
175 + bandwidth = 0;
176 + unlimited = 1;
177 + autorate = 0;
178 + } else if (strcmp(*argv, "autorate_ingress") == 0) {
179 + autorate = 1;
180 +
181 + } else if (strcmp(*argv, "rtt") == 0) {
182 + NEXT_ARG();
183 + if (get_time(&interval, *argv)) {
184 + fprintf(stderr, "Illegal \"rtt\"\n");
185 + return -1;
186 + }
187 + target = interval / 20;
188 + if(!target)
189 + target = 1;
190 + } else if (strcmp(*argv, "datacentre") == 0) {
191 + interval = 100;
192 + target = 5;
193 + } else if (strcmp(*argv, "lan") == 0) {
194 + interval = 1000;
195 + target = 50;
196 + } else if (strcmp(*argv, "metro") == 0) {
197 + interval = 10000;
198 + target = 500;
199 + } else if (strcmp(*argv, "regional") == 0) {
200 + interval = 30000;
201 + target = 1500;
202 + } else if (strcmp(*argv, "internet") == 0) {
203 + interval = 100000;
204 + target = 5000;
205 + } else if (strcmp(*argv, "oceanic") == 0) {
206 + interval = 300000;
207 + target = 15000;
208 + } else if (strcmp(*argv, "satellite") == 0) {
209 + interval = 1000000;
210 + target = 50000;
211 + } else if (strcmp(*argv, "interplanetary") == 0) {
212 + interval = 3600000000U;
213 + target = 5000;
214 +
215 + } else if (strcmp(*argv, "besteffort") == 0) {
216 + diffserv = 1;
217 + } else if (strcmp(*argv, "precedence") == 0) {
218 + diffserv = 2;
219 + } else if (strcmp(*argv, "diffserv8") == 0) {
220 + diffserv = 3;
221 + } else if (strcmp(*argv, "diffserv4") == 0) {
222 + diffserv = 4;
223 + } else if (strcmp(*argv, "diffserv") == 0) {
224 + diffserv = 4;
225 + } else if (strcmp(*argv, "diffserv-llt") == 0) {
226 + diffserv = 5;
227 +
228 + } else if (strcmp(*argv, "nowash") == 0) {
229 + wash = 0;
230 + } else if (strcmp(*argv, "wash") == 0) {
231 + wash = 1;
232 +
233 + } else if (strcmp(*argv, "flowblind") == 0) {
234 + flowmode = 0;
235 + } else if (strcmp(*argv, "srchost") == 0) {
236 + flowmode = 1;
237 + } else if (strcmp(*argv, "dsthost") == 0) {
238 + flowmode = 2;
239 + } else if (strcmp(*argv, "hosts") == 0) {
240 + flowmode = 3;
241 + } else if (strcmp(*argv, "flows") == 0) {
242 + flowmode = 4;
243 + } else if (strcmp(*argv, "dual-srchost") == 0) {
244 + flowmode = 5;
245 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
246 + flowmode = 6;
247 + } else if (strcmp(*argv, "triple-isolate") == 0) {
248 + flowmode = 7;
249 +
250 + } else if (strcmp(*argv, "nat") == 0) {
251 + nat = 1;
252 + } else if (strcmp(*argv, "nonat") == 0) {
253 + nat = 0;
254 +
255 + } else if (strcmp(*argv, "ptm") == 0) {
256 + atm = 2;
257 + } else if (strcmp(*argv, "atm") == 0) {
258 + atm = 1;
259 + } else if (strcmp(*argv, "noatm") == 0) {
260 + atm = 0;
261 +
262 + } else if (strcmp(*argv, "raw") == 0) {
263 + atm = 0;
264 + overhead = 0;
265 + overhead_set = true;
266 + overhead_override = true;
267 + } else if (strcmp(*argv, "conservative") == 0) {
268 + /*
269 + * Deliberately over-estimate overhead:
270 + * one whole ATM cell plus ATM framing.
271 + * A safe choice if the actual overhead is unknown.
272 + */
273 + atm = 1;
274 + overhead = 48;
275 + overhead_set = true;
276 +
277 + /* Various ADSL framing schemes, all over ATM cells */
278 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
279 + atm = 1;
280 + overhead += 8;
281 + overhead_set = true;
282 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
283 + atm = 1;
284 + overhead += 16;
285 + overhead_set = true;
286 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
287 + atm = 1;
288 + overhead += 24;
289 + overhead_set = true;
290 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
291 + atm = 1;
292 + overhead += 32;
293 + overhead_set = true;
294 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
295 + atm = 1;
296 + overhead += 10;
297 + overhead_set = true;
298 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
299 + atm = 1;
300 + overhead += 14;
301 + overhead_set = true;
302 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
303 + atm = 1;
304 + overhead += 32;
305 + overhead_set = true;
306 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
307 + atm = 1;
308 + overhead += 40;
309 + overhead_set = true;
310 +
311 + /* Typical VDSL2 framing schemes, both over PTM */
312 + /* PTM has 64b/65b coding which absorbs some bandwidth */
313 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
314 + atm = 2;
315 + overhead += 27;
316 + overhead_set = true;
317 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
318 + atm = 2;
319 + overhead += 19;
320 + overhead_set = true;
321 +
322 + } else if (strcmp(*argv, "via-ethernet") == 0) {
323 + /*
324 + * We used to use this flag to manually compensate for
325 + * Linux including the Ethernet header on Ethernet-type
326 + * interfaces, but not on IP-type interfaces.
327 + *
328 + * It is no longer needed, because Cake now adjusts for
329 + * that automatically, and is thus ignored.
330 + *
331 + * It would be deleted entirely, but it appears in the
332 + * stats output when the automatic compensation is active.
333 + */
334 +
335 + } else if (strcmp(*argv, "ethernet") == 0) {
336 + /* ethernet pre-amble & interframe gap & FCS
337 + * you may need to add vlan tag */
338 + overhead += 38;
339 + overhead_set = true;
340 +
341 + /* Additional Ethernet-related overhead used by some ISPs */
342 + } else if (strcmp(*argv, "ether-vlan") == 0) {
343 + /* 802.1q VLAN tag - may be repeated */
344 + overhead += 4;
345 + overhead_set = true;
346 +
347 + /*
348 + * DOCSIS cable shapers account for Ethernet frame with FCS,
349 + * but not interframe gap nor preamble.
350 + */
351 + } else if (strcmp(*argv, "docsis") == 0) {
352 + atm = 0;
353 + overhead += 18;
354 + overhead_set = true;
355 +
356 + } else if (strcmp(*argv, "overhead") == 0) {
357 + char* p = NULL;
358 + NEXT_ARG();
359 + overhead = strtol(*argv, &p, 10);
360 + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
361 + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
362 + return -1;
363 + }
364 + overhead_set = true;
365 +
366 + } else if (strcmp(*argv, "memlimit") == 0) {
367 + NEXT_ARG();
368 + if(get_size(&memlimit, *argv)) {
369 + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
370 + return -1;
371 + }
372 +
373 + } else if (strcmp(*argv, "help") == 0) {
374 + explain();
375 + return -1;
376 + } else {
377 + fprintf(stderr, "What is \"%s\"?\n", *argv);
378 + explain();
379 + return -1;
380 + }
381 + argc--; argv++;
382 + }
383 +
384 + tail = NLMSG_TAIL(n);
385 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
386 + if (bandwidth || unlimited)
387 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth));
388 + if (diffserv)
389 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
390 + if (atm != -1)
391 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
392 + if (flowmode != -1)
393 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
394 + if (overhead_set)
395 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
396 + if (overhead_override) {
397 + unsigned zero = 0;
398 + addattr_l(n, 1024, TCA_CAKE_ETHERNET, &zero, sizeof(zero));
399 + }
400 + if (interval)
401 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
402 + if (target)
403 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
404 + if (autorate != -1)
405 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
406 + if (memlimit)
407 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
408 + if (nat != -1)
409 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
410 + if (wash != -1)
411 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
412 +
413 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
414 + return 0;
415 +}
416 +
417 +
418 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
419 +{
420 + struct rtattr *tb[TCA_CAKE_MAX + 1];
421 + unsigned bandwidth = 0;
422 + unsigned diffserv = 0;
423 + unsigned flowmode = 0;
424 + unsigned interval = 0;
425 + unsigned memlimit = 0;
426 + int overhead = 0;
427 + int ethernet = 0;
428 + int atm = 0;
429 + int nat = 0;
430 + int autorate = 0;
431 + int wash = 0;
432 + SPRINT_BUF(b1);
433 + SPRINT_BUF(b2);
434 +
435 + if (opt == NULL)
436 + return 0;
437 +
438 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
439 +
440 + if (tb[TCA_CAKE_BASE_RATE] &&
441 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) {
442 + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]);
443 + if(bandwidth)
444 + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1));
445 + else
446 + fprintf(f, "unlimited ");
447 + }
448 + if (tb[TCA_CAKE_AUTORATE] &&
449 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
450 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
451 + if(autorate == 1)
452 + fprintf(f, "autorate_ingress ");
453 + else if(autorate)
454 + fprintf(f, "(?autorate?) ");
455 + }
456 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
457 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
458 + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
459 + switch(diffserv) {
460 + case 1:
461 + fprintf(f, "besteffort ");
462 + break;
463 + case 2:
464 + fprintf(f, "precedence ");
465 + break;
466 + case 3:
467 + fprintf(f, "diffserv8 ");
468 + break;
469 + case 4:
470 + fprintf(f, "diffserv4 ");
471 + break;
472 + case 5:
473 + fprintf(f, "diffserv-llt ");
474 + break;
475 + default:
476 + fprintf(f, "(?diffserv?) ");
477 + break;
478 + };
479 + }
480 + if (tb[TCA_CAKE_FLOW_MODE] &&
481 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
482 + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
483 + nat = !!(flowmode & 64);
484 + flowmode &= ~64;
485 + switch(flowmode) {
486 + case 0:
487 + fprintf(f, "flowblind ");
488 + break;
489 + case 1:
490 + fprintf(f, "srchost ");
491 + break;
492 + case 2:
493 + fprintf(f, "dsthost ");
494 + break;
495 + case 3:
496 + fprintf(f, "hosts ");
497 + break;
498 + case 4:
499 + fprintf(f, "flows ");
500 + break;
501 + case 5:
502 + fprintf(f, "dual-srchost ");
503 + break;
504 + case 6:
505 + fprintf(f, "dual-dsthost ");
506 + break;
507 + case 7:
508 + fprintf(f, "triple-isolate ");
509 + break;
510 + default:
511 + fprintf(f, "(?flowmode?) ");
512 + break;
513 + };
514 +
515 + if(nat)
516 + fprintf(f, "nat ");
517 + }
518 + if (tb[TCA_CAKE_WASH] &&
519 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
520 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
521 + }
522 + if (tb[TCA_CAKE_ATM] &&
523 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
524 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
525 + }
526 + if (tb[TCA_CAKE_OVERHEAD] &&
527 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__u32)) {
528 + overhead = rta_getattr_u32(tb[TCA_CAKE_OVERHEAD]);
529 + }
530 + if (tb[TCA_CAKE_ETHERNET] &&
531 + RTA_PAYLOAD(tb[TCA_CAKE_ETHERNET]) >= sizeof(__u32)) {
532 + ethernet = rta_getattr_u32(tb[TCA_CAKE_ETHERNET]);
533 + }
534 + if (tb[TCA_CAKE_RTT] &&
535 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
536 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
537 + }
538 +
539 + if (wash)
540 + fprintf(f,"wash ");
541 +
542 + if (interval)
543 + fprintf(f, "rtt %s ", sprint_time(interval, b2));
544 +
545 + if (!atm && overhead == ethernet) {
546 + fprintf(f, "raw ");
547 + } else {
548 + if (atm == 1)
549 + fprintf(f, "atm ");
550 + else if (atm == 2)
551 + fprintf(f, "ptm ");
552 + else
553 + fprintf(f, "noatm ");
554 +
555 + fprintf(f, "overhead %d ", overhead);
556 +
557 + // This is actually the *amount* of automatic compensation, but we only report
558 + // its presence as a boolean for now.
559 + if (ethernet)
560 + fprintf(f, "via-ethernet ");
561 + }
562 +
563 + if (memlimit)
564 + fprintf(f, "memlimit %s", sprint_size(memlimit, b1));
565 +
566 + return 0;
567 +}
568 +
569 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
570 + struct rtattr *xstats)
571 +{
572 + /* fq_codel stats format borrowed */
573 + struct tc_fq_codel_xstats *st;
574 + struct tc_cake_xstats *stnc;
575 + SPRINT_BUF(b1);
576 + SPRINT_BUF(b2);
577 +
578 + if (xstats == NULL)
579 + return 0;
580 +
581 + if (RTA_PAYLOAD(xstats) < sizeof(st->type))
582 + return -1;
583 +
584 + st = RTA_DATA(xstats);
585 + stnc = RTA_DATA(xstats);
586 +
587 + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
588 + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
589 + st->qdisc_stats.maxpacket,
590 + st->qdisc_stats.drop_overlimit,
591 + st->qdisc_stats.new_flow_count,
592 + st->qdisc_stats.ecn_mark);
593 + fprintf(f, "\n new_flows_len %u old_flows_len %u",
594 + st->qdisc_stats.new_flows_len,
595 + st->qdisc_stats.old_flows_len);
596 + } else if (st->type == TCA_FQ_CODEL_XSTATS_CLASS && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
597 + fprintf(f, " deficit %d count %u lastcount %u ldelay %s",
598 + st->class_stats.deficit,
599 + st->class_stats.count,
600 + st->class_stats.lastcount,
601 + sprint_time(st->class_stats.ldelay, b1));
602 + if (st->class_stats.dropping) {
603 + fprintf(f, " dropping");
604 + if (st->class_stats.drop_next < 0)
605 + fprintf(f, " drop_next -%s",
606 + sprint_time(-st->class_stats.drop_next, b1));
607 + else
608 + fprintf(f, " drop_next %s",
609 + sprint_time(st->class_stats.drop_next, b1));
610 + }
611 + } else if (stnc->version >= 1 && stnc->version < 0xFF
612 + && stnc->max_tins == TC_CAKE_MAX_TINS
613 + && RTA_PAYLOAD(xstats) >= offsetof(struct tc_cake_xstats, capacity_estimate))
614 + {
615 + int i;
616 +
617 + if(stnc->version >= 3)
618 + fprintf(f, " memory used: %s of %s\n", sprint_size(stnc->memory_used, b1), sprint_size(stnc->memory_limit, b2));
619 +
620 + if(stnc->version >= 2)
621 + fprintf(f, " capacity estimate: %s\n", sprint_rate(stnc->capacity_estimate, b1));
622 +
623 + switch(stnc->tin_cnt) {
624 + case 4:
625 + fprintf(f, " Bulk Best Effort Video Voice\n");
626 + break;
627 +
628 + case 5:
629 + fprintf(f, " Low Loss Best Effort Low Delay Bulk Net Control\n");
630 + break;
631 +
632 + default:
633 + fprintf(f, " ");
634 + for(i=0; i < stnc->tin_cnt; i++)
635 + fprintf(f, " Tin %u", i);
636 + fprintf(f, "\n");
637 + };
638 +
639 + fprintf(f, " thresh ");
640 + for(i=0; i < stnc->tin_cnt; i++)
641 + fprintf(f, "%12s", sprint_rate(stnc->threshold_rate[i], b1));
642 + fprintf(f, "\n");
643 +
644 + fprintf(f, " target ");
645 + for(i=0; i < stnc->tin_cnt; i++)
646 + fprintf(f, "%12s", sprint_time(stnc->target_us[i], b1));
647 + fprintf(f, "\n");
648 +
649 + fprintf(f, " interval");
650 + for(i=0; i < stnc->tin_cnt; i++)
651 + fprintf(f, "%12s", sprint_time(stnc->interval_us[i], b1));
652 + fprintf(f, "\n");
653 +
654 + fprintf(f, " pk_delay");
655 + for(i=0; i < stnc->tin_cnt; i++)
656 + fprintf(f, "%12s", sprint_time(stnc->peak_delay_us[i], b1));
657 + fprintf(f, "\n");
658 +
659 + fprintf(f, " av_delay");
660 + for(i=0; i < stnc->tin_cnt; i++)
661 + fprintf(f, "%12s", sprint_time(stnc->avge_delay_us[i], b1));
662 + fprintf(f, "\n");
663 +
664 + fprintf(f, " sp_delay");
665 + for(i=0; i < stnc->tin_cnt; i++)
666 + fprintf(f, "%12s", sprint_time(stnc->base_delay_us[i], b1));
667 + fprintf(f, "\n");
668 +
669 + fprintf(f, " pkts ");
670 + for(i=0; i < stnc->tin_cnt; i++)
671 + fprintf(f, "%12u", stnc->sent[i].packets);
672 + fprintf(f, "\n");
673 +
674 + fprintf(f, " bytes ");
675 + for(i=0; i < stnc->tin_cnt; i++)
676 + fprintf(f, "%12llu", stnc->sent[i].bytes);
677 + fprintf(f, "\n");
678 +
679 + fprintf(f, " way_inds");
680 + for(i=0; i < stnc->tin_cnt; i++)
681 + fprintf(f, "%12u", stnc->way_indirect_hits[i]);
682 + fprintf(f, "\n");
683 +
684 + fprintf(f, " way_miss");
685 + for(i=0; i < stnc->tin_cnt; i++)
686 + fprintf(f, "%12u", stnc->way_misses[i]);
687 + fprintf(f, "\n");
688 +
689 + fprintf(f, " way_cols");
690 + for(i=0; i < stnc->tin_cnt; i++)
691 + fprintf(f, "%12u", stnc->way_collisions[i]);
692 + fprintf(f, "\n");
693 +
694 + fprintf(f, " drops ");
695 + for(i=0; i < stnc->tin_cnt; i++)
696 + fprintf(f, "%12u", stnc->dropped[i].packets);
697 + fprintf(f, "\n");
698 +
699 + fprintf(f, " marks ");
700 + for(i=0; i < stnc->tin_cnt; i++)
701 + fprintf(f, "%12u", stnc->ecn_marked[i].packets);
702 + fprintf(f, "\n");
703 +
704 + fprintf(f, " sp_flows");
705 + for(i=0; i < stnc->tin_cnt; i++)
706 + fprintf(f, "%12u", stnc->sparse_flows[i]);
707 + fprintf(f, "\n");
708 +
709 + fprintf(f, " bk_flows");
710 + for(i=0; i < stnc->tin_cnt; i++)
711 + fprintf(f, "%12u", stnc->bulk_flows[i]);
712 + fprintf(f, "\n");
713 +
714 + if(stnc->version >= 4) {
715 + fprintf(f, " un_flows");
716 + for(i=0; i < stnc->tin_cnt; i++)
717 + fprintf(f, "%12u", stnc->unresponse_flows[i]);
718 + fprintf(f, "\n");
719 + }
720 +
721 + fprintf(f, " max_len ");
722 + for(i=0; i < stnc->tin_cnt; i++)
723 + fprintf(f, "%12u", stnc->max_skblen[i]);
724 + fprintf(f, "\n");
725 + } else {
726 + return -1;
727 + }
728 + return 0;
729 +}
730 +
731 +struct qdisc_util cake_qdisc_util = {
732 + .id = "cake",
733 + .parse_qopt = cake_parse_opt,
734 + .print_qopt = cake_print_opt,
735 + .print_xstats = cake_print_xstats,
736 +};