xref: /freebsd/sys/net/altq/altq_priq.h (revision 3cbb4cc200f8a0ad7ed08233425ea54524a21f1c)
1 /*-
2  * Copyright (C) 2000-2003
3  *	Sony Computer Science Laboratories Inc.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SONY CSL AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL SONY CSL OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $KAME: altq_priq.h,v 1.7 2003/10/03 05:05:15 kjc Exp $
27  * $FreeBSD$
28  */
29 
30 #ifndef _ALTQ_ALTQ_PRIQ_H_
31 #define	_ALTQ_ALTQ_PRIQ_H_
32 
33 #include <net/altq/altq.h>
34 #include <net/altq/altq_classq.h>
35 #include <net/altq/altq_codel.h>
36 #include <net/altq/altq_red.h>
37 #include <net/altq/altq_rio.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #define	PRIQ_MAXPRI	16	/* upper limit of the number of priorities */
44 
45 /* priq class flags */
46 #define	PRCF_RED		0x0001	/* use RED */
47 #define	PRCF_ECN		0x0002  /* use RED/ECN */
48 #define	PRCF_RIO		0x0004  /* use RIO */
49 #define	PRCF_CODEL		0x0008	/* use CoDel */
50 #define	PRCF_CLEARDSCP		0x0010  /* clear diffserv codepoint */
51 #define	PRCF_DEFAULTCLASS	0x1000	/* default class */
52 
53 /* special class handles */
54 #define	PRIQ_NULLCLASS_HANDLE	0
55 
56 struct priq_classstats {
57 	u_int32_t		class_handle;
58 
59 	u_int			qlength;
60 	u_int			qlimit;
61 	u_int			period;
62 	struct pktcntr		xmitcnt;  /* transmitted packet counter */
63 	struct pktcntr		dropcnt;  /* dropped packet counter */
64 
65 	/* codel, red and rio related info */
66 	int			qtype;
67 	struct redstats		red[3];	/* rio has 3 red stats */
68 	struct codel_stats	codel;
69 };
70 
71 /*
72  * PRIQ_STATS_VERSION is defined in altq.h to work around issues stemming
73  * from mixing of public-API and internal bits in each scheduler-specific
74  * header.
75  */
76 
77 #ifdef _KERNEL
78 
79 struct priq_class {
80 	u_int32_t	cl_handle;	/* class handle */
81 	class_queue_t	*cl_q;		/* class queue structure */
82 	union {
83 		struct red	*cl_red;	/* RED state */
84 		struct codel	*cl_codel;	/* CoDel state */
85 	} cl_aqm;
86 #define	cl_red		cl_aqm.cl_red
87 #define	cl_codel	cl_aqm.cl_codel
88 	int		cl_pri;		/* priority */
89 	int		cl_flags;	/* class flags */
90 	struct priq_if	*cl_pif;	/* back pointer to pif */
91 	struct altq_pktattr *cl_pktattr; /* saved header used by ECN */
92 
93 	/* statistics */
94 	u_int		cl_period;	/* backlog period */
95 	struct pktcntr  cl_xmitcnt;	/* transmitted packet counter */
96 	struct pktcntr  cl_dropcnt;	/* dropped packet counter */
97 };
98 
99 /*
100  * priq interface state
101  */
102 struct priq_if {
103 	struct priq_if		*pif_next;	/* interface state list */
104 	struct ifaltq		*pif_ifq;	/* backpointer to ifaltq */
105 	u_int			pif_bandwidth;	/* link bandwidth in bps */
106 	int			pif_maxpri;	/* max priority in use */
107 	struct priq_class	*pif_default;	/* default class */
108 	struct priq_class	*pif_classes[PRIQ_MAXPRI]; /* classes */
109 #ifdef ALTQ3_CLFIER_COMPAT
110 	struct acc_classifier	pif_classifier;	/* classifier */
111 #endif
112 };
113 
114 #endif /* _KERNEL */
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif /* _ALTQ_ALTQ_PRIQ_H_ */
121