| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* Flow Queue PIE |
| 4 |
* |
| 5 |
* Copyright (C) 2019 Mohit P. Tahiliani <[email protected]> |
| 6 |
* Copyright (C) 2019 Sachin D. Patil <[email protected]> |
| 7 |
* Copyright (C) 2019 V. Saicharan <[email protected]> |
| 8 |
* Copyright (C) 2019 Mohit Bhasi <[email protected]> |
| 9 |
* Copyright (C) 2019 Leslie Monis <[email protected]> |
| 10 |
* Copyright (C) 2019 Gautam Ramakrishnan <[email protected]> |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <unistd.h> |
| 16 |
#include <fcntl.h> |
| 17 |
#include <sys/socket.h> |
| 18 |
#include <netinet/in.h> |
| 19 |
#include <arpa/inet.h> |
| 20 |
#include <string.h> |
| 21 |
|
| 22 |
#include "utils.h" |
| 23 |
#include "tc_util.h" |
| 24 |
|
| 25 |
static void explain(void) |
| 26 |
{ |
| 27 |
fprintf(stderr, |
| 28 |
"Usage: ... fq_pie [ limit PACKETS ] [ flows NUMBER ]\n" |
| 29 |
" [ target TIME ] [ tupdate TIME ]\n" |
| 30 |
" [ alpha NUMBER ] [ beta NUMBER ]\n" |
| 31 |
" [ quantum BYTES ] [ memory_limit BYTES ]\n" |
| 32 |
" [ ecn_prob PERCENTAGE ] [ [no]ecn ]\n" |
| 33 |
" [ [no]bytemode ] [ [no_]dq_rate_estimator ]\n"); |
| 34 |
} |
| 35 |
|
| 36 |
#define ALPHA_MAX 32 |
| 37 |
#define BETA_MAX 32 |
| 38 |
|
| 39 |
static int fq_pie_parse_opt(const struct qdisc_util *qu, int argc, char **argv, |
| 40 |
struct nlmsghdr *n, const char *dev) |
| 41 |
{ |
| 42 |
unsigned int limit = 0; |
| 43 |
unsigned int flows = 0; |
| 44 |
unsigned int target = 0; |
| 45 |
unsigned int tupdate = 0; |
| 46 |
unsigned int alpha = 0; |
| 47 |
unsigned int beta = 0; |
| 48 |
unsigned int quantum = 0; |
| 49 |
unsigned int memory_limit = 0; |
| 50 |
unsigned int ecn_prob = 0; |
| 51 |
int ecn = -1; |
| 52 |
int bytemode = -1; |
| 53 |
int dq_rate_estimator = -1; |
| 54 |
struct rtattr *tail; |
| 55 |
|
| 56 |
while (argc > 0) { |
| 57 |
if (strcmp(*argv, "limit") == 0) { |
| 58 |
NEXT_ARG(); |
| 59 |
if (get_unsigned(&limit, *argv, 0)) { |
| 60 |
fprintf(stderr, "Illegal \"limit\"\n"); |
| 61 |
return -1; |
| 62 |
} |
| 63 |
} else if (strcmp(*argv, "flows") == 0) { |
| 64 |
NEXT_ARG(); |
| 65 |
if (get_unsigned(&flows, *argv, 0)) { |
| 66 |
fprintf(stderr, "Illegal \"flows\"\n"); |
| 67 |
return -1; |
| 68 |
} |
| 69 |
} else if (strcmp(*argv, "target") == 0) { |
| 70 |
NEXT_ARG(); |
| 71 |
if (get_time(&target, *argv)) { |
| 72 |
fprintf(stderr, "Illegal \"target\"\n"); |
| 73 |
return -1; |
| 74 |
} |
| 75 |
} else if (strcmp(*argv, "tupdate") == 0) { |
| 76 |
NEXT_ARG(); |
| 77 |
if (get_time(&tupdate, *argv)) { |
| 78 |
fprintf(stderr, "Illegal \"tupdate\"\n"); |
| 79 |
return -1; |
| 80 |
} |
| 81 |
} else if (strcmp(*argv, "alpha") == 0) { |
| 82 |
NEXT_ARG(); |
| 83 |
if (get_unsigned(&alpha, *argv, 0) || |
| 84 |
alpha > ALPHA_MAX) { |
| 85 |
fprintf(stderr, "Illegal \"alpha\"\n"); |
| 86 |
return -1; |
| 87 |
} |
| 88 |
} else if (strcmp(*argv, "beta") == 0) { |
| 89 |
NEXT_ARG(); |
| 90 |
if (get_unsigned(&beta, *argv, 0) || |
| 91 |
beta > BETA_MAX) { |
| 92 |
fprintf(stderr, "Illegal \"beta\"\n"); |
| 93 |
return -1; |
| 94 |
} |
| 95 |
} else if (strcmp(*argv, "quantum") == 0) { |
| 96 |
NEXT_ARG(); |
| 97 |
if (get_size(&quantum, *argv)) { |
| 98 |
fprintf(stderr, "Illegal \"quantum\"\n"); |
| 99 |
return -1; |
| 100 |
} |
| 101 |
} else if (strcmp(*argv, "memory_limit") == 0) { |
| 102 |
NEXT_ARG(); |
| 103 |
if (get_size(&memory_limit, *argv)) { |
| 104 |
fprintf(stderr, "Illegal \"memory_limit\"\n"); |
| 105 |
return -1; |
| 106 |
} |
| 107 |
} else if (strcmp(*argv, "ecn_prob") == 0) { |
| 108 |
NEXT_ARG(); |
| 109 |
if (get_unsigned(&ecn_prob, *argv, 0) || |
| 110 |
ecn_prob >= 100) { |
| 111 |
fprintf(stderr, "Illegal \"ecn_prob\"\n"); |
| 112 |
return -1; |
| 113 |
} |
| 114 |
} else if (strcmp(*argv, "ecn") == 0) { |
| 115 |
ecn = 1; |
| 116 |
} else if (strcmp(*argv, "noecn") == 0) { |
| 117 |
ecn = 0; |
| 118 |
} else if (strcmp(*argv, "bytemode") == 0) { |
| 119 |
bytemode = 1; |
| 120 |
} else if (strcmp(*argv, "nobytemode") == 0) { |
| 121 |
bytemode = 0; |
| 122 |
} else if (strcmp(*argv, "dq_rate_estimator") == 0) { |
| 123 |
dq_rate_estimator = 1; |
| 124 |
} else if (strcmp(*argv, "no_dq_rate_estimator") == 0) { |
| 125 |
dq_rate_estimator = 0; |
| 126 |
} else if (strcmp(*argv, "help") == 0) { |
| 127 |
explain(); |
| 128 |
return -1; |
| 129 |
} else { |
| 130 |
fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 131 |
explain(); |
| 132 |
return -1; |
| 133 |
} |
| 134 |
|
| 135 |
argc--; |
| 136 |
argv++; |
| 137 |
} |
| 138 |
|
| 139 |
tail = addattr_nest(n, 1024, TCA_OPTIONS | NLA_F_NESTED); |
| 140 |
if (limit) |
| 141 |
addattr_l(n, 1024, TCA_FQ_PIE_LIMIT, &limit, sizeof(limit)); |
| 142 |
if (flows) |
| 143 |
addattr_l(n, 1024, TCA_FQ_PIE_FLOWS, &flows, sizeof(flows)); |
| 144 |
if (target) |
| 145 |
addattr_l(n, 1024, TCA_FQ_PIE_TARGET, &target, sizeof(target)); |
| 146 |
if (tupdate) |
| 147 |
addattr_l(n, 1024, TCA_FQ_PIE_TUPDATE, &tupdate, |
| 148 |
sizeof(tupdate)); |
| 149 |
if (alpha) |
| 150 |
addattr_l(n, 1024, TCA_FQ_PIE_ALPHA, &alpha, sizeof(alpha)); |
| 151 |
if (beta) |
| 152 |
addattr_l(n, 1024, TCA_FQ_PIE_BETA, &beta, sizeof(beta)); |
| 153 |
if (quantum) |
| 154 |
addattr_l(n, 1024, TCA_FQ_PIE_QUANTUM, &quantum, |
| 155 |
sizeof(quantum)); |
| 156 |
if (memory_limit) |
| 157 |
addattr_l(n, 1024, TCA_FQ_PIE_MEMORY_LIMIT, &memory_limit, |
| 158 |
sizeof(memory_limit)); |
| 159 |
if (ecn_prob) |
| 160 |
addattr_l(n, 1024, TCA_FQ_PIE_ECN_PROB, &ecn_prob, |
| 161 |
sizeof(ecn_prob)); |
| 162 |
if (ecn != -1) |
| 163 |
addattr_l(n, 1024, TCA_FQ_PIE_ECN, &ecn, sizeof(ecn)); |
| 164 |
if (bytemode != -1) |
| 165 |
addattr_l(n, 1024, TCA_FQ_PIE_BYTEMODE, &bytemode, |
| 166 |
sizeof(bytemode)); |
| 167 |
if (dq_rate_estimator != -1) |
| 168 |
addattr_l(n, 1024, TCA_FQ_PIE_DQ_RATE_ESTIMATOR, |
| 169 |
&dq_rate_estimator, sizeof(dq_rate_estimator)); |
| 170 |
addattr_nest_end(n, tail); |
| 171 |
|
| 172 |
return 0; |
| 173 |
} |
| 174 |
|
| 175 |
static int fq_pie_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *opt) |
| 176 |
{ |
| 177 |
struct rtattr *tb[TCA_FQ_PIE_MAX + 1]; |
| 178 |
unsigned int limit = 0; |
| 179 |
unsigned int flows = 0; |
| 180 |
unsigned int target = 0; |
| 181 |
unsigned int tupdate = 0; |
| 182 |
unsigned int alpha = 0; |
| 183 |
unsigned int beta = 0; |
| 184 |
unsigned int quantum = 0; |
| 185 |
unsigned int memory_limit = 0; |
| 186 |
unsigned int ecn_prob = 0; |
| 187 |
int ecn = -1; |
| 188 |
int bytemode = -1; |
| 189 |
int dq_rate_estimator = -1; |
| 190 |
|
| 191 |
SPRINT_BUF(b1); |
| 192 |
|
| 193 |
if (opt == NULL) |
| 194 |
return 0; |
| 195 |
|
| 196 |
parse_rtattr_nested(tb, TCA_FQ_PIE_MAX, opt); |
| 197 |
|
| 198 |
if (tb[TCA_FQ_PIE_LIMIT] && |
| 199 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_LIMIT]) >= sizeof(__u32)) { |
| 200 |
limit = rta_getattr_u32(tb[TCA_FQ_PIE_LIMIT]); |
| 201 |
print_uint(PRINT_ANY, "limit", "limit %up ", limit); |
| 202 |
} |
| 203 |
if (tb[TCA_FQ_PIE_FLOWS] && |
| 204 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_FLOWS]) >= sizeof(__u32)) { |
| 205 |
flows = rta_getattr_u32(tb[TCA_FQ_PIE_FLOWS]); |
| 206 |
print_uint(PRINT_ANY, "flows", "flows %u ", flows); |
| 207 |
} |
| 208 |
if (tb[TCA_FQ_PIE_TARGET] && |
| 209 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_TARGET]) >= sizeof(__u32)) { |
| 210 |
target = rta_getattr_u32(tb[TCA_FQ_PIE_TARGET]); |
| 211 |
print_uint(PRINT_JSON, "target", NULL, target); |
| 212 |
print_string(PRINT_FP, NULL, "target %s ", |
| 213 |
sprint_time(target, b1)); |
| 214 |
} |
| 215 |
if (tb[TCA_FQ_PIE_TUPDATE] && |
| 216 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_TUPDATE]) >= sizeof(__u32)) { |
| 217 |
tupdate = rta_getattr_u32(tb[TCA_FQ_PIE_TUPDATE]); |
| 218 |
print_uint(PRINT_JSON, "tupdate", NULL, tupdate); |
| 219 |
print_string(PRINT_FP, NULL, "tupdate %s ", |
| 220 |
sprint_time(tupdate, b1)); |
| 221 |
} |
| 222 |
if (tb[TCA_FQ_PIE_ALPHA] && |
| 223 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_ALPHA]) >= sizeof(__u32)) { |
| 224 |
alpha = rta_getattr_u32(tb[TCA_FQ_PIE_ALPHA]); |
| 225 |
print_uint(PRINT_ANY, "alpha", "alpha %u ", alpha); |
| 226 |
} |
| 227 |
if (tb[TCA_FQ_PIE_BETA] && |
| 228 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_BETA]) >= sizeof(__u32)) { |
| 229 |
beta = rta_getattr_u32(tb[TCA_FQ_PIE_BETA]); |
| 230 |
print_uint(PRINT_ANY, "beta", "beta %u ", beta); |
| 231 |
} |
| 232 |
if (tb[TCA_FQ_PIE_QUANTUM] && |
| 233 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_QUANTUM]) >= sizeof(__u32)) { |
| 234 |
quantum = rta_getattr_u32(tb[TCA_FQ_PIE_QUANTUM]); |
| 235 |
print_size(PRINT_ANY, "quantum", "quantum %s ", quantum); |
| 236 |
} |
| 237 |
if (tb[TCA_FQ_PIE_MEMORY_LIMIT] && |
| 238 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_MEMORY_LIMIT]) >= sizeof(__u32)) { |
| 239 |
memory_limit = rta_getattr_u32(tb[TCA_FQ_PIE_MEMORY_LIMIT]); |
| 240 |
print_size(PRINT_ANY, "memory_limit", "memory_limit %s ", |
| 241 |
memory_limit); |
| 242 |
} |
| 243 |
if (tb[TCA_FQ_PIE_ECN_PROB] && |
| 244 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_ECN_PROB]) >= sizeof(__u32)) { |
| 245 |
ecn_prob = rta_getattr_u32(tb[TCA_FQ_PIE_ECN_PROB]); |
| 246 |
print_uint(PRINT_ANY, "ecn_prob", "ecn_prob %u ", ecn_prob); |
| 247 |
} |
| 248 |
if (tb[TCA_FQ_PIE_ECN] && |
| 249 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_ECN]) >= sizeof(__u32)) { |
| 250 |
ecn = rta_getattr_u32(tb[TCA_FQ_PIE_ECN]); |
| 251 |
if (ecn) |
| 252 |
print_bool(PRINT_ANY, "ecn", "ecn ", true); |
| 253 |
} |
| 254 |
if (tb[TCA_FQ_PIE_BYTEMODE] && |
| 255 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_BYTEMODE]) >= sizeof(__u32)) { |
| 256 |
bytemode = rta_getattr_u32(tb[TCA_FQ_PIE_BYTEMODE]); |
| 257 |
if (bytemode) |
| 258 |
print_bool(PRINT_ANY, "bytemode", "bytemode ", true); |
| 259 |
} |
| 260 |
if (tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR] && |
| 261 |
RTA_PAYLOAD(tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR]) >= sizeof(__u32)) { |
| 262 |
dq_rate_estimator = |
| 263 |
rta_getattr_u32(tb[TCA_FQ_PIE_DQ_RATE_ESTIMATOR]); |
| 264 |
if (dq_rate_estimator) |
| 265 |
print_bool(PRINT_ANY, "dq_rate_estimator", |
| 266 |
"dq_rate_estimator ", true); |
| 267 |
} |
| 268 |
|
| 269 |
return 0; |
| 270 |
} |
| 271 |
|
| 272 |
static int fq_pie_print_xstats(const struct qdisc_util *qu, FILE *f, |
| 273 |
struct rtattr *xstats) |
| 274 |
{ |
| 275 |
struct tc_fq_pie_xstats _st = {}, *st; |
| 276 |
|
| 277 |
if (xstats == NULL) |
| 278 |
return 0; |
| 279 |
|
| 280 |
st = RTA_DATA(xstats); |
| 281 |
if (RTA_PAYLOAD(xstats) < sizeof(*st)) { |
| 282 |
memcpy(&_st, st, RTA_PAYLOAD(xstats)); |
| 283 |
st = &_st; |
| 284 |
} |
| 285 |
|
| 286 |
print_uint(PRINT_ANY, "pkts_in", " pkts_in %u", |
| 287 |
st->packets_in); |
| 288 |
print_uint(PRINT_ANY, "overlimit", " overlimit %u", |
| 289 |
st->overlimit); |
| 290 |
print_uint(PRINT_ANY, "overmemory", " overmemory %u", |
| 291 |
st->overmemory); |
| 292 |
print_uint(PRINT_ANY, "dropped", " dropped %u", |
| 293 |
st->dropped); |
| 294 |
print_uint(PRINT_ANY, "ecn_mark", " ecn_mark %u", |
| 295 |
st->ecn_mark); |
| 296 |
print_nl(); |
| 297 |
print_uint(PRINT_ANY, "new_flow_count", " new_flow_count %u", |
| 298 |
st->new_flow_count); |
| 299 |
print_uint(PRINT_ANY, "new_flows_len", " new_flows_len %u", |
| 300 |
st->new_flows_len); |
| 301 |
print_uint(PRINT_ANY, "old_flows_len", " old_flows_len %u", |
| 302 |
st->old_flows_len); |
| 303 |
print_uint(PRINT_ANY, "memory_used", " memory_used %u", |
| 304 |
st->memory_usage); |
| 305 |
|
| 306 |
return 0; |
| 307 |
|
| 308 |
} |
| 309 |
|
| 310 |
struct qdisc_util fq_pie_qdisc_util = { |
| 311 |
.id = "fq_pie", |
| 312 |
.parse_qopt = fq_pie_parse_opt, |
| 313 |
.print_qopt = fq_pie_print_opt, |
| 314 |
.print_xstats = fq_pie_print_xstats, |
| 315 |
}; |