1/* $KAME: altq_hfsc.h,v 1.12 2003/12/05 05:40:46 kjc Exp $ */ 2 3/* 4 * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved. 5 * 6 * Permission to use, copy, modify, and distribute this software and 7 * its documentation is hereby granted (including for commercial or 8 * for-profit use), provided that both the copyright notice and this 9 * permission notice appear in all copies of the software, derivative 10 * works, or modified versions, and any portions thereof. 11 * 12 * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF 13 * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS 14 * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED 15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 20 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 21 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 22 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 24 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 * DAMAGE. 26 * 27 * Carnegie Mellon encourages (but does not require) users of this 28 * software to return any improvements or extensions that they make, 29 * and to grant Carnegie Mellon the rights to redistribute these 30 * changes without encumbrance. 31 */ 32#ifndef _ALTQ_ALTQ_HFSC_H_ 33#define _ALTQ_ALTQ_HFSC_H_ 34 35#include <altq/altq.h> 36#include <altq/altq_classq.h> 37#include <altq/altq_codel.h> 38#include <altq/altq_red.h> 39#include <altq/altq_rio.h> 40 41#ifdef __cplusplus 42extern "C" { 43#endif 44 45struct service_curve { 46 u_int m1; /* slope of the first segment in bits/sec */ 47 u_int d; /* the x-projection of the first segment in msec */ 48 u_int m2; /* slope of the second segment in bits/sec */ 49}; 50 51/* special class handles */ 52#define HFSC_NULLCLASS_HANDLE 0 53#define HFSC_MAX_CLASSES 64 54 55/* hfsc class flags */ 56#define HFCF_RED 0x0001 /* use RED */ 57#define HFCF_ECN 0x0002 /* use RED/ECN */ 58#define HFCF_RIO 0x0004 /* use RIO */ 59#define HFCF_CODEL 0x0008 /* use CoDel */ 60#define HFCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */ 61#define HFCF_DEFAULTCLASS 0x1000 /* default class */ 62 63/* service curve types */ 64#define HFSC_REALTIMESC 1 65#define HFSC_LINKSHARINGSC 2 66#define HFSC_UPPERLIMITSC 4 67#define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC) 68 69struct hfsc_classstats { 70 u_int class_id; 71 u_int32_t class_handle; 72 struct service_curve rsc; 73 struct service_curve fsc; 74 struct service_curve usc; /* upper limit service curve */ 75 76 u_int64_t total; /* total work in bytes */ 77 u_int64_t cumul; /* cumulative work in bytes 78 done by real-time criteria */ 79 u_int64_t d; /* deadline */ 80 u_int64_t e; /* eligible time */ 81 u_int64_t vt; /* virtual time */ 82 u_int64_t f; /* fit time for upper-limit */ 83 84 /* info helpful for debugging */ 85 u_int64_t initvt; /* init virtual time */ 86 u_int64_t vtoff; /* cl_vt_ipoff */ 87 u_int64_t cvtmax; /* cl_maxvt */ 88 u_int64_t myf; /* cl_myf */ 89 u_int64_t cfmin; /* cl_mincf */ 90 u_int64_t cvtmin; /* cl_mincvt */ 91 u_int64_t myfadj; /* cl_myfadj */ 92 u_int64_t vtadj; /* cl_vtadj */ 93 u_int64_t cur_time; 94 u_int32_t machclk_freq; 95 96 u_int qlength; 97 u_int qlimit; 98 struct pktcntr xmit_cnt; 99 struct pktcntr drop_cnt; 100 u_int period; 101 102 u_int vtperiod; /* vt period sequence no */ 103 u_int parentperiod; /* parent's vt period seqno */ 104 int nactive; /* number of active children */ 105 106 /* codel, red and rio related info */ 107 int qtype; 108 struct redstats red[3]; 109 struct codel_stats codel; 110}; 111 112#ifdef ALTQ3_COMPAT 113struct hfsc_interface { 114 char hfsc_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */ 115}; 116 117struct hfsc_attach { 118 struct hfsc_interface iface; 119 u_int bandwidth; /* link bandwidth in bits/sec */ 120}; 121 122struct hfsc_add_class { 123 struct hfsc_interface iface; 124 u_int32_t parent_handle; 125 struct service_curve service_curve; 126 int qlimit; 127 int flags; 128 129 u_int32_t class_handle; /* return value */ 130}; 131 132struct hfsc_delete_class { 133 struct hfsc_interface iface; 134 u_int32_t class_handle; 135}; 136 137struct hfsc_modify_class { 138 struct hfsc_interface iface; 139 u_int32_t class_handle; 140 struct service_curve service_curve; 141 int sctype; 142}; 143 144struct hfsc_add_filter { 145 struct hfsc_interface iface; 146 u_int32_t class_handle; 147 struct flow_filter filter; 148 149 u_long filter_handle; /* return value */ 150}; 151 152struct hfsc_delete_filter { 153 struct hfsc_interface iface; 154 u_long filter_handle; 155}; 156 157struct hfsc_class_stats { 158 struct hfsc_interface iface; 159 int nskip; /* skip # of classes */ 160 int nclasses; /* # of class stats (WR) */ 161 u_int64_t cur_time; /* current time */ 162 u_int32_t machclk_freq; /* machine clock frequency */ 163 u_int hif_classes; /* # of classes in the tree */ 164 u_int hif_packets; /* # of packets in the tree */ 165 struct hfsc_classstats *stats; /* pointer to stats array */ 166}; 167 168#define HFSC_IF_ATTACH _IOW('Q', 1, struct hfsc_attach) 169#define HFSC_IF_DETACH _IOW('Q', 2, struct hfsc_interface) 170#define HFSC_ENABLE _IOW('Q', 3, struct hfsc_interface) 171#define HFSC_DISABLE _IOW('Q', 4, struct hfsc_interface) 172#define HFSC_CLEAR_HIERARCHY _IOW('Q', 5, struct hfsc_interface) 173#define HFSC_ADD_CLASS _IOWR('Q', 7, struct hfsc_add_class) 174#define HFSC_DEL_CLASS _IOW('Q', 8, struct hfsc_delete_class) 175#define HFSC_MOD_CLASS _IOW('Q', 9, struct hfsc_modify_class) 176#define HFSC_ADD_FILTER _IOWR('Q', 10, struct hfsc_add_filter) 177#define HFSC_DEL_FILTER _IOW('Q', 11, struct hfsc_delete_filter) 178#define HFSC_GETSTATS _IOWR('Q', 12, struct hfsc_class_stats) 179#endif /* ALTQ3_COMPAT */ 180 181#ifdef _KERNEL 182/* 183 * kernel internal service curve representation 184 * coordinates are given by 64 bit unsigned integers. 185 * x-axis: unit is clock count. for the intel x86 architecture, 186 * the raw Pentium TSC (Timestamp Counter) value is used. 187 * virtual time is also calculated in this time scale. 188 * y-axis: unit is byte. 189 * 190 * the service curve parameters are converted to the internal 191 * representation. 192 * the slope values are scaled to avoid overflow. 193 * the inverse slope values as well as the y-projection of the 1st 194 * segment are kept in order to to avoid 64-bit divide operations 195 * that are expensive on 32-bit architectures. 196 * 197 * note: Intel Pentium TSC never wraps around in several thousands of years. 198 * x-axis doesn't wrap around for 1089 years with 1GHz clock. 199 * y-axis doesn't wrap around for 4358 years with 1Gbps bandwidth. 200 */ 201 202/* kernel internal representation of a service curve */ 203struct internal_sc { 204 u_int64_t sm1; /* scaled slope of the 1st segment */ 205 u_int64_t ism1; /* scaled inverse-slope of the 1st segment */ 206 u_int64_t dx; /* the x-projection of the 1st segment */ 207 u_int64_t dy; /* the y-projection of the 1st segment */ 208 u_int64_t sm2; /* scaled slope of the 2nd segment */ 209 u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */ 210}; 211 212/* runtime service curve */ 213struct runtime_sc { 214 u_int64_t x; /* current starting position on x-axis */ 215 u_int64_t y; /* current starting position on x-axis */ 216 u_int64_t sm1; /* scaled slope of the 1st segment */ 217 u_int64_t ism1; /* scaled inverse-slope of the 1st segment */ 218 u_int64_t dx; /* the x-projection of the 1st segment */ 219 u_int64_t dy; /* the y-projection of the 1st segment */ 220 u_int64_t sm2; /* scaled slope of the 2nd segment */ 221 u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */ 222}; 223 224struct hfsc_class { 225 u_int cl_id; /* class id (just for debug) */ 226 u_int32_t cl_handle; /* class handle */ 227 struct hfsc_if *cl_hif; /* back pointer to struct hfsc_if */ 228 int cl_flags; /* misc flags */ 229 230 struct hfsc_class *cl_parent; /* parent class */ 231 struct hfsc_class *cl_siblings; /* sibling classes */ 232 struct hfsc_class *cl_children; /* child classes */ 233 234 class_queue_t *cl_q; /* class queue structure */ 235 union { 236 struct red *cl_red; /* RED state */ 237 struct codel *cl_codel; /* CoDel state */ 238 } cl_aqm; 239#define cl_red cl_aqm.cl_red 240#define cl_codel cl_aqm.cl_codel 241 struct altq_pktattr *cl_pktattr; /* saved header used by ECN */ 242 243 u_int64_t cl_total; /* total work in bytes */ 244 u_int64_t cl_cumul; /* cumulative work in bytes 245 done by real-time criteria */ 246 u_int64_t cl_d; /* deadline */ 247 u_int64_t cl_e; /* eligible time */ 248 u_int64_t cl_vt; /* virtual time */ 249 u_int64_t cl_f; /* time when this class will fit for 250 link-sharing, max(myf, cfmin) */ 251 u_int64_t cl_myf; /* my fit-time (as calculated from this 252 class's own upperlimit curve) */ 253 u_int64_t cl_myfadj; /* my fit-time adjustment 254 (to cancel history dependence) */ 255 u_int64_t cl_cfmin; /* earliest children's fit-time (used 256 with cl_myf to obtain cl_f) */ 257 u_int64_t cl_cvtmin; /* minimal virtual time among the 258 children fit for link-sharing 259 (monotonic within a period) */ 260 u_int64_t cl_vtadj; /* intra-period cumulative vt 261 adjustment */ 262 u_int64_t cl_vtoff; /* inter-period cumulative vt offset */ 263 u_int64_t cl_cvtmax; /* max child's vt in the last period */ 264 265 u_int64_t cl_initvt; /* init virtual time (for debugging) */ 266 267 struct internal_sc *cl_rsc; /* internal real-time service curve */ 268 struct internal_sc *cl_fsc; /* internal fair service curve */ 269 struct internal_sc *cl_usc; /* internal upperlimit service curve */ 270 struct runtime_sc cl_deadline; /* deadline curve */ 271 struct runtime_sc cl_eligible; /* eligible curve */ 272 struct runtime_sc cl_virtual; /* virtual curve */ 273 struct runtime_sc cl_ulimit; /* upperlimit curve */ 274 275 u_int cl_vtperiod; /* vt period sequence no */ 276 u_int cl_parentperiod; /* parent's vt period seqno */ 277 int cl_nactive; /* number of active children */ 278 279 TAILQ_HEAD(acthead, hfsc_class) cl_actc; /* active children list */ 280 TAILQ_ENTRY(hfsc_class) cl_actlist; /* active children list entry */ 281 TAILQ_ENTRY(hfsc_class) cl_ellist; /* eligible list entry */ 282 283 struct { 284 struct pktcntr xmit_cnt; 285 struct pktcntr drop_cnt; 286 u_int period; 287 } cl_stats; 288}; 289 290/* 291 * hfsc interface state 292 */ 293struct hfsc_if { 294 struct hfsc_if *hif_next; /* interface state list */ 295 struct ifaltq *hif_ifq; /* backpointer to ifaltq */ 296 struct hfsc_class *hif_rootclass; /* root class */ 297 struct hfsc_class *hif_defaultclass; /* default class */ 298 struct hfsc_class *hif_class_tbl[HFSC_MAX_CLASSES]; 299 struct hfsc_class *hif_pollcache; /* cache for poll operation */ 300 301 u_int hif_classes; /* # of classes in the tree */ 302 u_int hif_packets; /* # of packets in the tree */ 303 u_int hif_classid; /* class id sequence number */ 304 305 TAILQ_HEAD(elighead, hfsc_class) hif_eligible; /* eligible list */ 306 307#ifdef ALTQ3_CLFIER_COMPAT 308 struct acc_classifier hif_classifier; 309#endif 310}; 311 312#endif /* _KERNEL */ 313 314#ifdef __cplusplus 315} 316#endif 317 318#endif /* _ALTQ_ALTQ_HFSC_H_ */ 319