iproute2: cake: support new operating modes
[openwrt/staging/lynxis.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,771 @@
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 +" [ ack-filter | ack-filter-aggressive | no-ack-filter * ]\n"
144 +" [ memlimit LIMIT ]\n"
145 +" [ ptm | atm | noatm* ] [ overhead N | conservative | raw* ]\n"
146 +" [ mpu N ] [ ingress | egress* ]\n"
147 +" (* marks defaults)\n");
148 +}
149 +
150 +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv,
151 + struct nlmsghdr *n)
152 +{
153 + int unlimited = 0;
154 + unsigned bandwidth = 0;
155 + unsigned interval = 0;
156 + unsigned target = 0;
157 + unsigned diffserv = 0;
158 + unsigned memlimit = 0;
159 + int overhead = 0;
160 + bool overhead_set = false;
161 + bool overhead_override = false;
162 + int mpu = 0;
163 + int flowmode = -1;
164 + int nat = -1;
165 + int atm = -1;
166 + int autorate = -1;
167 + int wash = -1;
168 + int ingress = -1;
169 + int ack_filter = -1;
170 + struct rtattr *tail;
171 +
172 + while (argc > 0) {
173 + if (strcmp(*argv, "bandwidth") == 0) {
174 + NEXT_ARG();
175 + if (get_rate(&bandwidth, *argv)) {
176 + fprintf(stderr, "Illegal \"bandwidth\"\n");
177 + return -1;
178 + }
179 + unlimited = 0;
180 + autorate = 0;
181 + } else if (strcmp(*argv, "unlimited") == 0) {
182 + bandwidth = 0;
183 + unlimited = 1;
184 + autorate = 0;
185 + } else if (strcmp(*argv, "autorate_ingress") == 0) {
186 + autorate = 1;
187 +
188 + } else if (strcmp(*argv, "rtt") == 0) {
189 + NEXT_ARG();
190 + if (get_time(&interval, *argv)) {
191 + fprintf(stderr, "Illegal \"rtt\"\n");
192 + return -1;
193 + }
194 + target = interval / 20;
195 + if(!target)
196 + target = 1;
197 + } else if (strcmp(*argv, "datacentre") == 0) {
198 + interval = 100;
199 + target = 5;
200 + } else if (strcmp(*argv, "lan") == 0) {
201 + interval = 1000;
202 + target = 50;
203 + } else if (strcmp(*argv, "metro") == 0) {
204 + interval = 10000;
205 + target = 500;
206 + } else if (strcmp(*argv, "regional") == 0) {
207 + interval = 30000;
208 + target = 1500;
209 + } else if (strcmp(*argv, "internet") == 0) {
210 + interval = 100000;
211 + target = 5000;
212 + } else if (strcmp(*argv, "oceanic") == 0) {
213 + interval = 300000;
214 + target = 15000;
215 + } else if (strcmp(*argv, "satellite") == 0) {
216 + interval = 1000000;
217 + target = 50000;
218 + } else if (strcmp(*argv, "interplanetary") == 0) {
219 + interval = 3600000000U;
220 + target = 5000;
221 +
222 + } else if (strcmp(*argv, "besteffort") == 0) {
223 + diffserv = 1;
224 + } else if (strcmp(*argv, "precedence") == 0) {
225 + diffserv = 2;
226 + } else if (strcmp(*argv, "diffserv8") == 0) {
227 + diffserv = 3;
228 + } else if (strcmp(*argv, "diffserv4") == 0) {
229 + diffserv = 4;
230 + } else if (strcmp(*argv, "diffserv") == 0) {
231 + diffserv = 4;
232 + } else if (strcmp(*argv, "diffserv-llt") == 0) {
233 + diffserv = 5;
234 + } else if (strcmp(*argv, "diffserv3") == 0) {
235 + diffserv = 6;
236 +
237 + } else if (strcmp(*argv, "nowash") == 0) {
238 + wash = 0;
239 + } else if (strcmp(*argv, "wash") == 0) {
240 + wash = 1;
241 +
242 + } else if (strcmp(*argv, "flowblind") == 0) {
243 + flowmode = 0;
244 + } else if (strcmp(*argv, "srchost") == 0) {
245 + flowmode = 1;
246 + } else if (strcmp(*argv, "dsthost") == 0) {
247 + flowmode = 2;
248 + } else if (strcmp(*argv, "hosts") == 0) {
249 + flowmode = 3;
250 + } else if (strcmp(*argv, "flows") == 0) {
251 + flowmode = 4;
252 + } else if (strcmp(*argv, "dual-srchost") == 0) {
253 + flowmode = 5;
254 + } else if (strcmp(*argv, "dual-dsthost") == 0) {
255 + flowmode = 6;
256 + } else if (strcmp(*argv, "triple-isolate") == 0) {
257 + flowmode = 7;
258 +
259 + } else if (strcmp(*argv, "nat") == 0) {
260 + nat = 1;
261 + } else if (strcmp(*argv, "nonat") == 0) {
262 + nat = 0;
263 +
264 + } else if (strcmp(*argv, "ptm") == 0) {
265 + atm = 2;
266 + } else if (strcmp(*argv, "atm") == 0) {
267 + atm = 1;
268 + } else if (strcmp(*argv, "noatm") == 0) {
269 + atm = 0;
270 +
271 + } else if (strcmp(*argv, "raw") == 0) {
272 + atm = 0;
273 + overhead = 0;
274 + overhead_set = true;
275 + overhead_override = true;
276 + } else if (strcmp(*argv, "conservative") == 0) {
277 + /*
278 + * Deliberately over-estimate overhead:
279 + * one whole ATM cell plus ATM framing.
280 + * A safe choice if the actual overhead is unknown.
281 + */
282 + atm = 1;
283 + overhead = 48;
284 + overhead_set = true;
285 +
286 + /* Various ADSL framing schemes, all over ATM cells */
287 + } else if (strcmp(*argv, "ipoa-vcmux") == 0) {
288 + atm = 1;
289 + overhead += 8;
290 + overhead_set = true;
291 + } else if (strcmp(*argv, "ipoa-llcsnap") == 0) {
292 + atm = 1;
293 + overhead += 16;
294 + overhead_set = true;
295 + } else if (strcmp(*argv, "bridged-vcmux") == 0) {
296 + atm = 1;
297 + overhead += 24;
298 + overhead_set = true;
299 + } else if (strcmp(*argv, "bridged-llcsnap") == 0) {
300 + atm = 1;
301 + overhead += 32;
302 + overhead_set = true;
303 + } else if (strcmp(*argv, "pppoa-vcmux") == 0) {
304 + atm = 1;
305 + overhead += 10;
306 + overhead_set = true;
307 + } else if (strcmp(*argv, "pppoa-llc") == 0) {
308 + atm = 1;
309 + overhead += 14;
310 + overhead_set = true;
311 + } else if (strcmp(*argv, "pppoe-vcmux") == 0) {
312 + atm = 1;
313 + overhead += 32;
314 + overhead_set = true;
315 + } else if (strcmp(*argv, "pppoe-llcsnap") == 0) {
316 + atm = 1;
317 + overhead += 40;
318 + overhead_set = true;
319 +
320 + /* Typical VDSL2 framing schemes, both over PTM */
321 + /* PTM has 64b/65b coding which absorbs some bandwidth */
322 + } else if (strcmp(*argv, "pppoe-ptm") == 0) {
323 + /* 2B PPP + 6B PPPoE + 6B dest MAC + 6B src MAC
324 + * + 2B ethertype + 4B Frame Check Sequence
325 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
326 + * + 2B TC-CRC (PTM-FCS) = 30B
327 + */
328 + atm = 2;
329 + overhead += 30;
330 + overhead_set = true;
331 + } else if (strcmp(*argv, "bridged-ptm") == 0) {
332 + /* 6B dest MAC + 6B src MAC + 2B ethertype
333 + * + 4B Frame Check Sequence
334 + * + 1B Start of Frame (S) + 1B End of Frame (Ck)
335 + * + 2B TC-CRC (PTM-FCS) = 22B
336 + */
337 + atm = 2;
338 + overhead += 22;
339 + overhead_set = true;
340 +
341 + } else if (strcmp(*argv, "via-ethernet") == 0) {
342 + /*
343 + * We used to use this flag to manually compensate for
344 + * Linux including the Ethernet header on Ethernet-type
345 + * interfaces, but not on IP-type interfaces.
346 + *
347 + * It is no longer needed, because Cake now adjusts for
348 + * that automatically, and is thus ignored.
349 + *
350 + * It would be deleted entirely, but it appears in the
351 + * stats output when the automatic compensation is
352 + * active.
353 + */
354 +
355 + } else if (strcmp(*argv, "total_overhead") == 0) {
356 + /*
357 + * This is the overhead cake accounts for; added here so
358 + * that cake's "tc -s qdisc" output can be directly
359 + * pasted into the tc command to instantate a new cake..
360 + */
361 + NEXT_ARG();
362 +
363 + } else if (strcmp(*argv, "hard_header_len") == 0) {
364 + /*
365 + * This is the overhead the kernel automatically
366 + * accounted for; added here so that cake's "tc -s
367 + * qdisc" output can be directly pasted into the tc
368 + * command to instantiate a new cake..
369 + */
370 + NEXT_ARG();
371 +
372 + } else if (strcmp(*argv, "ethernet") == 0) {
373 + /* ethernet pre-amble & interframe gap & FCS
374 + * you may need to add vlan tag */
375 + overhead += 38;
376 + overhead_set = true;
377 + mpu = 84;
378 +
379 + /* Additional Ethernet-related overhead used by some ISPs */
380 + } else if (strcmp(*argv, "ether-vlan") == 0) {
381 + /* 802.1q VLAN tag - may be repeated */
382 + overhead += 4;
383 + overhead_set = true;
384 +
385 + /*
386 + * DOCSIS cable shapers account for Ethernet frame with FCS,
387 + * but not interframe gap or preamble.
388 + */
389 + } else if (strcmp(*argv, "docsis") == 0) {
390 + atm = 0;
391 + overhead += 18;
392 + overhead_set = true;
393 + mpu = 64;
394 +
395 + } else if (strcmp(*argv, "overhead") == 0) {
396 + char* p = NULL;
397 + NEXT_ARG();
398 + overhead = strtol(*argv, &p, 10);
399 + if(!p || *p || !*argv || overhead < -64 || overhead > 256) {
400 + fprintf(stderr, "Illegal \"overhead\", valid range is -64 to 256\\n");
401 + return -1;
402 + }
403 + overhead_set = true;
404 +
405 + } else if (strcmp(*argv, "mpu") == 0) {
406 + char* p = NULL;
407 + NEXT_ARG();
408 + mpu = strtol(*argv, &p, 10);
409 + if(!p || *p || !*argv || mpu < 0 || mpu > 256) {
410 + fprintf(stderr, "Illegal \"mpu\", valid range is 0 to 256\\n");
411 + return -1;
412 + }
413 +
414 + } else if (strcmp(*argv, "ingress") == 0) {
415 + ingress = 1;
416 + } else if (strcmp(*argv, "egress") == 0) {
417 + ingress = 0;
418 +
419 + } else if (strcmp(*argv, "no-ack-filter") == 0) {
420 + ack_filter = 0;
421 + } else if (strcmp(*argv, "ack-filter") == 0) {
422 + ack_filter = 0x0200;
423 + } else if (strcmp(*argv, "ack-filter-aggressive") == 0) {
424 + ack_filter = 0x0600;
425 +
426 + } else if (strcmp(*argv, "memlimit") == 0) {
427 + NEXT_ARG();
428 + if(get_size(&memlimit, *argv)) {
429 + fprintf(stderr, "Illegal value for \"memlimit\": \"%s\"\n", *argv);
430 + return -1;
431 + }
432 +
433 + } else if (strcmp(*argv, "help") == 0) {
434 + explain();
435 + return -1;
436 + } else {
437 + fprintf(stderr, "What is \"%s\"?\n", *argv);
438 + explain();
439 + return -1;
440 + }
441 + argc--; argv++;
442 + }
443 +
444 + tail = NLMSG_TAIL(n);
445 + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
446 + if (bandwidth || unlimited)
447 + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth));
448 + if (diffserv)
449 + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv));
450 + if (atm != -1)
451 + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm));
452 + if (flowmode != -1)
453 + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode));
454 + if (overhead_set)
455 + addattr_l(n, 1024, TCA_CAKE_OVERHEAD, &overhead, sizeof(overhead));
456 + if (overhead_override) {
457 + unsigned zero = 0;
458 + addattr_l(n, 1024, TCA_CAKE_ETHERNET, &zero, sizeof(zero));
459 + }
460 + if (mpu > 0)
461 + addattr_l(n, 1024, TCA_CAKE_MPU, &mpu, sizeof(mpu));
462 + if (interval)
463 + addattr_l(n, 1024, TCA_CAKE_RTT, &interval, sizeof(interval));
464 + if (target)
465 + addattr_l(n, 1024, TCA_CAKE_TARGET, &target, sizeof(target));
466 + if (autorate != -1)
467 + addattr_l(n, 1024, TCA_CAKE_AUTORATE, &autorate, sizeof(autorate));
468 + if (memlimit)
469 + addattr_l(n, 1024, TCA_CAKE_MEMORY, &memlimit, sizeof(memlimit));
470 + if (nat != -1)
471 + addattr_l(n, 1024, TCA_CAKE_NAT, &nat, sizeof(nat));
472 + if (wash != -1)
473 + addattr_l(n, 1024, TCA_CAKE_WASH, &wash, sizeof(wash));
474 + if (ingress != -1)
475 + addattr_l(n, 1024, TCA_CAKE_INGRESS, &ingress, sizeof(ingress));
476 + if (ack_filter != -1)
477 + addattr_l(n, 1024, TCA_CAKE_ACK_FILTER, &ack_filter, sizeof(ack_filter));
478 +
479 + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
480 + return 0;
481 +}
482 +
483 +
484 +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
485 +{
486 + struct rtattr *tb[TCA_CAKE_MAX + 1];
487 + unsigned bandwidth = 0;
488 + unsigned diffserv = 0;
489 + unsigned flowmode = 0;
490 + unsigned interval = 0;
491 + unsigned memlimit = 0;
492 + int overhead = 0;
493 + int ethernet = 0;
494 + int mpu = 0;
495 + int atm = 0;
496 + int nat = 0;
497 + int autorate = 0;
498 + int wash = 0;
499 + int ingress = 0;
500 + int ack_filter = 0;
501 + SPRINT_BUF(b1);
502 + SPRINT_BUF(b2);
503 +
504 + if (opt == NULL)
505 + return 0;
506 +
507 + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt);
508 +
509 + if (tb[TCA_CAKE_BASE_RATE] &&
510 + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) {
511 + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]);
512 + if(bandwidth)
513 + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1));
514 + else
515 + fprintf(f, "unlimited ");
516 + }
517 + if (tb[TCA_CAKE_AUTORATE] &&
518 + RTA_PAYLOAD(tb[TCA_CAKE_AUTORATE]) >= sizeof(__u32)) {
519 + autorate = rta_getattr_u32(tb[TCA_CAKE_AUTORATE]);
520 + if(autorate == 1)
521 + fprintf(f, "autorate_ingress ");
522 + else if(autorate)
523 + fprintf(f, "(?autorate?) ");
524 + }
525 + if (tb[TCA_CAKE_DIFFSERV_MODE] &&
526 + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) {
527 + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]);
528 + switch(diffserv) {
529 + case 1:
530 + fprintf(f, "besteffort ");
531 + break;
532 + case 2:
533 + fprintf(f, "precedence ");
534 + break;
535 + case 3:
536 + fprintf(f, "diffserv8 ");
537 + break;
538 + case 4:
539 + fprintf(f, "diffserv4 ");
540 + break;
541 + case 5:
542 + fprintf(f, "diffserv-llt ");
543 + break;
544 + case 6:
545 + fprintf(f, "diffserv3 ");
546 + break;
547 + default:
548 + fprintf(f, "(?diffserv?) ");
549 + break;
550 + };
551 + }
552 + if (tb[TCA_CAKE_FLOW_MODE] &&
553 + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) {
554 + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]);
555 + nat = !!(flowmode & 64);
556 + flowmode &= ~64;
557 + switch(flowmode) {
558 + case 0:
559 + fprintf(f, "flowblind ");
560 + break;
561 + case 1:
562 + fprintf(f, "srchost ");
563 + break;
564 + case 2:
565 + fprintf(f, "dsthost ");
566 + break;
567 + case 3:
568 + fprintf(f, "hosts ");
569 + break;
570 + case 4:
571 + fprintf(f, "flows ");
572 + break;
573 + case 5:
574 + fprintf(f, "dual-srchost ");
575 + break;
576 + case 6:
577 + fprintf(f, "dual-dsthost ");
578 + break;
579 + case 7:
580 + fprintf(f, "triple-isolate ");
581 + break;
582 + default:
583 + fprintf(f, "(?flowmode?) ");
584 + break;
585 + };
586 +
587 + if(nat)
588 + fprintf(f, "nat ");
589 + }
590 + if (tb[TCA_CAKE_WASH] &&
591 + RTA_PAYLOAD(tb[TCA_CAKE_WASH]) >= sizeof(__u32)) {
592 + wash = rta_getattr_u32(tb[TCA_CAKE_WASH]);
593 + }
594 + if (tb[TCA_CAKE_ATM] &&
595 + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) {
596 + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]);
597 + }
598 + if (tb[TCA_CAKE_OVERHEAD] &&
599 + RTA_PAYLOAD(tb[TCA_CAKE_OVERHEAD]) >= sizeof(__u32)) {
600 + overhead = rta_getattr_u32(tb[TCA_CAKE_OVERHEAD]);
601 + }
602 + if (tb[TCA_CAKE_MPU] &&
603 + RTA_PAYLOAD(tb[TCA_CAKE_MPU]) >= sizeof(__u32)) {
604 + mpu = rta_getattr_u32(tb[TCA_CAKE_MPU]);
605 + }
606 + if (tb[TCA_CAKE_INGRESS] &&
607 + RTA_PAYLOAD(tb[TCA_CAKE_INGRESS]) >= sizeof(__u32)) {
608 + ingress = rta_getattr_u32(tb[TCA_CAKE_INGRESS]);
609 + }
610 + if (tb[TCA_CAKE_ACK_FILTER] &&
611 + RTA_PAYLOAD(tb[TCA_CAKE_ACK_FILTER]) >= sizeof(__u32)) {
612 + ack_filter = rta_getattr_u32(tb[TCA_CAKE_ACK_FILTER]);
613 + }
614 + if (tb[TCA_CAKE_ETHERNET] &&
615 + RTA_PAYLOAD(tb[TCA_CAKE_ETHERNET]) >= sizeof(__u32)) {
616 + ethernet = rta_getattr_u32(tb[TCA_CAKE_ETHERNET]);
617 + }
618 + if (tb[TCA_CAKE_RTT] &&
619 + RTA_PAYLOAD(tb[TCA_CAKE_RTT]) >= sizeof(__u32)) {
620 + interval = rta_getattr_u32(tb[TCA_CAKE_RTT]);
621 + }
622 +
623 + if (wash)
624 + fprintf(f,"wash ");
625 +
626 + if (ingress)
627 + fprintf(f,"ingress ");
628 +
629 + if (ack_filter == 0x0600)
630 + fprintf(f,"ack-filter-aggressive ");
631 + else if (ack_filter)
632 + fprintf(f,"ack-filter ");
633 +
634 + if (interval)
635 + fprintf(f, "rtt %s ", sprint_time(interval, b2));
636 +
637 + if (!atm && overhead == ethernet) {
638 + fprintf(f, "raw ");
639 + } else {
640 + if (atm == 1)
641 + fprintf(f, "atm ");
642 + else if (atm == 2)
643 + fprintf(f, "ptm ");
644 + else
645 + fprintf(f, "noatm ");
646 +
647 + fprintf(f, "overhead %d ", overhead);
648 +
649 + /* This is actually the *amount* of automatic compensation, but
650 + * we only report its presence as a boolean for now.
651 + */
652 + if (ethernet)
653 + fprintf(f, "via-ethernet ");
654 + }
655 +
656 + /* unconditionally report the overhead and hard_header_len overhead the
657 + * kernel added automatically
658 + */
659 + fprintf(f, "total_overhead %d ", overhead);
660 + fprintf(f, "hard_header_len %d ", ethernet);
661 +
662 + if (mpu) {
663 + fprintf(f, "mpu %d ", mpu);
664 + }
665 +
666 + if (memlimit)
667 + fprintf(f, "memlimit %s", sprint_size(memlimit, b1));
668 +
669 + return 0;
670 +}
671 +
672 +static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
673 + struct rtattr *xstats)
674 +{
675 + /* fq_codel stats format borrowed */
676 + struct tc_fq_codel_xstats *st;
677 + struct tc_cake_xstats *stnc;
678 + SPRINT_BUF(b1);
679 + SPRINT_BUF(b2);
680 +
681 + if (xstats == NULL)
682 + return 0;
683 +
684 + if (RTA_PAYLOAD(xstats) < sizeof(st->type))
685 + return -1;
686 +
687 + st = RTA_DATA(xstats);
688 + stnc = RTA_DATA(xstats);
689 +
690 + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
691 + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
692 + st->qdisc_stats.maxpacket,
693 + st->qdisc_stats.drop_overlimit,
694 + st->qdisc_stats.new_flow_count,
695 + st->qdisc_stats.ecn_mark);
696 + fprintf(f, "\n new_flows_len %u old_flows_len %u",
697 + st->qdisc_stats.new_flows_len,
698 + st->qdisc_stats.old_flows_len);
699 + } else if (st->type == TCA_FQ_CODEL_XSTATS_CLASS && RTA_PAYLOAD(xstats) >= sizeof(*st)) {
700 + fprintf(f, " deficit %d count %u lastcount %u ldelay %s",
701 + st->class_stats.deficit,
702 + st->class_stats.count,
703 + st->class_stats.lastcount,
704 + sprint_time(st->class_stats.ldelay, b1));
705 + if (st->class_stats.dropping) {
706 + fprintf(f, " dropping");
707 + if (st->class_stats.drop_next < 0)
708 + fprintf(f, " drop_next -%s",
709 + sprint_time(-st->class_stats.drop_next, b1));
710 + else
711 + fprintf(f, " drop_next %s",
712 + sprint_time(st->class_stats.drop_next, b1));
713 + }
714 + } else if (stnc->version >= 1 && stnc->version < 0xFF
715 + && stnc->max_tins == TC_CAKE_MAX_TINS
716 + && RTA_PAYLOAD(xstats) >= offsetof(struct tc_cake_xstats, capacity_estimate))
717 + {
718 + int i;
719 +
720 + if(stnc->version >= 3)
721 + fprintf(f, " memory used: %s of %s\n", sprint_size(stnc->memory_used, b1), sprint_size(stnc->memory_limit, b2));
722 +
723 + if(stnc->version >= 2)
724 + fprintf(f, " capacity estimate: %s\n", sprint_rate(stnc->capacity_estimate, b1));
725 +
726 + switch(stnc->tin_cnt) {
727 + case 3:
728 + fprintf(f, " Bulk Best Effort Voice\n");
729 + break;
730 +
731 + case 4:
732 + fprintf(f, " Bulk Best Effort Video Voice\n");
733 + break;
734 +
735 + case 5:
736 + fprintf(f, " Low Loss Best Effort Low Delay Bulk Net Control\n");
737 + break;
738 +
739 + default:
740 + fprintf(f, " ");
741 + for(i=0; i < stnc->tin_cnt; i++)
742 + fprintf(f, " Tin %u", i);
743 + fprintf(f, "\n");
744 + };
745 +
746 + fprintf(f, " thresh ");
747 + for(i=0; i < stnc->tin_cnt; i++)
748 + fprintf(f, " %12s", sprint_rate(stnc->threshold_rate[i], b1));
749 + fprintf(f, "\n");
750 +
751 + fprintf(f, " target ");
752 + for(i=0; i < stnc->tin_cnt; i++)
753 + fprintf(f, " %12s", sprint_time(stnc->target_us[i], b1));
754 + fprintf(f, "\n");
755 +
756 + fprintf(f, " interval");
757 + for(i=0; i < stnc->tin_cnt; i++)
758 + fprintf(f, " %12s", sprint_time(stnc->interval_us[i], b1));
759 + fprintf(f, "\n");
760 +
761 + fprintf(f, " pk_delay");
762 + for(i=0; i < stnc->tin_cnt; i++)
763 + fprintf(f, " %12s", sprint_time(stnc->peak_delay_us[i], b1));
764 + fprintf(f, "\n");
765 +
766 + fprintf(f, " av_delay");
767 + for(i=0; i < stnc->tin_cnt; i++)
768 + fprintf(f, " %12s", sprint_time(stnc->avge_delay_us[i], b1));
769 + fprintf(f, "\n");
770 +
771 + fprintf(f, " sp_delay");
772 + for(i=0; i < stnc->tin_cnt; i++)
773 + fprintf(f, " %12s", sprint_time(stnc->base_delay_us[i], b1));
774 + fprintf(f, "\n");
775 +
776 + fprintf(f, " pkts ");
777 + for(i=0; i < stnc->tin_cnt; i++)
778 + fprintf(f, " %12u", stnc->sent[i].packets);
779 + fprintf(f, "\n");
780 +
781 + fprintf(f, " bytes ");
782 + for(i=0; i < stnc->tin_cnt; i++)
783 + fprintf(f, " %12llu", stnc->sent[i].bytes);
784 + fprintf(f, "\n");
785 +
786 + fprintf(f, " way_inds");
787 + for(i=0; i < stnc->tin_cnt; i++)
788 + fprintf(f, " %12u", stnc->way_indirect_hits[i]);
789 + fprintf(f, "\n");
790 +
791 + fprintf(f, " way_miss");
792 + for(i=0; i < stnc->tin_cnt; i++)
793 + fprintf(f, " %12u", stnc->way_misses[i]);
794 + fprintf(f, "\n");
795 +
796 + fprintf(f, " way_cols");
797 + for(i=0; i < stnc->tin_cnt; i++)
798 + fprintf(f, " %12u", stnc->way_collisions[i]);
799 + fprintf(f, "\n");
800 +
801 + fprintf(f, " drops ");
802 + for(i=0; i < stnc->tin_cnt; i++)
803 + fprintf(f, " %12u", stnc->dropped[i].packets);
804 + fprintf(f, "\n");
805 +
806 + fprintf(f, " marks ");
807 + for(i=0; i < stnc->tin_cnt; i++)
808 + fprintf(f, " %12u", stnc->ecn_marked[i].packets);
809 + fprintf(f, "\n");
810 +
811 + if(stnc->version >= 5) {
812 + fprintf(f, " ack_drop");
813 + for(i=0; i < stnc->tin_cnt; i++)
814 + fprintf(f, " %12u", stnc->ack_drops[i].packets);
815 + fprintf(f, "\n");
816 + }
817 +
818 + fprintf(f, " sp_flows");
819 + for(i=0; i < stnc->tin_cnt; i++)
820 + fprintf(f, " %12u", stnc->sparse_flows[i]);
821 + fprintf(f, "\n");
822 +
823 + fprintf(f, " bk_flows");
824 + for(i=0; i < stnc->tin_cnt; i++)
825 + fprintf(f, " %12u", stnc->bulk_flows[i]);
826 + fprintf(f, "\n");
827 +
828 + if(stnc->version >= 4) {
829 + fprintf(f, " un_flows");
830 + for(i=0; i < stnc->tin_cnt; i++)
831 + fprintf(f, " %12u", stnc->unresponse_flows[i]);
832 + fprintf(f, "\n");
833 + }
834 +
835 + fprintf(f, " max_len ");
836 + for(i=0; i < stnc->tin_cnt; i++)
837 + fprintf(f, " %12u", stnc->max_skblen[i]);
838 + fprintf(f, "\n");
839 + } else {
840 + return -1;
841 + }
842 + return 0;
843 +}
844 +
845 +struct qdisc_util cake_qdisc_util = {
846 + .id = "cake",
847 + .parse_qopt = cake_parse_opt,
848 + .print_qopt = cake_print_opt,
849 + .print_xstats = cake_print_xstats,
850 +};