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