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 static int red_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
36 struct tc_red_qopt opt;
39 double probability = 0.02;
46 memset(&opt, 0, sizeof(opt));
49 if (strcmp(*argv, "limit") == 0) {
51 if (get_size(&opt.limit, *argv)) {
52 fprintf(stderr, "Illegal \"limit\"\n");
55 } else if (strcmp(*argv, "min") == 0) {
57 if (get_size(&opt.qth_min, *argv)) {
58 fprintf(stderr, "Illegal \"min\"\n");
61 } else if (strcmp(*argv, "max") == 0) {
63 if (get_size(&opt.qth_max, *argv)) {
64 fprintf(stderr, "Illegal \"max\"\n");
67 } else if (strcmp(*argv, "burst") == 0) {
69 if (get_unsigned(&burst, *argv, 0)) {
70 fprintf(stderr, "Illegal \"burst\"\n");
73 } else if (strcmp(*argv, "avpkt") == 0) {
75 if (get_size(&avpkt, *argv)) {
76 fprintf(stderr, "Illegal \"avpkt\"\n");
79 } else if (strcmp(*argv, "probability") == 0) {
81 if (sscanf(*argv, "%lg", &probability) != 1) {
82 fprintf(stderr, "Illegal \"probability\"\n");
85 } else if (strcmp(*argv, "bandwidth") == 0) {
87 if (get_rate(&rate, *argv)) {
88 fprintf(stderr, "Illegal \"bandwidth\"\n");
91 } else if (strcmp(*argv, "ecn") == 0) {
93 } else if (strcmp(*argv, "help") == 0) {
97 fprintf(stderr, "What is \"%s\"?\n", *argv);
105 get_rate(&rate, "10Mbit");
107 if (!opt.qth_min || !opt.qth_max || !burst || !opt.limit || !avpkt) {
108 fprintf(stderr, "Required parameter (min, max, burst, limit, avpkt) is missing\n");
112 if ((wlog = tc_red_eval_ewma(opt.qth_min, burst, avpkt)) < 0) {
113 fprintf(stderr, "RED: failed to calculate EWMA constant.\n");
117 fprintf(stderr, "RED: WARNING. Burst %d seems to be to large.\n", burst);
119 if ((wlog = tc_red_eval_P(opt.qth_min, opt.qth_max, probability)) < 0) {
120 fprintf(stderr, "RED: failed to calculate probability.\n");
124 if ((wlog = tc_red_eval_idle_damping(opt.Wlog, avpkt, rate, sbuf)) < 0) {
125 fprintf(stderr, "RED: failed to calculate idle damping table.\n");
128 opt.Scell_log = wlog;
131 opt.flags |= TC_RED_ECN;
133 fprintf(stderr, "RED: ECN support is missing in this binary.\n");
138 tail = NLMSG_TAIL(n);
139 addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
140 addattr_l(n, 1024, TCA_RED_PARMS, &opt, sizeof(opt));
141 addattr_l(n, 1024, TCA_RED_STAB, sbuf, 256);
142 tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
146 static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
148 struct rtattr *tb[TCA_RED_STAB+1];
149 struct tc_red_qopt *qopt;
157 parse_rtattr_nested(tb, TCA_RED_STAB, opt);
159 if (tb[TCA_RED_PARMS] == NULL)
161 qopt = RTA_DATA(tb[TCA_RED_PARMS]);
162 if (RTA_PAYLOAD(tb[TCA_RED_PARMS]) < sizeof(*qopt))
164 fprintf(f, "limit %s min %s max %s ",
165 sprint_size(qopt->limit, b1),
166 sprint_size(qopt->qth_min, b2),
167 sprint_size(qopt->qth_max, b3));
169 if (qopt->flags & TC_RED_ECN)
173 fprintf(f, "ewma %u Plog %u Scell_log %u",
174 qopt->Wlog, qopt->Plog, qopt->Scell_log);
179 static int red_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
182 struct tc_red_xstats *st;
187 if (RTA_PAYLOAD(xstats) < sizeof(*st))
190 st = RTA_DATA(xstats);
191 fprintf(f, " marked %u early %u pdrop %u other %u",
192 st->marked, st->early, st->pdrop, st->other);
200 struct qdisc_util red_qdisc_util = {
202 .parse_qopt = red_parse_opt,
203 .print_qopt = red_print_opt,
204 .print_xstats = red_print_xstats,