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