xref: /onnv-gate/usr/src/uts/common/ipp/meters/meter_impl.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef _IPP_METERS_METER_IMPL_H
28*0Sstevel@tonic-gate #define	_IPP_METERS_METER_IMPL_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #include <sys/types.h>
33*0Sstevel@tonic-gate #include <sys/cmn_err.h>
34*0Sstevel@tonic-gate #include <sys/debug.h>
35*0Sstevel@tonic-gate #include <sys/spl.h>
36*0Sstevel@tonic-gate #include <ipp/ipp.h>
37*0Sstevel@tonic-gate #include <inet/ipp_common.h>
38*0Sstevel@tonic-gate #include <ipp/meters/meter.h>
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #ifdef	__cplusplus
41*0Sstevel@tonic-gate extern "C" {
42*0Sstevel@tonic-gate #endif
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate /* Header file for implementation of all the metering modules */
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate #ifdef	_KERNEL
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate /* for a colour aware meter */
49*0Sstevel@tonic-gate enum meter_colour {
50*0Sstevel@tonic-gate 	TOKENMT_GREEN = 0x01,
51*0Sstevel@tonic-gate 	TOKENMT_YELLOW = 0x02,
52*0Sstevel@tonic-gate 	TOKENMT_RED = 0x04
53*0Sstevel@tonic-gate };
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate /* If yellow action is not provided, set it to infinity */
56*0Sstevel@tonic-gate #define	TOKENMT_NO_ACTION	0x7fffffff
57*0Sstevel@tonic-gate 
58*0Sstevel@tonic-gate #define	METER_SEC_TO_NSEC	1000000000
59*0Sstevel@tonic-gate #define	METER_MSEC_TO_NSEC	1000000
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate #define	_TOKENMT_DEBUG
62*0Sstevel@tonic-gate #define	_TSWTCL_DEBUG
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate #ifdef _TOKENMT_DEBUG
65*0Sstevel@tonic-gate #define	tokenmt0dbg(a)		printf a
66*0Sstevel@tonic-gate #define	tokenmt1dbg(a)		if (tokenmt_debug > 2) printf a
67*0Sstevel@tonic-gate #define	tokenmt2dbg(a)		if (tokenmt_debug > 3) printf a
68*0Sstevel@tonic-gate #else
69*0Sstevel@tonic-gate #define	tokenmt0dbg(a)		/*  */
70*0Sstevel@tonic-gate #define	tokenmt1dbg(a)		/*  */
71*0Sstevel@tonic-gate #define	tokenmt2dbg(a)		/*  */
72*0Sstevel@tonic-gate #endif /* _TOKENMT_DEBUG */
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate #ifdef _TSWTCL_DEBUG
75*0Sstevel@tonic-gate #define	tswtcl0dbg(a)		printf a
76*0Sstevel@tonic-gate #define	tswtcl1dbg(a)		if (tswtcl_debug > 2) printf a
77*0Sstevel@tonic-gate #define	tswtcl2dbg(a)		if (tswtcl_debug > 3) printf a
78*0Sstevel@tonic-gate #else
79*0Sstevel@tonic-gate #define	tswtcl0dbg(a)		/*  */
80*0Sstevel@tonic-gate #define	tswtcl1dbg(a)		/*  */
81*0Sstevel@tonic-gate #define	tswtcl2dbg(a)		/*  */
82*0Sstevel@tonic-gate #endif /* _TSWTCL_DEBUG */
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate #define	SRTCL_TOKENMT		0x01
85*0Sstevel@tonic-gate #define	TRTCL_TOKENMT		0x02
86*0Sstevel@tonic-gate 
87*0Sstevel@tonic-gate #define	DROP_PRECD_MASK		0x07
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate /* Stat structure for the tokenmts */
90*0Sstevel@tonic-gate typedef struct meter_stat_t {
91*0Sstevel@tonic-gate 	ipp_named_t red_bits;
92*0Sstevel@tonic-gate 	ipp_named_t yellow_bits;
93*0Sstevel@tonic-gate 	ipp_named_t green_bits;
94*0Sstevel@tonic-gate 	ipp_named_t red_packets;
95*0Sstevel@tonic-gate 	ipp_named_t yellow_packets;
96*0Sstevel@tonic-gate 	ipp_named_t green_packets;
97*0Sstevel@tonic-gate 	ipp_named_t epackets;
98*0Sstevel@tonic-gate } meter_stat_t;
99*0Sstevel@tonic-gate 
100*0Sstevel@tonic-gate #define	TOKENMT_STATS_STRING	"tokenmt statistics"
101*0Sstevel@tonic-gate #define	TSWTCL_STATS_STRING	"tswtclmtr statistics"
102*0Sstevel@tonic-gate #define	METER_STATS_COUNT	7
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate /* Configuration paratokenmts for tokenmt */
105*0Sstevel@tonic-gate typedef struct tokenmt_cfg_s {
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 	/* Next action for Green, Yellow and Red packets */
108*0Sstevel@tonic-gate 	ipp_action_id_t red_action;
109*0Sstevel@tonic-gate 	ipp_action_id_t yellow_action;
110*0Sstevel@tonic-gate 	ipp_action_id_t green_action;
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate 	/* Meter type  - SRTCL_TOKENMT or TRTCL_TOKENMT */
113*0Sstevel@tonic-gate 	uint_t tokenmt_type;
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate 	/* Committed rate in Kb/sec */
116*0Sstevel@tonic-gate 	uint32_t committed_rate;
117*0Sstevel@tonic-gate 	uint32_t peak_rate;
118*0Sstevel@tonic-gate 
119*0Sstevel@tonic-gate 	/* Committed and Peak burst sizes in bits */
120*0Sstevel@tonic-gate 	uint32_t committed_burst;
121*0Sstevel@tonic-gate 	uint32_t peak_burst;
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate 	/* Needs stats or not */
124*0Sstevel@tonic-gate 	boolean_t stats;
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	/* Meter Colour aware or not */
127*0Sstevel@tonic-gate 	boolean_t colour_aware;
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 	/* Meter dscp to colour mapping, if colour aware */
130*0Sstevel@tonic-gate 	enum meter_colour dscp_to_colour[64];
131*0Sstevel@tonic-gate 
132*0Sstevel@tonic-gate 	/* timer */
133*0Sstevel@tonic-gate 	timeout_id_t timer;
134*0Sstevel@tonic-gate }tokenmt_cfg_t;
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate typedef struct tokenmt_data_s {
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate 	/* stats for this instance */
139*0Sstevel@tonic-gate 	ipp_stat_t *stats;
140*0Sstevel@tonic-gate 
141*0Sstevel@tonic-gate 	/* # packets classified as Red, Yellow and Green for this instance */
142*0Sstevel@tonic-gate 	uint64_t red_packets;
143*0Sstevel@tonic-gate 	uint64_t yellow_packets;
144*0Sstevel@tonic-gate 	uint64_t green_packets;
145*0Sstevel@tonic-gate 	uint64_t red_bits;
146*0Sstevel@tonic-gate 	uint64_t yellow_bits;
147*0Sstevel@tonic-gate 	uint64_t green_bits;
148*0Sstevel@tonic-gate 	uint64_t epackets;
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate 	/* configured paratokenmts */
151*0Sstevel@tonic-gate 	tokenmt_cfg_t *cfg_parms;
152*0Sstevel@tonic-gate 
153*0Sstevel@tonic-gate 	/* No. of tokens at the committed and peak burst */
154*0Sstevel@tonic-gate 	uint64_t committed_tokens;
155*0Sstevel@tonic-gate 	uint64_t peak_tokens;
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 	/* For replenishing the token buckets */
158*0Sstevel@tonic-gate 	uint64_t last_seen;
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 	/* Lock to protect data structures */
161*0Sstevel@tonic-gate 	kmutex_t tokenmt_lock;
162*0Sstevel@tonic-gate } tokenmt_data_t;
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate typedef struct tswtcl_cfg_s {
165*0Sstevel@tonic-gate 
166*0Sstevel@tonic-gate 	/* Next action for Green, Yellow and Red packets */
167*0Sstevel@tonic-gate 	ipp_action_id_t red_action;
168*0Sstevel@tonic-gate 	ipp_action_id_t yellow_action;
169*0Sstevel@tonic-gate 	ipp_action_id_t green_action;
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate 	/* Committed and Peak rates in KB/sec */
172*0Sstevel@tonic-gate 	uint32_t committed_rate;
173*0Sstevel@tonic-gate 	uint32_t peak_rate;
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 	/* Window size in ms */
176*0Sstevel@tonic-gate 	uint32_t window;
177*0Sstevel@tonic-gate 
178*0Sstevel@tonic-gate 	/* Need stats or not */
179*0Sstevel@tonic-gate 	boolean_t stats;
180*0Sstevel@tonic-gate 
181*0Sstevel@tonic-gate 	/* For aiding computations */
182*0Sstevel@tonic-gate 	uint64_t nsecwindow;
183*0Sstevel@tonic-gate 	uint32_t pminusc;
184*0Sstevel@tonic-gate }tswtcl_cfg_t;
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate typedef struct tswtcl_data_s {
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate 	/* stats for this instance */
189*0Sstevel@tonic-gate 	ipp_stat_t *stats;
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate 	/* Computed average rate */
192*0Sstevel@tonic-gate 	uint32_t avg_rate;
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate 	/* Front of the sliding window */
195*0Sstevel@tonic-gate 	hrtime_t win_front;
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate 	/* # packets classified as Red, Yellow and Green for this instance */
198*0Sstevel@tonic-gate 	uint64_t red_packets;
199*0Sstevel@tonic-gate 	uint64_t yellow_packets;
200*0Sstevel@tonic-gate 	uint64_t green_packets;
201*0Sstevel@tonic-gate 	uint64_t red_bits;
202*0Sstevel@tonic-gate 	uint64_t yellow_bits;
203*0Sstevel@tonic-gate 	uint64_t green_bits;
204*0Sstevel@tonic-gate 	uint64_t epackets;
205*0Sstevel@tonic-gate 
206*0Sstevel@tonic-gate 	/* Configured paramters */
207*0Sstevel@tonic-gate 	tswtcl_cfg_t *cfg_parms;
208*0Sstevel@tonic-gate 
209*0Sstevel@tonic-gate 	/* Lock to protect data structures */
210*0Sstevel@tonic-gate 	kmutex_t tswtcl_lock;
211*0Sstevel@tonic-gate } tswtcl_data_t;
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate #define	TOKENMT_DATA_SZ		sizeof (tokenmt_data_t)
214*0Sstevel@tonic-gate #define	TOKENMT_CFG_SZ		sizeof (tokenmt_cfg_t)
215*0Sstevel@tonic-gate #define	TSWTCL_DATA_SZ		sizeof (tswtcl_data_t)
216*0Sstevel@tonic-gate #define	TSWTCL_CFG_SZ		sizeof (tswtcl_cfg_t)
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate extern int tokenmt_process(mblk_t **, tokenmt_data_t *, ipp_action_id_t *);
219*0Sstevel@tonic-gate extern int tswtcl_process(mblk_t **, tswtcl_data_t *, ipp_action_id_t *);
220*0Sstevel@tonic-gate 
221*0Sstevel@tonic-gate #endif /* _KERNEL */
222*0Sstevel@tonic-gate 
223*0Sstevel@tonic-gate #ifdef	__cplusplus
224*0Sstevel@tonic-gate }
225*0Sstevel@tonic-gate #endif
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate #endif /* _IPP_METERS_METER_IMPL_H */
228