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