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