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