initial version, corresponding to ipfw3-2012
[ipfw-google.git] / test / dn_test.h
1 /*
2  * $Id: dn_test.h 5626 2010-03-04 21:55:22Z luigi $
3  *
4  * userspace compatibility code for dummynet schedulers
5  */
6
7 #ifndef _DN_TEST_H
8 #define _DN_TEST_H
9 #include <inttypes.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <strings.h>    /* bzero, ffs, ... */
13 #include <string.h>     /* strcmp */
14 #include <errno.h>
15 #include <sys/queue.h>
16 #include <sys/time.h>
17
18 extern int debug;
19 #define ND(fmt, args...) do {} while (0)
20 #define D1(fmt, args...) do {} while (0)
21 #define D(fmt, args...) fprintf(stderr, "%-8s " fmt "\n",      \
22         __FUNCTION__, ## args)
23 #define DX(lev, fmt, args...) do {              \
24         if (debug > lev) D(fmt, ## args); } while (0)
25
26
27 #define offsetof(t,m) (int)((&((t *)0L)->m))
28
29 #include <mylist.h>
30
31 /* prevent include of other system headers */
32 #define _NETINET_IP_VAR_H_      /* ip_fw_args */
33 #define _IPFW2_H
34 #define _SYS_MBUF_H_
35
36 enum    {
37         DN_QUEUE,
38 };
39
40 enum    {
41         DN_SCHED_FIFO,
42         DN_SCHED_WF2QP,
43 };
44
45 struct dn_id {
46         int type, subtype, len, id;
47 };
48 struct dn_fs {
49         int par[4];     /* flowset parameters */
50
51         /* simulation entries.
52          * 'index' is not strictly necessary
53          * y is used for the inverse mapping ,
54          */
55         int index;
56         int y;  /* inverse mapping */
57         int base_y;     /* inverse mapping */
58         int next_y;     /* inverse mapping */
59         int n_flows;
60         int first_flow;
61         int next_flow;  /* first_flow + n_flows */
62         /*
63          * when generating, let 'cur' go from 0 to n_flows-1,
64          * then point to flow first_flow + cur
65          */
66         int     cur;
67 };
68 struct dn_sch {
69 };
70 struct dn_flow {
71         struct dn_id oid;
72         int length;
73         int len_bytes;
74         int drops;
75         uint64_t tot_bytes;
76         uint32_t flow_id;
77         struct list_head h;     /* used by the generator */
78 };
79 struct dn_link {
80 };
81
82 struct ip_fw_args {
83 };
84
85 struct mbuf {
86         struct {
87                 int len;
88         } m_pkthdr;
89         struct mbuf *m_nextpkt;
90         int flow_id;    /* for testing, index of a flow */
91         //int flowset_id;       /* for testing, index of a flowset */
92         void *cfg;      /* config args */
93 };
94
95 #define MALLOC_DECLARE(x)
96 #define KASSERT(x, y)   do { if (!(x)) printf y ; exit(0); } while (0)
97 struct ipfw_flow_id {
98 };
99
100 typedef void * module_t;
101 struct _md_t {
102         const char *name;
103         int (*f)(module_t, int, void *);
104         void *p;
105 };
106 typedef struct _md_t moduledata_t;
107 #define DECLARE_MODULE(name, b, c, d)   \
108         moduledata_t *_g_##name = & b
109 #define MODULE_DEPEND(a, b, c, d, e)
110
111 #ifdef IPFW
112 #include <dn_heap.h>
113 #include <ip_dn_private.h>
114 #include <dn_sched.h>
115 #else
116 struct dn_queue {
117         struct dn_fsk *fs;             /* parent flowset. */
118         struct dn_sch_inst *_si;        /* parent sched instance. */
119 };
120 struct dn_schk {
121 };
122 struct dn_fsk {
123         struct dn_fs fs;
124         struct dn_schk *sched;
125 };
126 struct dn_sch_inst {
127         struct dn_schk *sched;
128 };
129 struct dn_alg {
130         int type;
131         const char *name;
132         void *enqueue, *dequeue;
133         int q_datalen, si_datalen, schk_datalen;
134         int (*config)(struct dn_schk *);
135         int (*new_sched)(struct dn_sch_inst *);
136         int (*new_fsk)(struct dn_fsk *);
137         int (*new_queue)(struct dn_queue *q);
138 };
139
140 #endif
141
142 #ifndef __FreeBSD__
143 int fls(int);
144 #endif
145
146 static inline void
147 mq_append(struct mq *q, struct mbuf *m)
148 {
149         if (q->head == NULL)
150                 q->head = m;
151         else
152                 q->tail->m_nextpkt = m;
153         q->tail = m;
154         m->m_nextpkt = NULL;
155 }
156
157 #endif /* _DN_TEST_H */