ip_dummynet.h revision 239124
1190207Srpaulo/*- 275115Sfenner * Copyright (c) 1998-2010 Luigi Rizzo, Universita` di Pisa 375115Sfenner * Portions Copyright (c) 2000 Akamba Corp. 475115Sfenner * All rights reserved 575115Sfenner * 675115Sfenner * Redistribution and use in source and binary forms, with or without 775115Sfenner * modification, are permitted provided that the following conditions 875115Sfenner * are met: 975115Sfenner * 1. Redistributions of source code must retain the above copyright 1075115Sfenner * notice, this list of conditions and the following disclaimer. 1175115Sfenner * 2. Redistributions in binary form must reproduce the above copyright 1275115Sfenner * notice, this list of conditions and the following disclaimer in the 1375115Sfenner * documentation and/or other materials provided with the distribution. 1475115Sfenner * 1575115Sfenner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1675115Sfenner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1775115Sfenner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1875115Sfenner * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1975115Sfenner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2075115Sfenner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2175115Sfenner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2275115Sfenner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2375115Sfenner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2475115Sfenner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2575115Sfenner * SUCH DAMAGE. 2675115Sfenner * 2775115Sfenner * $FreeBSD: head/sys/netinet/ip_dummynet.h 239124 2012-08-07 07:52:25Z luigi $ 2875115Sfenner */ 2975115Sfenner 3075115Sfenner#ifndef _IP_DUMMYNET_H 3175115Sfenner#define _IP_DUMMYNET_H 3275115Sfenner 3375115Sfenner/* 3475115Sfenner * Definition of the kernel-userland API for dummynet. 3575115Sfenner * 3675115Sfenner * Setsockopt() and getsockopt() pass a batch of objects, each 37127668Sbms * of them starting with a "struct dn_id" which should fully identify 3875115Sfenner * the object and its relation with others in the sequence. 3975115Sfenner * The first object in each request should have 4075115Sfenner * type= DN_CMD_*, id = DN_API_VERSION. 4175115Sfenner * For other objects, type and subtype specify the object, len indicates 4275115Sfenner * the total length including the header, and 'id' identifies the specific 4375115Sfenner * object. 44127668Sbms * 4575115Sfenner * Most objects are numbered with an identifier in the range 1..65535. 4675115Sfenner * DN_MAX_ID indicates the first value outside the range. 4775115Sfenner */ 4875115Sfenner 4975115Sfenner#define DN_API_VERSION 12500000 5075115Sfenner#define DN_MAX_ID 0x10000 5175115Sfenner 5275115Sfennerstruct dn_id { 5375115Sfenner uint16_t len; /* total obj len including this header */ 5475115Sfenner uint8_t type; 5575115Sfenner uint8_t subtype; 5675115Sfenner uint32_t id; /* generic id */ 5775115Sfenner}; 5875115Sfenner 5975115Sfenner/* 6075115Sfenner * These values are in the type field of struct dn_id. 6175115Sfenner * To preserve the ABI, never rearrange the list or delete 6275115Sfenner * entries with the exception of DN_LAST 6375115Sfenner */ 6475115Sfennerenum { 6575115Sfenner DN_NONE = 0, 6675115Sfenner DN_LINK = 1, 6775115Sfenner DN_FS, 6875115Sfenner DN_SCH, 6975115Sfenner DN_SCH_I, 7075115Sfenner DN_QUEUE, 7175115Sfenner DN_DELAY_LINE, 7275115Sfenner DN_PROFILE, 7375115Sfenner DN_FLOW, /* struct dn_flow */ 7475115Sfenner DN_TEXT, /* opaque text is the object */ 7575115Sfenner 7675115Sfenner DN_CMD_CONFIG = 0x80, /* objects follow */ 7775115Sfenner DN_CMD_DELETE, /* subtype + list of entries */ 78172683Smlaier DN_CMD_GET, /* subtype + list of entries */ 79172683Smlaier DN_CMD_FLUSH, 80172683Smlaier /* for compatibility with FreeBSD 7.2/8 */ 81172683Smlaier DN_COMPAT_PIPE, 82172683Smlaier DN_COMPAT_QUEUE, 83172683Smlaier DN_GET_COMPAT, 84172683Smlaier 85172683Smlaier /* special commands for emulation of sysctl variables */ 86127668Sbms DN_SYSCTL_GET, 8775115Sfenner DN_SYSCTL_SET, 8875115Sfenner 8975115Sfenner DN_LAST, 9075115Sfenner}; 9175115Sfenner 9275115Sfennerenum { /* subtype for schedulers, flowset and the like */ 9375115Sfenner DN_SCHED_UNKNOWN = 0, 9475115Sfenner DN_SCHED_FIFO = 1, 9575115Sfenner DN_SCHED_WF2QP = 2, 9675115Sfenner /* others are in individual modules */ 9775115Sfenner}; 9875115Sfenner 9975115Sfennerenum { /* user flags */ 10075115Sfenner DN_HAVE_MASK = 0x0001, /* fs or sched has a mask */ 10175115Sfenner DN_NOERROR = 0x0002, /* do not report errors */ 10275115Sfenner DN_QHT_HASH = 0x0004, /* qht is a hash table */ 10375115Sfenner DN_QSIZE_BYTES = 0x0008, /* queue size is in bytes */ 10475115Sfenner DN_HAS_PROFILE = 0x0010, /* a link has a profile */ 10575115Sfenner DN_IS_RED = 0x0020, 10675115Sfenner DN_IS_GENTLE_RED= 0x0040, 10775115Sfenner DN_PIPE_CMD = 0x1000, /* pipe config... */ 10898524Sfenner}; 10998524Sfenner 11098524Sfenner/* 11198524Sfenner * link template. 11298524Sfenner */ 11398524Sfennerstruct dn_link { 11498524Sfenner struct dn_id oid; 11598524Sfenner 11698524Sfenner /* 11798524Sfenner * Userland sets bw and delay in bits/s and milliseconds. 11898524Sfenner * The kernel converts this back and forth to bits/tick and ticks. 11998524Sfenner * XXX what about burst ? 12098524Sfenner */ 12198524Sfenner int32_t link_nr; 12298524Sfenner int bandwidth; /* bit/s or bits/tick. */ 12398524Sfenner int delay; /* ms and ticks */ 12498524Sfenner uint64_t burst; /* scaled. bits*Hz XXX */ 12575115Sfenner}; 12675115Sfenner 12775115Sfenner/* 12875115Sfenner * A flowset, which is a template for flows. Contains parameters 12975115Sfenner * from the command line: id, target scheduler, queue sizes, plr, 13075115Sfenner * flow masks, buckets for the flow hash, and possibly scheduler- 13175115Sfenner * specific parameters (weight, quantum and so on). 13275115Sfenner */ 13375115Sfennerstruct dn_fs { 13475115Sfenner struct dn_id oid; 13575115Sfenner uint32_t fs_nr; /* the flowset number */ 13675115Sfenner uint32_t flags; /* userland flags */ 13775115Sfenner int qsize; /* queue size in slots or bytes */ 13875115Sfenner int32_t plr; /* PLR, pkt loss rate (2^31-1 means 100%) */ 13975115Sfenner uint32_t buckets; /* buckets used for the queue hash table */ 14075115Sfenner 14175115Sfenner struct ipfw_flow_id flow_mask; 14275115Sfenner uint32_t sched_nr; /* the scheduler we attach to */ 14375115Sfenner /* generic scheduler parameters. Leave them at -1 if unset. 14475115Sfenner * Now we use 0: weight, 1: lmax, 2: priority 14575115Sfenner */ 14675115Sfenner int par[4]; 14775115Sfenner 14875115Sfenner /* RED/GRED parameters. 14975115Sfenner * weight and probabilities are in the range 0..1 represented 15075115Sfenner * in fixed point arithmetic with SCALE_RED decimal bits. 15175115Sfenner */ 15275115Sfenner#define SCALE_RED 16 15375115Sfenner#define SCALE(x) ( (x) << SCALE_RED ) 15475115Sfenner#define SCALE_VAL(x) ( (x) >> SCALE_RED ) 15575115Sfenner#define SCALE_MUL(x,y) ( ( (x) * (y) ) >> SCALE_RED ) 15675115Sfenner int w_q ; /* queue weight (scaled) */ 15798524Sfenner int max_th ; /* maximum threshold for queue (scaled) */ 15898524Sfenner int min_th ; /* minimum threshold for queue (scaled) */ 15998524Sfenner int max_p ; /* maximum value for p_b (scaled) */ 16075115Sfenner 16175115Sfenner}; 16298524Sfenner 16398524Sfenner/* 16498524Sfenner * dn_flow collects flow_id and stats for queues and scheduler 16598524Sfenner * instances, and is used to pass these info to userland. 16698524Sfenner * oid.type/oid.subtype describe the object, oid.id is number 16798524Sfenner * of the parent object. 16898524Sfenner */ 16998524Sfennerstruct dn_flow { 17098524Sfenner struct dn_id oid; 17198524Sfenner struct ipfw_flow_id fid; 17298524Sfenner uint64_t tot_pkts; /* statistics counters */ 17398524Sfenner uint64_t tot_bytes; 174172683Smlaier uint32_t length; /* Queue length, in packets */ 175172683Smlaier uint32_t len_bytes; /* Queue length, in bytes */ 17698524Sfenner uint32_t drops; 17798524Sfenner}; 178172683Smlaier 17998524Sfenner 180172683Smlaier/* 181172683Smlaier * Scheduler template, mostly indicating the name, number, 182172683Smlaier * sched_mask and buckets. 183172683Smlaier */ 184172683Smlaierstruct dn_sch { 185172683Smlaier struct dn_id oid; 186172683Smlaier uint32_t sched_nr; /* N, scheduler number */ 18775115Sfenner uint32_t buckets; /* number of buckets for the instances */ 188172683Smlaier uint32_t flags; /* have_mask, ... */ 18975115Sfenner 19075115Sfenner char name[16]; /* null terminated */ 19175115Sfenner /* mask to select the appropriate scheduler instance */ 19275115Sfenner struct ipfw_flow_id sched_mask; /* M */ 19398524Sfenner}; 19475115Sfenner 19598524Sfenner 19698524Sfenner/* A delay profile is attached to a link. 19798524Sfenner * Note that a profile, as any other object, cannot be longer than 2^16 19875115Sfenner */ 19975115Sfenner#define ED_MAX_SAMPLES_NO 1024 20075115Sfennerstruct dn_profile { 20175115Sfenner struct dn_id oid; 20275115Sfenner /* fields to simulate a delay profile */ 20375115Sfenner#define ED_MAX_NAME_LEN 32 20475115Sfenner char name[ED_MAX_NAME_LEN]; 20575115Sfenner int link_nr; 20675115Sfenner int loss_level; 20775115Sfenner int bandwidth; // XXX use link bandwidth? 20875115Sfenner int samples_no; /* actual len of samples[] */ 20975115Sfenner int samples[ED_MAX_SAMPLES_NO]; /* may be shorter */ 21075115Sfenner}; 21175115Sfenner 212172683Smlaier 213172683Smlaier 21475115Sfenner/* 21575115Sfenner * Overall structure of dummynet 21675115Sfenner 21775115SfennerIn dummynet, packets are selected with the firewall rules, and passed 21875115Sfennerto two different objects: PIPE or QUEUE (bad name). 21975115Sfenner 22075115SfennerA QUEUE defines a classifier, which groups packets into flows 22175115Sfenneraccording to a 'mask', puts them into independent queues (one 22275115Sfennerper flow) with configurable size and queue management policy, 22375115Sfennerand passes flows to a scheduler: 22475115Sfenner 22575115Sfenner (flow_mask|sched_mask) sched_mask 22675115Sfenner +---------+ weight Wx +-------------+ 22775115Sfenner | |->-[flow]-->--| |-+ 22875115Sfenner -->--| QUEUE x | ... | | | 22975115Sfenner | |->-[flow]-->--| SCHEDuler N | | 23075115Sfenner +---------+ | | | 23175115Sfenner ... | +--[LINK N]-->-- 23275115Sfenner +---------+ weight Wy | | +--[LINK N]-->-- 23375115Sfenner | |->-[flow]-->--| | | 23475115Sfenner -->--| QUEUE y | ... | | | 23575115Sfenner | |->-[flow]-->--| | | 23675115Sfenner +---------+ +-------------+ | 23775115Sfenner +-------------+ 23875115Sfenner 23975115SfennerMany QUEUE objects can connect to the same scheduler, each 24075115SfennerQUEUE object can have its own set of parameters. 24175115Sfenner 24275115SfennerIn turn, the SCHEDuler 'forks' multiple instances according 24375115Sfennerto a 'sched_mask', each instance manages its own set of queues 24475115Sfennerand transmits on a private instance of a configurable LINK. 24575115Sfenner 24675115SfennerA PIPE is a simplified version of the above, where there 24775115Sfenneris no flow_mask, and each scheduler instance handles a single queue. 24875115Sfenner 24975115SfennerThe following data structures (visible from userland) describe 25075115Sfennerthe objects used by dummynet: 25175115Sfenner 25275115Sfenner + dn_link, contains the main configuration parameters related 25375115Sfenner to delay and bandwidth; 25475115Sfenner + dn_profile describes a delay profile; 25575115Sfenner + dn_flow describes the flow status (flow id, statistics) 256127668Sbms 25775115Sfenner + dn_sch describes a scheduler 25875115Sfenner + dn_fs describes a flowset (msk, weight, queue parameters) 25975115Sfenner 26075115Sfenner * 26175115Sfenner */ 26275115Sfenner 26375115Sfenner#endif /* _IP_DUMMYNET_H */ 26475115Sfenner