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 #include <sys/types.h> 31 #include <sys/cmn_err.h> 32 #include <sys/debug.h> 33 #include <sys/spl.h> 34 #include <ipp/ipp.h> 35 #include <inet/ipp_common.h> 36 #include <ipp/meters/meter.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 /* Header file for implementation of all the metering modules */ 43 44 #ifdef _KERNEL 45 46 /* for a colour aware meter */ 47 enum meter_colour { 48 TOKENMT_GREEN = 0x01, 49 TOKENMT_YELLOW = 0x02, 50 TOKENMT_RED = 0x04 51 }; 52 53 /* If yellow action is not provided, set it to infinity */ 54 #define TOKENMT_NO_ACTION 0x7fffffff 55 56 #define METER_SEC_TO_NSEC 1000000000 57 #define METER_MSEC_TO_NSEC 1000000 58 59 #define _TOKENMT_DEBUG 60 #define _TSWTCL_DEBUG 61 62 #ifdef _TOKENMT_DEBUG 63 #define tokenmt0dbg(a) printf a 64 #define tokenmt1dbg(a) if (tokenmt_debug > 2) printf a 65 #define tokenmt2dbg(a) if (tokenmt_debug > 3) printf a 66 #else 67 #define tokenmt0dbg(a) /* */ 68 #define tokenmt1dbg(a) /* */ 69 #define tokenmt2dbg(a) /* */ 70 #endif /* _TOKENMT_DEBUG */ 71 72 #ifdef _TSWTCL_DEBUG 73 #define tswtcl0dbg(a) printf a 74 #define tswtcl1dbg(a) if (tswtcl_debug > 2) printf a 75 #define tswtcl2dbg(a) if (tswtcl_debug > 3) printf a 76 #else 77 #define tswtcl0dbg(a) /* */ 78 #define tswtcl1dbg(a) /* */ 79 #define tswtcl2dbg(a) /* */ 80 #endif /* _TSWTCL_DEBUG */ 81 82 #define SRTCL_TOKENMT 0x01 83 #define TRTCL_TOKENMT 0x02 84 85 #define DROP_PRECD_MASK 0x07 86 87 /* Stat structure for the tokenmts */ 88 typedef struct meter_stat_t { 89 ipp_named_t red_bits; 90 ipp_named_t yellow_bits; 91 ipp_named_t green_bits; 92 ipp_named_t red_packets; 93 ipp_named_t yellow_packets; 94 ipp_named_t green_packets; 95 ipp_named_t epackets; 96 } meter_stat_t; 97 98 #define TOKENMT_STATS_STRING "tokenmt statistics" 99 #define TSWTCL_STATS_STRING "tswtclmtr statistics" 100 #define METER_STATS_COUNT 7 101 102 /* Configuration paratokenmts for tokenmt */ 103 typedef struct tokenmt_cfg_s { 104 105 /* Next action for Green, Yellow and Red packets */ 106 ipp_action_id_t red_action; 107 ipp_action_id_t yellow_action; 108 ipp_action_id_t green_action; 109 110 /* Meter type - SRTCL_TOKENMT or TRTCL_TOKENMT */ 111 uint_t tokenmt_type; 112 113 /* Committed rate in Kb/sec */ 114 uint32_t committed_rate; 115 uint32_t peak_rate; 116 117 /* Committed and Peak burst sizes in bits */ 118 uint32_t committed_burst; 119 uint32_t peak_burst; 120 121 /* Needs stats or not */ 122 boolean_t stats; 123 124 /* Meter Colour aware or not */ 125 boolean_t colour_aware; 126 127 /* Meter dscp to colour mapping, if colour aware */ 128 enum meter_colour dscp_to_colour[64]; 129 130 /* timer */ 131 timeout_id_t timer; 132 }tokenmt_cfg_t; 133 134 typedef struct tokenmt_data_s { 135 136 /* stats for this instance */ 137 ipp_stat_t *stats; 138 139 /* # packets classified as Red, Yellow and Green for this instance */ 140 uint64_t red_packets; 141 uint64_t yellow_packets; 142 uint64_t green_packets; 143 uint64_t red_bits; 144 uint64_t yellow_bits; 145 uint64_t green_bits; 146 uint64_t epackets; 147 148 /* configured paratokenmts */ 149 tokenmt_cfg_t *cfg_parms; 150 151 /* No. of tokens at the committed and peak burst */ 152 uint64_t committed_tokens; 153 uint64_t peak_tokens; 154 155 /* For replenishing the token buckets */ 156 uint64_t last_seen; 157 158 /* Lock to protect data structures */ 159 kmutex_t tokenmt_lock; 160 } tokenmt_data_t; 161 162 typedef struct tswtcl_cfg_s { 163 164 /* Next action for Green, Yellow and Red packets */ 165 ipp_action_id_t red_action; 166 ipp_action_id_t yellow_action; 167 ipp_action_id_t green_action; 168 169 /* Committed and Peak rates in KB/sec */ 170 uint32_t committed_rate; 171 uint32_t peak_rate; 172 173 /* Window size in ms */ 174 uint32_t window; 175 176 /* Need stats or not */ 177 boolean_t stats; 178 179 /* For aiding computations */ 180 uint64_t nsecwindow; 181 uint32_t pminusc; 182 }tswtcl_cfg_t; 183 184 typedef struct tswtcl_data_s { 185 186 /* stats for this instance */ 187 ipp_stat_t *stats; 188 189 /* Computed average rate */ 190 uint32_t avg_rate; 191 192 /* Front of the sliding window */ 193 hrtime_t win_front; 194 195 /* # packets classified as Red, Yellow and Green for this instance */ 196 uint64_t red_packets; 197 uint64_t yellow_packets; 198 uint64_t green_packets; 199 uint64_t red_bits; 200 uint64_t yellow_bits; 201 uint64_t green_bits; 202 uint64_t epackets; 203 204 /* Configured paramters */ 205 tswtcl_cfg_t *cfg_parms; 206 207 /* Lock to protect data structures */ 208 kmutex_t tswtcl_lock; 209 } tswtcl_data_t; 210 211 #define TOKENMT_DATA_SZ sizeof (tokenmt_data_t) 212 #define TOKENMT_CFG_SZ sizeof (tokenmt_cfg_t) 213 #define TSWTCL_DATA_SZ sizeof (tswtcl_data_t) 214 #define TSWTCL_CFG_SZ sizeof (tswtcl_cfg_t) 215 216 extern int tokenmt_process(mblk_t **, tokenmt_data_t *, ipp_action_id_t *); 217 extern int tswtcl_process(mblk_t **, tswtcl_data_t *, ipp_action_id_t *); 218 219 #endif /* _KERNEL */ 220 221 #ifdef __cplusplus 222 } 223 #endif 224 225 #endif /* _IPP_METERS_METER_IMPL_H */ 226