Home | History | Annotate | Line # | Download | only in altq
altq_wfq.h revision 1.3
      1 /*	$NetBSD: altq_wfq.h,v 1.3 2005/02/26 23:04:16 perry Exp $	*/
      2 /*	$KAME: altq_wfq.h,v 1.5 2000/12/14 08:12:46 thorpej Exp $	*/
      3 
      4 /*
      5  * Copyright (C) 1997-2000
      6  *	Sony Computer Science Laboratories Inc.  All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     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.
     16  *
     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
     27  * SUCH DAMAGE.
     28  */
     29 /*
     30  *  March 27, 1997.  Written by Hiroshi Kyusojin of Keio University
     31  *  (kyu (at) mt.cs.keio.ac.jp).
     32  */
     33 
     34 #ifndef _ALTQ_ALTQ_WFQ_H_
     35 #define	_ALTQ_ALTQ_WFQ_H_
     36 
     37 #include <altq/altq.h>
     38 
     39 #define	DEFAULT_QSIZE	256
     40 #define	MAX_QSIZE	2048
     41 
     42 struct wfq_interface{
     43 	char wfq_ifacename[IFNAMSIZ];
     44 };
     45 
     46 struct wfq_getqid{
     47 	struct wfq_interface 	iface;
     48 	struct flowinfo 	flow;
     49 	u_long			qid;
     50 };
     51 
     52 struct wfq_setweight {
     53 	struct wfq_interface	iface;
     54 	int 			qid;
     55 	int 			weight;
     56 };
     57 
     58 typedef struct each_queue_stats {
     59 	int bytes;		/* bytes in this queue */
     60 	int weight;		/* weight in percent */
     61 	struct pktcntr xmit_cnt;
     62 	struct pktcntr drop_cnt;
     63 } queue_stats;
     64 
     65 struct wfq_getstats {
     66 	struct wfq_interface	iface;
     67 	int			qid;
     68 	queue_stats		stats;
     69 };
     70 
     71 struct wfq_conf {
     72 	struct wfq_interface	iface;
     73 	int			hash_policy;	/* hash policy */
     74 	int			nqueues;	/* number of queues */
     75 	int			qlimit;		/* queue size in bytes */
     76 };
     77 
     78 #define	WFQ_HASH_DSTADDR	0	/* hash by dst address */
     79 #define	WFQ_HASH_SRCPORT	1	/* hash by src port */
     80 #define	WFQ_HASH_FULL		2	/* hash by all fields */
     81 
     82 #define	WFQ_IF_ATTACH		_IOW('Q', 1, struct wfq_interface)
     83 #define	WFQ_IF_DETACH		_IOW('Q', 2, struct wfq_interface)
     84 #define	WFQ_ENABLE		_IOW('Q', 3, struct wfq_interface)
     85 #define	WFQ_DISABLE		_IOW('Q', 4, struct wfq_interface)
     86 #define	WFQ_CONFIG		_IOWR('Q', 6, struct wfq_conf)
     87 #define	WFQ_GET_STATS		_IOWR('Q', 12, struct wfq_getstats)
     88 #define	WFQ_GET_QID		_IOWR('Q', 30, struct wfq_getqid)
     89 #define	WFQ_SET_WEIGHT		_IOWR('Q', 31, struct wfq_setweight)
     90 
     91 #ifdef _KERNEL
     92 
     93 #define	HWM			(64 * 1024)
     94 #define	WFQ_QUOTA		512	/* quota bytes to send at a time */
     95 #define	WFQ_ADDQUOTA(q)		((q)->quota += WFQ_QUOTA * (q)->weight / 100)
     96 #define	ENABLE			0
     97 #define	DISABLE			1
     98 
     99 typedef struct weighted_fair_queue{
    100 	struct weighted_fair_queue *next, *prev;
    101 	struct mbuf *head, *tail;
    102 	int bytes;			/* bytes in this queue */
    103 	int quota;			/* bytes sent in this round */
    104 	int weight;			/* weight in percent */
    105 
    106 	struct pktcntr xmit_cnt;
    107 	struct pktcntr drop_cnt;
    108 } wfq;
    109 
    110 
    111 typedef struct wfqstate {
    112 	struct wfqstate *next;		/* for wfqstate list */
    113 	struct ifaltq *ifq;
    114 	int nums;			/* number of queues */
    115 	int hwm;			/* high water mark */
    116 	int bytes;			/* total bytes in all the queues */
    117 	wfq *rrp;			/* round robin pointer */
    118 	wfq *queue;			/* pointer to queue list */
    119 	u_long (*hash_func)(struct flowinfo *, int);
    120 	u_int32_t fbmask;		/* filter bitmask */
    121 } wfq_state_t;
    122 
    123 #endif /* _KERNEL */
    124 
    125 #endif /* _ALTQ_ALTQ_WFQ_H */
    126