1130803Smarcel/*	$KAME: altq_rio.h,v 1.9 2003/07/10 12:07:49 kjc Exp $	*/
2130803Smarcel
3130803Smarcel/*
4130803Smarcel * Copyright (C) 1998-2003
5130803Smarcel *	Sony Computer Science Laboratories Inc.  All rights reserved.
6130803Smarcel *
7130803Smarcel * Redistribution and use in source and binary forms, with or without
8130803Smarcel * modification, are permitted provided that the following conditions
9130803Smarcel * are met:
10130803Smarcel * 1. Redistributions of source code must retain the above copyright
11130803Smarcel *    notice, this list of conditions and the following disclaimer.
12130803Smarcel * 2. Redistributions in binary form must reproduce the above copyright
13130803Smarcel *    notice, this list of conditions and the following disclaimer in the
14130803Smarcel *    documentation and/or other materials provided with the distribution.
15130803Smarcel *
16130803Smarcel * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
17130803Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18130803Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19130803Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
20130803Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21130803Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22130803Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23130803Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24130803Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25130803Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26130803Smarcel * SUCH DAMAGE.
27130803Smarcel */
28130803Smarcel
29130803Smarcel#ifndef _ALTQ_ALTQ_RIO_H_
30130803Smarcel#define	_ALTQ_ALTQ_RIO_H_
31
32#include <altq/altq_classq.h>
33
34/*
35 * RIO: RED with IN/OUT bit
36 * (extended to support more than 2 drop precedence values)
37 */
38#define	RIO_NDROPPREC	3	/* number of drop precedence values */
39
40#ifdef ALTQ3_COMPAT
41struct rio_interface {
42	char	rio_ifname[IFNAMSIZ];
43};
44
45struct rio_stats {
46	struct rio_interface iface;
47	int q_len[RIO_NDROPPREC];
48	struct redstats q_stats[RIO_NDROPPREC];
49
50	/* static red parameters */
51	int q_limit;
52	int weight;
53	int flags;
54	struct redparams q_params[RIO_NDROPPREC];
55};
56
57struct rio_conf {
58	struct rio_interface iface;
59	struct redparams q_params[RIO_NDROPPREC];
60	int rio_weight;		/* weight for EWMA */
61	int rio_limit;		/* max queue length */
62	int rio_pkttime;	/* average packet time in usec */
63	int rio_flags;		/* see below */
64};
65#endif /* ALTQ3_COMPAT */
66
67/* rio flags */
68#define	RIOF_ECN4	0x01	/* use packet marking for IPv4 packets */
69#define	RIOF_ECN6	0x02	/* use packet marking for IPv6 packets */
70#define	RIOF_ECN	(RIOF_ECN4 | RIOF_ECN6)
71#define	RIOF_CLEARDSCP	0x200	/* clear diffserv codepoint */
72
73#ifdef ALTQ3_COMPAT
74/*
75 * IOCTLs for RIO
76 */
77#define	RIO_IF_ATTACH		_IOW('Q', 1, struct rio_interface)
78#define	RIO_IF_DETACH		_IOW('Q', 2, struct rio_interface)
79#define	RIO_ENABLE		_IOW('Q', 3, struct rio_interface)
80#define	RIO_DISABLE		_IOW('Q', 4, struct rio_interface)
81#define	RIO_CONFIG		_IOWR('Q', 6, struct rio_conf)
82#define	RIO_GETSTATS		_IOWR('Q', 12, struct rio_stats)
83#define	RIO_SETDEFAULTS		_IOW('Q', 30, struct redparams[RIO_NDROPPREC])
84#endif /* ALTQ3_COMPAT */
85
86#ifdef _KERNEL
87
88typedef struct rio {
89	/* per drop precedence structure */
90	struct dropprec_state {
91		/* red parameters */
92		int	inv_pmax;	/* inverse of max drop probability */
93		int	th_min;		/* red min threshold */
94		int	th_max;		/* red max threshold */
95
96		/* variables for internal use */
97		int	th_min_s;	/* th_min scaled by avgshift */
98		int	th_max_s;	/* th_max scaled by avgshift */
99		int	probd;		/* drop probability denominator */
100
101		int	qlen;		/* queue length */
102		int	avg;		/* (scaled) queue length average */
103		int	count;		/* packet count since the last dropped/
104					   marked packet */
105		int	idle;		/* queue was empty */
106		int	old;		/* avg is above th_min */
107		struct timeval	last;	/* timestamp when queue becomes idle */
108	} rio_precstate[RIO_NDROPPREC];
109
110	int		 rio_wshift;	/* log(red_weight) */
111	int		 rio_weight;	/* weight for EWMA */
112	struct wtab	*rio_wtab;	/* weight table */
113
114	int		 rio_pkttime;	/* average packet time in micro sec
115					   used for idle calibration */
116	int		 rio_flags;	/* rio flags */
117
118	u_int8_t	 rio_codepoint;	/* codepoint value to tag packets */
119	u_int8_t	 rio_codepointmask;	/* codepoint mask bits */
120
121	struct redstats q_stats[RIO_NDROPPREC];	/* statistics */
122} rio_t;
123
124#ifdef ALTQ3_COMPAT
125typedef struct rio_queue {
126	struct rio_queue	*rq_next;	/* next red_state in the list */
127	struct ifaltq		*rq_ifq;	/* backpointer to ifaltq */
128
129	class_queue_t		*rq_q;
130
131	rio_t			*rq_rio;
132} rio_queue_t;
133#endif /* ALTQ3_COMPAT */
134
135extern rio_t		*rio_alloc(int, struct redparams *, int, int);
136extern void		 rio_destroy(rio_t *);
137extern void		 rio_getstats(rio_t *, struct redstats *);
138extern int		 rio_addq(rio_t *, class_queue_t *, struct mbuf *,
139			     struct altq_pktattr *);
140extern struct mbuf	*rio_getq(rio_t *, class_queue_t *);
141
142#endif /* _KERNEL */
143
144#endif /* _ALTQ_ALTQ_RIO_H_ */
145