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