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> 37130365Smlaier#include <altq/altq_red.h> 38130365Smlaier#include <altq/altq_rio.h> 39130365Smlaier 40130365Smlaier#ifdef __cplusplus 41130365Smlaierextern "C" { 42130365Smlaier#endif 43130365Smlaier 44130365Smlaierstruct service_curve { 45130365Smlaier u_int m1; /* slope of the first segment in bits/sec */ 46130365Smlaier u_int d; /* the x-projection of the first segment in msec */ 47130365Smlaier u_int m2; /* slope of the second segment in bits/sec */ 48130365Smlaier}; 49130365Smlaier 50130365Smlaier/* special class handles */ 51130365Smlaier#define HFSC_NULLCLASS_HANDLE 0 52130365Smlaier#define HFSC_MAX_CLASSES 64 53130365Smlaier 54130365Smlaier/* hfsc class flags */ 55130365Smlaier#define HFCF_RED 0x0001 /* use RED */ 56130365Smlaier#define HFCF_ECN 0x0002 /* use RED/ECN */ 57130365Smlaier#define HFCF_RIO 0x0004 /* use RIO */ 58130365Smlaier#define HFCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */ 59130365Smlaier#define HFCF_DEFAULTCLASS 0x1000 /* default class */ 60130365Smlaier 61130365Smlaier/* service curve types */ 62130365Smlaier#define HFSC_REALTIMESC 1 63130365Smlaier#define HFSC_LINKSHARINGSC 2 64130365Smlaier#define HFSC_UPPERLIMITSC 4 65130365Smlaier#define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC) 66130365Smlaier 67130365Smlaierstruct hfsc_classstats { 68130365Smlaier u_int class_id; 69130365Smlaier u_int32_t class_handle; 70130365Smlaier struct service_curve rsc; 71130365Smlaier struct service_curve fsc; 72130365Smlaier struct service_curve usc; /* upper limit service curve */ 73130365Smlaier 74130365Smlaier u_int64_t total; /* total work in bytes */ 75130365Smlaier u_int64_t cumul; /* cumulative work in bytes 76130365Smlaier done by real-time criteria */ 77130365Smlaier u_int64_t d; /* deadline */ 78130365Smlaier u_int64_t e; /* eligible time */ 79130365Smlaier u_int64_t vt; /* virtual time */ 80130365Smlaier u_int64_t f; /* fit time for upper-limit */ 81130365Smlaier 82130365Smlaier /* info helpful for debugging */ 83130365Smlaier u_int64_t initvt; /* init virtual time */ 84130365Smlaier u_int64_t vtoff; /* cl_vt_ipoff */ 85130365Smlaier u_int64_t cvtmax; /* cl_maxvt */ 86130365Smlaier u_int64_t myf; /* cl_myf */ 87130365Smlaier u_int64_t cfmin; /* cl_mincf */ 88130365Smlaier u_int64_t cvtmin; /* cl_mincvt */ 89130365Smlaier u_int64_t myfadj; /* cl_myfadj */ 90130365Smlaier u_int64_t vtadj; /* cl_vtadj */ 91130365Smlaier u_int64_t cur_time; 92130365Smlaier u_int32_t machclk_freq; 93130365Smlaier 94130365Smlaier u_int qlength; 95130365Smlaier u_int qlimit; 96130365Smlaier struct pktcntr xmit_cnt; 97130365Smlaier struct pktcntr drop_cnt; 98130365Smlaier u_int period; 99130365Smlaier 100130365Smlaier u_int vtperiod; /* vt period sequence no */ 101130365Smlaier u_int parentperiod; /* parent's vt period seqno */ 102130365Smlaier int nactive; /* number of active children */ 103130365Smlaier 104130365Smlaier /* red and rio related info */ 105130365Smlaier int qtype; 106130365Smlaier struct redstats red[3]; 107130365Smlaier}; 108130365Smlaier 109130365Smlaier#ifdef ALTQ3_COMPAT 110130365Smlaierstruct hfsc_interface { 111130365Smlaier char hfsc_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */ 112130365Smlaier}; 113130365Smlaier 114130365Smlaierstruct hfsc_attach { 115130365Smlaier struct hfsc_interface iface; 116130365Smlaier u_int bandwidth; /* link bandwidth in bits/sec */ 117130365Smlaier}; 118130365Smlaier 119130365Smlaierstruct hfsc_add_class { 120130365Smlaier struct hfsc_interface iface; 121130365Smlaier u_int32_t parent_handle; 122130365Smlaier struct service_curve service_curve; 123130365Smlaier int qlimit; 124130365Smlaier int flags; 125130365Smlaier 126130365Smlaier u_int32_t class_handle; /* return value */ 127130365Smlaier}; 128130365Smlaier 129130365Smlaierstruct hfsc_delete_class { 130130365Smlaier struct hfsc_interface iface; 131130365Smlaier u_int32_t class_handle; 132130365Smlaier}; 133130365Smlaier 134130365Smlaierstruct hfsc_modify_class { 135130365Smlaier struct hfsc_interface iface; 136130365Smlaier u_int32_t class_handle; 137130365Smlaier struct service_curve service_curve; 138130365Smlaier int sctype; 139130365Smlaier}; 140130365Smlaier 141130365Smlaierstruct hfsc_add_filter { 142130365Smlaier struct hfsc_interface iface; 143130365Smlaier u_int32_t class_handle; 144130365Smlaier struct flow_filter filter; 145130365Smlaier 146130365Smlaier u_long filter_handle; /* return value */ 147130365Smlaier}; 148130365Smlaier 149130365Smlaierstruct hfsc_delete_filter { 150130365Smlaier struct hfsc_interface iface; 151130365Smlaier u_long filter_handle; 152130365Smlaier}; 153130365Smlaier 154130365Smlaierstruct hfsc_class_stats { 155130365Smlaier struct hfsc_interface iface; 156130365Smlaier int nskip; /* skip # of classes */ 157130365Smlaier int nclasses; /* # of class stats (WR) */ 158130365Smlaier u_int64_t cur_time; /* current time */ 159130365Smlaier u_int32_t machclk_freq; /* machine clock frequency */ 160130365Smlaier u_int hif_classes; /* # of classes in the tree */ 161130365Smlaier u_int hif_packets; /* # of packets in the tree */ 162130365Smlaier struct hfsc_classstats *stats; /* pointer to stats array */ 163130365Smlaier}; 164130365Smlaier 165130365Smlaier#define HFSC_IF_ATTACH _IOW('Q', 1, struct hfsc_attach) 166130365Smlaier#define HFSC_IF_DETACH _IOW('Q', 2, struct hfsc_interface) 167130365Smlaier#define HFSC_ENABLE _IOW('Q', 3, struct hfsc_interface) 168130365Smlaier#define HFSC_DISABLE _IOW('Q', 4, struct hfsc_interface) 169130365Smlaier#define HFSC_CLEAR_HIERARCHY _IOW('Q', 5, struct hfsc_interface) 170130365Smlaier#define HFSC_ADD_CLASS _IOWR('Q', 7, struct hfsc_add_class) 171130365Smlaier#define HFSC_DEL_CLASS _IOW('Q', 8, struct hfsc_delete_class) 172130365Smlaier#define HFSC_MOD_CLASS _IOW('Q', 9, struct hfsc_modify_class) 173130365Smlaier#define HFSC_ADD_FILTER _IOWR('Q', 10, struct hfsc_add_filter) 174130365Smlaier#define HFSC_DEL_FILTER _IOW('Q', 11, struct hfsc_delete_filter) 175130365Smlaier#define HFSC_GETSTATS _IOWR('Q', 12, struct hfsc_class_stats) 176130365Smlaier#endif /* ALTQ3_COMPAT */ 177130365Smlaier 178130365Smlaier#ifdef _KERNEL 179130365Smlaier/* 180130365Smlaier * kernel internal service curve representation 181130365Smlaier * coordinates are given by 64 bit unsigned integers. 182130365Smlaier * x-axis: unit is clock count. for the intel x86 architecture, 183130365Smlaier * the raw Pentium TSC (Timestamp Counter) value is used. 184130365Smlaier * virtual time is also calculated in this time scale. 185130365Smlaier * y-axis: unit is byte. 186130365Smlaier * 187130365Smlaier * the service curve parameters are converted to the internal 188130365Smlaier * representation. 189130365Smlaier * the slope values are scaled to avoid overflow. 190130365Smlaier * the inverse slope values as well as the y-projection of the 1st 191130365Smlaier * segment are kept in order to to avoid 64-bit divide operations 192130365Smlaier * that are expensive on 32-bit architectures. 193130365Smlaier * 194130365Smlaier * note: Intel Pentium TSC never wraps around in several thousands of years. 195130365Smlaier * x-axis doesn't wrap around for 1089 years with 1GHz clock. 196130365Smlaier * y-axis doesn't wrap around for 4358 years with 1Gbps bandwidth. 197130365Smlaier */ 198130365Smlaier 199130365Smlaier/* kernel internal representation of a service curve */ 200130365Smlaierstruct internal_sc { 201130365Smlaier u_int64_t sm1; /* scaled slope of the 1st segment */ 202130365Smlaier u_int64_t ism1; /* scaled inverse-slope of the 1st segment */ 203130365Smlaier u_int64_t dx; /* the x-projection of the 1st segment */ 204130365Smlaier u_int64_t dy; /* the y-projection of the 1st segment */ 205130365Smlaier u_int64_t sm2; /* scaled slope of the 2nd segment */ 206130365Smlaier u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */ 207130365Smlaier}; 208130365Smlaier 209130365Smlaier/* runtime service curve */ 210130365Smlaierstruct runtime_sc { 211130365Smlaier u_int64_t x; /* current starting position on x-axis */ 212130365Smlaier u_int64_t y; /* current starting position on x-axis */ 213130365Smlaier u_int64_t sm1; /* scaled slope of the 1st segment */ 214130365Smlaier u_int64_t ism1; /* scaled inverse-slope of the 1st segment */ 215130365Smlaier u_int64_t dx; /* the x-projection of the 1st segment */ 216130365Smlaier u_int64_t dy; /* the y-projection of the 1st segment */ 217130365Smlaier u_int64_t sm2; /* scaled slope of the 2nd segment */ 218130365Smlaier u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */ 219130365Smlaier}; 220130365Smlaier 221130365Smlaier/* for TAILQ based ellist and actlist implementation */ 222130365Smlaierstruct hfsc_class; 223130365Smlaiertypedef TAILQ_HEAD(_eligible, hfsc_class) ellist_t; 224130365Smlaiertypedef TAILQ_ENTRY(hfsc_class) elentry_t; 225130365Smlaiertypedef TAILQ_HEAD(_active, hfsc_class) actlist_t; 226130365Smlaiertypedef TAILQ_ENTRY(hfsc_class) actentry_t; 227130365Smlaier#define ellist_first(s) TAILQ_FIRST(s) 228130365Smlaier#define actlist_first(s) TAILQ_FIRST(s) 229130365Smlaier#define actlist_last(s) TAILQ_LAST(s, _active) 230130365Smlaier 231130365Smlaierstruct hfsc_class { 232130365Smlaier u_int cl_id; /* class id (just for debug) */ 233130365Smlaier u_int32_t cl_handle; /* class handle */ 234130365Smlaier struct hfsc_if *cl_hif; /* back pointer to struct hfsc_if */ 235130365Smlaier int cl_flags; /* misc flags */ 236130365Smlaier 237130365Smlaier struct hfsc_class *cl_parent; /* parent class */ 238130365Smlaier struct hfsc_class *cl_siblings; /* sibling classes */ 239130365Smlaier struct hfsc_class *cl_children; /* child classes */ 240130365Smlaier 241130365Smlaier class_queue_t *cl_q; /* class queue structure */ 242130365Smlaier struct red *cl_red; /* RED state */ 243130365Smlaier struct altq_pktattr *cl_pktattr; /* saved header used by ECN */ 244130365Smlaier 245130365Smlaier u_int64_t cl_total; /* total work in bytes */ 246130365Smlaier u_int64_t cl_cumul; /* cumulative work in bytes 247130365Smlaier done by real-time criteria */ 248130365Smlaier u_int64_t cl_d; /* deadline */ 249130365Smlaier u_int64_t cl_e; /* eligible time */ 250130365Smlaier u_int64_t cl_vt; /* virtual time */ 251130365Smlaier u_int64_t cl_f; /* time when this class will fit for 252130365Smlaier link-sharing, max(myf, cfmin) */ 253130365Smlaier u_int64_t cl_myf; /* my fit-time (as calculated from this 254130365Smlaier class's own upperlimit curve) */ 255130365Smlaier u_int64_t cl_myfadj; /* my fit-time adjustment 256130365Smlaier (to cancel history dependence) */ 257130365Smlaier u_int64_t cl_cfmin; /* earliest children's fit-time (used 258130365Smlaier with cl_myf to obtain cl_f) */ 259130365Smlaier u_int64_t cl_cvtmin; /* minimal virtual time among the 260130365Smlaier children fit for link-sharing 261130365Smlaier (monotonic within a period) */ 262130365Smlaier u_int64_t cl_vtadj; /* intra-period cumulative vt 263130365Smlaier adjustment */ 264130365Smlaier u_int64_t cl_vtoff; /* inter-period cumulative vt offset */ 265130365Smlaier u_int64_t cl_cvtmax; /* max child's vt in the last period */ 266130365Smlaier 267130365Smlaier u_int64_t cl_initvt; /* init virtual time (for debugging) */ 268130365Smlaier 269130365Smlaier struct internal_sc *cl_rsc; /* internal real-time service curve */ 270130365Smlaier struct internal_sc *cl_fsc; /* internal fair service curve */ 271130365Smlaier struct internal_sc *cl_usc; /* internal upperlimit service curve */ 272130365Smlaier struct runtime_sc cl_deadline; /* deadline curve */ 273130365Smlaier struct runtime_sc cl_eligible; /* eligible curve */ 274130365Smlaier struct runtime_sc cl_virtual; /* virtual curve */ 275130365Smlaier struct runtime_sc cl_ulimit; /* upperlimit curve */ 276130365Smlaier 277130365Smlaier u_int cl_vtperiod; /* vt period sequence no */ 278130365Smlaier u_int cl_parentperiod; /* parent's vt period seqno */ 279130365Smlaier int cl_nactive; /* number of active children */ 280130365Smlaier actlist_t *cl_actc; /* active children list */ 281130365Smlaier 282130365Smlaier actentry_t cl_actlist; /* active children list entry */ 283130365Smlaier elentry_t cl_ellist; /* eligible list entry */ 284130365Smlaier 285130365Smlaier struct { 286130365Smlaier struct pktcntr xmit_cnt; 287130365Smlaier struct pktcntr drop_cnt; 288130365Smlaier u_int period; 289130365Smlaier } cl_stats; 290130365Smlaier}; 291130365Smlaier 292130365Smlaier/* 293130365Smlaier * hfsc interface state 294130365Smlaier */ 295130365Smlaierstruct hfsc_if { 296130365Smlaier struct hfsc_if *hif_next; /* interface state list */ 297130365Smlaier struct ifaltq *hif_ifq; /* backpointer to ifaltq */ 298130365Smlaier struct hfsc_class *hif_rootclass; /* root class */ 299130365Smlaier struct hfsc_class *hif_defaultclass; /* default class */ 300130365Smlaier struct hfsc_class *hif_class_tbl[HFSC_MAX_CLASSES]; 301130365Smlaier struct hfsc_class *hif_pollcache; /* cache for poll operation */ 302130365Smlaier 303130365Smlaier u_int hif_classes; /* # of classes in the tree */ 304130365Smlaier u_int hif_packets; /* # of packets in the tree */ 305130365Smlaier u_int hif_classid; /* class id sequence number */ 306130365Smlaier 307130365Smlaier ellist_t *hif_eligible; /* eligible list */ 308130365Smlaier 309130365Smlaier#ifdef ALTQ3_CLFIER_COMPAT 310130365Smlaier struct acc_classifier hif_classifier; 311130365Smlaier#endif 312130365Smlaier}; 313130365Smlaier 314130365Smlaier#endif /* _KERNEL */ 315130365Smlaier 316130365Smlaier#ifdef __cplusplus 317130365Smlaier} 318130365Smlaier#endif 319130365Smlaier 320130365Smlaier#endif /* _ALTQ_ALTQ_HFSC_H_ */ 321