13b3a8eb9SGleb Smirnoff /*
23b3a8eb9SGleb Smirnoff *
33b3a8eb9SGleb Smirnoff * userspace compatibility code for dummynet schedulers
43b3a8eb9SGleb Smirnoff */
53b3a8eb9SGleb Smirnoff
63b3a8eb9SGleb Smirnoff #ifndef _DN_TEST_H
73b3a8eb9SGleb Smirnoff #define _DN_TEST_H
83b3a8eb9SGleb Smirnoff
93b3a8eb9SGleb Smirnoff #ifdef __cplusplus
103b3a8eb9SGleb Smirnoff extern "C" {
113b3a8eb9SGleb Smirnoff #endif
123b3a8eb9SGleb Smirnoff
133b3a8eb9SGleb Smirnoff #include <inttypes.h>
143b3a8eb9SGleb Smirnoff #include <stdio.h>
153b3a8eb9SGleb Smirnoff #include <stdlib.h>
163b3a8eb9SGleb Smirnoff #include <strings.h> /* bzero, ffs, ... */
173b3a8eb9SGleb Smirnoff #include <string.h> /* strcmp */
183b3a8eb9SGleb Smirnoff #include <errno.h>
193b3a8eb9SGleb Smirnoff #include <sys/queue.h>
203b3a8eb9SGleb Smirnoff #include <sys/time.h>
213b3a8eb9SGleb Smirnoff
223b3a8eb9SGleb Smirnoff extern int debug;
233b3a8eb9SGleb Smirnoff #define ND(fmt, args...) do {} while (0)
243b3a8eb9SGleb Smirnoff #define D1(fmt, args...) do {} while (0)
251cdc5f0bSLuigi Rizzo #define D(fmt, args...) fprintf(stderr, "%-10s %4d %-8s " fmt "\n", \
261cdc5f0bSLuigi Rizzo __FILE__, __LINE__, __FUNCTION__, ## args)
273b3a8eb9SGleb Smirnoff #define DX(lev, fmt, args...) do { \
283b3a8eb9SGleb Smirnoff if (debug > lev) D(fmt, ## args); } while (0)
293b3a8eb9SGleb Smirnoff
303b3a8eb9SGleb Smirnoff #ifndef offsetof
31e25716b7SLuigi Rizzo #define offsetof(t,m) (int)(intptr_t)((&((t *)0L)->m))
323b3a8eb9SGleb Smirnoff #endif
333b3a8eb9SGleb Smirnoff
34e25716b7SLuigi Rizzo #if defined(__APPLE__) // XXX osx
35e25716b7SLuigi Rizzo typedef unsigned int u_int;
36e25716b7SLuigi Rizzo #endif /* osx */
37e25716b7SLuigi Rizzo
383b3a8eb9SGleb Smirnoff #include <mylist.h>
393b3a8eb9SGleb Smirnoff
403b3a8eb9SGleb Smirnoff /* prevent include of other system headers */
413b3a8eb9SGleb Smirnoff #define _NETINET_IP_VAR_H_ /* ip_fw_args */
423b3a8eb9SGleb Smirnoff #define _IPFW2_H
433b3a8eb9SGleb Smirnoff #define _SYS_MBUF_H_
443b3a8eb9SGleb Smirnoff
453b3a8eb9SGleb Smirnoff enum {
463b3a8eb9SGleb Smirnoff DN_QUEUE,
473b3a8eb9SGleb Smirnoff };
483b3a8eb9SGleb Smirnoff
493b3a8eb9SGleb Smirnoff enum {
503b3a8eb9SGleb Smirnoff DN_SCHED_FIFO,
513b3a8eb9SGleb Smirnoff DN_SCHED_WF2QP,
523b3a8eb9SGleb Smirnoff };
533b3a8eb9SGleb Smirnoff
541cdc5f0bSLuigi Rizzo /* from ip_dummynet.h, fields used in ip_dn_private.h */
553b3a8eb9SGleb Smirnoff struct dn_id {
561cdc5f0bSLuigi Rizzo uint16_t len; /* total len inc. this header */
571cdc5f0bSLuigi Rizzo uint8_t type;
581cdc5f0bSLuigi Rizzo uint8_t subtype;
591cdc5f0bSLuigi Rizzo // uint32_t id; /* generic id */
603b3a8eb9SGleb Smirnoff };
613b3a8eb9SGleb Smirnoff
621cdc5f0bSLuigi Rizzo /* (from ip_dummynet.h)
631cdc5f0bSLuigi Rizzo * A flowset, which is a template for flows. Contains parameters
641cdc5f0bSLuigi Rizzo * from the command line: id, target scheduler, queue sizes, plr,
651cdc5f0bSLuigi Rizzo * flow masks, buckets for the flow hash, and possibly scheduler-
661cdc5f0bSLuigi Rizzo * specific parameters (weight, quantum and so on).
671cdc5f0bSLuigi Rizzo */
683b3a8eb9SGleb Smirnoff struct dn_fs {
691cdc5f0bSLuigi Rizzo /* generic scheduler parameters. Leave them at -1 if unset.
701cdc5f0bSLuigi Rizzo * Now we use 0: weight, 1: lmax, 2: priority
711cdc5f0bSLuigi Rizzo */
723b3a8eb9SGleb Smirnoff int par[4]; /* flowset parameters */
733b3a8eb9SGleb Smirnoff
743b3a8eb9SGleb Smirnoff /* simulation entries.
753b3a8eb9SGleb Smirnoff * 'index' is not strictly necessary
763b3a8eb9SGleb Smirnoff * y is used for the inverse mapping ,
773b3a8eb9SGleb Smirnoff */
783b3a8eb9SGleb Smirnoff int index;
793b3a8eb9SGleb Smirnoff int y; /* inverse mapping */
803b3a8eb9SGleb Smirnoff int base_y; /* inverse mapping */
813b3a8eb9SGleb Smirnoff int next_y; /* inverse mapping */
823b3a8eb9SGleb Smirnoff int n_flows;
833b3a8eb9SGleb Smirnoff int first_flow;
843b3a8eb9SGleb Smirnoff int next_flow; /* first_flow + n_flows */
853b3a8eb9SGleb Smirnoff /*
863b3a8eb9SGleb Smirnoff * when generating, let 'cur' go from 0 to n_flows-1,
873b3a8eb9SGleb Smirnoff * then point to flow first_flow + cur
883b3a8eb9SGleb Smirnoff */
893b3a8eb9SGleb Smirnoff int cur;
903b3a8eb9SGleb Smirnoff };
913b3a8eb9SGleb Smirnoff
921cdc5f0bSLuigi Rizzo /* (ip_dummynet.h)
931cdc5f0bSLuigi Rizzo * scheduler template, indicating nam, number, mask and buckets
941cdc5f0bSLuigi Rizzo */
953b3a8eb9SGleb Smirnoff struct dn_sch {
963b3a8eb9SGleb Smirnoff };
973b3a8eb9SGleb Smirnoff
981cdc5f0bSLuigi Rizzo /* (from ip_dummynet.h)
991cdc5f0bSLuigi Rizzo * dn_flow collects flow_id and stats for queues and scheduler
1001cdc5f0bSLuigi Rizzo * instances, and is used to pass these info to userland.
1011cdc5f0bSLuigi Rizzo * oid.type/oid.subtype describe the object, oid.id is number
1021cdc5f0bSLuigi Rizzo * of the parent object.
1031cdc5f0bSLuigi Rizzo */
1043b3a8eb9SGleb Smirnoff struct dn_flow {
1053b3a8eb9SGleb Smirnoff struct dn_id oid;
1061cdc5f0bSLuigi Rizzo uint64_t tot_pkts;
1073b3a8eb9SGleb Smirnoff uint64_t tot_bytes;
1081cdc5f0bSLuigi Rizzo uint32_t length; /* Queue length, in packets */
1091cdc5f0bSLuigi Rizzo uint32_t len_bytes; /* Queue length, in bytes */
1101cdc5f0bSLuigi Rizzo uint32_t drops;
1111cdc5f0bSLuigi Rizzo //uint32_t flow_id;
1121cdc5f0bSLuigi Rizzo
1131cdc5f0bSLuigi Rizzo /* the following fields are used by the traffic generator.
1141cdc5f0bSLuigi Rizzo */
1153b3a8eb9SGleb Smirnoff struct list_head h; /* used by the generator */
116e25716b7SLuigi Rizzo
117e25716b7SLuigi Rizzo /* bytes served by the flow since the last backlog time */
118e25716b7SLuigi Rizzo uint64_t bytes;
119e25716b7SLuigi Rizzo /* bytes served by the system at the last backlog time */
120e25716b7SLuigi Rizzo uint64_t sch_bytes;
1213b3a8eb9SGleb Smirnoff };
1223b3a8eb9SGleb Smirnoff
1231cdc5f0bSLuigi Rizzo /* the link */
1243b3a8eb9SGleb Smirnoff struct dn_link {
1253b3a8eb9SGleb Smirnoff };
1263b3a8eb9SGleb Smirnoff
1273b3a8eb9SGleb Smirnoff struct ip_fw_args {
1283b3a8eb9SGleb Smirnoff };
1293b3a8eb9SGleb Smirnoff
1303b3a8eb9SGleb Smirnoff struct mbuf {
1313b3a8eb9SGleb Smirnoff struct {
1323b3a8eb9SGleb Smirnoff int len;
1333b3a8eb9SGleb Smirnoff } m_pkthdr;
1343b3a8eb9SGleb Smirnoff struct mbuf *m_nextpkt;
1351cdc5f0bSLuigi Rizzo uint32_t flow_id; /* for testing, index of a flow */
1363b3a8eb9SGleb Smirnoff //int flowset_id; /* for testing, index of a flowset */
1371cdc5f0bSLuigi Rizzo //void *cfg; /* config args */
1383b3a8eb9SGleb Smirnoff };
1393b3a8eb9SGleb Smirnoff
140e25716b7SLuigi Rizzo #define MALLOC_DECLARE(x) extern volatile int __dummy__ ## x
1413b3a8eb9SGleb Smirnoff #define KASSERT(x, y) do { if (!(x)) printf y ; exit(0); } while (0)
1423b3a8eb9SGleb Smirnoff struct ipfw_flow_id {
1433b3a8eb9SGleb Smirnoff };
1443b3a8eb9SGleb Smirnoff
1453b3a8eb9SGleb Smirnoff typedef void * module_t;
1463b3a8eb9SGleb Smirnoff
1473b3a8eb9SGleb Smirnoff struct _md_t {
1483b3a8eb9SGleb Smirnoff const char *name;
1493b3a8eb9SGleb Smirnoff int (*f)(module_t, int, void *);
1503b3a8eb9SGleb Smirnoff void *p;
1513b3a8eb9SGleb Smirnoff };
1523b3a8eb9SGleb Smirnoff
1533b3a8eb9SGleb Smirnoff typedef struct _md_t moduledata_t;
1543b3a8eb9SGleb Smirnoff
1553b3a8eb9SGleb Smirnoff #define DECLARE_MODULE(name, b, c, d) \
1563b3a8eb9SGleb Smirnoff moduledata_t *_g_##name = & b
1573b3a8eb9SGleb Smirnoff #define MODULE_DEPEND(a, b, c, d, e)
1583b3a8eb9SGleb Smirnoff
1593b3a8eb9SGleb Smirnoff #include <dn_heap.h>
1603b3a8eb9SGleb Smirnoff #include <ip_dn_private.h>
1613b3a8eb9SGleb Smirnoff #include <dn_sched.h>
1623b3a8eb9SGleb Smirnoff
1633b3a8eb9SGleb Smirnoff #ifndef __FreeBSD__
1643b3a8eb9SGleb Smirnoff int fls(int);
1653b3a8eb9SGleb Smirnoff #endif
1663b3a8eb9SGleb Smirnoff
1673b3a8eb9SGleb Smirnoff static inline void
mq_append(struct mq * q,struct mbuf * m)1683b3a8eb9SGleb Smirnoff mq_append(struct mq *q, struct mbuf *m)
1693b3a8eb9SGleb Smirnoff {
1703b3a8eb9SGleb Smirnoff if (q->head == NULL)
1713b3a8eb9SGleb Smirnoff q->head = m;
1723b3a8eb9SGleb Smirnoff else
1733b3a8eb9SGleb Smirnoff q->tail->m_nextpkt = m;
1743b3a8eb9SGleb Smirnoff q->tail = m;
1753b3a8eb9SGleb Smirnoff m->m_nextpkt = NULL;
1763b3a8eb9SGleb Smirnoff }
1773b3a8eb9SGleb Smirnoff
1783b3a8eb9SGleb Smirnoff #ifdef __cplusplus
1793b3a8eb9SGleb Smirnoff }
1803b3a8eb9SGleb Smirnoff #endif
1813b3a8eb9SGleb Smirnoff
1823b3a8eb9SGleb Smirnoff #endif /* _DN_TEST_H */
183