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