diff --git a/include/linux/pkt_sched.h b/include/linux/pkt_sched.h index 534b847..a1d7b67 100644 --- a/include/linux/pkt_sched.h +++ b/include/linux/pkt_sched.h @@ -845,4 +845,38 @@ struct tc_pie_xstats { __u32 maxq; /* maximum queue size */ __u32 ecn_mark; /* packets marked with ecn*/ }; + +/* CAKE */ +enum { + TCA_CAKE_UNSPEC, + TCA_CAKE_BASE_RATE, + TCA_CAKE_DIFFSERV_MODE, + TCA_CAKE_ATM, + TCA_CAKE_FLOW_MODE, + __TCA_CAKE_MAX +}; +#define TCA_CAKE_MAX (__TCA_CAKE_MAX - 1) + +struct tc_cake_xstats { + __u16 type; /* constant magic 0xCAFE */ + __u16 class_cnt; + struct { + __u32 rate; + __u32 target_us; + __u32 packets; + __u32 interval_us; + __u64 bytes; + __u32 dropped; + __u32 ecn_marked; + __u32 way_indirect_hits; + __u32 way_misses; + __u32 way_collisions; + __u32 backlog_bytes; + __u32 peak_delay; /* delay to fat flows */ + __u32 avge_delay; + __u32 base_delay; /* delay to sparse flows */ + __u32 dummy2; + } cls[8]; +}; + #endif diff --git a/tc/Makefile b/tc/Makefile index d831a15..e503c8a 100644 --- a/tc/Makefile +++ b/tc/Makefile @@ -59,8 +59,17 @@ TCMODULES += em_meta.o TCMODULES += q_mqprio.o TCMODULES += q_codel.o TCMODULES += q_fq_codel.o +TCMODULES += q_nfq_codel.o +TCMODULES += q_efq_codel.o +TCMODULES += q_sfq_codel.o +TCMODULES += q_pfq_codel.o +TCMODULES += q_ns2_codel.o +TCMODULES += q_ns4_codel.o TCMODULES += q_fq.o TCMODULES += q_pie.o +TCMODULES += q_cake.o +TCMODULES += q_cake0.o +TCMODULES += q_cake2.o TCMODULES += q_hhf.o ifeq ($(TC_CONFIG_IPSET), y) diff --git a/tc/q_cake.c b/tc/q_cake.c new file mode 100644 index 0000000..d9415d3 --- /dev/null +++ b/tc/q_cake.c @@ -0,0 +1,333 @@ +/* + * Common Applications Kept Enhanced -- CAKE + * + * Copyright (C) 2014-2015 Jonathan Morton + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... cake [ bandwidth RATE | unlimited ]\n" + " [ besteffort | precedence | diffserv8 | diffserv4 ]\n" + " [ flowblind | srchost | dsthost | hosts | flows ]\n" + " [ atm ]\n"); +} + +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, + struct nlmsghdr *n) +{ + int unlimited = 0; + unsigned bandwidth = 0; + unsigned diffserv = 0; + int flowmode = -1; + int atm = -1; + struct rtattr *tail; + + while (argc > 0) { + if (strcmp(*argv, "bandwidth") == 0) { + NEXT_ARG(); + if (get_rate(&bandwidth, *argv)) { + fprintf(stderr, "Illegal \"bandwidth\"\n"); + return -1; + } + unlimited = 0; + } else if (strcmp(*argv, "unlimited") == 0) { + bandwidth = 0; + unlimited = 1; + + } else if (strcmp(*argv, "besteffort") == 0) { + diffserv = 1; + } else if (strcmp(*argv, "precedence") == 0) { + diffserv = 2; + } else if (strcmp(*argv, "diffserv8") == 0) { + diffserv = 3; + } else if (strcmp(*argv, "diffserv4") == 0) { + diffserv = 4; + } else if (strcmp(*argv, "diffserv") == 0) { + diffserv = 4; + + } else if (strcmp(*argv, "flowblind") == 0) { + flowmode = 0; + } else if (strcmp(*argv, "srchost") == 0) { + flowmode = 1; + } else if (strcmp(*argv, "dsthost") == 0) { + flowmode = 2; + } else if (strcmp(*argv, "hosts") == 0) { + flowmode = 3; + } else if (strcmp(*argv, "flows") == 0) { + flowmode = 4; + + } else if (strcmp(*argv, "atm") == 0) { + atm = 1; + } else if (strcmp(*argv, "noatm") == 0) { + atm = 0; + + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + if (bandwidth || unlimited) + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth)); + if (diffserv) + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv)); + if (atm != -1) + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm)); + if (flowmode != -1) + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_CAKE_MAX + 1]; + unsigned bandwidth = 0; + unsigned diffserv = 0; + unsigned flowmode = 0; + int atm = -1; + SPRINT_BUF(b1); + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt); + + if (tb[TCA_CAKE_BASE_RATE] && + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) { + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]); + if(bandwidth) + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1)); + else + fprintf(f, "unlimited "); + } + if (tb[TCA_CAKE_DIFFSERV_MODE] && + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) { + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]); + switch(diffserv) { + case 1: + fprintf(f, "besteffort "); + break; + case 2: + fprintf(f, "precedence "); + break; + case 3: + fprintf(f, "diffserv8 "); + break; + case 4: + fprintf(f, "diffserv4 "); + break; + default: + fprintf(f, "(?diffserv?) "); + break; + }; + } + if (tb[TCA_CAKE_FLOW_MODE] && + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) { + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]); + switch(flowmode) { + case 0: + fprintf(f, "flowblind "); + break; + case 1: + fprintf(f, "srchost "); + break; + case 2: + fprintf(f, "dsthost "); + break; + case 3: + fprintf(f, "hosts "); + break; + case 4: + fprintf(f, "flows "); + break; + default: + fprintf(f, "(?flowmode?) "); + break; + }; + } + if (tb[TCA_CAKE_ATM] && + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) { + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]); + if (atm) + fprintf(f, "atm "); + } + + return 0; +} + +static int cake_print_xstats(struct qdisc_util *qu, FILE *f, + struct rtattr *xstats) +{ + /* fq_codel stats format borrowed */ + struct tc_fq_codel_xstats *st; + struct tc_cake_xstats *stc; + SPRINT_BUF(b1); + + if (xstats == NULL) + return 0; + + if (RTA_PAYLOAD(xstats) < sizeof(st->type)) + return -1; + + st = RTA_DATA(xstats); + stc = RTA_DATA(xstats); + + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC && RTA_PAYLOAD(xstats) >= sizeof(*st)) { + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u", + st->qdisc_stats.maxpacket, + st->qdisc_stats.drop_overlimit, + st->qdisc_stats.new_flow_count, + st->qdisc_stats.ecn_mark); + fprintf(f, "\n new_flows_len %u old_flows_len %u", + st->qdisc_stats.new_flows_len, + st->qdisc_stats.old_flows_len); + } else if (st->type == TCA_FQ_CODEL_XSTATS_CLASS && RTA_PAYLOAD(xstats) >= sizeof(*st)) { + fprintf(f, " deficit %d count %u lastcount %u ldelay %s", + st->class_stats.deficit, + st->class_stats.count, + st->class_stats.lastcount, + sprint_time(st->class_stats.ldelay, b1)); + if (st->class_stats.dropping) { + fprintf(f, " dropping"); + if (st->class_stats.drop_next < 0) + fprintf(f, " drop_next -%s", + sprint_time(-st->class_stats.drop_next, b1)); + else + fprintf(f, " drop_next %s", + sprint_time(st->class_stats.drop_next, b1)); + } + } else if (stc->type == 0xCAFE && RTA_PAYLOAD(xstats) >= sizeof(*stc)) { + int i; + + fprintf(f, " "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, " Class %u ", i); + fprintf(f, "\n"); + + fprintf(f, " rate "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12s", sprint_rate(stc->cls[i].rate, b1)); + fprintf(f, "\n"); + + fprintf(f, " target"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12s", sprint_time(stc->cls[i].target_us, b1)); + fprintf(f, "\n"); + + fprintf(f, "interval"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12s", sprint_time(stc->cls[i].interval_us, b1)); + fprintf(f, "\n"); + + fprintf(f, "Pk delay"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12s", sprint_time(stc->cls[i].peak_delay, b1)); + fprintf(f, "\n"); + + fprintf(f, "Av delay"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12s", sprint_time(stc->cls[i].avge_delay, b1)); + fprintf(f, "\n"); + + fprintf(f, "Sp delay"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12s", sprint_time(stc->cls[i].base_delay, b1)); + fprintf(f, "\n"); + + fprintf(f, " pkts "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12u", stc->cls[i].packets); + fprintf(f, "\n"); + + fprintf(f, "way inds"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12u", stc->cls[i].way_indirect_hits); + fprintf(f, "\n"); + + fprintf(f, "way miss"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12u", stc->cls[i].way_misses); + fprintf(f, "\n"); + + fprintf(f, "way cols"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12u", stc->cls[i].way_collisions); + fprintf(f, "\n"); + + fprintf(f, " bytes "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12llu", stc->cls[i].bytes); + fprintf(f, "\n"); + + fprintf(f, " drops "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12u", stc->cls[i].dropped); + fprintf(f, "\n"); + + fprintf(f, " marks "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%12u", stc->cls[i].ecn_marked); + } else { + return -1; + } + return 0; +} + +struct qdisc_util cake_qdisc_util = { + .id = "cake", + .parse_qopt = cake_parse_opt, + .print_qopt = cake_print_opt, + .print_xstats = cake_print_xstats, +}; diff --git a/tc/q_cake0.c b/tc/q_cake0.c new file mode 100644 index 0000000..9fb63ed --- /dev/null +++ b/tc/q_cake0.c @@ -0,0 +1,301 @@ +/* + * Common Applications Kept Enhanced -- CAKE + * + * Copyright (C) 2014 Jonathan Morton + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... cake0 [ bandwidth RATE | unlimited ]\n" + " [ besteffort | precedence | diffserv ]\n" + " [ flowblind | srchost | dsthost | hosts | flows ]\n" + " [ atm ]\n"); +} + +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, + struct nlmsghdr *n) +{ + int unlimited = 0; + unsigned bandwidth = 0; + unsigned diffserv = 0; + int flowmode = -1; + int atm = -1; + struct rtattr *tail; + + while (argc > 0) { + if (strcmp(*argv, "bandwidth") == 0) { + NEXT_ARG(); + if (get_rate(&bandwidth, *argv)) { + fprintf(stderr, "Illegal \"bandwidth\"\n"); + return -1; + } + unlimited = 0; + } else if (strcmp(*argv, "unlimited") == 0) { + bandwidth = 0; + unlimited = 1; + + } else if (strcmp(*argv, "besteffort") == 0) { + diffserv = 1; + } else if (strcmp(*argv, "precedence") == 0) { + diffserv = 2; + } else if (strcmp(*argv, "diffserv") == 0) { + diffserv = 3; + + } else if (strcmp(*argv, "flowblind") == 0) { + flowmode = 0; + } else if (strcmp(*argv, "srchost") == 0) { + flowmode = 1; + } else if (strcmp(*argv, "dsthost") == 0) { + flowmode = 2; + } else if (strcmp(*argv, "hosts") == 0) { + flowmode = 3; + } else if (strcmp(*argv, "flows") == 0) { + flowmode = 4; + + } else if (strcmp(*argv, "atm") == 0) { + atm = 1; + } else if (strcmp(*argv, "noatm") == 0) { + atm = 0; + + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + if (bandwidth || unlimited) + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth)); + if (diffserv) + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv)); + if (atm != -1) + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm)); + if (flowmode != -1) + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_CAKE_MAX + 1]; + unsigned bandwidth = 0; + unsigned diffserv = 0; + unsigned flowmode = 0; + int atm = -1; + SPRINT_BUF(b1); + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt); + + if (tb[TCA_CAKE_BASE_RATE] && + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) { + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]); + if(bandwidth) + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1)); + else + fprintf(f, "unlimited"); + } + if (tb[TCA_CAKE_DIFFSERV_MODE] && + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) { + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]); + switch(diffserv) { + case 1: + fprintf(f, "besteffort "); + break; + case 2: + fprintf(f, "precedence "); + break; + case 3: + fprintf(f, "diffserv "); + break; + default: + fprintf(f, "(?diffserv?) "); + break; + }; + } + if (tb[TCA_CAKE_FLOW_MODE] && + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) { + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]); + switch(flowmode) { + case 0: + fprintf(f, "flowblind "); + break; + case 1: + fprintf(f, "srchost "); + break; + case 2: + fprintf(f, "dsthost "); + break; + case 3: + fprintf(f, "hosts "); + break; + case 4: + fprintf(f, "flows "); + break; + default: + fprintf(f, "(?flowmode?) "); + break; + }; + } + if (tb[TCA_CAKE_ATM] && + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) { + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]); + if (atm) + fprintf(f, "atm "); + } + + return 0; +} + +static int cake_print_xstats(struct qdisc_util *qu, FILE *f, + struct rtattr *xstats) +{ + /* fq_codel stats format borrowed */ + struct tc_fq_codel_xstats *st; + struct tc_cake_xstats *stc; + SPRINT_BUF(b1); + + if (xstats == NULL) + return 0; + + if (RTA_PAYLOAD(xstats) < sizeof(st->type)) + return -1; + + st = RTA_DATA(xstats); + stc = RTA_DATA(xstats); + + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC && RTA_PAYLOAD(xstats) >= sizeof(*st)) { + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u", + st->qdisc_stats.maxpacket, + st->qdisc_stats.drop_overlimit, + st->qdisc_stats.new_flow_count, + st->qdisc_stats.ecn_mark); + fprintf(f, "\n new_flows_len %u old_flows_len %u", + st->qdisc_stats.new_flows_len, + st->qdisc_stats.old_flows_len); + } else if (st->type == TCA_FQ_CODEL_XSTATS_CLASS && RTA_PAYLOAD(xstats) >= sizeof(*st)) { + fprintf(f, " deficit %d count %u lastcount %u ldelay %s", + st->class_stats.deficit, + st->class_stats.count, + st->class_stats.lastcount, + sprint_time(st->class_stats.ldelay, b1)); + if (st->class_stats.dropping) { + fprintf(f, " dropping"); + if (st->class_stats.drop_next < 0) + fprintf(f, " drop_next -%s", + sprint_time(-st->class_stats.drop_next, b1)); + else + fprintf(f, " drop_next %s", + sprint_time(st->class_stats.drop_next, b1)); + } + } else if (stc->type == 0xCAFE && RTA_PAYLOAD(xstats) >= sizeof(*stc)) { + int i; + + fprintf(f, " "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, " Class %u ", i); + fprintf(f, "\n"); + + fprintf(f, " rate "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10s", sprint_rate(stc->cls[i].rate, b1)); + fprintf(f, "\n"); + + fprintf(f, " target"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10s", sprint_time(stc->cls[i].target_us, b1)); + fprintf(f, "\n"); + + fprintf(f, "interval"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10s", sprint_time(stc->cls[i].interval_us, b1)); + fprintf(f, "\n"); + + fprintf(f, " delay "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10s", sprint_time(stc->cls[i].peak_delay, b1)); + fprintf(f, "\n"); + + fprintf(f, " pkts "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10u", stc->cls[i].packets); + fprintf(f, "\n"); + + fprintf(f, " bytes "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10llu", stc->cls[i].bytes); + fprintf(f, "\n"); + + fprintf(f, " drops "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10u", stc->cls[i].dropped); + fprintf(f, "\n"); + + fprintf(f, " marks "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10u", stc->cls[i].ecn_marked); + } else { + return -1; + } + return 0; +} + +struct qdisc_util cake0_qdisc_util = { + .id = "cake0", + .parse_qopt = cake_parse_opt, + .print_qopt = cake_print_opt, + .print_xstats = cake_print_xstats, +}; diff --git a/tc/q_cake2.c b/tc/q_cake2.c new file mode 100644 index 0000000..a4d3f7c --- /dev/null +++ b/tc/q_cake2.c @@ -0,0 +1,296 @@ +/* + * Common Applications Kept Enhanced -- CAKE + * + * Copyright (C) 2014 Jonathan Morton + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... cake2 [ bandwidth RATE | unlimited ]\n" + " [ besteffort | precedence | diffserv ]\n" + " [ flowblind | srchost | dsthost | hosts | flows ]\n" + " [ atm ]\n"); +} + +static int cake_parse_opt(struct qdisc_util *qu, int argc, char **argv, + struct nlmsghdr *n) +{ + int unlimited = 0; + unsigned bandwidth = 0; + unsigned diffserv = 0; + int flowmode = -1; + int atm = -1; + struct rtattr *tail; + + while (argc > 0) { + if (strcmp(*argv, "bandwidth") == 0) { + NEXT_ARG(); + if (get_rate(&bandwidth, *argv)) { + fprintf(stderr, "Illegal \"bandwidth\"\n"); + return -1; + } + unlimited = 0; + } else if (strcmp(*argv, "unlimited") == 0) { + bandwidth = 0; + unlimited = 1; + + } else if (strcmp(*argv, "besteffort") == 0) { + diffserv = 1; + } else if (strcmp(*argv, "precedence") == 0) { + diffserv = 2; + } else if (strcmp(*argv, "diffserv") == 0) { + diffserv = 3; + + } else if (strcmp(*argv, "flowblind") == 0) { + flowmode = 0; + } else if (strcmp(*argv, "srchost") == 0) { + flowmode = 1; + } else if (strcmp(*argv, "dsthost") == 0) { + flowmode = 2; + } else if (strcmp(*argv, "hosts") == 0) { + flowmode = 3; + } else if (strcmp(*argv, "flows") == 0) { + flowmode = 4; + + } else if (strcmp(*argv, "atm") == 0) { + atm = 1; + } else if (strcmp(*argv, "noatm") == 0) { + atm = 0; + + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + if (bandwidth || unlimited) + addattr_l(n, 1024, TCA_CAKE_BASE_RATE, &bandwidth, sizeof(bandwidth)); + if (diffserv) + addattr_l(n, 1024, TCA_CAKE_DIFFSERV_MODE, &diffserv, sizeof(diffserv)); + if (atm != -1) + addattr_l(n, 1024, TCA_CAKE_ATM, &atm, sizeof(atm)); + if (flowmode != -1) + addattr_l(n, 1024, TCA_CAKE_FLOW_MODE, &flowmode, sizeof(flowmode)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int cake_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_CAKE_MAX + 1]; + unsigned bandwidth = 0; + unsigned diffserv = 0; + unsigned flowmode = 0; + int atm = -1; + SPRINT_BUF(b1); + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_CAKE_MAX, opt); + + if (tb[TCA_CAKE_BASE_RATE] && + RTA_PAYLOAD(tb[TCA_CAKE_BASE_RATE]) >= sizeof(__u32)) { + bandwidth = rta_getattr_u32(tb[TCA_CAKE_BASE_RATE]); + if(bandwidth) + fprintf(f, "bandwidth %s ", sprint_rate(bandwidth, b1)); + else + fprintf(f, "unlimited"); + } + if (tb[TCA_CAKE_DIFFSERV_MODE] && + RTA_PAYLOAD(tb[TCA_CAKE_DIFFSERV_MODE]) >= sizeof(__u32)) { + diffserv = rta_getattr_u32(tb[TCA_CAKE_DIFFSERV_MODE]); + switch(diffserv) { + case 1: + fprintf(f, "besteffort "); + break; + case 2: + fprintf(f, "precedence "); + break; + case 3: + fprintf(f, "diffserv "); + break; + default: + fprintf(f, "(?diffserv?) "); + break; + }; + } + if (tb[TCA_CAKE_FLOW_MODE] && + RTA_PAYLOAD(tb[TCA_CAKE_FLOW_MODE]) >= sizeof(__u32)) { + flowmode = rta_getattr_u32(tb[TCA_CAKE_FLOW_MODE]); + switch(flowmode) { + case 0: + fprintf(f, "flowblind "); + break; + case 1: + fprintf(f, "srchost "); + break; + case 2: + fprintf(f, "dsthost "); + break; + case 3: + fprintf(f, "hosts "); + break; + case 4: + fprintf(f, "flows "); + break; + default: + fprintf(f, "(?flowmode?) "); + break; + }; + } + if (tb[TCA_CAKE_ATM] && + RTA_PAYLOAD(tb[TCA_CAKE_ATM]) >= sizeof(__u32)) { + atm = rta_getattr_u32(tb[TCA_CAKE_ATM]); + if (atm) + fprintf(f, "atm "); + } + + return 0; +} + +static int cake_print_xstats(struct qdisc_util *qu, FILE *f, + struct rtattr *xstats) +{ + /* fq_codel stats format borrowed */ + struct tc_fq_codel_xstats *st; + struct tc_cake_xstats *stc; + SPRINT_BUF(b1); + + if (xstats == NULL) + return 0; + + if (RTA_PAYLOAD(xstats) < sizeof(st->type)) + return -1; + + st = RTA_DATA(xstats); + stc = RTA_DATA(xstats); + + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC && RTA_PAYLOAD(xstats) >= sizeof(*st)) { + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u", + st->qdisc_stats.maxpacket, + st->qdisc_stats.drop_overlimit, + st->qdisc_stats.new_flow_count, + st->qdisc_stats.ecn_mark); + fprintf(f, "\n new_flows_len %u old_flows_len %u", + st->qdisc_stats.new_flows_len, + st->qdisc_stats.old_flows_len); + } else if (st->type == TCA_FQ_CODEL_XSTATS_CLASS && RTA_PAYLOAD(xstats) >= sizeof(*st)) { + fprintf(f, " deficit %d count %u lastcount %u ldelay %s", + st->class_stats.deficit, + st->class_stats.count, + st->class_stats.lastcount, + sprint_time(st->class_stats.ldelay, b1)); + if (st->class_stats.dropping) { + fprintf(f, " dropping"); + if (st->class_stats.drop_next < 0) + fprintf(f, " drop_next -%s", + sprint_time(-st->class_stats.drop_next, b1)); + else + fprintf(f, " drop_next %s", + sprint_time(st->class_stats.drop_next, b1)); + } + } else if (stc->type == 0xCAFE && RTA_PAYLOAD(xstats) >= sizeof(*stc)) { + int i; + + fprintf(f, " "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, " Class %u ", i); + fprintf(f, "\n"); + + fprintf(f, " rate "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10s", sprint_rate(stc->cls[i].rate, b1)); + fprintf(f, "\n"); + + fprintf(f, " target"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10s", sprint_time(stc->cls[i].target_us, b1)); + fprintf(f, "\n"); + + fprintf(f, "interval"); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10s", sprint_time(stc->cls[i].interval_us, b1)); + fprintf(f, "\n"); + + fprintf(f, " pkts "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10u", stc->cls[i].packets); + fprintf(f, "\n"); + + fprintf(f, " bytes "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10llu", stc->cls[i].bytes); + fprintf(f, "\n"); + + fprintf(f, " drops "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10u", stc->cls[i].dropped); + fprintf(f, "\n"); + + fprintf(f, " marks "); + for(i=0; i < stc->class_cnt; i++) + fprintf(f, "%10u", stc->cls[i].ecn_marked); + } else { + return -1; + } + return 0; +} + +struct qdisc_util cake2_qdisc_util = { + .id = "cake2", + .parse_qopt = cake_parse_opt, + .print_qopt = cake_print_opt, + .print_xstats = cake_print_xstats, +}; diff --git a/tc/q_efq_codel.c b/tc/q_efq_codel.c new file mode 100644 index 0000000..b80e5e4 --- /dev/null +++ b/tc/q_efq_codel.c @@ -0,0 +1,232 @@ +/* + * Fair Queue Codel + * + * Copyright (C) 2012 Eric Dumazet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... efq_codel [ limit PACKETS ] [ flows NUMBER ]\n"); + fprintf(stderr, " [ target TIME] [ interval TIME ]\n"); + fprintf(stderr, " [ quantum BYTES ] [ [no]ecn ]\n"); +} + +static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv, + struct nlmsghdr *n) +{ + unsigned limit = 0; + unsigned flows = 0; + unsigned target = 0; + unsigned interval = 0; + unsigned quantum = 0; + int ecn = -1; + struct rtattr *tail; + + while (argc > 0) { + if (strcmp(*argv, "limit") == 0) { + NEXT_ARG(); + if (get_unsigned(&limit, *argv, 0)) { + fprintf(stderr, "Illegal \"limit\"\n"); + return -1; + } + } else if (strcmp(*argv, "flows") == 0) { + NEXT_ARG(); + if (get_unsigned(&flows, *argv, 0)) { + fprintf(stderr, "Illegal \"flows\"\n"); + return -1; + } + } else if (strcmp(*argv, "quantum") == 0) { + NEXT_ARG(); + if (get_unsigned(&quantum, *argv, 0)) { + fprintf(stderr, "Illegal \"quantum\"\n"); + return -1; + } + } else if (strcmp(*argv, "target") == 0) { + NEXT_ARG(); + if (get_time(&target, *argv)) { + fprintf(stderr, "Illegal \"target\"\n"); + return -1; + } + } else if (strcmp(*argv, "interval") == 0) { + NEXT_ARG(); + if (get_time(&interval, *argv)) { + fprintf(stderr, "Illegal \"interval\"\n"); + return -1; + } + } else if (strcmp(*argv, "ecn") == 0) { + ecn = 1; + } else if (strcmp(*argv, "noecn") == 0) { + ecn = 0; + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + if (limit) + addattr_l(n, 1024, TCA_FQ_CODEL_LIMIT, &limit, sizeof(limit)); + if (flows) + addattr_l(n, 1024, TCA_FQ_CODEL_FLOWS, &flows, sizeof(flows)); + if (quantum) + addattr_l(n, 1024, TCA_FQ_CODEL_QUANTUM, &quantum, sizeof(quantum)); + if (interval) + addattr_l(n, 1024, TCA_FQ_CODEL_INTERVAL, &interval, sizeof(interval)); + if (target) + addattr_l(n, 1024, TCA_FQ_CODEL_TARGET, &target, sizeof(target)); + if (ecn != -1) + addattr_l(n, 1024, TCA_FQ_CODEL_ECN, &ecn, sizeof(ecn)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_FQ_CODEL_MAX + 1]; + unsigned limit; + unsigned flows; + unsigned interval; + unsigned target; + unsigned ecn; + unsigned quantum; + SPRINT_BUF(b1); + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_FQ_CODEL_MAX, opt); + + if (tb[TCA_FQ_CODEL_LIMIT] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_LIMIT]) >= sizeof(__u32)) { + limit = rta_getattr_u32(tb[TCA_FQ_CODEL_LIMIT]); + fprintf(f, "limit %up ", limit); + } + if (tb[TCA_FQ_CODEL_FLOWS] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_FLOWS]) >= sizeof(__u32)) { + flows = rta_getattr_u32(tb[TCA_FQ_CODEL_FLOWS]); + fprintf(f, "flows %u ", flows); + } + if (tb[TCA_FQ_CODEL_QUANTUM] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_QUANTUM]) >= sizeof(__u32)) { + quantum = rta_getattr_u32(tb[TCA_FQ_CODEL_QUANTUM]); + fprintf(f, "quantum %u ", quantum); + } + if (tb[TCA_FQ_CODEL_TARGET] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_TARGET]) >= sizeof(__u32)) { + target = rta_getattr_u32(tb[TCA_FQ_CODEL_TARGET]); + fprintf(f, "target %s ", sprint_time(target, b1)); + } + if (tb[TCA_FQ_CODEL_INTERVAL] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_INTERVAL]) >= sizeof(__u32)) { + interval = rta_getattr_u32(tb[TCA_FQ_CODEL_INTERVAL]); + fprintf(f, "interval %s ", sprint_time(interval, b1)); + } + if (tb[TCA_FQ_CODEL_ECN] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_ECN]) >= sizeof(__u32)) { + ecn = rta_getattr_u32(tb[TCA_FQ_CODEL_ECN]); + if (ecn) + fprintf(f, "ecn "); + } + + return 0; +} + +static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f, + struct rtattr *xstats) +{ + struct tc_fq_codel_xstats *st; + SPRINT_BUF(b1); + + if (xstats == NULL) + return 0; + + if (RTA_PAYLOAD(xstats) < sizeof(*st)) + return -1; + + st = RTA_DATA(xstats); + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC) { + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u", + st->qdisc_stats.maxpacket, + st->qdisc_stats.drop_overlimit, + st->qdisc_stats.new_flow_count, + st->qdisc_stats.ecn_mark); + fprintf(f, "\n new_flows_len %u old_flows_len %u", + st->qdisc_stats.new_flows_len, + st->qdisc_stats.old_flows_len); + } + if (st->type == TCA_FQ_CODEL_XSTATS_CLASS) { + fprintf(f, " deficit %d count %u lastcount %u ldelay %s", + st->class_stats.deficit, + st->class_stats.count, + st->class_stats.lastcount, + sprint_time(st->class_stats.ldelay, b1)); + if (st->class_stats.dropping) { + fprintf(f, " dropping"); + if (st->class_stats.drop_next < 0) + fprintf(f, " drop_next -%s", + sprint_time(-st->class_stats.drop_next, b1)); + else + fprintf(f, " drop_next %s", + sprint_time(st->class_stats.drop_next, b1)); + } + } + return 0; + +} + +struct qdisc_util efq_codel_qdisc_util = { + .id = "efq_codel", + .parse_qopt = fq_codel_parse_opt, + .print_qopt = fq_codel_print_opt, + .print_xstats = fq_codel_print_xstats, +}; diff --git a/tc/q_nfq_codel.c b/tc/q_nfq_codel.c new file mode 100644 index 0000000..ef24909 --- /dev/null +++ b/tc/q_nfq_codel.c @@ -0,0 +1,232 @@ +/* + * Fair Queue Codel + * + * Copyright (C) 2012 Eric Dumazet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... nfq_codel [ limit PACKETS ] [ flows NUMBER ]\n"); + fprintf(stderr, " [ target TIME] [ interval TIME ]\n"); + fprintf(stderr, " [ quantum BYTES ] [ [no]ecn ]\n"); +} + +static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv, + struct nlmsghdr *n) +{ + unsigned limit = 0; + unsigned flows = 0; + unsigned target = 0; + unsigned interval = 0; + unsigned quantum = 0; + int ecn = -1; + struct rtattr *tail; + + while (argc > 0) { + if (strcmp(*argv, "limit") == 0) { + NEXT_ARG(); + if (get_unsigned(&limit, *argv, 0)) { + fprintf(stderr, "Illegal \"limit\"\n"); + return -1; + } + } else if (strcmp(*argv, "flows") == 0) { + NEXT_ARG(); + if (get_unsigned(&flows, *argv, 0)) { + fprintf(stderr, "Illegal \"flows\"\n"); + return -1; + } + } else if (strcmp(*argv, "quantum") == 0) { + NEXT_ARG(); + if (get_unsigned(&quantum, *argv, 0)) { + fprintf(stderr, "Illegal \"quantum\"\n"); + return -1; + } + } else if (strcmp(*argv, "target") == 0) { + NEXT_ARG(); + if (get_time(&target, *argv)) { + fprintf(stderr, "Illegal \"target\"\n"); + return -1; + } + } else if (strcmp(*argv, "interval") == 0) { + NEXT_ARG(); + if (get_time(&interval, *argv)) { + fprintf(stderr, "Illegal \"interval\"\n"); + return -1; + } + } else if (strcmp(*argv, "ecn") == 0) { + ecn = 1; + } else if (strcmp(*argv, "noecn") == 0) { + ecn = 0; + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + if (limit) + addattr_l(n, 1024, TCA_FQ_CODEL_LIMIT, &limit, sizeof(limit)); + if (flows) + addattr_l(n, 1024, TCA_FQ_CODEL_FLOWS, &flows, sizeof(flows)); + if (quantum) + addattr_l(n, 1024, TCA_FQ_CODEL_QUANTUM, &quantum, sizeof(quantum)); + if (interval) + addattr_l(n, 1024, TCA_FQ_CODEL_INTERVAL, &interval, sizeof(interval)); + if (target) + addattr_l(n, 1024, TCA_FQ_CODEL_TARGET, &target, sizeof(target)); + if (ecn != -1) + addattr_l(n, 1024, TCA_FQ_CODEL_ECN, &ecn, sizeof(ecn)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_FQ_CODEL_MAX + 1]; + unsigned limit; + unsigned flows; + unsigned interval; + unsigned target; + unsigned ecn; + unsigned quantum; + SPRINT_BUF(b1); + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_FQ_CODEL_MAX, opt); + + if (tb[TCA_FQ_CODEL_LIMIT] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_LIMIT]) >= sizeof(__u32)) { + limit = rta_getattr_u32(tb[TCA_FQ_CODEL_LIMIT]); + fprintf(f, "limit %up ", limit); + } + if (tb[TCA_FQ_CODEL_FLOWS] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_FLOWS]) >= sizeof(__u32)) { + flows = rta_getattr_u32(tb[TCA_FQ_CODEL_FLOWS]); + fprintf(f, "flows %u ", flows); + } + if (tb[TCA_FQ_CODEL_QUANTUM] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_QUANTUM]) >= sizeof(__u32)) { + quantum = rta_getattr_u32(tb[TCA_FQ_CODEL_QUANTUM]); + fprintf(f, "quantum %u ", quantum); + } + if (tb[TCA_FQ_CODEL_TARGET] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_TARGET]) >= sizeof(__u32)) { + target = rta_getattr_u32(tb[TCA_FQ_CODEL_TARGET]); + fprintf(f, "target %s ", sprint_time(target, b1)); + } + if (tb[TCA_FQ_CODEL_INTERVAL] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_INTERVAL]) >= sizeof(__u32)) { + interval = rta_getattr_u32(tb[TCA_FQ_CODEL_INTERVAL]); + fprintf(f, "interval %s ", sprint_time(interval, b1)); + } + if (tb[TCA_FQ_CODEL_ECN] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_ECN]) >= sizeof(__u32)) { + ecn = rta_getattr_u32(tb[TCA_FQ_CODEL_ECN]); + if (ecn) + fprintf(f, "ecn "); + } + + return 0; +} + +static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f, + struct rtattr *xstats) +{ + struct tc_fq_codel_xstats *st; + SPRINT_BUF(b1); + + if (xstats == NULL) + return 0; + + if (RTA_PAYLOAD(xstats) < sizeof(*st)) + return -1; + + st = RTA_DATA(xstats); + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC) { + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u", + st->qdisc_stats.maxpacket, + st->qdisc_stats.drop_overlimit, + st->qdisc_stats.new_flow_count, + st->qdisc_stats.ecn_mark); + fprintf(f, "\n new_flows_len %u old_flows_len %u", + st->qdisc_stats.new_flows_len, + st->qdisc_stats.old_flows_len); + } + if (st->type == TCA_FQ_CODEL_XSTATS_CLASS) { + fprintf(f, " deficit %d count %u lastcount %u ldelay %s", + st->class_stats.deficit, + st->class_stats.count, + st->class_stats.lastcount, + sprint_time(st->class_stats.ldelay, b1)); + if (st->class_stats.dropping) { + fprintf(f, " dropping"); + if (st->class_stats.drop_next < 0) + fprintf(f, " drop_next -%s", + sprint_time(-st->class_stats.drop_next, b1)); + else + fprintf(f, " drop_next %s", + sprint_time(st->class_stats.drop_next, b1)); + } + } + return 0; + +} + +struct qdisc_util nfq_codel_qdisc_util = { + .id = "nfq_codel", + .parse_qopt = fq_codel_parse_opt, + .print_qopt = fq_codel_print_opt, + .print_xstats = fq_codel_print_xstats, +}; diff --git a/tc/q_ns2_codel.c b/tc/q_ns2_codel.c new file mode 100644 index 0000000..223a971 --- /dev/null +++ b/tc/q_ns2_codel.c @@ -0,0 +1,188 @@ +/* + * Codel - The Controlled-Delay Active Queue Management algorithm + * + * Copyright (C) 2011-2012 Kathleen Nichols + * Copyright (C) 2011-2012 Van Jacobson + * Copyright (C) 2012 Michael D. Taht + * Copyright (C) 2012 Eric Dumazet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... ns2_codel [ limit PACKETS ] [ target TIME]\n"); + fprintf(stderr, " [ interval TIME ] [ ecn | noecn ]\n"); +} + +static int codel_parse_opt(struct qdisc_util *qu, int argc, char **argv, + struct nlmsghdr *n) +{ + unsigned limit = 0; + unsigned target = 0; + unsigned interval = 0; + int ecn = -1; + struct rtattr *tail; + + while (argc > 0) { + if (strcmp(*argv, "limit") == 0) { + NEXT_ARG(); + if (get_unsigned(&limit, *argv, 0)) { + fprintf(stderr, "Illegal \"limit\"\n"); + return -1; + } + } else if (strcmp(*argv, "target") == 0) { + NEXT_ARG(); + if (get_time(&target, *argv)) { + fprintf(stderr, "Illegal \"target\"\n"); + return -1; + } + } else if (strcmp(*argv, "interval") == 0) { + NEXT_ARG(); + if (get_time(&interval, *argv)) { + fprintf(stderr, "Illegal \"interval\"\n"); + return -1; + } + } else if (strcmp(*argv, "ecn") == 0) { + ecn = 1; + } else if (strcmp(*argv, "noecn") == 0) { + ecn = 0; + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + if (limit) + addattr_l(n, 1024, TCA_CODEL_LIMIT, &limit, sizeof(limit)); + if (interval) + addattr_l(n, 1024, TCA_CODEL_INTERVAL, &interval, sizeof(interval)); + if (target) + addattr_l(n, 1024, TCA_CODEL_TARGET, &target, sizeof(target)); + if (ecn != -1) + addattr_l(n, 1024, TCA_CODEL_ECN, &ecn, sizeof(ecn)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_CODEL_MAX + 1]; + unsigned limit; + unsigned interval; + unsigned target; + unsigned ecn; + SPRINT_BUF(b1); + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_CODEL_MAX, opt); + + if (tb[TCA_CODEL_LIMIT] && + RTA_PAYLOAD(tb[TCA_CODEL_LIMIT]) >= sizeof(__u32)) { + limit = rta_getattr_u32(tb[TCA_CODEL_LIMIT]); + fprintf(f, "limit %up ", limit); + } + if (tb[TCA_CODEL_TARGET] && + RTA_PAYLOAD(tb[TCA_CODEL_TARGET]) >= sizeof(__u32)) { + target = rta_getattr_u32(tb[TCA_CODEL_TARGET]); + fprintf(f, "target %s ", sprint_time(target, b1)); + } + if (tb[TCA_CODEL_INTERVAL] && + RTA_PAYLOAD(tb[TCA_CODEL_INTERVAL]) >= sizeof(__u32)) { + interval = rta_getattr_u32(tb[TCA_CODEL_INTERVAL]); + fprintf(f, "interval %s ", sprint_time(interval, b1)); + } + if (tb[TCA_CODEL_ECN] && + RTA_PAYLOAD(tb[TCA_CODEL_ECN]) >= sizeof(__u32)) { + ecn = rta_getattr_u32(tb[TCA_CODEL_ECN]); + if (ecn) + fprintf(f, "ecn "); + } + + return 0; +} + +static int codel_print_xstats(struct qdisc_util *qu, FILE *f, + struct rtattr *xstats) +{ + struct tc_codel_xstats *st; + SPRINT_BUF(b1); + + if (xstats == NULL) + return 0; + + if (RTA_PAYLOAD(xstats) < sizeof(*st)) + return -1; + + st = RTA_DATA(xstats); + fprintf(f, " count %u lastcount %u ldelay %s", + st->count, st->lastcount, sprint_time(st->ldelay, b1)); + if (st->dropping) + fprintf(f, " dropping"); + if (st->drop_next < 0) + fprintf(f, " drop_next -%s", sprint_time(-st->drop_next, b1)); + else + fprintf(f, " drop_next %s", sprint_time(st->drop_next, b1)); + fprintf(f, "\n maxpacket %u ecn_mark %u drop_overlimit %u", + st->maxpacket, st->ecn_mark, st->drop_overlimit); + return 0; + +} + +struct qdisc_util ns2_codel_qdisc_util = { + .id = "ns2_codel", + .parse_qopt = codel_parse_opt, + .print_qopt = codel_print_opt, + .print_xstats = codel_print_xstats, +}; diff --git a/tc/q_ns4_codel.c b/tc/q_ns4_codel.c new file mode 100644 index 0000000..0aaa349 --- /dev/null +++ b/tc/q_ns4_codel.c @@ -0,0 +1,188 @@ +/* + * Codel - The Controlled-Delay Active Queue Management algorithm + * + * Copyright (C) 2011-2012 Kathleen Nichols + * Copyright (C) 2011-2012 Van Jacobson + * Copyright (C) 2012 Michael D. Taht + * Copyright (C) 2012 Eric Dumazet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... ns4_codel [ limit PACKETS ] [ target TIME]\n"); + fprintf(stderr, " [ interval TIME ] [ ecn | noecn ]\n"); +} + +static int codel_parse_opt(struct qdisc_util *qu, int argc, char **argv, + struct nlmsghdr *n) +{ + unsigned limit = 0; + unsigned target = 0; + unsigned interval = 0; + int ecn = -1; + struct rtattr *tail; + + while (argc > 0) { + if (strcmp(*argv, "limit") == 0) { + NEXT_ARG(); + if (get_unsigned(&limit, *argv, 0)) { + fprintf(stderr, "Illegal \"limit\"\n"); + return -1; + } + } else if (strcmp(*argv, "target") == 0) { + NEXT_ARG(); + if (get_time(&target, *argv)) { + fprintf(stderr, "Illegal \"target\"\n"); + return -1; + } + } else if (strcmp(*argv, "interval") == 0) { + NEXT_ARG(); + if (get_time(&interval, *argv)) { + fprintf(stderr, "Illegal \"interval\"\n"); + return -1; + } + } else if (strcmp(*argv, "ecn") == 0) { + ecn = 1; + } else if (strcmp(*argv, "noecn") == 0) { + ecn = 0; + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + if (limit) + addattr_l(n, 1024, TCA_CODEL_LIMIT, &limit, sizeof(limit)); + if (interval) + addattr_l(n, 1024, TCA_CODEL_INTERVAL, &interval, sizeof(interval)); + if (target) + addattr_l(n, 1024, TCA_CODEL_TARGET, &target, sizeof(target)); + if (ecn != -1) + addattr_l(n, 1024, TCA_CODEL_ECN, &ecn, sizeof(ecn)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_CODEL_MAX + 1]; + unsigned limit; + unsigned interval; + unsigned target; + unsigned ecn; + SPRINT_BUF(b1); + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_CODEL_MAX, opt); + + if (tb[TCA_CODEL_LIMIT] && + RTA_PAYLOAD(tb[TCA_CODEL_LIMIT]) >= sizeof(__u32)) { + limit = rta_getattr_u32(tb[TCA_CODEL_LIMIT]); + fprintf(f, "limit %up ", limit); + } + if (tb[TCA_CODEL_TARGET] && + RTA_PAYLOAD(tb[TCA_CODEL_TARGET]) >= sizeof(__u32)) { + target = rta_getattr_u32(tb[TCA_CODEL_TARGET]); + fprintf(f, "target %s ", sprint_time(target, b1)); + } + if (tb[TCA_CODEL_INTERVAL] && + RTA_PAYLOAD(tb[TCA_CODEL_INTERVAL]) >= sizeof(__u32)) { + interval = rta_getattr_u32(tb[TCA_CODEL_INTERVAL]); + fprintf(f, "interval %s ", sprint_time(interval, b1)); + } + if (tb[TCA_CODEL_ECN] && + RTA_PAYLOAD(tb[TCA_CODEL_ECN]) >= sizeof(__u32)) { + ecn = rta_getattr_u32(tb[TCA_CODEL_ECN]); + if (ecn) + fprintf(f, "ecn "); + } + + return 0; +} + +static int codel_print_xstats(struct qdisc_util *qu, FILE *f, + struct rtattr *xstats) +{ + struct tc_codel_xstats *st; + SPRINT_BUF(b1); + + if (xstats == NULL) + return 0; + + if (RTA_PAYLOAD(xstats) < sizeof(*st)) + return -1; + + st = RTA_DATA(xstats); + fprintf(f, " count %u lastcount %u ldelay %s", + st->count, st->lastcount, sprint_time(st->ldelay, b1)); + if (st->dropping) + fprintf(f, " dropping"); + if (st->drop_next < 0) + fprintf(f, " drop_next -%s", sprint_time(-st->drop_next, b1)); + else + fprintf(f, " drop_next %s", sprint_time(st->drop_next, b1)); + fprintf(f, "\n maxpacket %u ecn_mark %u drop_overlimit %u", + st->maxpacket, st->ecn_mark, st->drop_overlimit); + return 0; + +} + +struct qdisc_util ns4_codel_qdisc_util = { + .id = "ns4_codel", + .parse_qopt = codel_parse_opt, + .print_qopt = codel_print_opt, + .print_xstats = codel_print_xstats, +}; diff --git a/tc/q_pfq_codel.c b/tc/q_pfq_codel.c new file mode 100644 index 0000000..52c5160 --- /dev/null +++ b/tc/q_pfq_codel.c @@ -0,0 +1,232 @@ +/* + * Fair Queue Codel + * + * Copyright (C) 2012 Eric Dumazet + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils.h" +#include "tc_util.h" + +static void explain(void) +{ + fprintf(stderr, "Usage: ... pfq_codel [ limit PACKETS ] [ flows NUMBER ]\n"); + fprintf(stderr, " [ target TIME] [ interval TIME ]\n"); + fprintf(stderr, " [ quantum BYTES ] [ [no]ecn ]\n"); +} + +static int fq_codel_parse_opt(struct qdisc_util *qu, int argc, char **argv, + struct nlmsghdr *n) +{ + unsigned limit = 0; + unsigned flows = 0; + unsigned target = 0; + unsigned interval = 0; + unsigned quantum = 0; + int ecn = -1; + struct rtattr *tail; + + while (argc > 0) { + if (strcmp(*argv, "limit") == 0) { + NEXT_ARG(); + if (get_unsigned(&limit, *argv, 0)) { + fprintf(stderr, "Illegal \"limit\"\n"); + return -1; + } + } else if (strcmp(*argv, "flows") == 0) { + NEXT_ARG(); + if (get_unsigned(&flows, *argv, 0)) { + fprintf(stderr, "Illegal \"flows\"\n"); + return -1; + } + } else if (strcmp(*argv, "quantum") == 0) { + NEXT_ARG(); + if (get_unsigned(&quantum, *argv, 0)) { + fprintf(stderr, "Illegal \"quantum\"\n"); + return -1; + } + } else if (strcmp(*argv, "target") == 0) { + NEXT_ARG(); + if (get_time(&target, *argv)) { + fprintf(stderr, "Illegal \"target\"\n"); + return -1; + } + } else if (strcmp(*argv, "interval") == 0) { + NEXT_ARG(); + if (get_time(&interval, *argv)) { + fprintf(stderr, "Illegal \"interval\"\n"); + return -1; + } + } else if (strcmp(*argv, "ecn") == 0) { + ecn = 1; + } else if (strcmp(*argv, "noecn") == 0) { + ecn = 0; + } else if (strcmp(*argv, "help") == 0) { + explain(); + return -1; + } else { + fprintf(stderr, "What is \"%s\"?\n", *argv); + explain(); + return -1; + } + argc--; argv++; + } + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); + if (limit) + addattr_l(n, 1024, TCA_FQ_CODEL_LIMIT, &limit, sizeof(limit)); + if (flows) + addattr_l(n, 1024, TCA_FQ_CODEL_FLOWS, &flows, sizeof(flows)); + if (quantum) + addattr_l(n, 1024, TCA_FQ_CODEL_QUANTUM, &quantum, sizeof(quantum)); + if (interval) + addattr_l(n, 1024, TCA_FQ_CODEL_INTERVAL, &interval, sizeof(interval)); + if (target) + addattr_l(n, 1024, TCA_FQ_CODEL_TARGET, &target, sizeof(target)); + if (ecn != -1) + addattr_l(n, 1024, TCA_FQ_CODEL_ECN, &ecn, sizeof(ecn)); + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *) tail; + return 0; +} + +static int fq_codel_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) +{ + struct rtattr *tb[TCA_FQ_CODEL_MAX + 1]; + unsigned limit; + unsigned flows; + unsigned interval; + unsigned target; + unsigned ecn; + unsigned quantum; + SPRINT_BUF(b1); + + if (opt == NULL) + return 0; + + parse_rtattr_nested(tb, TCA_FQ_CODEL_MAX, opt); + + if (tb[TCA_FQ_CODEL_LIMIT] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_LIMIT]) >= sizeof(__u32)) { + limit = rta_getattr_u32(tb[TCA_FQ_CODEL_LIMIT]); + fprintf(f, "limit %up ", limit); + } + if (tb[TCA_FQ_CODEL_FLOWS] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_FLOWS]) >= sizeof(__u32)) { + flows = rta_getattr_u32(tb[TCA_FQ_CODEL_FLOWS]); + fprintf(f, "flows %u ", flows); + } + if (tb[TCA_FQ_CODEL_QUANTUM] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_QUANTUM]) >= sizeof(__u32)) { + quantum = rta_getattr_u32(tb[TCA_FQ_CODEL_QUANTUM]); + fprintf(f, "quantum %u ", quantum); + } + if (tb[TCA_FQ_CODEL_TARGET] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_TARGET]) >= sizeof(__u32)) { + target = rta_getattr_u32(tb[TCA_FQ_CODEL_TARGET]); + fprintf(f, "target %s ", sprint_time(target, b1)); + } + if (tb[TCA_FQ_CODEL_INTERVAL] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_INTERVAL]) >= sizeof(__u32)) { + interval = rta_getattr_u32(tb[TCA_FQ_CODEL_INTERVAL]); + fprintf(f, "interval %s ", sprint_time(interval, b1)); + } + if (tb[TCA_FQ_CODEL_ECN] && + RTA_PAYLOAD(tb[TCA_FQ_CODEL_ECN]) >= sizeof(__u32)) { + ecn = rta_getattr_u32(tb[TCA_FQ_CODEL_ECN]); + if (ecn) + fprintf(f, "ecn "); + } + + return 0; +} + +static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f, + struct rtattr *xstats) +{ + struct tc_fq_codel_xstats *st; + SPRINT_BUF(b1); + + if (xstats == NULL) + return 0; + + if (RTA_PAYLOAD(xstats) < sizeof(*st)) + return -1; + + st = RTA_DATA(xstats); + if (st->type == TCA_FQ_CODEL_XSTATS_QDISC) { + fprintf(f, " maxpacket %u drop_overlimit %u new_flow_count %u ecn_mark %u", + st->qdisc_stats.maxpacket, + st->qdisc_stats.drop_overlimit, + st->qdisc_stats.new_flow_count, + st->qdisc_stats.ecn_mark); + fprintf(f, "\n new_flows_len %u old_flows_len %u", + st->qdisc_stats.new_flows_len, + st->qdisc_stats.old_flows_len); + } + if (st->type == TCA_FQ_CODEL_XSTATS_CLASS) { + fprintf(f, " deficit %d count %u lastcount %u ldelay %s", + st->class_stats.deficit, + st->class_stats.count, + st->class_stats.lastcount, + sprint_time(st->class_stats.ldelay, b1)); + if (st->class_stats.dropping) { + fprintf(f, " dropping"); + if (st->class_stats.drop_next < 0) + fprintf(f, " drop_next -%s", + sprint_time(-st->class_stats.drop_next, b1)); + else + fprintf(f, " drop_next %s", + sprint_time(st->class_stats.drop_next, b1)); + } + } + return 0; + +} + +struct qdisc_util pfq_codel_qdisc_util = { + .id = "pfq_codel", + .parse_qopt = fq_codel_parse_opt, + .print_qopt = fq_codel_print_opt, + .print_xstats = fq_codel_print_xstats, +};