133965Sjdp/*- 260484Sobrien * Copyright (C) 1997-2003 333965Sjdp * Sony Computer Science Laboratories Inc. All rights reserved. 433965Sjdp * 533965Sjdp * Redistribution and use in source and binary forms, with or without 633965Sjdp * modification, are permitted provided that the following conditions 733965Sjdp * are met: 860484Sobrien * 1. Redistributions of source code must retain the above copyright 933965Sjdp * notice, this list of conditions and the following disclaimer. 1033965Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1133965Sjdp * notice, this list of conditions and the following disclaimer in the 1233965Sjdp * documentation and/or other materials provided with the distribution. 1333965Sjdp * 1433965Sjdp * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND 1533965Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1633965Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1733965Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE 1833965Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1933965Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2033965Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2133965Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2233965Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2333965Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2433965Sjdp * SUCH DAMAGE. 2533965Sjdp * 2633965Sjdp * $KAME: altq_red.h,v 1.8 2003/07/10 12:07:49 kjc Exp $ 2733965Sjdp */ 2833965Sjdp 2933965Sjdp#ifndef _ALTQ_ALTQ_RED_H_ 3033965Sjdp#define _ALTQ_ALTQ_RED_H_ 3133965Sjdp 3233965Sjdp#include <net/altq/altq_classq.h> 3333965Sjdp 3433965Sjdp/* red flags */ 3533965Sjdp#define REDF_ECN4 0x01 /* use packet marking for IPv4 packets */ 3633965Sjdp#define REDF_ECN6 0x02 /* use packet marking for IPv6 packets */ 3733965Sjdp#define REDF_ECN (REDF_ECN4 | REDF_ECN6) 3833965Sjdp#define REDF_FLOWVALVE 0x04 /* use flowvalve (aka penalty-box) */ 3933965Sjdp 4033965Sjdp/* 4133965Sjdp * simpler versions of red parameters and statistics used by other 4233965Sjdp * disciplines (e.g., CBQ) 4333965Sjdp */ 4433965Sjdpstruct redparams { 4533965Sjdp int th_min; /* red min threshold */ 4633965Sjdp int th_max; /* red max threshold */ 4733965Sjdp int inv_pmax; /* inverse of max drop probability */ 4833965Sjdp}; 4933965Sjdp 5033965Sjdpstruct redstats { 5133965Sjdp int q_avg; 5233965Sjdp struct pktcntr xmit_cnt; 5333965Sjdp struct pktcntr drop_cnt; 5433965Sjdp u_int drop_forced; 5533965Sjdp u_int drop_unforced; 5633965Sjdp u_int marked_packets; 5733965Sjdp}; 5833965Sjdp 5933965Sjdp#ifdef _KERNEL 6033965Sjdp 6133965Sjdp/* weight table structure for idle time calibration */ 6233965Sjdpstruct wtab { 6333965Sjdp struct wtab *w_next; 6433965Sjdp int w_weight; 6533965Sjdp int w_param_max; 6633965Sjdp int w_refcount; 6733965Sjdp int32_t w_tab[32]; 6833965Sjdp}; 6933965Sjdp 7033965Sjdptypedef struct red { 7133965Sjdp int red_pkttime; /* average packet time in micro sec 7233965Sjdp used for idle calibration */ 7333965Sjdp int red_flags; /* red flags */ 7433965Sjdp 7533965Sjdp /* red parameters */ 7633965Sjdp int red_weight; /* weight for EWMA */ 7733965Sjdp int red_inv_pmax; /* inverse of max drop probability */ 7833965Sjdp int red_thmin; /* red min threshold */ 7933965Sjdp int red_thmax; /* red max threshold */ 8033965Sjdp 8133965Sjdp /* variables for internal use */ 8233965Sjdp int red_wshift; /* log(red_weight) */ 8333965Sjdp int red_thmin_s; /* th_min scaled by avgshift */ 8433965Sjdp int red_thmax_s; /* th_max scaled by avgshift */ 8533965Sjdp int red_probd; /* drop probability denominator */ 8633965Sjdp 8733965Sjdp int red_avg; /* queue len avg scaled by avgshift */ 8833965Sjdp int red_count; /* packet count since last dropped/ 8933965Sjdp marked packet */ 9033965Sjdp int red_idle; /* queue was empty */ 9133965Sjdp int red_old; /* avg is above th_min */ 9233965Sjdp struct wtab *red_wtab; /* weight table */ 9333965Sjdp struct timeval red_last; /* time when the queue becomes idle */ 9433965Sjdp 9533965Sjdp struct { 9633965Sjdp struct pktcntr xmit_cnt; 9733965Sjdp struct pktcntr drop_cnt; 9833965Sjdp u_int drop_forced; 9933965Sjdp u_int drop_unforced; 10033965Sjdp u_int marked_packets; 10133965Sjdp } red_stats; 10233965Sjdp} red_t; 10333965Sjdp 10433965Sjdp/* red drop types */ 10533965Sjdp#define DTYPE_NODROP 0 /* no drop */ 10633965Sjdp#define DTYPE_FORCED 1 /* a "forced" drop */ 10733965Sjdp#define DTYPE_EARLY 2 /* an "unforced" (early) drop */ 10833965Sjdp 10933965Sjdpextern red_t *red_alloc(int, int, int, int, int, int); 11033965Sjdpextern void red_destroy(red_t *); 11133965Sjdpextern void red_getstats(red_t *, struct redstats *); 11233965Sjdpextern int red_addq(red_t *, class_queue_t *, struct mbuf *, 11333965Sjdp struct altq_pktattr *); 11433965Sjdpextern struct mbuf *red_getq(red_t *, class_queue_t *); 11533965Sjdpextern int drop_early(int, int, int); 11633965Sjdpextern int mark_ecn(struct mbuf *, struct altq_pktattr *, int); 11733965Sjdpextern struct wtab *wtab_alloc(int); 11833965Sjdpextern int wtab_destroy(struct wtab *); 11933965Sjdpextern int32_t pow_w(struct wtab *, int); 12033965Sjdp 12133965Sjdp#endif /* _KERNEL */ 12233965Sjdp 12333965Sjdp#endif /* _ALTQ_ALTQ_RED_H_ */ 12433965Sjdp