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