1204591Sluigi/* 2204591Sluigi * $FreeBSD$ 3204591Sluigi * 4204591Sluigi * userspace compatibility code for dummynet schedulers 5204591Sluigi */ 6204591Sluigi 7204591Sluigi#ifndef _DN_TEST_H 8204591Sluigi#define _DN_TEST_H 9204866Sluigi 10204866Sluigi#ifdef __cplusplus 11204866Sluigiextern "C" { 12204866Sluigi#endif 13204866Sluigi 14204591Sluigi#include <inttypes.h> 15204591Sluigi#include <stdio.h> 16204591Sluigi#include <stdlib.h> 17204591Sluigi#include <strings.h> /* bzero, ffs, ... */ 18204591Sluigi#include <string.h> /* strcmp */ 19204591Sluigi#include <errno.h> 20204591Sluigi#include <sys/queue.h> 21204591Sluigi#include <sys/time.h> 22204591Sluigi 23204591Sluigiextern int debug; 24204591Sluigi#define ND(fmt, args...) do {} while (0) 25204591Sluigi#define D1(fmt, args...) do {} while (0) 26294882Sluigi#define D(fmt, args...) fprintf(stderr, "%-10s %4d %-8s " fmt "\n", \ 27294882Sluigi __FILE__, __LINE__, __FUNCTION__, ## args) 28204591Sluigi#define DX(lev, fmt, args...) do { \ 29204591Sluigi if (debug > lev) D(fmt, ## args); } while (0) 30204591Sluigi 31204591Sluigi 32204866Sluigi#ifndef offsetof 33285360Sluigi#define offsetof(t,m) (int)(intptr_t)((&((t *)0L)->m)) 34204866Sluigi#endif 35204591Sluigi 36285360Sluigi#if defined(__APPLE__) // XXX osx 37285360Sluigitypedef unsigned int u_int; 38285360Sluigi#endif /* osx */ 39285360Sluigi 40204591Sluigi#include <mylist.h> 41204591Sluigi 42204591Sluigi/* prevent include of other system headers */ 43204591Sluigi#define _NETINET_IP_VAR_H_ /* ip_fw_args */ 44204591Sluigi#define _IPFW2_H 45204591Sluigi#define _SYS_MBUF_H_ 46204591Sluigi 47204591Sluigienum { 48204591Sluigi DN_QUEUE, 49204591Sluigi}; 50204591Sluigi 51204591Sluigienum { 52204591Sluigi DN_SCHED_FIFO, 53204591Sluigi DN_SCHED_WF2QP, 54204591Sluigi}; 55204591Sluigi 56294882Sluigi/* from ip_dummynet.h, fields used in ip_dn_private.h */ 57204591Sluigistruct dn_id { 58294882Sluigi uint16_t len; /* total len inc. this header */ 59294882Sluigi uint8_t type; 60294882Sluigi uint8_t subtype; 61294882Sluigi// uint32_t id; /* generic id */ 62204591Sluigi}; 63204866Sluigi 64294882Sluigi/* (from ip_dummynet.h) 65294882Sluigi * A flowset, which is a template for flows. Contains parameters 66294882Sluigi * from the command line: id, target scheduler, queue sizes, plr, 67294882Sluigi * flow masks, buckets for the flow hash, and possibly scheduler- 68294882Sluigi * specific parameters (weight, quantum and so on). 69294882Sluigi */ 70204591Sluigistruct dn_fs { 71294882Sluigi /* generic scheduler parameters. Leave them at -1 if unset. 72294882Sluigi * Now we use 0: weight, 1: lmax, 2: priority 73294882Sluigi */ 74204591Sluigi int par[4]; /* flowset parameters */ 75204591Sluigi 76204591Sluigi /* simulation entries. 77204591Sluigi * 'index' is not strictly necessary 78204591Sluigi * y is used for the inverse mapping , 79204591Sluigi */ 80204591Sluigi int index; 81204591Sluigi int y; /* inverse mapping */ 82204591Sluigi int base_y; /* inverse mapping */ 83204591Sluigi int next_y; /* inverse mapping */ 84204591Sluigi int n_flows; 85204591Sluigi int first_flow; 86204591Sluigi int next_flow; /* first_flow + n_flows */ 87204591Sluigi /* 88204591Sluigi * when generating, let 'cur' go from 0 to n_flows-1, 89204591Sluigi * then point to flow first_flow + cur 90204591Sluigi */ 91204591Sluigi int cur; 92204591Sluigi}; 93204866Sluigi 94294882Sluigi/* (ip_dummynet.h) 95294882Sluigi * scheduler template, indicating nam, number, mask and buckets 96294882Sluigi */ 97204591Sluigistruct dn_sch { 98204591Sluigi}; 99204866Sluigi 100294882Sluigi/* (from ip_dummynet.h) 101294882Sluigi * dn_flow collects flow_id and stats for queues and scheduler 102294882Sluigi * instances, and is used to pass these info to userland. 103294882Sluigi * oid.type/oid.subtype describe the object, oid.id is number 104294882Sluigi * of the parent object. 105294882Sluigi */ 106204591Sluigistruct dn_flow { 107204591Sluigi struct dn_id oid; 108294882Sluigi uint64_t tot_pkts; 109204591Sluigi uint64_t tot_bytes; 110294882Sluigi uint32_t length; /* Queue length, in packets */ 111294882Sluigi uint32_t len_bytes; /* Queue length, in bytes */ 112294882Sluigi uint32_t drops; 113294882Sluigi //uint32_t flow_id; 114294882Sluigi 115294882Sluigi /* the following fields are used by the traffic generator. 116294882Sluigi */ 117204591Sluigi struct list_head h; /* used by the generator */ 118285360Sluigi 119285360Sluigi /* bytes served by the flow since the last backlog time */ 120285360Sluigi uint64_t bytes; 121285360Sluigi /* bytes served by the system at the last backlog time */ 122285360Sluigi uint64_t sch_bytes; 123204591Sluigi}; 124204866Sluigi 125294882Sluigi/* the link */ 126204591Sluigistruct dn_link { 127204591Sluigi}; 128204591Sluigi 129204591Sluigistruct ip_fw_args { 130204591Sluigi}; 131204591Sluigi 132204591Sluigistruct mbuf { 133204591Sluigi struct { 134204591Sluigi int len; 135204591Sluigi } m_pkthdr; 136204591Sluigi struct mbuf *m_nextpkt; 137294882Sluigi uint32_t flow_id; /* for testing, index of a flow */ 138204591Sluigi //int flowset_id; /* for testing, index of a flowset */ 139294882Sluigi //void *cfg; /* config args */ 140204591Sluigi}; 141204591Sluigi 142285360Sluigi#define MALLOC_DECLARE(x) extern volatile int __dummy__ ## x 143204591Sluigi#define KASSERT(x, y) do { if (!(x)) printf y ; exit(0); } while (0) 144204591Sluigistruct ipfw_flow_id { 145204591Sluigi}; 146204591Sluigi 147204591Sluigitypedef void * module_t; 148204866Sluigi 149204591Sluigistruct _md_t { 150204591Sluigi const char *name; 151204591Sluigi int (*f)(module_t, int, void *); 152204591Sluigi void *p; 153204591Sluigi}; 154204866Sluigi 155204591Sluigitypedef struct _md_t moduledata_t; 156204866Sluigi 157204591Sluigi#define DECLARE_MODULE(name, b, c, d) \ 158204591Sluigi moduledata_t *_g_##name = & b 159204591Sluigi#define MODULE_DEPEND(a, b, c, d, e) 160204591Sluigi 161204591Sluigi#include <dn_heap.h> 162204591Sluigi#include <ip_dn_private.h> 163204591Sluigi#include <dn_sched.h> 164204591Sluigi 165204736Sluigi#ifndef __FreeBSD__ 166204736Sluigiint fls(int); 167204736Sluigi#endif 168204736Sluigi 169204591Sluigistatic inline void 170204591Sluigimq_append(struct mq *q, struct mbuf *m) 171204591Sluigi{ 172204591Sluigi if (q->head == NULL) 173204591Sluigi q->head = m; 174204591Sluigi else 175204591Sluigi q->tail->m_nextpkt = m; 176204591Sluigi q->tail = m; 177204591Sluigi m->m_nextpkt = NULL; 178204591Sluigi} 179204591Sluigi 180204866Sluigi#ifdef __cplusplus 181204866Sluigi} 182204866Sluigi#endif 183204866Sluigi 184204591Sluigi#endif /* _DN_TEST_H */ 185