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