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