altq_rmclass.h revision 1.2.2.2 1 1.2.2.2 bouyer /* $NetBSD: altq_rmclass.h,v 1.2.2.2 2001/01/05 17:39:37 bouyer Exp $ */
2 1.2.2.2 bouyer /* $KAME: altq_rmclass.h,v 1.6 2000/12/09 09:22:44 kjc Exp $ */
3 1.2.2.2 bouyer
4 1.2.2.2 bouyer /*
5 1.2.2.2 bouyer * Copyright (c) 1991-1997 Regents of the University of California.
6 1.2.2.2 bouyer * All rights reserved.
7 1.2.2.2 bouyer *
8 1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
9 1.2.2.2 bouyer * modification, are permitted provided that the following conditions
10 1.2.2.2 bouyer * are met:
11 1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
12 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer.
13 1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
14 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
15 1.2.2.2 bouyer * documentation and/or other materials provided with the distribution.
16 1.2.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
17 1.2.2.2 bouyer * must display the following acknowledgement:
18 1.2.2.2 bouyer * This product includes software developed by the Network Research
19 1.2.2.2 bouyer * Group at Lawrence Berkeley Laboratory.
20 1.2.2.2 bouyer * 4. Neither the name of the University nor of the Laboratory may be used
21 1.2.2.2 bouyer * to endorse or promote products derived from this software without
22 1.2.2.2 bouyer * specific prior written permission.
23 1.2.2.2 bouyer *
24 1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.2.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.2.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.2.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.2.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.2.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.2.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.2.2.2 bouyer * SUCH DAMAGE.
35 1.2.2.2 bouyer */
36 1.2.2.2 bouyer
37 1.2.2.2 bouyer #ifndef _ALTQ_ALTQ_RMCLASS_H_
38 1.2.2.2 bouyer #define _ALTQ_ALTQ_RMCLASS_H_
39 1.2.2.2 bouyer
40 1.2.2.2 bouyer #include <altq/altq_classq.h>
41 1.2.2.2 bouyer
42 1.2.2.2 bouyer /* #pragma ident "@(#)rm_class.h 1.20 97/10/23 SMI" */
43 1.2.2.2 bouyer
44 1.2.2.2 bouyer #ifdef __cplusplus
45 1.2.2.2 bouyer extern "C" {
46 1.2.2.2 bouyer #endif
47 1.2.2.2 bouyer
48 1.2.2.2 bouyer #ifdef _KERNEL
49 1.2.2.2 bouyer
50 1.2.2.2 bouyer typedef struct mbuf mbuf_t;
51 1.2.2.2 bouyer typedef struct rm_ifdat rm_ifdat_t;
52 1.2.2.2 bouyer typedef struct rm_class rm_class_t;
53 1.2.2.2 bouyer
54 1.2.2.2 bouyer struct red;
55 1.2.2.2 bouyer
56 1.2.2.2 bouyer /*
57 1.2.2.2 bouyer * Macros for dealing with time values. We assume all times are
58 1.2.2.2 bouyer * 'timevals'. `microtime' is used to get the best available clock
59 1.2.2.2 bouyer * resolution. If `microtime' *doesn't* return a value that's about
60 1.2.2.2 bouyer * ten times smaller than the average packet time on the fastest
61 1.2.2.2 bouyer * link that will use these routines, a slightly different clock
62 1.2.2.2 bouyer * scheme than this one should be used.
63 1.2.2.2 bouyer * (Bias due to truncation error in this scheme will overestimate utilization
64 1.2.2.2 bouyer * and discriminate against high bandwidth classes. To remove this bias an
65 1.2.2.2 bouyer * integrator needs to be added. The simplest integrator uses a history of
66 1.2.2.2 bouyer * 10 * avg.packet.time / min.tick.time packet completion entries. This is
67 1.2.2.2 bouyer * straight forward to add but we don't want to pay the extra memory
68 1.2.2.2 bouyer * traffic to maintain it if it's not necessary (occasionally a vendor
69 1.2.2.2 bouyer * accidentally builds a workstation with a decent clock - e.g., Sun & HP).)
70 1.2.2.2 bouyer */
71 1.2.2.2 bouyer
72 1.2.2.2 bouyer #define RM_GETTIME(now) microtime(&now)
73 1.2.2.2 bouyer
74 1.2.2.2 bouyer #define TV_LT(a, b) (((a)->tv_sec < (b)->tv_sec) || \
75 1.2.2.2 bouyer (((a)->tv_usec < (b)->tv_usec) && ((a)->tv_sec <= (b)->tv_sec)))
76 1.2.2.2 bouyer
77 1.2.2.2 bouyer #define TV_DELTA(a, b, delta) { \
78 1.2.2.2 bouyer register int xxs; \
79 1.2.2.2 bouyer \
80 1.2.2.2 bouyer delta = (a)->tv_usec - (b)->tv_usec; \
81 1.2.2.2 bouyer if ((xxs = (a)->tv_sec - (b)->tv_sec)) { \
82 1.2.2.2 bouyer switch (xxs) { \
83 1.2.2.2 bouyer default: \
84 1.2.2.2 bouyer if (xxs < 0) \
85 1.2.2.2 bouyer printf("rm_class: bogus time values\n"); \
86 1.2.2.2 bouyer delta = 0; \
87 1.2.2.2 bouyer /* fall through */ \
88 1.2.2.2 bouyer case 2: \
89 1.2.2.2 bouyer delta += 1000000; \
90 1.2.2.2 bouyer /* fall through */ \
91 1.2.2.2 bouyer case 1: \
92 1.2.2.2 bouyer delta += 1000000; \
93 1.2.2.2 bouyer break; \
94 1.2.2.2 bouyer } \
95 1.2.2.2 bouyer } \
96 1.2.2.2 bouyer }
97 1.2.2.2 bouyer
98 1.2.2.2 bouyer #define TV_ADD_DELTA(a, delta, res) { \
99 1.2.2.2 bouyer register int xxus = (a)->tv_usec + (delta); \
100 1.2.2.2 bouyer \
101 1.2.2.2 bouyer (res)->tv_sec = (a)->tv_sec; \
102 1.2.2.2 bouyer while (xxus >= 1000000) { \
103 1.2.2.2 bouyer ++((res)->tv_sec); \
104 1.2.2.2 bouyer xxus -= 1000000; \
105 1.2.2.2 bouyer } \
106 1.2.2.2 bouyer (res)->tv_usec = xxus; \
107 1.2.2.2 bouyer }
108 1.2.2.2 bouyer
109 1.2.2.2 bouyer #define RM_TIMEOUT 2 /* 1 Clock tick. */
110 1.2.2.2 bouyer
111 1.2.2.2 bouyer #if 1
112 1.2.2.2 bouyer #define RM_MAXQUEUED 1 /* this isn't used in ALTQ/CBQ */
113 1.2.2.2 bouyer #else
114 1.2.2.2 bouyer #define RM_MAXQUEUED 16 /* Max number of packets downstream of CBQ */
115 1.2.2.2 bouyer #endif
116 1.2.2.2 bouyer #define RM_MAXPRIO 8 /* Max priority */
117 1.2.2.2 bouyer #define RM_MAXQUEUE 64 /* Max queue length */
118 1.2.2.2 bouyer #define RM_FILTER_GAIN 5 /* log2 of gain, e.g., 5 => 31/32 */
119 1.2.2.2 bouyer #define RM_POWER (1 << RM_FILTER_GAIN)
120 1.2.2.2 bouyer #define RM_MAXDEPTH 32
121 1.2.2.2 bouyer #define RM_NS_PER_SEC (1000000000)
122 1.2.2.2 bouyer
123 1.2.2.2 bouyer typedef struct _rm_class_stats_ {
124 1.2.2.2 bouyer u_int handle;
125 1.2.2.2 bouyer u_int depth;
126 1.2.2.2 bouyer
127 1.2.2.2 bouyer struct pktcntr xmit_cnt; /* packets sent in this class */
128 1.2.2.2 bouyer struct pktcntr drop_cnt; /* dropped packets */
129 1.2.2.2 bouyer u_int over; /* # times went over limit */
130 1.2.2.2 bouyer u_int borrows; /* # times tried to borrow */
131 1.2.2.2 bouyer u_int overactions; /* # times invoked overlimit action */
132 1.2.2.2 bouyer u_int delays; /* # times invoked delay actions */
133 1.2.2.2 bouyer } rm_class_stats_t;
134 1.2.2.2 bouyer
135 1.2.2.2 bouyer /*
136 1.2.2.2 bouyer * CBQ Class state structure
137 1.2.2.2 bouyer */
138 1.2.2.2 bouyer struct rm_class {
139 1.2.2.2 bouyer class_queue_t *q_; /* Queue of packets */
140 1.2.2.2 bouyer rm_ifdat_t *ifdat_;
141 1.2.2.2 bouyer int pri_; /* Class priority. */
142 1.2.2.2 bouyer int depth_; /* Class depth */
143 1.2.2.2 bouyer u_int ns_per_byte_; /* NanoSeconds per byte. */
144 1.2.2.2 bouyer u_int maxrate_; /* Bytes per second for this class. */
145 1.2.2.2 bouyer u_int allotment_; /* Fraction of link bandwidth. */
146 1.2.2.2 bouyer u_int w_allotment_; /* Weighted allotment for WRR */
147 1.2.2.2 bouyer int bytes_alloc_; /* Allocation for round of WRR */
148 1.2.2.2 bouyer
149 1.2.2.2 bouyer int avgidle_;
150 1.2.2.2 bouyer int maxidle_;
151 1.2.2.2 bouyer int minidle_;
152 1.2.2.2 bouyer int offtime_;
153 1.2.2.2 bouyer int sleeping_; /* != 0 if delaying */
154 1.2.2.2 bouyer int qthresh_; /* Queue threshold for formal link sharing */
155 1.2.2.2 bouyer int leaf_; /* Note whether leaf class or not.*/
156 1.2.2.2 bouyer
157 1.2.2.2 bouyer rm_class_t *children_; /* Children of this class */
158 1.2.2.2 bouyer rm_class_t *next_; /* Next pointer, used if child */
159 1.2.2.2 bouyer
160 1.2.2.2 bouyer rm_class_t *peer_; /* Peer class */
161 1.2.2.2 bouyer rm_class_t *borrow_; /* Borrow class */
162 1.2.2.2 bouyer rm_class_t *parent_; /* Parent class */
163 1.2.2.2 bouyer
164 1.2.2.2 bouyer void (*overlimit)(struct rm_class *, struct rm_class *);
165 1.2.2.2 bouyer void (*drop)(struct rm_class *); /* Class drop action. */
166 1.2.2.2 bouyer
167 1.2.2.2 bouyer struct red *red_; /* RED state pointer */
168 1.2.2.2 bouyer struct altq_pktattr *pktattr_; /* saved hdr used by RED/ECN */
169 1.2.2.2 bouyer int flags_;
170 1.2.2.2 bouyer
171 1.2.2.2 bouyer int last_pkttime_; /* saved pkt_time */
172 1.2.2.2 bouyer struct timeval undertime_; /* time can next send */
173 1.2.2.2 bouyer struct timeval last_; /* time last packet sent */
174 1.2.2.2 bouyer struct timeval overtime_;
175 1.2.2.2 bouyer struct callout callout_; /* for timeout() calls */
176 1.2.2.2 bouyer
177 1.2.2.2 bouyer rm_class_stats_t stats_; /* Class Statistics */
178 1.2.2.2 bouyer };
179 1.2.2.2 bouyer
180 1.2.2.2 bouyer /*
181 1.2.2.2 bouyer * CBQ Interface state
182 1.2.2.2 bouyer */
183 1.2.2.2 bouyer struct rm_ifdat {
184 1.2.2.2 bouyer int queued_; /* # pkts queued downstream */
185 1.2.2.2 bouyer int efficient_; /* Link Efficency bit */
186 1.2.2.2 bouyer int wrr_; /* Enable Weighted Round-Robin */
187 1.2.2.2 bouyer u_long ns_per_byte_; /* Link byte speed. */
188 1.2.2.2 bouyer int maxqueued_; /* Max packets to queue */
189 1.2.2.2 bouyer int maxpkt_; /* Max packet size. */
190 1.2.2.2 bouyer int qi_; /* In/out pointers for downstream */
191 1.2.2.2 bouyer int qo_; /* packets */
192 1.2.2.2 bouyer
193 1.2.2.2 bouyer /*
194 1.2.2.2 bouyer * Active class state and WRR state.
195 1.2.2.2 bouyer */
196 1.2.2.2 bouyer rm_class_t *active_[RM_MAXPRIO]; /* Active cl's in each pri */
197 1.2.2.2 bouyer int na_[RM_MAXPRIO]; /* # of active cl's in a pri */
198 1.2.2.2 bouyer int num_[RM_MAXPRIO]; /* # of cl's per pri */
199 1.2.2.2 bouyer int alloc_[RM_MAXPRIO]; /* Byte Allocation */
200 1.2.2.2 bouyer u_long M_[RM_MAXPRIO]; /* WRR weights. */
201 1.2.2.2 bouyer
202 1.2.2.2 bouyer /*
203 1.2.2.2 bouyer * Network Interface/Solaris Queue state pointer.
204 1.2.2.2 bouyer */
205 1.2.2.2 bouyer struct ifaltq *ifq_;
206 1.2.2.2 bouyer rm_class_t *default_; /* Default Pkt class, BE */
207 1.2.2.2 bouyer rm_class_t *root_; /* Root Link class. */
208 1.2.2.2 bouyer rm_class_t *ctl_; /* Control Traffic class. */
209 1.2.2.2 bouyer void (*restart)(struct ifaltq *); /* Restart routine. */
210 1.2.2.2 bouyer
211 1.2.2.2 bouyer /*
212 1.2.2.2 bouyer * Current packet downstream packet state and dynamic state.
213 1.2.2.2 bouyer */
214 1.2.2.2 bouyer rm_class_t *borrowed_[RM_MAXQUEUED]; /* Class borrowed last */
215 1.2.2.2 bouyer rm_class_t *class_[RM_MAXQUEUED]; /* class sending */
216 1.2.2.2 bouyer int curlen_[RM_MAXQUEUED]; /* Current pktlen */
217 1.2.2.2 bouyer struct timeval now_[RM_MAXQUEUED]; /* Current packet time. */
218 1.2.2.2 bouyer int is_overlimit_[RM_MAXQUEUED];/* Current packet time. */
219 1.2.2.2 bouyer
220 1.2.2.2 bouyer int cutoff_; /* Cut-off depth for borrowing */
221 1.2.2.2 bouyer
222 1.2.2.2 bouyer struct timeval ifnow_; /* expected xmit completion time */
223 1.2.2.2 bouyer #if 1 /* ALTQ4PPP */
224 1.2.2.2 bouyer int maxiftime_; /* max delay inside interface */
225 1.2.2.2 bouyer #endif
226 1.2.2.2 bouyer rm_class_t *pollcache_; /* cached rm_class by poll operation */
227 1.2.2.2 bouyer };
228 1.2.2.2 bouyer
229 1.2.2.2 bouyer /* flags for rmc_init and rmc_newclass */
230 1.2.2.2 bouyer /* class flags */
231 1.2.2.2 bouyer #define RMCF_RED 0x0001
232 1.2.2.2 bouyer #define RMCF_ECN 0x0002
233 1.2.2.2 bouyer #define RMCF_RIO 0x0004
234 1.2.2.2 bouyer #define RMCF_FLOWVALVE 0x0008 /* use flowvalve (aka penalty-box) */
235 1.2.2.2 bouyer #define RMCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
236 1.2.2.2 bouyer
237 1.2.2.2 bouyer /* flags for rmc_init */
238 1.2.2.2 bouyer #define RMCF_WRR 0x0100
239 1.2.2.2 bouyer #define RMCF_EFFICIENT 0x0200
240 1.2.2.2 bouyer
241 1.2.2.2 bouyer #define is_a_parent_class(cl) ((cl)->children_ != NULL)
242 1.2.2.2 bouyer
243 1.2.2.2 bouyer extern rm_class_t *rmc_newclass __P((int, struct rm_ifdat *, u_int,
244 1.2.2.2 bouyer void (*)(struct rm_class *,
245 1.2.2.2 bouyer struct rm_class *),
246 1.2.2.2 bouyer int, struct rm_class *, struct rm_class *,
247 1.2.2.2 bouyer u_int, int, u_int, int, int));
248 1.2.2.2 bouyer extern void rmc_delete_class __P((struct rm_ifdat *, struct rm_class *));
249 1.2.2.2 bouyer extern int rmc_modclass __P((struct rm_class *, u_int, int,
250 1.2.2.2 bouyer u_int, int, u_int, int));
251 1.2.2.2 bouyer extern void rmc_init __P((struct ifaltq *, struct rm_ifdat *, u_int,
252 1.2.2.2 bouyer void (*)(struct ifaltq *),
253 1.2.2.2 bouyer int, int, u_int, int, u_int, int));
254 1.2.2.2 bouyer extern int rmc_queue_packet __P((struct rm_class *, mbuf_t *));
255 1.2.2.2 bouyer extern mbuf_t *rmc_dequeue_next __P((struct rm_ifdat *, int));
256 1.2.2.2 bouyer extern void rmc_update_class_util __P((struct rm_ifdat *));
257 1.2.2.2 bouyer extern void rmc_delay_action __P((struct rm_class *, struct rm_class *));
258 1.2.2.2 bouyer extern void rmc_dropall __P((struct rm_class *));
259 1.2.2.2 bouyer extern int rmc_get_weight __P((struct rm_ifdat *, int));
260 1.2.2.2 bouyer
261 1.2.2.2 bouyer #endif /* _KERNEL */
262 1.2.2.2 bouyer
263 1.2.2.2 bouyer #ifdef __cplusplus
264 1.2.2.2 bouyer }
265 1.2.2.2 bouyer #endif
266 1.2.2.2 bouyer
267 1.2.2.2 bouyer #endif /* _ALTQ_ALTQ_RMCLASS_H_ */
268