| 1 |
// SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause |
| 2 |
/* Copyright (C) 2024 Nokia |
| 3 |
* |
| 4 |
* Author: Koen De Schepper <[email protected]> |
| 5 |
* Author: Olga Albisser <[email protected]> |
| 6 |
* Author: Henrik Steen <[email protected]> |
| 7 |
* Author: Olivier Tilmans <[email protected]> |
| 8 |
* Author: Chia-Yu Chang <[email protected]> |
| 9 |
* |
| 10 |
* DualPI Improved with a Square (dualpi2): |
| 11 |
* - Supports congestion controls that comply with the Prague requirements |
| 12 |
* in RFC9331 (e.g. TCP-Prague) |
| 13 |
* - Supports coupled dual-queue with PI2 as defined in RFC9332 |
| 14 |
* - Supports ECN L4S-identifier (IP.ECN==0b*1) |
| 15 |
* |
| 16 |
* note: Although DCTCP and BBRv3 can use shallow-threshold ECN marks, |
| 17 |
* they do not meet the 'Prague L4S Requirements' listed in RFC 9331 |
| 18 |
* Section 4, so they can only be used with DualPI2 in a datacenter |
| 19 |
* context. |
| 20 |
* |
| 21 |
* References: |
| 22 |
* - RFC9332: https://datatracker.ietf.org/doc/html/rfc9332 |
| 23 |
* - De Schepper, Koen, et al. "PI 2: A linearized AQM for both classic and |
| 24 |
* scalable TCP." in proc. ACM CoNEXT'16, 2016. |
| 25 |
*/ |
| 26 |
|
| 27 |
#include <stdio.h> |
| 28 |
#include <stdlib.h> |
| 29 |
#include <unistd.h> |
| 30 |
#include <syslog.h> |
| 31 |
#include <fcntl.h> |
| 32 |
#include <sys/socket.h> |
| 33 |
#include <netinet/in.h> |
| 34 |
#include <arpa/inet.h> |
| 35 |
#include <string.h> |
| 36 |
#include <math.h> |
| 37 |
#include <errno.h> |
| 38 |
|
| 39 |
#include "utils.h" |
| 40 |
#include "tc_util.h" |
| 41 |
|
| 42 |
#define MAX_PROB ((uint32_t)(~0U)) |
| 43 |
#define DEFAULT_ALPHA_BETA ((uint32_t)(~0U)) |
| 44 |
#define ALPHA_BETA_MAX ((2 << 23) - 1) /* see net/sched/sch_dualpi2.c */ |
| 45 |
#define ALPHA_BETA_SCALE (1 << 8) |
| 46 |
#define RTT_TYP_TO_MAX 6 |
| 47 |
|
| 48 |
static const char *get_credit_queue(int credit) |
| 49 |
{ |
| 50 |
return credit > 0 ? "C-queue" : "L-queue"; |
| 51 |
} |
| 52 |
|
| 53 |
static const char *get_ecn_type(uint8_t ect) |
| 54 |
{ |
| 55 |
switch (ect & TC_DUALPI2_ECN_MASK_ANY_ECT) { |
| 56 |
case TC_DUALPI2_ECN_MASK_L4S_ECT: return "l4s_ect"; |
| 57 |
case TC_DUALPI2_ECN_MASK_CLA_ECT: |
| 58 |
case TC_DUALPI2_ECN_MASK_ANY_ECT: return "any_ect"; |
| 59 |
default: |
| 60 |
fprintf(stderr, |
| 61 |
"Warning: Unexpected ecn type %u!\n", ect); |
| 62 |
return ""; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
static const char *get_ecn_type_json(uint8_t ect) |
| 67 |
{ |
| 68 |
switch (ect & TC_DUALPI2_ECN_MASK_ANY_ECT) { |
| 69 |
case TC_DUALPI2_ECN_MASK_L4S_ECT: return "l4s-ect"; |
| 70 |
case TC_DUALPI2_ECN_MASK_CLA_ECT: |
| 71 |
case TC_DUALPI2_ECN_MASK_ANY_ECT: return "any-ect"; |
| 72 |
default: |
| 73 |
fprintf(stderr, |
| 74 |
"Warning: Unexpected ecn type %u!\n", ect); |
| 75 |
return ""; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
static void explain(void) |
| 80 |
{ |
| 81 |
fprintf(stderr, "Usage: ... dualpi2\n"); |
| 82 |
fprintf(stderr, " [limit PACKETS]\n"); |
| 83 |
fprintf(stderr, " [memlimit BYTES]\n"); |
| 84 |
fprintf(stderr, " [coupling_factor NUMBER]\n"); |
| 85 |
fprintf(stderr, " [step_thresh TIME|PACKETS]\n"); |
| 86 |
fprintf(stderr, " [min_qlen_step PACKETS]\n"); |
| 87 |
fprintf(stderr, " [drop_on_overload|overflow]\n"); |
| 88 |
fprintf(stderr, " [drop_enqueue|drop_dequeue]\n"); |
| 89 |
fprintf(stderr, " [classic_protection PERCENTAGE]\n"); |
| 90 |
fprintf(stderr, " [max_rtt TIME [typical_rtt TIME]]\n"); |
| 91 |
fprintf(stderr, " [target TIME] [tupdate TIME]\n"); |
| 92 |
fprintf(stderr, " [alpha ALPHA] [beta BETA]\n"); |
| 93 |
fprintf(stderr, " [split_gso|no_split_gso]\n"); |
| 94 |
} |
| 95 |
|
| 96 |
static int get_packets(uint32_t *val, const char *arg) |
| 97 |
{ |
| 98 |
const char *suffixes[] = {"p", "pkt", "pkts", "packet", "packets"}; |
| 99 |
size_t suffix_cnt = sizeof(suffixes) / sizeof(suffixes[0]); |
| 100 |
unsigned long res; |
| 101 |
char *ptr; |
| 102 |
size_t i; |
| 103 |
|
| 104 |
if (!arg || !*arg) |
| 105 |
return -1; |
| 106 |
res = strtoul(arg, &ptr, 10); |
| 107 |
if (!ptr || ptr == arg) |
| 108 |
return -1; |
| 109 |
for (i = 0; i < suffix_cnt; i++) { |
| 110 |
if (strcmp(ptr, suffixes[i]) == 0) |
| 111 |
break; |
| 112 |
} |
| 113 |
if (i == suffix_cnt) |
| 114 |
return -1; |
| 115 |
if (res == ULONG_MAX && errno == ERANGE) |
| 116 |
return -1; |
| 117 |
if (res > 0xFFFFFFFFUL) |
| 118 |
return -1; |
| 119 |
*val = res; |
| 120 |
|
| 121 |
return 0; |
| 122 |
} |
| 123 |
|
| 124 |
static int parse_alpha_beta(const char *name, char *argv, uint32_t *field) |
| 125 |
{ |
| 126 |
float field_f; |
| 127 |
|
| 128 |
if (get_float_min_max(&field_f, argv, 0.0, ALPHA_BETA_MAX)) { |
| 129 |
fprintf(stderr, "Illegal \"%s\"\n", name); |
| 130 |
return -1; |
| 131 |
} else if (field_f < 1.0f / ALPHA_BETA_SCALE) |
| 132 |
fprintf(stderr, |
| 133 |
"Warning: \"%s\" is too small and will be rounded to zero.\n", |
| 134 |
name); |
| 135 |
*field = (uint32_t)(field_f * ALPHA_BETA_SCALE); |
| 136 |
|
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
static int try_get_percent(int *val, const char *arg) |
| 141 |
{ |
| 142 |
double per; |
| 143 |
|
| 144 |
if (parse_percent(&per, arg)) |
| 145 |
return -1; |
| 146 |
|
| 147 |
*val = rint(per * 100); |
| 148 |
|
| 149 |
return 0; |
| 150 |
} |
| 151 |
|
| 152 |
static int dualpi2_parse_opt(const struct qdisc_util *qu, int argc, |
| 153 |
char **argv, struct nlmsghdr *n, const char *dev) |
| 154 |
{ |
| 155 |
uint8_t drop_overload = __TCA_DUALPI2_DROP_OVERLOAD_MAX; |
| 156 |
uint8_t drop_early = __TCA_DUALPI2_DROP_EARLY_MAX; |
| 157 |
uint8_t split_gso = __TCA_DUALPI2_SPLIT_GSO_MAX; |
| 158 |
uint32_t alpha = DEFAULT_ALPHA_BETA; |
| 159 |
uint32_t beta = DEFAULT_ALPHA_BETA; |
| 160 |
int step_unit = __TCA_DUALPI2_MAX; |
| 161 |
bool set_min_qlen_step = false; |
| 162 |
int32_t coupling_factor = -1; |
| 163 |
uint32_t min_qlen_step = 0; |
| 164 |
uint32_t memory_limit = 0; |
| 165 |
uint32_t step_thresh = 0; |
| 166 |
int c_protection = -1; |
| 167 |
uint32_t tupdate = 0; |
| 168 |
uint8_t ecn_mask = 0; |
| 169 |
uint32_t rtt_max = 0; |
| 170 |
uint32_t rtt_typ = 0; |
| 171 |
uint32_t target = 0; |
| 172 |
struct rtattr *tail; |
| 173 |
uint32_t limit = 0; |
| 174 |
|
| 175 |
while (argc > 0) { |
| 176 |
if (strcmp(*argv, "limit") == 0) { |
| 177 |
NEXT_ARG(); |
| 178 |
if (get_u32(&limit, *argv, 10)) { |
| 179 |
fprintf(stderr, "Illegal \"limit\"\n"); |
| 180 |
return -1; |
| 181 |
} |
| 182 |
} else if (strcmp(*argv, "memlimit") == 0) { |
| 183 |
NEXT_ARG(); |
| 184 |
if (get_u32(&memory_limit, *argv, 10)) { |
| 185 |
fprintf(stderr, "Illegal \"memlimit\"\n"); |
| 186 |
return -1; |
| 187 |
} |
| 188 |
} else if (strcmp(*argv, "target") == 0) { |
| 189 |
NEXT_ARG(); |
| 190 |
if (get_time(&target, *argv)) { |
| 191 |
fprintf(stderr, "Illegal \"target\"\n"); |
| 192 |
return -1; |
| 193 |
} |
| 194 |
} else if (strcmp(*argv, "tupdate") == 0) { |
| 195 |
NEXT_ARG(); |
| 196 |
if (get_time(&tupdate, *argv)) { |
| 197 |
fprintf(stderr, "Illegal \"tupdate\"\n"); |
| 198 |
return -1; |
| 199 |
} |
| 200 |
} else if (strcmp(*argv, "alpha") == 0) { |
| 201 |
NEXT_ARG(); |
| 202 |
if (parse_alpha_beta("alpha", *argv, &alpha)) |
| 203 |
return -1; |
| 204 |
} else if (strcmp(*argv, "beta") == 0) { |
| 205 |
NEXT_ARG(); |
| 206 |
if (parse_alpha_beta("beta", *argv, &beta)) |
| 207 |
return -1; |
| 208 |
} else if (strcmp(*argv, "coupling_factor") == 0) { |
| 209 |
NEXT_ARG(); |
| 210 |
if (get_s32(&coupling_factor, *argv, 0) || |
| 211 |
coupling_factor > 0xFFUL || coupling_factor < 0) { |
| 212 |
fprintf(stderr, |
| 213 |
"Illegal \"coupling_factor\"\n"); |
| 214 |
return -1; |
| 215 |
} |
| 216 |
} else if (strcmp(*argv, "l4s_ect") == 0) |
| 217 |
ecn_mask = TC_DUALPI2_ECN_MASK_L4S_ECT; |
| 218 |
else if (strcmp(*argv, "any_ect") == 0) |
| 219 |
ecn_mask = TC_DUALPI2_ECN_MASK_ANY_ECT; |
| 220 |
else if (strcmp(*argv, "step_thresh") == 0) { |
| 221 |
NEXT_ARG(); |
| 222 |
/* First assume that this is specified in time */ |
| 223 |
if (get_time(&step_thresh, *argv)) { |
| 224 |
/* Then packets */ |
| 225 |
if (get_packets(&step_thresh, *argv)) { |
| 226 |
fprintf(stderr, |
| 227 |
"Illegal \"step_thresh\"\n"); |
| 228 |
return -1; |
| 229 |
} |
| 230 |
step_unit = TCA_DUALPI2_STEP_THRESH_PKTS; |
| 231 |
} else { |
| 232 |
step_unit = TCA_DUALPI2_STEP_THRESH_US; |
| 233 |
} |
| 234 |
} else if (strcmp(*argv, "min_qlen_step") == 0) { |
| 235 |
NEXT_ARG(); |
| 236 |
if (get_u32(&min_qlen_step, *argv, 10)) { |
| 237 |
fprintf(stderr, "Illegal \"min_qlen_step\"\n"); |
| 238 |
return -1; |
| 239 |
} |
| 240 |
set_min_qlen_step = true; |
| 241 |
} else if (strcmp(*argv, "overflow") == 0) { |
| 242 |
drop_overload = TC_DUALPI2_DROP_OVERLOAD_OVERFLOW; |
| 243 |
} else if (strcmp(*argv, "drop_on_overload") == 0) { |
| 244 |
drop_overload = TC_DUALPI2_DROP_OVERLOAD_DROP; |
| 245 |
} else if (strcmp(*argv, "drop_enqueue") == 0) { |
| 246 |
drop_early = TC_DUALPI2_DROP_EARLY_DROP_ENQUEUE; |
| 247 |
} else if (strcmp(*argv, "drop_dequeue") == 0) { |
| 248 |
drop_early = TC_DUALPI2_DROP_EARLY_DROP_DEQUEUE; |
| 249 |
} else if (strcmp(*argv, "split_gso") == 0) { |
| 250 |
split_gso = TC_DUALPI2_SPLIT_GSO_SPLIT_GSO; |
| 251 |
} else if (strcmp(*argv, "no_split_gso") == 0) { |
| 252 |
split_gso = TC_DUALPI2_SPLIT_GSO_NO_SPLIT_GSO; |
| 253 |
} else if (strcmp(*argv, "classic_protection") == 0) { |
| 254 |
NEXT_ARG(); |
| 255 |
if (try_get_percent(&c_protection, *argv) || |
| 256 |
c_protection > 100 || |
| 257 |
c_protection < 0) { |
| 258 |
fprintf(stderr, |
| 259 |
"Illegal \"classic_protection\"\n"); |
| 260 |
return -1; |
| 261 |
} |
| 262 |
} else if (strcmp(*argv, "max_rtt") == 0) { |
| 263 |
NEXT_ARG(); |
| 264 |
if (get_time(&rtt_max, *argv)) { |
| 265 |
fprintf(stderr, "Illegal \"max_rtt\"\n"); |
| 266 |
return -1; |
| 267 |
} |
| 268 |
} else if (strcmp(*argv, "typical_rtt") == 0) { |
| 269 |
NEXT_ARG(); |
| 270 |
if (get_time(&rtt_typ, *argv)) { |
| 271 |
fprintf(stderr, "Illegal \"typical_rtt\"\n"); |
| 272 |
return -1; |
| 273 |
} |
| 274 |
} else if (strcmp(*argv, "help") == 0) { |
| 275 |
explain(); |
| 276 |
return -1; |
| 277 |
} else { |
| 278 |
fprintf(stderr, "What is \"%s\"?\n", *argv); |
| 279 |
explain(); |
| 280 |
return -1; |
| 281 |
} |
| 282 |
--argc; |
| 283 |
++argv; |
| 284 |
} |
| 285 |
|
| 286 |
if (rtt_max || rtt_typ) { |
| 287 |
double alpha_f, beta_f; |
| 288 |
|
| 289 |
SPRINT_BUF(max_rtt_t); |
| 290 |
SPRINT_BUF(typ_rtt_t); |
| 291 |
SPRINT_BUF(tupdate_t); |
| 292 |
SPRINT_BUF(target_t); |
| 293 |
|
| 294 |
if (!rtt_typ) |
| 295 |
rtt_typ = max(rtt_max / RTT_TYP_TO_MAX, 1U); |
| 296 |
else if (!rtt_max) |
| 297 |
rtt_max = rtt_typ * RTT_TYP_TO_MAX; |
| 298 |
else if (rtt_typ > rtt_max) { |
| 299 |
fprintf(stderr, "typical_rtt must be <= max_rtt!\n"); |
| 300 |
return -1; |
| 301 |
} |
| 302 |
if (alpha != DEFAULT_ALPHA_BETA || beta != DEFAULT_ALPHA_BETA || |
| 303 |
tupdate || target) |
| 304 |
fprintf(stderr, |
| 305 |
"rtt_max is specified, ignore alpha/beta/tupdate/target\n"); |
| 306 |
target = rtt_typ; |
| 307 |
tupdate = (double)rtt_typ < (double)rtt_max / 3.0f ? |
| 308 |
rtt_typ : (double)rtt_max / 3.0f; |
| 309 |
tupdate = max(tupdate, 1U); |
| 310 |
alpha_f = (double)tupdate / rtt_max / rtt_max |
| 311 |
* TIME_UNITS_PER_SEC * 0.1f; |
| 312 |
beta_f = 0.3f / (double)rtt_max * TIME_UNITS_PER_SEC; |
| 313 |
if (beta_f > ALPHA_BETA_MAX) { |
| 314 |
fprintf(stderr, |
| 315 |
"max_rtt=%s is too low and cause beta to overflow!\n", |
| 316 |
sprint_time(rtt_max, max_rtt_t)); |
| 317 |
return -1; |
| 318 |
} |
| 319 |
if (alpha_f < 1.0f / ALPHA_BETA_SCALE || |
| 320 |
beta_f < 1.0f / ALPHA_BETA_SCALE) { |
| 321 |
fprintf(stderr, |
| 322 |
"Large max_rtt=%s rounds down alpha=%f and/or beta=%f!\n", |
| 323 |
sprint_time(rtt_max, max_rtt_t), |
| 324 |
alpha_f, beta_f); |
| 325 |
return -1; |
| 326 |
} |
| 327 |
fprintf(stderr, |
| 328 |
"Auto-config [max_rtt: %s, typical_rtt: %s]: target=%s tupdate=%s alpha=%f beta=%f\n", |
| 329 |
sprint_time(rtt_max, max_rtt_t), |
| 330 |
sprint_time(rtt_typ, typ_rtt_t), |
| 331 |
sprint_time(target, target_t), |
| 332 |
sprint_time(tupdate, tupdate_t), alpha_f, beta_f); |
| 333 |
alpha = alpha_f * ALPHA_BETA_SCALE; |
| 334 |
beta = beta_f * ALPHA_BETA_SCALE; |
| 335 |
} |
| 336 |
|
| 337 |
tail = addattr_nest(n, 1024, TCA_OPTIONS | NLA_F_NESTED); |
| 338 |
if (limit) |
| 339 |
addattr32(n, 1024, TCA_DUALPI2_LIMIT, limit); |
| 340 |
if (memory_limit) |
| 341 |
addattr32(n, 1024, TCA_DUALPI2_MEMORY_LIMIT, memory_limit); |
| 342 |
if (tupdate) |
| 343 |
addattr32(n, 1024, TCA_DUALPI2_TUPDATE, tupdate); |
| 344 |
if (target) |
| 345 |
addattr32(n, 1024, TCA_DUALPI2_TARGET, target); |
| 346 |
if (alpha != DEFAULT_ALPHA_BETA) |
| 347 |
addattr32(n, 1024, TCA_DUALPI2_ALPHA, alpha); |
| 348 |
if (beta != DEFAULT_ALPHA_BETA) |
| 349 |
addattr32(n, 1024, TCA_DUALPI2_BETA, beta); |
| 350 |
if (ecn_mask != 0) |
| 351 |
addattr8(n, 1024, TCA_DUALPI2_ECN_MASK, ecn_mask); |
| 352 |
if (drop_overload != __TCA_DUALPI2_DROP_OVERLOAD_MAX) |
| 353 |
addattr8(n, 1024, TCA_DUALPI2_DROP_OVERLOAD, drop_overload); |
| 354 |
if (coupling_factor != -1) |
| 355 |
addattr8(n, 1024, TCA_DUALPI2_COUPLING, coupling_factor); |
| 356 |
if (split_gso != __TCA_DUALPI2_SPLIT_GSO_MAX) |
| 357 |
addattr8(n, 1024, TCA_DUALPI2_SPLIT_GSO, split_gso); |
| 358 |
if (step_thresh) { |
| 359 |
if (step_unit == TCA_DUALPI2_STEP_THRESH_PKTS || |
| 360 |
step_unit == TCA_DUALPI2_STEP_THRESH_US) |
| 361 |
addattr32(n, 1024, step_unit, step_thresh); |
| 362 |
} |
| 363 |
if (set_min_qlen_step) |
| 364 |
addattr32(n, 1024, TCA_DUALPI2_MIN_QLEN_STEP, min_qlen_step); |
| 365 |
if (drop_early != __TCA_DUALPI2_DROP_EARLY_MAX) |
| 366 |
addattr8(n, 1024, TCA_DUALPI2_DROP_EARLY, drop_early); |
| 367 |
if (c_protection != -1) |
| 368 |
addattr8(n, 1024, TCA_DUALPI2_C_PROTECTION, c_protection); |
| 369 |
addattr_nest_end(n, tail); |
| 370 |
|
| 371 |
return 0; |
| 372 |
} |
| 373 |
|
| 374 |
static float get_scaled_alpha_beta(struct rtattr *tb) |
| 375 |
{ |
| 376 |
if (!tb) |
| 377 |
return 0; |
| 378 |
|
| 379 |
if (RTA_PAYLOAD(tb) < sizeof(__u32)) |
| 380 |
return -1; |
| 381 |
|
| 382 |
return ((float)rta_getattr_u32(tb)) / ALPHA_BETA_SCALE; |
| 383 |
} |
| 384 |
|
| 385 |
static int dualpi2_print_opt(const struct qdisc_util *qu, FILE *f, |
| 386 |
struct rtattr *opt) |
| 387 |
{ |
| 388 |
struct rtattr *tb[TCA_DUALPI2_MAX + 1]; |
| 389 |
uint8_t drop_overload; |
| 390 |
uint32_t step_thresh; |
| 391 |
uint8_t drop_early; |
| 392 |
uint8_t split_gso; |
| 393 |
uint32_t tupdate; |
| 394 |
uint8_t ecn_type; |
| 395 |
uint32_t target; |
| 396 |
|
| 397 |
SPRINT_BUF(b1); |
| 398 |
|
| 399 |
if (opt == NULL) |
| 400 |
return 0; |
| 401 |
|
| 402 |
parse_rtattr_nested(tb, TCA_DUALPI2_MAX, opt); |
| 403 |
|
| 404 |
if (tb[TCA_DUALPI2_LIMIT] && |
| 405 |
RTA_PAYLOAD(tb[TCA_DUALPI2_LIMIT]) >= sizeof(__u32)) |
| 406 |
print_uint(PRINT_ANY, "limit", "limit %up ", |
| 407 |
rta_getattr_u32(tb[TCA_DUALPI2_LIMIT])); |
| 408 |
if (tb[TCA_DUALPI2_MEMORY_LIMIT] && |
| 409 |
RTA_PAYLOAD(tb[TCA_DUALPI2_MEMORY_LIMIT]) >= sizeof(__u32)) |
| 410 |
print_uint(PRINT_ANY, "memory-limit", "memlimit %uB ", |
| 411 |
rta_getattr_u32(tb[TCA_DUALPI2_MEMORY_LIMIT])); |
| 412 |
if (tb[TCA_DUALPI2_TARGET] && |
| 413 |
RTA_PAYLOAD(tb[TCA_DUALPI2_TARGET]) >= sizeof(__u32)) { |
| 414 |
target = rta_getattr_u32(tb[TCA_DUALPI2_TARGET]); |
| 415 |
print_uint(PRINT_JSON, "target", NULL, target); |
| 416 |
print_string(PRINT_FP, NULL, "target %s ", |
| 417 |
sprint_time(target, b1)); |
| 418 |
} |
| 419 |
if (tb[TCA_DUALPI2_TUPDATE] && |
| 420 |
RTA_PAYLOAD(tb[TCA_DUALPI2_TUPDATE]) >= sizeof(__u32)) { |
| 421 |
tupdate = rta_getattr_u32(tb[TCA_DUALPI2_TUPDATE]); |
| 422 |
print_uint(PRINT_JSON, "tupdate", NULL, tupdate); |
| 423 |
print_string(PRINT_FP, NULL, "tupdate %s ", |
| 424 |
sprint_time(tupdate, b1)); |
| 425 |
} |
| 426 |
if (tb[TCA_DUALPI2_ALPHA] && |
| 427 |
RTA_PAYLOAD(tb[TCA_DUALPI2_ALPHA]) >= sizeof(__u32)) |
| 428 |
print_float(PRINT_ANY, "alpha", "alpha %f ", |
| 429 |
get_scaled_alpha_beta(tb[TCA_DUALPI2_ALPHA])); |
| 430 |
if (tb[TCA_DUALPI2_BETA] && |
| 431 |
RTA_PAYLOAD(tb[TCA_DUALPI2_BETA]) >= sizeof(__u32)) |
| 432 |
print_float(PRINT_ANY, "beta", "beta %f ", |
| 433 |
get_scaled_alpha_beta(tb[TCA_DUALPI2_BETA])); |
| 434 |
if (tb[TCA_DUALPI2_STEP_THRESH_PKTS] && |
| 435 |
RTA_PAYLOAD(tb[TCA_DUALPI2_STEP_THRESH_PKTS]) >= sizeof(__u32)) |
| 436 |
print_uint(PRINT_ANY, "step-thresh-pkts", "step_thresh %up ", |
| 437 |
rta_getattr_u32(tb[TCA_DUALPI2_STEP_THRESH_PKTS])); |
| 438 |
if (tb[TCA_DUALPI2_STEP_THRESH_US] && |
| 439 |
RTA_PAYLOAD(tb[TCA_DUALPI2_STEP_THRESH_US]) >= sizeof(__u32)) { |
| 440 |
step_thresh = rta_getattr_u32(tb[TCA_DUALPI2_STEP_THRESH_US]); |
| 441 |
print_uint(PRINT_JSON, "step-thresh-us", NULL, step_thresh); |
| 442 |
print_string(PRINT_FP, NULL, "step_thresh %s ", |
| 443 |
sprint_time(step_thresh, b1)); |
| 444 |
} |
| 445 |
if (tb[TCA_DUALPI2_MIN_QLEN_STEP] && |
| 446 |
RTA_PAYLOAD(tb[TCA_DUALPI2_MIN_QLEN_STEP]) >= sizeof(__u32)) |
| 447 |
print_uint(PRINT_ANY, "min-qlen-step", "min_qlen_step %up ", |
| 448 |
rta_getattr_u32(tb[TCA_DUALPI2_MIN_QLEN_STEP])); |
| 449 |
if (tb[TCA_DUALPI2_COUPLING] && |
| 450 |
RTA_PAYLOAD(tb[TCA_DUALPI2_COUPLING]) >= sizeof(__u8)) |
| 451 |
print_uint(PRINT_ANY, "coupling", "coupling_factor %u ", |
| 452 |
rta_getattr_u8(tb[TCA_DUALPI2_COUPLING])); |
| 453 |
if (tb[TCA_DUALPI2_DROP_OVERLOAD] && |
| 454 |
RTA_PAYLOAD(tb[TCA_DUALPI2_DROP_OVERLOAD]) >= sizeof(__u8)) { |
| 455 |
drop_overload = rta_getattr_u8(tb[TCA_DUALPI2_DROP_OVERLOAD]); |
| 456 |
print_string(PRINT_FP, NULL, "%s ", |
| 457 |
drop_overload ? "drop_on_overload" : "overflow"); |
| 458 |
print_string(PRINT_JSON, "drop-overload", NULL, |
| 459 |
drop_overload ? "drop" : "overflow"); |
| 460 |
} |
| 461 |
if (tb[TCA_DUALPI2_DROP_EARLY] && |
| 462 |
RTA_PAYLOAD(tb[TCA_DUALPI2_DROP_EARLY]) >= sizeof(__u8)) { |
| 463 |
drop_early = rta_getattr_u8(tb[TCA_DUALPI2_DROP_EARLY]); |
| 464 |
print_string(PRINT_FP, NULL, "%s ", |
| 465 |
drop_early ? "drop_enqueue" : "drop_dequeue"); |
| 466 |
print_string(PRINT_JSON, "drop-early", NULL, |
| 467 |
drop_early ? "drop-enqueue" : "drop-dequeue"); |
| 468 |
} |
| 469 |
if (tb[TCA_DUALPI2_C_PROTECTION] && |
| 470 |
RTA_PAYLOAD(tb[TCA_DUALPI2_C_PROTECTION]) >= sizeof(__u8)) |
| 471 |
print_uint(PRINT_ANY, "c-protection", |
| 472 |
"classic_protection %u%% ", |
| 473 |
rta_getattr_u8(tb[TCA_DUALPI2_C_PROTECTION])); |
| 474 |
if (tb[TCA_DUALPI2_ECN_MASK] && |
| 475 |
RTA_PAYLOAD(tb[TCA_DUALPI2_ECN_MASK]) >= sizeof(__u8)) { |
| 476 |
ecn_type = rta_getattr_u8(tb[TCA_DUALPI2_ECN_MASK]); |
| 477 |
print_string(PRINT_FP, NULL, "%s ", get_ecn_type(ecn_type)); |
| 478 |
print_string(PRINT_JSON, "ecn-mask", NULL, |
| 479 |
get_ecn_type_json(ecn_type)); |
| 480 |
} |
| 481 |
if (tb[TCA_DUALPI2_SPLIT_GSO] && |
| 482 |
RTA_PAYLOAD(tb[TCA_DUALPI2_SPLIT_GSO]) >= sizeof(__u8)) { |
| 483 |
split_gso = rta_getattr_u8(tb[TCA_DUALPI2_SPLIT_GSO]); |
| 484 |
print_string(PRINT_FP, NULL, "%ssplit_gso ", split_gso ? "" : "no_"); |
| 485 |
if (split_gso) |
| 486 |
print_null(PRINT_JSON, "split-gso", NULL, NULL); |
| 487 |
} |
| 488 |
|
| 489 |
return 0; |
| 490 |
} |
| 491 |
|
| 492 |
static int dualpi2_print_xstats(const struct qdisc_util *qu, FILE *f, |
| 493 |
struct rtattr *xstats) |
| 494 |
{ |
| 495 |
struct tc_dualpi2_xstats *st; |
| 496 |
|
| 497 |
if (xstats == NULL) |
| 498 |
return 0; |
| 499 |
|
| 500 |
if (RTA_PAYLOAD(xstats) < sizeof(*st)) |
| 501 |
return -1; |
| 502 |
|
| 503 |
st = RTA_DATA(xstats); |
| 504 |
print_float(PRINT_ANY, "prob", "prob %f ", (double)st->prob / (double)MAX_PROB); |
| 505 |
print_uint(PRINT_ANY, "delay-c", "delay_c %uus ", st->delay_c); |
| 506 |
print_uint(PRINT_ANY, "delay-l", "delay_l %uus", st->delay_l); |
| 507 |
print_nl(); |
| 508 |
|
| 509 |
print_uint(PRINT_ANY, "pkts-in-c", "pkts_in_c %u ", st->packets_in_c); |
| 510 |
print_uint(PRINT_ANY, "pkts-in-l", "pkts_in_l %u ", st->packets_in_l); |
| 511 |
print_uint(PRINT_ANY, "maxq", "maxq %u", st->maxq); |
| 512 |
print_nl(); |
| 513 |
|
| 514 |
print_uint(PRINT_ANY, "ecn-mark", "ecn_mark %u ", st->ecn_mark); |
| 515 |
print_uint(PRINT_ANY, "step-mark", "step_mark %u", st->step_marks); |
| 516 |
print_nl(); |
| 517 |
|
| 518 |
print_int(PRINT_ANY, "credit", "credit %d ", st->credit); |
| 519 |
print_string(PRINT_FP, NULL, "(%s)", get_credit_queue(st->credit)); |
| 520 |
print_nl(); |
| 521 |
|
| 522 |
print_uint(PRINT_ANY, "memory-used", "memory_used %u ", st->memory_used); |
| 523 |
print_uint(PRINT_ANY, "max-memory-used", "(max %u) ", st->max_memory_used); |
| 524 |
print_uint(PRINT_ANY, "memory-limit", "of memory limit %u", st->memory_limit); |
| 525 |
print_nl(); |
| 526 |
|
| 527 |
return 0; |
| 528 |
} |
| 529 |
|
| 530 |
struct qdisc_util dualpi2_qdisc_util = { |
| 531 |
.id = "dualpi2", |
| 532 |
.parse_qopt = dualpi2_parse_opt, |
| 533 |
.print_qopt = dualpi2_print_opt, |
| 534 |
.print_xstats = dualpi2_print_xstats, |
| 535 |
}; |