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: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
28 static void explain(void)
30 fprintf(stderr, "Usage: ... red limit BYTES min BYTES max BYTES avpkt BYTES burst PACKETS\n");
31 fprintf(stderr, " probability PROBABILITY bandwidth KBPS [ ecn ]\n");
34 #define usage() return(-1)
36 static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
39 struct tc_red_qopt opt;
42 double probability = 0.02;
49 memset(&opt, 0, sizeof(opt));
52 if (strcmp(*argv, "limit") == 0) {
54 if (get_size(&opt.limit, *argv)) {
55 fprintf(stderr, "Illegal \"limit\"\n");
59 } else if (strcmp(*argv, "min") == 0) {
61 if (get_size(&opt.qth_min, *argv)) {
62 fprintf(stderr, "Illegal \"min\"\n");
66 } else if (strcmp(*argv, "max") == 0) {
68 if (get_size(&opt.qth_max, *argv)) {
69 fprintf(stderr, "Illegal \"max\"\n");
73 } else if (strcmp(*argv, "burst") == 0) {
75 if (get_unsigned(&burst, *argv, 0)) {
76 fprintf(stderr, "Illegal \"burst\"\n");
80 } else if (strcmp(*argv, "avpkt") == 0) {
82 if (get_size(&avpkt, *argv)) {
83 fprintf(stderr, "Illegal \"avpkt\"\n");
87 } else if (strcmp(*argv, "probability") == 0) {
89 if (sscanf(*argv, "%lg", &probability) != 1) {
90 fprintf(stderr, "Illegal \"probability\"\n");
94 } else if (strcmp(*argv, "bandwidth") == 0) {
96 if (get_rate(&rate, *argv)) {
97 fprintf(stderr, "Illegal \"bandwidth\"\n");
101 } else if (strcmp(*argv, "ecn") == 0) {
104 } else if (strcmp(*argv, "help") == 0) {
108 fprintf(stderr, "What is \"%s\"?\n", *argv);
119 get_rate(&rate, "10Mbit");
121 if (!opt.qth_min || !opt.qth_max || !burst || !opt.limit || !avpkt) {
122 fprintf(stderr, "Required parameter (min, max, burst, limit, avpket) is missing\n");
126 if ((wlog = tc_red_eval_ewma(opt.qth_min, burst, avpkt)) < 0) {
127 fprintf(stderr, "RED: failed to calculate EWMA constant.\n");
131 fprintf(stderr, "RED: WARNING. Burst %d seems to be to large.\n", burst);
133 if ((wlog = tc_red_eval_P(opt.qth_min, opt.qth_max, probability)) < 0) {
134 fprintf(stderr, "RED: failed to calculate probability.\n");
138 if ((wlog = tc_red_eval_idle_damping(opt.Wlog, avpkt, rate, sbuf)) < 0) {
139 fprintf(stderr, "RED: failed to calculate idle damping table.\n");
142 opt.Scell_log = wlog;
145 opt.flags |= TC_RED_ECN;
147 fprintf(stderr, "RED: ECN support is missing in this binary.\n");
152 tail = NLMSG_TAIL(n);
153 addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
154 addattr_l(n, 1024, TCA_RED_PARMS, &opt, sizeof(opt));
155 addattr_l(n, 1024, TCA_RED_STAB, sbuf, 256);
156 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
160 static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
162 struct rtattr *tb[TCA_RED_STAB+1];
163 struct tc_red_qopt *qopt;
171 parse_rtattr_nested(tb, TCA_RED_STAB, opt);
173 if (tb[TCA_RED_PARMS] == NULL)
175 qopt = RTA_DATA(tb[TCA_RED_PARMS]);
176 if (RTA_PAYLOAD(tb[TCA_RED_PARMS]) < sizeof(*qopt))
178 fprintf(f, "limit %s min %s max %s ",
179 sprint_size(qopt->limit, b1),
180 sprint_size(qopt->qth_min, b2),
181 sprint_size(qopt->qth_max, b3));
183 if (qopt->flags & TC_RED_ECN)
187 fprintf(f, "ewma %u Plog %u Scell_log %u",
188 qopt->Wlog, qopt->Plog, qopt->Scell_log);
193 static int red_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
196 struct tc_red_xstats *st;
201 if (RTA_PAYLOAD(xstats) < sizeof(*st))
204 st = RTA_DATA(xstats);
205 fprintf(f, " marked %u early %u pdrop %u other %u",
206 st->marked, st->early, st->pdrop, st->other);
214 struct qdisc_util red_qdisc_util = {
216 .parse_qopt = red_parse_opt,
217 .print_qopt = red_print_opt,
218 .print_xstats = red_print_xstats,