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