]>
git.proxmox.com Git - mirror_iproute2.git/blob - tc/q_netem.c
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.
9 * Authors: Stephen Hemminger <shemminger@osdl.org>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
26 static void explain(void)
29 "Usage: ... netem latency TIME [ jitter TIME ] [ limit PACKETS] \n" \
30 " [ loss PERCENT ] [ duplicate PERCENT ]\n" \
34 static void explain1(const char *arg
)
36 fprintf(stderr
, "Illegal \"%s\"\n", arg
);
39 #define usage() return(-1)
41 static int netem_parse_opt(struct qdisc_util
*qu
, int argc
, char **argv
,
44 struct tc_netem_qopt opt
;
48 memset(&opt
, 0, sizeof(opt
));
52 if (matches(*argv
, "limit") == 0) {
54 if (get_size(&opt
.limit
, *argv
)) {
59 } else if (matches(*argv
, "latency") == 0) {
61 if (get_usecs(&latency
, *argv
)) {
66 } else if (matches(*argv
, "loss") == 0) {
68 if (get_percent(&opt
.loss
, *argv
)) {
73 } else if (matches(*argv
, "gap") == 0) {
75 if (get_u32(&opt
.gap
, *argv
, 0)) {
80 } else if (matches(*argv
, "duplicate") == 0) {
82 if (get_percent(&opt
.duplicate
, *argv
)) {
83 explain1("duplicate");
87 } else if (matches(*argv
, "jitter") == 0) {
89 if (get_usecs(&opt
.jitter
, *argv
)) {
94 } else if (strcmp(*argv
, "help") == 0) {
98 fprintf(stderr
, "What is \"%s\"?\n", *argv
);
105 opt
.latency
= tc_core_usec2tick(latency
);
107 return ok
? addattr_l(n
, 1024, TCA_OPTIONS
, &opt
, sizeof(opt
)) : 0;
110 static int netem_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
112 struct tc_netem_qopt
*qopt
;
118 if (RTA_PAYLOAD(opt
) < sizeof(*qopt
))
121 qopt
= RTA_DATA(opt
);
123 fprintf(f
, "limit %d", qopt
->limit
);
125 fprintf(f
, " latency %s",
126 sprint_usecs(tc_core_tick2usec(qopt
->latency
), b1
));
128 fprintf(f
, " jitter %s", sprint_usecs(qopt
->jitter
, b1
));
131 fprintf(f
, " loss %s",
132 sprint_percent(qopt
->loss
, b1
));
134 fprintf(f
, " gap %lu", (unsigned long)qopt
->gap
);
140 static int netem_print_xstats(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*xstats
)
145 struct qdisc_util netem_util
= {
147 .parse_qopt
= netem_parse_opt
,
148 .print_qopt
= netem_print_opt
,
149 .print_xstats
= netem_print_xstats
,