2
* lib/route/qdisc/sfq.c SFQ Qdisc
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation version 2.1
9
* Copyright (c) 2003-2011 Thomas Graf <tgraf@suug.ch>
14
* @defgroup qdisc_sfq Stochastic Fairness Queueing (SFQ)
17
* @par Parameter Description
18
* - \b Quantum: Number of bytes to send out per slot and round.
19
* - \b Perturbation: Timer period between changing the hash function.
20
* - \b Limit: Upper limit of queue in number of packets before SFQ starts
22
* - \b Divisor: Hash table divisor, i.e. size of hash table.
26
#include <netlink-local.h>
27
#include <netlink-tc.h>
28
#include <netlink/netlink.h>
29
#include <netlink/utils.h>
30
#include <netlink/route/tc-api.h>
31
#include <netlink/route/qdisc.h>
32
#include <netlink/route/qdisc/sfq.h>
35
#define SCH_SFQ_ATTR_QUANTUM 0x01
36
#define SCH_SFQ_ATTR_PERTURB 0x02
37
#define SCH_SFQ_ATTR_LIMIT 0x04
38
#define SCH_SFQ_ATTR_DIVISOR 0x08
39
#define SCH_SFQ_ATTR_FLOWS 0x10
42
static int sfq_msg_parser(struct rtnl_tc *tc, void *data)
44
struct rtnl_sfq *sfq = data;
45
struct tc_sfq_qopt *opts;
47
if (!(tc->ce_mask & TCA_ATTR_OPTS))
50
if (tc->tc_opts->d_size < sizeof(*opts))
53
opts = (struct tc_sfq_qopt *) tc->tc_opts->d_data;
55
sfq->qs_quantum = opts->quantum;
56
sfq->qs_perturb = opts->perturb_period;
57
sfq->qs_limit = opts->limit;
58
sfq->qs_divisor = opts->divisor;
59
sfq->qs_flows = opts->flows;
61
sfq->qs_mask = (SCH_SFQ_ATTR_QUANTUM | SCH_SFQ_ATTR_PERTURB |
62
SCH_SFQ_ATTR_LIMIT | SCH_SFQ_ATTR_DIVISOR |
68
static void sfq_dump_line(struct rtnl_tc *tc, void *data,
69
struct nl_dump_params *p)
71
struct rtnl_sfq *sfq = data;
74
nl_dump(p, " quantum %u perturb %us", sfq->qs_quantum,
78
static void sfq_dump_details(struct rtnl_tc *tc, void *data,
79
struct nl_dump_params *p)
81
struct rtnl_sfq *sfq = data;
84
nl_dump(p, "limit %u divisor %u",
85
sfq->qs_limit, sfq->qs_divisor);
88
static int sfq_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg)
90
struct rtnl_sfq *sfq = data;
91
struct tc_sfq_qopt opts = {0};
96
opts.quantum = sfq->qs_quantum;
97
opts.perturb_period = sfq->qs_perturb;
98
opts.limit = sfq->qs_limit;
100
return nlmsg_append(msg, &opts, sizeof(opts), NL_DONTPAD);
104
* @name Attribute Access
109
* Set quantum of SFQ qdisc.
110
* @arg qdisc SFQ qdisc to be modified.
111
* @arg quantum New quantum in bytes.
112
* @return 0 on success or a negative error code.
114
void rtnl_sfq_set_quantum(struct rtnl_qdisc *qdisc, int quantum)
116
struct rtnl_sfq *sfq;
118
if (!(sfq = rtnl_tc_data(TC_CAST(qdisc))))
121
sfq->qs_quantum = quantum;
122
sfq->qs_mask |= SCH_SFQ_ATTR_QUANTUM;
126
* Get quantum of SFQ qdisc.
127
* @arg qdisc SFQ qdisc.
128
* @return Quantum in bytes or a negative error code.
130
int rtnl_sfq_get_quantum(struct rtnl_qdisc *qdisc)
132
struct rtnl_sfq *sfq;
134
if (!(sfq = rtnl_tc_data(TC_CAST(qdisc))))
137
if (sfq->qs_mask & SCH_SFQ_ATTR_QUANTUM)
138
return sfq->qs_quantum;
144
* Set limit of SFQ qdisc.
145
* @arg qdisc SFQ qdisc to be modified.
146
* @arg limit New limit in number of packets.
147
* @return 0 on success or a negative error code.
149
void rtnl_sfq_set_limit(struct rtnl_qdisc *qdisc, int limit)
151
struct rtnl_sfq *sfq;
153
if (!(sfq = rtnl_tc_data(TC_CAST(qdisc))))
156
sfq->qs_limit = limit;
157
sfq->qs_mask |= SCH_SFQ_ATTR_LIMIT;
161
* Get limit of SFQ qdisc.
162
* @arg qdisc SFQ qdisc.
163
* @return Limit or a negative error code.
165
int rtnl_sfq_get_limit(struct rtnl_qdisc *qdisc)
167
struct rtnl_sfq *sfq;
169
if (!(sfq = rtnl_tc_data(TC_CAST(qdisc))))
172
if (sfq->qs_mask & SCH_SFQ_ATTR_LIMIT)
173
return sfq->qs_limit;
179
* Set perturbation interval of SFQ qdisc.
180
* @arg qdisc SFQ qdisc to be modified.
181
* @arg perturb New perturbation interval in seconds.
182
* @note A value of 0 disables perturbation altogether.
183
* @return 0 on success or a negative error code.
185
void rtnl_sfq_set_perturb(struct rtnl_qdisc *qdisc, int perturb)
187
struct rtnl_sfq *sfq;
189
if (!(sfq = rtnl_tc_data(TC_CAST(qdisc))))
192
sfq->qs_perturb = perturb;
193
sfq->qs_mask |= SCH_SFQ_ATTR_PERTURB;
197
* Get perturbation interval of SFQ qdisc.
198
* @arg qdisc SFQ qdisc.
199
* @return Perturbation interval in seconds or a negative error code.
201
int rtnl_sfq_get_perturb(struct rtnl_qdisc *qdisc)
203
struct rtnl_sfq *sfq;
205
if (!(sfq = rtnl_tc_data(TC_CAST(qdisc))))
208
if (sfq->qs_mask & SCH_SFQ_ATTR_PERTURB)
209
return sfq->qs_perturb;
215
* Get divisor of SFQ qdisc.
216
* @arg qdisc SFQ qdisc.
217
* @return Divisor in number of entries or a negative error code.
219
int rtnl_sfq_get_divisor(struct rtnl_qdisc *qdisc)
221
struct rtnl_sfq *sfq;
223
if (!(sfq = rtnl_tc_data(TC_CAST(qdisc))))
226
if (sfq->qs_mask & SCH_SFQ_ATTR_DIVISOR)
227
return sfq->qs_divisor;
234
static struct rtnl_tc_ops sfq_ops = {
236
.to_type = RTNL_TC_TYPE_QDISC,
237
.to_size = sizeof(struct rtnl_sfq),
238
.to_msg_parser = sfq_msg_parser,
240
[NL_DUMP_LINE] = sfq_dump_line,
241
[NL_DUMP_DETAILS] = sfq_dump_details,
243
.to_msg_fill = sfq_msg_fill,
246
static void __init sfq_init(void)
248
rtnl_tc_register(&sfq_ops);
251
static void __exit sfq_exit(void)
253
rtnl_tc_unregister(&sfq_ops);