Index: iproute2-2.6.11-w/include/linux/pkt_sched.h =================================================================== --- iproute2-2.6.11-w/include/linux/pkt_sched.h (revision 1) +++ iproute2-2.6.11-w/include/linux/pkt_sched.h (working copy) @@ -272,6 +272,28 @@ __u32 ctokens; }; + +/* PERFLOW section */ + +#define TC_PERFLOW_DEFAULTLIMIT 1024 + +struct tc_perflow_qopt +{ + struct tc_ratespec rate; + struct tc_ratespec ceil; + __u32 limit; + __u32 qlen; +}; +enum +{ + TCA_PERFLOW_UNSPEC, + TCA_PERFLOW_PARMS, + __TCA_PERFLOW_MAX, +}; + +#define TCA_PERFLOW_MAX (__TCA_PERFLOW_MAX - 1) + + /* HFSC section */ struct tc_hfsc_qopt Index: iproute2-2.6.11-w/tc/q_perflow.c =================================================================== --- iproute2-2.6.11-w/tc/q_perflow.c (revision 0) +++ iproute2-2.6.11-w/tc/q_perflow.c (revision 0) @@ -0,0 +1,153 @@ +/* + * q_perflow.c PERFLOW. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * Authors: Wang Jian , 2005 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, +"Usage: ... perflow rate RATE [ ceil CEIL ] [ limit LIMIT ] [ qlen QLEN ]\n" +"\n" +"rate rate allocated to each flow (flow can still borrow)\n" +"ceil upper limit for each flow (flow can not borrow)\n" +"limit maximum concurrent flows\n" +"qlen maximum queue length\n" + ); +} + +#define usage() return(-1) + +static int perflow_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) +{ + struct tc_perflow_qopt opt; + struct rtattr *tail; + int ok = 0; + + memset(&opt, 0, sizeof(opt)); + + while (argc > 0) { + if (strcmp(*argv, "rate") == 0) { + NEXT_ARG(); + if (opt.rate.rate) { + fprintf(stderr, "Double \"ceil\" spec\n"); + return -1; + } + if (get_rate(&opt.rate.rate, *argv)) { + fprintf(stderr, "Illegal \"rate\"\n"); + return -1; + } + ok++; + } else if (strcmp(*argv, "ceil") == 0) { + NEXT_ARG(); + if (opt.ceil.rate) { + fprintf(stderr, "Double \"ceil\" spec\n"); + return -1; + } + if (get_rate(&opt.ceil.rate, *argv)) { + fprintf(stderr, "Illegal \"ceil\"\n"); + return -1; + } + ok++; + } else if (strcmp(*argv, "limit") == 0) { + NEXT_ARG(); + if (get_size(&opt.limit, *argv)) { + fprintf(stderr, "Illegal \"limit\"\n"); + return -1; + } + ok++; + } else if (strcmp(*argv, "qlen") == 0) { + NEXT_ARG(); + if (get_size(&opt.qlen, *argv)) { + fprintf(stderr, "Illegal \"limit\"\n"); + return -1; + } + ok++; + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + if (!ok) + return 0; + + if (opt.rate.rate == 0) { + fprintf(stderr, "\"rate\" is required.\n"); + return -1; + } + + if (opt.ceil.rate == 0) + opt.ceil = opt.rate; + + if (opt.ceil.rate < opt.rate.rate) { + fprintf(stderr, "\"ceil\" must be >= \"rate\".\n"); + return -1; + } + + if (opt.limit == 0) + opt.limit = TC_PERFLOW_DEFAULTLIMIT; + + if (opt.qlen > 0 && opt.qlen < 5) { + fprintf(stderr, "\"qlen\" must be >= 5.\n"); + return -1; + } + + tail = NLMSG_TAIL(n); + //addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + //addattr_l(n, 1024, TCA_PERFLOW_PARMS, &opt, sizeof(opt)); + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + + return 0; +} + +static int perflow_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct tc_perflow_qopt *qopt; + + if (opt == NULL) + return 0; + + if (RTA_PAYLOAD(opt) < sizeof(*qopt)) + return -1; + + qopt = RTA_DATA(opt); + + SPRINT_BUF(b1); + fprintf(f, "rate %s ", sprint_rate(qopt->rate.rate, b1)); + fprintf(f, "ceil %s ", sprint_rate(qopt->ceil.rate, b1)); + fprintf(f, "limit %s ", sprint_size(qopt->rate.rate, b1)); + + return 0; +} + +struct qdisc_util perflow_qdisc_util = { + .id = "perflow", + .parse_qopt = perflow_parse_opt, + .print_qopt = perflow_print_opt, +}; Index: iproute2-2.6.11-w/tc/Makefile =================================================================== --- iproute2-2.6.11-w/tc/Makefile (revision 1) +++ iproute2-2.6.11-w/tc/Makefile (working copy) @@ -7,6 +7,7 @@ TCMODULES += q_fifo.o TCMODULES += q_sfq.o TCMODULES += q_red.o +TCMODULES += q_perflow.o TCMODULES += q_prio.o TCMODULES += q_tbf.o TCMODULES += q_cbq.o