summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/ipp/meters/meter_impl.h
blob: ff7b9081d29a8e198c5352ebdac0199285d311f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _IPP_METERS_METER_IMPL_H
#define	_IPP_METERS_METER_IMPL_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/types.h>
#include <sys/cmn_err.h>
#include <sys/debug.h>
#include <sys/spl.h>
#include <ipp/ipp.h>
#include <inet/ipp_common.h>
#include <ipp/meters/meter.h>

#ifdef	__cplusplus
extern "C" {
#endif

/* Header file for implementation of all the metering modules */

#ifdef	_KERNEL

/* for a colour aware meter */
enum meter_colour {
	TOKENMT_GREEN = 0x01,
	TOKENMT_YELLOW = 0x02,
	TOKENMT_RED = 0x04
};

/* If yellow action is not provided, set it to infinity */
#define	TOKENMT_NO_ACTION	0x7fffffff

#define	METER_SEC_TO_NSEC	1000000000
#define	METER_MSEC_TO_NSEC	1000000

#define	_TOKENMT_DEBUG
#define	_TSWTCL_DEBUG

#ifdef _TOKENMT_DEBUG
#define	tokenmt0dbg(a)		printf a
#define	tokenmt1dbg(a)		if (tokenmt_debug > 2) printf a
#define	tokenmt2dbg(a)		if (tokenmt_debug > 3) printf a
#else
#define	tokenmt0dbg(a)		/*  */
#define	tokenmt1dbg(a)		/*  */
#define	tokenmt2dbg(a)		/*  */
#endif /* _TOKENMT_DEBUG */

#ifdef _TSWTCL_DEBUG
#define	tswtcl0dbg(a)		printf a
#define	tswtcl1dbg(a)		if (tswtcl_debug > 2) printf a
#define	tswtcl2dbg(a)		if (tswtcl_debug > 3) printf a
#else
#define	tswtcl0dbg(a)		/*  */
#define	tswtcl1dbg(a)		/*  */
#define	tswtcl2dbg(a)		/*  */
#endif /* _TSWTCL_DEBUG */

#define	SRTCL_TOKENMT		0x01
#define	TRTCL_TOKENMT		0x02

#define	DROP_PRECD_MASK		0x07

/* Stat structure for the tokenmts */
typedef struct meter_stat_t {
	ipp_named_t red_bits;
	ipp_named_t yellow_bits;
	ipp_named_t green_bits;
	ipp_named_t red_packets;
	ipp_named_t yellow_packets;
	ipp_named_t green_packets;
	ipp_named_t epackets;
} meter_stat_t;

#define	TOKENMT_STATS_STRING	"tokenmt statistics"
#define	TSWTCL_STATS_STRING	"tswtclmtr statistics"
#define	METER_STATS_COUNT	7

/* Configuration paratokenmts for tokenmt */
typedef struct tokenmt_cfg_s {

	/* Next action for Green, Yellow and Red packets */
	ipp_action_id_t red_action;
	ipp_action_id_t yellow_action;
	ipp_action_id_t green_action;

	/* Meter type  - SRTCL_TOKENMT or TRTCL_TOKENMT */
	uint_t tokenmt_type;

	/* Committed rate in Kb/sec */
	uint32_t committed_rate;
	uint32_t peak_rate;

	/* Committed and Peak burst sizes in bits */
	uint32_t committed_burst;
	uint32_t peak_burst;

	/* Needs stats or not */
	boolean_t stats;

	/* Meter Colour aware or not */
	boolean_t colour_aware;

	/* Meter dscp to colour mapping, if colour aware */
	enum meter_colour dscp_to_colour[64];

	/* timer */
	timeout_id_t timer;
}tokenmt_cfg_t;

typedef struct tokenmt_data_s {

	/* stats for this instance */
	ipp_stat_t *stats;

	/* # packets classified as Red, Yellow and Green for this instance */
	uint64_t red_packets;
	uint64_t yellow_packets;
	uint64_t green_packets;
	uint64_t red_bits;
	uint64_t yellow_bits;
	uint64_t green_bits;
	uint64_t epackets;

	/* configured paratokenmts */
	tokenmt_cfg_t *cfg_parms;

	/* No. of tokens at the committed and peak burst */
	uint64_t committed_tokens;
	uint64_t peak_tokens;

	/* For replenishing the token buckets */
	uint64_t last_seen;

	/* Lock to protect data structures */
	kmutex_t tokenmt_lock;
} tokenmt_data_t;

typedef struct tswtcl_cfg_s {

	/* Next action for Green, Yellow and Red packets */
	ipp_action_id_t red_action;
	ipp_action_id_t yellow_action;
	ipp_action_id_t green_action;

	/* Committed and Peak rates in KB/sec */
	uint32_t committed_rate;
	uint32_t peak_rate;

	/* Window size in ms */
	uint32_t window;

	/* Need stats or not */
	boolean_t stats;

	/* For aiding computations */
	uint64_t nsecwindow;
	uint32_t pminusc;
}tswtcl_cfg_t;

typedef struct tswtcl_data_s {

	/* stats for this instance */
	ipp_stat_t *stats;

	/* Computed average rate */
	uint32_t avg_rate;

	/* Front of the sliding window */
	hrtime_t win_front;

	/* # packets classified as Red, Yellow and Green for this instance */
	uint64_t red_packets;
	uint64_t yellow_packets;
	uint64_t green_packets;
	uint64_t red_bits;
	uint64_t yellow_bits;
	uint64_t green_bits;
	uint64_t epackets;

	/* Configured paramters */
	tswtcl_cfg_t *cfg_parms;

	/* Lock to protect data structures */
	kmutex_t tswtcl_lock;
} tswtcl_data_t;

#define	TOKENMT_DATA_SZ		sizeof (tokenmt_data_t)
#define	TOKENMT_CFG_SZ		sizeof (tokenmt_cfg_t)
#define	TSWTCL_DATA_SZ		sizeof (tswtcl_data_t)
#define	TSWTCL_CFG_SZ		sizeof (tswtcl_cfg_t)

extern int tokenmt_process(mblk_t **, tokenmt_data_t *, ipp_action_id_t *);
extern int tswtcl_process(mblk_t **, tswtcl_data_t *, ipp_action_id_t *);

#endif /* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif /* _IPP_METERS_METER_IMPL_H */