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