Home | History | Annotate | Line # | Download | only in altq
      1  1.5    peter /*	$NetBSD: altq_red.h,v 1.5 2006/10/12 19:59:08 peter Exp $	*/
      2  1.5    peter /*	$KAME: altq_red.h,v 1.8 2003/07/10 12:07:49 kjc Exp $	*/
      3  1.1  thorpej 
      4  1.1  thorpej /*
      5  1.5    peter  * Copyright (C) 1997-2003
      6  1.1  thorpej  *	Sony Computer Science Laboratories Inc.  All rights reserved.
      7  1.1  thorpej  *
      8  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
      9  1.1  thorpej  * modification, are permitted provided that the following conditions
     10  1.1  thorpej  * are met:
     11  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     12  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     13  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     16  1.1  thorpej  *
     17  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
     18  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
     21  1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  1.1  thorpej  * SUCH DAMAGE.
     28  1.1  thorpej  */
     29  1.1  thorpej 
     30  1.1  thorpej #ifndef _ALTQ_ALTQ_RED_H_
     31  1.1  thorpej #define	_ALTQ_ALTQ_RED_H_
     32  1.1  thorpej 
     33  1.1  thorpej #include <altq/altq_classq.h>
     34  1.1  thorpej 
     35  1.5    peter #ifdef ALTQ3_COMPAT
     36  1.1  thorpej struct red_interface {
     37  1.1  thorpej 	char	red_ifname[IFNAMSIZ];
     38  1.1  thorpej };
     39  1.1  thorpej 
     40  1.1  thorpej struct red_stats {
     41  1.1  thorpej 	struct red_interface iface;
     42  1.1  thorpej 	int q_len;
     43  1.1  thorpej 	int q_avg;
     44  1.1  thorpej 
     45  1.1  thorpej 	struct pktcntr	xmit_cnt;
     46  1.1  thorpej 	struct pktcntr	drop_cnt;
     47  1.1  thorpej 	u_int		drop_forced;
     48  1.1  thorpej 	u_int		drop_unforced;
     49  1.1  thorpej 	u_int		marked_packets;
     50  1.1  thorpej 
     51  1.1  thorpej 	/* static red parameters */
     52  1.1  thorpej 	int q_limit;
     53  1.1  thorpej 	int weight;
     54  1.1  thorpej 	int inv_pmax;
     55  1.1  thorpej 	int th_min;
     56  1.1  thorpej 	int th_max;
     57  1.1  thorpej 
     58  1.1  thorpej 	/* flowvalve related stuff */
     59  1.1  thorpej 	u_int fv_flows;
     60  1.1  thorpej 	u_int fv_pass;
     61  1.1  thorpej 	u_int fv_predrop;
     62  1.1  thorpej 	u_int fv_alloc;
     63  1.1  thorpej 	u_int fv_escape;
     64  1.1  thorpej };
     65  1.1  thorpej 
     66  1.1  thorpej struct red_conf {
     67  1.1  thorpej 	struct red_interface iface;
     68  1.1  thorpej 	int red_weight;		/* weight for EWMA */
     69  1.1  thorpej 	int red_inv_pmax;	/* inverse of max drop probability */
     70  1.1  thorpej 	int red_thmin;		/* red min threshold */
     71  1.1  thorpej 	int red_thmax;		/* red max threshold */
     72  1.1  thorpej 	int red_limit;		/* max queue length */
     73  1.1  thorpej 	int red_pkttime;	/* average packet time in usec */
     74  1.1  thorpej 	int red_flags;		/* see below */
     75  1.1  thorpej };
     76  1.5    peter #endif /* ALTQ3_COMPAT */
     77  1.1  thorpej 
     78  1.1  thorpej /* red flags */
     79  1.1  thorpej #define	REDF_ECN4	0x01	/* use packet marking for IPv4 packets */
     80  1.1  thorpej #define	REDF_ECN6	0x02	/* use packet marking for IPv6 packets */
     81  1.1  thorpej #define	REDF_ECN	(REDF_ECN4 | REDF_ECN6)
     82  1.1  thorpej #define	REDF_FLOWVALVE	0x04	/* use flowvalve (aka penalty-box) */
     83  1.1  thorpej 
     84  1.1  thorpej /*
     85  1.1  thorpej  * simpler versions of red parameters and statistics used by other
     86  1.1  thorpej  * disciplines (e.g., CBQ)
     87  1.1  thorpej  */
     88  1.1  thorpej struct redparams {
     89  1.1  thorpej 	int th_min;		/* red min threshold */
     90  1.1  thorpej 	int th_max;		/* red max threshold */
     91  1.1  thorpej 	int inv_pmax;		/* inverse of max drop probability */
     92  1.1  thorpej };
     93  1.1  thorpej 
     94  1.1  thorpej struct redstats {
     95  1.1  thorpej 	int		q_avg;
     96  1.1  thorpej 	struct pktcntr	xmit_cnt;
     97  1.1  thorpej 	struct pktcntr	drop_cnt;
     98  1.1  thorpej 	u_int		drop_forced;
     99  1.1  thorpej 	u_int		drop_unforced;
    100  1.1  thorpej 	u_int		marked_packets;
    101  1.1  thorpej };
    102  1.1  thorpej 
    103  1.5    peter #ifdef ALTQ3_COMPAT
    104  1.3    perry /*
    105  1.1  thorpej  * IOCTLs for RED
    106  1.1  thorpej  */
    107  1.1  thorpej #define	RED_IF_ATTACH		_IOW('Q', 1, struct red_interface)
    108  1.1  thorpej #define	RED_IF_DETACH		_IOW('Q', 2, struct red_interface)
    109  1.1  thorpej #define	RED_ENABLE		_IOW('Q', 3, struct red_interface)
    110  1.1  thorpej #define	RED_DISABLE		_IOW('Q', 4, struct red_interface)
    111  1.1  thorpej #define	RED_CONFIG		_IOWR('Q', 6, struct red_conf)
    112  1.1  thorpej #define	RED_GETSTATS		_IOWR('Q', 12, struct red_stats)
    113  1.1  thorpej #define	RED_SETDEFAULTS		_IOW('Q', 30, struct redparams)
    114  1.5    peter #endif /* ALTQ3_COMPAT */
    115  1.1  thorpej 
    116  1.1  thorpej #ifdef _KERNEL
    117  1.1  thorpej 
    118  1.5    peter #ifdef ALTQ3_COMPAT
    119  1.1  thorpej struct flowvalve;
    120  1.5    peter #endif
    121  1.1  thorpej 
    122  1.1  thorpej /* weight table structure for idle time calibration */
    123  1.1  thorpej struct wtab {
    124  1.5    peter 	struct wtab	*w_next;
    125  1.5    peter 	int		 w_weight;
    126  1.5    peter 	int		 w_param_max;
    127  1.5    peter 	int		 w_refcount;
    128  1.5    peter 	int32_t		 w_tab[32];
    129  1.1  thorpej };
    130  1.1  thorpej 
    131  1.1  thorpej typedef struct red {
    132  1.5    peter 	int		red_pkttime;	/* average packet time in micro sec
    133  1.5    peter 					   used for idle calibration */
    134  1.5    peter 	int		red_flags;	/* red flags */
    135  1.1  thorpej 
    136  1.1  thorpej 	/* red parameters */
    137  1.5    peter 	int		red_weight;	/* weight for EWMA */
    138  1.5    peter 	int		red_inv_pmax;	/* inverse of max drop probability */
    139  1.5    peter 	int		red_thmin;	/* red min threshold */
    140  1.5    peter 	int		red_thmax;	/* red max threshold */
    141  1.1  thorpej 
    142  1.1  thorpej 	/* variables for internal use */
    143  1.5    peter 	int		red_wshift;	/* log(red_weight) */
    144  1.5    peter 	int		red_thmin_s;	/* th_min scaled by avgshift */
    145  1.5    peter 	int		red_thmax_s;	/* th_max scaled by avgshift */
    146  1.5    peter 	int		red_probd;	/* drop probability denominator */
    147  1.5    peter 
    148  1.5    peter 	int		red_avg;	/* queue len avg scaled by avgshift */
    149  1.5    peter 	int		red_count;	/* packet count since last dropped/
    150  1.5    peter 					   marked packet */
    151  1.5    peter 	int		red_idle;	/* queue was empty */
    152  1.5    peter 	int		red_old;	/* avg is above th_min */
    153  1.5    peter 	struct wtab	*red_wtab;	/* weight table */
    154  1.5    peter 	struct timeval	 red_last;	/* time when the queue becomes idle */
    155  1.1  thorpej 
    156  1.5    peter #ifdef ALTQ3_COMPAT
    157  1.1  thorpej 	struct flowvalve *red_flowvalve;	/* flowvalve state */
    158  1.5    peter #endif
    159  1.1  thorpej 
    160  1.1  thorpej 	struct {
    161  1.1  thorpej 		struct pktcntr	xmit_cnt;
    162  1.1  thorpej 		struct pktcntr	drop_cnt;
    163  1.1  thorpej 		u_int		drop_forced;
    164  1.1  thorpej 		u_int		drop_unforced;
    165  1.1  thorpej 		u_int		marked_packets;
    166  1.1  thorpej 	} red_stats;
    167  1.1  thorpej } red_t;
    168  1.1  thorpej 
    169  1.5    peter #ifdef ALTQ3_COMPAT
    170  1.1  thorpej typedef struct red_queue {
    171  1.1  thorpej 	struct red_queue *rq_next;	/* next red_state in the list */
    172  1.1  thorpej 	struct ifaltq *rq_ifq;		/* backpointer to ifaltq */
    173  1.1  thorpej 
    174  1.1  thorpej 	class_queue_t *rq_q;
    175  1.1  thorpej 
    176  1.1  thorpej 	red_t *rq_red;
    177  1.1  thorpej } red_queue_t;
    178  1.5    peter #endif /* ALTQ3_COMPAT */
    179  1.1  thorpej 
    180  1.1  thorpej /* red drop types */
    181  1.1  thorpej #define	DTYPE_NODROP	0	/* no drop */
    182  1.1  thorpej #define	DTYPE_FORCED	1	/* a "forced" drop */
    183  1.1  thorpej #define	DTYPE_EARLY	2	/* an "unforced" (early) drop */
    184  1.1  thorpej 
    185  1.5    peter extern red_t		*red_alloc(int, int, int, int, int, int);
    186  1.5    peter extern void		 red_destroy(red_t *);
    187  1.5    peter extern void		 red_getstats(red_t *, struct redstats *);
    188  1.5    peter extern int		 red_addq(red_t *, class_queue_t *, struct mbuf *,
    189  1.5    peter 			     struct altq_pktattr *);
    190  1.5    peter extern struct mbuf	*red_getq(red_t *, class_queue_t *);
    191  1.5    peter extern int		 drop_early(int, int, int);
    192  1.5    peter extern int		 mark_ecn(struct mbuf *, struct altq_pktattr *, int);
    193  1.5    peter extern struct wtab	*wtab_alloc(int);
    194  1.5    peter extern int		 wtab_destroy(struct wtab *);
    195  1.5    peter extern int32_t		 pow_w(struct wtab *, int);
    196  1.1  thorpej 
    197  1.1  thorpej #endif /* _KERNEL */
    198  1.1  thorpej 
    199  1.1  thorpej #endif /* _ALTQ_ALTQ_RED_H_ */
    200