1130365Smlaier/* $KAME: altq_hfsc.h,v 1.12 2003/12/05 05:40:46 kjc Exp $ */ 2130365Smlaier 3130365Smlaier/* 4130365Smlaier * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved. 5130365Smlaier * 6130365Smlaier * Permission to use, copy, modify, and distribute this software and 7130365Smlaier * its documentation is hereby granted (including for commercial or 8130365Smlaier * for-profit use), provided that both the copyright notice and this 9130365Smlaier * permission notice appear in all copies of the software, derivative 10130365Smlaier * works, or modified versions, and any portions thereof. 11130365Smlaier * 12130365Smlaier * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF 13130365Smlaier * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS 14130365Smlaier * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED 15130365Smlaier * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16130365Smlaier * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17130365Smlaier * DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 18130365Smlaier * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19130365Smlaier * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 20130365Smlaier * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 21130365Smlaier * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22130365Smlaier * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23130365Smlaier * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24130365Smlaier * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25130365Smlaier * DAMAGE. 26130365Smlaier * 27130365Smlaier * Carnegie Mellon encourages (but does not require) users of this 28130365Smlaier * software to return any improvements or extensions that they make, 29130365Smlaier * and to grant Carnegie Mellon the rights to redistribute these 30130365Smlaier * changes without encumbrance. 31130365Smlaier */ 32130365Smlaier#ifndef _ALTQ_ALTQ_HFSC_H_ 33130365Smlaier#define _ALTQ_ALTQ_HFSC_H_ 34130365Smlaier 35130365Smlaier#include <altq/altq.h> 36130365Smlaier#include <altq/altq_classq.h> 37298133Sloos#include <altq/altq_codel.h> 38130365Smlaier#include <altq/altq_red.h> 39130365Smlaier#include <altq/altq_rio.h> 40130365Smlaier 41130365Smlaier#ifdef __cplusplus 42130365Smlaierextern "C" { 43130365Smlaier#endif 44130365Smlaier 45130365Smlaierstruct service_curve { 46130365Smlaier u_int m1; /* slope of the first segment in bits/sec */ 47130365Smlaier u_int d; /* the x-projection of the first segment in msec */ 48130365Smlaier u_int m2; /* slope of the second segment in bits/sec */ 49130365Smlaier}; 50130365Smlaier 51130365Smlaier/* special class handles */ 52130365Smlaier#define HFSC_NULLCLASS_HANDLE 0 53130365Smlaier#define HFSC_MAX_CLASSES 64 54130365Smlaier 55130365Smlaier/* hfsc class flags */ 56130365Smlaier#define HFCF_RED 0x0001 /* use RED */ 57130365Smlaier#define HFCF_ECN 0x0002 /* use RED/ECN */ 58130365Smlaier#define HFCF_RIO 0x0004 /* use RIO */ 59298133Sloos#define HFCF_CODEL 0x0008 /* use CoDel */ 60130365Smlaier#define HFCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */ 61130365Smlaier#define HFCF_DEFAULTCLASS 0x1000 /* default class */ 62130365Smlaier 63130365Smlaier/* service curve types */ 64130365Smlaier#define HFSC_REALTIMESC 1 65130365Smlaier#define HFSC_LINKSHARINGSC 2 66130365Smlaier#define HFSC_UPPERLIMITSC 4 67130365Smlaier#define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC) 68130365Smlaier 69130365Smlaierstruct hfsc_classstats { 70130365Smlaier u_int class_id; 71130365Smlaier u_int32_t class_handle; 72130365Smlaier struct service_curve rsc; 73130365Smlaier struct service_curve fsc; 74130365Smlaier struct service_curve usc; /* upper limit service curve */ 75130365Smlaier 76130365Smlaier u_int64_t total; /* total work in bytes */ 77130365Smlaier u_int64_t cumul; /* cumulative work in bytes 78130365Smlaier done by real-time criteria */ 79130365Smlaier u_int64_t d; /* deadline */ 80130365Smlaier u_int64_t e; /* eligible time */ 81130365Smlaier u_int64_t vt; /* virtual time */ 82130365Smlaier u_int64_t f; /* fit time for upper-limit */ 83130365Smlaier 84130365Smlaier /* info helpful for debugging */ 85130365Smlaier u_int64_t initvt; /* init virtual time */ 86130365Smlaier u_int64_t vtoff; /* cl_vt_ipoff */ 87130365Smlaier u_int64_t cvtmax; /* cl_maxvt */ 88130365Smlaier u_int64_t myf; /* cl_myf */ 89130365Smlaier u_int64_t cfmin; /* cl_mincf */ 90130365Smlaier u_int64_t cvtmin; /* cl_mincvt */ 91130365Smlaier u_int64_t myfadj; /* cl_myfadj */ 92130365Smlaier u_int64_t vtadj; /* cl_vtadj */ 93130365Smlaier u_int64_t cur_time; 94130365Smlaier u_int32_t machclk_freq; 95130365Smlaier 96130365Smlaier u_int qlength; 97130365Smlaier u_int qlimit; 98130365Smlaier struct pktcntr xmit_cnt; 99130365Smlaier struct pktcntr drop_cnt; 100130365Smlaier u_int period; 101130365Smlaier 102130365Smlaier u_int vtperiod; /* vt period sequence no */ 103130365Smlaier u_int parentperiod; /* parent's vt period seqno */ 104130365Smlaier int nactive; /* number of active children */ 105130365Smlaier 106298133Sloos /* codel, red and rio related info */ 107130365Smlaier int qtype; 108130365Smlaier struct redstats red[3]; 109298133Sloos struct codel_stats codel; 110130365Smlaier}; 111130365Smlaier 112130365Smlaier#ifdef ALTQ3_COMPAT 113130365Smlaierstruct hfsc_interface { 114130365Smlaier char hfsc_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */ 115130365Smlaier}; 116130365Smlaier 117130365Smlaierstruct hfsc_attach { 118130365Smlaier struct hfsc_interface iface; 119130365Smlaier u_int bandwidth; /* link bandwidth in bits/sec */ 120130365Smlaier}; 121130365Smlaier 122130365Smlaierstruct hfsc_add_class { 123130365Smlaier struct hfsc_interface iface; 124130365Smlaier u_int32_t parent_handle; 125130365Smlaier struct service_curve service_curve; 126130365Smlaier int qlimit; 127130365Smlaier int flags; 128130365Smlaier 129130365Smlaier u_int32_t class_handle; /* return value */ 130130365Smlaier}; 131130365Smlaier 132130365Smlaierstruct hfsc_delete_class { 133130365Smlaier struct hfsc_interface iface; 134130365Smlaier u_int32_t class_handle; 135130365Smlaier}; 136130365Smlaier 137130365Smlaierstruct hfsc_modify_class { 138130365Smlaier struct hfsc_interface iface; 139130365Smlaier u_int32_t class_handle; 140130365Smlaier struct service_curve service_curve; 141130365Smlaier int sctype; 142130365Smlaier}; 143130365Smlaier 144130365Smlaierstruct hfsc_add_filter { 145130365Smlaier struct hfsc_interface iface; 146130365Smlaier u_int32_t class_handle; 147130365Smlaier struct flow_filter filter; 148130365Smlaier 149130365Smlaier u_long filter_handle; /* return value */ 150130365Smlaier}; 151130365Smlaier 152130365Smlaierstruct hfsc_delete_filter { 153130365Smlaier struct hfsc_interface iface; 154130365Smlaier u_long filter_handle; 155130365Smlaier}; 156130365Smlaier 157130365Smlaierstruct hfsc_class_stats { 158130365Smlaier struct hfsc_interface iface; 159130365Smlaier int nskip; /* skip # of classes */ 160130365Smlaier int nclasses; /* # of class stats (WR) */ 161130365Smlaier u_int64_t cur_time; /* current time */ 162130365Smlaier u_int32_t machclk_freq; /* machine clock frequency */ 163130365Smlaier u_int hif_classes; /* # of classes in the tree */ 164130365Smlaier u_int hif_packets; /* # of packets in the tree */ 165130365Smlaier struct hfsc_classstats *stats; /* pointer to stats array */ 166130365Smlaier}; 167130365Smlaier 168130365Smlaier#define HFSC_IF_ATTACH _IOW('Q', 1, struct hfsc_attach) 169130365Smlaier#define HFSC_IF_DETACH _IOW('Q', 2, struct hfsc_interface) 170130365Smlaier#define HFSC_ENABLE _IOW('Q', 3, struct hfsc_interface) 171130365Smlaier#define HFSC_DISABLE _IOW('Q', 4, struct hfsc_interface) 172130365Smlaier#define HFSC_CLEAR_HIERARCHY _IOW('Q', 5, struct hfsc_interface) 173130365Smlaier#define HFSC_ADD_CLASS _IOWR('Q', 7, struct hfsc_add_class) 174130365Smlaier#define HFSC_DEL_CLASS _IOW('Q', 8, struct hfsc_delete_class) 175130365Smlaier#define HFSC_MOD_CLASS _IOW('Q', 9, struct hfsc_modify_class) 176130365Smlaier#define HFSC_ADD_FILTER _IOWR('Q', 10, struct hfsc_add_filter) 177130365Smlaier#define HFSC_DEL_FILTER _IOW('Q', 11, struct hfsc_delete_filter) 178130365Smlaier#define HFSC_GETSTATS _IOWR('Q', 12, struct hfsc_class_stats) 179130365Smlaier#endif /* ALTQ3_COMPAT */ 180130365Smlaier 181130365Smlaier#ifdef _KERNEL 182130365Smlaier/* 183130365Smlaier * kernel internal service curve representation 184130365Smlaier * coordinates are given by 64 bit unsigned integers. 185130365Smlaier * x-axis: unit is clock count. for the intel x86 architecture, 186130365Smlaier * the raw Pentium TSC (Timestamp Counter) value is used. 187130365Smlaier * virtual time is also calculated in this time scale. 188130365Smlaier * y-axis: unit is byte. 189130365Smlaier * 190130365Smlaier * the service curve parameters are converted to the internal 191130365Smlaier * representation. 192130365Smlaier * the slope values are scaled to avoid overflow. 193130365Smlaier * the inverse slope values as well as the y-projection of the 1st 194130365Smlaier * segment are kept in order to to avoid 64-bit divide operations 195130365Smlaier * that are expensive on 32-bit architectures. 196130365Smlaier * 197130365Smlaier * note: Intel Pentium TSC never wraps around in several thousands of years. 198130365Smlaier * x-axis doesn't wrap around for 1089 years with 1GHz clock. 199130365Smlaier * y-axis doesn't wrap around for 4358 years with 1Gbps bandwidth. 200130365Smlaier */ 201130365Smlaier 202130365Smlaier/* kernel internal representation of a service curve */ 203130365Smlaierstruct internal_sc { 204130365Smlaier u_int64_t sm1; /* scaled slope of the 1st segment */ 205130365Smlaier u_int64_t ism1; /* scaled inverse-slope of the 1st segment */ 206130365Smlaier u_int64_t dx; /* the x-projection of the 1st segment */ 207130365Smlaier u_int64_t dy; /* the y-projection of the 1st segment */ 208130365Smlaier u_int64_t sm2; /* scaled slope of the 2nd segment */ 209130365Smlaier u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */ 210130365Smlaier}; 211130365Smlaier 212130365Smlaier/* runtime service curve */ 213130365Smlaierstruct runtime_sc { 214130365Smlaier u_int64_t x; /* current starting position on x-axis */ 215130365Smlaier u_int64_t y; /* current starting position on x-axis */ 216130365Smlaier u_int64_t sm1; /* scaled slope of the 1st segment */ 217130365Smlaier u_int64_t ism1; /* scaled inverse-slope of the 1st segment */ 218130365Smlaier u_int64_t dx; /* the x-projection of the 1st segment */ 219130365Smlaier u_int64_t dy; /* the y-projection of the 1st segment */ 220130365Smlaier u_int64_t sm2; /* scaled slope of the 2nd segment */ 221130365Smlaier u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */ 222130365Smlaier}; 223130365Smlaier 224130365Smlaierstruct hfsc_class { 225130365Smlaier u_int cl_id; /* class id (just for debug) */ 226130365Smlaier u_int32_t cl_handle; /* class handle */ 227130365Smlaier struct hfsc_if *cl_hif; /* back pointer to struct hfsc_if */ 228130365Smlaier int cl_flags; /* misc flags */ 229130365Smlaier 230130365Smlaier struct hfsc_class *cl_parent; /* parent class */ 231130365Smlaier struct hfsc_class *cl_siblings; /* sibling classes */ 232130365Smlaier struct hfsc_class *cl_children; /* child classes */ 233130365Smlaier 234130365Smlaier class_queue_t *cl_q; /* class queue structure */ 235298133Sloos union { 236298133Sloos struct red *cl_red; /* RED state */ 237298133Sloos struct codel *cl_codel; /* CoDel state */ 238298133Sloos } cl_aqm; 239298133Sloos#define cl_red cl_aqm.cl_red 240298133Sloos#define cl_codel cl_aqm.cl_codel 241130365Smlaier struct altq_pktattr *cl_pktattr; /* saved header used by ECN */ 242130365Smlaier 243130365Smlaier u_int64_t cl_total; /* total work in bytes */ 244130365Smlaier u_int64_t cl_cumul; /* cumulative work in bytes 245130365Smlaier done by real-time criteria */ 246130365Smlaier u_int64_t cl_d; /* deadline */ 247130365Smlaier u_int64_t cl_e; /* eligible time */ 248130365Smlaier u_int64_t cl_vt; /* virtual time */ 249130365Smlaier u_int64_t cl_f; /* time when this class will fit for 250130365Smlaier link-sharing, max(myf, cfmin) */ 251130365Smlaier u_int64_t cl_myf; /* my fit-time (as calculated from this 252130365Smlaier class's own upperlimit curve) */ 253130365Smlaier u_int64_t cl_myfadj; /* my fit-time adjustment 254130365Smlaier (to cancel history dependence) */ 255130365Smlaier u_int64_t cl_cfmin; /* earliest children's fit-time (used 256130365Smlaier with cl_myf to obtain cl_f) */ 257130365Smlaier u_int64_t cl_cvtmin; /* minimal virtual time among the 258130365Smlaier children fit for link-sharing 259130365Smlaier (monotonic within a period) */ 260130365Smlaier u_int64_t cl_vtadj; /* intra-period cumulative vt 261130365Smlaier adjustment */ 262130365Smlaier u_int64_t cl_vtoff; /* inter-period cumulative vt offset */ 263130365Smlaier u_int64_t cl_cvtmax; /* max child's vt in the last period */ 264130365Smlaier 265130365Smlaier u_int64_t cl_initvt; /* init virtual time (for debugging) */ 266130365Smlaier 267130365Smlaier struct internal_sc *cl_rsc; /* internal real-time service curve */ 268130365Smlaier struct internal_sc *cl_fsc; /* internal fair service curve */ 269130365Smlaier struct internal_sc *cl_usc; /* internal upperlimit service curve */ 270130365Smlaier struct runtime_sc cl_deadline; /* deadline curve */ 271130365Smlaier struct runtime_sc cl_eligible; /* eligible curve */ 272130365Smlaier struct runtime_sc cl_virtual; /* virtual curve */ 273130365Smlaier struct runtime_sc cl_ulimit; /* upperlimit curve */ 274130365Smlaier 275130365Smlaier u_int cl_vtperiod; /* vt period sequence no */ 276130365Smlaier u_int cl_parentperiod; /* parent's vt period seqno */ 277130365Smlaier int cl_nactive; /* number of active children */ 278130365Smlaier 279247830Sglebius TAILQ_HEAD(acthead, hfsc_class) cl_actc; /* active children list */ 280247830Sglebius TAILQ_ENTRY(hfsc_class) cl_actlist; /* active children list entry */ 281247830Sglebius TAILQ_ENTRY(hfsc_class) cl_ellist; /* eligible list entry */ 282130365Smlaier 283130365Smlaier struct { 284130365Smlaier struct pktcntr xmit_cnt; 285130365Smlaier struct pktcntr drop_cnt; 286130365Smlaier u_int period; 287130365Smlaier } cl_stats; 288130365Smlaier}; 289130365Smlaier 290130365Smlaier/* 291130365Smlaier * hfsc interface state 292130365Smlaier */ 293130365Smlaierstruct hfsc_if { 294130365Smlaier struct hfsc_if *hif_next; /* interface state list */ 295130365Smlaier struct ifaltq *hif_ifq; /* backpointer to ifaltq */ 296130365Smlaier struct hfsc_class *hif_rootclass; /* root class */ 297130365Smlaier struct hfsc_class *hif_defaultclass; /* default class */ 298130365Smlaier struct hfsc_class *hif_class_tbl[HFSC_MAX_CLASSES]; 299130365Smlaier struct hfsc_class *hif_pollcache; /* cache for poll operation */ 300130365Smlaier 301130365Smlaier u_int hif_classes; /* # of classes in the tree */ 302130365Smlaier u_int hif_packets; /* # of packets in the tree */ 303130365Smlaier u_int hif_classid; /* class id sequence number */ 304130365Smlaier 305247830Sglebius TAILQ_HEAD(elighead, hfsc_class) hif_eligible; /* eligible list */ 306130365Smlaier 307130365Smlaier#ifdef ALTQ3_CLFIER_COMPAT 308130365Smlaier struct acc_classifier hif_classifier; 309130365Smlaier#endif 310130365Smlaier}; 311130365Smlaier 312130365Smlaier#endif /* _KERNEL */ 313130365Smlaier 314130365Smlaier#ifdef __cplusplus 315130365Smlaier} 316130365Smlaier#endif 317130365Smlaier 318130365Smlaier#endif /* _ALTQ_ALTQ_HFSC_H_ */ 319