]>
Commit | Line | Data |
---|---|---|
aba5acdf SH |
1 | /* |
2 | * q_gred.c GRED. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
ae665a52 SH |
9 | * Authors: J Hadi Salim(hadi@nortelnetworks.com) |
10 | * code ruthlessly ripped from | |
11 | * Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> | |
aba5acdf SH |
12 | * |
13 | */ | |
14 | ||
15 | #include <stdio.h> | |
16 | #include <stdlib.h> | |
17 | #include <unistd.h> | |
aba5acdf SH |
18 | #include <fcntl.h> |
19 | #include <sys/socket.h> | |
20 | #include <netinet/in.h> | |
21 | #include <arpa/inet.h> | |
22 | #include <string.h> | |
1b6f0bb5 | 23 | #include <math.h> |
aba5acdf SH |
24 | |
25 | #include "utils.h" | |
26 | #include "tc_util.h" | |
27 | ||
28 | #include "tc_red.h" | |
29 | ||
30 | ||
31 | #if 0 | |
32a121cb | 32 | #define DPRINTF(format, args...) fprintf(stderr, format, ##args) |
aba5acdf | 33 | #else |
32a121cb | 34 | #define DPRINTF(format, args...) |
aba5acdf SH |
35 | #endif |
36 | ||
37 | static void explain(void) | |
38 | { | |
8589eb4e MC |
39 | fprintf(stderr, |
40 | "Usage: tc qdisc { add | replace | change } ... gred setup vqs NUMBER\n" | |
41 | " default DEFAULT_VQ [ grio ] [ limit BYTES ] [ecn] [harddrop]\n" | |
42 | " tc qdisc change ... gred vq VQ [ prio VALUE ] limit BYTES\n" | |
43 | " min BYTES max BYTES avpkt BYTES [ burst PACKETS ]\n" | |
44 | " [ probability PROBABILITY ] [ bandwidth KBPS ] [ecn] [harddrop]\n"); | |
aba5acdf SH |
45 | } |
46 | ||
3d0b7439 | 47 | static int init_gred(struct qdisc_util *qu, int argc, char **argv, |
ebde8780 | 48 | struct nlmsghdr *n) |
aba5acdf SH |
49 | { |
50 | ||
51 | struct rtattr *tail; | |
cb4bd0ec | 52 | struct tc_gred_sopt opt = { 0 }; |
aacee269 | 53 | __u32 limit = 0; |
eb6d7d6a DW |
54 | |
55 | opt.def_DP = MAX_DPs; | |
aba5acdf SH |
56 | |
57 | while (argc > 0) { | |
32a121cb | 58 | DPRINTF(stderr, "init_gred: invoked with %s\n", *argv); |
357c45ad DW |
59 | if (strcmp(*argv, "vqs") == 0 || |
60 | strcmp(*argv, "DPs") == 0) { | |
aba5acdf | 61 | NEXT_ARG(); |
eb6d7d6a | 62 | if (get_unsigned(&opt.DPs, *argv, 10)) { |
357c45ad | 63 | fprintf(stderr, "Illegal \"vqs\"\n"); |
eb6d7d6a DW |
64 | return -1; |
65 | } else if (opt.DPs > MAX_DPs) { | |
32a121cb SH |
66 | fprintf(stderr, "GRED: only %u VQs are currently supported\n", |
67 | MAX_DPs); | |
aba5acdf SH |
68 | return -1; |
69 | } | |
70 | } else if (strcmp(*argv, "default") == 0) { | |
eb6d7d6a | 71 | if (opt.DPs == 0) { |
32a121cb | 72 | fprintf(stderr, "\"default\" must be defined after \"vqs\"\n"); |
aba5acdf SH |
73 | return -1; |
74 | } | |
eb6d7d6a DW |
75 | NEXT_ARG(); |
76 | if (get_unsigned(&opt.def_DP, *argv, 10)) { | |
77 | fprintf(stderr, "Illegal \"default\"\n"); | |
78 | return -1; | |
79 | } else if (opt.def_DP >= opt.DPs) { | |
32a121cb | 80 | fprintf(stderr, "\"default\" must be less than \"vqs\"\n"); |
aba5acdf SH |
81 | return -1; |
82 | } | |
83 | } else if (strcmp(*argv, "grio") == 0) { | |
cb4bd0ec | 84 | opt.grio = 1; |
aacee269 DW |
85 | } else if (strcmp(*argv, "limit") == 0) { |
86 | NEXT_ARG(); | |
87 | if (get_size(&limit, *argv)) { | |
88 | fprintf(stderr, "Illegal \"limit\"\n"); | |
89 | return -1; | |
90 | } | |
2d7c564a JK |
91 | } else if (strcmp(*argv, "ecn") == 0) { |
92 | opt.flags |= TC_RED_ECN; | |
93 | } else if (strcmp(*argv, "harddrop") == 0) { | |
94 | opt.flags |= TC_RED_HARDDROP; | |
aba5acdf SH |
95 | } else if (strcmp(*argv, "help") == 0) { |
96 | explain(); | |
97 | return -1; | |
98 | } else { | |
99 | fprintf(stderr, "What is \"%s\"?\n", *argv); | |
100 | explain(); | |
101 | return -1; | |
102 | } | |
103 | argc--; argv++; | |
ebde8780 | 104 | } |
aba5acdf | 105 | |
eb6d7d6a | 106 | if (!opt.DPs || opt.def_DP == MAX_DPs) { |
32a121cb | 107 | fprintf(stderr, "Illegal gred setup parameters\n"); |
ebde8780 SH |
108 | return -1; |
109 | } | |
110 | ||
32a121cb SH |
111 | DPRINTF("TC_GRED: sending DPs=%u def_DP=%u\n", opt.DPs, opt.def_DP); |
112 | n->nlmsg_flags |= NLM_F_CREATE; | |
c14f9d92 | 113 | tail = addattr_nest(n, 1024, TCA_OPTIONS); |
aba5acdf | 114 | addattr_l(n, 1024, TCA_GRED_DPS, &opt, sizeof(struct tc_gred_sopt)); |
aacee269 DW |
115 | if (limit) |
116 | addattr32(n, 1024, TCA_GRED_LIMIT, limit); | |
c14f9d92 | 117 | addattr_nest_end(n, tail); |
ebde8780 | 118 | return 0; |
aba5acdf SH |
119 | } |
120 | /* | |
121 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
122 | */ | |
927e3cfb | 123 | static int gred_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n, const char *dev) |
aba5acdf | 124 | { |
f7a8749a | 125 | struct rtattr *tail, *entry, *vqs; |
32a121cb | 126 | int ok = 0; |
eb6d7d6a | 127 | struct tc_gred_qopt opt = { 0 }; |
32a121cb SH |
128 | unsigned int burst = 0; |
129 | unsigned int avpkt = 0; | |
f7a8749a | 130 | unsigned int flags = 0; |
aba5acdf | 131 | double probability = 0.02; |
32a121cb | 132 | unsigned int rate = 0; |
9d9a67c7 | 133 | int parm; |
aba5acdf | 134 | __u8 sbuf[256]; |
1b6f0bb5 | 135 | __u32 max_P; |
aba5acdf | 136 | |
eb6d7d6a | 137 | opt.DP = MAX_DPs; |
aba5acdf SH |
138 | |
139 | while (argc > 0) { | |
140 | if (strcmp(*argv, "limit") == 0) { | |
141 | NEXT_ARG(); | |
142 | if (get_size(&opt.limit, *argv)) { | |
143 | fprintf(stderr, "Illegal \"limit\"\n"); | |
144 | return -1; | |
145 | } | |
146 | ok++; | |
147 | } else if (strcmp(*argv, "setup") == 0) { | |
148 | if (ok) { | |
149 | fprintf(stderr, "Illegal \"setup\"\n"); | |
150 | return -1; | |
151 | } | |
d73e0408 | 152 | return init_gred(qu, argc-1, argv+1, n); |
aba5acdf SH |
153 | } else if (strcmp(*argv, "min") == 0) { |
154 | NEXT_ARG(); | |
155 | if (get_size(&opt.qth_min, *argv)) { | |
156 | fprintf(stderr, "Illegal \"min\"\n"); | |
157 | return -1; | |
158 | } | |
159 | ok++; | |
160 | } else if (strcmp(*argv, "max") == 0) { | |
161 | NEXT_ARG(); | |
162 | if (get_size(&opt.qth_max, *argv)) { | |
163 | fprintf(stderr, "Illegal \"max\"\n"); | |
164 | return -1; | |
165 | } | |
166 | ok++; | |
357c45ad DW |
167 | } else if (strcmp(*argv, "vq") == 0 || |
168 | strcmp(*argv, "DP") == 0) { | |
aba5acdf | 169 | NEXT_ARG(); |
eb6d7d6a | 170 | if (get_unsigned(&opt.DP, *argv, 10)) { |
357c45ad | 171 | fprintf(stderr, "Illegal \"vq\"\n"); |
aba5acdf | 172 | return -1; |
eb6d7d6a | 173 | } else if (opt.DP >= MAX_DPs) { |
32a121cb SH |
174 | fprintf(stderr, "GRED: only %u VQs are currently supported\n", |
175 | MAX_DPs); | |
eb6d7d6a DW |
176 | return -1; |
177 | } /* need a better error check */ | |
aba5acdf SH |
178 | ok++; |
179 | } else if (strcmp(*argv, "burst") == 0) { | |
180 | NEXT_ARG(); | |
d73e0408 | 181 | if (get_unsigned(&burst, *argv, 0)) { |
aba5acdf SH |
182 | fprintf(stderr, "Illegal \"burst\"\n"); |
183 | return -1; | |
184 | } | |
185 | ok++; | |
186 | } else if (strcmp(*argv, "avpkt") == 0) { | |
187 | NEXT_ARG(); | |
188 | if (get_size(&avpkt, *argv)) { | |
189 | fprintf(stderr, "Illegal \"avpkt\"\n"); | |
190 | return -1; | |
191 | } | |
192 | ok++; | |
193 | } else if (strcmp(*argv, "probability") == 0) { | |
194 | NEXT_ARG(); | |
195 | if (sscanf(*argv, "%lg", &probability) != 1) { | |
196 | fprintf(stderr, "Illegal \"probability\"\n"); | |
197 | return -1; | |
198 | } | |
199 | ok++; | |
200 | } else if (strcmp(*argv, "prio") == 0) { | |
201 | NEXT_ARG(); | |
32a121cb | 202 | opt.prio = strtol(*argv, (char **)NULL, 10); |
aba5acdf SH |
203 | /* some error check here */ |
204 | ok++; | |
205 | } else if (strcmp(*argv, "bandwidth") == 0) { | |
206 | NEXT_ARG(); | |
927e3cfb ND |
207 | if (strchr(*argv, '%')) { |
208 | if (get_percent_rate(&rate, *argv, dev)) { | |
209 | fprintf(stderr, "Illegal \"bandwidth\"\n"); | |
210 | return -1; | |
211 | } | |
212 | } else if (get_rate(&rate, *argv)) { | |
aba5acdf SH |
213 | fprintf(stderr, "Illegal \"bandwidth\"\n"); |
214 | return -1; | |
215 | } | |
216 | ok++; | |
f7a8749a JK |
217 | } else if (strcmp(*argv, "ecn") == 0) { |
218 | flags |= TC_RED_ECN; | |
219 | } else if (strcmp(*argv, "harddrop") == 0) { | |
220 | flags |= TC_RED_HARDDROP; | |
aba5acdf SH |
221 | } else if (strcmp(*argv, "help") == 0) { |
222 | explain(); | |
223 | return -1; | |
224 | } else { | |
225 | fprintf(stderr, "What is \"%s\"?\n", *argv); | |
226 | explain(); | |
227 | return -1; | |
228 | } | |
229 | argc--; argv++; | |
230 | } | |
231 | ||
a77905ef DW |
232 | if (!ok) { |
233 | explain(); | |
234 | return -1; | |
235 | } | |
eb6d7d6a DW |
236 | if (opt.DP == MAX_DPs || !opt.limit || !opt.qth_min || !opt.qth_max || |
237 | !avpkt) { | |
32a121cb | 238 | fprintf(stderr, "Required parameter (vq, limit, min, max, avpkt) is missing\n"); |
aba5acdf SH |
239 | return -1; |
240 | } | |
ab15aeac ED |
241 | if (!burst) { |
242 | burst = (2 * opt.qth_min + opt.qth_max) / (3 * avpkt); | |
243 | fprintf(stderr, "GRED: set burst to %u\n", burst); | |
244 | } | |
d93c909a DW |
245 | if (!rate) { |
246 | get_rate(&rate, "10Mbit"); | |
247 | fprintf(stderr, "GRED: set bandwidth to 10Mbit\n"); | |
248 | } | |
9d9a67c7 | 249 | if ((parm = tc_red_eval_ewma(opt.qth_min, burst, avpkt)) < 0) { |
aba5acdf SH |
250 | fprintf(stderr, "GRED: failed to calculate EWMA constant.\n"); |
251 | return -1; | |
252 | } | |
9d9a67c7 | 253 | if (parm >= 10) |
32a121cb SH |
254 | fprintf(stderr, "GRED: WARNING. Burst %u seems to be too large.\n", |
255 | burst); | |
9d9a67c7 DW |
256 | opt.Wlog = parm; |
257 | if ((parm = tc_red_eval_P(opt.qth_min, opt.qth_max, probability)) < 0) { | |
aba5acdf SH |
258 | fprintf(stderr, "GRED: failed to calculate probability.\n"); |
259 | return -1; | |
260 | } | |
9d9a67c7 DW |
261 | opt.Plog = parm; |
262 | if ((parm = tc_red_eval_idle_damping(opt.Wlog, avpkt, rate, sbuf)) < 0) | |
aba5acdf | 263 | { |
32a121cb | 264 | fprintf(stderr, "GRED: failed to calculate idle damping table.\n"); |
aba5acdf SH |
265 | return -1; |
266 | } | |
9d9a67c7 | 267 | opt.Scell_log = parm; |
aba5acdf | 268 | |
c14f9d92 | 269 | tail = addattr_nest(n, 1024, TCA_OPTIONS); |
aba5acdf SH |
270 | addattr_l(n, 1024, TCA_GRED_PARMS, &opt, sizeof(opt)); |
271 | addattr_l(n, 1024, TCA_GRED_STAB, sbuf, 256); | |
1b6f0bb5 ED |
272 | max_P = probability * pow(2, 32); |
273 | addattr32(n, 1024, TCA_GRED_MAX_P, max_P); | |
f7a8749a JK |
274 | |
275 | vqs = addattr_nest(n, 1024, TCA_GRED_VQ_LIST); | |
276 | entry = addattr_nest(n, 1024, TCA_GRED_VQ_ENTRY); | |
277 | addattr32(n, 1024, TCA_GRED_VQ_DP, opt.DP); | |
278 | addattr32(n, 1024, TCA_GRED_VQ_FLAGS, flags); | |
279 | addattr_nest_end(n, entry); | |
280 | addattr_nest_end(n, vqs); | |
281 | ||
c14f9d92 | 282 | addattr_nest_end(n, tail); |
aba5acdf SH |
283 | return 0; |
284 | } | |
285 | ||
fdaff63c | 286 | struct tc_gred_info { |
f7a8749a | 287 | bool flags_present; |
fdaff63c JK |
288 | __u64 bytes; |
289 | __u32 packets; | |
290 | __u32 backlog; | |
291 | __u32 prob_drop; | |
292 | __u32 prob_mark; | |
293 | __u32 forced_drop; | |
294 | __u32 forced_mark; | |
295 | __u32 pdrop; | |
296 | __u32 other; | |
f7a8749a | 297 | __u32 flags; |
fdaff63c JK |
298 | }; |
299 | ||
300 | static void | |
301 | gred_parse_vqs(struct tc_gred_info *info, struct rtattr *vqs) | |
c3e1cd28 | 302 | { |
fdaff63c JK |
303 | int rem = RTA_PAYLOAD(vqs); |
304 | unsigned int offset = 0; | |
305 | ||
306 | while (rem > offset) { | |
307 | struct rtattr *tb_entry[TCA_GRED_VQ_ENTRY_MAX + 1] = {}; | |
308 | struct rtattr *tb[TCA_GRED_VQ_MAX + 1] = {}; | |
309 | struct rtattr *entry; | |
310 | unsigned int len; | |
311 | unsigned int dp; | |
312 | ||
313 | entry = RTA_DATA(vqs) + offset; | |
314 | ||
315 | parse_rtattr(tb_entry, TCA_GRED_VQ_ENTRY_MAX, entry, | |
316 | rem - offset); | |
317 | len = RTA_LENGTH(RTA_PAYLOAD(entry)); | |
318 | offset += len; | |
319 | ||
320 | if (!tb_entry[TCA_GRED_VQ_ENTRY]) { | |
321 | fprintf(stderr, | |
322 | "ERROR: Failed to parse Virtual Queue entry\n"); | |
323 | continue; | |
324 | } | |
325 | ||
326 | parse_rtattr_nested(tb, TCA_GRED_VQ_MAX, | |
327 | tb_entry[TCA_GRED_VQ_ENTRY]); | |
328 | ||
329 | if (!tb[TCA_GRED_VQ_DP]) { | |
330 | fprintf(stderr, | |
331 | "ERROR: Virtual Queue without DP attribute\n"); | |
332 | continue; | |
333 | } | |
334 | ||
335 | dp = rta_getattr_u32(tb[TCA_GRED_VQ_DP]); | |
336 | ||
337 | if (tb[TCA_GRED_VQ_STAT_BYTES]) | |
338 | info[dp].bytes = | |
339 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_BYTES]); | |
340 | if (tb[TCA_GRED_VQ_STAT_PACKETS]) | |
341 | info[dp].packets = | |
342 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_PACKETS]); | |
343 | if (tb[TCA_GRED_VQ_STAT_BACKLOG]) | |
344 | info[dp].backlog = | |
345 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_BACKLOG]); | |
346 | if (tb[TCA_GRED_VQ_STAT_PROB_DROP]) | |
347 | info[dp].prob_drop = | |
348 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_PROB_DROP]); | |
349 | if (tb[TCA_GRED_VQ_STAT_PROB_MARK]) | |
350 | info[dp].prob_mark = | |
351 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_PROB_MARK]); | |
352 | if (tb[TCA_GRED_VQ_STAT_FORCED_DROP]) | |
353 | info[dp].forced_drop = | |
354 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_FORCED_DROP]); | |
355 | if (tb[TCA_GRED_VQ_STAT_FORCED_MARK]) | |
356 | info[dp].forced_mark = | |
357 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_FORCED_MARK]); | |
358 | if (tb[TCA_GRED_VQ_STAT_PDROP]) | |
359 | info[dp].pdrop = | |
360 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_PDROP]); | |
361 | if (tb[TCA_GRED_VQ_STAT_OTHER]) | |
362 | info[dp].other = | |
363 | rta_getattr_u32(tb[TCA_GRED_VQ_STAT_OTHER]); | |
f7a8749a JK |
364 | info[dp].flags_present = !!tb[TCA_GRED_VQ_FLAGS]; |
365 | if (tb[TCA_GRED_VQ_FLAGS]) | |
366 | info[dp].flags = | |
367 | rta_getattr_u32(tb[TCA_GRED_VQ_FLAGS]); | |
fdaff63c JK |
368 | } |
369 | } | |
370 | ||
371 | static void | |
372 | gred_print_stats(struct tc_gred_info *info, struct tc_gred_qopt *qopt) | |
373 | { | |
374 | __u64 bytes = info ? info->bytes : qopt->bytesin; | |
375 | ||
c3e1cd28 JK |
376 | SPRINT_BUF(b1); |
377 | ||
378 | if (!is_json_context()) | |
379 | printf("\n Queue size: "); | |
380 | ||
381 | print_uint(PRINT_JSON, "qave", NULL, qopt->qave); | |
382 | print_string(PRINT_FP, NULL, "average %s ", | |
383 | sprint_size(qopt->qave, b1)); | |
384 | ||
385 | print_uint(PRINT_JSON, "backlog", NULL, qopt->backlog); | |
386 | print_string(PRINT_FP, NULL, "current %s ", | |
387 | sprint_size(qopt->backlog, b1)); | |
388 | ||
389 | if (!is_json_context()) | |
390 | printf("\n Dropped packets: "); | |
391 | ||
fdaff63c JK |
392 | if (info) { |
393 | print_uint(PRINT_ANY, "forced_drop", "forced %u ", | |
394 | info->forced_drop); | |
395 | print_uint(PRINT_ANY, "prob_drop", "early %u ", | |
396 | info->prob_drop); | |
397 | print_uint(PRINT_ANY, "pdrop", "pdrop %u ", info->pdrop); | |
398 | print_uint(PRINT_ANY, "other", "other %u ", info->other); | |
399 | ||
400 | if (!is_json_context()) | |
401 | printf("\n Marked packets: "); | |
402 | print_uint(PRINT_ANY, "forced_mark", "forced %u ", | |
403 | info->forced_mark); | |
404 | print_uint(PRINT_ANY, "prob_mark", "early %u ", | |
405 | info->prob_mark); | |
406 | } else { | |
407 | print_uint(PRINT_ANY, "forced_drop", "forced %u ", | |
408 | qopt->forced); | |
409 | print_uint(PRINT_ANY, "prob_drop", "early %u ", qopt->early); | |
410 | print_uint(PRINT_ANY, "pdrop", "pdrop %u ", qopt->pdrop); | |
411 | print_uint(PRINT_ANY, "other", "other %u ", qopt->other); | |
412 | } | |
c3e1cd28 JK |
413 | |
414 | if (!is_json_context()) | |
415 | printf("\n Total packets: "); | |
416 | ||
417 | print_uint(PRINT_ANY, "packets", "%u ", qopt->packets); | |
418 | ||
fdaff63c JK |
419 | print_uint(PRINT_JSON, "bytes", NULL, bytes); |
420 | print_string(PRINT_FP, NULL, "(%s) ", sprint_size(bytes, b1)); | |
c3e1cd28 JK |
421 | } |
422 | ||
aba5acdf SH |
423 | static int gred_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
424 | { | |
fdaff63c | 425 | struct tc_gred_info infos[MAX_DPs] = {}; |
1b6f0bb5 | 426 | struct rtattr *tb[TCA_GRED_MAX + 1]; |
1693a4d3 | 427 | struct tc_gred_sopt *sopt; |
aba5acdf | 428 | struct tc_gred_qopt *qopt; |
fdaff63c | 429 | bool vq_info = false; |
1b6f0bb5 | 430 | __u32 *max_p = NULL; |
aacee269 | 431 | __u32 *limit = NULL; |
32a121cb SH |
432 | unsigned int i; |
433 | ||
aba5acdf | 434 | SPRINT_BUF(b1); |
aba5acdf SH |
435 | |
436 | if (opt == NULL) | |
437 | return 0; | |
438 | ||
1b6f0bb5 | 439 | parse_rtattr_nested(tb, TCA_GRED_MAX, opt); |
aba5acdf SH |
440 | |
441 | if (tb[TCA_GRED_PARMS] == NULL) | |
442 | return -1; | |
a5a6f1e8 | 443 | |
1b6f0bb5 ED |
444 | if (tb[TCA_GRED_MAX_P] && |
445 | RTA_PAYLOAD(tb[TCA_GRED_MAX_P]) >= sizeof(__u32) * MAX_DPs) | |
446 | max_p = RTA_DATA(tb[TCA_GRED_MAX_P]); | |
447 | ||
aacee269 DW |
448 | if (tb[TCA_GRED_LIMIT] && |
449 | RTA_PAYLOAD(tb[TCA_GRED_LIMIT]) == sizeof(__u32)) | |
450 | limit = RTA_DATA(tb[TCA_GRED_LIMIT]); | |
451 | ||
1693a4d3 | 452 | sopt = RTA_DATA(tb[TCA_GRED_DPS]); |
aba5acdf | 453 | qopt = RTA_DATA(tb[TCA_GRED_PARMS]); |
1693a4d3 DW |
454 | if (RTA_PAYLOAD(tb[TCA_GRED_DPS]) < sizeof(*sopt) || |
455 | RTA_PAYLOAD(tb[TCA_GRED_PARMS]) < sizeof(*qopt)*MAX_DPs) { | |
32a121cb | 456 | fprintf(f, "\n GRED received message smaller than expected\n"); |
aba5acdf | 457 | return -1; |
1693a4d3 | 458 | } |
ae665a52 | 459 | |
f7a8749a | 460 | if (tb[TCA_GRED_VQ_LIST]) { |
fdaff63c JK |
461 | gred_parse_vqs(infos, tb[TCA_GRED_VQ_LIST]); |
462 | vq_info = true; | |
463 | } | |
464 | ||
6475e6a5 JK |
465 | print_uint(PRINT_ANY, "dp_cnt", "vqs %u ", sopt->DPs); |
466 | print_uint(PRINT_ANY, "dp_default", "default %u ", sopt->def_DP); | |
1693a4d3 | 467 | |
6475e6a5 JK |
468 | if (sopt->grio) |
469 | print_bool(PRINT_ANY, "grio", "grio ", true); | |
470 | else | |
471 | print_bool(PRINT_ANY, "grio", NULL, false); | |
472 | ||
473 | if (limit) { | |
474 | print_uint(PRINT_JSON, "limit", NULL, *limit); | |
475 | print_string(PRINT_FP, NULL, "limit %s ", | |
476 | sprint_size(*limit, b1)); | |
477 | } | |
aacee269 | 478 | |
2d7c564a JK |
479 | tc_red_print_flags(sopt->flags); |
480 | ||
6475e6a5 | 481 | open_json_array(PRINT_JSON, "vqs"); |
32a121cb | 482 | for (i = 0; i < MAX_DPs; i++, qopt++) { |
6475e6a5 JK |
483 | if (qopt->DP >= MAX_DPs) |
484 | continue; | |
485 | ||
486 | open_json_object(NULL); | |
487 | ||
488 | print_uint(PRINT_ANY, "vq", "\n vq %u ", qopt->DP); | |
489 | print_hhu(PRINT_ANY, "prio", "prio %hhu ", qopt->prio); | |
490 | ||
491 | print_uint(PRINT_JSON, "limit", NULL, qopt->limit); | |
492 | print_string(PRINT_FP, NULL, "limit %s ", | |
493 | sprint_size(qopt->limit, b1)); | |
494 | ||
495 | print_uint(PRINT_JSON, "min", NULL, qopt->qth_min); | |
496 | print_string(PRINT_FP, NULL, "min %s ", | |
497 | sprint_size(qopt->qth_min, b1)); | |
498 | ||
499 | print_uint(PRINT_JSON, "max", NULL, qopt->qth_max); | |
500 | print_string(PRINT_FP, NULL, "max %s ", | |
501 | sprint_size(qopt->qth_max, b1)); | |
502 | ||
f7a8749a JK |
503 | if (infos[i].flags_present) |
504 | tc_red_print_flags(infos[i].flags); | |
505 | ||
1693a4d3 | 506 | if (show_details) { |
6475e6a5 | 507 | print_uint(PRINT_ANY, "ewma", "ewma %u ", qopt->Wlog); |
1693a4d3 | 508 | if (max_p) |
6475e6a5 JK |
509 | print_float(PRINT_ANY, "probability", |
510 | "probability %lg ", | |
511 | max_p[i] / pow(2, 32)); | |
1693a4d3 | 512 | else |
6475e6a5 JK |
513 | print_uint(PRINT_ANY, "Plog", "Plog %u ", |
514 | qopt->Plog); | |
515 | print_uint(PRINT_ANY, "Scell_log", "Scell_log %u ", | |
516 | qopt->Scell_log); | |
1693a4d3 | 517 | } |
c3e1cd28 | 518 | if (show_stats) |
fdaff63c | 519 | gred_print_stats(vq_info ? &infos[i] : NULL, qopt); |
6475e6a5 | 520 | close_json_object(); |
aba5acdf | 521 | } |
6475e6a5 | 522 | close_json_array(PRINT_JSON, "vqs"); |
aba5acdf SH |
523 | return 0; |
524 | } | |
525 | ||
95812b56 | 526 | struct qdisc_util gred_qdisc_util = { |
f2f99e2e SH |
527 | .id = "gred", |
528 | .parse_qopt = gred_parse_opt, | |
529 | .print_qopt = gred_print_opt, | |
aba5acdf | 530 | }; |