Home | History | Annotate | Line # | Download | only in altq
altq_wfq.h revision 1.1
      1 /*	$KAME: altq_wfq.h,v 1.5 2000/12/14 08:12:46 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1997-2000
      5  *	Sony Computer Science Laboratories Inc.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 /*
     29  *  March 27, 1997.  Written by Hiroshi Kyusojin of Keio University
     30  *  (kyu (at) mt.cs.keio.ac.jp).
     31  */
     32 
     33 #ifndef _ALTQ_ALTQ_WFQ_H_
     34 #define	_ALTQ_ALTQ_WFQ_H_
     35 
     36 #include <altq/altq.h>
     37 
     38 #define	DEFAULT_QSIZE	256
     39 #define	MAX_QSIZE	2048
     40 
     41 struct wfq_interface{
     42 	char wfq_ifacename[IFNAMSIZ];
     43 };
     44 
     45 struct wfq_getqid{
     46 	struct wfq_interface 	iface;
     47 	struct flowinfo 	flow;
     48 	u_long			qid;
     49 };
     50 
     51 struct wfq_setweight {
     52 	struct wfq_interface	iface;
     53 	int 			qid;
     54 	int 			weight;
     55 };
     56 
     57 typedef struct each_queue_stats {
     58 	int bytes;		/* bytes in this queue */
     59 	int weight;		/* weight in percent */
     60 	struct pktcntr xmit_cnt;
     61 	struct pktcntr drop_cnt;
     62 } queue_stats;
     63 
     64 struct wfq_getstats {
     65 	struct wfq_interface	iface;
     66 	int			qid;
     67 	queue_stats		stats;
     68 };
     69 
     70 struct wfq_conf {
     71 	struct wfq_interface	iface;
     72 	int			hash_policy;	/* hash policy */
     73 	int			nqueues;	/* number of queues */
     74 	int			qlimit;		/* queue size in bytes */
     75 };
     76 
     77 #define	WFQ_HASH_DSTADDR	0	/* hash by dst address */
     78 #define	WFQ_HASH_SRCPORT	1	/* hash by src port */
     79 #define	WFQ_HASH_FULL		2	/* hash by all fields */
     80 
     81 #define	WFQ_IF_ATTACH		_IOW('Q', 1, struct wfq_interface)
     82 #define	WFQ_IF_DETACH		_IOW('Q', 2, struct wfq_interface)
     83 #define	WFQ_ENABLE		_IOW('Q', 3, struct wfq_interface)
     84 #define	WFQ_DISABLE		_IOW('Q', 4, struct wfq_interface)
     85 #define	WFQ_CONFIG		_IOWR('Q', 6, struct wfq_conf)
     86 #define	WFQ_GET_STATS		_IOWR('Q', 12, struct wfq_getstats)
     87 #define	WFQ_GET_QID		_IOWR('Q', 30, struct wfq_getqid)
     88 #define	WFQ_SET_WEIGHT		_IOWR('Q', 31, struct wfq_setweight)
     89 
     90 #ifdef _KERNEL
     91 
     92 #define	HWM			(64 * 1024)
     93 #define	WFQ_QUOTA		512	/* quota bytes to send at a time */
     94 #define	WFQ_ADDQUOTA(q)		((q)->quota += WFQ_QUOTA * (q)->weight / 100)
     95 #define	ENABLE			0
     96 #define	DISABLE			1
     97 
     98 typedef struct weighted_fair_queue{
     99 	struct weighted_fair_queue *next, *prev;
    100 	struct mbuf *head, *tail;
    101 	int bytes;			/* bytes in this queue */
    102 	int quota;			/* bytes sent in this round */
    103 	int weight;			/* weight in percent */
    104 
    105 	struct pktcntr xmit_cnt;
    106 	struct pktcntr drop_cnt;
    107 } wfq;
    108 
    109 
    110 typedef struct wfqstate {
    111 	struct wfqstate *next;		/* for wfqstate list */
    112 	struct ifaltq *ifq;
    113 	int nums;			/* number of queues */
    114 	int hwm;			/* high water mark */
    115 	int bytes;			/* total bytes in all the queues */
    116 	wfq *rrp;			/* round robin pointer */
    117 	wfq *queue;			/* pointer to queue list */
    118 	u_long (*hash_func)(struct flowinfo *, int);
    119 	u_int32_t fbmask;		/* filter bitmask */
    120 } wfq_state_t;
    121 
    122 #endif /* _KERNEL */
    123 
    124 #endif /* _ALTQ_ALTQ_WFQ_H */
    125