1281613Sglebius/*- 2130365Smlaier * Copyright (C) 1998-2003 3130365Smlaier * Sony Computer Science Laboratories Inc. All rights reserved. 4130365Smlaier * 5130365Smlaier * Redistribution and use in source and binary forms, with or without 6130365Smlaier * modification, are permitted provided that the following conditions 7130365Smlaier * are met: 8130365Smlaier * 1. Redistributions of source code must retain the above copyright 9130365Smlaier * notice, this list of conditions and the following disclaimer. 10130365Smlaier * 2. Redistributions in binary form must reproduce the above copyright 11130365Smlaier * notice, this list of conditions and the following disclaimer in the 12130365Smlaier * documentation and/or other materials provided with the distribution. 13130365Smlaier * 14130365Smlaier * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 15130365Smlaier * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16130365Smlaier * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17130365Smlaier * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 18130365Smlaier * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19130365Smlaier * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20130365Smlaier * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21130365Smlaier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22130365Smlaier * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23130365Smlaier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24130365Smlaier * SUCH DAMAGE. 25281613Sglebius * 26281613Sglebius * $KAME: altq_rio.h,v 1.9 2003/07/10 12:07:49 kjc Exp $ 27281613Sglebius * $FreeBSD: releng/11.0/sys/net/altq/altq_rio.h 281613 2015-04-16 20:22:40Z glebius $ 28130365Smlaier */ 29130365Smlaier 30130365Smlaier#ifndef _ALTQ_ALTQ_RIO_H_ 31130365Smlaier#define _ALTQ_ALTQ_RIO_H_ 32130365Smlaier 33281613Sglebius#include <net/altq/altq_classq.h> 34130365Smlaier 35130365Smlaier/* 36130365Smlaier * RIO: RED with IN/OUT bit 37130365Smlaier * (extended to support more than 2 drop precedence values) 38130365Smlaier */ 39130365Smlaier#define RIO_NDROPPREC 3 /* number of drop precedence values */ 40130365Smlaier 41130365Smlaier#ifdef ALTQ3_COMPAT 42130365Smlaierstruct rio_interface { 43130365Smlaier char rio_ifname[IFNAMSIZ]; 44130365Smlaier}; 45130365Smlaier 46130365Smlaierstruct rio_stats { 47130365Smlaier struct rio_interface iface; 48130365Smlaier int q_len[RIO_NDROPPREC]; 49130365Smlaier struct redstats q_stats[RIO_NDROPPREC]; 50130365Smlaier 51130365Smlaier /* static red parameters */ 52130365Smlaier int q_limit; 53130365Smlaier int weight; 54130365Smlaier int flags; 55130365Smlaier struct redparams q_params[RIO_NDROPPREC]; 56130365Smlaier}; 57130365Smlaier 58130365Smlaierstruct rio_conf { 59130365Smlaier struct rio_interface iface; 60130365Smlaier struct redparams q_params[RIO_NDROPPREC]; 61130365Smlaier int rio_weight; /* weight for EWMA */ 62130365Smlaier int rio_limit; /* max queue length */ 63130365Smlaier int rio_pkttime; /* average packet time in usec */ 64130365Smlaier int rio_flags; /* see below */ 65130365Smlaier}; 66130365Smlaier#endif /* ALTQ3_COMPAT */ 67130365Smlaier 68130365Smlaier/* rio flags */ 69130365Smlaier#define RIOF_ECN4 0x01 /* use packet marking for IPv4 packets */ 70130365Smlaier#define RIOF_ECN6 0x02 /* use packet marking for IPv6 packets */ 71130365Smlaier#define RIOF_ECN (RIOF_ECN4 | RIOF_ECN6) 72130365Smlaier#define RIOF_CLEARDSCP 0x200 /* clear diffserv codepoint */ 73130365Smlaier 74130365Smlaier#ifdef ALTQ3_COMPAT 75130365Smlaier/* 76130365Smlaier * IOCTLs for RIO 77130365Smlaier */ 78130365Smlaier#define RIO_IF_ATTACH _IOW('Q', 1, struct rio_interface) 79130365Smlaier#define RIO_IF_DETACH _IOW('Q', 2, struct rio_interface) 80130365Smlaier#define RIO_ENABLE _IOW('Q', 3, struct rio_interface) 81130365Smlaier#define RIO_DISABLE _IOW('Q', 4, struct rio_interface) 82130365Smlaier#define RIO_CONFIG _IOWR('Q', 6, struct rio_conf) 83130365Smlaier#define RIO_GETSTATS _IOWR('Q', 12, struct rio_stats) 84130365Smlaier#define RIO_SETDEFAULTS _IOW('Q', 30, struct redparams[RIO_NDROPPREC]) 85130365Smlaier#endif /* ALTQ3_COMPAT */ 86130365Smlaier 87130365Smlaier#ifdef _KERNEL 88130365Smlaier 89130365Smlaiertypedef struct rio { 90130365Smlaier /* per drop precedence structure */ 91130365Smlaier struct dropprec_state { 92130365Smlaier /* red parameters */ 93130365Smlaier int inv_pmax; /* inverse of max drop probability */ 94130365Smlaier int th_min; /* red min threshold */ 95130365Smlaier int th_max; /* red max threshold */ 96130365Smlaier 97130365Smlaier /* variables for internal use */ 98130365Smlaier int th_min_s; /* th_min scaled by avgshift */ 99130365Smlaier int th_max_s; /* th_max scaled by avgshift */ 100130365Smlaier int probd; /* drop probability denominator */ 101130365Smlaier 102130365Smlaier int qlen; /* queue length */ 103130365Smlaier int avg; /* (scaled) queue length average */ 104130365Smlaier int count; /* packet count since the last dropped/ 105130365Smlaier marked packet */ 106130365Smlaier int idle; /* queue was empty */ 107130365Smlaier int old; /* avg is above th_min */ 108130365Smlaier struct timeval last; /* timestamp when queue becomes idle */ 109130365Smlaier } rio_precstate[RIO_NDROPPREC]; 110130365Smlaier 111130365Smlaier int rio_wshift; /* log(red_weight) */ 112130365Smlaier int rio_weight; /* weight for EWMA */ 113130365Smlaier struct wtab *rio_wtab; /* weight table */ 114130365Smlaier 115130365Smlaier int rio_pkttime; /* average packet time in micro sec 116130365Smlaier used for idle calibration */ 117130365Smlaier int rio_flags; /* rio flags */ 118130365Smlaier 119130365Smlaier u_int8_t rio_codepoint; /* codepoint value to tag packets */ 120130365Smlaier u_int8_t rio_codepointmask; /* codepoint mask bits */ 121130365Smlaier 122130365Smlaier struct redstats q_stats[RIO_NDROPPREC]; /* statistics */ 123130365Smlaier} rio_t; 124130365Smlaier 125130365Smlaier#ifdef ALTQ3_COMPAT 126130365Smlaiertypedef struct rio_queue { 127130365Smlaier struct rio_queue *rq_next; /* next red_state in the list */ 128130365Smlaier struct ifaltq *rq_ifq; /* backpointer to ifaltq */ 129130365Smlaier 130130365Smlaier class_queue_t *rq_q; 131130365Smlaier 132130365Smlaier rio_t *rq_rio; 133130365Smlaier} rio_queue_t; 134130365Smlaier#endif /* ALTQ3_COMPAT */ 135130365Smlaier 136130365Smlaierextern rio_t *rio_alloc(int, struct redparams *, int, int); 137130365Smlaierextern void rio_destroy(rio_t *); 138130365Smlaierextern void rio_getstats(rio_t *, struct redstats *); 139130365Smlaierextern int rio_addq(rio_t *, class_queue_t *, struct mbuf *, 140130365Smlaier struct altq_pktattr *); 141130365Smlaierextern struct mbuf *rio_getq(rio_t *, class_queue_t *); 142130365Smlaier 143130365Smlaier#endif /* _KERNEL */ 144130365Smlaier 145130365Smlaier#endif /* _ALTQ_ALTQ_RIO_H_ */ 146