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