xref: /freebsd/sys/net/altq/altq_red.h (revision 2ff63af9b88c7413b7d71715b5532625752a248e)
1*772e66a6SGleb Smirnoff /*-
2*772e66a6SGleb Smirnoff  * Copyright (C) 1997-2003
3*772e66a6SGleb Smirnoff  *	Sony Computer Science Laboratories Inc.  All rights reserved.
4*772e66a6SGleb Smirnoff  *
5*772e66a6SGleb Smirnoff  * Redistribution and use in source and binary forms, with or without
6*772e66a6SGleb Smirnoff  * modification, are permitted provided that the following conditions
7*772e66a6SGleb Smirnoff  * are met:
8*772e66a6SGleb Smirnoff  * 1. Redistributions of source code must retain the above copyright
9*772e66a6SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer.
10*772e66a6SGleb Smirnoff  * 2. Redistributions in binary form must reproduce the above copyright
11*772e66a6SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer in the
12*772e66a6SGleb Smirnoff  *    documentation and/or other materials provided with the distribution.
13*772e66a6SGleb Smirnoff  *
14*772e66a6SGleb Smirnoff  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
15*772e66a6SGleb Smirnoff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*772e66a6SGleb Smirnoff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*772e66a6SGleb Smirnoff  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
18*772e66a6SGleb Smirnoff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*772e66a6SGleb Smirnoff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*772e66a6SGleb Smirnoff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*772e66a6SGleb Smirnoff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*772e66a6SGleb Smirnoff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*772e66a6SGleb Smirnoff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*772e66a6SGleb Smirnoff  * SUCH DAMAGE.
25*772e66a6SGleb Smirnoff  *
26*772e66a6SGleb Smirnoff  * $KAME: altq_red.h,v 1.8 2003/07/10 12:07:49 kjc Exp $
27*772e66a6SGleb Smirnoff  */
28*772e66a6SGleb Smirnoff 
29*772e66a6SGleb Smirnoff #ifndef _ALTQ_ALTQ_RED_H_
30*772e66a6SGleb Smirnoff #define	_ALTQ_ALTQ_RED_H_
31*772e66a6SGleb Smirnoff 
32*772e66a6SGleb Smirnoff #include <net/altq/altq_classq.h>
33*772e66a6SGleb Smirnoff 
34*772e66a6SGleb Smirnoff /* red flags */
35*772e66a6SGleb Smirnoff #define	REDF_ECN4	0x01	/* use packet marking for IPv4 packets */
36*772e66a6SGleb Smirnoff #define	REDF_ECN6	0x02	/* use packet marking for IPv6 packets */
37*772e66a6SGleb Smirnoff #define	REDF_ECN	(REDF_ECN4 | REDF_ECN6)
38*772e66a6SGleb Smirnoff #define	REDF_FLOWVALVE	0x04	/* use flowvalve (aka penalty-box) */
39*772e66a6SGleb Smirnoff 
40*772e66a6SGleb Smirnoff /*
41*772e66a6SGleb Smirnoff  * simpler versions of red parameters and statistics used by other
42*772e66a6SGleb Smirnoff  * disciplines (e.g., CBQ)
43*772e66a6SGleb Smirnoff  */
44*772e66a6SGleb Smirnoff struct redparams {
45*772e66a6SGleb Smirnoff 	int th_min;		/* red min threshold */
46*772e66a6SGleb Smirnoff 	int th_max;		/* red max threshold */
47*772e66a6SGleb Smirnoff 	int inv_pmax;		/* inverse of max drop probability */
48*772e66a6SGleb Smirnoff };
49*772e66a6SGleb Smirnoff 
50*772e66a6SGleb Smirnoff struct redstats {
51*772e66a6SGleb Smirnoff 	int		q_avg;
52*772e66a6SGleb Smirnoff 	struct pktcntr	xmit_cnt;
53*772e66a6SGleb Smirnoff 	struct pktcntr	drop_cnt;
54*772e66a6SGleb Smirnoff 	u_int		drop_forced;
55*772e66a6SGleb Smirnoff 	u_int		drop_unforced;
56*772e66a6SGleb Smirnoff 	u_int		marked_packets;
57*772e66a6SGleb Smirnoff };
58*772e66a6SGleb Smirnoff 
59*772e66a6SGleb Smirnoff #ifdef _KERNEL
60*772e66a6SGleb Smirnoff 
61*772e66a6SGleb Smirnoff /* weight table structure for idle time calibration */
62*772e66a6SGleb Smirnoff struct wtab {
63*772e66a6SGleb Smirnoff 	struct wtab	*w_next;
64*772e66a6SGleb Smirnoff 	int		 w_weight;
65*772e66a6SGleb Smirnoff 	int		 w_param_max;
66*772e66a6SGleb Smirnoff 	int		 w_refcount;
67*772e66a6SGleb Smirnoff 	int32_t		 w_tab[32];
68*772e66a6SGleb Smirnoff };
69*772e66a6SGleb Smirnoff 
70*772e66a6SGleb Smirnoff typedef struct red {
71*772e66a6SGleb Smirnoff 	int		red_pkttime;	/* average packet time in micro sec
72*772e66a6SGleb Smirnoff 					   used for idle calibration */
73*772e66a6SGleb Smirnoff 	int		red_flags;	/* red flags */
74*772e66a6SGleb Smirnoff 
75*772e66a6SGleb Smirnoff 	/* red parameters */
76*772e66a6SGleb Smirnoff 	int		red_weight;	/* weight for EWMA */
77*772e66a6SGleb Smirnoff 	int		red_inv_pmax;	/* inverse of max drop probability */
78*772e66a6SGleb Smirnoff 	int		red_thmin;	/* red min threshold */
79*772e66a6SGleb Smirnoff 	int		red_thmax;	/* red max threshold */
80*772e66a6SGleb Smirnoff 
81*772e66a6SGleb Smirnoff 	/* variables for internal use */
82*772e66a6SGleb Smirnoff 	int		red_wshift;	/* log(red_weight) */
83*772e66a6SGleb Smirnoff 	int		red_thmin_s;	/* th_min scaled by avgshift */
84*772e66a6SGleb Smirnoff 	int		red_thmax_s;	/* th_max scaled by avgshift */
85*772e66a6SGleb Smirnoff 	int		red_probd;	/* drop probability denominator */
86*772e66a6SGleb Smirnoff 
87*772e66a6SGleb Smirnoff 	int		red_avg;	/* queue len avg scaled by avgshift */
88*772e66a6SGleb Smirnoff 	int		red_count;	/* packet count since last dropped/
89*772e66a6SGleb Smirnoff 					   marked packet */
90*772e66a6SGleb Smirnoff 	int		red_idle;	/* queue was empty */
91*772e66a6SGleb Smirnoff 	int		red_old;	/* avg is above th_min */
92*772e66a6SGleb Smirnoff 	struct wtab	*red_wtab;	/* weight table */
93*772e66a6SGleb Smirnoff 	struct timeval	 red_last;	/* time when the queue becomes idle */
94*772e66a6SGleb Smirnoff 
95*772e66a6SGleb Smirnoff 	struct {
96*772e66a6SGleb Smirnoff 		struct pktcntr	xmit_cnt;
97*772e66a6SGleb Smirnoff 		struct pktcntr	drop_cnt;
98*772e66a6SGleb Smirnoff 		u_int		drop_forced;
99*772e66a6SGleb Smirnoff 		u_int		drop_unforced;
100*772e66a6SGleb Smirnoff 		u_int		marked_packets;
101*772e66a6SGleb Smirnoff 	} red_stats;
102*772e66a6SGleb Smirnoff } red_t;
103*772e66a6SGleb Smirnoff 
104*772e66a6SGleb Smirnoff /* red drop types */
105*772e66a6SGleb Smirnoff #define	DTYPE_NODROP	0	/* no drop */
106*772e66a6SGleb Smirnoff #define	DTYPE_FORCED	1	/* a "forced" drop */
107*772e66a6SGleb Smirnoff #define	DTYPE_EARLY	2	/* an "unforced" (early) drop */
108*772e66a6SGleb Smirnoff 
109*772e66a6SGleb Smirnoff extern red_t		*red_alloc(int, int, int, int, int, int);
110*772e66a6SGleb Smirnoff extern void		 red_destroy(red_t *);
111*772e66a6SGleb Smirnoff extern void		 red_getstats(red_t *, struct redstats *);
112*772e66a6SGleb Smirnoff extern int		 red_addq(red_t *, class_queue_t *, struct mbuf *,
113*772e66a6SGleb Smirnoff 			     struct altq_pktattr *);
114*772e66a6SGleb Smirnoff extern struct mbuf	*red_getq(red_t *, class_queue_t *);
115*772e66a6SGleb Smirnoff extern int		 drop_early(int, int, int);
116*772e66a6SGleb Smirnoff extern int		 mark_ecn(struct mbuf *, struct altq_pktattr *, int);
117*772e66a6SGleb Smirnoff extern struct wtab	*wtab_alloc(int);
118*772e66a6SGleb Smirnoff extern int		 wtab_destroy(struct wtab *);
119*772e66a6SGleb Smirnoff extern int32_t		 pow_w(struct wtab *, int);
120*772e66a6SGleb Smirnoff 
121*772e66a6SGleb Smirnoff #endif /* _KERNEL */
122*772e66a6SGleb Smirnoff 
123*772e66a6SGleb Smirnoff #endif /* _ALTQ_ALTQ_RED_H_ */
124