altq_hfsc.h revision 1.2.2.2 1 1.2.2.2 bouyer /* $NetBSD: altq_hfsc.h,v 1.2.2.2 2001/01/05 17:39:36 bouyer Exp $ */
2 1.2.2.2 bouyer /* $KAME: altq_hfsc.h,v 1.6 2000/12/14 08:12:46 thorpej Exp $ */
3 1.2.2.2 bouyer
4 1.2.2.2 bouyer /*
5 1.2.2.2 bouyer * Copyright (c) 1997-1999 Carnegie Mellon University. All Rights Reserved.
6 1.2.2.2 bouyer *
7 1.2.2.2 bouyer * Permission to use, copy, modify, and distribute this software and
8 1.2.2.2 bouyer * its documentation is hereby granted (including for commercial or
9 1.2.2.2 bouyer * for-profit use), provided that both the copyright notice and this
10 1.2.2.2 bouyer * permission notice appear in all copies of the software, derivative
11 1.2.2.2 bouyer * works, or modified versions, and any portions thereof, and that
12 1.2.2.2 bouyer * both notices appear in supporting documentation, and that credit
13 1.2.2.2 bouyer * is given to Carnegie Mellon University in all publications reporting
14 1.2.2.2 bouyer * on direct or indirect use of this code or its derivatives.
15 1.2.2.2 bouyer *
16 1.2.2.2 bouyer * THIS SOFTWARE IS EXPERIMENTAL AND IS KNOWN TO HAVE BUGS, SOME OF
17 1.2.2.2 bouyer * WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON PROVIDES THIS
18 1.2.2.2 bouyer * SOFTWARE IN ITS ``AS IS'' CONDITION, AND ANY EXPRESS OR IMPLIED
19 1.2.2.2 bouyer * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.2.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 1.2.2.2 bouyer * DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
22 1.2.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.2.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 1.2.2.2 bouyer * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 1.2.2.2 bouyer * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 1.2.2.2 bouyer * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.2.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
28 1.2.2.2 bouyer * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 1.2.2.2 bouyer * DAMAGE.
30 1.2.2.2 bouyer *
31 1.2.2.2 bouyer * Carnegie Mellon encourages (but does not require) users of this
32 1.2.2.2 bouyer * software to return any improvements or extensions that they make,
33 1.2.2.2 bouyer * and to grant Carnegie Mellon the rights to redistribute these
34 1.2.2.2 bouyer * changes without encumbrance.
35 1.2.2.2 bouyer */
36 1.2.2.2 bouyer #ifndef _ALTQ_ALTQ_HFSC_H_
37 1.2.2.2 bouyer #define _ALTQ_ALTQ_HFSC_H_
38 1.2.2.2 bouyer
39 1.2.2.2 bouyer #include <altq/altq.h>
40 1.2.2.2 bouyer #include <altq/altq_classq.h>
41 1.2.2.2 bouyer #include <altq/altq_red.h>
42 1.2.2.2 bouyer #include <altq/altq_rio.h>
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 struct hfsc_interface {
49 1.2.2.2 bouyer char hfsc_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */
50 1.2.2.2 bouyer };
51 1.2.2.2 bouyer
52 1.2.2.2 bouyer struct hfsc_attach {
53 1.2.2.2 bouyer struct hfsc_interface iface;
54 1.2.2.2 bouyer u_int bandwidth; /* link bandwidth in bits/sec */
55 1.2.2.2 bouyer };
56 1.2.2.2 bouyer
57 1.2.2.2 bouyer struct service_curve {
58 1.2.2.2 bouyer u_int m1; /* slope of the first segment in bits/sec */
59 1.2.2.2 bouyer u_int d; /* the x-projection of the first segment in msec */
60 1.2.2.2 bouyer u_int m2; /* slope of the second segment in bits/sec */
61 1.2.2.2 bouyer };
62 1.2.2.2 bouyer
63 1.2.2.2 bouyer struct hfsc_add_class {
64 1.2.2.2 bouyer struct hfsc_interface iface;
65 1.2.2.2 bouyer u_long parent_handle;
66 1.2.2.2 bouyer struct service_curve service_curve;
67 1.2.2.2 bouyer int qlimit;
68 1.2.2.2 bouyer int flags;
69 1.2.2.2 bouyer
70 1.2.2.2 bouyer u_long class_handle; /* return value */
71 1.2.2.2 bouyer };
72 1.2.2.2 bouyer
73 1.2.2.2 bouyer /* special class handles */
74 1.2.2.2 bouyer #define HFSC_ROOTCLASS_HANDLE 0
75 1.2.2.2 bouyer #define HFSC_NULLCLASS_HANDLE 0
76 1.2.2.2 bouyer
77 1.2.2.2 bouyer /* hfsc class flags */
78 1.2.2.2 bouyer #define HFCF_RED 0x0001 /* use RED */
79 1.2.2.2 bouyer #define HFCF_ECN 0x0002 /* use RED/ECN */
80 1.2.2.2 bouyer #define HFCF_RIO 0x0004 /* use RIO */
81 1.2.2.2 bouyer #define HFCF_CLEARDSCP 0x0010 /* clear diffserv codepoint */
82 1.2.2.2 bouyer #define HFCF_DEFAULTCLASS 0x1000 /* default class */
83 1.2.2.2 bouyer
84 1.2.2.2 bouyer struct hfsc_delete_class {
85 1.2.2.2 bouyer struct hfsc_interface iface;
86 1.2.2.2 bouyer u_long class_handle;
87 1.2.2.2 bouyer };
88 1.2.2.2 bouyer
89 1.2.2.2 bouyer /* service curve types */
90 1.2.2.2 bouyer #define HFSC_REALTIMESC 1
91 1.2.2.2 bouyer #define HFSC_LINKSHARINGSC 2
92 1.2.2.2 bouyer #define HFSC_DEFAULTSC (HFSC_REALTIMESC|HFSC_LINKSHARINGSC)
93 1.2.2.2 bouyer
94 1.2.2.2 bouyer struct hfsc_modify_class {
95 1.2.2.2 bouyer struct hfsc_interface iface;
96 1.2.2.2 bouyer u_long class_handle;
97 1.2.2.2 bouyer struct service_curve service_curve;
98 1.2.2.2 bouyer int sctype;
99 1.2.2.2 bouyer };
100 1.2.2.2 bouyer
101 1.2.2.2 bouyer struct hfsc_add_filter {
102 1.2.2.2 bouyer struct hfsc_interface iface;
103 1.2.2.2 bouyer u_long class_handle;
104 1.2.2.2 bouyer struct flow_filter filter;
105 1.2.2.2 bouyer
106 1.2.2.2 bouyer u_long filter_handle; /* return value */
107 1.2.2.2 bouyer };
108 1.2.2.2 bouyer
109 1.2.2.2 bouyer struct hfsc_delete_filter {
110 1.2.2.2 bouyer struct hfsc_interface iface;
111 1.2.2.2 bouyer u_long filter_handle;
112 1.2.2.2 bouyer };
113 1.2.2.2 bouyer
114 1.2.2.2 bouyer struct class_stats {
115 1.2.2.2 bouyer u_int class_id;
116 1.2.2.2 bouyer u_long class_handle;
117 1.2.2.2 bouyer struct service_curve rsc;
118 1.2.2.2 bouyer struct service_curve fsc;
119 1.2.2.2 bouyer
120 1.2.2.2 bouyer u_int64_t total; /* total work in bytes */
121 1.2.2.2 bouyer u_int64_t cumul; /* cumulative work in bytes
122 1.2.2.2 bouyer done by real-time criteria */
123 1.2.2.2 bouyer u_int64_t d; /* deadline */
124 1.2.2.2 bouyer u_int64_t e; /* eligible time */
125 1.2.2.2 bouyer u_int64_t vt; /* virtual time */
126 1.2.2.2 bouyer
127 1.2.2.2 bouyer u_int qlength;
128 1.2.2.2 bouyer struct pktcntr xmit_cnt;
129 1.2.2.2 bouyer struct pktcntr drop_cnt;
130 1.2.2.2 bouyer u_int period;
131 1.2.2.2 bouyer
132 1.2.2.2 bouyer /* red and rio related info */
133 1.2.2.2 bouyer int qtype;
134 1.2.2.2 bouyer struct redstats red[3];
135 1.2.2.2 bouyer };
136 1.2.2.2 bouyer
137 1.2.2.2 bouyer struct hfsc_class_stats {
138 1.2.2.2 bouyer struct hfsc_interface iface;
139 1.2.2.2 bouyer int nskip; /* skip # of classes */
140 1.2.2.2 bouyer int nclasses; /* # of class stats (WR) */
141 1.2.2.2 bouyer u_int64_t cur_time; /* current time */
142 1.2.2.2 bouyer u_int hif_classes; /* # of classes in the tree */
143 1.2.2.2 bouyer u_int hif_packets; /* # of packets in the tree */
144 1.2.2.2 bouyer struct class_stats *stats; /* pointer to stats array */
145 1.2.2.2 bouyer };
146 1.2.2.2 bouyer
147 1.2.2.2 bouyer #define HFSC_IF_ATTACH _IOW('Q', 1, struct hfsc_attach)
148 1.2.2.2 bouyer #define HFSC_IF_DETACH _IOW('Q', 2, struct hfsc_interface)
149 1.2.2.2 bouyer #define HFSC_ENABLE _IOW('Q', 3, struct hfsc_interface)
150 1.2.2.2 bouyer #define HFSC_DISABLE _IOW('Q', 4, struct hfsc_interface)
151 1.2.2.2 bouyer #define HFSC_CLEAR_HIERARCHY _IOW('Q', 5, struct hfsc_interface)
152 1.2.2.2 bouyer #define HFSC_ADD_CLASS _IOWR('Q', 7, struct hfsc_add_class)
153 1.2.2.2 bouyer #define HFSC_DEL_CLASS _IOW('Q', 8, struct hfsc_delete_class)
154 1.2.2.2 bouyer #define HFSC_MOD_CLASS _IOW('Q', 9, struct hfsc_modify_class)
155 1.2.2.2 bouyer #define HFSC_ADD_FILTER _IOWR('Q', 10, struct hfsc_add_filter)
156 1.2.2.2 bouyer #define HFSC_DEL_FILTER _IOW('Q', 11, struct hfsc_delete_filter)
157 1.2.2.2 bouyer #define HFSC_GETSTATS _IOWR('Q', 12, struct hfsc_class_stats)
158 1.2.2.2 bouyer
159 1.2.2.2 bouyer #ifdef _KERNEL
160 1.2.2.2 bouyer /*
161 1.2.2.2 bouyer * kernel internal service curve representation
162 1.2.2.2 bouyer * coordinates are given by 64 bit unsigned integers.
163 1.2.2.2 bouyer * x-axis: unit is clock count. for the intel x86 architecture,
164 1.2.2.2 bouyer * the raw Pentium TSC (Timestamp Counter) value is used.
165 1.2.2.2 bouyer * virtual time is also calculated in this time scale.
166 1.2.2.2 bouyer * y-axis: unit is byte.
167 1.2.2.2 bouyer *
168 1.2.2.2 bouyer * the service curve parameters are converted to the internal
169 1.2.2.2 bouyer * representation.
170 1.2.2.2 bouyer * the slope values are scaled to avoid overflow.
171 1.2.2.2 bouyer * the inverse slope values as well as the y-projection of the 1st
172 1.2.2.2 bouyer * segment are kept in order to to avoid 64-bit divide operations
173 1.2.2.2 bouyer * that are expensive on 32-bit architectures.
174 1.2.2.2 bouyer *
175 1.2.2.2 bouyer * note: Intel Pentium TSC never wraps around in several thousands of years.
176 1.2.2.2 bouyer * x-axis doesn't wrap around for 1089 years with 1GHz clock.
177 1.2.2.2 bouyer * y-axis doesn't wrap around for 4358 years with 1Gbps bandwidth.
178 1.2.2.2 bouyer */
179 1.2.2.2 bouyer
180 1.2.2.2 bouyer /* kernel internal representation of a service curve */
181 1.2.2.2 bouyer struct internal_sc {
182 1.2.2.2 bouyer u_int64_t sm1; /* scaled slope of the 1st segment */
183 1.2.2.2 bouyer u_int64_t ism1; /* scaled inverse-slope of the 1st segment */
184 1.2.2.2 bouyer u_int64_t dx; /* the x-projection of the 1st segment */
185 1.2.2.2 bouyer u_int64_t dy; /* the y-projection of the 1st segment */
186 1.2.2.2 bouyer u_int64_t sm2; /* scaled slope of the 2nd segment */
187 1.2.2.2 bouyer u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */
188 1.2.2.2 bouyer };
189 1.2.2.2 bouyer
190 1.2.2.2 bouyer /* runtime service curve */
191 1.2.2.2 bouyer struct runtime_sc {
192 1.2.2.2 bouyer u_int64_t x; /* current starting position on x-axis */
193 1.2.2.2 bouyer u_int64_t y; /* current starting position on x-axis */
194 1.2.2.2 bouyer u_int64_t sm1; /* scaled slope of the 1st segment */
195 1.2.2.2 bouyer u_int64_t ism1; /* scaled inverse-slope of the 1st segment */
196 1.2.2.2 bouyer u_int64_t dx; /* the x-projection of the 1st segment */
197 1.2.2.2 bouyer u_int64_t dy; /* the y-projection of the 1st segment */
198 1.2.2.2 bouyer u_int64_t sm2; /* scaled slope of the 2nd segment */
199 1.2.2.2 bouyer u_int64_t ism2; /* scaled inverse-slope of the 2nd segment */
200 1.2.2.2 bouyer };
201 1.2.2.2 bouyer
202 1.2.2.2 bouyer /* for TAILQ based ellist and actlist implementation */
203 1.2.2.2 bouyer struct hfsc_class;
204 1.2.2.2 bouyer typedef TAILQ_HEAD(_eligible, hfsc_class) ellist_t;
205 1.2.2.2 bouyer typedef TAILQ_ENTRY(hfsc_class) elentry_t;
206 1.2.2.2 bouyer typedef TAILQ_HEAD(_active, hfsc_class) actlist_t;
207 1.2.2.2 bouyer typedef TAILQ_ENTRY(hfsc_class) actentry_t;
208 1.2.2.2 bouyer #define ellist_first(s) TAILQ_FIRST(s)
209 1.2.2.2 bouyer #define actlist_first(s) TAILQ_FIRST(s)
210 1.2.2.2 bouyer #define actlist_last(s) TAILQ_LAST(s, _active)
211 1.2.2.2 bouyer
212 1.2.2.2 bouyer struct hfsc_class {
213 1.2.2.2 bouyer u_int cl_id; /* class id (just for debug) */
214 1.2.2.2 bouyer u_long cl_handle; /* class handle */
215 1.2.2.2 bouyer struct hfsc_if *cl_hif; /* back pointer to struct hfsc_if */
216 1.2.2.2 bouyer int cl_flags; /* misc flags */
217 1.2.2.2 bouyer
218 1.2.2.2 bouyer struct hfsc_class *cl_parent; /* parent class */
219 1.2.2.2 bouyer struct hfsc_class *cl_siblings; /* sibling classes */
220 1.2.2.2 bouyer struct hfsc_class *cl_children; /* child classes */
221 1.2.2.2 bouyer
222 1.2.2.2 bouyer class_queue_t *cl_q; /* class queue structure */
223 1.2.2.2 bouyer struct red *cl_red; /* RED state */
224 1.2.2.2 bouyer struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
225 1.2.2.2 bouyer
226 1.2.2.2 bouyer u_int64_t cl_total; /* total work in bytes */
227 1.2.2.2 bouyer u_int64_t cl_cumul; /* cumulative work in bytes
228 1.2.2.2 bouyer done by real-time criteria */
229 1.2.2.2 bouyer u_int64_t cl_d; /* deadline */
230 1.2.2.2 bouyer u_int64_t cl_e; /* eligible time */
231 1.2.2.2 bouyer u_int64_t cl_vt; /* virtual time */
232 1.2.2.2 bouyer
233 1.2.2.2 bouyer struct internal_sc *cl_rsc; /* internal real-time service curve */
234 1.2.2.2 bouyer struct internal_sc *cl_fsc; /* internal fair service curve */
235 1.2.2.2 bouyer struct runtime_sc cl_deadline; /* deadline curve */
236 1.2.2.2 bouyer struct runtime_sc cl_eligible; /* eligible curve */
237 1.2.2.2 bouyer struct runtime_sc cl_virtual; /* virtual curve */
238 1.2.2.2 bouyer
239 1.2.2.2 bouyer u_int cl_vtperiod; /* vt period sequence no */
240 1.2.2.2 bouyer u_int cl_parentperiod; /* parent's vt period seqno */
241 1.2.2.2 bouyer int cl_nactive; /* number of active children */
242 1.2.2.2 bouyer actlist_t *cl_actc; /* active children list */
243 1.2.2.2 bouyer
244 1.2.2.2 bouyer actentry_t cl_actlist; /* active children list entry */
245 1.2.2.2 bouyer elentry_t cl_ellist; /* eligible list entry */
246 1.2.2.2 bouyer
247 1.2.2.2 bouyer struct {
248 1.2.2.2 bouyer struct pktcntr xmit_cnt;
249 1.2.2.2 bouyer struct pktcntr drop_cnt;
250 1.2.2.2 bouyer u_int period;
251 1.2.2.2 bouyer } cl_stats;
252 1.2.2.2 bouyer };
253 1.2.2.2 bouyer
254 1.2.2.2 bouyer /*
255 1.2.2.2 bouyer * hfsc interface state
256 1.2.2.2 bouyer */
257 1.2.2.2 bouyer struct hfsc_if {
258 1.2.2.2 bouyer struct hfsc_if *hif_next; /* interface state list */
259 1.2.2.2 bouyer struct ifaltq *hif_ifq; /* backpointer to ifaltq */
260 1.2.2.2 bouyer struct hfsc_class *hif_rootclass; /* root class */
261 1.2.2.2 bouyer struct hfsc_class *hif_defaultclass; /* default class */
262 1.2.2.2 bouyer struct hfsc_class *hif_pollcache; /* cache for poll operation */
263 1.2.2.2 bouyer
264 1.2.2.2 bouyer u_int hif_classes; /* # of classes in the tree */
265 1.2.2.2 bouyer u_int hif_packets; /* # of packets in the tree */
266 1.2.2.2 bouyer u_int hif_classid; /* class id sequence number */
267 1.2.2.2 bouyer
268 1.2.2.2 bouyer ellist_t *hif_eligible; /* eligible list */
269 1.2.2.2 bouyer
270 1.2.2.2 bouyer struct acc_classifier hif_classifier;
271 1.2.2.2 bouyer };
272 1.2.2.2 bouyer
273 1.2.2.2 bouyer #endif /* _KERNEL */
274 1.2.2.2 bouyer
275 1.2.2.2 bouyer #ifdef __cplusplus
276 1.2.2.2 bouyer }
277 1.2.2.2 bouyer #endif
278 1.2.2.2 bouyer
279 1.2.2.2 bouyer #endif /* _ALTQ_ALTQ_HFSC_H_ */
280