examples/ip_pipeline: add more ports
[dpdk.git] / examples / ip_pipeline / config_check.c
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 #include <stdio.h>
35
36 #include <rte_ip.h>
37
38 #include "app.h"
39
40 static void
41 check_mempools(struct app_params *app)
42 {
43         uint32_t i;
44
45         for (i = 0; i < app->n_mempools; i++) {
46                 struct app_mempool_params *p = &app->mempool_params[i];
47
48                 APP_CHECK((p->pool_size > 0),
49                         "Mempool %s size is 0\n", p->name);
50
51                 APP_CHECK((p->cache_size > 0),
52                         "Mempool %s cache size is 0\n", p->name);
53
54                 APP_CHECK(rte_is_power_of_2(p->cache_size),
55                         "Mempool %s cache size not a power of 2\n", p->name);
56         }
57 }
58
59 static void
60 check_links(struct app_params *app)
61 {
62         uint32_t n_links_port_mask = __builtin_popcountll(app->port_mask);
63         uint32_t i;
64
65         /* Check that number of links matches the port mask */
66         APP_CHECK((app->n_links == n_links_port_mask),
67                 "Not enough links provided in the PORT_MASK\n");
68
69         for (i = 0; i < app->n_links; i++) {
70                 struct app_link_params *link = &app->link_params[i];
71                 uint32_t rxq_max, n_rxq, n_txq, link_id, i;
72
73                 APP_PARAM_GET_ID(link, "LINK", link_id);
74
75                 /* Check that link RXQs are contiguous */
76                 rxq_max = 0;
77                 if (link->arp_q > rxq_max)
78                         rxq_max = link->arp_q;
79                 if (link->tcp_syn_local_q > rxq_max)
80                         rxq_max = link->tcp_syn_local_q;
81                 if (link->ip_local_q > rxq_max)
82                         rxq_max = link->ip_local_q;
83                 if (link->tcp_local_q > rxq_max)
84                         rxq_max = link->tcp_local_q;
85                 if (link->udp_local_q > rxq_max)
86                         rxq_max = link->udp_local_q;
87                 if (link->sctp_local_q > rxq_max)
88                         rxq_max = link->sctp_local_q;
89
90                 for (i = 1; i <= rxq_max; i++)
91                         APP_CHECK(((link->arp_q == i) ||
92                                 (link->tcp_syn_local_q == i) ||
93                                 (link->ip_local_q == i) ||
94                                 (link->tcp_local_q == i) ||
95                                 (link->udp_local_q == i) ||
96                                 (link->sctp_local_q == i)),
97                                 "%s RXQs are not contiguous (A)\n", link->name);
98
99                 n_rxq = app_link_get_n_rxq(app, link);
100
101                 APP_CHECK((n_rxq == rxq_max + 1),
102                         "%s RXQs are not contiguous (B)\n", link->name);
103
104                 for (i = 0; i < n_rxq; i++) {
105                         char name[APP_PARAM_NAME_SIZE];
106                         int pos;
107
108                         sprintf(name, "RXQ%" PRIu32 ".%" PRIu32,
109                                 link_id, i);
110                         pos = APP_PARAM_FIND(app->hwq_in_params, name);
111                         APP_CHECK((pos >= 0),
112                                 "%s RXQs are not contiguous (C)\n", link->name);
113                 }
114
115                 /* Check that link RXQs are contiguous */
116                 n_txq = app_link_get_n_txq(app, link);
117
118                 for (i = 0; i < n_txq; i++) {
119                         char name[APP_PARAM_NAME_SIZE];
120                         int pos;
121
122                         sprintf(name, "TXQ%" PRIu32 ".%" PRIu32,
123                                 link_id, i);
124                         pos = APP_PARAM_FIND(app->hwq_out_params, name);
125                         APP_CHECK((pos >= 0),
126                                 "%s TXQs are not contiguous\n", link->name);
127                 }
128         }
129 }
130
131 static void
132 check_rxqs(struct app_params *app)
133 {
134         uint32_t i;
135
136         for (i = 0; i < app->n_pktq_hwq_in; i++) {
137                 struct app_pktq_hwq_in_params *p = &app->hwq_in_params[i];
138                 uint32_t n_readers = app_rxq_get_readers(app, p);
139
140                 APP_CHECK((p->size > 0),
141                         "%s size is 0\n", p->name);
142
143                 APP_CHECK((rte_is_power_of_2(p->size)),
144                         "%s size is not a power of 2\n", p->name);
145
146                 APP_CHECK((p->burst > 0),
147                         "%s burst size is 0\n", p->name);
148
149                 APP_CHECK((p->burst <= p->size),
150                         "%s burst size is bigger than its size\n", p->name);
151
152                 APP_CHECK((n_readers != 0),
153                         "%s has no reader\n", p->name);
154
155                 APP_CHECK((n_readers == 1),
156                         "%s has more than one reader\n", p->name);
157         }
158 }
159
160 static void
161 check_txqs(struct app_params *app)
162 {
163         uint32_t i;
164
165         for (i = 0; i < app->n_pktq_hwq_out; i++) {
166                 struct app_pktq_hwq_out_params *p = &app->hwq_out_params[i];
167                 uint32_t n_writers = app_txq_get_writers(app, p);
168
169                 APP_CHECK((p->size > 0),
170                         "%s size is 0\n", p->name);
171
172                 APP_CHECK((rte_is_power_of_2(p->size)),
173                         "%s size is not a power of 2\n", p->name);
174
175                 APP_CHECK((p->burst > 0),
176                         "%s burst size is 0\n", p->name);
177
178                 APP_CHECK((p->burst <= p->size),
179                         "%s burst size is bigger than its size\n", p->name);
180
181                 APP_CHECK((n_writers != 0),
182                         "%s has no writer\n", p->name);
183
184                 APP_CHECK((n_writers == 1),
185                         "%s has more than one writer\n", p->name);
186         }
187 }
188
189 static void
190 check_swqs(struct app_params *app)
191 {
192         uint32_t i;
193
194         for (i = 0; i < app->n_pktq_swq; i++) {
195                 struct app_pktq_swq_params *p = &app->swq_params[i];
196                 uint32_t n_readers = app_swq_get_readers(app, p);
197                 uint32_t n_writers = app_swq_get_writers(app, p);
198                 uint32_t n_flags;
199
200                 APP_CHECK((p->size > 0),
201                         "%s size is 0\n", p->name);
202
203                 APP_CHECK((rte_is_power_of_2(p->size)),
204                         "%s size is not a power of 2\n", p->name);
205
206                 APP_CHECK((p->burst_read > 0),
207                         "%s read burst size is 0\n", p->name);
208
209                 APP_CHECK((p->burst_read <= p->size),
210                         "%s read burst size is bigger than its size\n",
211                         p->name);
212
213                 APP_CHECK((p->burst_write > 0),
214                         "%s write burst size is 0\n", p->name);
215
216                 APP_CHECK((p->burst_write <= p->size),
217                         "%s write burst size is bigger than its size\n",
218                         p->name);
219
220                 APP_CHECK((n_readers != 0),
221                         "%s has no reader\n", p->name);
222
223                 if (n_readers > 1)
224                         APP_LOG(app, LOW, "%s has more than one reader", p->name);
225
226                 APP_CHECK((n_writers != 0),
227                         "%s has no writer\n", p->name);
228
229                 if (n_writers > 1)
230                         APP_LOG(app, LOW, "%s has more than one writer", p->name);
231
232                 n_flags = p->ipv4_frag + p->ipv6_frag + p->ipv4_ras + p->ipv6_ras;
233
234                 APP_CHECK((n_flags < 2),
235                         "%s has more than one fragmentation or reassembly mode enabled\n",
236                         p->name);
237
238                 APP_CHECK((!((n_readers > 1) && (n_flags == 1))),
239                         "%s has more than one reader when fragmentation or reassembly"
240                         " mode enabled\n",
241                         p->name);
242
243                 APP_CHECK((!((n_writers > 1) && (n_flags == 1))),
244                         "%s has more than one writer when fragmentation or reassembly"
245                         " mode enabled\n",
246                         p->name);
247
248                 n_flags = p->ipv4_ras + p->ipv6_ras;
249
250                 APP_CHECK((!((p->dropless == 1) && (n_flags == 1))),
251                         "%s has dropless when reassembly mode enabled\n", p->name);
252
253                 n_flags = p->ipv4_frag + p->ipv6_frag;
254
255                 if (n_flags == 1) {
256                         uint16_t ip_hdr_size = (p->ipv4_frag) ? sizeof(struct ipv4_hdr) :
257                                 sizeof(struct ipv6_hdr);
258
259                         APP_CHECK((p->mtu > ip_hdr_size),
260                                 "%s mtu size is smaller than ip header\n", p->name);
261
262                         APP_CHECK((!((p->mtu - ip_hdr_size) % 8)),
263                                 "%s mtu size is incorrect\n", p->name);
264                 }
265         }
266 }
267
268 static void
269 check_tms(struct app_params *app)
270 {
271         uint32_t i;
272
273         for (i = 0; i < app->n_pktq_tm; i++) {
274                 struct app_pktq_tm_params *p = &app->tm_params[i];
275                 uint32_t n_readers = app_tm_get_readers(app, p);
276                 uint32_t n_writers = app_tm_get_writers(app, p);
277
278                 APP_CHECK((n_readers != 0),
279                         "%s has no reader\n", p->name);
280
281                 APP_CHECK((n_readers == 1),
282                         "%s has more than one reader\n", p->name);
283
284                 APP_CHECK((n_writers != 0),
285                         "%s has no writer\n", p->name);
286
287                 APP_CHECK((n_writers == 1),
288                         "%s has more than one writer\n", p->name);
289         }
290 }
291
292 static void
293 check_sources(struct app_params *app)
294 {
295         uint32_t i;
296
297         for (i = 0; i < app->n_pktq_source; i++) {
298                 struct app_pktq_source_params *p = &app->source_params[i];
299                 uint32_t n_readers = app_source_get_readers(app, p);
300
301                 APP_CHECK((n_readers != 0),
302                         "%s has no reader\n", p->name);
303
304                 APP_CHECK((n_readers == 1),
305                         "%s has more than one reader\n", p->name);
306         }
307 }
308
309 static void
310 check_sinks(struct app_params *app)
311 {
312         uint32_t i;
313
314         for (i = 0; i < app->n_pktq_sink; i++) {
315                 struct app_pktq_sink_params *p = &app->sink_params[i];
316                 uint32_t n_writers = app_sink_get_writers(app, p);
317
318                 APP_CHECK((n_writers != 0),
319                         "%s has no writer\n", p->name);
320
321                 APP_CHECK((n_writers == 1),
322                         "%s has more than one writer\n", p->name);
323         }
324 }
325
326 static void
327 check_msgqs(struct app_params *app)
328 {
329         uint32_t i;
330
331         for (i = 0; i < app->n_msgq; i++) {
332                 struct app_msgq_params *p = &app->msgq_params[i];
333                 uint32_t n_readers = app_msgq_get_readers(app, p);
334                 uint32_t n_writers = app_msgq_get_writers(app, p);
335                 uint32_t msgq_req_pipeline, msgq_rsp_pipeline;
336                 uint32_t msgq_req_core, msgq_rsp_core;
337
338                 APP_CHECK((p->size > 0),
339                         "%s size is 0\n", p->name);
340
341                 APP_CHECK((rte_is_power_of_2(p->size)),
342                         "%s size is not a power of 2\n", p->name);
343
344                 msgq_req_pipeline = (strncmp(p->name, "MSGQ-REQ-PIPELINE",
345                         strlen("MSGQ-REQ-PIPELINE")) == 0);
346
347                 msgq_rsp_pipeline = (strncmp(p->name, "MSGQ-RSP-PIPELINE",
348                         strlen("MSGQ-RSP-PIPELINE")) == 0);
349
350                 msgq_req_core = (strncmp(p->name, "MSGQ-REQ-CORE",
351                         strlen("MSGQ-REQ-CORE")) == 0);
352
353                 msgq_rsp_core = (strncmp(p->name, "MSGQ-RSP-CORE",
354                         strlen("MSGQ-RSP-CORE")) == 0);
355
356                 if ((msgq_req_pipeline == 0) &&
357                         (msgq_rsp_pipeline == 0) &&
358                         (msgq_req_core == 0) &&
359                         (msgq_rsp_core == 0)) {
360                         APP_CHECK((n_readers != 0),
361                                 "%s has no reader\n", p->name);
362
363                         APP_CHECK((n_readers == 1),
364                                 "%s has more than one reader\n", p->name);
365
366                         APP_CHECK((n_writers != 0),
367                                 "%s has no writer\n", p->name);
368
369                         APP_CHECK((n_writers == 1),
370                                 "%s has more than one writer\n", p->name);
371                 }
372
373                 if (msgq_req_pipeline) {
374                         struct app_pipeline_params *pipeline;
375                         uint32_t pipeline_id;
376
377                         APP_PARAM_GET_ID(p, "MSGQ-REQ-PIPELINE", pipeline_id);
378
379                         APP_PARAM_FIND_BY_ID(app->pipeline_params,
380                                 "PIPELINE",
381                                 pipeline_id,
382                                 pipeline);
383
384                         APP_CHECK((pipeline != NULL),
385                                 "%s is not associated with a valid pipeline\n",
386                                 p->name);
387                 }
388
389                 if (msgq_rsp_pipeline) {
390                         struct app_pipeline_params *pipeline;
391                         uint32_t pipeline_id;
392
393                         APP_PARAM_GET_ID(p, "MSGQ-RSP-PIPELINE", pipeline_id);
394
395                         APP_PARAM_FIND_BY_ID(app->pipeline_params,
396                                 "PIPELINE",
397                                 pipeline_id,
398                                 pipeline);
399
400                         APP_CHECK((pipeline != NULL),
401                                 "%s is not associated with a valid pipeline\n",
402                                 p->name);
403                 }
404         }
405 }
406
407 static void
408 check_pipelines(struct app_params *app)
409 {
410         uint32_t i;
411
412         for (i = 0; i < app->n_pipelines; i++) {
413                 struct app_pipeline_params *p = &app->pipeline_params[i];
414
415                 APP_CHECK((p->n_msgq_in == p->n_msgq_out),
416                         "%s number of input MSGQs does not match "
417                         "the number of output MSGQs\n", p->name);
418         }
419 }
420
421 int
422 app_config_check(struct app_params *app)
423 {
424         check_mempools(app);
425         check_links(app);
426         check_rxqs(app);
427         check_txqs(app);
428         check_swqs(app);
429         check_tms(app);
430         check_sources(app);
431         check_sinks(app);
432         check_msgqs(app);
433         check_pipelines(app);
434
435         return 0;
436 }