Root/package/network/utils/iproute2/patches/210-add_codel.patch

1--- a/tc/Makefile
2+++ b/tc/Makefile
3@@ -49,6 +49,8 @@ TCMODULES += em_cmp.o
4 TCMODULES += em_u32.o
5 TCMODULES += em_meta.o
6 TCMODULES += q_mqprio.o
7+TCMODULES += q_codel.o
8+TCMODULES += q_fq_codel.o
9 
10 TCSO :=
11 ifeq ($(TC_CONFIG_ATM),y)
12--- /dev/null
13+++ b/tc/q_codel.c
14@@ -0,0 +1,188 @@
15+/*
16+ * Codel - The Controlled-Delay Active Queue Management algorithm
17+ *
18+ * Copyright (C) 2011-2012 Kathleen Nichols <nichols@pollere.com>
19+ * Copyright (C) 2011-2012 Van Jacobson <van@pollere.com>
20+ * Copyright (C) 2012 Michael D. Taht <dave.taht@bufferbloat.net>
21+ * Copyright (C) 2012 Eric Dumazet <edumazet@google.com>
22+ *
23+ * Redistribution and use in source and binary forms, with or without
24+ * modification, are permitted provided that the following conditions
25+ * are met:
26+ * 1. Redistributions of source code must retain the above copyright
27+ * notice, this list of conditions, and the following disclaimer,
28+ * without modification.
29+ * 2. Redistributions in binary form must reproduce the above copyright
30+ * notice, this list of conditions and the following disclaimer in the
31+ * documentation and/or other materials provided with the distribution.
32+ * 3. The names of the authors may not be used to endorse or promote products
33+ * derived from this software without specific prior written permission.
34+ *
35+ * Alternatively, provided that this notice is retained in full, this
36+ * software may be distributed under the terms of the GNU General
37+ * Public License ("GPL") version 2, in which case the provisions of the
38+ * GPL apply INSTEAD OF those given above.
39+ *
40+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
41+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
42+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
43+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
44+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
47+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
48+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
50+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
51+ * DAMAGE.
52+ *
53+ */
54+
55+#include <stdio.h>
56+#include <stdlib.h>
57+#include <unistd.h>
58+#include <syslog.h>
59+#include <fcntl.h>
60+#include <sys/socket.h>
61+#include <netinet/in.h>
62+#include <arpa/inet.h>
63+#include <string.h>
64+
65+#include "utils.h"
66+#include "tc_util.h"
67+
68+static void explain(void)
69+{
70+ fprintf(stderr, "Usage: ... codel [ limit PACKETS ] [ target TIME]\n");
71+ fprintf(stderr, " [ interval TIME ] [ ecn ]\n");
72+}
73+
74+static int codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
75+ struct nlmsghdr *n)
76+{
77+ unsigned limit = 0;
78+ unsigned target = 0;
79+ unsigned interval = 0;
80+ int ecn = -1;
81+ struct rtattr *tail;
82+
83+ while (argc > 0) {
84+ if (strcmp(*argv, "limit") == 0) {
85+ NEXT_ARG();
86+ if (get_unsigned(&limit, *argv, 0)) {
87+ fprintf(stderr, "Illegal \"limit\"\n");
88+ return -1;
89+ }
90+ } else if (strcmp(*argv, "target") == 0) {
91+ NEXT_ARG();
92+ if (get_time(&target, *argv)) {
93+ fprintf(stderr, "Illegal \"target\"\n");
94+ return -1;
95+ }
96+ } else if (strcmp(*argv, "interval") == 0) {
97+ NEXT_ARG();
98+ if (get_time(&interval, *argv)) {
99+ fprintf(stderr, "Illegal \"interval\"\n");
100+ return -1;
101+ }
102+ } else if (strcmp(*argv, "ecn") == 0) {
103+ ecn = 1;
104+ } else if (strcmp(*argv, "noecn") == 0) {
105+ ecn = 0;
106+ } else if (strcmp(*argv, "help") == 0) {
107+ explain();
108+ return -1;
109+ } else {
110+ fprintf(stderr, "What is \"%s\"?\n", *argv);
111+ explain();
112+ return -1;
113+ }
114+ argc--; argv++;
115+ }
116+
117+ tail = NLMSG_TAIL(n);
118+ addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
119+ if (limit)
120+ addattr_l(n, 1024, TCA_CODEL_LIMIT, &limit, sizeof(limit));
121+ if (interval)
122+ addattr_l(n, 1024, TCA_CODEL_INTERVAL, &interval, sizeof(interval));
123+ if (target)
124+ addattr_l(n, 1024, TCA_CODEL_TARGET, &target, sizeof(target));
125+ if (ecn != -1)
126+ addattr_l(n, 1024, TCA_CODEL_ECN, &ecn, sizeof(ecn));
127+ tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
128+ return 0;
129+}
130+
131+static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
132+{
133+ struct rtattr *tb[TCA_CODEL_MAX + 1];
134+ unsigned limit;
135+ unsigned interval;
136+ unsigned target;
137+ unsigned ecn;
138+ SPRINT_BUF(b1);
139+
140+ if (opt == NULL)
141+ return 0;
142+
143+ parse_rtattr_nested(tb, TCA_CODEL_MAX, opt);
144+
145+ if (tb[TCA_CODEL_LIMIT] &&
146+ RTA_PAYLOAD(tb[TCA_CODEL_LIMIT]) >= sizeof(__u32)) {
147+ limit = rta_getattr_u32(tb[TCA_CODEL_LIMIT]);
148+ fprintf(f, "limit %up ", limit);
149+ }
150+ if (tb[TCA_CODEL_TARGET] &&
151+ RTA_PAYLOAD(tb[TCA_CODEL_TARGET]) >= sizeof(__u32)) {
152+ target = rta_getattr_u32(tb[TCA_CODEL_TARGET]);
153+ fprintf(f, "target %s ", sprint_time(target, b1));
154+ }
155+ if (tb[TCA_CODEL_INTERVAL] &&
156+ RTA_PAYLOAD(tb[TCA_CODEL_INTERVAL]) >= sizeof(__u32)) {
157+ interval = rta_getattr_u32(tb[TCA_CODEL_INTERVAL]);
158+ fprintf(f, "interval %s ", sprint_time(interval, b1));
159+ }
160+ if (tb[TCA_CODEL_ECN] &&
161+ RTA_PAYLOAD(tb[TCA_CODEL_ECN]) >= sizeof(__u32)) {
162+ ecn = rta_getattr_u32(tb[TCA_CODEL_ECN]);
163+ if (ecn)
164+ fprintf(f, "ecn ");
165+ }
166+
167+ return 0;
168+}
169+
170+static int codel_print_xstats(struct qdisc_util *qu, FILE *f,
171+ struct rtattr *xstats)
172+{
173+ struct tc_codel_xstats *st;
174+ SPRINT_BUF(b1);
175+
176+ if (xstats == NULL)
177+ return 0;
178+
179+ if (RTA_PAYLOAD(xstats) < sizeof(*st))
180+ return -1;
181+
182+ st = RTA_DATA(xstats);
183+ fprintf(f, " count %u lastcount %u ldelay %s",
184+ st->count, st->lastcount, sprint_time(st->ldelay, b1));
185+ if (st->dropping)
186+ fprintf(f, " dropping");
187+ if (st->drop_next < 0)
188+ fprintf(f, " drop_next -%s", sprint_time(-st->drop_next, b1));
189+ else
190+ fprintf(f, " drop_next %s", sprint_time(st->drop_next, b1));
191+ fprintf(f, "\n maxpacket %u ecn_mark %u drop_overlimit %u",
192+ st->maxpacket, st->ecn_mark, st->drop_overlimit);
193+ return 0;
194+
195+}
196+
197+struct qdisc_util codel_qdisc_util = {
198+ .id = "codel",
199+ .parse_qopt = codel_parse_opt,
200+ .print_qopt = codel_print_opt,
201+ .print_xstats = codel_print_xstats,
202+};
203--- /dev/null
204+++ b/tc/q_fq_codel.c
205@@ -0,0 +1,232 @@
206+/*
207+ * Fair Queue Codel
208+ *
209+ * Copyright (C) 2012 Eric Dumazet <edumazet@google.com>
210+ *
211+ * Redistribution and use in source and binary forms, with or without
212+ * modification, are permitted provided that the following conditions
213+ * are met:
214+ * 1. Redistributions of source code must retain the above copyright
215+ * notice, this list of conditions, and the following disclaimer,
216+ * without modification.
217+ * 2. Redistributions in binary form must reproduce the above copyright
218+ * notice, this list of conditions and the following disclaimer in the
219+ * documentation and/or other materials provided with the distribution.
220+ * 3. The names of the authors may not be used to endorse or promote products
221+ * derived from this software without specific prior written permission.
222+ *
223+ * Alternatively, provided that this notice is retained in full, this
224+ * software may be distributed under the terms of the GNU General
225+ * Public License ("GPL") version 2, in which case the provisions of the
226+ * GPL apply INSTEAD OF those given above.
227+ *
228+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
229+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
230+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
231+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
232+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
233+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
234+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
237+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
238+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
239+ * DAMAGE.
240+ *
241+ */
242+
243+#include <stdio.h>
244+#include <stdlib.h>
245+#include <unistd.h>
246+#include <syslog.h>
247+#include <fcntl.h>
248+#include <sys/socket.h>
249+#include <netinet/in.h>
250+#include <arpa/inet.h>
251+#include <string.h>
252+
253+#include "utils.h"
254+#include "tc_util.h"
255+
256+static void explain(void)
257+{
258+ fprintf(stderr, "Usage: ... fq_codel [ limit PACKETS ] [ flows NUMBER ]\n");
259+ fprintf(stderr, " [ target TIME] [ interval TIME ]\n");
260+ fprintf(stderr, " [ quantum BYTES ] [ [no]ecn ]\n");
261+}
262+
263+static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv,
264+ struct nlmsghdr *n)
265+{
266+ unsigned limit = 0;
267+ unsigned flows = 0;
268+ unsigned target = 0;
269+ unsigned interval = 0;
270+ unsigned quantum = 0;
271+ int ecn = -1;
272+ struct rtattr *tail;
273+
274+ while (argc > 0) {
275+ if (strcmp(*argv, "limit") == 0) {
276+ NEXT_ARG();
277+ if (get_unsigned(&limit, *argv, 0)) {
278+ fprintf(stderr, "Illegal \"limit\"\n");
279+ return -1;
280+ }
281+ } else if (strcmp(*argv, "flows") == 0) {
282+ NEXT_ARG();
283+ if (get_unsigned(&flows, *argv, 0)) {
284+ fprintf(stderr, "Illegal \"flows\"\n");
285+ return -1;
286+ }
287+ } else if (strcmp(*argv, "quantum") == 0) {
288+ NEXT_ARG();
289+ if (get_unsigned(&quantum, *argv, 0)) {
290+ fprintf(stderr, "Illegal \"quantum\"\n");
291+ return -1;
292+ }
293+ } else if (strcmp(*argv, "target") == 0) {
294+ NEXT_ARG();
295+ if (get_time(&target, *argv)) {
296+ fprintf(stderr, "Illegal \"target\"\n");
297+ return -1;
298+ }
299+ } else if (strcmp(*argv, "interval") == 0) {
300+ NEXT_ARG();
301+ if (get_time(&interval, *argv)) {
302+ fprintf(stderr, "Illegal \"interval\"\n");
303+ return -1;
304+ }
305+ } else if (strcmp(*argv, "ecn") == 0) {
306+ ecn = 1;
307+ } else if (strcmp(*argv, "noecn") == 0) {
308+ ecn = 0;
309+ } else if (strcmp(*argv, "help") == 0) {
310+ explain();
311+ return -1;
312+ } else {
313+ fprintf(stderr, "What is \"%s\"?\n", *argv);
314+ explain();
315+ return -1;
316+ }
317+ argc--; argv++;
318+ }
319+
320+ tail = NLMSG_TAIL(n);
321+ addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
322+ if (limit)
323+ addattr_l(n, 1024, TCA_FQ_CODEL_LIMIT, &limit, sizeof(limit));
324+ if (flows)
325+ addattr_l(n, 1024, TCA_FQ_CODEL_FLOWS, &flows, sizeof(flows));
326+ if (quantum)
327+ addattr_l(n, 1024, TCA_FQ_CODEL_QUANTUM, &quantum, sizeof(quantum));
328+ if (interval)
329+ addattr_l(n, 1024, TCA_FQ_CODEL_INTERVAL, &interval, sizeof(interval));
330+ if (target)
331+ addattr_l(n, 1024, TCA_FQ_CODEL_TARGET, &target, sizeof(target));
332+ if (ecn != -1)
333+ addattr_l(n, 1024, TCA_FQ_CODEL_ECN, &ecn, sizeof(ecn));
334+ tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail;
335+ return 0;
336+}
337+
338+static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
339+{
340+ struct rtattr *tb[TCA_FQ_CODEL_MAX + 1];
341+ unsigned limit;
342+ unsigned flows;
343+ unsigned interval;
344+ unsigned target;
345+ unsigned ecn;
346+ unsigned quantum;
347+ SPRINT_BUF(b1);
348+
349+ if (opt == NULL)
350+ return 0;
351+
352+ parse_rtattr_nested(tb, TCA_FQ_CODEL_MAX, opt);
353+
354+ if (tb[TCA_FQ_CODEL_LIMIT] &&
355+ RTA_PAYLOAD(tb[TCA_FQ_CODEL_LIMIT]) >= sizeof(__u32)) {
356+ limit = rta_getattr_u32(tb[TCA_FQ_CODEL_LIMIT]);
357+ fprintf(f, "limit %up ", limit);
358+ }
359+ if (tb[TCA_FQ_CODEL_FLOWS] &&
360+ RTA_PAYLOAD(tb[TCA_FQ_CODEL_FLOWS]) >= sizeof(__u32)) {
361+ flows = rta_getattr_u32(tb[TCA_FQ_CODEL_FLOWS]);
362+ fprintf(f, "flows %u ", flows);
363+ }
364+ if (tb[TCA_FQ_CODEL_QUANTUM] &&
365+ RTA_PAYLOAD(tb[TCA_FQ_CODEL_QUANTUM]) >= sizeof(__u32)) {
366+ quantum = rta_getattr_u32(tb[TCA_FQ_CODEL_QUANTUM]);
367+ fprintf(f, "quantum %u ", quantum);
368+ }
369+ if (tb[TCA_FQ_CODEL_TARGET] &&
370+ RTA_PAYLOAD(tb[TCA_FQ_CODEL_TARGET]) >= sizeof(__u32)) {
371+ target = rta_getattr_u32(tb[TCA_FQ_CODEL_TARGET]);
372+ fprintf(f, "target %s ", sprint_time(target, b1));
373+ }
374+ if (tb[TCA_FQ_CODEL_INTERVAL] &&
375+ RTA_PAYLOAD(tb[TCA_FQ_CODEL_INTERVAL]) >= sizeof(__u32)) {
376+ interval = rta_getattr_u32(tb[TCA_FQ_CODEL_INTERVAL]);
377+ fprintf(f, "interval %s ", sprint_time(interval, b1));
378+ }
379+ if (tb[TCA_FQ_CODEL_ECN] &&
380+ RTA_PAYLOAD(tb[TCA_FQ_CODEL_ECN]) >= sizeof(__u32)) {
381+ ecn = rta_getattr_u32(tb[TCA_FQ_CODEL_ECN]);
382+ if (ecn)
383+ fprintf(f, "ecn ");
384+ }
385+
386+ return 0;
387+}
388+
389+static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
390+ struct rtattr *xstats)
391+{
392+ struct tc_fq_codel_xstats *st;
393+ SPRINT_BUF(b1);
394+
395+ if (xstats == NULL)
396+ return 0;
397+
398+ if (RTA_PAYLOAD(xstats) < sizeof(*st))
399+ return -1;
400+
401+ st = RTA_DATA(xstats);
402+ if (st->type == TCA_FQ_CODEL_XSTATS_QDISC) {
403+ fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u",
404+ st->qdisc_stats.maxpacket,
405+ st->qdisc_stats.drop_overlimit,
406+ st->qdisc_stats.new_flow_count,
407+ st->qdisc_stats.ecn_mark);
408+ fprintf(f, "\n new_flows_len %u old_flows_len %u",
409+ st->qdisc_stats.new_flows_len,
410+ st->qdisc_stats.old_flows_len);
411+ }
412+ if (st->type == TCA_FQ_CODEL_XSTATS_CLASS) {
413+ fprintf(f, " deficit %d count %u lastcount %u ldelay %s",
414+ st->class_stats.deficit,
415+ st->class_stats.count,
416+ st->class_stats.lastcount,
417+ sprint_time(st->class_stats.ldelay, b1));
418+ if (st->class_stats.dropping) {
419+ fprintf(f, " dropping");
420+ if (st->class_stats.drop_next < 0)
421+ fprintf(f, " drop_next -%s",
422+ sprint_time(-st->class_stats.drop_next, b1));
423+ else
424+ fprintf(f, " drop_next %s",
425+ sprint_time(st->class_stats.drop_next, b1));
426+ }
427+ }
428+ return 0;
429+
430+}
431+
432+struct qdisc_util fq_codel_qdisc_util = {
433+ .id = "fq_codel",
434+ .parse_qopt = fq_codel_parse_opt,
435+ .print_qopt = fq_codel_print_opt,
436+ .print_xstats = fq_codel_print_xstats,
437+};
438

Archive Download this file



interactive