| 1 | --- |
| 2 | include/linux/pkt_sched.h | 59 +++++++++++++ |
| 3 | tc/Makefile | 1 |
| 4 | tc/q_esfq.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++ |
| 5 | 3 files changed, 260 insertions(+) |
| 6 | |
| 7 | --- a/include/linux/pkt_sched.h |
| 8 | +++ b/include/linux/pkt_sched.h |
| 9 | @@ -174,8 +174,38 @@ struct tc_sfq_qopt |
| 10 | * |
| 11 | * The only reason for this is efficiency, it is possible |
| 12 | * to change these parameters in compile time. |
| 13 | + * |
| 14 | + * If you need to play with these values use esfq instead. |
| 15 | */ |
| 16 | |
| 17 | +/* ESFQ section */ |
| 18 | + |
| 19 | +enum |
| 20 | +{ |
| 21 | + /* traditional */ |
| 22 | + TCA_SFQ_HASH_CLASSIC, |
| 23 | + TCA_SFQ_HASH_DST, |
| 24 | + TCA_SFQ_HASH_SRC, |
| 25 | + /* conntrack */ |
| 26 | + TCA_SFQ_HASH_CTORIGDST, |
| 27 | + TCA_SFQ_HASH_CTORIGSRC, |
| 28 | + TCA_SFQ_HASH_CTREPLDST, |
| 29 | + TCA_SFQ_HASH_CTREPLSRC, |
| 30 | + TCA_SFQ_HASH_CTNATCHG, |
| 31 | +}; |
| 32 | + |
| 33 | +struct tc_esfq_qopt |
| 34 | +{ |
| 35 | + unsigned quantum; /* Bytes per round allocated to flow */ |
| 36 | + int perturb_period; /* Period of hash perturbation */ |
| 37 | + __u32 limit; /* Maximal packets in queue */ |
| 38 | + unsigned divisor; /* Hash divisor */ |
| 39 | + unsigned flows; /* Maximal number of flows */ |
| 40 | + unsigned hash_kind; /* Hash function to use for flow identification */ |
| 41 | +}; |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | /* RED section */ |
| 46 | |
| 47 | enum |
| 48 | @@ -579,8 +609,37 @@ struct tc_sfq_xstats { |
| 49 | * |
| 50 | * The only reason for this is efficiency, it is possible |
| 51 | * to change these parameters in compile time. |
| 52 | + * |
| 53 | + * If you need to play with these values use esfq instead. |
| 54 | */ |
| 55 | |
| 56 | +/* ESFQ section */ |
| 57 | + |
| 58 | +enum |
| 59 | +{ |
| 60 | + /* traditional */ |
| 61 | + TCA_SFQ_HASH_CLASSIC, |
| 62 | + TCA_SFQ_HASH_DST, |
| 63 | + TCA_SFQ_HASH_SRC, |
| 64 | + /* conntrack */ |
| 65 | + TCA_SFQ_HASH_CTORIGDST, |
| 66 | + TCA_SFQ_HASH_CTORIGSRC, |
| 67 | + TCA_SFQ_HASH_CTREPLDST, |
| 68 | + TCA_SFQ_HASH_CTREPLSRC, |
| 69 | + TCA_SFQ_HASH_CTNATCHG, |
| 70 | +}; |
| 71 | + |
| 72 | +struct tc_esfq_qopt |
| 73 | +{ |
| 74 | + unsigned quantum; /* Bytes per round allocated to flow */ |
| 75 | + int perturb_period; /* Period of hash perturbation */ |
| 76 | + __u32 limit; /* Maximal packets in queue */ |
| 77 | + unsigned divisor; /* Hash divisor */ |
| 78 | + unsigned flows; /* Maximal number of flows */ |
| 79 | + unsigned hash_kind; /* Hash function to use for flow identification */ |
| 80 | +}; |
| 81 | + |
| 82 | + |
| 83 | /* RED section */ |
| 84 | |
| 85 | enum { |
| 86 | --- a/tc/Makefile |
| 87 | +++ b/tc/Makefile |
| 88 | @@ -8,6 +8,7 @@ SHARED_LIBS ?= y |
| 89 | TCMODULES := |
| 90 | TCMODULES += q_fifo.o |
| 91 | TCMODULES += q_sfq.o |
| 92 | +TCMODULES += q_esfq.o |
| 93 | TCMODULES += q_red.o |
| 94 | TCMODULES += q_prio.o |
| 95 | TCMODULES += q_tbf.o |
| 96 | --- /dev/null |
| 97 | +++ b/tc/q_esfq.c |
| 98 | @@ -0,0 +1,200 @@ |
| 99 | +/* |
| 100 | + * q_esfq.c ESFQ. |
| 101 | + * |
| 102 | + * This program is free software; you can redistribute it and/or |
| 103 | + * modify it under the terms of the GNU General Public License |
| 104 | + * as published by the Free Software Foundation; either version |
| 105 | + * 2 of the License, or (at your option) any later version. |
| 106 | + * |
| 107 | + * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
| 108 | + * |
| 109 | + * Changes: Alexander Atanasov, <alex@ssi.bg> |
| 110 | + * Alexander Clouter, <alex@digriz.org.uk> |
| 111 | + * Corey Hickey, <bugfood-c@fatooh.org> |
| 112 | + * |
| 113 | + */ |
| 114 | + |
| 115 | +#include <stdio.h> |
| 116 | +#include <stdlib.h> |
| 117 | +#include <unistd.h> |
| 118 | +#include <syslog.h> |
| 119 | +#include <fcntl.h> |
| 120 | +#include <math.h> |
| 121 | +#include <sys/socket.h> |
| 122 | +#include <netinet/in.h> |
| 123 | +#include <arpa/inet.h> |
| 124 | +#include <string.h> |
| 125 | + |
| 126 | +#include "utils.h" |
| 127 | +#include "tc_util.h" |
| 128 | + |
| 129 | +static void explain(void) |
| 130 | +{ |
| 131 | + fprintf(stderr, "Usage: ... esfq [ perturb SECS ] [ quantum BYTES ] [ depth FLOWS ]\n\t[ divisor HASHBITS ] [ limit PKTS ] [ hash HASHTYPE]\n"); |
| 132 | + fprintf(stderr,"Where: \n"); |
| 133 | + fprintf(stderr,"HASHTYPE := { classic | src | dst | ctorigdst | ctorigsrc | ctrepldst | ctreplsrc | ctnatchg }\n"); |
| 134 | +} |
| 135 | + |
| 136 | +#define usage() return(-1) |
| 137 | + |
| 138 | +static int esfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) |
| 139 | +{ |
| 140 | + int ok=0; |
| 141 | + struct tc_esfq_qopt opt; |
| 142 | + |
| 143 | + memset(&opt, 0, sizeof(opt)); |
| 144 | + |
| 145 | + opt.hash_kind= TCA_SFQ_HASH_CLASSIC; |
| 146 | + |
| 147 | + while (argc > 0) { |
| 148 | + if (strcmp(*argv, "quantum") == 0) { |
| 149 | + NEXT_ARG(); |
| 150 | + if (get_size(&opt.quantum, *argv)) { |
| 151 | + fprintf(stderr, "Illegal \"quantum\"\n"); |
| 152 | + return -1; |
| 153 | + } |
| 154 | + ok++; |
| 155 | + } else if (strcmp(*argv, "perturb") == 0) { |
| 156 | + NEXT_ARG(); |
| 157 | + if (get_integer(&opt.perturb_period, *argv, 0)) { |
| 158 | + fprintf(stderr, "Illegal \"perturb\"\n"); |
| 159 | + return -1; |
| 160 | + } |
| 161 | + ok++; |
| 162 | + } else if (strcmp(*argv, "depth") == 0) { |
| 163 | + NEXT_ARG(); |
| 164 | + if (get_integer((int *) &opt.flows, *argv, 0)) { |
| 165 | + fprintf(stderr, "Illegal \"depth\"\n"); |
| 166 | + return -1; |
| 167 | + } |
| 168 | + ok++; |
| 169 | + } else if (strcmp(*argv, "divisor") == 0) { |
| 170 | + NEXT_ARG(); |
| 171 | + if (get_integer((int *) &opt.divisor, *argv, 0)) { |
| 172 | + fprintf(stderr, "Illegal \"divisor\"\n"); |
| 173 | + return -1; |
| 174 | + } |
| 175 | + if(opt.divisor >= 14) { |
| 176 | + fprintf(stderr, "Illegal \"divisor\": must be < 14\n"); |
| 177 | + return -1; |
| 178 | + } |
| 179 | + opt.divisor=pow(2,opt.divisor); |
| 180 | + ok++; |
| 181 | + } else if (strcmp(*argv, "limit") == 0) { |
| 182 | + NEXT_ARG(); |
| 183 | + if (get_integer((int *) &opt.limit, *argv, 0)) { |
| 184 | + fprintf(stderr, "Illegal \"limit\"\n"); |
| 185 | + return -1; |
| 186 | + } |
| 187 | + ok++; |
| 188 | + } else if (strcmp(*argv, "hash") == 0) { |
| 189 | + NEXT_ARG(); |
| 190 | + if(strcmp(*argv, "classic") == 0) { |
| 191 | + opt.hash_kind= TCA_SFQ_HASH_CLASSIC; |
| 192 | + } else |
| 193 | + if(strcmp(*argv, "dst") == 0) { |
| 194 | + opt.hash_kind= TCA_SFQ_HASH_DST; |
| 195 | + } else |
| 196 | + if(strcmp(*argv, "src") == 0) { |
| 197 | + opt.hash_kind= TCA_SFQ_HASH_SRC; |
| 198 | + } else |
| 199 | + if(strcmp(*argv, "ctorigsrc") == 0) { |
| 200 | + opt.hash_kind= TCA_SFQ_HASH_CTORIGSRC; |
| 201 | + } else |
| 202 | + if(strcmp(*argv, "ctorigdst") == 0) { |
| 203 | + opt.hash_kind= TCA_SFQ_HASH_CTORIGDST; |
| 204 | + } else |
| 205 | + if(strcmp(*argv, "ctreplsrc") == 0) { |
| 206 | + opt.hash_kind= TCA_SFQ_HASH_CTREPLSRC; |
| 207 | + } else |
| 208 | + if(strcmp(*argv, "ctrepldst") == 0) { |
| 209 | + opt.hash_kind= TCA_SFQ_HASH_CTREPLDST; |
| 210 | + } else |
| 211 | + if(strcmp(*argv, "ctnatchg") == 0) { |
| 212 | + opt.hash_kind= TCA_SFQ_HASH_CTNATCHG; |
| 213 | + } else { |
| 214 | + fprintf(stderr, "Illegal \"hash\"\n"); |
| 215 | + explain(); |
| 216 | + return -1; |
| 217 | + } |
| 218 | + ok++; |
| 219 | + } else if (strcmp(*argv, "help") == 0) { |
| 220 | + explain(); |
| 221 | + return -1; |
| 222 | + } else { |
| 223 | + fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 224 | + explain(); |
| 225 | + return -1; |
| 226 | + } |
| 227 | + argc--; argv++; |
| 228 | + } |
| 229 | + |
| 230 | + if (ok) |
| 231 | + addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); |
| 232 | + return 0; |
| 233 | +} |
| 234 | + |
| 235 | +static int esfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
| 236 | +{ |
| 237 | + struct tc_esfq_qopt *qopt; |
| 238 | + SPRINT_BUF(b1); |
| 239 | + |
| 240 | + if (opt == NULL) |
| 241 | + return 0; |
| 242 | + |
| 243 | + if (RTA_PAYLOAD(opt) < sizeof(*qopt)) |
| 244 | + return -1; |
| 245 | + qopt = RTA_DATA(opt); |
| 246 | + fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1)); |
| 247 | + if (show_details) { |
| 248 | + fprintf(f, "limit %up flows %u/%u ", |
| 249 | + qopt->limit, qopt->flows, qopt->divisor); |
| 250 | + } |
| 251 | + if (qopt->perturb_period) |
| 252 | + fprintf(f, "perturb %dsec ", qopt->perturb_period); |
| 253 | + |
| 254 | + fprintf(f,"hash: "); |
| 255 | + switch(qopt->hash_kind) |
| 256 | + { |
| 257 | + case TCA_SFQ_HASH_CLASSIC: |
| 258 | + fprintf(f,"classic"); |
| 259 | + break; |
| 260 | + case TCA_SFQ_HASH_DST: |
| 261 | + fprintf(f,"dst"); |
| 262 | + break; |
| 263 | + case TCA_SFQ_HASH_SRC: |
| 264 | + fprintf(f,"src"); |
| 265 | + break; |
| 266 | + case TCA_SFQ_HASH_CTORIGSRC: |
| 267 | + fprintf(f,"ctorigsrc"); |
| 268 | + break; |
| 269 | + case TCA_SFQ_HASH_CTORIGDST: |
| 270 | + fprintf(f,"ctorigdst"); |
| 271 | + break; |
| 272 | + case TCA_SFQ_HASH_CTREPLSRC: |
| 273 | + fprintf(f,"ctreplsrc"); |
| 274 | + break; |
| 275 | + case TCA_SFQ_HASH_CTREPLDST: |
| 276 | + fprintf(f,"ctrepldst"); |
| 277 | + break; |
| 278 | + case TCA_SFQ_HASH_CTNATCHG: |
| 279 | + fprintf(f,"ctnatchg"); |
| 280 | + break; |
| 281 | + default: |
| 282 | + fprintf(f,"Unknown"); |
| 283 | + } |
| 284 | + return 0; |
| 285 | +} |
| 286 | + |
| 287 | +static int esfq_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats) |
| 288 | +{ |
| 289 | + return 0; |
| 290 | +} |
| 291 | + |
| 292 | + |
| 293 | +struct qdisc_util esfq_qdisc_util = { |
| 294 | + .id = "esfq", |
| 295 | + .parse_qopt = esfq_parse_opt, |
| 296 | + .print_qopt = esfq_print_opt, |
| 297 | + .print_xstats = esfq_print_xstats, |
| 298 | +}; |
| 299 | |