Home | History | Annotate | Line # | Download | only in altq
altq_hfsc.h revision 1.1
      1 /*	$KAME: altq_hfsc.h,v 1.6 2000/12/14 08:12:46 thorpej 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, and that
     11  * both notices appear in supporting documentation, and that credit
     12  * is given to Carnegie Mellon University in all publications reporting
     13  * on direct or indirect use of this code or its derivatives.
     14  *
     15  * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF
     16  * WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON PROVIDES THIS
     17  * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED
     18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     20  * DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
     21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
     23  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
     27  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
     28  * DAMAGE.
     29  *
     30  * Carnegie Mellon encourages (but does not require) users of this
     31  * software to return any improvements or extensions that they make,
     32  * and to grant Carnegie Mellon the rights to redistribute these
     33  * changes without encumbrance.
     34  */
     35 #ifndef _ALTQ_ALTQ_HFSC_H_
     36 #define	_ALTQ_ALTQ_HFSC_H_
     37 
     38 #include <altq/altq.h>
     39 #include <altq/altq_classq.h>
     40 #include <altq/altq_red.h>
     41 #include <altq/altq_rio.h>
     42 
     43 #ifdef __cplusplus
     44 extern "C" {
     45 #endif
     46 
     47 struct hfsc_interface {
     48 	char	hfsc_ifname[IFNAMSIZ];  /* interface name (e.g., fxp0) */
     49 };
     50 
     51 struct hfsc_attach {
     52 	struct hfsc_interface	iface;
     53 	u_int			bandwidth;  /* link bandwidth in bits/sec */
     54 };
     55 
     56 struct service_curve {
     57 	u_int	m1;	/* slope of the first segment in bits/sec */
     58 	u_int	d;	/* the x-projection of the first segment in msec */
     59 	u_int	m2;	/* slope of the second segment in bits/sec */
     60 };
     61 
     62 struct hfsc_add_class {
     63 	struct hfsc_interface	iface;
     64 	u_long			parent_handle;
     65 	struct service_curve	service_curve;
     66 	int			qlimit;
     67 	int			flags;
     68 
     69 	u_long			class_handle;  /* return value */
     70 };
     71 
     72 /* special class handles */
     73 #define	HFSC_ROOTCLASS_HANDLE	0
     74 #define	HFSC_NULLCLASS_HANDLE	0
     75 
     76 /* hfsc class flags */
     77 #define	HFCF_RED		0x0001	/* use RED */
     78 #define	HFCF_ECN		0x0002  /* use RED/ECN */
     79 #define	HFCF_RIO		0x0004  /* use RIO */
     80 #define	HFCF_CLEARDSCP		0x0010  /* clear diffserv codepoint */
     81 #define	HFCF_DEFAULTCLASS	0x1000	/* default class */
     82 
     83 struct hfsc_delete_class {
     84 	struct hfsc_interface	iface;
     85 	u_long			class_handle;
     86 };
     87 
     88 /* service curve types */
     89 #define	HFSC_REALTIMESC		1
     90 #define	HFSC_LINKSHARINGSC	2
     91 #define	HFSC_DEFAULTSC		(HFSC_REALTIMESC|HFSC_LINKSHARINGSC)
     92 
     93 struct hfsc_modify_class {
     94 	struct hfsc_interface	iface;
     95 	u_long			class_handle;
     96 	struct service_curve	service_curve;
     97 	int			sctype;
     98 };
     99 
    100 struct hfsc_add_filter {
    101 	struct hfsc_interface	iface;
    102 	u_long			class_handle;
    103 	struct flow_filter	filter;
    104 
    105 	u_long			filter_handle;  /* return value */
    106 };
    107 
    108 struct hfsc_delete_filter {
    109 	struct hfsc_interface	iface;
    110 	u_long			filter_handle;
    111 };
    112 
    113 struct class_stats {
    114 	u_int			class_id;
    115 	u_long			class_handle;
    116 	struct service_curve	rsc;
    117 	struct service_curve	fsc;
    118 
    119 	u_int64_t		total;	/* total work in bytes */
    120 	u_int64_t		cumul;	/* cumulative work in bytes
    121 					   done by real-time criteria */
    122 	u_int64_t		d;		/* deadline */
    123 	u_int64_t		e;		/* eligible time */
    124 	u_int64_t		vt;		/* virtual time */
    125 
    126 	u_int			qlength;
    127 	struct pktcntr		xmit_cnt;
    128 	struct pktcntr		drop_cnt;
    129 	u_int 			period;
    130 
    131 	/* red and rio related info */
    132 	int		qtype;
    133 	struct redstats	red[3];
    134 };
    135 
    136 struct hfsc_class_stats {
    137 	struct hfsc_interface	iface;
    138 	int			nskip;		/* skip # of classes */
    139 	int			nclasses;	/* # of class stats (WR) */
    140 	u_int64_t		cur_time;	/* current time */
    141 	u_int			hif_classes;	/* # of classes in the tree */
    142 	u_int			hif_packets;	/* # of packets in the tree */
    143 	struct class_stats	*stats;		/* pointer to stats array */
    144 };
    145 
    146 #define	HFSC_IF_ATTACH		_IOW('Q', 1, struct hfsc_attach)
    147 #define	HFSC_IF_DETACH		_IOW('Q', 2, struct hfsc_interface)
    148 #define	HFSC_ENABLE		_IOW('Q', 3, struct hfsc_interface)
    149 #define	HFSC_DISABLE		_IOW('Q', 4, struct hfsc_interface)
    150 #define	HFSC_CLEAR_HIERARCHY	_IOW('Q', 5, struct hfsc_interface)
    151 #define	HFSC_ADD_CLASS		_IOWR('Q', 7, struct hfsc_add_class)
    152 #define	HFSC_DEL_CLASS		_IOW('Q', 8, struct hfsc_delete_class)
    153 #define	HFSC_MOD_CLASS		_IOW('Q', 9, struct hfsc_modify_class)
    154 #define	HFSC_ADD_FILTER		_IOWR('Q', 10, struct hfsc_add_filter)
    155 #define	HFSC_DEL_FILTER		_IOW('Q', 11, struct hfsc_delete_filter)
    156 #define	HFSC_GETSTATS		_IOWR('Q', 12, struct hfsc_class_stats)
    157 
    158 #ifdef _KERNEL
    159 /*
    160  * kernel internal service curve representation
    161  *	coordinates are given by 64 bit unsigned integers.
    162  *	x-axis: unit is clock count.  for the intel x86 architecture,
    163  *		the raw Pentium TSC (Timestamp Counter) value is used.
    164  *		virtual time is also calculated in this time scale.
    165  *	y-axis: unit is byte.
    166  *
    167  *	the service curve parameters are converted to the internal
    168  *	representation.
    169  *	the slope values are scaled to avoid overflow.
    170  *	the inverse slope values as well as the y-projection of the 1st
    171  *	segment are kept in order to to avoid 64-bit divide operations
    172  *	that are expensive on 32-bit architectures.
    173  *
    174  *  note: Intel Pentium TSC never wraps around in several thousands of years.
    175  *	x-axis doesn't wrap around for 1089 years with 1GHz clock.
    176  *      y-axis doesn't wrap around for 4358 years with 1Gbps bandwidth.
    177  */
    178 
    179 /* kernel internal representation of a service curve */
    180 struct internal_sc {
    181 	u_int64_t	sm1;	/* scaled slope of the 1st segment */
    182 	u_int64_t	ism1;	/* scaled inverse-slope of the 1st segment */
    183 	u_int64_t	dx;	/* the x-projection of the 1st segment */
    184 	u_int64_t	dy;	/* the y-projection of the 1st segment */
    185 	u_int64_t	sm2;	/* scaled slope of the 2nd segment */
    186 	u_int64_t	ism2;	/* scaled inverse-slope of the 2nd segment */
    187 };
    188 
    189 /* runtime service curve */
    190 struct runtime_sc {
    191 	u_int64_t	x;	/* current starting position on x-axis */
    192 	u_int64_t	y;	/* current starting position on x-axis */
    193 	u_int64_t	sm1;	/* scaled slope of the 1st segment */
    194 	u_int64_t	ism1;	/* scaled inverse-slope of the 1st segment */
    195 	u_int64_t	dx;	/* the x-projection of the 1st segment */
    196 	u_int64_t	dy;	/* the y-projection of the 1st segment */
    197 	u_int64_t	sm2;	/* scaled slope of the 2nd segment */
    198 	u_int64_t	ism2;	/* scaled inverse-slope of the 2nd segment */
    199 };
    200 
    201 /* for TAILQ based ellist and actlist implementation */
    202 struct hfsc_class;
    203 typedef TAILQ_HEAD(_eligible, hfsc_class) ellist_t;
    204 typedef TAILQ_ENTRY(hfsc_class) elentry_t;
    205 typedef TAILQ_HEAD(_active, hfsc_class) actlist_t;
    206 typedef TAILQ_ENTRY(hfsc_class) actentry_t;
    207 #define	ellist_first(s)		TAILQ_FIRST(s)
    208 #define	actlist_first(s)	TAILQ_FIRST(s)
    209 #define	actlist_last(s)		TAILQ_LAST(s, _active)
    210 
    211 struct hfsc_class {
    212 	u_int		cl_id;		/* class id (just for debug) */
    213 	u_long		cl_handle;	/* class handle */
    214 	struct hfsc_if	*cl_hif;	/* back pointer to struct hfsc_if */
    215 	int		cl_flags;	/* misc flags */
    216 
    217 	struct hfsc_class *cl_parent;	/* parent class */
    218 	struct hfsc_class *cl_siblings;	/* sibling classes */
    219 	struct hfsc_class *cl_children;	/* child classes */
    220 
    221 	class_queue_t	*cl_q;		/* class queue structure */
    222 	struct red	*cl_red;	/* RED state */
    223 	struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
    224 
    225 	u_int64_t	cl_total;	/* total work in bytes */
    226 	u_int64_t	cl_cumul;	/* cumulative work in bytes
    227 					   done by real-time criteria */
    228 	u_int64_t	cl_d;		/* deadline */
    229 	u_int64_t	cl_e;		/* eligible time */
    230 	u_int64_t	cl_vt;		/* virtual time */
    231 
    232 	struct internal_sc *cl_rsc;	/* internal real-time service curve */
    233 	struct internal_sc *cl_fsc;	/* internal fair service curve */
    234 	struct runtime_sc  cl_deadline;	/* deadline curve */
    235 	struct runtime_sc  cl_eligible;	/* eligible curve */
    236 	struct runtime_sc  cl_virtual;	/* virtual curve */
    237 
    238 	u_int		cl_vtperiod;	/* vt period sequence no */
    239 	u_int		cl_parentperiod;  /* parent's vt period seqno */
    240 	int		cl_nactive;	/* number of active children */
    241 	actlist_t	*cl_actc;	/* active children list */
    242 
    243 	actentry_t	cl_actlist;	/* active children list entry */
    244 	elentry_t	cl_ellist;	/* eligible list entry */
    245 
    246 	struct {
    247 		struct pktcntr	xmit_cnt;
    248 		struct pktcntr	drop_cnt;
    249 		u_int period;
    250 	} cl_stats;
    251 };
    252 
    253 /*
    254  * hfsc interface state
    255  */
    256 struct hfsc_if {
    257 	struct hfsc_if		*hif_next;	/* interface state list */
    258 	struct ifaltq		*hif_ifq;	/* backpointer to ifaltq */
    259 	struct hfsc_class	*hif_rootclass;		/* root class */
    260 	struct hfsc_class	*hif_defaultclass;	/* default class */
    261 	struct hfsc_class	*hif_pollcache;	/* cache for poll operation */
    262 
    263 	u_int	hif_classes;			/* # of classes in the tree */
    264 	u_int	hif_packets;			/* # of packets in the tree */
    265 	u_int	hif_classid;			/* class id sequence number */
    266 
    267 	ellist_t *hif_eligible;			/* eligible list */
    268 
    269 	struct acc_classifier	hif_classifier;
    270 };
    271 
    272 #endif /* _KERNEL */
    273 
    274 #ifdef __cplusplus
    275 }
    276 #endif
    277 
    278 #endif /* _ALTQ_ALTQ_HFSC_H_ */
    279