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