1206360Sjoel/*-
2182734Sjulian * Copyright (c) 2004-2008 University of Zagreb
3182734Sjulian * Copyright (c) 2007-2008 FreeBSD Foundation
4182734Sjulian *
5182734Sjulian * This software was developed by the University of Zagreb and the
6182734Sjulian * FreeBSD Foundation under sponsorship by the Stichting NLnet and the
7182734Sjulian * FreeBSD Foundation.
8182734Sjulian *
9182734Sjulian * Redistribution and use in source and binary forms, with or without
10182734Sjulian * modification, are permitted provided that the following conditions
11182734Sjulian * are met:
12182734Sjulian * 1. Redistributions of source code must retain the above copyright
13182734Sjulian *    notice, this list of conditions and the following disclaimer.
14182734Sjulian * 2. Redistributions in binary form must reproduce the above copyright
15182734Sjulian *    notice, this list of conditions and the following disclaimer in the
16182734Sjulian *    documentation and/or other materials provided with the distribution.
17182734Sjulian *
18182734Sjulian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19182734Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20182734Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21182734Sjulian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22182734Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23182734Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24182734Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25182734Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26182734Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27182734Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28182734Sjulian * SUCH DAMAGE.
29182734Sjulian *
30182734Sjulian * $FreeBSD$
31182734Sjulian */
32182734Sjulian
33182734Sjulian#ifndef _NETGRAPH_PIPE_H_
34182734Sjulian#define _NETGRAPH_PIPE_H_
35182734Sjulian
36182734Sjulian/* Node type name and magic cookie */
37182734Sjulian#define NG_PIPE_NODE_TYPE	"pipe"
38182734Sjulian#define NGM_PIPE_COOKIE		200708191
39182734Sjulian
40182734Sjulian/* Hook names */
41182734Sjulian#define NG_PIPE_HOOK_UPPER	"upper"
42182734Sjulian#define NG_PIPE_HOOK_LOWER	"lower"
43182734Sjulian
44182734Sjulian#define MAX_FSIZE 16384	/* Largest supported frame size, in bytes, for BER */
45182734Sjulian#define MAX_OHSIZE 256	/* Largest supported dummy-framing size, in bytes */
46182734Sjulian
47182734Sjulian/* Statistics structure for one hook */
48182734Sjulianstruct ng_pipe_hookstat {
49182734Sjulian	u_int64_t		fwd_octets;
50182734Sjulian	u_int64_t		fwd_frames;
51182734Sjulian	u_int64_t		in_disc_octets;
52182734Sjulian	u_int64_t		in_disc_frames;
53182734Sjulian	u_int64_t		out_disc_octets;
54182734Sjulian	u_int64_t		out_disc_frames;
55182734Sjulian};
56182734Sjulian
57182734Sjulian/* Keep this in sync with the above structure definition */
58182734Sjulian#define NG_PIPE_HOOKSTAT_INFO	{					\
59182734Sjulian	{ "FwdOctets",		&ng_parse_uint64_type	},		\
60182734Sjulian	{ "FwdFrames",		&ng_parse_uint64_type	},		\
61182734Sjulian	{ "queueDropOctets",	&ng_parse_uint64_type	},		\
62182734Sjulian	{ "queueDropFrames",	&ng_parse_uint64_type	},		\
63182734Sjulian	{ "delayDropOctets",	&ng_parse_uint64_type	},		\
64182734Sjulian	{ "delayDropFrames",	&ng_parse_uint64_type	},		\
65182734Sjulian	{ NULL },							\
66182734Sjulian}
67182734Sjulian
68182734Sjulian/* Statistics structure returned by NGM_PIPE_GET_STATS */
69182734Sjulianstruct ng_pipe_stats {
70182734Sjulian	struct ng_pipe_hookstat	downstream;
71182734Sjulian	struct ng_pipe_hookstat	upstream;
72182734Sjulian};
73182734Sjulian
74182734Sjulian/* Keep this in sync with the above structure definition */
75182734Sjulian#define NG_PIPE_STATS_INFO(hstype)	{				\
76182734Sjulian	{ "downstream",		(hstype) },				\
77182734Sjulian	{ "upstream",		(hstype) },				\
78182734Sjulian	{ NULL },							\
79182734Sjulian}
80182734Sjulian
81182734Sjulian/* Runtime structure for one hook */
82182734Sjulianstruct ng_pipe_hookrun {
83182734Sjulian	u_int32_t		fifo_queues;
84182734Sjulian	u_int32_t		qin_octets;
85182734Sjulian	u_int32_t		qin_frames;
86182734Sjulian	u_int32_t		qout_octets;
87182734Sjulian	u_int32_t		qout_frames;
88182734Sjulian};
89182734Sjulian
90182734Sjulian/* Keep this in sync with the above structure definition */
91182734Sjulian#define NG_PIPE_HOOKRUN_INFO	{					\
92182734Sjulian	{ "queues",		&ng_parse_uint32_type	},		\
93182734Sjulian	{ "queuedOctets",	&ng_parse_uint32_type	},		\
94182734Sjulian	{ "queuedFrames",	&ng_parse_uint32_type	},		\
95182734Sjulian	{ "delayedOctets",	&ng_parse_uint32_type	},		\
96182734Sjulian	{ "delayedFrames",	&ng_parse_uint32_type	},		\
97182734Sjulian	{ NULL },							\
98182734Sjulian}
99182734Sjulian
100182734Sjulian/* Runtime structure returned by NGM_PIPE_GET_RUN */
101182734Sjulianstruct ng_pipe_run {
102182734Sjulian	struct ng_pipe_hookrun	downstream;
103182734Sjulian	struct ng_pipe_hookrun	upstream;
104182734Sjulian};
105182734Sjulian
106182734Sjulian/* Keep this in sync with the above structure definition */
107182734Sjulian#define NG_PIPE_RUN_INFO(hstype)	{				\
108182734Sjulian	{ "downstream",		(hstype) },				\
109182734Sjulian	{ "upstream",		(hstype) },				\
110182734Sjulian	{ NULL },							\
111182734Sjulian}
112182734Sjulian
113182734Sjulian/* Config structure for one hook */
114182734Sjulianstruct ng_pipe_hookcfg {
115182734Sjulian	u_int64_t		bandwidth;
116182734Sjulian	u_int64_t		ber;
117182734Sjulian	u_int32_t		qin_size_limit;
118182734Sjulian	u_int32_t		qout_size_limit;
119182734Sjulian	u_int32_t		duplicate;
120182734Sjulian	u_int32_t		fifo;
121182734Sjulian	u_int32_t		drr;
122182734Sjulian	u_int32_t		wfq;
123182734Sjulian	u_int32_t		droptail;
124182734Sjulian	u_int32_t		drophead;
125182734Sjulian};
126182734Sjulian
127182734Sjulian/* Keep this in sync with the above structure definition */
128182734Sjulian#define NG_PIPE_HOOKCFG_INFO	{					\
129182734Sjulian	{ "bandwidth",		&ng_parse_uint64_type	},		\
130182734Sjulian	{ "BER",		&ng_parse_uint64_type	},		\
131182734Sjulian	{ "queuelen",		&ng_parse_uint32_type	},		\
132182734Sjulian	{ "delaylen",		&ng_parse_uint32_type	},		\
133182734Sjulian	{ "duplicate",		&ng_parse_uint32_type	},		\
134182734Sjulian	{ "fifo",		&ng_parse_uint32_type	},		\
135182734Sjulian	{ "drr",		&ng_parse_uint32_type	},		\
136182734Sjulian	{ "wfq",		&ng_parse_uint32_type	},		\
137182734Sjulian	{ "droptail",		&ng_parse_uint32_type	},		\
138182734Sjulian	{ "drophead",		&ng_parse_uint32_type	},		\
139182734Sjulian	{ NULL },							\
140182734Sjulian}
141182734Sjulian
142182734Sjulian/* Config structure returned by NGM_PIPE_GET_CFG */
143182734Sjulianstruct ng_pipe_cfg {
144182734Sjulian	u_int64_t		bandwidth;
145182734Sjulian	u_int64_t		delay;
146182734Sjulian	u_int32_t		header_offset;
147182734Sjulian	u_int32_t		overhead;
148182734Sjulian	struct ng_pipe_hookcfg	downstream;
149182734Sjulian	struct ng_pipe_hookcfg	upstream;
150182734Sjulian};
151182734Sjulian
152182734Sjulian/* Keep this in sync with the above structure definition */
153182734Sjulian#define NG_PIPE_CFG_INFO(hstype)	{				\
154182734Sjulian	{ "bandwidth",		&ng_parse_uint64_type	},		\
155182734Sjulian	{ "delay",		&ng_parse_uint64_type	},		\
156182734Sjulian	{ "header_offset",	&ng_parse_uint32_type	},		\
157182734Sjulian	{ "overhead",		&ng_parse_uint32_type	},		\
158182734Sjulian	{ "downstream",		(hstype)		},		\
159182734Sjulian	{ "upstream",		(hstype)		},		\
160182734Sjulian	{ NULL },							\
161182734Sjulian}
162182734Sjulian
163182734Sjulian/* Netgraph commands */
164182734Sjulianenum {
165182734Sjulian	NGM_PIPE_GET_STATS=1,		/* get stats */
166182734Sjulian	NGM_PIPE_CLR_STATS,		/* clear stats */
167182734Sjulian	NGM_PIPE_GETCLR_STATS,		/* atomically get and clear stats */
168182734Sjulian	NGM_PIPE_GET_RUN,		/* get current runtime status */
169182734Sjulian	NGM_PIPE_GET_CFG,		/* get configurable parameters */
170182734Sjulian	NGM_PIPE_SET_CFG,		/* set configurable parameters */
171182734Sjulian};
172182734Sjulian
173182734Sjulian#endif /* _NETGRAPH_PIPE_H_ */
174