1169577Smav/*-
2169577Smav * Copyright (c) 2005 Nuno Antunes <nuno.antunes@gmail.com>
3169577Smav * Copyright (c) 2007 Alexander Motin <mav@freebsd.org>
4169577Smav * All rights reserved.
5169577Smav *
6169577Smav * Redistribution and use in source and binary forms, with or without
7169577Smav * modification, are permitted provided that the following conditions
8169577Smav * are met:
9169577Smav * 1. Redistributions of source code must retain the above copyright
10169577Smav *    notice, this list of conditions and the following disclaimer.
11169577Smav * 2. Redistributions in binary form must reproduce the above copyright
12169577Smav *    notice, this list of conditions and the following disclaimer in the
13169577Smav *    documentation and/or other materials provided with the distribution.
14169577Smav *
15169577Smav * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16169577Smav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17169577Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18169577Smav * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19169577Smav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20169577Smav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21169577Smav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22169577Smav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23169577Smav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24169577Smav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25169577Smav * SUCH DAMAGE.
26169577Smav *
27169577Smav * $FreeBSD$
28169577Smav */
29169577Smav
30169577Smav#ifndef _NETGRAPH_NG_CAR_H_
31169577Smav#define _NETGRAPH_NG_CAR_H_
32169577Smav
33169577Smav#define NG_CAR_NODE_TYPE	"car"
34169577Smav#define NGM_CAR_COOKIE		1173648034
35169577Smav
36169577Smav/* Hook names */
37169577Smav#define NG_CAR_HOOK_UPPER	"upper"
38169577Smav#define NG_CAR_HOOK_LOWER	"lower"
39169577Smav
40169577Smav/* Per hook statistics counters */
41169577Smavstruct ng_car_hookstats {
42169577Smav	u_int64_t passed_pkts;	/* Counter for passed packets */
43169577Smav	u_int64_t droped_pkts;	/* Counter for droped packets */
44169577Smav	u_int64_t green_pkts;	/* Counter for green packets */
45169577Smav	u_int64_t yellow_pkts;	/* Counter for yellow packets */
46169577Smav	u_int64_t red_pkts;	/* Counter for red packets */
47169577Smav	u_int64_t errors;	/* Counter for operation errors */
48169577Smav};
49169577Smav#define NG_CAR_HOOKSTATS	{				\
50169577Smav	  { "passed",		&ng_parse_uint64_type	},	\
51169577Smav	  { "droped",		&ng_parse_uint64_type	},	\
52169577Smav	  { "green",		&ng_parse_uint64_type	},	\
53169577Smav	  { "yellow",		&ng_parse_uint64_type	},	\
54169577Smav	  { "red",		&ng_parse_uint64_type	},	\
55169577Smav	  { "errors",		&ng_parse_uint64_type	},	\
56169577Smav	  { NULL }						\
57169577Smav}
58169577Smav
59169577Smav/* Bulk statistics */
60169577Smavstruct ng_car_bulkstats {
61169577Smav	struct ng_car_hookstats upstream;
62169577Smav	struct ng_car_hookstats downstream;
63169577Smav};
64169577Smav#define NG_CAR_BULKSTATS(hstatstype) {				\
65169577Smav	  { "upstream",		(hstatstype)		},	\
66169577Smav	  { "downstream",	(hstatstype)		},	\
67169577Smav	  { NULL }						\
68169577Smav}
69169577Smav
70169577Smav/* Per hook configuration */
71169577Smavstruct ng_car_hookconf {
72169577Smav	u_int64_t cbs;		/* Commited burst size (bytes) */
73169577Smav	u_int64_t ebs;		/* Exceeded/Peak burst size (bytes) */
74169577Smav	u_int64_t cir;		/* Commited information rate (bits/s) */
75169577Smav	u_int64_t pir;		/* Peak information rate (bits/s) */
76169577Smav	u_int8_t green_action;	/* Action for green packets */
77169577Smav	u_int8_t yellow_action;	/* Action for yellow packets */
78169577Smav	u_int8_t red_action;	/* Action for red packets */
79169577Smav	u_int8_t mode;		/* single/double rate, ... */
80169577Smav	u_int8_t opt;		/* color-aware or color-blind */
81169577Smav};
82169577Smav/* Keep this definition in sync with the above structure */
83169577Smav#define NG_CAR_HOOKCONF	{					\
84169577Smav	  { "cbs",		&ng_parse_uint64_type	},	\
85169577Smav	  { "ebs",		&ng_parse_uint64_type	},	\
86169577Smav	  { "cir",		&ng_parse_uint64_type	},	\
87169577Smav	  { "pir",		&ng_parse_uint64_type	},	\
88169577Smav	  { "greenAction",	&ng_parse_uint8_type	},	\
89169577Smav	  { "yellowAction",	&ng_parse_uint8_type	},	\
90169577Smav	  { "redAction",	&ng_parse_uint8_type	},	\
91169577Smav	  { "mode",		&ng_parse_uint8_type	},	\
92169577Smav	  { "opt",		&ng_parse_uint8_type	},	\
93169577Smav	  { NULL }						\
94169577Smav}
95169577Smav
96169577Smav#define NG_CAR_CBS_MIN		8192
97169577Smav#define NG_CAR_EBS_MIN		8192
98169577Smav#define NG_CAR_CIR_DFLT		10240
99169577Smav
100169577Smav/* possible actions (...Action) */
101169577Smavenum {
102169577Smav    NG_CAR_ACTION_FORWARD = 1,
103169577Smav    NG_CAR_ACTION_DROP,
104169577Smav    NG_CAR_ACTION_MARK,
105169577Smav    NG_CAR_ACTION_SET_TOS
106169577Smav};
107169577Smav
108169577Smav/* operation modes (mode) */
109169577Smavenum {
110169577Smav    NG_CAR_SINGLE_RATE = 0,
111169577Smav    NG_CAR_DOUBLE_RATE,
112169577Smav    NG_CAR_RED,
113169577Smav    NG_CAR_SHAPE
114169577Smav};
115169577Smav
116169577Smav/* mode options (opt) */
117169577Smav#define NG_CAR_COLOR_AWARE	1
118174795Smav#define NG_CAR_COUNT_PACKETS	2
119169577Smav
120169577Smav/* Bulk config */
121169577Smavstruct ng_car_bulkconf {
122169577Smav	struct ng_car_hookconf upstream;
123169577Smav	struct ng_car_hookconf downstream;
124169577Smav};
125169577Smav#define NG_CAR_BULKCONF(hconftype) {				\
126169577Smav	  { "upstream",		(hconftype)		},	\
127169577Smav	  { "downstream",	(hconftype)		},	\
128169577Smav	  { NULL }						\
129169577Smav}
130169577Smav
131169577Smav/* Commands */
132169577Smavenum {
133169577Smav	NGM_CAR_GET_STATS = 1,		/* Get statistics */
134169577Smav	NGM_CAR_CLR_STATS,		/* Clear statistics */
135169577Smav	NGM_CAR_GETCLR_STATS,		/* Get and clear statistics */
136169577Smav	NGM_CAR_GET_CONF,		/* Get bulk configuration */
137169577Smav	NGM_CAR_SET_CONF,		/* Set bulk configuration */
138169577Smav};
139169577Smav
140169577Smav#endif /* _NETGRAPH_NG_CAR_H_ */
141