1 /*
2 * $FreeBSD: stable/12/sys/netpfil/ipfw/test/dn_test.h 294882 2016-01-27 02:22:31Z luigi $
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, "%-10s %4d %-8s " fmt "\n", \
27 __FILE__, __LINE__, __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 /* from ip_dummynet.h, fields used in ip_dn_private.h */
57 struct dn_id {
58 uint16_t len; /* total len inc. this header */
59 uint8_t type;
60 uint8_t subtype;
61 // uint32_t id; /* generic id */
62 };
63
64 /* (from ip_dummynet.h)
65 * A flowset, which is a template for flows. Contains parameters
66 * from the command line: id, target scheduler, queue sizes, plr,
67 * flow masks, buckets for the flow hash, and possibly scheduler-
68 * specific parameters (weight, quantum and so on).
69 */
70 struct dn_fs {
71 /* generic scheduler parameters. Leave them at -1 if unset.
72 * Now we use 0: weight, 1: lmax, 2: priority
73 */
74 int par[4]; /* flowset parameters */
75
76 /* simulation entries.
77 * 'index' is not strictly necessary
78 * y is used for the inverse mapping ,
79 */
80 int index;
81 int y; /* inverse mapping */
82 int base_y; /* inverse mapping */
83 int next_y; /* inverse mapping */
84 int n_flows;
85 int first_flow;
86 int next_flow; /* first_flow + n_flows */
87 /*
88 * when generating, let 'cur' go from 0 to n_flows-1,
89 * then point to flow first_flow + cur
90 */
91 int cur;
92 };
93
94 /* (ip_dummynet.h)
95 * scheduler template, indicating nam, number, mask and buckets
96 */
97 struct dn_sch {
98 };
99
100 /* (from ip_dummynet.h)
101 * dn_flow collects flow_id and stats for queues and scheduler
102 * instances, and is used to pass these info to userland.
103 * oid.type/oid.subtype describe the object, oid.id is number
104 * of the parent object.
105 */
106 struct dn_flow {
107 struct dn_id oid;
108 uint64_t tot_pkts;
109 uint64_t tot_bytes;
110 uint32_t length; /* Queue length, in packets */
111 uint32_t len_bytes; /* Queue length, in bytes */
112 uint32_t drops;
113 //uint32_t flow_id;
114
115 /* the following fields are used by the traffic generator.
116 */
117 struct list_head h; /* used by the generator */
118
119 /* bytes served by the flow since the last backlog time */
120 uint64_t bytes;
121 /* bytes served by the system at the last backlog time */
122 uint64_t sch_bytes;
123 };
124
125 /* the link */
126 struct dn_link {
127 };
128
129 struct ip_fw_args {
130 };
131
132 struct mbuf {
133 struct {
134 int len;
135 } m_pkthdr;
136 struct mbuf *m_nextpkt;
137 uint32_t flow_id; /* for testing, index of a flow */
138 //int flowset_id; /* for testing, index of a flowset */
139 //void *cfg; /* config args */
140 };
141
142 #define MALLOC_DECLARE(x) extern volatile int __dummy__ ## x
143 #define KASSERT(x, y) do { if (!(x)) printf y ; exit(0); } while (0)
144 struct ipfw_flow_id {
145 };
146
147 typedef void * module_t;
148
149 struct _md_t {
150 const char *name;
151 int (*f)(module_t, int, void *);
152 void *p;
153 };
154
155 typedef struct _md_t moduledata_t;
156
157 #define DECLARE_MODULE(name, b, c, d) \
158 moduledata_t *_g_##name = & b
159 #define MODULE_DEPEND(a, b, c, d, e)
160
161 #include <dn_heap.h>
162 #include <ip_dn_private.h>
163 #include <dn_sched.h>
164
165 #ifndef __FreeBSD__
166 int fls(int);
167 #endif
168
169 static inline void
mq_append(struct mq * q,struct mbuf * m)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