Fix warning when compiling with ninja
[samplevnf.git] / common / vnf_common / pipeline_be.h
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef __INCLUDE_PIPELINE_BE_H__
18 #define __INCLUDE_PIPELINE_BE_H__
19
20 #include <rte_port_ethdev.h>
21 #include <rte_port_ring.h>
22 #include <rte_port_frag.h>
23 #include <rte_port_ras.h>
24 #include <rte_port_sched.h>
25 #include <rte_port_source_sink.h>
26 #include <rte_pipeline.h>
27
28 enum pipeline_port_in_type {
29         PIPELINE_PORT_IN_ETHDEV_READER,
30         PIPELINE_PORT_IN_RING_READER,
31         PIPELINE_PORT_IN_RING_MULTI_READER,
32         PIPELINE_PORT_IN_RING_READER_IPV4_FRAG,
33         PIPELINE_PORT_IN_RING_READER_IPV6_FRAG,
34         PIPELINE_PORT_IN_SCHED_READER,
35         PIPELINE_PORT_IN_SOURCE,
36 };
37
38 struct pipeline_port_in_params {
39         enum pipeline_port_in_type type;
40         union {
41                 struct rte_port_ethdev_reader_params ethdev;
42                 struct rte_port_ring_reader_params ring;
43                 struct rte_port_ring_multi_reader_params ring_multi;
44                 struct rte_port_ring_reader_ipv4_frag_params ring_ipv4_frag;
45                 struct rte_port_ring_reader_ipv6_frag_params ring_ipv6_frag;
46                 struct rte_port_sched_reader_params sched;
47                 struct rte_port_source_params source;
48         } params;
49         uint32_t burst_size;
50 };
51
52 static inline void *
53 pipeline_port_in_params_convert(struct pipeline_port_in_params  *p)
54 {
55         switch (p->type) {
56         case PIPELINE_PORT_IN_ETHDEV_READER:
57                 return (void *) &p->params.ethdev;
58         case PIPELINE_PORT_IN_RING_READER:
59                 return (void *) &p->params.ring;
60         case PIPELINE_PORT_IN_RING_MULTI_READER:
61                 return (void *) &p->params.ring_multi;
62         case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
63                 return (void *) &p->params.ring_ipv4_frag;
64         case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
65                 return (void *) &p->params.ring_ipv6_frag;
66         case PIPELINE_PORT_IN_SCHED_READER:
67                 return (void *) &p->params.sched;
68         case PIPELINE_PORT_IN_SOURCE:
69                 return (void *) &p->params.source;
70         default:
71                 return NULL;
72         }
73 }
74
75 static inline struct rte_port_in_ops *
76 pipeline_port_in_params_get_ops(struct pipeline_port_in_params  *p)
77 {
78         switch (p->type) {
79         case PIPELINE_PORT_IN_ETHDEV_READER:
80                 return &rte_port_ethdev_reader_ops;
81         case PIPELINE_PORT_IN_RING_READER:
82                 return &rte_port_ring_reader_ops;
83         case PIPELINE_PORT_IN_RING_MULTI_READER:
84                 return &rte_port_ring_multi_reader_ops;
85         case PIPELINE_PORT_IN_RING_READER_IPV4_FRAG:
86                 return &rte_port_ring_reader_ipv4_frag_ops;
87         case PIPELINE_PORT_IN_RING_READER_IPV6_FRAG:
88                 return &rte_port_ring_reader_ipv6_frag_ops;
89         case PIPELINE_PORT_IN_SCHED_READER:
90                 return &rte_port_sched_reader_ops;
91         case PIPELINE_PORT_IN_SOURCE:
92                 return &rte_port_source_ops;
93         default:
94                 return NULL;
95         }
96 }
97
98 enum pipeline_port_out_type {
99         PIPELINE_PORT_OUT_ETHDEV_WRITER,
100         PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP,
101         PIPELINE_PORT_OUT_RING_WRITER,
102         PIPELINE_PORT_OUT_RING_MULTI_WRITER,
103         PIPELINE_PORT_OUT_RING_WRITER_NODROP,
104         PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP,
105         PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS,
106         PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS,
107         PIPELINE_PORT_OUT_SCHED_WRITER,
108         PIPELINE_PORT_OUT_SINK,
109 };
110
111 struct pipeline_port_out_params {
112         enum pipeline_port_out_type type;
113         union {
114                 struct rte_port_ethdev_writer_params ethdev;
115                 struct rte_port_ethdev_writer_nodrop_params ethdev_nodrop;
116                 struct rte_port_ring_writer_params ring;
117                 struct rte_port_ring_multi_writer_params ring_multi;
118                 struct rte_port_ring_writer_nodrop_params ring_nodrop;
119                 struct rte_port_ring_multi_writer_nodrop_params ring_multi_nodrop;
120                 struct rte_port_ring_writer_ipv4_ras_params ring_ipv4_ras;
121                 struct rte_port_ring_writer_ipv6_ras_params ring_ipv6_ras;
122                 struct rte_port_sched_writer_params sched;
123                 struct rte_port_sink_params sink;
124         } params;
125 };
126
127 static inline void *
128 pipeline_port_out_params_convert(struct pipeline_port_out_params  *p)
129 {
130         switch (p->type) {
131         case PIPELINE_PORT_OUT_ETHDEV_WRITER:
132                 return (void *) &p->params.ethdev;
133         case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
134                 return (void *) &p->params.ethdev_nodrop;
135         case PIPELINE_PORT_OUT_RING_WRITER:
136                 return (void *) &p->params.ring;
137         case PIPELINE_PORT_OUT_RING_MULTI_WRITER:
138                 return (void *) &p->params.ring_multi;
139         case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
140                 return (void *) &p->params.ring_nodrop;
141         case PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP:
142                 return (void *) &p->params.ring_multi_nodrop;
143         case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
144                 return (void *) &p->params.ring_ipv4_ras;
145         case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
146                 return (void *) &p->params.ring_ipv6_ras;
147         case PIPELINE_PORT_OUT_SCHED_WRITER:
148                 return (void *) &p->params.sched;
149         case PIPELINE_PORT_OUT_SINK:
150                 return (void *) &p->params.sink;
151         default:
152                 return NULL;
153         }
154 }
155
156 static inline void *
157 pipeline_port_out_params_get_ops(struct pipeline_port_out_params  *p)
158 {
159         switch (p->type) {
160         case PIPELINE_PORT_OUT_ETHDEV_WRITER:
161                 return &rte_port_ethdev_writer_ops;
162         case PIPELINE_PORT_OUT_ETHDEV_WRITER_NODROP:
163                 return &rte_port_ethdev_writer_nodrop_ops;
164         case PIPELINE_PORT_OUT_RING_WRITER:
165                 return &rte_port_ring_writer_ops;
166         case PIPELINE_PORT_OUT_RING_MULTI_WRITER:
167                 return &rte_port_ring_multi_writer_ops;
168         case PIPELINE_PORT_OUT_RING_WRITER_NODROP:
169                 return &rte_port_ring_writer_nodrop_ops;
170         case PIPELINE_PORT_OUT_RING_MULTI_WRITER_NODROP:
171                 return &rte_port_ring_multi_writer_nodrop_ops;
172         case PIPELINE_PORT_OUT_RING_WRITER_IPV4_RAS:
173                 return &rte_port_ring_writer_ipv4_ras_ops;
174         case PIPELINE_PORT_OUT_RING_WRITER_IPV6_RAS:
175                 return &rte_port_ring_writer_ipv6_ras_ops;
176         case PIPELINE_PORT_OUT_SCHED_WRITER:
177                 return &rte_port_sched_writer_ops;
178         case PIPELINE_PORT_OUT_SINK:
179                 return &rte_port_sink_ops;
180         default:
181                 return NULL;
182         }
183 }
184
185 #ifndef PIPELINE_NAME_SIZE
186 #define PIPELINE_NAME_SIZE                       64
187 #endif
188
189 #ifndef PIPELINE_MAX_PORT_IN
190 #define PIPELINE_MAX_PORT_IN                     64
191 #endif
192
193 #ifndef PIPELINE_MAX_PORT_OUT
194 #define PIPELINE_MAX_PORT_OUT                    64
195 #endif
196
197 #ifndef PIPELINE_MAX_TABLES
198 #define PIPELINE_MAX_TABLES                      64
199 #endif
200
201 #ifndef PIPELINE_MAX_MSGQ_IN
202 #define PIPELINE_MAX_MSGQ_IN                     64
203 #endif
204
205 #ifndef PIPELINE_MAX_MSGQ_OUT
206 #define PIPELINE_MAX_MSGQ_OUT                    64
207 #endif
208
209 #ifndef PIPELINE_MAX_ARGS
210 #define PIPELINE_MAX_ARGS                        64
211 #endif
212
213 struct pipeline_params {
214         char name[PIPELINE_NAME_SIZE];
215
216         struct pipeline_port_in_params port_in[PIPELINE_MAX_PORT_IN];
217         struct pipeline_port_out_params port_out[PIPELINE_MAX_PORT_OUT];
218         struct rte_ring *msgq_in[PIPELINE_MAX_MSGQ_IN];
219         struct rte_ring *msgq_out[PIPELINE_MAX_MSGQ_OUT];
220
221         uint32_t n_ports_in;
222         uint32_t n_ports_out;
223         uint32_t n_msgq;
224
225         int socket_id;
226
227         char *args_name[PIPELINE_MAX_ARGS];
228         char *args_value[PIPELINE_MAX_ARGS];
229         uint32_t n_args;
230
231         uint32_t log_level;
232 };
233
234 /*
235  * Pipeline type back-end operations
236  */
237
238 typedef void* (*pipeline_be_op_init)(struct pipeline_params *params,
239         void *arg);
240
241 typedef int (*pipeline_be_op_free)(void *pipeline);
242
243 typedef int (*pipeline_be_op_run)(void *pipeline);
244
245 typedef int (*pipeline_be_op_timer)(void *pipeline);
246
247 typedef int (*pipeline_be_op_track)(void *pipeline,
248         uint32_t port_in,
249         uint32_t *port_out);
250
251 struct pipeline_be_ops {
252         pipeline_be_op_init f_init;
253         pipeline_be_op_free f_free;
254         pipeline_be_op_run f_run;
255         pipeline_be_op_timer f_timer;
256         pipeline_be_op_track f_track;
257 };
258
259 /* Pipeline specific config parse error messages */
260 #define PIPELINE_ARG_CHECK(exp, fmt, ...)                               \
261 do {                                                                    \
262         if (!(exp)) {                                                   \
263                 fprintf(stderr, fmt "\n", ## __VA_ARGS__);              \
264                 return -1;                                              \
265         }                                                               \
266 } while (0)
267
268 #define PIPELINE_PARSE_ERR_INV_VAL(exp, section, entry, val)            \
269 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": entry \"%s\" "  \
270         "has invalid value (\"%s\")", section, entry, val)
271
272 #define PIPELINE_PARSE_ERR_OUT_RNG(exp, section, entry, val)            \
273 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": entry \"%s\" "  \
274         "value is out of range (\"%s\")", section, entry, val)
275
276 #define PIPELINE_PARSE_ERR_DUPLICATE(exp, section, entry)               \
277 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": duplicated "    \
278         "entry \"%s\"", section, entry)
279
280 #define PIPELINE_PARSE_ERR_INV_ENT(exp, section, entry)                 \
281 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": invalid entry " \
282         "\"%s\"", section, entry)
283
284 #define PIPELINE_PARSE_ERR_MANDATORY(exp, section, entry)               \
285 PIPELINE_ARG_CHECK(exp, "Parse error in section \"%s\": mandatory "     \
286         "entry \"%s\" is missing", section, entry)
287
288 #endif