sch_netem.c 15.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6
/*
 * net/sched/sch_netem.c	Network emulator
 *
 * 		This program is free software; you can redistribute it and/or
 * 		modify it under the terms of the GNU General Public License
 * 		as published by the Free Software Foundation; either version
7
 * 		2 of the License.
L
Linus Torvalds 已提交
8 9
 *
 *  		Many of the algorithms and ideas for this came from
10
 *		NIST Net which is not copyrighted.
L
Linus Torvalds 已提交
11 12 13 14 15 16
 *
 * Authors:	Stephen Hemminger <shemminger@osdl.org>
 *		Catalin(ux aka Dino) BOIE <catab at umbrella dot ro>
 */

#include <linux/module.h>
17
#include <linux/slab.h>
L
Linus Torvalds 已提交
18 19 20 21 22 23
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/skbuff.h>
#include <linux/rtnetlink.h>

24
#include <net/netlink.h>
L
Linus Torvalds 已提交
25 26
#include <net/pkt_sched.h>

27
#define VERSION "1.2"
S
Stephen Hemminger 已提交
28

L
Linus Torvalds 已提交
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
/*	Network Emulation Queuing algorithm.
	====================================

	Sources: [1] Mark Carson, Darrin Santay, "NIST Net - A Linux-based
		 Network Emulation Tool
		 [2] Luigi Rizzo, DummyNet for FreeBSD

	 ----------------------------------------------------------------

	 This started out as a simple way to delay outgoing packets to
	 test TCP but has grown to include most of the functionality
	 of a full blown network emulator like NISTnet. It can delay
	 packets and add random jitter (and correlation). The random
	 distribution can be loaded from a table as well to provide
	 normal, Pareto, or experimental curves. Packet loss,
	 duplication, and reordering can also be emulated.

	 This qdisc does not do classification that can be handled in
	 layering other disciplines.  It does not need to do bandwidth
	 control either since that can be handled by using token
	 bucket or other rate control.
*/

struct netem_sched_data {
	struct Qdisc	*qdisc;
54
	struct qdisc_watchdog watchdog;
L
Linus Torvalds 已提交
55

56 57 58
	psched_tdiff_t latency;
	psched_tdiff_t jitter;

L
Linus Torvalds 已提交
59 60 61 62 63
	u32 loss;
	u32 limit;
	u32 counter;
	u32 gap;
	u32 duplicate;
64
	u32 reorder;
65
	u32 corrupt;
L
Linus Torvalds 已提交
66 67

	struct crndstate {
68 69
		u32 last;
		u32 rho;
70
	} delay_cor, loss_cor, dup_cor, reorder_cor, corrupt_cor;
L
Linus Torvalds 已提交
71 72 73 74 75 76 77 78 79 80 81 82

	struct disttable {
		u32  size;
		s16 table[0];
	} *delay_dist;
};

/* Time stamp put into socket buffer control block */
struct netem_skb_cb {
	psched_time_t	time_to_send;
};

83 84
static inline struct netem_skb_cb *netem_skb_cb(struct sk_buff *skb)
{
85 86 87
	BUILD_BUG_ON(sizeof(skb->cb) <
		sizeof(struct qdisc_skb_cb) + sizeof(struct netem_skb_cb));
	return (struct netem_skb_cb *)qdisc_skb_cb(skb)->data;
88 89
}

L
Linus Torvalds 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102
/* init_crandom - initialize correlated random number generator
 * Use entropy source for initial seed.
 */
static void init_crandom(struct crndstate *state, unsigned long rho)
{
	state->rho = rho;
	state->last = net_random();
}

/* get_crandom - correlated random number generator
 * Next number depends on last value.
 * rho is scaled to avoid floating point.
 */
103
static u32 get_crandom(struct crndstate *state)
L
Linus Torvalds 已提交
104 105 106 107
{
	u64 value, rho;
	unsigned long answer;

S
Stephen Hemminger 已提交
108
	if (state->rho == 0)	/* no correlation */
L
Linus Torvalds 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121
		return net_random();

	value = net_random();
	rho = (u64)state->rho + 1;
	answer = (value * ((1ull<<32) - rho) + state->last * rho) >> 32;
	state->last = answer;
	return answer;
}

/* tabledist - return a pseudo-randomly distributed value with mean mu and
 * std deviation sigma.  Uses table lookup to approximate the desired
 * distribution, and a uniformly-distributed pseudo-random source.
 */
122 123 124
static psched_tdiff_t tabledist(psched_tdiff_t mu, psched_tdiff_t sigma,
				struct crndstate *state,
				const struct disttable *dist)
L
Linus Torvalds 已提交
125
{
126 127 128
	psched_tdiff_t x;
	long t;
	u32 rnd;
L
Linus Torvalds 已提交
129 130 131 132 133 134 135

	if (sigma == 0)
		return mu;

	rnd = get_crandom(state);

	/* default uniform distribution */
136
	if (dist == NULL)
L
Linus Torvalds 已提交
137 138 139 140 141 142 143 144 145 146 147 148
		return (rnd % (2*sigma)) - sigma + mu;

	t = dist->table[rnd % dist->size];
	x = (sigma % NETEM_DIST_SCALE) * t;
	if (x >= 0)
		x += NETEM_DIST_SCALE/2;
	else
		x -= NETEM_DIST_SCALE/2;

	return  x / NETEM_DIST_SCALE + (sigma / NETEM_DIST_SCALE) * t + mu;
}

149 150 151 152 153 154
/*
 * Insert one skb into qdisc.
 * Note: parent depends on return value to account for queue length.
 * 	NET_XMIT_DROP: queue length didn't change.
 *      NET_XMIT_SUCCESS: one skb was queued.
 */
L
Linus Torvalds 已提交
155 156 157
static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch)
{
	struct netem_sched_data *q = qdisc_priv(sch);
158 159
	/* We don't fill cb now as skb_unshare() may invalidate it */
	struct netem_skb_cb *cb;
160
	struct sk_buff *skb2;
L
Linus Torvalds 已提交
161
	int ret;
162
	int count = 1;
L
Linus Torvalds 已提交
163

164
	pr_debug("netem_enqueue skb=%p\n", skb);
L
Linus Torvalds 已提交
165

166 167 168 169
	/* Random duplication */
	if (q->duplicate && q->duplicate >= get_crandom(&q->dup_cor))
		++count;

L
Linus Torvalds 已提交
170
	/* Random packet drop 0 => none, ~0 => all */
171 172 173 174
	if (q->loss && q->loss >= get_crandom(&q->loss_cor))
		--count;

	if (count == 0) {
L
Linus Torvalds 已提交
175 176
		sch->qstats.drops++;
		kfree_skb(skb);
177
		return NET_XMIT_SUCCESS | __NET_XMIT_BYPASS;
L
Linus Torvalds 已提交
178 179
	}

180 181
	skb_orphan(skb);

182 183 184 185 186 187
	/*
	 * If we need to duplicate packet, then re-insert at top of the
	 * qdisc tree, since parent queuer expects that only one
	 * skb will be queued.
	 */
	if (count > 1 && (skb2 = skb_clone(skb, GFP_ATOMIC)) != NULL) {
188
		struct Qdisc *rootq = qdisc_root(sch);
189 190 191
		u32 dupsave = q->duplicate; /* prevent duplicating a dup... */
		q->duplicate = 0;

192
		qdisc_enqueue_root(skb2, rootq);
193
		q->duplicate = dupsave;
L
Linus Torvalds 已提交
194 195
	}

196 197 198 199 200 201 202
	/*
	 * Randomized packet corruption.
	 * Make copy if needed since we are modifying
	 * If packet is going to be hardware checksummed, then
	 * do it now in software before we mangle it.
	 */
	if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor)) {
203 204 205
		if (!(skb = skb_unshare(skb, GFP_ATOMIC)) ||
		    (skb->ip_summed == CHECKSUM_PARTIAL &&
		     skb_checksum_help(skb))) {
206 207 208 209 210 211 212
			sch->qstats.drops++;
			return NET_XMIT_DROP;
		}

		skb->data[net_random() % skb_headlen(skb)] ^= 1<<(net_random() % 8);
	}

213
	cb = netem_skb_cb(skb);
E
Eric Dumazet 已提交
214 215
	if (q->gap == 0 ||		/* not doing reordering */
	    q->counter < q->gap ||	/* inside last reordering gap */
216
	    q->reorder < get_crandom(&q->reorder_cor)) {
217
		psched_time_t now;
S
Stephen Hemminger 已提交
218 219 220 221 222
		psched_tdiff_t delay;

		delay = tabledist(q->latency, q->jitter,
				  &q->delay_cor, q->delay_dist);

223
		now = psched_get_time();
224
		cb->time_to_send = now + delay;
L
Linus Torvalds 已提交
225
		++q->counter;
226
		ret = qdisc_enqueue(skb, q->qdisc);
L
Linus Torvalds 已提交
227
	} else {
228
		/*
229 230 231
		 * Do re-ordering by putting one out of N packets at the front
		 * of the queue.
		 */
232
		cb->time_to_send = psched_get_time();
233
		q->counter = 0;
234 235 236 237 238

		__skb_queue_head(&q->qdisc->q, skb);
		q->qdisc->qstats.backlog += qdisc_pkt_len(skb);
		q->qdisc->qstats.requeues++;
		ret = NET_XMIT_SUCCESS;
L
Linus Torvalds 已提交
239 240 241 242
	}

	if (likely(ret == NET_XMIT_SUCCESS)) {
		sch->q.qlen++;
243
	} else if (net_xmit_drop_count(ret)) {
L
Linus Torvalds 已提交
244
		sch->qstats.drops++;
245
	}
L
Linus Torvalds 已提交
246

247
	pr_debug("netem: enqueue ret %d\n", ret);
L
Linus Torvalds 已提交
248 249 250
	return ret;
}

E
Eric Dumazet 已提交
251
static unsigned int netem_drop(struct Qdisc *sch)
L
Linus Torvalds 已提交
252 253
{
	struct netem_sched_data *q = qdisc_priv(sch);
254
	unsigned int len = 0;
L
Linus Torvalds 已提交
255

256
	if (q->qdisc->ops->drop && (len = q->qdisc->ops->drop(q->qdisc)) != 0) {
L
Linus Torvalds 已提交
257 258 259 260 261 262 263 264 265 266 267
		sch->q.qlen--;
		sch->qstats.drops++;
	}
	return len;
}

static struct sk_buff *netem_dequeue(struct Qdisc *sch)
{
	struct netem_sched_data *q = qdisc_priv(sch);
	struct sk_buff *skb;

268
	if (qdisc_is_throttled(sch))
269 270
		return NULL;

271
	skb = q->qdisc->ops->peek(q->qdisc);
272
	if (skb) {
273
		const struct netem_skb_cb *cb = netem_skb_cb(skb);
274
		psched_time_t now = psched_get_time();
275 276

		/* if more time remaining? */
P
Patrick McHardy 已提交
277
		if (cb->time_to_send <= now) {
278 279
			skb = qdisc_dequeue_peeked(q->qdisc);
			if (unlikely(!skb))
280 281
				return NULL;

282 283 284 285 286 287 288 289
#ifdef CONFIG_NET_CLS_ACT
			/*
			 * If it's at ingress let's pretend the delay is
			 * from the network (tstamp will be updated).
			 */
			if (G_TC_FROM(skb->tc_verd) & AT_INGRESS)
				skb->tstamp.tv64 = 0;
#endif
290
			pr_debug("netem_dequeue: return skb=%p\n", skb);
291
			qdisc_bstats_update(sch, skb);
292 293
			sch->q.qlen--;
			return skb;
S
Stephen Hemminger 已提交
294
		}
295 296

		qdisc_watchdog_schedule(&q->watchdog, cb->time_to_send);
297 298 299
	}

	return NULL;
L
Linus Torvalds 已提交
300 301 302 303 304 305 306 307
}

static void netem_reset(struct Qdisc *sch)
{
	struct netem_sched_data *q = qdisc_priv(sch);

	qdisc_reset(q->qdisc);
	sch->q.qlen = 0;
308
	qdisc_watchdog_cancel(&q->watchdog);
L
Linus Torvalds 已提交
309 310 311 312 313 314
}

/*
 * Distribution data is a variable size payload containing
 * signed 16 bit values.
 */
315
static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
L
Linus Torvalds 已提交
316 317
{
	struct netem_sched_data *q = qdisc_priv(sch);
318 319
	unsigned long n = nla_len(attr)/sizeof(__s16);
	const __s16 *data = nla_data(attr);
320
	spinlock_t *root_lock;
L
Linus Torvalds 已提交
321 322 323 324 325 326 327 328 329 330 331 332 333
	struct disttable *d;
	int i;

	if (n > 65536)
		return -EINVAL;

	d = kmalloc(sizeof(*d) + n*sizeof(d->table[0]), GFP_KERNEL);
	if (!d)
		return -ENOMEM;

	d->size = n;
	for (i = 0; i < n; i++)
		d->table[i] = data[i];
334

335
	root_lock = qdisc_root_sleeping_lock(sch);
336 337

	spin_lock_bh(root_lock);
338 339
	kfree(q->delay_dist);
	q->delay_dist = d;
340
	spin_unlock_bh(root_lock);
L
Linus Torvalds 已提交
341 342 343
	return 0;
}

344
static void get_correlation(struct Qdisc *sch, const struct nlattr *attr)
L
Linus Torvalds 已提交
345 346
{
	struct netem_sched_data *q = qdisc_priv(sch);
347
	const struct tc_netem_corr *c = nla_data(attr);
L
Linus Torvalds 已提交
348 349 350 351 352 353

	init_crandom(&q->delay_cor, c->delay_corr);
	init_crandom(&q->loss_cor, c->loss_corr);
	init_crandom(&q->dup_cor, c->dup_corr);
}

354
static void get_reorder(struct Qdisc *sch, const struct nlattr *attr)
355 356
{
	struct netem_sched_data *q = qdisc_priv(sch);
357
	const struct tc_netem_reorder *r = nla_data(attr);
358 359 360 361 362

	q->reorder = r->probability;
	init_crandom(&q->reorder_cor, r->correlation);
}

363
static void get_corrupt(struct Qdisc *sch, const struct nlattr *attr)
364 365
{
	struct netem_sched_data *q = qdisc_priv(sch);
366
	const struct tc_netem_corrupt *r = nla_data(attr);
367 368 369 370 371

	q->corrupt = r->probability;
	init_crandom(&q->corrupt_cor, r->correlation);
}

372 373 374 375 376 377
static const struct nla_policy netem_policy[TCA_NETEM_MAX + 1] = {
	[TCA_NETEM_CORR]	= { .len = sizeof(struct tc_netem_corr) },
	[TCA_NETEM_REORDER]	= { .len = sizeof(struct tc_netem_reorder) },
	[TCA_NETEM_CORRUPT]	= { .len = sizeof(struct tc_netem_corrupt) },
};

378 379 380 381 382 383 384 385 386 387 388 389 390 391
static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla,
		      const struct nla_policy *policy, int len)
{
	int nested_len = nla_len(nla) - NLA_ALIGN(len);

	if (nested_len < 0)
		return -EINVAL;
	if (nested_len >= nla_attr_size(0))
		return nla_parse(tb, maxtype, nla_data(nla) + NLA_ALIGN(len),
				 nested_len, policy);
	memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));
	return 0;
}

392
/* Parse netlink message to set options */
393
static int netem_change(struct Qdisc *sch, struct nlattr *opt)
L
Linus Torvalds 已提交
394 395
{
	struct netem_sched_data *q = qdisc_priv(sch);
396
	struct nlattr *tb[TCA_NETEM_MAX + 1];
L
Linus Torvalds 已提交
397 398
	struct tc_netem_qopt *qopt;
	int ret;
399

400
	if (opt == NULL)
L
Linus Torvalds 已提交
401 402
		return -EINVAL;

403 404
	qopt = nla_data(opt);
	ret = parse_attr(tb, TCA_NETEM_MAX, opt, netem_policy, sizeof(*qopt));
405 406 407
	if (ret < 0)
		return ret;

408
	ret = fifo_set_limit(q->qdisc, qopt->limit);
L
Linus Torvalds 已提交
409 410 411 412
	if (ret) {
		pr_debug("netem: can't set fifo limit\n");
		return ret;
	}
413

L
Linus Torvalds 已提交
414 415 416 417
	q->latency = qopt->latency;
	q->jitter = qopt->jitter;
	q->limit = qopt->limit;
	q->gap = qopt->gap;
418
	q->counter = 0;
L
Linus Torvalds 已提交
419 420 421
	q->loss = qopt->loss;
	q->duplicate = qopt->duplicate;

S
Stephen Hemminger 已提交
422 423
	/* for compatibility with earlier versions.
	 * if gap is set, need to assume 100% probability
424
	 */
425 426
	if (q->gap)
		q->reorder = ~0;
427

428 429
	if (tb[TCA_NETEM_CORR])
		get_correlation(sch, tb[TCA_NETEM_CORR]);
L
Linus Torvalds 已提交
430

431 432 433 434 435
	if (tb[TCA_NETEM_DELAY_DIST]) {
		ret = get_dist_table(sch, tb[TCA_NETEM_DELAY_DIST]);
		if (ret)
			return ret;
	}
436

437 438
	if (tb[TCA_NETEM_REORDER])
		get_reorder(sch, tb[TCA_NETEM_REORDER]);
L
Linus Torvalds 已提交
439

440 441
	if (tb[TCA_NETEM_CORRUPT])
		get_corrupt(sch, tb[TCA_NETEM_CORRUPT]);
L
Linus Torvalds 已提交
442 443 444 445

	return 0;
}

446 447 448 449 450 451
/*
 * Special case version of FIFO queue for use by netem.
 * It queues in order based on timestamps in skb's
 */
struct fifo_sched_data {
	u32 limit;
S
Stephen Hemminger 已提交
452
	psched_time_t oldest;
453 454 455 456 457 458
};

static int tfifo_enqueue(struct sk_buff *nskb, struct Qdisc *sch)
{
	struct fifo_sched_data *q = qdisc_priv(sch);
	struct sk_buff_head *list = &sch->q;
459
	psched_time_t tnext = netem_skb_cb(nskb)->time_to_send;
460 461 462
	struct sk_buff *skb;

	if (likely(skb_queue_len(list) < q->limit)) {
S
Stephen Hemminger 已提交
463
		/* Optimize for add at tail */
P
Patrick McHardy 已提交
464
		if (likely(skb_queue_empty(list) || tnext >= q->oldest)) {
S
Stephen Hemminger 已提交
465 466 467 468
			q->oldest = tnext;
			return qdisc_enqueue_tail(nskb, sch);
		}

469
		skb_queue_reverse_walk(list, skb) {
470
			const struct netem_skb_cb *cb = netem_skb_cb(skb);
471

P
Patrick McHardy 已提交
472
			if (tnext >= cb->time_to_send)
473 474 475 476 477
				break;
		}

		__skb_queue_after(list, skb, nskb);

478
		sch->qstats.backlog += qdisc_pkt_len(nskb);
479 480 481 482

		return NET_XMIT_SUCCESS;
	}

S
Stephen Hemminger 已提交
483
	return qdisc_reshape_fail(nskb, sch);
484 485
}

486
static int tfifo_init(struct Qdisc *sch, struct nlattr *opt)
487 488 489 490
{
	struct fifo_sched_data *q = qdisc_priv(sch);

	if (opt) {
491 492
		struct tc_fifo_qopt *ctl = nla_data(opt);
		if (nla_len(opt) < sizeof(*ctl))
493 494 495 496
			return -EINVAL;

		q->limit = ctl->limit;
	} else
497
		q->limit = max_t(u32, qdisc_dev(sch)->tx_queue_len, 1);
498

499
	q->oldest = PSCHED_PASTPERFECT;
500 501 502 503 504 505 506 507
	return 0;
}

static int tfifo_dump(struct Qdisc *sch, struct sk_buff *skb)
{
	struct fifo_sched_data *q = qdisc_priv(sch);
	struct tc_fifo_qopt opt = { .limit = q->limit };

508
	NLA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
509 510
	return skb->len;

511
nla_put_failure:
512 513 514
	return -1;
}

515
static struct Qdisc_ops tfifo_qdisc_ops __read_mostly = {
516 517 518 519
	.id		=	"tfifo",
	.priv_size	=	sizeof(struct fifo_sched_data),
	.enqueue	=	tfifo_enqueue,
	.dequeue	=	qdisc_dequeue_head,
520
	.peek		=	qdisc_peek_head,
521 522 523 524 525 526 527
	.drop		=	qdisc_queue_drop,
	.init		=	tfifo_init,
	.reset		=	qdisc_reset_queue,
	.change		=	tfifo_init,
	.dump		=	tfifo_dump,
};

528
static int netem_init(struct Qdisc *sch, struct nlattr *opt)
L
Linus Torvalds 已提交
529 530 531 532 533 534 535
{
	struct netem_sched_data *q = qdisc_priv(sch);
	int ret;

	if (!opt)
		return -EINVAL;

536
	qdisc_watchdog_init(&q->watchdog, sch);
L
Linus Torvalds 已提交
537

538
	q->qdisc = qdisc_create_dflt(sch->dev_queue, &tfifo_qdisc_ops,
539
				     TC_H_MAKE(sch->handle, 1));
L
Linus Torvalds 已提交
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
	if (!q->qdisc) {
		pr_debug("netem: qdisc create failed\n");
		return -ENOMEM;
	}

	ret = netem_change(sch, opt);
	if (ret) {
		pr_debug("netem: change failed\n");
		qdisc_destroy(q->qdisc);
	}
	return ret;
}

static void netem_destroy(struct Qdisc *sch)
{
	struct netem_sched_data *q = qdisc_priv(sch);

557
	qdisc_watchdog_cancel(&q->watchdog);
L
Linus Torvalds 已提交
558 559 560 561 562 563 564
	qdisc_destroy(q->qdisc);
	kfree(q->delay_dist);
}

static int netem_dump(struct Qdisc *sch, struct sk_buff *skb)
{
	const struct netem_sched_data *q = qdisc_priv(sch);
S
stephen hemminger 已提交
565
	struct nlattr *nla = (struct nlattr *) skb_tail_pointer(skb);
L
Linus Torvalds 已提交
566 567
	struct tc_netem_qopt qopt;
	struct tc_netem_corr cor;
568
	struct tc_netem_reorder reorder;
569
	struct tc_netem_corrupt corrupt;
L
Linus Torvalds 已提交
570 571 572 573 574 575 576

	qopt.latency = q->latency;
	qopt.jitter = q->jitter;
	qopt.limit = q->limit;
	qopt.loss = q->loss;
	qopt.gap = q->gap;
	qopt.duplicate = q->duplicate;
577
	NLA_PUT(skb, TCA_OPTIONS, sizeof(qopt), &qopt);
L
Linus Torvalds 已提交
578 579 580 581

	cor.delay_corr = q->delay_cor.rho;
	cor.loss_corr = q->loss_cor.rho;
	cor.dup_corr = q->dup_cor.rho;
582
	NLA_PUT(skb, TCA_NETEM_CORR, sizeof(cor), &cor);
583 584 585

	reorder.probability = q->reorder;
	reorder.correlation = q->reorder_cor.rho;
586
	NLA_PUT(skb, TCA_NETEM_REORDER, sizeof(reorder), &reorder);
587

588 589
	corrupt.probability = q->corrupt;
	corrupt.correlation = q->corrupt_cor.rho;
590
	NLA_PUT(skb, TCA_NETEM_CORRUPT, sizeof(corrupt), &corrupt);
591

S
stephen hemminger 已提交
592
	return nla_nest_end(skb, nla);
L
Linus Torvalds 已提交
593

594
nla_put_failure:
S
stephen hemminger 已提交
595
	nlmsg_trim(skb, nla);
L
Linus Torvalds 已提交
596 597 598
	return -1;
}

599
static struct Qdisc_ops netem_qdisc_ops __read_mostly = {
L
Linus Torvalds 已提交
600 601 602 603
	.id		=	"netem",
	.priv_size	=	sizeof(struct netem_sched_data),
	.enqueue	=	netem_enqueue,
	.dequeue	=	netem_dequeue,
604
	.peek		=	qdisc_peek_dequeued,
L
Linus Torvalds 已提交
605 606 607 608 609 610 611 612 613 614 615 616
	.drop		=	netem_drop,
	.init		=	netem_init,
	.reset		=	netem_reset,
	.destroy	=	netem_destroy,
	.change		=	netem_change,
	.dump		=	netem_dump,
	.owner		=	THIS_MODULE,
};


static int __init netem_module_init(void)
{
S
Stephen Hemminger 已提交
617
	pr_info("netem: version " VERSION "\n");
L
Linus Torvalds 已提交
618 619 620 621 622 623 624 625 626
	return register_qdisc(&netem_qdisc_ops);
}
static void __exit netem_module_exit(void)
{
	unregister_qdisc(&netem_qdisc_ops);
}
module_init(netem_module_init)
module_exit(netem_module_exit)
MODULE_LICENSE("GPL");