]> git.pld-linux.org Git - packages/iproute2.git/blame - iproute2-hfsc.patch
- think
[packages/iproute2.git] / iproute2-hfsc.patch
CommitLineData
fe0a733d
PS
1diff -uNr iproute2.orig/tc/Makefile iproute2/tc/Makefile
2--- iproute2.orig/tc/Makefile 2004-04-06 04:13:37.944868904 +0200
3+++ iproute2/tc/Makefile 2004-04-06 04:22:48.397187432 +0200
4@@ -29,7 +29,7 @@
5 #TCMODULES += q_csz.o
6 TCMODULES += q_htb.o
7 #TCMODULES += q_hpfq.o
8-#TCMODULES += q_hfsc.o
9+TCMODULES += q_hfsc.o
10
11 TCOBJ += $(TCMODULES)
12
13diff -uNr iproute2.orig/tc/q_hfsc.c iproute2/tc/q_hfsc.c
14--- iproute2.orig/tc/q_hfsc.c 2000-04-16 19:42:54.000000000 +0200
15+++ iproute2/tc/q_hfsc.c 2004-04-06 04:22:48.416184544 +0200
16@@ -1,12 +1,12 @@
17 /*
18- * q_hfsc.c HFSC.
19+ * q_hfsc.c HFSC.
20 *
21 * This program is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU General Public License
23 * as published by the Free Software Foundation; either version
24 * 2 of the License, or (at your option) any later version.
25 *
26- * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
27+ * Authors: Patrick McHardy, <kaber@trash.ner>
28 *
29 */
30
31@@ -19,36 +19,247 @@
32 #include <netinet/in.h>
33 #include <arpa/inet.h>
34 #include <string.h>
35+#include <math.h>
36
37 #include "utils.h"
38 #include "tc_util.h"
39
40-static void explain()
41+static int hfsc_get_sc(int *, char ***, struct tc_service_curve *);
42+
43+
44+static void
45+explain_qdisc(void)
46+{
47+ fprintf(stderr,
48+ "Usage: ... hfsc [ default CLASSID ]\n"
49+ "\n"
50+ " default: default class for unclassified packets\n"
51+ );
52+}
53+
54+static void
55+explain_class(void)
56 {
57- fprintf(stderr, "Usage: ... hfsc \n");
58+ fprintf(stderr,
59+ "Usage: ... hfsc [ rt SC ] [ ls SC ] [ ul SC ]\n"
60+ "\n"
61+ "SC := [ [ m1 BPS ] [ d SEC ] m2 BPS\n"
62+ "\n"
63+ " m1 : slope of first segment\n"
64+ " d : x-coordinate of intersection\n"
65+ " m2 : slope of second segment\n"
66+ "\n"
67+ "Alternative format:\n"
68+ "\n"
69+ "SC := [ [ umax BYTE ] dmax SEC ] rate BPS\n"
70+ "\n"
71+ " umax : maximum unit of work\n"
72+ " dmax : maximum delay\n"
73+ " rate : rate\n"
74+ "\n"
75+ );
76 }
77
78-static void explain1(char *arg)
79+static void
80+explain1(char *arg)
81 {
82- fprintf(stderr, "Illegal \"%s\"\n", arg);
83+ fprintf(stderr, "HFSC: Illegal \"%s\"\n", arg);
84 }
85
86+static int
87+hfsc_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
88+{
89+ struct tc_hfsc_qopt qopt;
90+
91+ memset(&qopt, 0, sizeof(qopt));
92+
93+ while (argc > 0) {
94+ if (matches(*argv, "default") == 0) {
95+ NEXT_ARG();
96+ if (qopt.defcls != 0) {
97+ fprintf(stderr, "HFSC: Double \"default\"\n");
98+ return -1;
99+ }
100+ if (get_u16(&qopt.defcls, *argv, 16) < 0) {
101+ explain1("default");
102+ return -1;
103+ }
104+ } else if (matches(*argv, "help") == 0) {
105+ explain_qdisc();
106+ return -1;
107+ } else {
108+ fprintf(stderr, "HFSC: What is \"%s\" ?\n", *argv);
109+ explain_qdisc();
110+ return -1;
111+ }
112+ argc--, argv++;
113+ }
114
115-#define usage() return(-1)
116+ addattr_l(n, 1024, TCA_OPTIONS, &qopt, sizeof(qopt));
117+ return 0;
118+}
119
120-static int hfsc_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
121+static int
122+hfsc_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
123 {
124- return -1;
125+ struct tc_hfsc_qopt *qopt;
126+
127+ if (opt == NULL)
128+ return 0;
129+ if (RTA_PAYLOAD(opt) < sizeof(*qopt))
130+ return -1;
131+ qopt = RTA_DATA(opt);
132+
133+ if (qopt->defcls != 0)
134+ fprintf(f, "default %x ", qopt->defcls);
135+
136+ return 0;
137 }
138
139-static int hfsc_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
140+static int
141+hfsc_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
142 {
143- return -1;
144+ struct tc_hfsc_stats *st;
145+
146+ if (xstats == NULL)
147+ return 0;
148+ if (RTA_PAYLOAD(xstats) < sizeof(*st))
149+ return -1;
150+ st = RTA_DATA(xstats);
151+
152+ fprintf(f, " period %u ", st->period);
153+ if (st->work != 0)
154+ fprintf(f, "work %llu bytes ", st->work);
155+ if (st->rtwork != 0)
156+ fprintf(f, "rtwork %llu bytes ", st->rtwork);
157+ fprintf(f, "level %u ", st->level);
158+ fprintf(f, "\n");
159+
160+ return 0;
161 }
162
163-static int hfsc_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats)
164+static int
165+hfsc_parse_class_opt(struct qdisc_util *qu, int argc, char **argv,
166+ struct nlmsghdr *n)
167 {
168- return -1;
169+ struct tc_service_curve rsc, fsc, usc;
170+ int rsc_ok, fsc_ok, usc_ok;
171+ struct rtattr *tail;
172+
173+ memset(&rsc, 0, sizeof(rsc));
174+ memset(&fsc, 0, sizeof(fsc));
175+ memset(&usc, 0, sizeof(usc));
176+ rsc_ok = fsc_ok = usc_ok = 0;
177+
178+ while (argc > 0) {
179+ if (matches(*argv, "rt") == 0) {
180+ NEXT_ARG();
181+ if (hfsc_get_sc(&argc, &argv, &rsc) < 0) {
182+ explain1("rt");
183+ return -1;
184+ }
185+ rsc_ok = 1;
186+ } else if (matches(*argv, "ls") == 0) {
187+ NEXT_ARG();
188+ if (hfsc_get_sc(&argc, &argv, &fsc) < 0) {
189+ explain1("ls");
190+ return -1;
191+ }
192+ fsc_ok = 1;
193+ } else if (matches(*argv, "ul") == 0) {
194+ NEXT_ARG();
195+ if (hfsc_get_sc(&argc, &argv, &usc) < 0) {
196+ explain1("ul");
197+ return -1;
198+ }
199+ usc_ok = 1;
200+ } else if (matches(*argv, "help") == 0) {
201+ explain_class();
202+ return -1;
203+ } else {
204+ fprintf(stderr, "HFSC: What is \"%s\" ?\n", *argv);
205+ explain_class();
206+ return -1;
207+ }
208+ argc--, argv++;
209+ }
210+
211+ if (!(rsc_ok || fsc_ok || usc_ok)) {
212+ fprintf(stderr, "HFSC: no parameters given\n");
213+ explain_class();
214+ return -1;
215+ }
216+ if (usc_ok && !fsc_ok) {
217+ fprintf(stderr, "HFSC: Upper-limit Service Curve without "
218+ "Link-Share Service Curve\n");
219+ explain_class();
220+ return -1;
221+ }
222+
223+ tail = (struct rtattr*)(((void*)n) + NLMSG_ALIGN(n->nlmsg_len));
224+
225+ addattr_l(n, 1024, TCA_OPTIONS, NULL, 0);
226+ if (rsc_ok)
227+ addattr_l(n, 1024, TCA_HFSC_RSC, &rsc, sizeof(rsc));
228+ if (fsc_ok)
229+ addattr_l(n, 1024, TCA_HFSC_FSC, &fsc, sizeof(fsc));
230+ if (usc_ok)
231+ addattr_l(n, 1024, TCA_HFSC_USC, &usc, sizeof(usc));
232+
233+ tail->rta_len = (((void*)n) + NLMSG_ALIGN(n->nlmsg_len)) - (void*)tail;
234+ return 0;
235+}
236+
237+static void
238+hfsc_print_sc(FILE *f, char *name, struct tc_service_curve *sc)
239+{
240+ SPRINT_BUF(b1);
241+
242+ fprintf(f, "%s ", name);
243+ fprintf(f, "m1 %s ", sprint_rate(sc->m1, b1));
244+ fprintf(f, "d %s ", sprint_usecs(sc->d, b1));
245+ fprintf(f, "m2 %s ", sprint_rate(sc->m2, b1));
246+}
247+
248+static int
249+hfsc_print_class_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
250+{
251+ struct rtattr *tb[TCA_HFSC_MAX+1];
252+ struct tc_service_curve *rsc = NULL, *fsc = NULL, *usc = NULL;
253+
254+ if (opt == NULL)
255+ return 0;
256+
257+ memset(tb, 0, sizeof(tb));
258+ parse_rtattr(tb, TCA_HFSC_MAX, RTA_DATA(opt), RTA_PAYLOAD(opt));
259+
260+ if (tb[TCA_HFSC_RSC]) {
261+ if (RTA_PAYLOAD(tb[TCA_HFSC_RSC]) < sizeof(*rsc))
262+ fprintf(stderr, "HFSC: truncated realtime option\n");
263+ else
264+ rsc = RTA_DATA(tb[TCA_HFSC_RSC]);
265+ }
266+ if (tb[TCA_HFSC_FSC]) {
267+ if (RTA_PAYLOAD(tb[TCA_HFSC_FSC]) < sizeof(*fsc))
268+ fprintf(stderr, "HFSC: truncated linkshare option\n");
269+ else
270+ fsc = RTA_DATA(tb[TCA_HFSC_FSC]);
271+ }
272+ if (tb[TCA_HFSC_USC]) {
273+ if (RTA_PAYLOAD(tb[TCA_HFSC_USC]) < sizeof(*usc))
274+ fprintf(stderr, "HFSC: truncated upperlimit option\n");
275+ else
276+ usc = RTA_DATA(tb[TCA_HFSC_USC]);
277+ }
278+
279+ if (rsc != NULL)
280+ hfsc_print_sc(f, "rt", rsc);
281+ if (fsc != NULL)
282+ hfsc_print_sc(f, "ls", fsc);
283+ if (usc != NULL)
284+ hfsc_print_sc(f, "ul", usc);
285+
286+ return 0;
287 }
288
289 struct qdisc_util hfsc_util = {
290@@ -57,5 +268,126 @@
291 hfsc_parse_opt,
292 hfsc_print_opt,
293 hfsc_print_xstats,
294+ hfsc_parse_class_opt,
295+ hfsc_print_class_opt,
296 };
297
298+static int
299+hfsc_get_sc1(int *argcp, char ***argvp, struct tc_service_curve *sc)
300+{
301+ char **argv = *argvp;
302+ int argc = *argcp;
303+ unsigned int m1 = 0, d = 0, m2 = 0;
304+
305+ if (matches(*argv, "m1") == 0) {
306+ NEXT_ARG();
307+ if (get_rate(&m1, *argv) < 0) {
308+ explain1("m1");
309+ return -1;
310+ }
311+ NEXT_ARG();
312+ }
313+
314+ if (matches(*argv, "d") == 0) {
315+ NEXT_ARG();
316+ if (get_usecs(&d, *argv) < 0) {
317+ explain1("d");
318+ return -1;
319+ }
320+ NEXT_ARG();
321+ }
322+
323+ if (matches(*argv, "m2") == 0) {
324+ NEXT_ARG();
325+ if (get_rate(&m2, *argv) < 0) {
326+ explain1("m2");
327+ return -1;
328+ }
329+ } else
330+ return -1;
331+
332+ sc->m1 = m1;
333+ sc->d = d;
334+ sc->m2 = m2;
335+
336+ *argvp = argv;
337+ *argcp = argc;
338+ return 0;
339+}
340+
341+static int
342+hfsc_get_sc2(int *argcp, char ***argvp, struct tc_service_curve *sc)
343+{
344+ char **argv = *argvp;
345+ int argc = *argcp;
346+ unsigned int umax = 0, dmax = 0, rate = 0;
347+
348+ if (matches(*argv, "umax") == 0) {
349+ NEXT_ARG();
350+ if (get_size(&umax, *argv) < 0) {
351+ explain1("umax");
352+ return -1;
353+ }
354+ NEXT_ARG();
355+ }
356+
357+ if (matches(*argv, "dmax") == 0) {
358+ NEXT_ARG();
359+ if (get_usecs(&dmax, *argv) < 0) {
360+ explain1("dmax");
361+ return -1;
362+ }
363+ NEXT_ARG();
364+ }
365+
366+ if (matches(*argv, "rate") == 0) {
367+ NEXT_ARG();
368+ if (get_rate(&rate, *argv) < 0) {
369+ explain1("rate");
370+ return -1;
371+ }
372+ } else
373+ return -1;
374+
375+ if (umax != 0 && dmax == 0) {
376+ fprintf(stderr, "HFSC: umax given but dmax is zero.\n");
377+ return -1;
378+ }
379+
380+ if (dmax != 0 && ceil(umax * 1000000.0 / dmax) > rate) {
381+ /*
382+ * concave curve, slope of first segment is umax/dmax,
383+ * intersection is at dmax
384+ */
385+ sc->m1 = ceil(umax * 1000000.0 / dmax); /* in bps */
386+ sc->d = dmax;
387+ sc->m2 = rate;
388+ } else {
389+ /*
390+ * convex curve, slope of first segment is 0, intersection
391+ * is at dmax - umax / rate
392+ */
393+ sc->m1 = 0;
394+ sc->d = ceil(dmax - umax * 1000000.0 / rate); /* in usec */
395+ sc->m2 = rate;
396+ }
397+
398+ *argvp = argv;
399+ *argcp = argc;
400+ return 0;
401+}
402+
403+static int
404+hfsc_get_sc(int *argcp, char ***argvp, struct tc_service_curve *sc)
405+{
406+ if (hfsc_get_sc1(argcp, argvp, sc) < 0 &&
407+ hfsc_get_sc2(argcp, argvp, sc) < 0)
408+ return -1;
409+
410+ if (sc->m1 == 0 && sc->m2 == 0) {
411+ fprintf(stderr, "HFSC: Service Curve has two zero slopes\n");
412+ return -1;
413+ }
414+
415+ return 0;
416+}
This page took 0.116358 seconds and 4 git commands to generate.