19
19
#include <netinet/in.h>
20
20
#include <arpa/inet.h>
21
21
#include <string.h>
24
25
#include "tc_util.h"
26
28
static void explain(void)
28
30
fprintf(stderr, "Usage: ... sfq [ limit NUMBER ] [ perturb SECS ] [ quantum BYTES ]\n");
29
fprintf(stderr, " [ divisor NUMBER ]\n");
31
fprintf(stderr, " [ divisor NUMBER ] [ flows NUMBER] [ depth NUMBER ]\n");
32
fprintf(stderr, " [ headdrop ]\n");
33
fprintf(stderr, " [ redflowlimit BYTES ] [ min BYTES ] [ max BYTES ]\n");
34
fprintf(stderr, " [ avpkt BYTES ] [ burst PACKETS ] [ probability P ]\n");
35
fprintf(stderr, " [ ecn ] [ harddrop ]\n");
32
38
static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n)
35
struct tc_sfq_qopt opt;
41
struct tc_sfq_qopt_v1 opt;
42
unsigned int burst = 0;
44
unsigned int avpkt = 1000;
45
double probability = 0.02;
37
47
memset(&opt, 0, sizeof(opt));
40
50
if (strcmp(*argv, "quantum") == 0) {
42
if (get_size(&opt.quantum, *argv)) {
52
if (get_size(&opt.v0.quantum, *argv)) {
43
53
fprintf(stderr, "Illegal \"limit\"\n");
47
57
} else if (strcmp(*argv, "perturb") == 0) {
49
if (get_integer(&opt.perturb_period, *argv, 0)) {
59
if (get_integer(&opt.v0.perturb_period, *argv, 0)) {
50
60
fprintf(stderr, "Illegal \"perturb\"\n");
54
64
} else if (strcmp(*argv, "limit") == 0) {
56
if (get_u32(&opt.limit, *argv, 0)) {
66
if (get_u32(&opt.v0.limit, *argv, 0)) {
57
67
fprintf(stderr, "Illegal \"limit\"\n");
70
if (opt.v0.limit < 2) {
61
71
fprintf(stderr, "Illegal \"limit\", must be > 1\n");
65
75
} else if (strcmp(*argv, "divisor") == 0) {
67
if (get_u32(&opt.divisor, *argv, 0)) {
77
if (get_u32(&opt.v0.divisor, *argv, 0)) {
68
78
fprintf(stderr, "Illegal \"divisor\"\n");
82
} else if (strcmp(*argv, "flows") == 0) {
84
if (get_u32(&opt.v0.flows, *argv, 0)) {
85
fprintf(stderr, "Illegal \"flows\"\n");
89
} else if (strcmp(*argv, "depth") == 0) {
91
if (get_u32(&opt.depth, *argv, 0)) {
92
fprintf(stderr, "Illegal \"flows\"\n");
96
} else if (strcmp(*argv, "headdrop") == 0) {
99
} else if (strcmp(*argv, "redflowlimit") == 0) {
101
if (get_u32(&opt.limit, *argv, 0)) {
102
fprintf(stderr, "Illegal \"redflowlimit\"\n");
106
} else if (strcmp(*argv, "min") == 0) {
108
if (get_u32(&opt.qth_min, *argv, 0)) {
109
fprintf(stderr, "Illegal \"min\"\n");
113
} else if (strcmp(*argv, "max") == 0) {
115
if (get_u32(&opt.qth_max, *argv, 0)) {
116
fprintf(stderr, "Illegal \"max\"\n");
120
} else if (strcmp(*argv, "burst") == 0) {
122
if (get_unsigned(&burst, *argv, 0)) {
123
fprintf(stderr, "Illegal \"burst\"\n");
127
} else if (strcmp(*argv, "avpkt") == 0) {
129
if (get_size(&avpkt, *argv)) {
130
fprintf(stderr, "Illegal \"avpkt\"\n");
134
} else if (strcmp(*argv, "probability") == 0) {
136
if (sscanf(*argv, "%lg", &probability) != 1) {
137
fprintf(stderr, "Illegal \"probability\"\n");
141
} else if (strcmp(*argv, "ecn") == 0) {
142
opt.flags |= TC_RED_ECN;
144
} else if (strcmp(*argv, "harddrop") == 0) {
145
opt.flags |= TC_RED_HARDDROP;
72
147
} else if (strcmp(*argv, "help") == 0) {
159
fprintf(stderr, "Required parameter (redflowlimit) is missing\n");
162
/* Compute default min/max thresholds based on
163
Sally Floyd's recommendations:
164
http://www.icir.org/floyd/REDparameters.txt
167
opt.qth_max = opt.limit / 4;
169
opt.qth_min = opt.qth_max / 3;
171
burst = (2 * opt.qth_min + opt.qth_max) / (3 * avpkt);
173
if (opt.qth_max > opt.limit) {
174
fprintf(stderr, "\"max\" is larger than \"limit\"\n");
178
if (opt.qth_min >= opt.qth_max) {
179
fprintf(stderr, "\"min\" is not smaller than \"max\"\n");
183
wlog = tc_red_eval_ewma(opt.qth_min, burst, avpkt);
185
fprintf(stderr, "SFQ: failed to calculate EWMA constant.\n");
189
fprintf(stderr, "SFQ: WARNING. Burst %u seems to be too large.\n", burst);
192
wlog = tc_red_eval_P(opt.qth_min, opt.qth_max, probability);
194
fprintf(stderr, "SFQ: failed to calculate probability.\n");
198
opt.max_P = probability * pow(2, 32);
84
202
addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt));
88
206
static int sfq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
90
208
struct tc_sfq_qopt *qopt;
209
struct tc_sfq_qopt_v1 *qopt_ext = NULL;
96
216
if (RTA_PAYLOAD(opt) < sizeof(*qopt))
218
if (RTA_PAYLOAD(opt) >= sizeof(*qopt_ext))
219
qopt_ext = RTA_DATA(opt);
98
220
qopt = RTA_DATA(opt);
99
221
fprintf(f, "limit %up ", qopt->limit);
100
222
fprintf(f, "quantum %s ", sprint_size(qopt->quantum, b1));
223
if (qopt_ext && qopt_ext->depth)
224
fprintf(f, "depth %u ", qopt_ext->depth);
225
if (qopt_ext && qopt_ext->headdrop)
226
fprintf(f, "headdrop ");
101
228
if (show_details) {
102
229
fprintf(f, "flows %u/%u ", qopt->flows, qopt->divisor);
104
231
fprintf(f, "divisor %u ", qopt->divisor);
105
232
if (qopt->perturb_period)
106
233
fprintf(f, "perturb %dsec ", qopt->perturb_period);
234
if (qopt_ext && qopt_ext->qth_min) {
235
fprintf(f, "\n ewma %u ", qopt_ext->Wlog);
236
fprintf(f, "min %s max %s probability %g ",
237
sprint_size(qopt_ext->qth_min, b2),
238
sprint_size(qopt_ext->qth_max, b3),
239
qopt_ext->max_P / pow(2, 32));
240
if (qopt_ext->flags & TC_RED_ECN)
243
fprintf(f, "\n prob_mark %u prob_mark_head %u prob_drop %u",
244
qopt_ext->stats.prob_mark,
245
qopt_ext->stats.prob_mark_head,
246
qopt_ext->stats.prob_drop);
247
fprintf(f, "\n forced_mark %u forced_mark_head %u forced_drop %u",
248
qopt_ext->stats.forced_mark,
249
qopt_ext->stats.forced_mark_head,
250
qopt_ext->stats.forced_drop);