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