1 /* $NetBSD: altq_rio.h,v 1.4.12.1 2006/03/18 12:08:18 peter Exp $ */
2 /* $KAME: altq_rio.h,v 1.9 2003/07/10 12:07:49 kjc Exp $ */
5 * Copyright (C) 1998-2003
6 * Sony Computer Science Laboratories Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #ifndef _ALTQ_ALTQ_RIO_H_
31 #define _ALTQ_ALTQ_RIO_H_
33 #include <altq/altq_classq.h>
36 * RIO: RED with IN/OUT bit
37 * (extended to support more than 2 drop precedence values)
39 #define RIO_NDROPPREC 3 /* number of drop precedence values */
42 struct rio_interface
{
43 char rio_ifname
[IFNAMSIZ
];
47 struct rio_interface iface
;
48 int q_len
[RIO_NDROPPREC
];
49 struct redstats q_stats
[RIO_NDROPPREC
];
51 /* static red parameters */
55 struct redparams q_params
[RIO_NDROPPREC
];
59 struct rio_interface iface
;
60 struct redparams q_params
[RIO_NDROPPREC
];
61 int rio_weight
; /* weight for EWMA */
62 int rio_limit
; /* max queue length */
63 int rio_pkttime
; /* average packet time in usec */
64 int rio_flags
; /* see below */
66 #endif /* ALTQ3_COMPAT */
69 #define RIOF_ECN4 0x01 /* use packet marking for IPv4 packets */
70 #define RIOF_ECN6 0x02 /* use packet marking for IPv6 packets */
71 #define RIOF_ECN (RIOF_ECN4 | RIOF_ECN6)
72 #define RIOF_CLEARDSCP 0x200 /* clear diffserv codepoint */
78 #define RIO_IF_ATTACH _IOW('Q', 1, struct rio_interface)
79 #define RIO_IF_DETACH _IOW('Q', 2, struct rio_interface)
80 #define RIO_ENABLE _IOW('Q', 3, struct rio_interface)
81 #define RIO_DISABLE _IOW('Q', 4, struct rio_interface)
82 #define RIO_CONFIG _IOWR('Q', 6, struct rio_conf)
83 #define RIO_GETSTATS _IOWR('Q', 12, struct rio_stats)
84 #define RIO_SETDEFAULTS _IOW('Q', 30, struct redparams[RIO_NDROPPREC])
85 #endif /* ALTQ3_COMPAT */
90 /* per drop precedence structure */
91 struct dropprec_state
{
93 int inv_pmax
; /* inverse of max drop probability */
94 int th_min
; /* red min threshold */
95 int th_max
; /* red max threshold */
97 /* variables for internal use */
98 int th_min_s
; /* th_min scaled by avgshift */
99 int th_max_s
; /* th_max scaled by avgshift */
100 int probd
; /* drop probability denominator */
102 int qlen
; /* queue length */
103 int avg
; /* (scaled) queue length average */
104 int count
; /* packet count since the last dropped/
106 int idle
; /* queue was empty */
107 int old
; /* avg is above th_min */
108 struct timeval last
; /* timestamp when queue becomes idle */
109 } rio_precstate
[RIO_NDROPPREC
];
111 int rio_wshift
; /* log(red_weight) */
112 int rio_weight
; /* weight for EWMA */
113 struct wtab
*rio_wtab
; /* weight table */
115 int rio_pkttime
; /* average packet time in micro sec
116 used for idle calibration */
117 int rio_flags
; /* rio flags */
119 u_int8_t rio_codepoint
; /* codepoint value to tag packets */
120 u_int8_t rio_codepointmask
; /* codepoint mask bits */
122 struct redstats q_stats
[RIO_NDROPPREC
]; /* statistics */
126 typedef struct rio_queue
{
127 struct rio_queue
*rq_next
; /* next red_state in the list */
128 struct ifaltq
*rq_ifq
; /* backpointer to ifaltq */
134 #endif /* ALTQ3_COMPAT */
136 extern rio_t
*rio_alloc(int, struct redparams
*, int, int);
137 extern void rio_destroy(rio_t
*);
138 extern void rio_getstats(rio_t
*, struct redstats
*);
139 extern int rio_addq(rio_t
*, class_queue_t
*, struct mbuf
*,
140 struct altq_pktattr
*);
141 extern struct mbuf
*rio_getq(rio_t
*, class_queue_t
*);
145 #endif /* _ALTQ_ALTQ_RIO_H_ */