1 /* $OpenBSD: hfsc.h,v 1.11 2015/11/20 03:35:23 dlg Exp $ */ 2 3 /* 4 * Copyright (c) 2012-2013 Henning Brauer <henning@openbsd.org> 5 * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved. 6 * 7 * Permission to use, copy, modify, and distribute this software and 8 * its documentation is hereby granted (including for commercial or 9 * for-profit use), provided that both the copyright notice and this 10 * permission notice appear in all copies of the software, derivative 11 * works, or modified versions, and any portions thereof. 12 * 13 * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF 14 * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS 15 * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED 16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 25 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 26 * DAMAGE. 27 * 28 * Carnegie Mellon encourages (but does not require) users of this 29 * software to return any improvements or extensions that they make, 30 * and to grant Carnegie Mellon the rights to redistribute these 31 * changes without encumbrance. 32 */ 33 #ifndef _HFSC_H_ 34 #define _HFSC_H_ 35 36 /* hfsc class flags */ 37 #define HFSC_RED 0x0001 /* use RED */ 38 #define HFSC_ECN 0x0002 /* use RED/ECN */ 39 #define HFSC_RIO 0x0004 /* use RIO */ 40 #define HFSC_DEFAULTCLASS 0x1000 /* default class */ 41 42 struct hfsc_pktcntr { 43 u_int64_t packets; 44 u_int64_t bytes; 45 }; 46 47 #define PKTCNTR_INC(cntr, len) \ 48 do { (cntr)->packets++; (cntr)->bytes += len; } while (0) 49 50 struct hfsc_sc { 51 u_int m1; /* slope of the first segment in bits/sec */ 52 u_int d; /* the x-projection of the first segment in msec */ 53 u_int m2; /* slope of the second segment in bits/sec */ 54 }; 55 56 /* special class handles */ 57 #define HFSC_NULLCLASS_HANDLE 0 58 #define HFSC_DEFAULT_CLASSES 64 59 #define HFSC_MAX_CLASSES 65535 60 61 /* service curve types */ 62 #define HFSC_REALTIMESC 1 63 #define HFSC_LINKSHARINGSC 2 64 #define HFSC_UPPERLIMITSC 4 65 #define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC) 66 67 struct hfsc_class_stats { 68 u_int class_id; 69 u_int32_t class_handle; 70 struct hfsc_sc rsc; 71 struct hfsc_sc fsc; 72 struct hfsc_sc usc; /* upper limit service curve */ 73 74 u_int64_t total; /* total work in bytes */ 75 u_int64_t cumul; /* cumulative work in bytes 76 done by real-time criteria */ 77 u_int64_t d; /* deadline */ 78 u_int64_t e; /* eligible time */ 79 u_int64_t vt; /* virtual time */ 80 u_int64_t f; /* fit time for upper-limit */ 81 82 /* info helpful for debugging */ 83 u_int64_t initvt; /* init virtual time */ 84 u_int64_t vtoff; /* cl_vt_ipoff */ 85 u_int64_t cvtmax; /* cl_maxvt */ 86 u_int64_t myf; /* cl_myf */ 87 u_int64_t cfmin; /* cl_mincf */ 88 u_int64_t cvtmin; /* cl_mincvt */ 89 u_int64_t myfadj; /* cl_myfadj */ 90 u_int64_t vtadj; /* cl_vtadj */ 91 u_int64_t cur_time; 92 u_int32_t machclk_freq; 93 94 u_int qlength; 95 u_int qlimit; 96 struct hfsc_pktcntr xmit_cnt; 97 struct hfsc_pktcntr drop_cnt; 98 u_int period; 99 100 u_int vtperiod; /* vt period sequence no */ 101 u_int parentperiod; /* parent's vt period seqno */ 102 int nactive; /* number of active children */ 103 104 /* red and rio related info */ 105 int qtype; 106 /* struct redstats red[3]; */ 107 }; 108 109 #ifdef _KERNEL 110 struct ifnet; 111 struct ifqueue; 112 struct pf_queuespec; 113 struct hfsc_if; 114 115 extern const struct ifq_ops * const ifq_hfsc_ops; 116 117 #define HFSC_ENABLED(ifq) ((ifq)->ifq_ops == ifq_hfsc_ops) 118 #define HFSC_DEFAULT_QLIMIT 50 119 120 struct hfsc_if *hfsc_pf_alloc(struct ifnet *); 121 int hfsc_pf_addqueue(struct hfsc_if *, struct pf_queuespec *); 122 void hfsc_pf_free(struct hfsc_if *); 123 int hfsc_pf_qstats(struct pf_queuespec *, void *, int *); 124 125 void hfsc_initialize(void); 126 u_int64_t hfsc_microuptime(void); 127 128 #endif /* _KERNEL */ 129 #endif /* _HFSC_H_ */ 130