/*-1* Copyright (C) 1997-20032* Sony Computer Science Laboratories Inc. All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25* $KAME: altq_red.h,v 1.8 2003/07/10 12:07:49 kjc Exp $26*/2728#ifndef _ALTQ_ALTQ_RED_H_29#define _ALTQ_ALTQ_RED_H_3031#include <net/altq/altq_classq.h>3233/* red flags */34#define REDF_ECN4 0x01 /* use packet marking for IPv4 packets */35#define REDF_ECN6 0x02 /* use packet marking for IPv6 packets */36#define REDF_ECN (REDF_ECN4 | REDF_ECN6)37#define REDF_FLOWVALVE 0x04 /* use flowvalve (aka penalty-box) */3839/*40* simpler versions of red parameters and statistics used by other41* disciplines (e.g., CBQ)42*/43struct redparams {44int th_min; /* red min threshold */45int th_max; /* red max threshold */46int inv_pmax; /* inverse of max drop probability */47};4849struct redstats {50int q_avg;51struct pktcntr xmit_cnt;52struct pktcntr drop_cnt;53u_int drop_forced;54u_int drop_unforced;55u_int marked_packets;56};5758#ifdef _KERNEL5960/* weight table structure for idle time calibration */61struct wtab {62struct wtab *w_next;63int w_weight;64int w_param_max;65int w_refcount;66int32_t w_tab[32];67};6869typedef struct red {70int red_pkttime; /* average packet time in micro sec71used for idle calibration */72int red_flags; /* red flags */7374/* red parameters */75int red_weight; /* weight for EWMA */76int red_inv_pmax; /* inverse of max drop probability */77int red_thmin; /* red min threshold */78int red_thmax; /* red max threshold */7980/* variables for internal use */81int red_wshift; /* log(red_weight) */82int red_thmin_s; /* th_min scaled by avgshift */83int red_thmax_s; /* th_max scaled by avgshift */84int red_probd; /* drop probability denominator */8586int red_avg; /* queue len avg scaled by avgshift */87int red_count; /* packet count since last dropped/88marked packet */89int red_idle; /* queue was empty */90int red_old; /* avg is above th_min */91struct wtab *red_wtab; /* weight table */92struct timeval red_last; /* time when the queue becomes idle */9394struct {95struct pktcntr xmit_cnt;96struct pktcntr drop_cnt;97u_int drop_forced;98u_int drop_unforced;99u_int marked_packets;100} red_stats;101} red_t;102103/* red drop types */104#define DTYPE_NODROP 0 /* no drop */105#define DTYPE_FORCED 1 /* a "forced" drop */106#define DTYPE_EARLY 2 /* an "unforced" (early) drop */107108extern red_t *red_alloc(int, int, int, int, int, int);109extern void red_destroy(red_t *);110extern void red_getstats(red_t *, struct redstats *);111extern int red_addq(red_t *, class_queue_t *, struct mbuf *,112struct altq_pktattr *);113extern struct mbuf *red_getq(red_t *, class_queue_t *);114extern int drop_early(int, int, int);115extern int mark_ecn(struct mbuf *, struct altq_pktattr *, int);116extern struct wtab *wtab_alloc(int);117extern int wtab_destroy(struct wtab *);118extern int32_t pow_w(struct wtab *, int);119120#endif /* _KERNEL */121122#endif /* _ALTQ_ALTQ_RED_H_ */123124125