1126385Smlaier/*	$FreeBSD$	*/
2126385Smlaier/*	$KAME: altq_rio.h,v 1.9 2003/07/10 12:07:49 kjc Exp $	*/
3126385Smlaier
4126385Smlaier/*
5126385Smlaier * Copyright (C) 1998-2003
6126385Smlaier *	Sony Computer Science Laboratories Inc.  All rights reserved.
7126385Smlaier *
8126385Smlaier * Redistribution and use in source and binary forms, with or without
9126385Smlaier * modification, are permitted provided that the following conditions
10126385Smlaier * are met:
11126385Smlaier * 1. Redistributions of source code must retain the above copyright
12126385Smlaier *    notice, this list of conditions and the following disclaimer.
13126385Smlaier * 2. Redistributions in binary form must reproduce the above copyright
14126385Smlaier *    notice, this list of conditions and the following disclaimer in the
15126385Smlaier *    documentation and/or other materials provided with the distribution.
16126385Smlaier *
17126385Smlaier * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
18126385Smlaier * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19126385Smlaier * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20126385Smlaier * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
21126385Smlaier * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22126385Smlaier * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23126385Smlaier * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24126385Smlaier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25126385Smlaier * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26126385Smlaier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27126385Smlaier * SUCH DAMAGE.
28126385Smlaier */
29126385Smlaier
30126385Smlaier#ifndef _ALTQ_ALTQ_RIO_H_
31126385Smlaier#define	_ALTQ_ALTQ_RIO_H_
32126385Smlaier
33126385Smlaier#include <altq/altq_classq.h>
34126385Smlaier
35126385Smlaier/*
36126385Smlaier * RIO: RED with IN/OUT bit
37126385Smlaier * (extended to support more than 2 drop precedence values)
38126385Smlaier */
39126385Smlaier#define	RIO_NDROPPREC	3	/* number of drop precedence values */
40126385Smlaier
41126385Smlaier#ifdef ALTQ3_COMPAT
42126385Smlaierstruct rio_interface {
43126385Smlaier	char	rio_ifname[IFNAMSIZ];
44126385Smlaier};
45126385Smlaier
46126385Smlaierstruct rio_stats {
47126385Smlaier	struct rio_interface iface;
48126385Smlaier	int q_len[RIO_NDROPPREC];
49126385Smlaier	struct redstats q_stats[RIO_NDROPPREC];
50126385Smlaier
51126385Smlaier	/* static red parameters */
52126385Smlaier	int q_limit;
53126385Smlaier	int weight;
54126385Smlaier	int flags;
55126385Smlaier	struct redparams q_params[RIO_NDROPPREC];
56126385Smlaier};
57126385Smlaier
58126385Smlaierstruct rio_conf {
59126385Smlaier	struct rio_interface iface;
60126385Smlaier	struct redparams q_params[RIO_NDROPPREC];
61126385Smlaier	int rio_weight;		/* weight for EWMA */
62126385Smlaier	int rio_limit;		/* max queue length */
63126385Smlaier	int rio_pkttime;	/* average packet time in usec */
64126385Smlaier	int rio_flags;		/* see below */
65126385Smlaier};
66126385Smlaier#endif /* ALTQ3_COMPAT */
67126385Smlaier
68126385Smlaier/* rio flags */
69126385Smlaier#define	RIOF_ECN4	0x01	/* use packet marking for IPv4 packets */
70126385Smlaier#define	RIOF_ECN6	0x02	/* use packet marking for IPv6 packets */
71126385Smlaier#define	RIOF_ECN	(RIOF_ECN4 | RIOF_ECN6)
72126385Smlaier#define	RIOF_CLEARDSCP	0x200	/* clear diffserv codepoint */
73126385Smlaier
74126385Smlaier#ifdef ALTQ3_COMPAT
75126385Smlaier/*
76126385Smlaier * IOCTLs for RIO
77126385Smlaier */
78126385Smlaier#define	RIO_IF_ATTACH		_IOW('Q', 1, struct rio_interface)
79126385Smlaier#define	RIO_IF_DETACH		_IOW('Q', 2, struct rio_interface)
80126385Smlaier#define	RIO_ENABLE		_IOW('Q', 3, struct rio_interface)
81126385Smlaier#define	RIO_DISABLE		_IOW('Q', 4, struct rio_interface)
82126385Smlaier#define	RIO_CONFIG		_IOWR('Q', 6, struct rio_conf)
83126385Smlaier#define	RIO_GETSTATS		_IOWR('Q', 12, struct rio_stats)
84126385Smlaier#define	RIO_SETDEFAULTS		_IOW('Q', 30, struct redparams[RIO_NDROPPREC])
85126385Smlaier#endif /* ALTQ3_COMPAT */
86126385Smlaier
87126385Smlaier#ifdef _KERNEL
88126385Smlaier
89126385Smlaiertypedef struct rio {
90126385Smlaier	/* per drop precedence structure */
91126385Smlaier	struct dropprec_state {
92126385Smlaier		/* red parameters */
93126385Smlaier		int	inv_pmax;	/* inverse of max drop probability */
94126385Smlaier		int	th_min;		/* red min threshold */
95126385Smlaier		int	th_max;		/* red max threshold */
96126385Smlaier
97126385Smlaier		/* variables for internal use */
98126385Smlaier		int	th_min_s;	/* th_min scaled by avgshift */
99126385Smlaier		int	th_max_s;	/* th_max scaled by avgshift */
100126385Smlaier		int	probd;		/* drop probability denominator */
101126385Smlaier
102126385Smlaier		int	qlen;		/* queue length */
103126385Smlaier		int	avg;		/* (scaled) queue length average */
104126385Smlaier		int	count;		/* packet count since the last dropped/
105126385Smlaier					   marked packet */
106126385Smlaier		int	idle;		/* queue was empty */
107126385Smlaier		int	old;		/* avg is above th_min */
108126385Smlaier		struct timeval	last;	/* timestamp when queue becomes idle */
109126385Smlaier	} rio_precstate[RIO_NDROPPREC];
110126385Smlaier
111126385Smlaier	int		 rio_wshift;	/* log(red_weight) */
112126385Smlaier	int		 rio_weight;	/* weight for EWMA */
113126385Smlaier	struct wtab	*rio_wtab;	/* weight table */
114126385Smlaier
115126385Smlaier	int		 rio_pkttime;	/* average packet time in micro sec
116126385Smlaier					   used for idle calibration */
117126385Smlaier	int		 rio_flags;	/* rio flags */
118126385Smlaier
119126385Smlaier	u_int8_t	 rio_codepoint;	/* codepoint value to tag packets */
120126385Smlaier	u_int8_t	 rio_codepointmask;	/* codepoint mask bits */
121126385Smlaier
122126385Smlaier	struct redstats q_stats[RIO_NDROPPREC];	/* statistics */
123126385Smlaier} rio_t;
124126385Smlaier
125126385Smlaier#ifdef ALTQ3_COMPAT
126126385Smlaiertypedef struct rio_queue {
127126385Smlaier	struct rio_queue	*rq_next;	/* next red_state in the list */
128126385Smlaier	struct ifaltq		*rq_ifq;	/* backpointer to ifaltq */
129126385Smlaier
130126385Smlaier	class_queue_t		*rq_q;
131126385Smlaier
132126385Smlaier	rio_t			*rq_rio;
133126385Smlaier} rio_queue_t;
134126385Smlaier#endif /* ALTQ3_COMPAT */
135126385Smlaier
136126385Smlaierextern rio_t		*rio_alloc(int, struct redparams *, int, int);
137126385Smlaierextern void		 rio_destroy(rio_t *);
138126385Smlaierextern void		 rio_getstats(rio_t *, struct redstats *);
139126385Smlaierextern int		 rio_addq(rio_t *, class_queue_t *, struct mbuf *,
140126385Smlaier			     struct altq_pktattr *);
141126385Smlaierextern struct mbuf	*rio_getq(rio_t *, class_queue_t *);
142126385Smlaier
143126385Smlaier#endif /* _KERNEL */
144126385Smlaier
145126385Smlaier#endif /* _ALTQ_ALTQ_RIO_H_ */
146