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
11extern "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
23extern 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)((&((t *)0L)->m))
34#endif
35
36#include <mylist.h>
37
38/* prevent include of other system headers */
39#define	_NETINET_IP_VAR_H_	/* ip_fw_args */
40#define _IPFW2_H
41#define _SYS_MBUF_H_
42
43enum	{
44	DN_QUEUE,
45};
46
47enum	{
48	DN_SCHED_FIFO,
49	DN_SCHED_WF2QP,
50};
51
52struct dn_id {
53	int type, subtype, len, id;
54};
55
56struct dn_fs {
57	int par[4];	/* flowset parameters */
58
59	/* simulation entries.
60	 * 'index' is not strictly necessary
61	 * y is used for the inverse mapping ,
62	 */
63	int index;
64	int y;	/* inverse mapping */
65	int base_y;	/* inverse mapping */
66	int next_y;	/* inverse mapping */
67	int n_flows;
68	int first_flow;
69	int next_flow;	/* first_flow + n_flows */
70	/*
71	 * when generating, let 'cur' go from 0 to n_flows-1,
72	 * then point to flow first_flow + cur
73	 */
74	int	cur;
75};
76
77struct dn_sch {
78};
79
80struct dn_flow {
81	struct dn_id oid;
82	int length;
83	int len_bytes;
84	int drops;
85	uint64_t tot_bytes;
86	uint32_t flow_id;
87	struct list_head h;	/* used by the generator */
88};
89
90struct dn_link {
91};
92
93struct ip_fw_args {
94};
95
96struct mbuf {
97        struct {
98                int len;
99        } m_pkthdr;
100        struct mbuf *m_nextpkt;
101	int flow_id;	/* for testing, index of a flow */
102	//int flowset_id;	/* for testing, index of a flowset */
103	void *cfg;	/* config args */
104};
105
106#define MALLOC_DECLARE(x)
107#define KASSERT(x, y)	do { if (!(x)) printf y ; exit(0); } while (0)
108struct ipfw_flow_id {
109};
110
111typedef void * module_t;
112
113struct _md_t {
114	const char *name;
115	int (*f)(module_t, int, void *);
116	void *p;
117};
118
119typedef struct _md_t moduledata_t;
120
121#define DECLARE_MODULE(name, b, c, d)	\
122	moduledata_t *_g_##name = & b
123#define MODULE_DEPEND(a, b, c, d, e)
124
125#ifdef IPFW
126#include <dn_heap.h>
127#include <ip_dn_private.h>
128#include <dn_sched.h>
129#else
130struct dn_queue {
131        struct dn_fsk *fs;             /* parent flowset. */
132        struct dn_sch_inst *_si;	/* parent sched instance. */
133};
134struct dn_schk {
135};
136struct dn_fsk {
137	struct dn_fs fs;
138	struct dn_schk *sched;
139};
140struct dn_sch_inst {
141	struct dn_schk *sched;
142};
143struct dn_alg {
144	int type;
145	const char *name;
146	void *enqueue, *dequeue;
147	int q_datalen, si_datalen, schk_datalen;
148	int (*config)(struct dn_schk *);
149	int (*new_sched)(struct dn_sch_inst *);
150	int (*new_fsk)(struct dn_fsk *);
151        int (*new_queue)(struct dn_queue *q);
152};
153
154#endif
155
156#ifndef __FreeBSD__
157int fls(int);
158#endif
159
160static inline void
161mq_append(struct mq *q, struct mbuf *m)
162{
163        if (q->head == NULL)
164                q->head = m;
165        else
166                q->tail->m_nextpkt = m;
167        q->tail = m;
168        m->m_nextpkt = NULL;
169}
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif /* _DN_TEST_H */
176