-
Notifications
You must be signed in to change notification settings - Fork 2
/
blue_csc573.c
271 lines (236 loc) · 6.9 KB
/
blue_csc573.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
* net/sched/sch_blue.c Random Early Detection queue.
*
* This program is free software; you can blueistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
*
* Changes:
* J Hadi Salim 980914: computation fixes
* Alexey Makarenko <makar@phoenix.kharkov.ua> 990814: qave on idle link was calculated incorrectly.
* J Hadi Salim 980816: ECN support
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <net/pkt_sched.h>
#include <net/inet_ecn.h>
#include <net/blue.h>
/* Parameters, settable by user:
-----------------------------
limit - bytes (must be > qth_max + burst)
Hard limit on queue length, should be chosen >qth_max
to allow packet bursts. This parameter does not
affect the algorithms behaviour and can be chosen
arbitrarily high (well, less than ram size)
Really, this limit will never be reached
if BLUE works correctly.
*/
struct blue_sched_data {
u32 limit; /* HARD maximal queue length */
unsigned char flags;
struct timer_list adapt_timer;
struct blue_parms parms;
struct blue_vars vars;
struct blue_stats stats;
struct Qdisc *qdisc;
};
static inline int blue_use_ecn(struct blue_sched_data *q)
{
return q->flags & TC_BLUE_ECN;
}
static inline int blue_use_harddrop(struct blue_sched_data *q)
{
return q->flags & TC_BLUE_HARDDROP;
}
static int blue_enqueue(struct sk_buff *skb, struct Qdisc *sch)
{
struct blue_sched_data *q = qdisc_priv(sch);
struct Qdisc *child = q->qdisc;
int ret;
//need to implement blue enqueue
}
static struct sk_buff *blue_dequeue(struct Qdisc *sch)
{
struct sk_buff *skb;
struct blue_sched_data *q = qdisc_priv(sch);
struct Qdisc *child = q->qdisc;
//need to implement blue dequeue
}
//this should be the same function as red, so no need to change.
static struct sk_buff *blue_peek(struct Qdisc *sch)
{
struct blue_sched_data *q = qdisc_priv(sch);
struct Qdisc *child = q->qdisc;
return child->ops->peek(child);
}
static unsigned int blue_drop(struct Qdisc *sch)
{
struct blue_sched_data *q = qdisc_priv(sch);
struct Qdisc *child = q->qdisc;
unsigned int len;
//the drop mechanism is different, need to implement drop function.
}
//No need to change
static void blue_reset(struct Qdisc *sch)
{
struct blue_sched_data *q = qdisc_priv(sch);
qdisc_reset(q->qdisc);
sch->q.qlen = 0;
blue_restart(&q->vars);
}
//So far i don't see the point of changing this.
static void blue_destroy(struct Qdisc *sch)
{
struct blue_sched_data *q = qdisc_priv(sch);
del_timer_sync(&q->adapt_timer);
qdisc_destroy(q->qdisc);
}
static const struct nla_policy blue_policy[TCA_BLUE_MAX + 1] = {
[TCA_BLUE_PARMS] = { .len = sizeof(struct tc_blue_qopt) },
[TCA_BLUE_STAB] = { .len = BLUE_STAB_SIZE },
[TCA_BLUE_MAX_P] = { .type = NLA_U32 },
};
static int blue_change(struct Qdisc *sch, struct nlattr *opt)
{
struct blue_sched_data *q = qdisc_priv(sch);
struct nlattr *tb[TCA_BLUE_MAX + 1];
struct tc_blue_qopt *ctl;
struct Qdisc *child = NULL;
int err;
u32 max_P;
//need to implement blue change, this is pretty complicated.
}
//Not sure how this worked in blue,
static inline void blue_adaptative_timer(unsigned long arg)
{
struct Qdisc *sch = (struct Qdisc *)arg;
struct blue_sched_data *q = qdisc_priv(sch);
spinlock_t *root_lock = qdisc_lock(qdisc_root_sleeping(sch));
// need to implement this, or may be we don't need this function.
}
static int blue_init(struct Qdisc *sch, struct nlattr *opt)
{
struct blue_sched_data *q = qdisc_priv(sch);
q->qdisc = &noop_qdisc;
setup_timer(&q->adapt_timer, blue_adaptative_timer, (unsigned long)sch);
return blue_change(sch, opt);
}
// We should be able to use this function, or may be we need to change something.
static int blue_dump(struct Qdisc *sch, struct sk_buff *skb)
{
struct blue_sched_data *q = qdisc_priv(sch);
struct nlattr *opts = NULL;
struct tc_blue_qopt opt = {
.limit = q->limit,
.flags = q->flags,
.qth_min = q->parms.qth_min >> q->parms.Wlog,
.qth_max = q->parms.qth_max >> q->parms.Wlog,
.Wlog = q->parms.Wlog,
.Plog = q->parms.Plog,
.Scell_log = q->parms.Scell_log,
};
sch->qstats.backlog = q->qdisc->qstats.backlog;
opts = nla_nest_start(skb, TCA_OPTIONS);
if (opts == NULL)
goto nla_put_failure;
if (nla_put(skb, TCA_BLUE_PARMS, sizeof(opt), &opt) ||
nla_put_u32(skb, TCA_BLUE_MAX_P, q->parms.max_P))
goto nla_put_failure;
return nla_nest_end(skb, opts);
nla_put_failure:
nla_nest_cancel(skb, opts);
return -EMSGSIZE;
}
static int blue_dump_stats(struct Qdisc *sch, struct gnet_dump *d)
{
struct blue_sched_data *q = qdisc_priv(sch);
struct tc_blue_xstats st = {
.early = q->stats.prob_drop + q->stats.forced_drop,
.pdrop = q->stats.pdrop,
.other = q->stats.other,
.marked = q->stats.prob_mark + q->stats.forced_mark,
};
return gnet_stats_copy_app(d, &st, sizeof(st));
}
//We should be able to use this.
static int blue_dump_class(struct Qdisc *sch, unsigned long cl,
struct sk_buff *skb, struct tcmsg *tcm)
{
struct blue_sched_data *q = qdisc_priv(sch);
tcm->tcm_handle |= TC_H_MIN(1);
tcm->tcm_info = q->qdisc->handle;
return 0;
}
static int blue_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
struct Qdisc **old)
{
struct blue_sched_data *q = qdisc_priv(sch);
// need to implement this
}
//no need to change.
static struct Qdisc *blue_leaf(struct Qdisc *sch, unsigned long arg)
{
struct blue_sched_data *q = qdisc_priv(sch);
return q->qdisc;
}
// no need to change
static unsigned long blue_get(struct Qdisc *sch, u32 classid)
{
return 1;
}
//no need to change
static void blue_put(struct Qdisc *sch, unsigned long arg)
{
}
//I don't quite understand how this works at this moment, but i don't think we need to change it.
static void blue_walk(struct Qdisc *sch, struct qdisc_walker *walker)
{
if (!walker->stop) {
if (walker->count >= walker->skip)
if (walker->fn(sch, 1, walker) < 0) {
walker->stop = 1;
return;
}
walker->count++;
}
}
static const struct Qdisc_class_ops blue_class_ops = {
.graft = blue_graft,
.leaf = blue_leaf,
.get = blue_get,
.put = blue_put,
.walk = blue_walk,
.dump = blue_dump_class,
};
static struct Qdisc_ops blue_qdisc_ops __read_mostly = {
.id = "blue",
.priv_size = sizeof(struct blue_sched_data),
.cl_ops = &blue_class_ops,
.enqueue = blue_enqueue,
.dequeue = blue_dequeue,
.peek = blue_peek,
.drop = blue_drop,
.init = blue_init,
.reset = blue_reset,
.destroy = blue_destroy,
.change = blue_change,
.dump = blue_dump,
.dump_stats = blue_dump_stats,
.owner = THIS_MODULE,
};
static int __init blue_module_init(void)
{
return register_qdisc(&blue_qdisc_ops);
}
static void __exit blue_module_exit(void)
{
unregister_qdisc(&blue_qdisc_ops);
}
module_init(blue_module_init)
module_exit(blue_module_exit)
MODULE_LICENSE("GPL");