]>
git.proxmox.com Git - mirror_iproute2.git/blob - tc/q_hfsc.c
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: Patrick McHardy, <kaber@trash.net>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
27 static int hfsc_get_sc(int *, char ***, struct tc_service_curve
*);
34 "Usage: ... hfsc [ default CLASSID ]\n"
36 " default: default class for unclassified packets\n"
44 "Usage: ... hfsc [ rt SC ] [ ls SC ] [ ul SC ]\n"
46 "SC := [ [ m1 BPS ] [ d SEC ] m2 BPS\n"
48 " m1 : slope of first segment\n"
49 " d : x-coordinate of intersection\n"
50 " m2 : slope of second segment\n"
52 "Alternative format:\n"
54 "SC := [ [ umax BYTE ] dmax SEC ] rate BPS\n"
56 " umax : maximum unit of work\n"
57 " dmax : maximum delay\n"
66 fprintf(stderr
, "HFSC: Illegal \"%s\"\n", arg
);
70 hfsc_parse_opt(struct qdisc_util
*qu
, int argc
, char **argv
, struct nlmsghdr
*n
)
72 struct tc_hfsc_qopt qopt
;
74 memset(&qopt
, 0, sizeof(qopt
));
77 if (matches(*argv
, "default") == 0) {
79 if (qopt
.defcls
!= 0) {
80 fprintf(stderr
, "HFSC: Double \"default\"\n");
83 if (get_u16(&qopt
.defcls
, *argv
, 16) < 0) {
87 } else if (matches(*argv
, "help") == 0) {
91 fprintf(stderr
, "HFSC: What is \"%s\" ?\n", *argv
);
98 addattr_l(n
, 1024, TCA_OPTIONS
, &qopt
, sizeof(qopt
));
103 hfsc_print_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
105 struct tc_hfsc_qopt
*qopt
;
109 if (RTA_PAYLOAD(opt
) < sizeof(*qopt
))
111 qopt
= RTA_DATA(opt
);
113 if (qopt
->defcls
!= 0)
114 fprintf(f
, "default %x ", qopt
->defcls
);
120 hfsc_print_xstats(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*xstats
)
122 struct tc_hfsc_stats
*st
;
126 if (RTA_PAYLOAD(xstats
) < sizeof(*st
))
128 st
= RTA_DATA(xstats
);
130 fprintf(f
, " period %u ", st
->period
);
132 fprintf(f
, "work %llu bytes ", st
->work
);
134 fprintf(f
, "rtwork %llu bytes ", st
->rtwork
);
135 fprintf(f
, "level %u ", st
->level
);
142 hfsc_parse_class_opt(struct qdisc_util
*qu
, int argc
, char **argv
,
145 struct tc_service_curve rsc
, fsc
, usc
;
146 int rsc_ok
, fsc_ok
, usc_ok
;
149 memset(&rsc
, 0, sizeof(rsc
));
150 memset(&fsc
, 0, sizeof(fsc
));
151 memset(&usc
, 0, sizeof(usc
));
152 rsc_ok
= fsc_ok
= usc_ok
= 0;
155 if (matches(*argv
, "rt") == 0) {
157 if (hfsc_get_sc(&argc
, &argv
, &rsc
) < 0) {
162 } else if (matches(*argv
, "ls") == 0) {
164 if (hfsc_get_sc(&argc
, &argv
, &fsc
) < 0) {
169 } else if (matches(*argv
, "ul") == 0) {
171 if (hfsc_get_sc(&argc
, &argv
, &usc
) < 0) {
176 } else if (matches(*argv
, "help") == 0) {
180 fprintf(stderr
, "HFSC: What is \"%s\" ?\n", *argv
);
187 if (!(rsc_ok
|| fsc_ok
|| usc_ok
)) {
188 fprintf(stderr
, "HFSC: no parameters given\n");
192 if (usc_ok
&& !fsc_ok
) {
193 fprintf(stderr
, "HFSC: Upper-limit Service Curve without "
194 "Link-Share Service Curve\n");
199 tail
= (struct rtattr
*)(((void*)n
) + NLMSG_ALIGN(n
->nlmsg_len
));
201 addattr_l(n
, 1024, TCA_OPTIONS
, NULL
, 0);
203 addattr_l(n
, 1024, TCA_HFSC_RSC
, &rsc
, sizeof(rsc
));
205 addattr_l(n
, 1024, TCA_HFSC_FSC
, &fsc
, sizeof(fsc
));
207 addattr_l(n
, 1024, TCA_HFSC_USC
, &usc
, sizeof(usc
));
209 tail
->rta_len
= (((void*)n
) + NLMSG_ALIGN(n
->nlmsg_len
)) - (void*)tail
;
214 hfsc_print_sc(FILE *f
, char *name
, struct tc_service_curve
*sc
)
218 fprintf(f
, "%s ", name
);
219 fprintf(f
, "m1 %s ", sprint_rate(sc
->m1
, b1
));
220 fprintf(f
, "d %s ", sprint_usecs(sc
->d
, b1
));
221 fprintf(f
, "m2 %s ", sprint_rate(sc
->m2
, b1
));
225 hfsc_print_class_opt(struct qdisc_util
*qu
, FILE *f
, struct rtattr
*opt
)
227 struct rtattr
*tb
[TCA_HFSC_MAX
+1];
228 struct tc_service_curve
*rsc
= NULL
, *fsc
= NULL
, *usc
= NULL
;
233 memset(tb
, 0, sizeof(tb
));
234 parse_rtattr(tb
, TCA_HFSC_MAX
, RTA_DATA(opt
), RTA_PAYLOAD(opt
));
236 if (tb
[TCA_HFSC_RSC
]) {
237 if (RTA_PAYLOAD(tb
[TCA_HFSC_RSC
]) < sizeof(*rsc
))
238 fprintf(stderr
, "HFSC: truncated realtime option\n");
240 rsc
= RTA_DATA(tb
[TCA_HFSC_RSC
]);
242 if (tb
[TCA_HFSC_FSC
]) {
243 if (RTA_PAYLOAD(tb
[TCA_HFSC_FSC
]) < sizeof(*fsc
))
244 fprintf(stderr
, "HFSC: truncated linkshare option\n");
246 fsc
= RTA_DATA(tb
[TCA_HFSC_FSC
]);
248 if (tb
[TCA_HFSC_USC
]) {
249 if (RTA_PAYLOAD(tb
[TCA_HFSC_USC
]) < sizeof(*usc
))
250 fprintf(stderr
, "HFSC: truncated upperlimit option\n");
252 usc
= RTA_DATA(tb
[TCA_HFSC_USC
]);
256 hfsc_print_sc(f
, "rt", rsc
);
258 hfsc_print_sc(f
, "ls", fsc
);
260 hfsc_print_sc(f
, "ul", usc
);
265 struct qdisc_util hfsc_util
= {
271 hfsc_parse_class_opt
,
272 hfsc_print_class_opt
,
276 hfsc_get_sc1(int *argcp
, char ***argvp
, struct tc_service_curve
*sc
)
278 char **argv
= *argvp
;
280 unsigned int m1
= 0, d
= 0, m2
= 0;
282 if (matches(*argv
, "m1") == 0) {
284 if (get_rate(&m1
, *argv
) < 0) {
291 if (matches(*argv
, "d") == 0) {
293 if (get_usecs(&d
, *argv
) < 0) {
300 if (matches(*argv
, "m2") == 0) {
302 if (get_rate(&m2
, *argv
) < 0) {
319 hfsc_get_sc2(int *argcp
, char ***argvp
, struct tc_service_curve
*sc
)
321 char **argv
= *argvp
;
323 unsigned int umax
= 0, dmax
= 0, rate
= 0;
325 if (matches(*argv
, "umax") == 0) {
327 if (get_size(&umax
, *argv
) < 0) {
334 if (matches(*argv
, "dmax") == 0) {
336 if (get_usecs(&dmax
, *argv
) < 0) {
343 if (matches(*argv
, "rate") == 0) {
345 if (get_rate(&rate
, *argv
) < 0) {
352 if (umax
!= 0 && dmax
== 0) {
353 fprintf(stderr
, "HFSC: umax given but dmax is zero.\n");
357 if (dmax
!= 0 && ceil(umax
* 1000000.0 / dmax
) > rate
) {
359 * concave curve, slope of first segment is umax/dmax,
360 * intersection is at dmax
362 sc
->m1
= ceil(umax
* 1000000.0 / dmax
); /* in bps */
367 * convex curve, slope of first segment is 0, intersection
368 * is at dmax - umax / rate
371 sc
->d
= ceil(dmax
- umax
* 1000000.0 / rate
); /* in usec */
381 hfsc_get_sc(int *argcp
, char ***argvp
, struct tc_service_curve
*sc
)
383 if (hfsc_get_sc1(argcp
, argvp
, sc
) < 0 &&
384 hfsc_get_sc2(argcp
, argvp
, sc
) < 0)
387 if (sc
->m1
== 0 && sc
->m2
== 0) {
388 fprintf(stderr
, "HFSC: Service Curve has two zero slopes\n");