]> git.proxmox.com Git - mirror_iproute2.git/blame - tc/q_netem.c
ip: add support for seg6local End.BPF action
[mirror_iproute2.git] / tc / q_netem.c
CommitLineData
309a4c90
SH
1/*
2 * q_netem.c NETEM.
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 *
59a935d2 9 * Authors: Stephen Hemminger <shemminger@linux-foundation.org>
309a4c90
SH
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
3c7950af
SH
15#include <math.h>
16#include <ctype.h>
309a4c90 17#include <unistd.h>
309a4c90 18#include <fcntl.h>
e4beb527 19#include <stdint.h>
309a4c90
SH
20#include <sys/socket.h>
21#include <netinet/in.h>
22#include <arpa/inet.h>
23#include <string.h>
b7be3d0c 24#include <errno.h>
309a4c90
SH
25
26#include "utils.h"
27#include "tc_util.h"
b7be3d0c 28#include "tc_common.h"
309a4c90
SH
29
30static void explain(void)
31{
ae665a52 32 fprintf(stderr,
32a121cb 33"Usage: ... netem [ limit PACKETS ]\n" \
ea8fc104
SH
34" [ delay TIME [ JITTER [CORRELATION]]]\n" \
35" [ distribution {uniform|normal|pareto|paretonormal} ]\n" \
32a121cb 36" [ corrupt PERCENT [CORRELATION]]\n" \
b7be3d0c 37" [ duplicate PERCENT [CORRELATION]]\n" \
3c7950af
SH
38" [ loss random PERCENT [CORRELATION]]\n" \
39" [ loss state P13 [P31 [P32 [P23 P14]]]\n" \
40" [ loss gemodel PERCENT [R [1-H [1-K]]]\n" \
1070205d 41" [ ecn ]\n" \
6b8dc4de
HPP
42" [ reorder PRECENT [CORRELATION] [ gap DISTANCE ]]\n" \
43" [ rate RATE [PACKETOVERHEAD] [CELLSIZE] [CELLOVERHEAD]]\n");
309a4c90
SH
44}
45
46static void explain1(const char *arg)
47{
48 fprintf(stderr, "Illegal \"%s\"\n", arg);
49}
50
3c7950af 51/* Upper bound on size of distribution
c1b81cb5
SH
52 * really (TCA_BUF_MAX - other headers) / sizeof (__s16)
53 */
54#define MAX_DIST (16*1024)
55
3c7950af
SH
56/* scaled value used to percent of maximum. */
57static void set_percent(__u32 *percent, double per)
58{
e4beb527 59 *percent = rint(per * UINT32_MAX);
3c7950af
SH
60}
61
3c7950af
SH
62static int get_percent(__u32 *percent, const char *str)
63{
64 double per;
65
66 if (parse_percent(&per, str))
67 return -1;
68
69 set_percent(percent, per);
70 return 0;
71}
72
d1f28cf1 73static void print_percent(char *buf, int len, __u32 per)
3c7950af 74{
e4beb527 75 snprintf(buf, len, "%g%%", (100. * per) / UINT32_MAX);
3c7950af
SH
76}
77
32a121cb 78static char *sprint_percent(__u32 per, char *buf)
3c7950af
SH
79{
80 print_percent(buf, SPRINT_BSIZE-1, per);
81 return buf;
82}
83
2e21655e
SH
84/*
85 * Simplistic file parser for distrbution data.
86 * Format is:
87 * # comment line(s)
c1b81cb5 88 * data0 data1 ...
2e21655e 89 */
c1b81cb5 90static int get_distribution(const char *type, __s16 *data, int maxdata)
b7be3d0c
SH
91{
92 FILE *f;
93 int n;
2e21655e
SH
94 long x;
95 size_t len;
fb9b1d0f 96 char *line = NULL;
2e21655e 97 char name[128];
b7be3d0c 98
aa27f88c 99 snprintf(name, sizeof(name), "%s/%s.dist", get_tc_lib(), type);
2e21655e 100 if ((f = fopen(name, "r")) == NULL) {
ae665a52 101 fprintf(stderr, "No distribution data for %s (%s: %s)\n",
2e21655e 102 type, name, strerror(errno));
b7be3d0c
SH
103 return -1;
104 }
ae665a52 105
b7be3d0c 106 n = 0;
2e21655e
SH
107 while (getline(&line, &len, f) != -1) {
108 char *p, *endp;
32a121cb 109
2e21655e 110 if (*line == '\n' || *line == '#')
b7be3d0c
SH
111 continue;
112
2e21655e
SH
113 for (p = line; ; p = endp) {
114 x = strtol(p, &endp, 0);
ae665a52 115 if (endp == p)
2e21655e
SH
116 break;
117
c1b81cb5 118 if (n >= maxdata) {
2e21655e
SH
119 fprintf(stderr, "%s: too much data\n",
120 name);
121 n = -1;
122 goto error;
123 }
b7be3d0c
SH
124 data[n++] = x;
125 }
126 }
2e21655e
SH
127 error:
128 free(line);
b7be3d0c 129 fclose(f);
b7be3d0c
SH
130 return n;
131}
132
3c7950af 133#define NEXT_IS_NUMBER() (NEXT_ARG_OK() && isdigit(argv[1][0]))
e72ca3fb
JN
134#define NEXT_IS_SIGNED_NUMBER() \
135 (NEXT_ARG_OK() && (isdigit(argv[1][0]) || argv[1][0] == '-'))
b7be3d0c 136
ae665a52 137/* Adjust for the fact that psched_ticks aren't always usecs
b7be3d0c
SH
138 (based on kernel PSCHED_CLOCK configuration */
139static int get_ticks(__u32 *ticks, const char *str)
140{
32a121cb 141 unsigned int t;
b7be3d0c 142
32a121cb 143 if (get_time(&t, str))
b7be3d0c 144 return -1;
ae665a52 145
8f34caaf
PM
146 if (tc_core_time2big(t)) {
147 fprintf(stderr, "Illegal %u time (too large)\n", t);
fa565130
SH
148 return -1;
149 }
150
8f34caaf 151 *ticks = tc_core_time2tick(t);
b7be3d0c
SH
152 return 0;
153}
154
ae665a52 155static int netem_parse_opt(struct qdisc_util *qu, int argc, char **argv,
927e3cfb 156 struct nlmsghdr *n, const char *dev)
309a4c90 157{
fcbd0165 158 int dist_size = 0;
2e21655e 159 struct rtattr *tail;
3c7950af 160 struct tc_netem_qopt opt = { .limit = 1000 };
d17b136f
PS
161 struct tc_netem_corr cor = {};
162 struct tc_netem_reorder reorder = {};
163 struct tc_netem_corrupt corrupt = {};
3c7950af
SH
164 struct tc_netem_gimodel gimodel;
165 struct tc_netem_gemodel gemodel;
d17b136f 166 struct tc_netem_rate rate = {};
a31a5d59 167 __s16 *dist_data = NULL;
3c7950af 168 __u16 loss_type = NETEM_LOSS_UNSPEC;
d17b136f 169 int present[__TCA_NETEM_MAX] = {};
dad2f72b 170 __u64 rate64 = 0;
309a4c90 171
32a121cb 172 for ( ; argc > 0; --argc, ++argv) {
309a4c90
SH
173 if (matches(*argv, "limit") == 0) {
174 NEXT_ARG();
2e21655e 175 if (get_size(&opt.limit, *argv)) {
309a4c90
SH
176 explain1("limit");
177 return -1;
178 }
b7be3d0c
SH
179 } else if (matches(*argv, "latency") == 0 ||
180 matches(*argv, "delay") == 0) {
309a4c90 181 NEXT_ARG();
2e21655e 182 if (get_ticks(&opt.latency, *argv)) {
309a4c90
SH
183 explain1("latency");
184 return -1;
185 }
b7be3d0c
SH
186
187 if (NEXT_IS_NUMBER()) {
188 NEXT_ARG();
2e21655e 189 if (get_ticks(&opt.jitter, *argv)) {
b7be3d0c
SH
190 explain1("latency");
191 return -1;
192 }
193
194 if (NEXT_IS_NUMBER()) {
195 NEXT_ARG();
40076f62 196 ++present[TCA_NETEM_CORR];
3c7950af 197 if (get_percent(&cor.delay_corr, *argv)) {
b7be3d0c
SH
198 explain1("latency");
199 return -1;
200 }
201 }
202 }
203 } else if (matches(*argv, "loss") == 0 ||
204 matches(*argv, "drop") == 0) {
3c7950af
SH
205 if (opt.loss > 0 || loss_type != NETEM_LOSS_UNSPEC) {
206 explain1("duplicate loss argument\n");
309a4c90
SH
207 return -1;
208 }
3c7950af
SH
209
210 NEXT_ARG();
211 /* Old (deprecated) random loss model syntax */
212 if (isdigit(argv[0][0]))
213 goto random_loss_model;
214
215 if (!strcmp(*argv, "random")) {
b7be3d0c 216 NEXT_ARG();
268a9eee 217 random_loss_model:
3c7950af
SH
218 if (get_percent(&opt.loss, *argv)) {
219 explain1("loss percent");
220 return -1;
221 }
222 if (NEXT_IS_NUMBER()) {
223 NEXT_ARG();
224 ++present[TCA_NETEM_CORR];
225 if (get_percent(&cor.loss_corr, *argv)) {
226 explain1("loss correllation");
227 return -1;
228 }
229 }
230 } else if (!strcmp(*argv, "state")) {
231 double p13;
232
233 NEXT_ARG();
234 if (parse_percent(&p13, *argv)) {
235 explain1("loss p13");
236 return -1;
237 }
238
239 /* set defaults */
240 set_percent(&gimodel.p13, p13);
241 set_percent(&gimodel.p31, 1. - p13);
242 set_percent(&gimodel.p32, 0);
243 set_percent(&gimodel.p23, 1.);
8f9672af 244 set_percent(&gimodel.p14, 0);
3c7950af
SH
245 loss_type = NETEM_LOSS_GI;
246
247 if (!NEXT_IS_NUMBER())
248 continue;
249 NEXT_ARG();
250 if (get_percent(&gimodel.p31, *argv)) {
251 explain1("loss p31");
252 return -1;
253 }
254
255 if (!NEXT_IS_NUMBER())
256 continue;
257 NEXT_ARG();
258 if (get_percent(&gimodel.p32, *argv)) {
259 explain1("loss p32");
260 return -1;
261 }
262
263 if (!NEXT_IS_NUMBER())
264 continue;
265 NEXT_ARG();
266 if (get_percent(&gimodel.p23, *argv)) {
267 explain1("loss p23");
268 return -1;
269 }
8f9672af
JV
270 if (!NEXT_IS_NUMBER())
271 continue;
272 NEXT_ARG();
273 if (get_percent(&gimodel.p14, *argv)) {
274 explain1("loss p14");
275 return -1;
276 }
3c7950af
SH
277
278 } else if (!strcmp(*argv, "gemodel")) {
279 NEXT_ARG();
280 if (get_percent(&gemodel.p, *argv)) {
281 explain1("loss gemodel p");
282 return -1;
283 }
284
285 /* set defaults */
286 set_percent(&gemodel.r, 1.);
287 set_percent(&gemodel.h, 0);
3757185b 288 set_percent(&gemodel.k1, 0);
3c7950af
SH
289 loss_type = NETEM_LOSS_GE;
290
291 if (!NEXT_IS_NUMBER())
292 continue;
293 NEXT_ARG();
294 if (get_percent(&gemodel.r, *argv)) {
295 explain1("loss gemodel r");
296 return -1;
297 }
298
299 if (!NEXT_IS_NUMBER())
300 continue;
301 NEXT_ARG();
302 if (get_percent(&gemodel.h, *argv)) {
303 explain1("loss gemodel h");
304 return -1;
305 }
3757185b
JV
306 /* netem option is "1-h" but kernel
307 * expects "h".
308 */
e4beb527 309 gemodel.h = UINT32_MAX - gemodel.h;
3c7950af
SH
310
311 if (!NEXT_IS_NUMBER())
312 continue;
313 NEXT_ARG();
314 if (get_percent(&gemodel.k1, *argv)) {
315 explain1("loss gemodel k");
b7be3d0c
SH
316 return -1;
317 }
3c7950af
SH
318 } else {
319 fprintf(stderr, "Unknown loss parameter: %s\n",
320 *argv);
321 return -1;
b7be3d0c 322 }
1070205d 323 } else if (matches(*argv, "ecn") == 0) {
268a9eee 324 present[TCA_NETEM_ECN] = 1;
ea8fc104
SH
325 } else if (matches(*argv, "reorder") == 0) {
326 NEXT_ARG();
40076f62 327 present[TCA_NETEM_REORDER] = 1;
ea8fc104
SH
328 if (get_percent(&reorder.probability, *argv)) {
329 explain1("reorder");
330 return -1;
331 }
332 if (NEXT_IS_NUMBER()) {
333 NEXT_ARG();
40076f62 334 ++present[TCA_NETEM_CORR];
ea8fc104
SH
335 if (get_percent(&reorder.correlation, *argv)) {
336 explain1("reorder");
337 return -1;
338 }
339 }
a31a5d59
SH
340 } else if (matches(*argv, "corrupt") == 0) {
341 NEXT_ARG();
40076f62 342 present[TCA_NETEM_CORRUPT] = 1;
a31a5d59
SH
343 if (get_percent(&corrupt.probability, *argv)) {
344 explain1("corrupt");
345 return -1;
346 }
347 if (NEXT_IS_NUMBER()) {
348 NEXT_ARG();
40076f62 349 ++present[TCA_NETEM_CORR];
a31a5d59
SH
350 if (get_percent(&corrupt.correlation, *argv)) {
351 explain1("corrupt");
352 return -1;
353 }
354 }
309a4c90 355 } else if (matches(*argv, "gap") == 0) {
309a4c90 356 NEXT_ARG();
2e21655e 357 if (get_u32(&opt.gap, *argv, 0)) {
309a4c90
SH
358 explain1("gap");
359 return -1;
360 }
ffb79d06 361 } else if (matches(*argv, "duplicate") == 0) {
309a4c90 362 NEXT_ARG();
2e21655e 363 if (get_percent(&opt.duplicate, *argv)) {
ffb79d06 364 explain1("duplicate");
309a4c90
SH
365 return -1;
366 }
b7be3d0c
SH
367 if (NEXT_IS_NUMBER()) {
368 NEXT_ARG();
2e21655e 369 if (get_percent(&cor.dup_corr, *argv)) {
b7be3d0c
SH
370 explain1("duplicate");
371 return -1;
372 }
373 }
374 } else if (matches(*argv, "distribution") == 0) {
309a4c90 375 NEXT_ARG();
c1b81cb5
SH
376 dist_data = calloc(sizeof(dist_data[0]), MAX_DIST);
377 dist_size = get_distribution(*argv, dist_data, MAX_DIST);
378 if (dist_size <= 0) {
379 free(dist_data);
309a4c90 380 return -1;
c1b81cb5 381 }
6b8dc4de
HPP
382 } else if (matches(*argv, "rate") == 0) {
383 ++present[TCA_NETEM_RATE];
384 NEXT_ARG();
927e3cfb
ND
385 if (strchr(*argv, '%')) {
386 if (get_percent_rate64(&rate64, *argv, dev)) {
387 explain1("rate");
388 return -1;
389 }
390 } else if (get_rate64(&rate64, *argv)) {
6b8dc4de
HPP
391 explain1("rate");
392 return -1;
393 }
e72ca3fb 394 if (NEXT_IS_SIGNED_NUMBER()) {
6b8dc4de
HPP
395 NEXT_ARG();
396 if (get_s32(&rate.packet_overhead, *argv, 0)) {
397 explain1("rate");
398 return -1;
399 }
400 }
401 if (NEXT_IS_NUMBER()) {
402 NEXT_ARG();
403 if (get_u32(&rate.cell_size, *argv, 0)) {
404 explain1("rate");
405 return -1;
406 }
407 }
e72ca3fb 408 if (NEXT_IS_SIGNED_NUMBER()) {
6b8dc4de
HPP
409 NEXT_ARG();
410 if (get_s32(&rate.cell_overhead, *argv, 0)) {
411 explain1("rate");
412 return -1;
413 }
414 }
309a4c90
SH
415 } else if (strcmp(*argv, "help") == 0) {
416 explain();
417 return -1;
418 } else {
419 fprintf(stderr, "What is \"%s\"?\n", *argv);
420 explain();
421 return -1;
422 }
309a4c90
SH
423 }
424
ea8fc104
SH
425 if (reorder.probability) {
426 if (opt.latency == 0) {
427 fprintf(stderr, "reordering not possible without specifying some delay\n");
14a1c164
VS
428 explain();
429 return -1;
ea8fc104
SH
430 }
431 if (opt.gap == 0)
432 opt.gap = 1;
433 } else if (opt.gap > 0) {
434 fprintf(stderr, "gap specified without reorder probability\n");
435 explain();
436 return -1;
437 }
438
1070205d
VS
439 if (present[TCA_NETEM_ECN]) {
440 if (opt.loss <= 0 && loss_type == NETEM_LOSS_UNSPEC) {
441 fprintf(stderr, "ecn requested without loss model\n");
442 explain();
443 return -1;
444 }
445 }
446
a31a5d59 447 if (dist_data && (opt.latency == 0 || opt.jitter == 0)) {
ea8fc104
SH
448 fprintf(stderr, "distribution specified but no latency and jitter values\n");
449 explain();
450 return -1;
451 }
452
c14f9d92 453 tail = addattr_nest_compat(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
2e21655e 454
40076f62 455 if (present[TCA_NETEM_CORR] &&
c1b81cb5 456 addattr_l(n, 1024, TCA_NETEM_CORR, &cor, sizeof(cor)) < 0)
268a9eee 457 return -1;
a31a5d59 458
3c7950af 459 if (present[TCA_NETEM_REORDER] &&
c1b81cb5 460 addattr_l(n, 1024, TCA_NETEM_REORDER, &reorder, sizeof(reorder)) < 0)
e9bc3c40 461 return -1;
a31a5d59 462
1070205d
VS
463 if (present[TCA_NETEM_ECN] &&
464 addattr_l(n, 1024, TCA_NETEM_ECN, &present[TCA_NETEM_ECN],
465 sizeof(present[TCA_NETEM_ECN])) < 0)
268a9eee 466 return -1;
1070205d 467
40076f62 468 if (present[TCA_NETEM_CORRUPT] &&
c1b81cb5 469 addattr_l(n, 1024, TCA_NETEM_CORRUPT, &corrupt, sizeof(corrupt)) < 0)
40076f62 470 return -1;
a31a5d59 471
3c7950af
SH
472 if (loss_type != NETEM_LOSS_UNSPEC) {
473 struct rtattr *start;
474
475 start = addattr_nest(n, 1024, TCA_NETEM_LOSS | NLA_F_NESTED);
476 if (loss_type == NETEM_LOSS_GI) {
477 if (addattr_l(n, 1024, NETEM_LOSS_GI,
478 &gimodel, sizeof(gimodel)) < 0)
268a9eee 479 return -1;
3c7950af
SH
480 } else if (loss_type == NETEM_LOSS_GE) {
481 if (addattr_l(n, 1024, NETEM_LOSS_GE,
482 &gemodel, sizeof(gemodel)) < 0)
268a9eee 483 return -1;
3c7950af
SH
484 } else {
485 fprintf(stderr, "loss in the weeds!\n");
486 return -1;
487 }
3d0b7439 488
3c7950af
SH
489 addattr_nest_end(n, start);
490 }
491
dad2f72b
YY
492 if (present[TCA_NETEM_RATE]) {
493 if (rate64 >= (1ULL << 32)) {
494 if (addattr_l(n, 1024,
495 TCA_NETEM_RATE64, &rate64, sizeof(rate64)) < 0)
496 return -1;
497 rate.rate = ~0U;
498 } else {
499 rate.rate = rate64;
500 }
501 if (addattr_l(n, 1024, TCA_NETEM_RATE, &rate, sizeof(rate)) < 0)
502 return -1;
503 }
6b8dc4de 504
a31a5d59 505 if (dist_data) {
c1b81cb5
SH
506 if (addattr_l(n, MAX_DIST * sizeof(dist_data[0]),
507 TCA_NETEM_DELAY_DIST,
508 dist_data, dist_size * sizeof(dist_data[0])) < 0)
a31a5d59 509 return -1;
c1b81cb5 510 free(dist_data);
2e21655e 511 }
c14f9d92 512 addattr_nest_compat_end(n, tail);
b7be3d0c 513 return 0;
309a4c90
SH
514}
515
516static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
517{
2e21655e 518 const struct tc_netem_corr *cor = NULL;
ea8fc104 519 const struct tc_netem_reorder *reorder = NULL;
a31a5d59 520 const struct tc_netem_corrupt *corrupt = NULL;
3c7950af
SH
521 const struct tc_netem_gimodel *gimodel = NULL;
522 const struct tc_netem_gemodel *gemodel = NULL;
1070205d 523 int *ecn = NULL;
2e21655e 524 struct tc_netem_qopt qopt;
6b8dc4de 525 const struct tc_netem_rate *rate = NULL;
a754de3c 526 int len;
dad2f72b 527 __u64 rate64 = 0;
32a121cb 528
309a4c90 529 SPRINT_BUF(b1);
309a4c90
SH
530
531 if (opt == NULL)
532 return 0;
533
a754de3c 534 len = RTA_PAYLOAD(opt) - sizeof(qopt);
2e21655e
SH
535 if (len < 0) {
536 fprintf(stderr, "options size error\n");
309a4c90 537 return -1;
b7be3d0c 538 }
2e21655e
SH
539 memcpy(&qopt, RTA_DATA(opt), sizeof(qopt));
540
541 if (len > 0) {
1d2d1cb5 542 struct rtattr *tb[TCA_NETEM_MAX+1];
32a121cb 543
2e21655e
SH
544 parse_rtattr(tb, TCA_NETEM_MAX, RTA_DATA(opt) + sizeof(qopt),
545 len);
ae665a52 546
2e21655e
SH
547 if (tb[TCA_NETEM_CORR]) {
548 if (RTA_PAYLOAD(tb[TCA_NETEM_CORR]) < sizeof(*cor))
549 return -1;
550 cor = RTA_DATA(tb[TCA_NETEM_CORR]);
551 }
ea8fc104
SH
552 if (tb[TCA_NETEM_REORDER]) {
553 if (RTA_PAYLOAD(tb[TCA_NETEM_REORDER]) < sizeof(*reorder))
554 return -1;
555 reorder = RTA_DATA(tb[TCA_NETEM_REORDER]);
556 }
a31a5d59
SH
557 if (tb[TCA_NETEM_CORRUPT]) {
558 if (RTA_PAYLOAD(tb[TCA_NETEM_CORRUPT]) < sizeof(*corrupt))
559 return -1;
e9bc3c40 560 corrupt = RTA_DATA(tb[TCA_NETEM_CORRUPT]);
a31a5d59 561 }
3c7950af
SH
562 if (tb[TCA_NETEM_LOSS]) {
563 struct rtattr *lb[NETEM_LOSS_MAX + 1];
564
565 parse_rtattr_nested(lb, NETEM_LOSS_MAX, tb[TCA_NETEM_LOSS]);
566 if (lb[NETEM_LOSS_GI])
8f9672af 567 gimodel = RTA_DATA(lb[NETEM_LOSS_GI]);
3c7950af
SH
568 if (lb[NETEM_LOSS_GE])
569 gemodel = RTA_DATA(lb[NETEM_LOSS_GE]);
3d0b7439 570 }
6b8dc4de
HPP
571 if (tb[TCA_NETEM_RATE]) {
572 if (RTA_PAYLOAD(tb[TCA_NETEM_RATE]) < sizeof(*rate))
573 return -1;
574 rate = RTA_DATA(tb[TCA_NETEM_RATE]);
575 }
1070205d
VS
576 if (tb[TCA_NETEM_ECN]) {
577 if (RTA_PAYLOAD(tb[TCA_NETEM_ECN]) < sizeof(*ecn))
578 return -1;
579 ecn = RTA_DATA(tb[TCA_NETEM_ECN]);
580 }
dad2f72b
YY
581 if (tb[TCA_NETEM_RATE64]) {
582 if (RTA_PAYLOAD(tb[TCA_NETEM_RATE64]) < sizeof(rate64))
583 return -1;
584 rate64 = rta_getattr_u64(tb[TCA_NETEM_RATE64]);
585 }
2e21655e 586 }
309a4c90 587
2e21655e 588 fprintf(f, "limit %d", qopt.limit);
31fa60e0 589
2e21655e
SH
590 if (qopt.latency) {
591 fprintf(f, " delay %s", sprint_ticks(qopt.latency, b1));
b7be3d0c 592
2e21655e
SH
593 if (qopt.jitter) {
594 fprintf(f, " %s", sprint_ticks(qopt.jitter, b1));
595 if (cor && cor->delay_corr)
596 fprintf(f, " %s", sprint_percent(cor->delay_corr, b1));
b7be3d0c
SH
597 }
598 }
599
2e21655e
SH
600 if (qopt.loss) {
601 fprintf(f, " loss %s", sprint_percent(qopt.loss, b1));
602 if (cor && cor->loss_corr)
603 fprintf(f, " %s", sprint_percent(cor->loss_corr, b1));
b7be3d0c
SH
604 }
605
3c7950af
SH
606 if (gimodel) {
607 fprintf(f, " loss state p13 %s", sprint_percent(gimodel->p13, b1));
608 fprintf(f, " p31 %s", sprint_percent(gimodel->p31, b1));
609 fprintf(f, " p32 %s", sprint_percent(gimodel->p32, b1));
610 fprintf(f, " p23 %s", sprint_percent(gimodel->p23, b1));
611 fprintf(f, " p14 %s", sprint_percent(gimodel->p14, b1));
612 }
613
614 if (gemodel) {
3757185b 615 fprintf(f, " loss gemodel p %s",
3c7950af
SH
616 sprint_percent(gemodel->p, b1));
617 fprintf(f, " r %s", sprint_percent(gemodel->r, b1));
e4beb527 618 fprintf(f, " 1-h %s", sprint_percent(UINT32_MAX -
3757185b 619 gemodel->h, b1));
3c7950af
SH
620 fprintf(f, " 1-k %s", sprint_percent(gemodel->k1, b1));
621 }
622
2e21655e 623 if (qopt.duplicate) {
b7be3d0c 624 fprintf(f, " duplicate %s",
2e21655e
SH
625 sprint_percent(qopt.duplicate, b1));
626 if (cor && cor->dup_corr)
627 fprintf(f, " %s", sprint_percent(cor->dup_corr, b1));
b7be3d0c 628 }
ae665a52 629
ea8fc104 630 if (reorder && reorder->probability) {
ae665a52 631 fprintf(f, " reorder %s",
ea8fc104
SH
632 sprint_percent(reorder->probability, b1));
633 if (reorder->correlation)
ae665a52 634 fprintf(f, " %s",
ea8fc104
SH
635 sprint_percent(reorder->correlation, b1));
636 }
b7be3d0c 637
a31a5d59 638 if (corrupt && corrupt->probability) {
ae665a52 639 fprintf(f, " corrupt %s",
a31a5d59
SH
640 sprint_percent(corrupt->probability, b1));
641 if (corrupt->correlation)
ae665a52 642 fprintf(f, " %s",
a31a5d59
SH
643 sprint_percent(corrupt->correlation, b1));
644 }
645
6b8dc4de 646 if (rate && rate->rate) {
dad2f72b
YY
647 if (rate64)
648 fprintf(f, " rate %s", sprint_rate(rate64, b1));
649 else
650 fprintf(f, " rate %s", sprint_rate(rate->rate, b1));
6b8dc4de
HPP
651 if (rate->packet_overhead)
652 fprintf(f, " packetoverhead %d", rate->packet_overhead);
653 if (rate->cell_size)
654 fprintf(f, " cellsize %u", rate->cell_size);
655 if (rate->cell_overhead)
656 fprintf(f, " celloverhead %d", rate->cell_overhead);
657 }
658
1070205d
VS
659 if (ecn)
660 fprintf(f, " ecn ");
661
2e21655e
SH
662 if (qopt.gap)
663 fprintf(f, " gap %lu", (unsigned long)qopt.gap);
309a4c90 664
1070205d 665
309a4c90
SH
666 return 0;
667}
668
95812b56 669struct qdisc_util netem_qdisc_util = {
32a121cb 670 .id = "netem",
31fa60e0
SH
671 .parse_qopt = netem_parse_opt,
672 .print_qopt = netem_print_opt,
309a4c90 673};