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 [ gap PACKETS] \n" \
30 " [ loss PERCENT ] [ duplicate PERCENT ]\n" \
31 " [ rate KBPS ] [ limit BYTES]\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;
47 memset(&opt, 0, sizeof(opt));
51 if (matches(*argv, "limit") == 0) {
53 if (get_size(&opt.limit, *argv)) {
58 } else if (matches(*argv, "latency") == 0) {
60 if (get_usecs(&opt.latency, *argv)) {
65 } else if (matches(*argv, "loss") == 0) {
67 if (get_percent(&opt.loss, *argv)) {
72 } else if (matches(*argv, "gap") == 0) {
75 opt.gap = strtoul(*argv, &p, 0);
76 if (p == *argv || *p) {
81 } else if (matches(*argv, "duplicate") == 0) {
83 if (get_percent(&opt.duplicate, *argv)) {
84 explain1("duplicate");
88 } else if (matches(*argv, "rate") == 0) {
90 if (get_rate(&opt.rate, *argv)) {
95 } else if (strcmp(*argv, "help") == 0) {
99 fprintf(stderr, "What is \"%s\"?\n", *argv);
107 addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
111 static int netem_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
113 struct tc_netem_qopt *qopt;
120 if (RTA_PAYLOAD(opt) < sizeof(*qopt))
123 qopt = RTA_DATA(opt);
125 fprintf(f, "limit %d", qopt->limit);
127 fprintf(f, " latency %s",
128 sprint_usecs(qopt->latency, b2));
130 fprintf(f, " loss %s",
131 sprint_percent(qopt->loss, b1));
133 fprintf(f, " gap %lu", (unsigned long)qopt->gap);
136 fprintf(f, " rate %s", sprint_rate(qopt->rate, b1));
141 static int netem_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
146 struct qdisc_util netem_util = {