dn_test.h revision 256281
11573Srgrimes/*
21573Srgrimes * $FreeBSD: stable/10/sys/netpfil/ipfw/test/dn_test.h 204866 2010-03-08 11:27:39Z luigi $
31573Srgrimes *
41573Srgrimes * userspace compatibility code for dummynet schedulers
51573Srgrimes */
61573Srgrimes
71573Srgrimes#ifndef _DN_TEST_H
81573Srgrimes#define _DN_TEST_H
91573Srgrimes
101573Srgrimes#ifdef __cplusplus
111573Srgrimesextern "C" {
121573Srgrimes#endif
131573Srgrimes
141573Srgrimes#include <inttypes.h>
151573Srgrimes#include <stdio.h>
161573Srgrimes#include <stdlib.h>
171573Srgrimes#include <strings.h>	/* bzero, ffs, ... */
181573Srgrimes#include <string.h>	/* strcmp */
191573Srgrimes#include <errno.h>
201573Srgrimes#include <sys/queue.h>
211573Srgrimes#include <sys/time.h>
221573Srgrimes
231573Srgrimesextern int debug;
241573Srgrimes#define ND(fmt, args...) do {} while (0)
251573Srgrimes#define D1(fmt, args...) do {} while (0)
261573Srgrimes#define D(fmt, args...) fprintf(stderr, "%-8s " fmt "\n",      \
271573Srgrimes        __FUNCTION__, ## args)
281573Srgrimes#define DX(lev, fmt, args...) do {              \
291573Srgrimes        if (debug > lev) D(fmt, ## args); } while (0)
301573Srgrimes
311573Srgrimes
321573Srgrimes#ifndef offsetof
3350476Speter#define offsetof(t,m) (int)((&((t *)0L)->m))
341573Srgrimes#endif
35210468Sbcr
361573Srgrimes#include <mylist.h>
371573Srgrimes
381573Srgrimes/* prevent include of other system headers */
391573Srgrimes#define	_NETINET_IP_VAR_H_	/* ip_fw_args */
401573Srgrimes#define _IPFW2_H
4159460Sphantom#define _SYS_MBUF_H_
4259460Sphantom
431573Srgrimesenum	{
4484306Sru	DN_QUEUE,
451573Srgrimes};
461573Srgrimes
471573Srgrimesenum	{
481573Srgrimes	DN_SCHED_FIFO,
491573Srgrimes	DN_SCHED_WF2QP,
501573Srgrimes};
511573Srgrimes
52148086Stjrstruct dn_id {
53152551Sru	int type, subtype, len, id;
5462465Sache};
5562465Sache
561573Srgrimesstruct dn_fs {
571573Srgrimes	int par[4];	/* flowset parameters */
581573Srgrimes
591573Srgrimes	/* simulation entries.
60210468Sbcr	 * 'index' is not strictly necessary
61104405Stjr	 * y is used for the inverse mapping ,
62134103Stjr	 */
63134103Stjr	int index;
64134103Stjr	int y;	/* inverse mapping */
65104405Stjr	int base_y;	/* inverse mapping */
66134103Stjr	int next_y;	/* inverse mapping */
67134103Stjr	int n_flows;
68134103Stjr	int first_flow;
69104405Stjr	int next_flow;	/* first_flow + n_flows */
70134103Stjr	/*
711573Srgrimes	 * when generating, let 'cur' go from 0 to n_flows-1,
7289259Sbde	 * then point to flow first_flow + cur
731573Srgrimes	 */
74104405Stjr	int	cur;
751573Srgrimes};
761573Srgrimes
7713100Sgpalmerstruct dn_sch {
781573Srgrimes};
7973088Sru
80struct dn_flow {
81	struct dn_id oid;
82	int length;
83	int len_bytes;
84	int drops;
85	uint64_t tot_bytes;
86	uint32_t flow_id;
87	struct list_head h;	/* used by the generator */
88};
89
90struct dn_link {
91};
92
93struct ip_fw_args {
94};
95
96struct mbuf {
97        struct {
98                int len;
99        } m_pkthdr;
100        struct mbuf *m_nextpkt;
101	int flow_id;	/* for testing, index of a flow */
102	//int flowset_id;	/* for testing, index of a flowset */
103	void *cfg;	/* config args */
104};
105
106#define MALLOC_DECLARE(x)
107#define KASSERT(x, y)	do { if (!(x)) printf y ; exit(0); } while (0)
108struct ipfw_flow_id {
109};
110
111typedef void * module_t;
112
113struct _md_t {
114	const char *name;
115	int (*f)(module_t, int, void *);
116	void *p;
117};
118
119typedef struct _md_t moduledata_t;
120
121#define DECLARE_MODULE(name, b, c, d)	\
122	moduledata_t *_g_##name = & b
123#define MODULE_DEPEND(a, b, c, d, e)
124
125#ifdef IPFW
126#include <dn_heap.h>
127#include <ip_dn_private.h>
128#include <dn_sched.h>
129#else
130struct dn_queue {
131        struct dn_fsk *fs;             /* parent flowset. */
132        struct dn_sch_inst *_si;	/* parent sched instance. */
133};
134struct dn_schk {
135};
136struct dn_fsk {
137	struct dn_fs fs;
138	struct dn_schk *sched;
139};
140struct dn_sch_inst {
141	struct dn_schk *sched;
142};
143struct dn_alg {
144	int type;
145	const char *name;
146	void *enqueue, *dequeue;
147	int q_datalen, si_datalen, schk_datalen;
148	int (*config)(struct dn_schk *);
149	int (*new_sched)(struct dn_sch_inst *);
150	int (*new_fsk)(struct dn_fsk *);
151        int (*new_queue)(struct dn_queue *q);
152};
153
154#endif
155
156#ifndef __FreeBSD__
157int fls(int);
158#endif
159
160static inline void
161mq_append(struct mq *q, struct mbuf *m)
162{
163        if (q->head == NULL)
164                q->head = m;
165        else
166                q->tail->m_nextpkt = m;
167        q->tail = m;
168        m->m_nextpkt = NULL;
169}
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif /* _DN_TEST_H */
176