freebsd-dev/sys/netinet/ipfw/test/test_dn_sched.c

90 lines
1.6 KiB
C
Raw Normal View History

Bring in the most recent version of ipfw and dummynet, developed and tested over the past two months in the ipfw3-head branch. This also happens to be the same code available in the Linux and Windows ports of ipfw and dummynet. The major enhancement is a completely restructured version of dummynet, with support for different packet scheduling algorithms (loadable at runtime), faster queue/pipe lookup, and a much cleaner internal architecture and kernel/userland ABI which simplifies future extensions. In addition to the existing schedulers (FIFO and WF2Q+), we include a Deficit Round Robin (DRR or RR for brevity) scheduler, and a new, very fast version of WF2Q+ called QFQ. Some test code is also present (in sys/netinet/ipfw/test) that lets you build and test schedulers in userland. Also, we have added a compatibility layer that understands requests from the RELENG_7 and RELENG_8 versions of the /sbin/ipfw binaries, and replies correctly (at least, it does its best; sometimes you just cannot tell who sent the request and how to answer). The compatibility layer should make it possible to MFC this code in a relatively short time. Some minor glitches (e.g. handling of ipfw set enable/disable, and a workaround for a bug in RELENG_7's /sbin/ipfw) will be fixed with separate commits. CREDITS: This work has been partly supported by the ONELAB2 project, and mostly developed by Riccardo Panicucci and myself. The code for the qfq scheduler is mostly from Fabio Checconi, and Marta Carbone and Francesco Magno have helped with testing, debugging and some bug fixes.
2010-03-02 17:40:48 +00:00
/*
* $FreeBSD$
*
* library functions for userland testing of dummynet schedulers
*/
#include "dn_test.h"
void
m_freem(struct mbuf *m)
{
printf("free %p\n", m);
}
int
dn_sched_modevent(module_t mod, int cmd, void *arg)
{
return 0;
}
void
dn_free_pkts(struct mbuf *m)
{
struct mbuf *x;
while ( (x = m) ) {
m = m->m_nextpkt;
m_freem(x);
}
}
int
dn_delete_queue(void *_q, void *do_free)
{
struct dn_queue *q = _q;
if (q->mq.head)
dn_free_pkts(q->mq.head);
free(q);
return 0;
}
/*
* This is a simplified function for testing purposes, which does
* not implement statistics or random loss.
* Enqueue a packet in q, subject to space and queue management policy
* (whose parameters are in q->fs).
* Update stats for the queue and the scheduler.
* Return 0 on success, 1 on drop. The packet is consumed anyways.
*/
int
dn_enqueue(struct dn_queue *q, struct mbuf* m, int drop)
{
if (drop)
goto drop;
if (q->ni.length >= 200)
goto drop;
mq_append(&q->mq, m);
q->ni.length++;
q->ni.tot_bytes += m->m_pkthdr.len;
return 0;
drop:
q->ni.drops++;
return 1;
}
int
ipdn_bound_var(int *v, int dflt, int lo, int hi, const char *msg)
{
if (*v < lo) {
*v = dflt;
} else if (*v > hi) {
*v = hi;
}
return *v;
}
2010-03-04 21:52:40 +00:00
#ifndef __FreeBSD__
int
fls(int mask)
{
int bit;
if (mask == 0)
return (0);
for (bit = 1; mask != 1; bit++)
mask = (unsigned int)mask >> 1;
return (bit);
}
#endif