altq_rio.h revision 1.5 1 1.5 peter /* $NetBSD: altq_rio.h,v 1.5 2006/10/12 19:59:08 peter Exp $ */
2 1.5 peter /* $KAME: altq_rio.h,v 1.9 2003/07/10 12:07:49 kjc Exp $ */
3 1.1 thorpej
4 1.1 thorpej /*
5 1.5 peter * Copyright (C) 1998-2003
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_RIO_H_
31 1.1 thorpej #define _ALTQ_ALTQ_RIO_H_
32 1.1 thorpej
33 1.1 thorpej #include <altq/altq_classq.h>
34 1.1 thorpej
35 1.1 thorpej /*
36 1.1 thorpej * RIO: RED with IN/OUT bit
37 1.1 thorpej * (extended to support more than 2 drop precedence values)
38 1.1 thorpej */
39 1.1 thorpej #define RIO_NDROPPREC 3 /* number of drop precedence values */
40 1.1 thorpej
41 1.5 peter #ifdef ALTQ3_COMPAT
42 1.1 thorpej struct rio_interface {
43 1.1 thorpej char rio_ifname[IFNAMSIZ];
44 1.1 thorpej };
45 1.1 thorpej
46 1.1 thorpej struct rio_stats {
47 1.1 thorpej struct rio_interface iface;
48 1.1 thorpej int q_len[RIO_NDROPPREC];
49 1.1 thorpej struct redstats q_stats[RIO_NDROPPREC];
50 1.1 thorpej
51 1.1 thorpej /* static red parameters */
52 1.1 thorpej int q_limit;
53 1.1 thorpej int weight;
54 1.1 thorpej int flags;
55 1.1 thorpej struct redparams q_params[RIO_NDROPPREC];
56 1.1 thorpej };
57 1.1 thorpej
58 1.1 thorpej struct rio_conf {
59 1.1 thorpej struct rio_interface iface;
60 1.1 thorpej struct redparams q_params[RIO_NDROPPREC];
61 1.1 thorpej int rio_weight; /* weight for EWMA */
62 1.1 thorpej int rio_limit; /* max queue length */
63 1.1 thorpej int rio_pkttime; /* average packet time in usec */
64 1.1 thorpej int rio_flags; /* see below */
65 1.1 thorpej };
66 1.5 peter #endif /* ALTQ3_COMPAT */
67 1.1 thorpej
68 1.1 thorpej /* rio flags */
69 1.1 thorpej #define RIOF_ECN4 0x01 /* use packet marking for IPv4 packets */
70 1.1 thorpej #define RIOF_ECN6 0x02 /* use packet marking for IPv6 packets */
71 1.1 thorpej #define RIOF_ECN (RIOF_ECN4 | RIOF_ECN6)
72 1.1 thorpej #define RIOF_CLEARDSCP 0x200 /* clear diffserv codepoint */
73 1.1 thorpej
74 1.5 peter #ifdef ALTQ3_COMPAT
75 1.3 perry /*
76 1.1 thorpej * IOCTLs for RIO
77 1.1 thorpej */
78 1.1 thorpej #define RIO_IF_ATTACH _IOW('Q', 1, struct rio_interface)
79 1.1 thorpej #define RIO_IF_DETACH _IOW('Q', 2, struct rio_interface)
80 1.1 thorpej #define RIO_ENABLE _IOW('Q', 3, struct rio_interface)
81 1.1 thorpej #define RIO_DISABLE _IOW('Q', 4, struct rio_interface)
82 1.1 thorpej #define RIO_CONFIG _IOWR('Q', 6, struct rio_conf)
83 1.1 thorpej #define RIO_GETSTATS _IOWR('Q', 12, struct rio_stats)
84 1.1 thorpej #define RIO_SETDEFAULTS _IOW('Q', 30, struct redparams[RIO_NDROPPREC])
85 1.5 peter #endif /* ALTQ3_COMPAT */
86 1.1 thorpej
87 1.1 thorpej #ifdef _KERNEL
88 1.1 thorpej
89 1.1 thorpej typedef struct rio {
90 1.1 thorpej /* per drop precedence structure */
91 1.1 thorpej struct dropprec_state {
92 1.1 thorpej /* red parameters */
93 1.5 peter int inv_pmax; /* inverse of max drop probability */
94 1.5 peter int th_min; /* red min threshold */
95 1.5 peter int th_max; /* red max threshold */
96 1.1 thorpej
97 1.1 thorpej /* variables for internal use */
98 1.5 peter int th_min_s; /* th_min scaled by avgshift */
99 1.5 peter int th_max_s; /* th_max scaled by avgshift */
100 1.5 peter int probd; /* drop probability denominator */
101 1.5 peter
102 1.5 peter int qlen; /* queue length */
103 1.5 peter int avg; /* (scaled) queue length average */
104 1.5 peter int count; /* packet count since the last dropped/
105 1.5 peter marked packet */
106 1.5 peter int idle; /* queue was empty */
107 1.5 peter int old; /* avg is above th_min */
108 1.5 peter struct timeval last; /* timestamp when queue becomes idle */
109 1.1 thorpej } rio_precstate[RIO_NDROPPREC];
110 1.3 perry
111 1.5 peter int rio_wshift; /* log(red_weight) */
112 1.5 peter int rio_weight; /* weight for EWMA */
113 1.5 peter struct wtab *rio_wtab; /* weight table */
114 1.5 peter
115 1.5 peter int rio_pkttime; /* average packet time in micro sec
116 1.5 peter used for idle calibration */
117 1.5 peter int rio_flags; /* rio flags */
118 1.1 thorpej
119 1.5 peter u_int8_t rio_codepoint; /* codepoint value to tag packets */
120 1.5 peter u_int8_t rio_codepointmask; /* codepoint mask bits */
121 1.3 perry
122 1.1 thorpej struct redstats q_stats[RIO_NDROPPREC]; /* statistics */
123 1.1 thorpej } rio_t;
124 1.1 thorpej
125 1.5 peter #ifdef ALTQ3_COMPAT
126 1.1 thorpej typedef struct rio_queue {
127 1.5 peter struct rio_queue *rq_next; /* next red_state in the list */
128 1.5 peter struct ifaltq *rq_ifq; /* backpointer to ifaltq */
129 1.1 thorpej
130 1.5 peter class_queue_t *rq_q;
131 1.1 thorpej
132 1.5 peter rio_t *rq_rio;
133 1.1 thorpej } rio_queue_t;
134 1.5 peter #endif /* ALTQ3_COMPAT */
135 1.1 thorpej
136 1.5 peter extern rio_t *rio_alloc(int, struct redparams *, int, int);
137 1.5 peter extern void rio_destroy(rio_t *);
138 1.5 peter extern void rio_getstats(rio_t *, struct redstats *);
139 1.5 peter extern int rio_addq(rio_t *, class_queue_t *, struct mbuf *,
140 1.5 peter struct altq_pktattr *);
141 1.5 peter extern struct mbuf *rio_getq(rio_t *, class_queue_t *);
142 1.1 thorpej
143 1.1 thorpej #endif /* _KERNEL */
144 1.1 thorpej
145 1.1 thorpej #endif /* _ALTQ_ALTQ_RIO_H_ */
146