xref: /dflybsd-src/sys/net/altq/altq_rio.h (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*	$KAME: altq_rio.h,v 1.9 2003/07/10 12:07:49 kjc Exp $	*/
286d7f5d3SJohn Marino /*	$DragonFly: src/sys/net/altq/altq_rio.h,v 1.1 2005/02/11 22:25:57 joerg Exp $ */
386d7f5d3SJohn Marino 
486d7f5d3SJohn Marino /*
586d7f5d3SJohn Marino  * Copyright (C) 1998-2003
686d7f5d3SJohn Marino  *	Sony Computer Science Laboratories Inc.  All rights reserved.
786d7f5d3SJohn Marino  *
886d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
986d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
1086d7f5d3SJohn Marino  * are met:
1186d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
1286d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
1386d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1486d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1586d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
1686d7f5d3SJohn Marino  *
1786d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
1886d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1986d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2086d7f5d3SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
2186d7f5d3SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2286d7f5d3SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2386d7f5d3SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2486d7f5d3SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2586d7f5d3SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2686d7f5d3SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2786d7f5d3SJohn Marino  * SUCH DAMAGE.
2886d7f5d3SJohn Marino  */
2986d7f5d3SJohn Marino 
3086d7f5d3SJohn Marino #ifndef _ALTQ_ALTQ_RIO_H_
3186d7f5d3SJohn Marino #define	_ALTQ_ALTQ_RIO_H_
3286d7f5d3SJohn Marino 
3386d7f5d3SJohn Marino #include <net/altq/altq_classq.h>
3486d7f5d3SJohn Marino 
3586d7f5d3SJohn Marino /*
3686d7f5d3SJohn Marino  * RIO: RED with IN/OUT bit
3786d7f5d3SJohn Marino  * (extended to support more than 2 drop precedence values)
3886d7f5d3SJohn Marino  */
3986d7f5d3SJohn Marino #define	RIO_NDROPPREC	3	/* number of drop precedence values */
4086d7f5d3SJohn Marino 
4186d7f5d3SJohn Marino /* rio flags */
4286d7f5d3SJohn Marino #define	RIOF_ECN4	0x01	/* use packet marking for IPv4 packets */
4386d7f5d3SJohn Marino #define	RIOF_ECN6	0x02	/* use packet marking for IPv6 packets */
4486d7f5d3SJohn Marino #define	RIOF_ECN	(RIOF_ECN4 | RIOF_ECN6)
4586d7f5d3SJohn Marino #define	RIOF_CLEARDSCP	0x200	/* clear diffserv codepoint */
4686d7f5d3SJohn Marino 
4786d7f5d3SJohn Marino #ifdef _KERNEL
4886d7f5d3SJohn Marino 
4986d7f5d3SJohn Marino typedef struct rio {
5086d7f5d3SJohn Marino 	/* per drop precedence structure */
5186d7f5d3SJohn Marino 	struct dropprec_state {
5286d7f5d3SJohn Marino 		/* red parameters */
5386d7f5d3SJohn Marino 		int	inv_pmax;	/* inverse of max drop probability */
5486d7f5d3SJohn Marino 		int	th_min;		/* red min threshold */
5586d7f5d3SJohn Marino 		int	th_max;		/* red max threshold */
5686d7f5d3SJohn Marino 
5786d7f5d3SJohn Marino 		/* variables for internal use */
5886d7f5d3SJohn Marino 		int	th_min_s;	/* th_min scaled by avgshift */
5986d7f5d3SJohn Marino 		int	th_max_s;	/* th_max scaled by avgshift */
6086d7f5d3SJohn Marino 		int	probd;		/* drop probability denominator */
6186d7f5d3SJohn Marino 
6286d7f5d3SJohn Marino 		int	qlen;		/* queue length */
6386d7f5d3SJohn Marino 		int	avg;		/* (scaled) queue length average */
6486d7f5d3SJohn Marino 		int	count;		/* packet count since the last dropped/
6586d7f5d3SJohn Marino 					   marked packet */
6686d7f5d3SJohn Marino 		int	idle;		/* queue was empty */
6786d7f5d3SJohn Marino 		int	old;		/* avg is above th_min */
6886d7f5d3SJohn Marino 		struct timeval	last;	/* timestamp when queue becomes idle */
6986d7f5d3SJohn Marino 	} rio_precstate[RIO_NDROPPREC];
7086d7f5d3SJohn Marino 
7186d7f5d3SJohn Marino 	int		 rio_wshift;	/* log(red_weight) */
7286d7f5d3SJohn Marino 	int		 rio_weight;	/* weight for EWMA */
7386d7f5d3SJohn Marino 	struct wtab	*rio_wtab;	/* weight table */
7486d7f5d3SJohn Marino 
7586d7f5d3SJohn Marino 	int		 rio_pkttime;	/* average packet time in micro sec
7686d7f5d3SJohn Marino 					   used for idle calibration */
7786d7f5d3SJohn Marino 	int		 rio_flags;	/* rio flags */
7886d7f5d3SJohn Marino 
7986d7f5d3SJohn Marino 	uint8_t		 rio_codepoint;	/* codepoint value to tag packets */
8086d7f5d3SJohn Marino 	uint8_t		 rio_codepointmask;	/* codepoint mask bits */
8186d7f5d3SJohn Marino 
8286d7f5d3SJohn Marino 	struct redstats q_stats[RIO_NDROPPREC];	/* statistics */
8386d7f5d3SJohn Marino } rio_t;
8486d7f5d3SJohn Marino 
8586d7f5d3SJohn Marino rio_t		*rio_alloc(int, struct redparams *, int, int);
8686d7f5d3SJohn Marino void		 rio_destroy(rio_t *);
8786d7f5d3SJohn Marino void		 rio_getstats(rio_t *, struct redstats *);
8886d7f5d3SJohn Marino int		 rio_addq(rio_t *, class_queue_t *, struct mbuf *,
8986d7f5d3SJohn Marino 			  struct altq_pktattr *);
9086d7f5d3SJohn Marino struct mbuf	*rio_getq(rio_t *, class_queue_t *);
9186d7f5d3SJohn Marino 
9286d7f5d3SJohn Marino #endif /* _KERNEL */
9386d7f5d3SJohn Marino 
9486d7f5d3SJohn Marino #endif /* _ALTQ_ALTQ_RIO_H_ */
95