summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/ng_car.h
blob: 3fda67512dd04a3e9b1eb8ed27499c80a98dba19 (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
/*-
 * Copyright (c) 2005 Nuno Antunes <nuno.antunes@gmail.com>
 * Copyright (c) 2007 Alexander Motin <mav@freebsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _NETGRAPH_NG_CAR_H_
#define _NETGRAPH_NG_CAR_H_

#define NG_CAR_NODE_TYPE	"car"
#define NGM_CAR_COOKIE		1173648034

/* Hook names */
#define NG_CAR_HOOK_UPPER	"upper"
#define NG_CAR_HOOK_LOWER	"lower"

/* Per hook statistics counters */
struct ng_car_hookstats {
	u_int64_t passed_pkts;	/* Counter for passed packets */
	u_int64_t droped_pkts;	/* Counter for droped packets */
	u_int64_t green_pkts;	/* Counter for green packets */
	u_int64_t yellow_pkts;	/* Counter for yellow packets */
	u_int64_t red_pkts;	/* Counter for red packets */
	u_int64_t errors;	/* Counter for operation errors */
};
#define NG_CAR_HOOKSTATS	{				\
	  { "passed",		&ng_parse_uint64_type	},	\
	  { "droped",		&ng_parse_uint64_type	},	\
	  { "green",		&ng_parse_uint64_type	},	\
	  { "yellow",		&ng_parse_uint64_type	},	\
	  { "red",		&ng_parse_uint64_type	},	\
	  { "errors",		&ng_parse_uint64_type	},	\
	  { NULL }						\
}

/* Bulk statistics */
struct ng_car_bulkstats {
	struct ng_car_hookstats upstream;
	struct ng_car_hookstats downstream;
};
#define NG_CAR_BULKSTATS(hstatstype) {				\
	  { "upstream",		(hstatstype)		},	\
	  { "downstream",	(hstatstype)		},	\
	  { NULL }						\
}

/* Per hook configuration */
struct ng_car_hookconf {
	u_int64_t cbs;		/* Committed burst size (bytes) */
	u_int64_t ebs;		/* Exceeded/Peak burst size (bytes) */
	u_int64_t cir;		/* Committed information rate (bits/s) */
	u_int64_t pir;		/* Peak information rate (bits/s) */
	u_int8_t green_action;	/* Action for green packets */
	u_int8_t yellow_action;	/* Action for yellow packets */
	u_int8_t red_action;	/* Action for red packets */
	u_int8_t mode;		/* single/double rate, ... */
	u_int8_t opt;		/* color-aware or color-blind */
};
/* Keep this definition in sync with the above structure */
#define NG_CAR_HOOKCONF	{					\
	  { "cbs",		&ng_parse_uint64_type	},	\
	  { "ebs",		&ng_parse_uint64_type	},	\
	  { "cir",		&ng_parse_uint64_type	},	\
	  { "pir",		&ng_parse_uint64_type	},	\
	  { "greenAction",	&ng_parse_uint8_type	},	\
	  { "yellowAction",	&ng_parse_uint8_type	},	\
	  { "redAction",	&ng_parse_uint8_type	},	\
	  { "mode",		&ng_parse_uint8_type	},	\
	  { "opt",		&ng_parse_uint8_type	},	\
	  { NULL }						\
}

#define NG_CAR_CBS_MIN		8192
#define NG_CAR_EBS_MIN		8192
#define NG_CAR_CIR_DFLT		10240

/* possible actions (...Action) */
enum {
    NG_CAR_ACTION_FORWARD = 1,
    NG_CAR_ACTION_DROP,
    NG_CAR_ACTION_MARK,
    NG_CAR_ACTION_SET_TOS
};

/* operation modes (mode) */
enum {
    NG_CAR_SINGLE_RATE = 0,
    NG_CAR_DOUBLE_RATE,
    NG_CAR_RED,
    NG_CAR_SHAPE
};

/* mode options (opt) */
#define NG_CAR_COLOR_AWARE	1
#define NG_CAR_COUNT_PACKETS	2

/* Bulk config */
struct ng_car_bulkconf {
	struct ng_car_hookconf upstream;
	struct ng_car_hookconf downstream;
};
#define NG_CAR_BULKCONF(hconftype) {				\
	  { "upstream",		(hconftype)		},	\
	  { "downstream",	(hconftype)		},	\
	  { NULL }						\
}

/* Commands */
enum {
	NGM_CAR_GET_STATS = 1,		/* Get statistics */
	NGM_CAR_CLR_STATS,		/* Clear statistics */
	NGM_CAR_GETCLR_STATS,		/* Get and clear statistics */
	NGM_CAR_GET_CONF,		/* Get bulk configuration */
	NGM_CAR_SET_CONF,		/* Set bulk configuration */
};

#endif /* _NETGRAPH_NG_CAR_H_ */
OpenPOWER on IntegriCloud