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