examples/ip_pipeline: rework config file syntax
[dpdk.git] / examples / ip_pipeline / pipeline_be.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef __INCLUDE_PIPELINE_BE_H__
35 #define __INCLUDE_PIPELINE_BE_H__
36
37 #include <rte_port_ethdev.h>
38 #include <rte_port_ring.h>
39 #include <rte_port_frag.h>
40 #include <rte_port_ras.h>
41 #include <rte_port_sched.h>
42 #include <rte_port_source_sink.h>
43 #include <rte_pipeline.h>
44
45 enum pipeline_port_in_type {
46         PIPELINE_PORT_IN_ETHDEV_READER,
47         PIPELINE_PORT_IN_RING_READER,
48         PIPELINE_PORT_IN_RING_READER_IPV4_FRAG,
49         PIPELINE_PORT_IN_RING_READER_IPV6_FRAG,
50         PIPELINE_PORT_IN_SCHED_READER,
51         PIPELINE_PORT_IN_SOURCE,
52 };
53
54 struct pipeline_port_in_params {
55         enum pipeline_port_in_type type;
56         union {
57                 struct rte_port_ethdev_reader_params ethdev;
58                 struct rte_port_ring_reader_params ring;
59                 struct rte_port_ring_reader_ipv4_frag_params ring_ipv4_frag;
60                 struct rte_port_ring_reader_ipv6_frag_params ring_ipv6_frag;
61                 struct rte_port_sched_reader_params sched;
62                 struct rte_port_source_params source;
63         } params;
64         uint32_t burst_size;
65 };
66
67 static inline void *
68 pipeline_port_in_params_convert(struct pipeline_port_in_params  *p)
69 {
70         switch (p->type) {
71         case PIPELINE_PORT_IN_ETHDEV_READER:
72                 return (void *) &p->params.ethdev;
73         case PIPELINE_PORT_IN_RING_READER:
74                 return (void *) &p->params.ring;
75         case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
76                 return (void *) &p->params.ring_ipv4_frag;
77         case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
78                 return (void *) &p->params.ring_ipv6_frag;
79         case PIPELINE_PORT_IN_SCHED_READER:
80                 return (void *) &p->params.sched;
81         case PIPELINE_PORT_IN_SOURCE:
82                 return (void *) &p->params.source;
83         default:
84                 return NULL;
85         }
86 }
87
88 static inline struct rte_port_in_ops *
89 pipeline_port_in_params_get_ops(struct pipeline_port_in_params  *p)
90 {
91         switch (p->type) {
92         case PIPELINE_PORT_IN_ETHDEV_READER:
93                 return &rte_port_ethdev_reader_ops;
94         case PIPELINE_PORT_IN_RING_READER:
95                 return &rte_port_ring_reader_ops;
96         case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
97                 return &rte_port_ring_reader_ipv4_frag_ops;
98         case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
99                 return &rte_port_ring_reader_ipv6_frag_ops;
100         case PIPELINE_PORT_IN_SCHED_READER:
101                 return &rte_port_sched_reader_ops;
102         case PIPELINE_PORT_IN_SOURCE:
103                 return &rte_port_source_ops;
104         default:
105                 return NULL;
106         }
107 }
108
109 enum pipeline_port_out_type {
110         PIPELINE_PORT_OUT_ETHDEV_WRITER,
111         PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP,
112         PIPELINE_PORT_OUT_RING_WRITER,
113         PIPELINE_PORT_OUT_RING_WRITER_NODROP,
114         PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS,
115         PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS,
116         PIPELINE_PORT_OUT_SCHED_WRITER,
117         PIPELINE_PORT_OUT_SINK,
118 };
119
120 struct pipeline_port_out_params {
121         enum pipeline_port_out_type type;
122         union {
123                 struct rte_port_ethdev_writer_params ethdev;
124                 struct rte_port_ethdev_writer_nodrop_params ethdev_nodrop;
125                 struct rte_port_ring_writer_params ring;
126                 struct rte_port_ring_writer_nodrop_params ring_nodrop;
127                 struct rte_port_ring_writer_ipv4_ras_params ring_ipv4_ras;
128                 struct rte_port_ring_writer_ipv6_ras_params ring_ipv6_ras;
129                 struct rte_port_sched_writer_params sched;
130         } params;
131 };
132
133 static inline void *
134 pipeline_port_out_params_convert(struct pipeline_port_out_params  *p)
135 {
136         switch (p->type) {
137         case PIPELINE_PORT_OUT_ETHDEV_WRITER:
138                 return (void *) &p->params.ethdev;
139         case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
140                 return (void *) &p->params.ethdev_nodrop;
141         case PIPELINE_PORT_OUT_RING_WRITER:
142                 return (void *) &p->params.ring;
143         case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
144                 return (void *) &p->params.ring_nodrop;
145         case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
146                 return (void *) &p->params.ring_ipv4_ras;
147         case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
148                 return (void *) &p->params.ring_ipv6_ras;
149         case PIPELINE_PORT_OUT_SCHED_WRITER:
150                 return (void *) &p->params.sched;
151         case PIPELINE_PORT_OUT_SINK:
152         default:
153                 return NULL;
154         }
155 }
156
157 static inline void *
158 pipeline_port_out_params_get_ops(struct pipeline_port_out_params  *p)
159 {
160         switch (p->type) {
161         case PIPELINE_PORT_OUT_ETHDEV_WRITER:
162                 return &rte_port_ethdev_writer_ops;
163         case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
164                 return &rte_port_ethdev_writer_nodrop_ops;
165         case PIPELINE_PORT_OUT_RING_WRITER:
166                 return &rte_port_ring_writer_ops;
167         case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
168                 return &rte_port_ring_writer_nodrop_ops;
169         case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
170                 return &rte_port_ring_writer_ipv4_ras_ops;
171         case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
172                 return &rte_port_ring_writer_ipv6_ras_ops;
173         case PIPELINE_PORT_OUT_SCHED_WRITER:
174                 return &rte_port_sched_writer_ops;
175         case PIPELINE_PORT_OUT_SINK:
176                 return &rte_port_sink_ops;
177         default:
178                 return NULL;
179         }
180 }
181
182 #ifndef PIPELINE_NAME_SIZE
183 #define PIPELINE_NAME_SIZE                       32
184 #endif
185
186 #ifndef PIPELINE_MAX_PORT_IN
187 #define PIPELINE_MAX_PORT_IN                     16
188 #endif
189
190 #ifndef PIPELINE_MAX_PORT_OUT
191 #define PIPELINE_MAX_PORT_OUT                    16
192 #endif
193
194 #ifndef PIPELINE_MAX_TABLES
195 #define PIPELINE_MAX_TABLES                      16
196 #endif
197
198 #ifndef PIPELINE_MAX_MSGQ_IN
199 #define PIPELINE_MAX_MSGQ_IN                     16
200 #endif
201
202 #ifndef PIPELINE_MAX_MSGQ_OUT
203 #define PIPELINE_MAX_MSGQ_OUT                    16
204 #endif
205
206 #ifndef PIPELINE_MAX_ARGS
207 #define PIPELINE_MAX_ARGS                        32
208 #endif
209
210 struct pipeline_params {
211         char name[PIPELINE_NAME_SIZE];
212
213         struct pipeline_port_in_params port_in[PIPELINE_MAX_PORT_IN];
214         struct pipeline_port_out_params port_out[PIPELINE_MAX_PORT_OUT];
215         struct rte_ring *msgq_in[PIPELINE_MAX_MSGQ_IN];
216         struct rte_ring *msgq_out[PIPELINE_MAX_MSGQ_OUT];
217
218         uint32_t n_ports_in;
219         uint32_t n_ports_out;
220         uint32_t n_msgq;
221
222         int socket_id;
223
224         char *args_name[PIPELINE_MAX_ARGS];
225         char *args_value[PIPELINE_MAX_ARGS];
226         uint32_t n_args;
227
228         uint32_t log_level;
229 };
230
231 /*
232  * Pipeline type back-end operations
233  */
234
235 typedef void* (*pipeline_be_op_init)(struct pipeline_params *params,
236         void *arg);
237
238 typedef int (*pipeline_be_op_free)(void *pipeline);
239
240 typedef int (*pipeline_be_op_run)(void *pipeline);
241
242 typedef int (*pipeline_be_op_timer)(void *pipeline);
243
244 typedef int (*pipeline_be_op_track)(void *pipeline,
245         uint32_t port_in,
246         uint32_t *port_out);
247
248 struct pipeline_be_ops {
249         pipeline_be_op_init f_init;
250         pipeline_be_op_free f_free;
251         pipeline_be_op_run f_run;
252         pipeline_be_op_timer f_timer;
253         pipeline_be_op_track f_track;
254 };
255
256 #endif