summaryrefslogtreecommitdiffstats
path: root/freebsd/sys/contrib/altq/altq/altq_cdnr.h
blob: d55402f4ef582933dfd63c8bb8ac2c1f91d96de4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*	$KAME: altq_cdnr.h,v 1.9 2003/07/10 12:07:48 kjc Exp $	*/

/*
 * Copyright (C) 1999-2002
 *	Sony Computer Science Laboratories Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef _ALTQ_ALTQ_CDNR_H_
#define	_ALTQ_ALTQ_CDNR_H_

#include <altq/altq.h>

/*
 * traffic conditioner element types
 */
#define	TCETYPE_NONE		0
#define	TCETYPE_TOP		1	/* top level conditioner */
#define	TCETYPE_ELEMENT		2	/* a simple tc element */
#define	TCETYPE_TBMETER		3	/* token bucket meter */
#define	TCETYPE_TRTCM		4	/* (two-rate) three color marker */
#define	TCETYPE_TSWTCM		5	/* time sliding window 3-color maker */

/*
 * traffic conditioner action
 */
struct cdnr_block;

struct tc_action {
	int	tca_code;	/* e.g., TCACODE_PASS */
	/* tca_code dependent variable */
	union {
		u_long		un_value;	/* template */
		u_int8_t	un_dscp;	/* diffserv code point */
		u_long		un_handle;	/* tc action handle */
		struct cdnr_block *un_next;	/* next tc element block */
	} tca_un;
};
#define	tca_value	tca_un.un_value
#define	tca_dscp	tca_un.un_dscp
#define	tca_handle	tca_un.un_handle
#define	tca_next	tca_un.un_next

#define	TCACODE_NONE	0	/* action is not set */
#define	TCACODE_PASS	1 	/* pass this packet */
#define	TCACODE_DROP	2	/* discard this packet */
#define	TCACODE_RETURN	3	/* do not process this packet */
#define	TCACODE_MARK	4	/* mark dscp */
#define	TCACODE_HANDLE	5	/* take action specified by handle */
#define	TCACODE_NEXT	6	/* take action in the next tc element */
#define	TCACODE_MAX	6

#define	CDNR_NULL_HANDLE	0

struct cdnr_interface {
	char	cdnr_ifname[IFNAMSIZ];  /* interface name (e.g., fxp0) */
};

/* simple element operations */
struct cdnr_add_element {
	struct cdnr_interface	iface;
	struct tc_action	action;

	u_long			cdnr_handle;	/* return value */
};

struct cdnr_delete_element {
	struct cdnr_interface	iface;
	u_long			cdnr_handle;
};

/* token-bucket meter operations */
struct cdnr_add_tbmeter {
	struct cdnr_interface	iface;
	struct tb_profile	profile;
	struct tc_action	in_action;
	struct tc_action	out_action;

	u_long			cdnr_handle;	/* return value */
};

struct cdnr_modify_tbmeter {
	struct cdnr_interface	iface;
	u_long			cdnr_handle;
	struct tb_profile	profile;
};

struct cdnr_tbmeter_stats {
	struct cdnr_interface	iface;
	u_long			cdnr_handle;
	struct pktcntr		in_cnt;
	struct pktcntr		out_cnt;
};

/* two-rate three-color marker operations */
struct cdnr_add_trtcm {
	struct cdnr_interface	iface;
	struct tb_profile	cmtd_profile;	/* profile for committed tb */
	struct tb_profile	peak_profile;	/* profile for peak tb */
	struct tc_action	green_action;	/* action for green packets */
	struct tc_action	yellow_action;	/* action for yellow packets */
	struct tc_action	red_action;	/* action for red packets */
	int			coloraware;	/* color-aware/color-blind */

	u_long			cdnr_handle;	/* return value */
};

struct cdnr_modify_trtcm {
	struct cdnr_interface	iface;
	u_long			cdnr_handle;
	struct tb_profile	cmtd_profile;	/* profile for committed tb */
	struct tb_profile	peak_profile;	/* profile for peak tb */
	int			coloraware;	/* color-aware/color-blind */
};

struct cdnr_tcm_stats {
	struct cdnr_interface	iface;
	u_long			cdnr_handle;
	struct pktcntr		green_cnt;
	struct pktcntr		yellow_cnt;
	struct pktcntr		red_cnt;
};

/* time sliding window three-color marker operations */
struct cdnr_add_tswtcm {
	struct cdnr_interface	iface;
	u_int32_t		cmtd_rate;	/* committed rate (bits/sec) */
	u_int32_t		peak_rate;	/* peak rate (bits/sec) */
	u_int32_t		avg_interval;	/* averaging interval (msec) */
	struct tc_action	green_action;	/* action for green packets */
	struct tc_action	yellow_action;	/* action for yellow packets */
	struct tc_action	red_action;	/* action for red packets */

	u_long			cdnr_handle;	/* return value */
};

struct cdnr_modify_tswtcm {
	struct cdnr_interface	iface;
	u_long			cdnr_handle;
	u_int32_t		cmtd_rate;	/* committed rate (bits/sec) */
	u_int32_t		peak_rate;	/* peak rate (bits/sec) */
	u_int32_t		avg_interval;	/* averaging interval (msec) */
};

struct cdnr_add_filter {
	struct cdnr_interface	iface;
	u_long			cdnr_handle;
#ifdef ALTQ3_CLFIER_COMPAT
	struct flow_filter	filter;
#endif
	u_long			filter_handle;	/* return value */
};

struct cdnr_delete_filter {
	struct cdnr_interface	iface;
	u_long			filter_handle;
};

struct tce_stats {
	u_long			tce_handle;	/* tc element handle */
	int			tce_type;	/* e.g., TCETYPE_ELEMENT */
	struct pktcntr		tce_cnts[3];	/* tcm returns 3 counters */
};

struct cdnr_get_stats {
	struct cdnr_interface	iface;
	struct pktcntr		cnts[TCACODE_MAX+1];

	/* element stats */
	int			nskip;		/* skip # of elements */
	int			nelements;	/* # of element stats (WR) */
	struct tce_stats	*tce_stats;	/* pointer to stats array */
};

#define	CDNR_IF_ATTACH		_IOW('Q', 1, struct cdnr_interface)
#define	CDNR_IF_DETACH		_IOW('Q', 2, struct cdnr_interface)
#define	CDNR_ENABLE		_IOW('Q', 3, struct cdnr_interface)
#define	CDNR_DISABLE		_IOW('Q', 4, struct cdnr_interface)
#define	CDNR_ADD_FILTER		_IOWR('Q', 10, struct cdnr_add_filter)
#define	CDNR_DEL_FILTER		_IOW('Q', 11, struct cdnr_delete_filter)
#define	CDNR_GETSTATS		_IOWR('Q', 12, struct cdnr_get_stats)
#define	CDNR_ADD_ELEM		_IOWR('Q', 30, struct cdnr_add_element)
#define	CDNR_DEL_ELEM		_IOW('Q', 31, struct cdnr_delete_element)
#define	CDNR_ADD_TBM		_IOWR('Q', 32, struct cdnr_add_tbmeter)
#define	CDNR_MOD_TBM		_IOW('Q', 33, struct cdnr_modify_tbmeter)
#define	CDNR_TBM_STATS		_IOWR('Q', 34, struct cdnr_tbmeter_stats)
#define	CDNR_ADD_TCM		_IOWR('Q', 35, struct cdnr_add_trtcm)
#define	CDNR_MOD_TCM		_IOWR('Q', 36, struct cdnr_modify_trtcm)
#define	CDNR_TCM_STATS		_IOWR('Q', 37, struct cdnr_tcm_stats)
#define	CDNR_ADD_TSW		_IOWR('Q', 38, struct cdnr_add_tswtcm)
#define	CDNR_MOD_TSW		_IOWR('Q', 39, struct cdnr_modify_tswtcm)

#ifndef DSCP_EF
/* diffserve code points */
#define	DSCP_MASK	0xfc
#define	DSCP_CUMASK	0x03
#define	DSCP_EF		0xb8
#define	DSCP_AF11	0x28
#define	DSCP_AF12	0x30
#define	DSCP_AF13	0x38
#define	DSCP_AF21	0x48
#define	DSCP_AF22	0x50
#define	DSCP_AF23	0x58
#define	DSCP_AF31	0x68
#define	DSCP_AF32	0x70
#define	DSCP_AF33	0x78
#define	DSCP_AF41	0x88
#define	DSCP_AF42	0x90
#define	DSCP_AF43	0x98
#define	AF_CLASSMASK		0xe0
#define	AF_DROPPRECMASK		0x18
#endif

#ifdef _KERNEL

/*
 * packet information passed to the input function of tc elements
 */
struct cdnr_pktinfo {
	int		pkt_len;	/* packet length */
	u_int8_t	pkt_dscp;	/* diffserv code point */
};

/*
 * traffic conditioner control block common to all types of tc elements
 */
struct cdnr_block {
	LIST_ENTRY(cdnr_block)	cb_next;
	int		cb_len;		/* size of this tc element */
	int		cb_type;	/* cdnr block type */
	int		cb_ref;		/* reference count of this element */
	u_long		cb_handle;	/* handle of this tc element */
	struct top_cdnr *cb_top;	/* back pointer to top */
	struct tc_action cb_action;	/* top level action for this tcb */
	struct tc_action *(*cb_input)(struct cdnr_block *,
				      struct cdnr_pktinfo *);
};

/*
 * top level traffic conditioner structure for an interface
 */
struct top_cdnr {
	struct cdnr_block	tc_block;

	LIST_ENTRY(top_cdnr)	tc_next;
	struct ifaltq		*tc_ifq;

	LIST_HEAD(, cdnr_block) tc_elements;
#ifdef ALTQ3_CLFIER_COMPAT
	struct acc_classifier	tc_classifier;
#endif
	struct pktcntr		tc_cnts[TCACODE_MAX+1];
};

/* token bucket element */
struct tbe {
	u_int64_t	rate;
	u_int64_t	depth;

	u_int64_t	token;
	u_int64_t	filluptime;
	u_int64_t	last;
};

/* token bucket meter structure */
struct tbmeter {
	struct cdnr_block	cdnrblk;	/* conditioner block */
	struct tbe		tb;		/* token bucket */
	struct tc_action	in_action;	/* actions for IN/OUT */
	struct tc_action	out_action;	/* actions for IN/OUT */
	struct pktcntr		in_cnt;		/* statistics for IN/OUT */
	struct pktcntr		out_cnt;	/* statistics for IN/OUT */
};

/* two-rate three-color marker structure */
struct trtcm {
	struct cdnr_block	cdnrblk;	/* conditioner block */
	struct tbe		cmtd_tb;	/* committed tb profile */
	struct tbe		peak_tb;	/* peak tb profile */
	struct tc_action	green_action;
	struct tc_action	yellow_action;
	struct tc_action	red_action;
	int			coloraware;
	u_int8_t		green_dscp;
	u_int8_t		yellow_dscp;
	u_int8_t		red_dscp;
	struct pktcntr		green_cnt;
	struct pktcntr		yellow_cnt;
	struct pktcntr		red_cnt;
};

/* time sliding window three-color marker structure */
struct tswtcm {
	struct cdnr_block	cdnrblk;	/* conditioner block */

	u_int32_t		avg_rate;	/* average rate (bytes/sec) */
	u_int64_t		t_front;	/* timestamp of last update */

	u_int64_t		timewin;	/* average interval */
	u_int32_t		cmtd_rate;	/* committed target rate */
	u_int32_t		peak_rate;	/* peak target rate */
	struct tc_action	green_action;
	struct tc_action	yellow_action;
	struct tc_action	red_action;
	u_int8_t		green_dscp;
	u_int8_t		yellow_dscp;
	u_int8_t		red_dscp;
	struct pktcntr		green_cnt;
	struct pktcntr		yellow_cnt;
	struct pktcntr		red_cnt;
};

#endif /* _KERNEL */

#endif /* _ALTQ_ALTQ_CDNR_H_ */