1*3b2bd0f6Slogwang /*-
2*3b2bd0f6Slogwang  * Copyright (c) 2004-2008 University of Zagreb
3*3b2bd0f6Slogwang  * Copyright (c) 2007-2008 FreeBSD Foundation
4*3b2bd0f6Slogwang  *
5*3b2bd0f6Slogwang  * This software was developed by the University of Zagreb and the
6*3b2bd0f6Slogwang  * FreeBSD Foundation under sponsorship by the Stichting NLnet and the
7*3b2bd0f6Slogwang  * FreeBSD Foundation.
8*3b2bd0f6Slogwang  *
9*3b2bd0f6Slogwang  * Redistribution and use in source and binary forms, with or without
10*3b2bd0f6Slogwang  * modification, are permitted provided that the following conditions
11*3b2bd0f6Slogwang  * are met:
12*3b2bd0f6Slogwang  * 1. Redistributions of source code must retain the above copyright
13*3b2bd0f6Slogwang  *    notice, this list of conditions and the following disclaimer.
14*3b2bd0f6Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
15*3b2bd0f6Slogwang  *    notice, this list of conditions and the following disclaimer in the
16*3b2bd0f6Slogwang  *    documentation and/or other materials provided with the distribution.
17*3b2bd0f6Slogwang  *
18*3b2bd0f6Slogwang  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19*3b2bd0f6Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*3b2bd0f6Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*3b2bd0f6Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22*3b2bd0f6Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*3b2bd0f6Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*3b2bd0f6Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*3b2bd0f6Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*3b2bd0f6Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*3b2bd0f6Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*3b2bd0f6Slogwang  * SUCH DAMAGE.
29*3b2bd0f6Slogwang  *
30*3b2bd0f6Slogwang  * $FreeBSD$
31*3b2bd0f6Slogwang  */
32*3b2bd0f6Slogwang 
33*3b2bd0f6Slogwang #ifndef _NETGRAPH_PIPE_H_
34*3b2bd0f6Slogwang #define _NETGRAPH_PIPE_H_
35*3b2bd0f6Slogwang 
36*3b2bd0f6Slogwang /* Node type name and magic cookie */
37*3b2bd0f6Slogwang #define NG_PIPE_NODE_TYPE	"pipe"
38*3b2bd0f6Slogwang #define NGM_PIPE_COOKIE		200708191
39*3b2bd0f6Slogwang 
40*3b2bd0f6Slogwang /* Hook names */
41*3b2bd0f6Slogwang #define NG_PIPE_HOOK_UPPER	"upper"
42*3b2bd0f6Slogwang #define NG_PIPE_HOOK_LOWER	"lower"
43*3b2bd0f6Slogwang 
44*3b2bd0f6Slogwang #define MAX_FSIZE 16384	/* Largest supported frame size, in bytes, for BER */
45*3b2bd0f6Slogwang #define MAX_OHSIZE 256	/* Largest supported dummy-framing size, in bytes */
46*3b2bd0f6Slogwang 
47*3b2bd0f6Slogwang /* Statistics structure for one hook */
48*3b2bd0f6Slogwang struct ng_pipe_hookstat {
49*3b2bd0f6Slogwang 	u_int64_t		fwd_octets;
50*3b2bd0f6Slogwang 	u_int64_t		fwd_frames;
51*3b2bd0f6Slogwang 	u_int64_t		in_disc_octets;
52*3b2bd0f6Slogwang 	u_int64_t		in_disc_frames;
53*3b2bd0f6Slogwang 	u_int64_t		out_disc_octets;
54*3b2bd0f6Slogwang 	u_int64_t		out_disc_frames;
55*3b2bd0f6Slogwang };
56*3b2bd0f6Slogwang 
57*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
58*3b2bd0f6Slogwang #define NG_PIPE_HOOKSTAT_INFO	{					\
59*3b2bd0f6Slogwang 	{ "FwdOctets",		&ng_parse_uint64_type	},		\
60*3b2bd0f6Slogwang 	{ "FwdFrames",		&ng_parse_uint64_type	},		\
61*3b2bd0f6Slogwang 	{ "queueDropOctets",	&ng_parse_uint64_type	},		\
62*3b2bd0f6Slogwang 	{ "queueDropFrames",	&ng_parse_uint64_type	},		\
63*3b2bd0f6Slogwang 	{ "delayDropOctets",	&ng_parse_uint64_type	},		\
64*3b2bd0f6Slogwang 	{ "delayDropFrames",	&ng_parse_uint64_type	},		\
65*3b2bd0f6Slogwang 	{ NULL },							\
66*3b2bd0f6Slogwang }
67*3b2bd0f6Slogwang 
68*3b2bd0f6Slogwang /* Statistics structure returned by NGM_PIPE_GET_STATS */
69*3b2bd0f6Slogwang struct ng_pipe_stats {
70*3b2bd0f6Slogwang 	struct ng_pipe_hookstat	downstream;
71*3b2bd0f6Slogwang 	struct ng_pipe_hookstat	upstream;
72*3b2bd0f6Slogwang };
73*3b2bd0f6Slogwang 
74*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
75*3b2bd0f6Slogwang #define NG_PIPE_STATS_INFO(hstype)	{				\
76*3b2bd0f6Slogwang 	{ "downstream",		(hstype) },				\
77*3b2bd0f6Slogwang 	{ "upstream",		(hstype) },				\
78*3b2bd0f6Slogwang 	{ NULL },							\
79*3b2bd0f6Slogwang }
80*3b2bd0f6Slogwang 
81*3b2bd0f6Slogwang /* Runtime structure for one hook */
82*3b2bd0f6Slogwang struct ng_pipe_hookrun {
83*3b2bd0f6Slogwang 	u_int32_t		fifo_queues;
84*3b2bd0f6Slogwang 	u_int32_t		qin_octets;
85*3b2bd0f6Slogwang 	u_int32_t		qin_frames;
86*3b2bd0f6Slogwang 	u_int32_t		qout_octets;
87*3b2bd0f6Slogwang 	u_int32_t		qout_frames;
88*3b2bd0f6Slogwang };
89*3b2bd0f6Slogwang 
90*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
91*3b2bd0f6Slogwang #define NG_PIPE_HOOKRUN_INFO	{					\
92*3b2bd0f6Slogwang 	{ "queues",		&ng_parse_uint32_type	},		\
93*3b2bd0f6Slogwang 	{ "queuedOctets",	&ng_parse_uint32_type	},		\
94*3b2bd0f6Slogwang 	{ "queuedFrames",	&ng_parse_uint32_type	},		\
95*3b2bd0f6Slogwang 	{ "delayedOctets",	&ng_parse_uint32_type	},		\
96*3b2bd0f6Slogwang 	{ "delayedFrames",	&ng_parse_uint32_type	},		\
97*3b2bd0f6Slogwang 	{ NULL },							\
98*3b2bd0f6Slogwang }
99*3b2bd0f6Slogwang 
100*3b2bd0f6Slogwang /* Runtime structure returned by NGM_PIPE_GET_RUN */
101*3b2bd0f6Slogwang struct ng_pipe_run {
102*3b2bd0f6Slogwang 	struct ng_pipe_hookrun	downstream;
103*3b2bd0f6Slogwang 	struct ng_pipe_hookrun	upstream;
104*3b2bd0f6Slogwang };
105*3b2bd0f6Slogwang 
106*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
107*3b2bd0f6Slogwang #define NG_PIPE_RUN_INFO(hstype)	{				\
108*3b2bd0f6Slogwang 	{ "downstream",		(hstype) },				\
109*3b2bd0f6Slogwang 	{ "upstream",		(hstype) },				\
110*3b2bd0f6Slogwang 	{ NULL },							\
111*3b2bd0f6Slogwang }
112*3b2bd0f6Slogwang 
113*3b2bd0f6Slogwang /* Config structure for one hook */
114*3b2bd0f6Slogwang struct ng_pipe_hookcfg {
115*3b2bd0f6Slogwang 	u_int64_t		bandwidth;
116*3b2bd0f6Slogwang 	u_int64_t		ber;
117*3b2bd0f6Slogwang 	u_int32_t		qin_size_limit;
118*3b2bd0f6Slogwang 	u_int32_t		qout_size_limit;
119*3b2bd0f6Slogwang 	u_int32_t		duplicate;
120*3b2bd0f6Slogwang 	u_int32_t		fifo;
121*3b2bd0f6Slogwang 	u_int32_t		drr;
122*3b2bd0f6Slogwang 	u_int32_t		wfq;
123*3b2bd0f6Slogwang 	u_int32_t		droptail;
124*3b2bd0f6Slogwang 	u_int32_t		drophead;
125*3b2bd0f6Slogwang };
126*3b2bd0f6Slogwang 
127*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
128*3b2bd0f6Slogwang #define NG_PIPE_HOOKCFG_INFO	{					\
129*3b2bd0f6Slogwang 	{ "bandwidth",		&ng_parse_uint64_type	},		\
130*3b2bd0f6Slogwang 	{ "BER",		&ng_parse_uint64_type	},		\
131*3b2bd0f6Slogwang 	{ "queuelen",		&ng_parse_uint32_type	},		\
132*3b2bd0f6Slogwang 	{ "delaylen",		&ng_parse_uint32_type	},		\
133*3b2bd0f6Slogwang 	{ "duplicate",		&ng_parse_uint32_type	},		\
134*3b2bd0f6Slogwang 	{ "fifo",		&ng_parse_uint32_type	},		\
135*3b2bd0f6Slogwang 	{ "drr",		&ng_parse_uint32_type	},		\
136*3b2bd0f6Slogwang 	{ "wfq",		&ng_parse_uint32_type	},		\
137*3b2bd0f6Slogwang 	{ "droptail",		&ng_parse_uint32_type	},		\
138*3b2bd0f6Slogwang 	{ "drophead",		&ng_parse_uint32_type	},		\
139*3b2bd0f6Slogwang 	{ NULL },							\
140*3b2bd0f6Slogwang }
141*3b2bd0f6Slogwang 
142*3b2bd0f6Slogwang /* Config structure returned by NGM_PIPE_GET_CFG */
143*3b2bd0f6Slogwang struct ng_pipe_cfg {
144*3b2bd0f6Slogwang 	u_int64_t		bandwidth;
145*3b2bd0f6Slogwang 	u_int64_t		delay;
146*3b2bd0f6Slogwang 	u_int32_t		header_offset;
147*3b2bd0f6Slogwang 	u_int32_t		overhead;
148*3b2bd0f6Slogwang 	struct ng_pipe_hookcfg	downstream;
149*3b2bd0f6Slogwang 	struct ng_pipe_hookcfg	upstream;
150*3b2bd0f6Slogwang };
151*3b2bd0f6Slogwang 
152*3b2bd0f6Slogwang /* Keep this in sync with the above structure definition */
153*3b2bd0f6Slogwang #define NG_PIPE_CFG_INFO(hstype)	{				\
154*3b2bd0f6Slogwang 	{ "bandwidth",		&ng_parse_uint64_type	},		\
155*3b2bd0f6Slogwang 	{ "delay",		&ng_parse_uint64_type	},		\
156*3b2bd0f6Slogwang 	{ "header_offset",	&ng_parse_uint32_type	},		\
157*3b2bd0f6Slogwang 	{ "overhead",		&ng_parse_uint32_type	},		\
158*3b2bd0f6Slogwang 	{ "downstream",		(hstype)		},		\
159*3b2bd0f6Slogwang 	{ "upstream",		(hstype)		},		\
160*3b2bd0f6Slogwang 	{ NULL },							\
161*3b2bd0f6Slogwang }
162*3b2bd0f6Slogwang 
163*3b2bd0f6Slogwang /* Netgraph commands */
164*3b2bd0f6Slogwang enum {
165*3b2bd0f6Slogwang 	NGM_PIPE_GET_STATS=1,		/* get stats */
166*3b2bd0f6Slogwang 	NGM_PIPE_CLR_STATS,		/* clear stats */
167*3b2bd0f6Slogwang 	NGM_PIPE_GETCLR_STATS,		/* atomically get and clear stats */
168*3b2bd0f6Slogwang 	NGM_PIPE_GET_RUN,		/* get current runtime status */
169*3b2bd0f6Slogwang 	NGM_PIPE_GET_CFG,		/* get configurable parameters */
170*3b2bd0f6Slogwang 	NGM_PIPE_SET_CFG,		/* set configurable parameters */
171*3b2bd0f6Slogwang };
172*3b2bd0f6Slogwang 
173*3b2bd0f6Slogwang #endif /* _NETGRAPH_PIPE_H_ */
174