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
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.
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]
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _IPP_METERS_METER_IMPL_H
28 #define _IPP_METERS_METER_IMPL_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
33 #include <sys/cmn_err.h>
34 #include <sys/debug.h>
37 #include <inet/ipp_common.h>
38 #include <ipp/meters/meter.h>
44 /* Header file for implementation of all the metering modules */
48 /* for a colour aware meter */
51 TOKENMT_YELLOW
= 0x02,
55 /* If yellow action is not provided, set it to infinity */
56 #define TOKENMT_NO_ACTION 0x7fffffff
58 #define METER_SEC_TO_NSEC 1000000000
59 #define METER_MSEC_TO_NSEC 1000000
61 #define _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
69 #define tokenmt0dbg(a) /* */
70 #define tokenmt1dbg(a) /* */
71 #define tokenmt2dbg(a) /* */
72 #endif /* _TOKENMT_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
79 #define tswtcl0dbg(a) /* */
80 #define tswtcl1dbg(a) /* */
81 #define tswtcl2dbg(a) /* */
82 #endif /* _TSWTCL_DEBUG */
84 #define SRTCL_TOKENMT 0x01
85 #define TRTCL_TOKENMT 0x02
87 #define DROP_PRECD_MASK 0x07
89 /* Stat structure for the tokenmts */
90 typedef struct meter_stat_t
{
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
;
100 #define TOKENMT_STATS_STRING "tokenmt statistics"
101 #define TSWTCL_STATS_STRING "tswtclmtr statistics"
102 #define METER_STATS_COUNT 7
104 /* Configuration paratokenmts for tokenmt */
105 typedef struct tokenmt_cfg_s
{
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
;
112 /* Meter type - SRTCL_TOKENMT or TRTCL_TOKENMT */
115 /* Committed rate in Kb/sec */
116 uint32_t committed_rate
;
119 /* Committed and Peak burst sizes in bits */
120 uint32_t committed_burst
;
123 /* Needs stats or not */
126 /* Meter Colour aware or not */
127 boolean_t colour_aware
;
129 /* Meter dscp to colour mapping, if colour aware */
130 enum meter_colour dscp_to_colour
[64];
136 typedef struct tokenmt_data_s
{
138 /* stats for this instance */
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
;
146 uint64_t yellow_bits
;
150 /* configured paratokenmts */
151 tokenmt_cfg_t
*cfg_parms
;
153 /* No. of tokens at the committed and peak burst */
154 uint64_t committed_tokens
;
155 uint64_t peak_tokens
;
157 /* For replenishing the token buckets */
160 /* Lock to protect data structures */
161 kmutex_t tokenmt_lock
;
164 typedef struct tswtcl_cfg_s
{
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
;
171 /* Committed and Peak rates in KB/sec */
172 uint32_t committed_rate
;
175 /* Window size in ms */
178 /* Need stats or not */
181 /* For aiding computations */
186 typedef struct tswtcl_data_s
{
188 /* stats for this instance */
191 /* Computed average rate */
194 /* Front of the sliding window */
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
;
202 uint64_t yellow_bits
;
206 /* Configured paramters */
207 tswtcl_cfg_t
*cfg_parms
;
209 /* Lock to protect data structures */
210 kmutex_t tswtcl_lock
;
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)
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
*);
227 #endif /* _IPP_METERS_METER_IMPL_H */