/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 1998-2010 Luigi Rizzo, Universita` di Pisa4* Portions Copyright (c) 2000 Akamba Corp.5* All rights reserved6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef _IP_DUMMYNET_H30#define _IP_DUMMYNET_H31#define NEW_AQM32/*33* Definition of the kernel-userland API for dummynet.34*35* Setsockopt() and getsockopt() pass a batch of objects, each36* of them starting with a "struct dn_id" which should fully identify37* the object and its relation with others in the sequence.38* The first object in each request should have39* type= DN_CMD_*, id = DN_API_VERSION.40* For other objects, type and subtype specify the object, len indicates41* the total length including the header, and 'id' identifies the specific42* object.43*44* Most objects are numbered with an identifier in the range 1..65535.45* DN_MAX_ID indicates the first value outside the range.46*/4748#define DN_API_VERSION 1250000049#define DN_MAX_ID 0x100005051struct dn_id {52uint16_t len; /* total obj len including this header */53uint8_t type;54uint8_t subtype;55uint32_t id; /* generic id */56};5758/*59* These values are in the type field of struct dn_id.60* To preserve the ABI, never rearrange the list or delete61* entries with the exception of DN_LAST62*/63enum {64DN_NONE = 0,65DN_LINK = 1,66DN_FS,67DN_SCH,68DN_SCH_I,69DN_QUEUE,70DN_DELAY_LINE,71DN_PROFILE,72DN_FLOW, /* struct dn_flow */73DN_TEXT, /* opaque text is the object */7475DN_CMD_CONFIG = 0x80, /* objects follow */76DN_CMD_DELETE, /* subtype + list of entries */77DN_CMD_GET, /* subtype + list of entries */78DN_CMD_FLUSH,79/* for compatibility with FreeBSD 7.2/8 */80DN_COMPAT_PIPE,81DN_COMPAT_QUEUE,82DN_GET_COMPAT,8384/* special commands for emulation of sysctl variables */85DN_SYSCTL_GET,86DN_SYSCTL_SET,87#ifdef NEW_AQM88/* subtypes used for setting/getting extra parameters.89* these subtypes used with IP_DUMMYNET3 command (get)90* and DN_TEXT (set). */91DN_AQM_PARAMS, /* AQM extra params */92DN_SCH_PARAMS, /* scheduler extra params */93#endif94DN_LAST,95};9697enum { /* subtype for schedulers, flowset and the like */98DN_SCHED_UNKNOWN = 0,99DN_SCHED_FIFO = 1,100DN_SCHED_WF2QP = 2,101/* others are in individual modules */102};103104enum { /* user flags */105DN_HAVE_MASK = 0x0001, /* fs or sched has a mask */106DN_NOERROR = 0x0002, /* do not report errors */107DN_QHT_HASH = 0x0004, /* qht is a hash table */108DN_QSIZE_BYTES = 0x0008, /* queue size is in bytes */109DN_HAS_PROFILE = 0x0010, /* a link has a profile */110DN_IS_RED = 0x0020,111DN_IS_GENTLE_RED= 0x0040,112DN_IS_ECN = 0x0080,113#ifdef NEW_AQM114DN_IS_AQM = 0x0100, /* AQMs: e.g Codel & PIE */115#endif116DN_PIPE_CMD = 0x1000, /* pipe config... */117};118119/*120* link template.121*/122struct dn_link {123struct dn_id oid;124125/*126* Userland sets bw and delay in bits/s and milliseconds.127* The kernel converts this back and forth to bits/tick and ticks.128* XXX what about burst ?129*/130int32_t link_nr;131uint32_t bandwidth; /* bit/s or bits/tick. */132int delay; /* ms and ticks */133uint64_t burst; /* scaled. bits*Hz XXX */134};135136/*137* A flowset, which is a template for flows. Contains parameters138* from the command line: id, target scheduler, queue sizes, plr,139* flow masks, buckets for the flow hash, and possibly scheduler-140* specific parameters (weight, quantum and so on).141*/142struct dn_fs {143struct dn_id oid;144uint32_t fs_nr; /* the flowset number */145uint32_t flags; /* userland flags */146int qsize; /* queue size in slots or bytes */147int32_t pl_state; /* packet loss state */148uint32_t buckets; /* buckets used for the queue hash table */149150struct ipfw_flow_id flow_mask;151uint32_t sched_nr; /* the scheduler we attach to */152/* generic scheduler parameters. Leave them at -1 if unset.153* Now we use 0: weight, 1: lmax, 2: priority154*/155int par[4];156157/* RED/GRED parameters.158* weight and probabilities are in the range 0..1 represented159* in fixed point arithmetic with SCALE_RED decimal bits.160*/161#define SCALE_RED 16162#define SCALE(x) ( (x) << SCALE_RED )163#define SCALE_VAL(x) ( (x) >> SCALE_RED )164#define SCALE_MUL(x,y) ( ( (x) * (y) ) >> SCALE_RED )165int w_q ; /* queue weight (scaled) */166int max_th ; /* maximum threshold for queue (scaled) */167int min_th ; /* minimum threshold for queue (scaled) */168int max_p ; /* maximum value for p_b (scaled) */169170int32_t plr[4]; /* PLR, pkt loss rate (2^31-1 means 100%) */171};172173/*174* dn_flow collects flow_id and stats for queues and scheduler175* instances, and is used to pass these info to userland.176* oid.type/oid.subtype describe the object, oid.id is number177* of the parent object.178*/179struct dn_flow {180struct dn_id oid;181struct ipfw_flow_id fid;182uint64_t tot_pkts; /* statistics counters */183uint64_t tot_bytes;184uint32_t length; /* Queue length, in packets */185uint32_t len_bytes; /* Queue length, in bytes */186uint32_t drops;187};188189/*190* Scheduler template, mostly indicating the name, number,191* sched_mask and buckets.192*/193struct dn_sch {194struct dn_id oid;195uint32_t sched_nr; /* N, scheduler number */196uint32_t buckets; /* number of buckets for the instances */197uint32_t flags; /* have_mask, ... */198199char name[16]; /* null terminated */200/* mask to select the appropriate scheduler instance */201struct ipfw_flow_id sched_mask; /* M */202};203204/* A delay profile is attached to a link.205* Note that a profile, as any other object, cannot be longer than 2^16206*/207#define ED_MAX_SAMPLES_NO 1024208struct dn_profile {209struct dn_id oid;210/* fields to simulate a delay profile */211#define ED_MAX_NAME_LEN 32212char name[ED_MAX_NAME_LEN];213int link_nr;214int loss_level;215uint32_t bandwidth; // XXX use link bandwidth?216int samples_no; /* actual len of samples[] */217int samples[ED_MAX_SAMPLES_NO]; /* may be shorter */218};219220#ifdef NEW_AQM221/* Extra parameters for AQM and scheduler.222* This struct is used to pass and retrieve parameters (configurations)223* to/from AQM and Scheduler.224*/225struct dn_extra_parms {226struct dn_id oid;227char name[16];228uint32_t nr;229#define DN_MAX_EXTRA_PARM 10230int64_t par[DN_MAX_EXTRA_PARM];231};232#endif233234/*235* Overall structure of dummynet236237In dummynet, packets are selected with the firewall rules, and passed238to two different objects: PIPE or QUEUE (bad name).239240A QUEUE defines a classifier, which groups packets into flows241according to a 'mask', puts them into independent queues (one242per flow) with configurable size and queue management policy,243and passes flows to a scheduler:244245(flow_mask|sched_mask) sched_mask246+---------+ weight Wx +-------------+247| |->-[flow]-->--| |-+248-->--| QUEUE x | ... | | |249| |->-[flow]-->--| SCHEDuler N | |250+---------+ | | |251... | +--[LINK N]-->--252+---------+ weight Wy | | +--[LINK N]-->--253| |->-[flow]-->--| | |254-->--| QUEUE y | ... | | |255| |->-[flow]-->--| | |256+---------+ +-------------+ |257+-------------+258259Many QUEUE objects can connect to the same scheduler, each260QUEUE object can have its own set of parameters.261262In turn, the SCHEDuler 'forks' multiple instances according263to a 'sched_mask', each instance manages its own set of queues264and transmits on a private instance of a configurable LINK.265266A PIPE is a simplified version of the above, where there267is no flow_mask, and each scheduler instance handles a single queue.268269The following data structures (visible from userland) describe270the objects used by dummynet:271272+ dn_link, contains the main configuration parameters related273to delay and bandwidth;274+ dn_profile describes a delay profile;275+ dn_flow describes the flow status (flow id, statistics)276277+ dn_sch describes a scheduler278+ dn_fs describes a flowset (msk, weight, queue parameters)279280*281*/282283#endif /* _IP_DUMMYNET_H */284285286