altq_cdnr.h revision 1.2.2.2 1 1.2.2.2 bouyer /* $NetBSD: altq_cdnr.h,v 1.2.2.2 2001/01/05 17:39:36 bouyer Exp $ */
2 1.2.2.2 bouyer /* $KAME: altq_cdnr.h,v 1.6 2000/12/14 08:12:45 thorpej Exp $ */
3 1.2.2.2 bouyer
4 1.2.2.2 bouyer /*
5 1.2.2.2 bouyer * Copyright (C) 1999-2000
6 1.2.2.2 bouyer * Sony Computer Science Laboratories Inc. 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 *
17 1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
18 1.2.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.2.2.2 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.2.2.2 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
21 1.2.2.2 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.2.2.2 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.2.2.2 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.2.2.2 bouyer * SUCH DAMAGE.
28 1.2.2.2 bouyer */
29 1.2.2.2 bouyer
30 1.2.2.2 bouyer #ifndef _ALTQ_ALTQ_CDNR_H_
31 1.2.2.2 bouyer #define _ALTQ_ALTQ_CDNR_H_
32 1.2.2.2 bouyer
33 1.2.2.2 bouyer #include <altq/altq.h>
34 1.2.2.2 bouyer
35 1.2.2.2 bouyer /*
36 1.2.2.2 bouyer * traffic conditioner element types
37 1.2.2.2 bouyer */
38 1.2.2.2 bouyer #define TCETYPE_NONE 0
39 1.2.2.2 bouyer #define TCETYPE_TOP 1 /* top level conditioner */
40 1.2.2.2 bouyer #define TCETYPE_ELEMENT 2 /* a simple tc element */
41 1.2.2.2 bouyer #define TCETYPE_TBMETER 3 /* token bucket meter */
42 1.2.2.2 bouyer #define TCETYPE_TRTCM 4 /* (two-rate) three color marker */
43 1.2.2.2 bouyer #define TCETYPE_TSWTCM 5 /* time sliding window 3-color maker */
44 1.2.2.2 bouyer
45 1.2.2.2 bouyer /*
46 1.2.2.2 bouyer * traffic conditioner action
47 1.2.2.2 bouyer */
48 1.2.2.2 bouyer struct cdnr_block;
49 1.2.2.2 bouyer
50 1.2.2.2 bouyer struct tc_action {
51 1.2.2.2 bouyer int tca_code; /* e.g., TCACODE_PASS */
52 1.2.2.2 bouyer /* tca_code dependent variable */
53 1.2.2.2 bouyer union {
54 1.2.2.2 bouyer u_long un_value; /* template */
55 1.2.2.2 bouyer u_int8_t un_dscp; /* diffserv code point */
56 1.2.2.2 bouyer u_long un_handle; /* tc action handle */
57 1.2.2.2 bouyer struct cdnr_block *un_next; /* next tc element block */
58 1.2.2.2 bouyer } tca_un;
59 1.2.2.2 bouyer };
60 1.2.2.2 bouyer #define tca_value tca_un.un_value
61 1.2.2.2 bouyer #define tca_dscp tca_un.un_dscp
62 1.2.2.2 bouyer #define tca_handle tca_un.un_handle
63 1.2.2.2 bouyer #define tca_next tca_un.un_next
64 1.2.2.2 bouyer
65 1.2.2.2 bouyer #define TCACODE_NONE 0 /* action is not set */
66 1.2.2.2 bouyer #define TCACODE_PASS 1 /* pass this packet */
67 1.2.2.2 bouyer #define TCACODE_DROP 2 /* discard this packet */
68 1.2.2.2 bouyer #define TCACODE_RETURN 3 /* do not process this packet */
69 1.2.2.2 bouyer #define TCACODE_MARK 4 /* mark dscp */
70 1.2.2.2 bouyer #define TCACODE_HANDLE 5 /* take action specified by handle */
71 1.2.2.2 bouyer #define TCACODE_NEXT 6 /* take action in the next tc element */
72 1.2.2.2 bouyer #define TCACODE_MAX 6
73 1.2.2.2 bouyer
74 1.2.2.2 bouyer #define CDNR_NULL_HANDLE 0
75 1.2.2.2 bouyer
76 1.2.2.2 bouyer struct cdnr_interface {
77 1.2.2.2 bouyer char cdnr_ifname[IFNAMSIZ]; /* interface name (e.g., fxp0) */
78 1.2.2.2 bouyer };
79 1.2.2.2 bouyer
80 1.2.2.2 bouyer /* simple element operations */
81 1.2.2.2 bouyer struct cdnr_add_element {
82 1.2.2.2 bouyer struct cdnr_interface iface;
83 1.2.2.2 bouyer struct tc_action action;
84 1.2.2.2 bouyer
85 1.2.2.2 bouyer u_long cdnr_handle; /* return value */
86 1.2.2.2 bouyer };
87 1.2.2.2 bouyer
88 1.2.2.2 bouyer struct cdnr_delete_element {
89 1.2.2.2 bouyer struct cdnr_interface iface;
90 1.2.2.2 bouyer u_long cdnr_handle;
91 1.2.2.2 bouyer };
92 1.2.2.2 bouyer
93 1.2.2.2 bouyer /* token-bucket meter operations */
94 1.2.2.2 bouyer struct cdnr_add_tbmeter {
95 1.2.2.2 bouyer struct cdnr_interface iface;
96 1.2.2.2 bouyer struct tb_profile profile;
97 1.2.2.2 bouyer struct tc_action in_action;
98 1.2.2.2 bouyer struct tc_action out_action;
99 1.2.2.2 bouyer
100 1.2.2.2 bouyer u_long cdnr_handle; /* return value */
101 1.2.2.2 bouyer };
102 1.2.2.2 bouyer
103 1.2.2.2 bouyer struct cdnr_modify_tbmeter {
104 1.2.2.2 bouyer struct cdnr_interface iface;
105 1.2.2.2 bouyer u_long cdnr_handle;
106 1.2.2.2 bouyer struct tb_profile profile;
107 1.2.2.2 bouyer };
108 1.2.2.2 bouyer
109 1.2.2.2 bouyer struct cdnr_tbmeter_stats {
110 1.2.2.2 bouyer struct cdnr_interface iface;
111 1.2.2.2 bouyer u_long cdnr_handle;
112 1.2.2.2 bouyer struct pktcntr in_cnt;
113 1.2.2.2 bouyer struct pktcntr out_cnt;
114 1.2.2.2 bouyer };
115 1.2.2.2 bouyer
116 1.2.2.2 bouyer /* two-rate three-color marker operations */
117 1.2.2.2 bouyer struct cdnr_add_trtcm {
118 1.2.2.2 bouyer struct cdnr_interface iface;
119 1.2.2.2 bouyer struct tb_profile cmtd_profile; /* profile for committed tb */
120 1.2.2.2 bouyer struct tb_profile peak_profile; /* profile for peak tb */
121 1.2.2.2 bouyer struct tc_action green_action; /* action for green packets */
122 1.2.2.2 bouyer struct tc_action yellow_action; /* action for yellow packets */
123 1.2.2.2 bouyer struct tc_action red_action; /* action for red packets */
124 1.2.2.2 bouyer int coloraware; /* color-aware/color-blind */
125 1.2.2.2 bouyer
126 1.2.2.2 bouyer u_long cdnr_handle; /* return value */
127 1.2.2.2 bouyer };
128 1.2.2.2 bouyer
129 1.2.2.2 bouyer struct cdnr_modify_trtcm {
130 1.2.2.2 bouyer struct cdnr_interface iface;
131 1.2.2.2 bouyer u_long cdnr_handle;
132 1.2.2.2 bouyer struct tb_profile cmtd_profile; /* profile for committed tb */
133 1.2.2.2 bouyer struct tb_profile peak_profile; /* profile for peak tb */
134 1.2.2.2 bouyer int coloraware; /* color-aware/color-blind */
135 1.2.2.2 bouyer };
136 1.2.2.2 bouyer
137 1.2.2.2 bouyer struct cdnr_tcm_stats {
138 1.2.2.2 bouyer struct cdnr_interface iface;
139 1.2.2.2 bouyer u_long cdnr_handle;
140 1.2.2.2 bouyer struct pktcntr green_cnt;
141 1.2.2.2 bouyer struct pktcntr yellow_cnt;
142 1.2.2.2 bouyer struct pktcntr red_cnt;
143 1.2.2.2 bouyer };
144 1.2.2.2 bouyer
145 1.2.2.2 bouyer /* time sliding window three-color marker operations */
146 1.2.2.2 bouyer struct cdnr_add_tswtcm {
147 1.2.2.2 bouyer struct cdnr_interface iface;
148 1.2.2.2 bouyer u_int32_t cmtd_rate; /* committed rate (bits/sec) */
149 1.2.2.2 bouyer u_int32_t peak_rate; /* peak rate (bits/sec) */
150 1.2.2.2 bouyer u_int32_t avg_interval; /* averaging interval (msec) */
151 1.2.2.2 bouyer struct tc_action green_action; /* action for green packets */
152 1.2.2.2 bouyer struct tc_action yellow_action; /* action for yellow packets */
153 1.2.2.2 bouyer struct tc_action red_action; /* action for red packets */
154 1.2.2.2 bouyer
155 1.2.2.2 bouyer u_long cdnr_handle; /* return value */
156 1.2.2.2 bouyer };
157 1.2.2.2 bouyer
158 1.2.2.2 bouyer struct cdnr_modify_tswtcm {
159 1.2.2.2 bouyer struct cdnr_interface iface;
160 1.2.2.2 bouyer u_long cdnr_handle;
161 1.2.2.2 bouyer u_int32_t cmtd_rate; /* committed rate (bits/sec) */
162 1.2.2.2 bouyer u_int32_t peak_rate; /* peak rate (bits/sec) */
163 1.2.2.2 bouyer u_int32_t avg_interval; /* averaging interval (msec) */
164 1.2.2.2 bouyer };
165 1.2.2.2 bouyer
166 1.2.2.2 bouyer struct cdnr_add_filter {
167 1.2.2.2 bouyer struct cdnr_interface iface;
168 1.2.2.2 bouyer u_long cdnr_handle;
169 1.2.2.2 bouyer struct flow_filter filter;
170 1.2.2.2 bouyer
171 1.2.2.2 bouyer u_long filter_handle; /* return value */
172 1.2.2.2 bouyer };
173 1.2.2.2 bouyer
174 1.2.2.2 bouyer struct cdnr_delete_filter {
175 1.2.2.2 bouyer struct cdnr_interface iface;
176 1.2.2.2 bouyer u_long filter_handle;
177 1.2.2.2 bouyer };
178 1.2.2.2 bouyer
179 1.2.2.2 bouyer struct tce_stats {
180 1.2.2.2 bouyer u_long tce_handle; /* tc element handle */
181 1.2.2.2 bouyer int tce_type; /* e.g., TCETYPE_ELEMENT */
182 1.2.2.2 bouyer struct pktcntr tce_cnts[3]; /* tcm returns 3 counters */
183 1.2.2.2 bouyer };
184 1.2.2.2 bouyer
185 1.2.2.2 bouyer struct cdnr_get_stats {
186 1.2.2.2 bouyer struct cdnr_interface iface;
187 1.2.2.2 bouyer struct pktcntr cnts[TCACODE_MAX+1];
188 1.2.2.2 bouyer
189 1.2.2.2 bouyer /* element stats */
190 1.2.2.2 bouyer int nskip; /* skip # of elements */
191 1.2.2.2 bouyer int nelements; /* # of element stats (WR) */
192 1.2.2.2 bouyer struct tce_stats *tce_stats; /* pointer to stats array */
193 1.2.2.2 bouyer };
194 1.2.2.2 bouyer
195 1.2.2.2 bouyer #define CDNR_IF_ATTACH _IOW('Q', 1, struct cdnr_interface)
196 1.2.2.2 bouyer #define CDNR_IF_DETACH _IOW('Q', 2, struct cdnr_interface)
197 1.2.2.2 bouyer #define CDNR_ENABLE _IOW('Q', 3, struct cdnr_interface)
198 1.2.2.2 bouyer #define CDNR_DISABLE _IOW('Q', 4, struct cdnr_interface)
199 1.2.2.2 bouyer #define CDNR_ADD_FILTER _IOWR('Q', 10, struct cdnr_add_filter)
200 1.2.2.2 bouyer #define CDNR_DEL_FILTER _IOW('Q', 11, struct cdnr_delete_filter)
201 1.2.2.2 bouyer #define CDNR_GETSTATS _IOWR('Q', 12, struct cdnr_get_stats)
202 1.2.2.2 bouyer #define CDNR_ADD_ELEM _IOWR('Q', 30, struct cdnr_add_element)
203 1.2.2.2 bouyer #define CDNR_DEL_ELEM _IOW('Q', 31, struct cdnr_delete_element)
204 1.2.2.2 bouyer #define CDNR_ADD_TBM _IOWR('Q', 32, struct cdnr_add_tbmeter)
205 1.2.2.2 bouyer #define CDNR_MOD_TBM _IOW('Q', 33, struct cdnr_modify_tbmeter)
206 1.2.2.2 bouyer #define CDNR_TBM_STATS _IOWR('Q', 34, struct cdnr_tbmeter_stats)
207 1.2.2.2 bouyer #define CDNR_ADD_TCM _IOWR('Q', 35, struct cdnr_add_trtcm)
208 1.2.2.2 bouyer #define CDNR_MOD_TCM _IOWR('Q', 36, struct cdnr_modify_trtcm)
209 1.2.2.2 bouyer #define CDNR_TCM_STATS _IOWR('Q', 37, struct cdnr_tcm_stats)
210 1.2.2.2 bouyer #define CDNR_ADD_TSW _IOWR('Q', 38, struct cdnr_add_tswtcm)
211 1.2.2.2 bouyer #define CDNR_MOD_TSW _IOWR('Q', 39, struct cdnr_modify_tswtcm)
212 1.2.2.2 bouyer
213 1.2.2.2 bouyer #ifndef DSCP_EF
214 1.2.2.2 bouyer /* diffserve code points */
215 1.2.2.2 bouyer #define DSCP_MASK 0xfc
216 1.2.2.2 bouyer #define DSCP_CUMASK 0x03
217 1.2.2.2 bouyer #define DSCP_EF 0xb8
218 1.2.2.2 bouyer #define DSCP_AF11 0x28
219 1.2.2.2 bouyer #define DSCP_AF12 0x30
220 1.2.2.2 bouyer #define DSCP_AF13 0x38
221 1.2.2.2 bouyer #define DSCP_AF21 0x48
222 1.2.2.2 bouyer #define DSCP_AF22 0x50
223 1.2.2.2 bouyer #define DSCP_AF23 0x58
224 1.2.2.2 bouyer #define DSCP_AF31 0x68
225 1.2.2.2 bouyer #define DSCP_AF32 0x70
226 1.2.2.2 bouyer #define DSCP_AF33 0x78
227 1.2.2.2 bouyer #define DSCP_AF41 0x88
228 1.2.2.2 bouyer #define DSCP_AF42 0x90
229 1.2.2.2 bouyer #define DSCP_AF43 0x98
230 1.2.2.2 bouyer #define AF_CLASSMASK 0xe0
231 1.2.2.2 bouyer #define AF_DROPPRECMASK 0x18
232 1.2.2.2 bouyer #endif
233 1.2.2.2 bouyer
234 1.2.2.2 bouyer #ifdef _KERNEL
235 1.2.2.2 bouyer
236 1.2.2.2 bouyer /*
237 1.2.2.2 bouyer * packet information passed to the input function of tc elements
238 1.2.2.2 bouyer */
239 1.2.2.2 bouyer struct cdnr_pktinfo {
240 1.2.2.2 bouyer int pkt_len; /* packet length */
241 1.2.2.2 bouyer u_int8_t pkt_dscp; /* diffserv code point */
242 1.2.2.2 bouyer };
243 1.2.2.2 bouyer
244 1.2.2.2 bouyer /*
245 1.2.2.2 bouyer * traffic conditioner control block common to all types of tc elements
246 1.2.2.2 bouyer */
247 1.2.2.2 bouyer struct cdnr_block {
248 1.2.2.2 bouyer LIST_ENTRY(cdnr_block) cb_next;
249 1.2.2.2 bouyer int cb_len; /* size of this tc element */
250 1.2.2.2 bouyer int cb_type; /* cdnr block type */
251 1.2.2.2 bouyer int cb_ref; /* reference count of this element */
252 1.2.2.2 bouyer u_long cb_handle; /* handle of this tc element */
253 1.2.2.2 bouyer struct top_cdnr *cb_top; /* back pointer to top */
254 1.2.2.2 bouyer struct tc_action cb_action; /* top level action for this tcb */
255 1.2.2.2 bouyer struct tc_action *(*cb_input)(struct cdnr_block *,
256 1.2.2.2 bouyer struct cdnr_pktinfo *);
257 1.2.2.2 bouyer };
258 1.2.2.2 bouyer
259 1.2.2.2 bouyer /*
260 1.2.2.2 bouyer * top level traffic conditioner structure for an interface
261 1.2.2.2 bouyer */
262 1.2.2.2 bouyer struct top_cdnr {
263 1.2.2.2 bouyer struct cdnr_block tc_block;
264 1.2.2.2 bouyer
265 1.2.2.2 bouyer LIST_ENTRY(top_cdnr) tc_next;
266 1.2.2.2 bouyer struct ifaltq *tc_ifq;
267 1.2.2.2 bouyer
268 1.2.2.2 bouyer LIST_HEAD(, cdnr_block) tc_elements;
269 1.2.2.2 bouyer struct acc_classifier tc_classifier;
270 1.2.2.2 bouyer
271 1.2.2.2 bouyer struct pktcntr tc_cnts[TCACODE_MAX+1];
272 1.2.2.2 bouyer };
273 1.2.2.2 bouyer
274 1.2.2.2 bouyer /* token bucket element */
275 1.2.2.2 bouyer struct tbe {
276 1.2.2.2 bouyer u_int64_t rate;
277 1.2.2.2 bouyer u_int64_t depth;
278 1.2.2.2 bouyer
279 1.2.2.2 bouyer u_int64_t token;
280 1.2.2.2 bouyer u_int64_t filluptime;
281 1.2.2.2 bouyer u_int64_t last;
282 1.2.2.2 bouyer };
283 1.2.2.2 bouyer
284 1.2.2.2 bouyer /* token bucket meter structure */
285 1.2.2.2 bouyer struct tbmeter {
286 1.2.2.2 bouyer struct cdnr_block cdnrblk; /* conditioner block */
287 1.2.2.2 bouyer struct tbe tb; /* token bucket */
288 1.2.2.2 bouyer struct tc_action in_action; /* actions for IN/OUT */
289 1.2.2.2 bouyer struct tc_action out_action; /* actions for IN/OUT */
290 1.2.2.2 bouyer struct pktcntr in_cnt; /* statistics for IN/OUT */
291 1.2.2.2 bouyer struct pktcntr out_cnt; /* statistics for IN/OUT */
292 1.2.2.2 bouyer };
293 1.2.2.2 bouyer
294 1.2.2.2 bouyer /* two-rate three-color marker structure */
295 1.2.2.2 bouyer struct trtcm {
296 1.2.2.2 bouyer struct cdnr_block cdnrblk; /* conditioner block */
297 1.2.2.2 bouyer struct tbe cmtd_tb; /* committed tb profile */
298 1.2.2.2 bouyer struct tbe peak_tb; /* peak tb profile */
299 1.2.2.2 bouyer struct tc_action green_action;
300 1.2.2.2 bouyer struct tc_action yellow_action;
301 1.2.2.2 bouyer struct tc_action red_action;
302 1.2.2.2 bouyer int coloraware;
303 1.2.2.2 bouyer u_int8_t green_dscp;
304 1.2.2.2 bouyer u_int8_t yellow_dscp;
305 1.2.2.2 bouyer u_int8_t red_dscp;
306 1.2.2.2 bouyer struct pktcntr green_cnt;
307 1.2.2.2 bouyer struct pktcntr yellow_cnt;
308 1.2.2.2 bouyer struct pktcntr red_cnt;
309 1.2.2.2 bouyer };
310 1.2.2.2 bouyer
311 1.2.2.2 bouyer /* time sliding window three-color marker structure */
312 1.2.2.2 bouyer struct tswtcm {
313 1.2.2.2 bouyer struct cdnr_block cdnrblk; /* conditioner block */
314 1.2.2.2 bouyer
315 1.2.2.2 bouyer u_int32_t avg_rate; /* average rate (bytes/sec) */
316 1.2.2.2 bouyer u_int64_t t_front; /* timestamp of last update */
317 1.2.2.2 bouyer
318 1.2.2.2 bouyer u_int64_t timewin; /* average interval */
319 1.2.2.2 bouyer u_int32_t cmtd_rate; /* committed target rate */
320 1.2.2.2 bouyer u_int32_t peak_rate; /* peak target rate */
321 1.2.2.2 bouyer struct tc_action green_action;
322 1.2.2.2 bouyer struct tc_action yellow_action;
323 1.2.2.2 bouyer struct tc_action red_action;
324 1.2.2.2 bouyer u_int8_t green_dscp;
325 1.2.2.2 bouyer u_int8_t yellow_dscp;
326 1.2.2.2 bouyer u_int8_t red_dscp;
327 1.2.2.2 bouyer struct pktcntr green_cnt;
328 1.2.2.2 bouyer struct pktcntr yellow_cnt;
329 1.2.2.2 bouyer struct pktcntr red_cnt;
330 1.2.2.2 bouyer };
331 1.2.2.2 bouyer
332 1.2.2.2 bouyer #endif /* _KERNEL */
333 1.2.2.2 bouyer
334 1.2.2.2 bouyer #endif /* _ALTQ_ALTQ_CDNR_H_ */
335