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