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