dbeb3a97183aeb7bec02532d9972a839fba97bec
[dpdk.git] / examples / ip_pipeline / config_parse.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 #include <stdint.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <ctype.h>
37 #include <getopt.h>
38 #include <errno.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <libgen.h>
42 #include <unistd.h>
43 #include <sys/wait.h>
44
45 #include <rte_errno.h>
46 #include <rte_cfgfile.h>
47 #include <rte_string_fns.h>
48
49 #include "app.h"
50
51 /**
52  * Default config values
53  **/
54
55 static struct app_params app_params_default = {
56         .config_file = "./config/ip_pipeline.cfg",
57         .log_level = APP_LOG_LEVEL_HIGH,
58
59         .eal_params = {
60                 .channels = 4,
61         },
62 };
63
64 static const struct app_mempool_params mempool_params_default = {
65         .parsed = 0,
66         .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
67         .pool_size = 32 * 1024,
68         .cache_size = 256,
69         .cpu_socket_id = 0,
70 };
71
72 static const struct app_link_params link_params_default = {
73         .parsed = 0,
74         .pmd_id = 0,
75         .arp_q = 0,
76         .tcp_syn_local_q = 0,
77         .ip_local_q = 0,
78         .tcp_local_q = 0,
79         .udp_local_q = 0,
80         .sctp_local_q = 0,
81         .state = 0,
82         .ip = 0,
83         .depth = 0,
84         .mac_addr = 0,
85
86         .conf = {
87                 .link_speed = 0,
88                 .link_duplex = 0,
89                 .rxmode = {
90                         .mq_mode = ETH_MQ_RX_NONE,
91
92                         .header_split   = 0, /* Header split */
93                         .hw_ip_checksum = 0, /* IP checksum offload */
94                         .hw_vlan_filter = 0, /* VLAN filtering */
95                         .hw_vlan_strip  = 0, /* VLAN strip */
96                         .hw_vlan_extend = 0, /* Extended VLAN */
97                         .jumbo_frame    = 0, /* Jumbo frame support */
98                         .hw_strip_crc   = 0, /* CRC strip by HW */
99                         .enable_scatter = 0, /* Scattered packets RX handler */
100
101                         .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
102                         .split_hdr_size = 0, /* Header split buffer size */
103                 },
104                 .txmode = {
105                         .mq_mode = ETH_MQ_TX_NONE,
106                 },
107                 .lpbk_mode = 0,
108         },
109
110         .promisc = 1,
111 };
112
113 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
114         .parsed = 0,
115         .mempool_id = 0,
116         .size = 128,
117         .burst = 32,
118
119         .conf = {
120                 .rx_thresh = {
121                                 .pthresh = 8,
122                                 .hthresh = 8,
123                                 .wthresh = 4,
124                 },
125                 .rx_free_thresh = 64,
126                 .rx_drop_en = 0,
127                 .rx_deferred_start = 0,
128         }
129 };
130
131 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
132         .parsed = 0,
133         .size = 512,
134         .burst = 32,
135         .dropless = 0,
136         .n_retries = 0,
137
138         .conf = {
139                 .tx_thresh = {
140                         .pthresh = 36,
141                         .hthresh = 0,
142                         .wthresh = 0,
143                 },
144                 .tx_rs_thresh = 0,
145                 .tx_free_thresh = 0,
146                 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
147                         ETH_TXQ_FLAGS_NOOFFLOADS,
148                 .tx_deferred_start = 0,
149         }
150 };
151
152 static const struct app_pktq_swq_params default_swq_params = {
153         .parsed = 0,
154         .size = 256,
155         .burst_read = 32,
156         .burst_write = 32,
157         .dropless = 0,
158         .n_retries = 0,
159         .cpu_socket_id = 0,
160         .ipv4_frag = 0,
161         .ipv6_frag = 0,
162         .ipv4_ras = 0,
163         .ipv6_ras = 0,
164         .mtu = 0,
165         .metadata_size = 0,
166         .mempool_direct_id = 0,
167         .mempool_indirect_id = 0,
168 };
169
170 struct app_pktq_tm_params default_tm_params = {
171         .parsed = 0,
172         .file_name = "./config/tm_profile.cfg",
173         .burst_read = 64,
174         .burst_write = 32,
175 };
176
177 struct app_pktq_source_params default_source_params = {
178         .parsed = 0,
179         .mempool_id = 0,
180         .burst = 32,
181 };
182
183 struct app_pktq_sink_params default_sink_params = {
184         .parsed = 0,
185 };
186
187 struct app_msgq_params default_msgq_params = {
188         .parsed = 0,
189         .size = 64,
190         .cpu_socket_id = 0,
191 };
192
193 struct app_pipeline_params default_pipeline_params = {
194         .parsed = 0,
195         .socket_id = 0,
196         .core_id = 0,
197         .hyper_th_id = 0,
198         .n_pktq_in = 0,
199         .n_pktq_out = 0,
200         .n_msgq_in = 0,
201         .n_msgq_out = 0,
202         .timer_period = 1,
203         .n_args = 0,
204 };
205
206 static const char app_usage[] =
207         "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] -p PORT_MASK "
208         "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
209         "\n"
210         "Arguments:\n"
211         "\t-f CONFIG_FILE: Default config file is %s\n"
212         "\t-p PORT_MASK: Mask of NIC port IDs in hexadecimal format\n"
213         "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
214         "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
215         "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
216         "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
217         "\n";
218
219 static void
220 app_print_usage(char *prgname)
221 {
222         rte_exit(0, app_usage, prgname, app_params_default.config_file);
223 }
224
225 #define skip_white_spaces(pos)                  \
226 ({                                              \
227         __typeof__(pos) _p = (pos);             \
228         for ( ; isspace(*_p); _p++);            \
229         _p;                                     \
230 })
231
232 #define PARSER_IMPLICIT_PARAM_ADD_CHECK(result, section_name)           \
233 do {                                                                    \
234         APP_CHECK((result != -EINVAL),                                  \
235                 "CFG: [%s] name too long", section_name);               \
236         APP_CHECK(result != -ENOMEM,                                    \
237                 "CFG: [%s] too much sections", section_name);           \
238         APP_CHECK(result >= 0,                                          \
239                 "CFG: [%s] Unknown error while adding '%s'",            \
240                 section_name, section_name);                            \
241 } while (0)
242
243 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name)      \
244 do {                                                                    \
245         APP_CHECK((result != -EINVAL),                                  \
246                 "CFG: [%s] name too long", section_name);               \
247         APP_CHECK((result != -ENOMEM),                                  \
248                 "CFG: [%s] too much sections", section_name);           \
249         APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
250                 "CFG: [%s] duplicate section", section_name);           \
251         APP_CHECK((result >= 0),                                        \
252                 "CFG: [%s] Unknown error while adding '%s'",            \
253                 section_name, section_name);                            \
254 } while (0)
255
256 static int
257 parser_read_arg_bool(const char *p)
258 {
259         p = skip_white_spaces(p);
260         int result = -EINVAL;
261
262         if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
263                 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
264                 p += 3;
265                 result = 1;
266         }
267
268         if (((p[0] == 'o') && (p[1] == 'n')) ||
269                 ((p[0] == 'O') && (p[1] == 'N'))) {
270                 p += 2;
271                 result = 1;
272         }
273
274         if (((p[0] == 'n') && (p[1] == 'o')) ||
275                 ((p[0] == 'N') && (p[1] == 'O'))) {
276                 p += 2;
277                 result = 0;
278         }
279
280         if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
281                 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
282                 p += 3;
283                 result = 0;
284         }
285
286         p = skip_white_spaces(p);
287
288         if (p[0] != '\0')
289                 return -EINVAL;
290
291         return result;
292 }
293
294 #define PARSE_ERROR(exp, section, entry)                                \
295 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
296
297 #define PARSE_ERROR_MALLOC(exp)                                         \
298 APP_CHECK(exp, "Parse error: no free memory\n")
299
300 #define PARSE_ERROR_SECTION(exp, section)                               \
301 APP_CHECK(exp, "Parse error in section \"%s\"", section)
302
303 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section)                    \
304 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
305
306 #define PARSE_WARNING_IGNORED(exp, section, entry)                      \
307 do                                                                      \
308 if (!(exp))                                                             \
309         fprintf(stderr, "Parse warning in section \"%s\": "             \
310                 "entry \"%s\" is ignored\n", section, entry);           \
311 while (0)
312
313 #define PARSE_ERROR_INVALID(exp, section, entry)                        \
314 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
315         section, entry)
316
317 #define PARSE_ERROR_DUPLICATE(exp, section, entry)                      \
318 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
319         section, entry)
320
321 static int
322 parser_read_uint64(uint64_t *value, const char *p)
323 {
324         char *next;
325         uint64_t val;
326
327         p = skip_white_spaces(p);
328         if (!isdigit(*p))
329                 return -EINVAL;
330
331         val = strtoul(p, &next, 10);
332         if (p == next)
333                 return -EINVAL;
334
335         p = next;
336         switch (*p) {
337         case 'T':
338                 val *= 1024ULL;
339                 /* fall trought */
340         case 'G':
341                 val *= 1024ULL;
342                 /* fall trought */
343         case 'M':
344                 val *= 1024ULL;
345                 /* fall trought */
346         case 'k':
347         case 'K':
348                 val *= 1024ULL;
349                 p++;
350                 break;
351         }
352
353         p = skip_white_spaces(p);
354         if (*p != '\0')
355                 return -EINVAL;
356
357         *value = val;
358         return 0;
359 }
360
361 static int
362 parser_read_uint32(uint32_t *value, const char *p)
363 {
364         uint64_t val = 0;
365         int ret = parser_read_uint64(&val, p);
366
367         if (ret < 0)
368                 return ret;
369         else if (val > UINT32_MAX)
370                 return -ERANGE;
371
372         *value = val;
373         return 0;
374 }
375
376 int
377 parse_pipeline_core(uint32_t *socket,
378         uint32_t *core,
379         uint32_t *ht,
380         const char *entry)
381 {
382         size_t num_len;
383         char num[8];
384
385         uint32_t s = 0, c = 0, h = 0, val;
386         uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
387         const char *next = skip_white_spaces(entry);
388         char type;
389
390         /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
391         while (*next != '\0') {
392                 /* If everything parsed nothing should left */
393                 if (s_parsed && c_parsed && h_parsed)
394                         return -EINVAL;
395
396                 type = *next;
397                 switch (type) {
398                 case 's':
399                 case 'S':
400                         if (s_parsed || c_parsed || h_parsed)
401                                 return -EINVAL;
402                         s_parsed = 1;
403                         next++;
404                         break;
405                 case 'c':
406                 case 'C':
407                         if (c_parsed || h_parsed)
408                                 return -EINVAL;
409                         c_parsed = 1;
410                         next++;
411                         break;
412                 case 'h':
413                 case 'H':
414                         if (h_parsed)
415                                 return -EINVAL;
416                         h_parsed = 1;
417                         next++;
418                         break;
419                 default:
420                         /* If it start from digit it must be only core id. */
421                         if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
422                                 return -EINVAL;
423
424                         type = 'C';
425                 }
426
427                 for (num_len = 0; *next != '\0'; next++, num_len++) {
428                         if (num_len == RTE_DIM(num))
429                                 return -EINVAL;
430
431                         if (!isdigit(*next))
432                                 break;
433
434                         num[num_len] = *next;
435                 }
436
437                 if (num_len == 0 && type != 'h' && type != 'H')
438                         return -EINVAL;
439
440                 if (num_len != 0 && (type == 'h' || type == 'H'))
441                         return -EINVAL;
442
443                 num[num_len] = '\0';
444                 val = strtol(num, NULL, 10);
445
446                 h = 0;
447                 switch (type) {
448                 case 's':
449                 case 'S':
450                         s = val;
451                         break;
452                 case 'c':
453                 case 'C':
454                         c = val;
455                         break;
456                 case 'h':
457                 case 'H':
458                         h = 1;
459                         break;
460                 }
461         }
462
463         *socket = s;
464         *core = c;
465         *ht = h;
466         return 0;
467 }
468
469 static uint32_t
470 get_hex_val(char c)
471 {
472         switch (c) {
473         case '0': case '1': case '2': case '3': case '4': case '5':
474         case '6': case '7': case '8': case '9':
475                 return c - '0';
476         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
477                 return c - 'A' + 10;
478         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
479                 return c - 'a' + 10;
480         default:
481                 return 0;
482         }
483 }
484
485 int
486 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
487 {
488         char *c;
489         uint32_t len, i;
490
491         /* Check input parameters */
492         if ((src == NULL) ||
493                 (dst == NULL) ||
494                 (size == NULL) ||
495                 (*size == 0))
496                 return -1;
497
498         len = strlen(src);
499         if (((len & 3) != 0) ||
500                 (len > (*size) * 2))
501                 return -1;
502         *size = len / 2;
503
504         for (c = src; *c != 0; c++) {
505                 if ((((*c) >= '0') && ((*c) <= '9')) ||
506                         (((*c) >= 'A') && ((*c) <= 'F')) ||
507                         (((*c) >= 'a') && ((*c) <= 'f')))
508                         continue;
509
510                 return -1;
511         }
512
513         /* Convert chars to bytes */
514         for (i = 0; i < *size; i++)
515                 dst[i] = get_hex_val(src[2 * i]) * 16 +
516                         get_hex_val(src[2 * i + 1]);
517
518         return 0;
519 }
520
521 static size_t
522 skip_digits(const char *src)
523 {
524         size_t i;
525
526         for (i = 0; isdigit(src[i]); i++);
527
528         return i;
529 }
530
531 static int
532 validate_name(const char *name, const char *prefix, int num)
533 {
534         size_t i, j;
535
536         for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
537                 if (name[i] != prefix[i])
538                         return -1;
539         }
540
541         if (prefix[i] != '\0')
542                 return -1;
543
544         if (!num) {
545                 if (name[i] != '\0')
546                         return -1;
547                 else
548                         return 0;
549         }
550
551         if (num == 2) {
552                 j = skip_digits(&name[i]);
553                 i += j;
554                 if ((j == 0) || (name[i] != '.'))
555                         return -1;
556                 i++;
557         }
558
559         if (num == 1) {
560                 j = skip_digits(&name[i]);
561                 i += j;
562                 if ((j == 0) || (name[i] != '\0'))
563                         return -1;
564         }
565
566         return 0;
567 }
568
569 static void
570 parse_eal(struct app_params *app,
571         const char *section_name,
572         struct rte_cfgfile *cfg)
573 {
574         struct app_eal_params *p = &app->eal_params;
575         struct rte_cfgfile_entry *entries;
576         int n_entries, i;
577
578         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
579         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
580
581         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
582         PARSE_ERROR_MALLOC(entries != NULL);
583
584         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
585
586         for (i = 0; i < n_entries; i++) {
587                 struct rte_cfgfile_entry *entry = &entries[i];
588
589                 /* coremask */
590                 if (strcmp(entry->name, "c") == 0) {
591                         PARSE_WARNING_IGNORED(0, section_name, entry->name);
592                         continue;
593                 }
594
595                 /* corelist */
596                 if (strcmp(entry->name, "l") == 0) {
597                         PARSE_WARNING_IGNORED(0, section_name, entry->name);
598                         continue;
599                 }
600
601                 /* coremap */
602                 if (strcmp(entry->name, "lcores") == 0) {
603                         PARSE_ERROR_DUPLICATE((p->coremap == NULL),
604                                 section_name,
605                                 entry->name);
606                         p->coremap = strdup(entry->value);
607                         continue;
608                 }
609
610                 /* master_lcore */
611                 if (strcmp(entry->name, "master_lcore") == 0) {
612                         int status;
613
614                         PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
615                                 section_name,
616                                 entry->name);
617                         p->master_lcore_present = 1;
618
619                         status = parser_read_uint32(&p->master_lcore,
620                                 entry->value);
621                         PARSE_ERROR((status == 0), section_name, entry->name);
622                         continue;
623                 }
624
625                 /* channels */
626                 if (strcmp(entry->name, "n") == 0) {
627                         int status;
628
629                         PARSE_ERROR_DUPLICATE((p->channels_present == 0),
630                                 section_name,
631                                 entry->name);
632                         p->channels_present = 1;
633
634                         status = parser_read_uint32(&p->channels, entry->value);
635                         PARSE_ERROR((status == 0), section_name, entry->name);
636                         continue;
637                 }
638
639                 /* memory */
640                 if (strcmp(entry->name, "m") == 0) {
641                         int status;
642
643                         PARSE_ERROR_DUPLICATE((p->memory_present == 0),
644                                 section_name,
645                                 entry->name);
646                         p->memory_present = 1;
647
648                         status = parser_read_uint32(&p->memory, entry->value);
649                         PARSE_ERROR((status == 0), section_name, entry->name);
650                         continue;
651                 }
652
653                 /* ranks */
654                 if (strcmp(entry->name, "r") == 0) {
655                         int status;
656
657                         PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
658                                 section_name,
659                                 entry->name);
660                         p->ranks_present = 1;
661
662                         status = parser_read_uint32(&p->ranks, entry->value);
663                         PARSE_ERROR((status == 0), section_name, entry->name);
664                         continue;
665                 }
666
667                 /* pci_blacklist */
668                 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
669                         (strcmp(entry->name, "b") == 0)) {
670                         PARSE_ERROR_DUPLICATE((p->pci_blacklist == NULL),
671                                 section_name,
672                                 entry->name);
673                         p->pci_blacklist = strdup(entry->value);
674                         continue;
675                 }
676
677                 /* pci_whitelist */
678                 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
679                         (strcmp(entry->name, "w") == 0)) {
680                         PARSE_ERROR_DUPLICATE((p->pci_whitelist == NULL),
681                                 section_name,
682                                 entry->name);
683                         p->pci_whitelist = strdup(entry->value);
684                         continue;
685                 }
686
687                 /* vdev */
688                 if (strcmp(entry->name, "vdev") == 0) {
689                         PARSE_ERROR_DUPLICATE((p->vdev == NULL),
690                                 section_name,
691                                 entry->name);
692                         p->vdev = strdup(entry->value);
693                         continue;
694                 }
695
696                 /* vmware_tsc_map */
697                 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
698                         int val;
699
700                         PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
701                                 section_name,
702                                 entry->name);
703                         p->vmware_tsc_map_present = 1;
704
705                         val = parser_read_arg_bool(entry->value);
706                         PARSE_ERROR((val >= 0), section_name, entry->name);
707                         p->vmware_tsc_map = val;
708                         continue;
709                 }
710
711                 /* proc_type */
712                 if (strcmp(entry->name, "proc_type") == 0) {
713                         PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
714                                 section_name,
715                                 entry->name);
716                         p->proc_type = strdup(entry->value);
717                         continue;
718                 }
719
720                 /* syslog */
721                 if (strcmp(entry->name, "syslog") == 0) {
722                         PARSE_ERROR_DUPLICATE((p->syslog == NULL),
723                                 section_name,
724                                 entry->name);
725                         p->syslog = strdup(entry->value);
726                         continue;
727                 }
728
729                 /* log_level */
730                 if (strcmp(entry->name, "log_level") == 0) {
731                         int status;
732
733                         PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
734                                 section_name,
735                                 entry->name);
736                         p->log_level_present = 1;
737
738                         status = parser_read_uint32(&p->log_level,
739                                 entry->value);
740                         PARSE_ERROR((status == 0), section_name, entry->name);
741                         continue;
742                 }
743
744                 /* version */
745                 if (strcmp(entry->name, "v") == 0) {
746                         int val;
747
748                         PARSE_ERROR_DUPLICATE((p->version_present == 0),
749                                 section_name,
750                                 entry->name);
751                         p->version_present = 1;
752
753                         val = parser_read_arg_bool(entry->value);
754                         PARSE_ERROR((val >= 0), section_name, entry->name);
755                         p->version = val;
756                         continue;
757                 }
758
759                 /* help */
760                 if ((strcmp(entry->name, "help") == 0) ||
761                         (strcmp(entry->name, "h") == 0)) {
762                         int val;
763
764                         PARSE_ERROR_DUPLICATE((p->help_present == 0),
765                                 section_name,
766                                 entry->name);
767                         p->help_present = 1;
768
769                         val = parser_read_arg_bool(entry->value);
770                         PARSE_ERROR((val >= 0), section_name, entry->name);
771                         p->help = val;
772                         continue;
773                 }
774
775                 /* no_huge */
776                 if (strcmp(entry->name, "no_huge") == 0) {
777                         int val;
778
779                         PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
780                                 section_name,
781                                 entry->name);
782                         p->no_huge_present = 1;
783
784                         val = parser_read_arg_bool(entry->value);
785                         PARSE_ERROR((val >= 0), section_name, entry->name);
786                         p->no_huge = val;
787                         continue;
788                 }
789
790                 /* no_pci */
791                 if (strcmp(entry->name, "no_pci") == 0) {
792                         int val;
793
794                         PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
795                                 section_name,
796                                 entry->name);
797                         p->no_pci_present = 1;
798
799                         val = parser_read_arg_bool(entry->value);
800                         PARSE_ERROR((val >= 0), section_name, entry->name);
801                         p->no_pci = val;
802                         continue;
803                 }
804
805                 /* no_hpet */
806                 if (strcmp(entry->name, "no_hpet") == 0) {
807                         int val;
808
809                         PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
810                                 section_name,
811                                 entry->name);
812                         p->no_hpet_present = 1;
813
814                         val = parser_read_arg_bool(entry->value);
815                         PARSE_ERROR((val >= 0), section_name, entry->name);
816                         p->no_hpet = val;
817                         continue;
818                 }
819
820                 /* no_shconf */
821                 if (strcmp(entry->name, "no_shconf") == 0) {
822                         int val;
823
824                         PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
825                                 section_name,
826                                 entry->name);
827                         p->no_shconf_present = 1;
828
829                         val = parser_read_arg_bool(entry->value);
830                         PARSE_ERROR((val >= 0), section_name, entry->name);
831                         p->no_shconf = val;
832                         continue;
833                 }
834
835                 /* add_driver */
836                 if (strcmp(entry->name, "d") == 0) {
837                         PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
838                                 section_name,
839                                 entry->name);
840                         p->add_driver = strdup(entry->value);
841                         continue;
842                 }
843
844                 /* socket_mem */
845                 if (strcmp(entry->name, "socket_mem") == 0) {
846                         PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
847                                 section_name,
848                                 entry->name);
849                         p->socket_mem = strdup(entry->value);
850                         continue;
851                 }
852
853                 /* huge_dir */
854                 if (strcmp(entry->name, "huge_dir") == 0) {
855                         PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
856                                 section_name,
857                                 entry->name);
858                         p->huge_dir = strdup(entry->value);
859                         continue;
860                 }
861
862                 /* file_prefix */
863                 if (strcmp(entry->name, "file_prefix") == 0) {
864                         PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
865                                 section_name,
866                                 entry->name);
867                         p->file_prefix = strdup(entry->value);
868                         continue;
869                 }
870
871                 /* base_virtaddr */
872                 if (strcmp(entry->name, "base_virtaddr") == 0) {
873                         PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
874                                 section_name,
875                                 entry->name);
876                         p->base_virtaddr = strdup(entry->value);
877                         continue;
878                 }
879
880                 /* create_uio_dev */
881                 if (strcmp(entry->name, "create_uio_dev") == 0) {
882                         int val;
883
884                         PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
885                                 section_name,
886                                 entry->name);
887                         p->create_uio_dev_present = 1;
888
889                         val = parser_read_arg_bool(entry->value);
890                         PARSE_ERROR((val >= 0), section_name, entry->name);
891                         p->create_uio_dev = val;
892                         continue;
893                 }
894
895                 /* vfio_intr */
896                 if (strcmp(entry->name, "vfio_intr") == 0) {
897                         PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
898                                 section_name,
899                                 entry->name);
900                         p->vfio_intr = strdup(entry->value);
901                         continue;
902                 }
903
904                 /* xen_dom0 */
905                 if (strcmp(entry->name, "xen_dom0") == 0) {
906                         int val;
907
908                         PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
909                                 section_name,
910                                 entry->name);
911                         p->xen_dom0_present = 1;
912
913                         val = parser_read_arg_bool(entry->value);
914                         PARSE_ERROR((val >= 0), section_name, entry->name);
915                         p->xen_dom0 = val;
916                         continue;
917                 }
918
919                 /* unrecognized */
920                 PARSE_ERROR_INVALID(0, section_name, entry->name);
921         }
922
923         free(entries);
924 }
925
926 static int
927 parse_pipeline_pktq_in(struct app_params *app,
928         struct app_pipeline_params *p,
929         const char *value)
930 {
931         const char *next = value;
932         char *end;
933         char name[APP_PARAM_NAME_SIZE];
934         size_t name_len;
935
936         while (*next != '\0') {
937                 enum app_pktq_in_type type;
938                 int id;
939
940                 end = strchr(next, ' ');
941                 if (!end)
942                         name_len = strlen(next);
943                 else
944                         name_len = end - next;
945
946                 if (name_len == 0 || name_len == sizeof(name))
947                         return -EINVAL;
948
949                 strncpy(name, next, name_len);
950                 name[name_len] = '\0';
951                 next += name_len;
952                 if (*next != '\0')
953                         next++;
954
955                 if (validate_name(name, "RXQ", 2) == 0) {
956                         type = APP_PKTQ_IN_HWQ;
957                         id = APP_PARAM_ADD(app->hwq_in_params, name);
958                 } else if (validate_name(name, "SWQ", 1) == 0) {
959                         type = APP_PKTQ_IN_SWQ;
960                         id = APP_PARAM_ADD(app->swq_params, name);
961                 } else if (validate_name(name, "TM", 1) == 0) {
962                         type = APP_PKTQ_IN_TM;
963                         id = APP_PARAM_ADD(app->tm_params, name);
964                 } else if (validate_name(name, "SOURCE", 1) == 0) {
965                         type = APP_PKTQ_IN_SOURCE;
966                         id = APP_PARAM_ADD(app->source_params, name);
967                 } else
968                         return -EINVAL;
969
970                 if (id < 0)
971                         return id;
972
973                 p->pktq_in[p->n_pktq_in].type = type;
974                 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
975                 p->n_pktq_in++;
976         }
977
978         return 0;
979 }
980
981 static int
982 parse_pipeline_pktq_out(struct app_params *app,
983         struct app_pipeline_params *p,
984         const char *value)
985 {
986         const char *next = value;
987         char *end;
988         char name[APP_PARAM_NAME_SIZE];
989         size_t name_len;
990
991         while (*next != '\0') {
992                 enum app_pktq_out_type type;
993                 int id;
994
995                 end = strchr(next, ' ');
996                 if (!end)
997                         name_len = strlen(next);
998                 else
999                         name_len = end - next;
1000
1001                 if (name_len == 0 || name_len == sizeof(name))
1002                         return -EINVAL;
1003
1004                 strncpy(name, next, name_len);
1005                 name[name_len] = '\0';
1006                 next += name_len;
1007                 if (*next != '\0')
1008                         next++;
1009
1010                 if (validate_name(name, "TXQ", 2) == 0) {
1011                         type = APP_PKTQ_OUT_HWQ;
1012                         id = APP_PARAM_ADD(app->hwq_out_params, name);
1013                 } else if (validate_name(name, "SWQ", 1) == 0) {
1014                         type = APP_PKTQ_OUT_SWQ;
1015                         id = APP_PARAM_ADD(app->swq_params, name);
1016                 } else if (validate_name(name, "TM", 1) == 0) {
1017                         type = APP_PKTQ_OUT_TM;
1018                         id = APP_PARAM_ADD(app->tm_params, name);
1019                 } else if (validate_name(name, "SINK", 1) == 0) {
1020                         type = APP_PKTQ_OUT_SINK;
1021                         id = APP_PARAM_ADD(app->sink_params, name);
1022                 } else
1023                         return -EINVAL;
1024
1025                 if (id < 0)
1026                         return id;
1027
1028                 p->pktq_out[p->n_pktq_out].type = type;
1029                 p->pktq_out[p->n_pktq_out].id = id;
1030                 p->n_pktq_out++;
1031         }
1032
1033         return 0;
1034 }
1035
1036 static int
1037 parse_pipeline_msgq_in(struct app_params *app,
1038         struct app_pipeline_params *p,
1039         const char *value)
1040 {
1041         const char *next = value;
1042         char *end;
1043         char name[APP_PARAM_NAME_SIZE];
1044         size_t name_len;
1045         ssize_t idx;
1046
1047         while (*next != '\0') {
1048                 end = strchr(next, ' ');
1049                 if (!end)
1050                         name_len = strlen(next);
1051                 else
1052                         name_len = end - next;
1053
1054                 if (name_len == 0 || name_len == sizeof(name))
1055                         return -EINVAL;
1056
1057                 strncpy(name, next, name_len);
1058                 name[name_len] = '\0';
1059                 next += name_len;
1060                 if (*next != '\0')
1061                         next++;
1062
1063                 if (validate_name(name, "MSGQ", 1) != 0)
1064                         return -EINVAL;
1065
1066                 idx = APP_PARAM_ADD(app->msgq_params, name);
1067                 if (idx < 0)
1068                         return idx;
1069
1070                 p->msgq_in[p->n_msgq_in] = idx;
1071                 p->n_msgq_in++;
1072         }
1073
1074         return 0;
1075 }
1076
1077 static int
1078 parse_pipeline_msgq_out(struct app_params *app,
1079         struct app_pipeline_params *p,
1080         const char *value)
1081 {
1082         const char *next = value;
1083         char *end;
1084         char name[APP_PARAM_NAME_SIZE];
1085         size_t name_len;
1086         ssize_t idx;
1087
1088         while (*next != '\0') {
1089                 end = strchr(next, ' ');
1090                 if (!end)
1091                         name_len = strlen(next);
1092                 else
1093                         name_len = end - next;
1094
1095                 if (name_len == 0 || name_len == sizeof(name))
1096                         return -EINVAL;
1097
1098                 strncpy(name, next, name_len);
1099                 name[name_len] = '\0';
1100                 next += name_len;
1101                 if (*next != '\0')
1102                         next++;
1103
1104                 if (validate_name(name, "MSGQ", 1) != 0)
1105                         return -EINVAL;
1106
1107                 idx = APP_PARAM_ADD(app->msgq_params, name);
1108                 if (idx < 0)
1109                         return idx;
1110
1111                 p->msgq_out[p->n_msgq_out] = idx;
1112                 p->n_msgq_out++;
1113         }
1114
1115         return 0;
1116 }
1117
1118
1119 static void
1120 parse_pipeline(struct app_params *app,
1121         const char *section_name,
1122         struct rte_cfgfile *cfg)
1123 {
1124         char name[CFG_NAME_LEN];
1125         struct app_pipeline_params *param;
1126         struct rte_cfgfile_entry *entries;
1127         ssize_t param_idx;
1128         int n_entries, ret, i;
1129
1130         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1131         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1132
1133         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1134         PARSE_ERROR_MALLOC(entries != NULL);
1135
1136         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1137
1138         param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1139         PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1140
1141         param = &app->pipeline_params[param_idx];
1142         param->parsed = 1;
1143
1144         for (i = 0; i < n_entries; i++) {
1145                 struct rte_cfgfile_entry *ent = &entries[i];
1146
1147                 if (strcmp(ent->name, "type") == 0) {
1148                         ret = snprintf(param->type,
1149                                 RTE_DIM(param->type),
1150                                 "%s",
1151                                 ent->value);
1152                         if ((ret > 0) && (ret < (int)RTE_DIM(param->type)))
1153                                 ret = 0;
1154                         else
1155                                 ret = -EINVAL;
1156                 } else if (strcmp(ent->name, "core") == 0)
1157                         ret = parse_pipeline_core(&param->socket_id,
1158                                 &param->core_id,
1159                                 &param->hyper_th_id,
1160                                 ent->value);
1161                 else if (strcmp(ent->name, "pktq_in") == 0)
1162                         ret = parse_pipeline_pktq_in(app, param, ent->value);
1163                 else if (strcmp(ent->name, "pktq_out") == 0)
1164                         ret = parse_pipeline_pktq_out(app, param, ent->value);
1165                 else if (strcmp(ent->name, "msgq_in") == 0)
1166                         ret = parse_pipeline_msgq_in(app, param, ent->value);
1167                 else if (strcmp(ent->name, "msgq_out") == 0)
1168                         ret = parse_pipeline_msgq_out(app, param, ent->value);
1169                 else if (strcmp(ent->name, "timer_period") == 0)
1170                         ret = parser_read_uint32(&param->timer_period,
1171                                 ent->value);
1172                 else {
1173                         APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1174                                 "CFG: [%s] out of memory",
1175                                 section_name);
1176
1177                         param->args_name[param->n_args] = strdup(ent->name);
1178                         param->args_value[param->n_args] = strdup(ent->value);
1179
1180                         APP_CHECK((param->args_name[param->n_args] != NULL) &&
1181                                 (param->args_value[param->n_args] != NULL),
1182                                 "CFG: [%s] out of memory",
1183                                 section_name);
1184
1185                         param->n_args++;
1186                         ret = 0;
1187                 }
1188
1189                 APP_CHECK(ret == 0,
1190                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1191                         section_name,
1192                         ent->name,
1193                         ent->value);
1194         }
1195
1196         snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1197         param_idx = APP_PARAM_ADD(app->msgq_params, name);
1198         PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1199         app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1200         param->msgq_in[param->n_msgq_in++] = param_idx;
1201
1202         snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1203         param_idx = APP_PARAM_ADD(app->msgq_params, name);
1204         PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1205         app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1206         param->msgq_out[param->n_msgq_out++] = param_idx;
1207
1208         snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1209                 param->socket_id,
1210                 param->core_id,
1211                 (param->hyper_th_id) ? "h" : "");
1212         param_idx = APP_PARAM_ADD(app->msgq_params, name);
1213         PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1214         app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1215
1216         snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1217                 param->socket_id,
1218                 param->core_id,
1219                 (param->hyper_th_id) ? "h" : "");
1220         param_idx = APP_PARAM_ADD(app->msgq_params, name);
1221         PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1222         app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1223
1224         free(entries);
1225 }
1226
1227 static void
1228 parse_mempool(struct app_params *app,
1229         const char *section_name,
1230         struct rte_cfgfile *cfg)
1231 {
1232         struct app_mempool_params *param;
1233         struct rte_cfgfile_entry *entries;
1234         ssize_t param_idx;
1235         int n_entries, ret, i;
1236
1237         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1238         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1239
1240         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1241         PARSE_ERROR_MALLOC(entries != NULL);
1242
1243         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1244
1245         param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1246         PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1247
1248         param = &app->mempool_params[param_idx];
1249         param->parsed = 1;
1250
1251         for (i = 0; i < n_entries; i++) {
1252                 struct rte_cfgfile_entry *ent = &entries[i];
1253
1254                 ret = -ESRCH;
1255                 if (strcmp(ent->name, "buffer_size") == 0)
1256                         ret = parser_read_uint32(&param->buffer_size,
1257                                 ent->value);
1258                 else if (strcmp(ent->name, "pool_size") == 0)
1259                         ret = parser_read_uint32(&param->pool_size,
1260                                 ent->value);
1261                 else if (strcmp(ent->name, "cache_size") == 0)
1262                         ret = parser_read_uint32(&param->cache_size,
1263                                 ent->value);
1264                 else if (strcmp(ent->name, "cpu") == 0)
1265                         ret = parser_read_uint32(&param->cpu_socket_id,
1266                                 ent->value);
1267
1268                 APP_CHECK(ret != -ESRCH,
1269                         "CFG: [%s] entry '%s': unknown entry\n",
1270                         section_name,
1271                         ent->name);
1272                 APP_CHECK(ret == 0,
1273                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1274                         section_name,
1275                         ent->name,
1276                         ent->value);
1277         }
1278
1279         free(entries);
1280 }
1281
1282 static void
1283 parse_link(struct app_params *app,
1284         const char *section_name,
1285         struct rte_cfgfile *cfg)
1286 {
1287         struct app_link_params *param;
1288         struct rte_cfgfile_entry *entries;
1289         int n_entries, ret, i;
1290         ssize_t param_idx;
1291
1292         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1293         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1294
1295         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1296         PARSE_ERROR_MALLOC(entries != NULL);
1297
1298         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1299
1300         param_idx = APP_PARAM_ADD(app->link_params, section_name);
1301         PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1302
1303         param = &app->link_params[param_idx];
1304         param->parsed = 1;
1305
1306         for (i = 0; i < n_entries; i++) {
1307                 struct rte_cfgfile_entry *ent = &entries[i];
1308
1309                 ret = -ESRCH;
1310                 if (strcmp(ent->name, "promisc") == 0) {
1311                         ret = parser_read_arg_bool(ent->value);
1312                         if (ret >= 0) {
1313                                 param->promisc = ret;
1314                                 ret = 0;
1315                         }
1316                 } else if (strcmp(ent->name, "arp_q") == 0)
1317                         ret = parser_read_uint32(&param->arp_q,
1318                                 ent->value);
1319                 else if (strcmp(ent->name, "tcp_syn_q") == 0)
1320                         ret = parser_read_uint32(&param->tcp_syn_local_q,
1321                                 ent->value);
1322                 else if (strcmp(ent->name, "ip_local_q") == 0)
1323                         ret = parser_read_uint32(&param->ip_local_q,
1324                                 ent->value);
1325                 else if (strcmp(ent->name, "tcp_local_q") == 0)
1326                         ret = parser_read_uint32(&param->tcp_local_q,
1327                                 ent->value);
1328                 else if (strcmp(ent->name, "udp_local_q") == 0)
1329                         ret = parser_read_uint32(&param->udp_local_q,
1330                                 ent->value);
1331                 else if (strcmp(ent->name, "sctp_local_q") == 0)
1332                         ret = parser_read_uint32(&param->sctp_local_q,
1333                                 ent->value);
1334
1335                 APP_CHECK(ret != -ESRCH,
1336                         "CFG: [%s] entry '%s': unknown entry\n",
1337                         section_name,
1338                         ent->name);
1339                 APP_CHECK(ret == 0,
1340                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1341                         section_name,
1342                         ent->name,
1343                         ent->value);
1344         }
1345
1346         free(entries);
1347 }
1348
1349 static void
1350 parse_rxq(struct app_params *app,
1351         const char *section_name,
1352         struct rte_cfgfile *cfg)
1353 {
1354         struct app_pktq_hwq_in_params *param;
1355         struct rte_cfgfile_entry *entries;
1356         int n_entries, ret, i;
1357         ssize_t param_idx;
1358
1359         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1360         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1361
1362         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1363         PARSE_ERROR_MALLOC(entries != NULL);
1364
1365         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1366
1367         param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1368         PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1369
1370         param = &app->hwq_in_params[param_idx];
1371         param->parsed = 1;
1372
1373         for (i = 0; i < n_entries; i++) {
1374                 struct rte_cfgfile_entry *ent = &entries[i];
1375
1376                 ret = -ESRCH;
1377                 if (strcmp(ent->name, "mempool") == 0) {
1378                         int status = validate_name(ent->value, "MEMPOOL", 1);
1379                         ssize_t idx;
1380
1381                         APP_CHECK((status == 0),
1382                                 "CFG: [%s] entry '%s': invalid mempool\n",
1383                                 section_name,
1384                                 ent->name);
1385
1386                         idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1387                         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1388                         param->mempool_id = idx;
1389                         ret = 0;
1390                 } else if (strcmp(ent->name, "size") == 0)
1391                         ret = parser_read_uint32(&param->size,
1392                                 ent->value);
1393                 else if (strcmp(ent->name, "burst") == 0)
1394                         ret = parser_read_uint32(&param->burst,
1395                                 ent->value);
1396
1397                 APP_CHECK(ret != -ESRCH,
1398                         "CFG: [%s] entry '%s': unknown entry\n",
1399                         section_name,
1400                         ent->name);
1401                 APP_CHECK(ret == 0,
1402                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1403                         section_name,
1404                         ent->name,
1405                         ent->value);
1406         }
1407
1408         free(entries);
1409 }
1410
1411 static void
1412 parse_txq(struct app_params *app,
1413         const char *section_name,
1414         struct rte_cfgfile *cfg)
1415 {
1416         struct app_pktq_hwq_out_params *param;
1417         struct rte_cfgfile_entry *entries;
1418         int n_entries, ret, i;
1419         ssize_t param_idx;
1420
1421         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1422         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1423
1424         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1425         PARSE_ERROR_MALLOC(entries != NULL);
1426
1427         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1428
1429         param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1430         PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1431
1432         param = &app->hwq_out_params[param_idx];
1433         param->parsed = 1;
1434
1435         for (i = 0; i < n_entries; i++) {
1436                 struct rte_cfgfile_entry *ent = &entries[i];
1437
1438                 ret = -ESRCH;
1439                 if (strcmp(ent->name, "size") == 0)
1440                         ret = parser_read_uint32(&param->size, ent->value);
1441                 else if (strcmp(ent->name, "burst") == 0)
1442                         ret = parser_read_uint32(&param->burst, ent->value);
1443                 else if (strcmp(ent->name, "dropless") == 0) {
1444                         ret = parser_read_arg_bool(ent->value);
1445                         if (ret >= 0) {
1446                                 param->dropless = ret;
1447                                 ret = 0;
1448                         }
1449                 }
1450
1451                 APP_CHECK(ret != -ESRCH,
1452                         "CFG: [%s] entry '%s': unknown entry\n",
1453                         section_name,
1454                         ent->name);
1455                 APP_CHECK(ret == 0,
1456                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1457                         section_name,
1458                         ent->name,
1459                         ent->value);
1460         }
1461
1462         free(entries);
1463 }
1464
1465 static void
1466 parse_swq(struct app_params *app,
1467         const char *section_name,
1468         struct rte_cfgfile *cfg)
1469 {
1470         struct app_pktq_swq_params *param;
1471         struct rte_cfgfile_entry *entries;
1472         int n_entries, ret, i;
1473         unsigned frag_entries = 0;
1474         ssize_t param_idx;
1475
1476         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1477         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1478
1479         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1480         PARSE_ERROR_MALLOC(entries != NULL);
1481
1482         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1483
1484         param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1485         PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1486
1487         param = &app->swq_params[param_idx];
1488         param->parsed = 1;
1489
1490         for (i = 0; i < n_entries; i++) {
1491                 struct rte_cfgfile_entry *ent = &entries[i];
1492
1493                 ret = -ESRCH;
1494                 if (strcmp(ent->name, "size") == 0)
1495                         ret = parser_read_uint32(&param->size,
1496                                 ent->value);
1497                 else if (strcmp(ent->name, "burst_read") == 0)
1498                         ret = parser_read_uint32(&param->burst_read,
1499                                 ent->value);
1500                 else if (strcmp(ent->name, "burst_write") == 0)
1501                         ret = parser_read_uint32(&param->burst_write,
1502                                 ent->value);
1503                 else if (strcmp(ent->name, "dropless") == 0) {
1504                         ret = parser_read_arg_bool(ent->value);
1505                         if (ret >= 0) {
1506                                 param->dropless = ret;
1507                                 ret = 0;
1508                         }
1509                 } else if (strcmp(ent->name, "n_retries") == 0)
1510                         ret = parser_read_uint64(&param->n_retries,
1511                                 ent->value);
1512                 else if (strcmp(ent->name, "cpu") == 0)
1513                         ret = parser_read_uint32(&param->cpu_socket_id,
1514                                 ent->value);
1515                 else if (strcmp(ent->name, "ipv4_frag") == 0) {
1516                         ret = parser_read_arg_bool(ent->value);
1517                         if (ret >= 0) {
1518                                 param->ipv4_frag = ret;
1519                                 if (param->mtu == 0)
1520                                         param->mtu = 1500;
1521                                 ret = 0;
1522                         }
1523                 } else if (strcmp(ent->name, "ipv6_frag") == 0) {
1524                         ret = parser_read_arg_bool(ent->value);
1525                         if (ret >= 0) {
1526                                 param->ipv6_frag = ret;
1527                                 if (param->mtu == 0)
1528                                         param->mtu = 1320;
1529                                 ret = 0;
1530                         }
1531                 } else if (strcmp(ent->name, "ipv4_ras") == 0) {
1532                         ret = parser_read_arg_bool(ent->value);
1533                         if (ret >= 0) {
1534                                 param->ipv4_ras = ret;
1535                                 ret = 0;
1536                         }
1537                 } else if (strcmp(ent->name, "ipv6_ras") == 0) {
1538                         ret = parser_read_arg_bool(ent->value);
1539                         if (ret >= 0) {
1540                                 param->ipv6_ras = ret;
1541                                 ret = 0;
1542                         }
1543                 } else if (strcmp(ent->name, "mtu") == 0) {
1544                         frag_entries = 1;
1545                         ret = parser_read_uint32(&param->mtu,
1546                                 ent->value);
1547                 } else if (strcmp(ent->name, "metadata_size") == 0) {
1548                         frag_entries = 1;
1549                         ret = parser_read_uint32(&param->metadata_size,
1550                                 ent->value);
1551                 } else if (strcmp(ent->name, "mempool_direct") == 0) {
1552                         int status = validate_name(ent->value, "MEMPOOL", 1);
1553                         ssize_t idx;
1554
1555                         APP_CHECK((status == 0),
1556                                 "CFG: [%s] entry '%s': invalid mempool\n",
1557                                 section_name,
1558                                 ent->name);
1559
1560                         idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1561                         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1562                         param->mempool_direct_id = idx;
1563                         frag_entries = 1;
1564                         ret = 0;
1565                 } else if (strcmp(ent->name, "mempool_indirect") == 0) {
1566                         int status = validate_name(ent->value, "MEMPOOL", 1);
1567                         ssize_t idx;
1568
1569                         APP_CHECK((status == 0),
1570                                 "CFG: [%s] entry '%s': invalid mempool\n",
1571                                 section_name,
1572                                 ent->name);
1573
1574                         idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1575                         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1576                         param->mempool_indirect_id = idx;
1577                         frag_entries = 1;
1578                         ret = 0;
1579                 }
1580
1581                 APP_CHECK(ret != -ESRCH,
1582                         "CFG: [%s] entry '%s': unknown entry\n",
1583                         section_name,
1584                         ent->name);
1585                 APP_CHECK(ret == 0,
1586                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1587                         section_name,
1588                         ent->name,
1589                         ent->value);
1590         }
1591
1592         if (frag_entries == 1) {
1593                 APP_CHECK(((param->ipv4_frag == 1) || (param->ipv6_frag == 1)),
1594                         "CFG: [%s] ipv4/ipv6 frag is off : unsupported entries on this"
1595                         " configuration\n",
1596                         section_name);
1597         }
1598
1599         free(entries);
1600 }
1601
1602 static void
1603 parse_tm(struct app_params *app,
1604         const char *section_name,
1605         struct rte_cfgfile *cfg)
1606 {
1607         struct app_pktq_tm_params *param;
1608         struct rte_cfgfile_entry *entries;
1609         int n_entries, ret, i;
1610         ssize_t param_idx;
1611
1612         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1613         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1614
1615         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1616         PARSE_ERROR_MALLOC(entries != NULL);
1617
1618         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1619
1620         param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1621         PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
1622
1623         param = &app->tm_params[param_idx];
1624         param->parsed = 1;
1625
1626         for (i = 0; i < n_entries; i++) {
1627                 struct rte_cfgfile_entry *ent = &entries[i];
1628
1629                 ret = -ESRCH;
1630                 if (strcmp(ent->name, "cfg") == 0) {
1631                         param->file_name = strdup(ent->value);
1632                         if (param->file_name == NULL)
1633                                 ret = -EINVAL;
1634
1635                         ret = 0;
1636                 } else if (strcmp(ent->name, "burst_read") == 0)
1637                         ret = parser_read_uint32(&param->burst_read,
1638                                 ent->value);
1639                 else if (strcmp(ent->name, "burst_write") == 0)
1640                         ret = parser_read_uint32(&param->burst_write,
1641                                 ent->value);
1642
1643                 APP_CHECK(ret != -ESRCH,
1644                         "CFG: [%s] entry '%s': unknown entry\n",
1645                         section_name,
1646                         ent->name);
1647                 APP_CHECK(ret != -EBADF,
1648                         "CFG: [%s] entry '%s': TM cfg parse error '%s'\n",
1649                         section_name,
1650                         ent->name,
1651                         ent->value);
1652                 APP_CHECK(ret == 0,
1653                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1654                         section_name,
1655                         ent->name,
1656                         ent->value);
1657         }
1658
1659         free(entries);
1660 }
1661
1662 static void
1663 parse_source(struct app_params *app,
1664         const char *section_name,
1665         struct rte_cfgfile *cfg)
1666 {
1667         struct app_pktq_source_params *param;
1668         struct rte_cfgfile_entry *entries;
1669         int n_entries, ret, i;
1670         ssize_t param_idx;
1671
1672         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1673         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1674
1675         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1676         PARSE_ERROR_MALLOC(entries != NULL);
1677
1678         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1679
1680         param_idx = APP_PARAM_ADD(app->source_params, section_name);
1681         PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
1682
1683         param = &app->source_params[param_idx];
1684         param->parsed = 1;
1685
1686         for (i = 0; i < n_entries; i++) {
1687                 struct rte_cfgfile_entry *ent = &entries[i];
1688
1689                 ret = -ESRCH;
1690                 if (strcmp(ent->name, "mempool") == 0) {
1691                         int status = validate_name(ent->value, "MEMPOOL", 1);
1692                         ssize_t idx;
1693
1694                         APP_CHECK((status == 0),
1695                                 "CFG: [%s] entry '%s': invalid mempool\n",
1696                                         section_name,
1697                                         ent->name);
1698
1699                         idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1700                         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1701                         param->mempool_id = idx;
1702                         ret = 0;
1703                 } else if (strcmp(ent->name, "burst") == 0)
1704                         ret = parser_read_uint32(&param->burst, ent->value);
1705
1706                 APP_CHECK(ret != -ESRCH,
1707                         "CFG: [%s] entry '%s': unknown entry\n",
1708                         section_name,
1709                         ent->name);
1710                 APP_CHECK(ret == 0,
1711                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1712                         section_name,
1713                         ent->name,
1714                         ent->value);
1715         }
1716
1717         free(entries);
1718 }
1719
1720 static void
1721 parse_msgq_req_pipeline(struct app_params *app,
1722         const char *section_name,
1723         struct rte_cfgfile *cfg)
1724 {
1725         struct app_msgq_params *param;
1726         struct rte_cfgfile_entry *entries;
1727         int n_entries, ret, i;
1728         ssize_t param_idx;
1729
1730         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1731         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1732
1733         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1734         PARSE_ERROR_MALLOC(entries != NULL);
1735
1736         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1737
1738         param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1739         PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1740
1741         param = &app->msgq_params[param_idx];
1742         param->parsed = 1;
1743
1744         for (i = 0; i < n_entries; i++) {
1745                 struct rte_cfgfile_entry *ent = &entries[i];
1746
1747                 ret = -ESRCH;
1748                 if (strcmp(ent->name, "size") == 0)
1749                         ret = parser_read_uint32(&param->size, ent->value);
1750
1751                 APP_CHECK(ret != -ESRCH,
1752                         "CFG: [%s] entry '%s': unknown entry\n",
1753                         section_name,
1754                         ent->name);
1755                 APP_CHECK(ret == 0,
1756                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1757                         section_name,
1758                         ent->name,
1759                         ent->value);
1760         }
1761
1762         free(entries);
1763 }
1764
1765 static void
1766 parse_msgq_rsp_pipeline(struct app_params *app,
1767         const char *section_name,
1768         struct rte_cfgfile *cfg)
1769 {
1770         struct app_msgq_params *param;
1771         struct rte_cfgfile_entry *entries;
1772         int n_entries, ret, i;
1773         ssize_t param_idx;
1774
1775         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1776         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1777
1778         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1779         PARSE_ERROR_MALLOC(entries != NULL);
1780
1781         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1782
1783         param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1784         PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1785
1786         param = &app->msgq_params[param_idx];
1787         param->parsed = 1;
1788
1789         for (i = 0; i < n_entries; i++) {
1790                 struct rte_cfgfile_entry *ent = &entries[i];
1791
1792                 ret = -ESRCH;
1793                 if (strcmp(ent->name, "size") == 0)
1794                         ret = parser_read_uint32(&param->size, ent->value);
1795
1796                 APP_CHECK(ret != -ESRCH,
1797                         "CFG: [%s] entry '%s': unknown entry\n",
1798                         section_name,
1799                         ent->name);
1800                 APP_CHECK(ret == 0,
1801                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1802                         section_name,
1803                         ent->name,
1804                         ent->value);
1805         }
1806
1807         free(entries);
1808 }
1809
1810 static void
1811 parse_msgq(struct app_params *app,
1812         const char *section_name,
1813         struct rte_cfgfile *cfg)
1814 {
1815         struct app_msgq_params *param;
1816         struct rte_cfgfile_entry *entries;
1817         int n_entries, ret, i;
1818         ssize_t param_idx;
1819
1820         n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1821         PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1822
1823         entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1824         PARSE_ERROR_MALLOC(entries != NULL);
1825
1826         rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1827
1828         param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1829         PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1830
1831         param = &app->msgq_params[param_idx];
1832         param->parsed = 1;
1833
1834         for (i = 0; i < n_entries; i++) {
1835                 struct rte_cfgfile_entry *ent = &entries[i];
1836
1837                 ret = -ESRCH;
1838                 if (strcmp(ent->name, "size") == 0)
1839                         ret = parser_read_uint32(&param->size,
1840                                 ent->value);
1841                 else if (strcmp(ent->name, "cpu") == 0)
1842                         ret = parser_read_uint32(&param->cpu_socket_id,
1843                                 ent->value);
1844
1845                 APP_CHECK(ret != -ESRCH,
1846                         "CFG: [%s] entry '%s': unknown entry\n",
1847                         section_name,
1848                         ent->name);
1849                 APP_CHECK(ret == 0,
1850                         "CFG: [%s] entry '%s': Invalid value '%s'\n",
1851                         section_name,
1852                         ent->name,
1853                         ent->value);
1854         }
1855
1856         free(entries);
1857 }
1858
1859 typedef void (*config_section_load)(struct app_params *p,
1860         const char *section_name,
1861         struct rte_cfgfile *cfg);
1862
1863 struct config_section {
1864         const char prefix[CFG_NAME_LEN];
1865         int numbers;
1866         config_section_load load;
1867 };
1868
1869 static const struct config_section cfg_file_scheme[] = {
1870         {"EAL", 0, parse_eal},
1871         {"PIPELINE", 1, parse_pipeline},
1872         {"MEMPOOL", 1, parse_mempool},
1873         {"LINK", 1, parse_link},
1874         {"RXQ", 2, parse_rxq},
1875         {"TXQ", 2, parse_txq},
1876         {"SWQ", 1, parse_swq},
1877         {"TM", 1, parse_tm},
1878         {"SOURCE", 1, parse_source},
1879         {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
1880         {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
1881         {"MSGQ", 1, parse_msgq},
1882 };
1883
1884 static void
1885 create_implicit_mempools(struct app_params *app)
1886 {
1887         ssize_t idx;
1888
1889         idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
1890         PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, "start-up");
1891 }
1892
1893 static void
1894 parse_port_mask(struct app_params *app, uint64_t port_mask)
1895 {
1896         uint32_t pmd_id, link_id;
1897
1898         link_id = 0;
1899         for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
1900                 char name[APP_PARAM_NAME_SIZE];
1901                 ssize_t idx;
1902
1903                 if ((port_mask & (1LLU << pmd_id)) == 0)
1904                         continue;
1905
1906                 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
1907                 idx = APP_PARAM_ADD(app->link_params, name);
1908                 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, name);
1909
1910                 app->link_params[idx].pmd_id = pmd_id;
1911                 link_id++;
1912         }
1913 }
1914
1915 int
1916 app_config_parse(struct app_params *app, const char *file_name)
1917 {
1918         struct rte_cfgfile *cfg;
1919         char **section_names;
1920         int i, j, sect_count;
1921
1922         /* Implicit mempools */
1923         create_implicit_mempools(app);
1924
1925         /* Port mask */
1926         parse_port_mask(app, app->port_mask);
1927
1928         /* Load application configuration file */
1929         cfg = rte_cfgfile_load(file_name, 0);
1930         APP_CHECK(cfg != NULL, "Unable to load config file %s", file_name);
1931
1932         sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
1933         APP_CHECK(sect_count > 0, "Number of sections return %d", sect_count);
1934
1935         section_names = malloc(sect_count * sizeof(char *));
1936         APP_CHECK(section_names != NULL, "Failed to allocate memory");
1937
1938         for (i = 0; i < sect_count; i++)
1939                 section_names[i] = malloc(CFG_NAME_LEN);
1940
1941         rte_cfgfile_sections(cfg, section_names, sect_count);
1942
1943         for (i = 0; i < sect_count; i++) {
1944                 const struct config_section *sch_s;
1945                 int len, cfg_name_len;
1946
1947                 cfg_name_len = strlen(section_names[i]);
1948
1949                 /* Find section type */
1950                 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
1951                         sch_s = &cfg_file_scheme[j];
1952                         len = strlen(sch_s->prefix);
1953
1954                         if (cfg_name_len < len)
1955                                 continue;
1956
1957                         /* After section name we expect only '\0' or digit or
1958                          * digit dot digit, so protect against false matching,
1959                          * for example: "ABC" should match section name
1960                          * "ABC0.0", but it should not match section_name
1961                          * "ABCDEF".
1962                          */
1963                         if ((section_names[i][len] != '\0') &&
1964                                 !isdigit(section_names[i][len]))
1965                                 continue;
1966
1967                         if (strncmp(sch_s->prefix, section_names[i], len) == 0)
1968                                 break;
1969                 }
1970
1971                 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
1972                         "Unknown section %s",
1973                         section_names[i]);
1974
1975                 APP_CHECK(validate_name(section_names[i],
1976                         sch_s->prefix,
1977                         sch_s->numbers) == 0,
1978                         "Invalid section name '%s'",
1979                         section_names[i]);
1980
1981                 sch_s->load(app, section_names[i], cfg);
1982         }
1983
1984         for (i = 0; i < sect_count; i++)
1985                 free(section_names[i]);
1986
1987         free(section_names);
1988
1989         rte_cfgfile_close(cfg);
1990
1991         APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
1992         APP_PARAM_COUNT(app->link_params, app->n_links);
1993         APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
1994         APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
1995         APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
1996         APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
1997         APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
1998         APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
1999         APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2000         APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2001
2002         /* Save configuration to output file */
2003         app_config_save(app, app->output_file);
2004
2005         /* Load TM configuration files */
2006         app_config_parse_tm(app);
2007
2008         return 0;
2009 }
2010
2011 static void
2012 save_eal_params(struct app_params *app, FILE *f)
2013 {
2014         struct app_eal_params *p = &app->eal_params;
2015
2016         fprintf(f, "[EAL]\n");
2017
2018         if (p->coremap)
2019                 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2020
2021         if (p->master_lcore_present)
2022                 fprintf(f, "%s = %" PRIu32 "\n",
2023                         "master_lcore", p->master_lcore);
2024
2025         fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2026
2027         if (p->memory_present)
2028                 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2029
2030         if (p->ranks_present)
2031                 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2032
2033         if (p->pci_blacklist)
2034                 fprintf(f, "%s = %s\n", "pci_blacklist", p->pci_blacklist);
2035
2036         if (p->pci_whitelist)
2037                 fprintf(f, "%s = %s\n", "pci_whitelist", p->pci_whitelist);
2038
2039         if (p->vdev)
2040                 fprintf(f, "%s = %s\n", "vdev", p->vdev);
2041
2042         if (p->vmware_tsc_map_present)
2043                 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2044                         (p->vmware_tsc_map) ? "yes" : "no");
2045
2046         if (p->proc_type)
2047                 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2048
2049         if (p->syslog)
2050                 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2051
2052         if (p->log_level_present)
2053                 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2054
2055         if (p->version_present)
2056                 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2057
2058         if (p->help_present)
2059                 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2060
2061         if (p->no_huge_present)
2062                 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2063
2064         if (p->no_pci_present)
2065                 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2066
2067         if (p->no_hpet_present)
2068                 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2069
2070         if (p->no_shconf_present)
2071                 fprintf(f, "%s = %s\n", "no_shconf",
2072                         (p->no_shconf) ? "yes" : "no");
2073
2074         if (p->add_driver)
2075                 fprintf(f, "%s = %s\n", "d", p->add_driver);
2076
2077         if (p->socket_mem)
2078                 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2079
2080         if (p->huge_dir)
2081                 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2082
2083         if (p->file_prefix)
2084                 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2085
2086         if (p->base_virtaddr)
2087                 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2088
2089         if (p->create_uio_dev_present)
2090                 fprintf(f, "%s = %s\n", "create_uio_dev",
2091                         (p->create_uio_dev) ? "yes" : "no");
2092
2093         if (p->vfio_intr)
2094                 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2095
2096         if (p->xen_dom0_present)
2097                 fprintf(f, "%s = %s\n", "xen_dom0",
2098                         (p->xen_dom0) ? "yes" : "no");
2099
2100         fputc('\n', f);
2101 }
2102
2103 static void
2104 save_mempool_params(struct app_params *app, FILE *f)
2105 {
2106         struct app_mempool_params *p;
2107         size_t i, count;
2108
2109         count = RTE_DIM(app->mempool_params);
2110         for (i = 0; i < count; i++) {
2111                 p = &app->mempool_params[i];
2112                 if (!APP_PARAM_VALID(p))
2113                         continue;
2114
2115                 fprintf(f, "[%s]\n", p->name);
2116                 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2117                 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2118                 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2119                 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2120
2121                 fputc('\n', f);
2122         }
2123 }
2124
2125 static void
2126 save_links_params(struct app_params *app, FILE *f)
2127 {
2128         struct app_link_params *p;
2129         size_t i, count;
2130
2131         count = RTE_DIM(app->link_params);
2132         for (i = 0; i < count; i++) {
2133                 p = &app->link_params[i];
2134                 if (!APP_PARAM_VALID(p))
2135                         continue;
2136
2137                 fprintf(f, "[%s]\n", p->name);
2138                 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2139                 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2140                 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2141                 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_local_q",
2142                         p->tcp_syn_local_q);
2143                 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2144                 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2145                 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2146                 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2147                         p->sctp_local_q);
2148
2149                 fputc('\n', f);
2150         }
2151 }
2152
2153 static void
2154 save_rxq_params(struct app_params *app, FILE *f)
2155 {
2156         struct app_pktq_hwq_in_params *p;
2157         size_t i, count;
2158
2159         count = RTE_DIM(app->hwq_in_params);
2160         for (i = 0; i < count; i++) {
2161                 p = &app->hwq_in_params[i];
2162                 if (!APP_PARAM_VALID(p))
2163                         continue;
2164
2165                 fprintf(f, "[%s]\n", p->name);
2166                 fprintf(f, "%s = %s\n",
2167                         "mempool",
2168                         app->mempool_params[p->mempool_id].name);
2169                 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2170                 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2171
2172                 fputc('\n', f);
2173         }
2174 }
2175
2176 static void
2177 save_txq_params(struct app_params *app, FILE *f)
2178 {
2179         struct app_pktq_hwq_out_params *p;
2180         size_t i, count;
2181
2182         count = RTE_DIM(app->hwq_out_params);
2183         for (i = 0; i < count; i++) {
2184                 p = &app->hwq_out_params[i];
2185                 if (!APP_PARAM_VALID(p))
2186                         continue;
2187
2188                 fprintf(f, "[%s]\n", p->name);
2189                 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2190                 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2191                 fprintf(f, "%s = %s\n",
2192                         "dropless",
2193                         p->dropless ? "yes" : "no");
2194
2195                 fputc('\n', f);
2196         }
2197 }
2198
2199 static void
2200 save_swq_params(struct app_params *app, FILE *f)
2201 {
2202         struct app_pktq_swq_params *p;
2203         size_t i, count;
2204
2205         count = RTE_DIM(app->swq_params);
2206         for (i = 0; i < count; i++) {
2207                 p = &app->swq_params[i];
2208                 if (!APP_PARAM_VALID(p))
2209                         continue;
2210
2211                 fprintf(f, "[%s]\n", p->name);
2212                 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2213                 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2214                 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2215                 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2216                 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2217                 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2218                 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2219                 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2220                 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2221                 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2222                 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2223                         fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2224                         fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2225                         fprintf(f, "%s = %s\n",
2226                                 "mempool_direct",
2227                                 app->mempool_params[p->mempool_direct_id].name);
2228                         fprintf(f, "%s = %s\n",
2229                                 "mempool_indirect",
2230                                 app->mempool_params[p->mempool_indirect_id].name);
2231                 }
2232
2233                 fputc('\n', f);
2234         }
2235 }
2236
2237 static void
2238 save_tm_params(struct app_params *app, FILE *f)
2239 {
2240         struct app_pktq_tm_params *p;
2241         size_t i, count;
2242
2243         count = RTE_DIM(app->tm_params);
2244         for (i = 0; i < count; i++) {
2245                 p = &app->tm_params[i];
2246                 if (!APP_PARAM_VALID(p))
2247                         continue;
2248
2249                 fprintf(f, "[%s]\n", p->name);
2250                 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2251                 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2252                 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2253
2254                 fputc('\n', f);
2255         }
2256 }
2257
2258 static void
2259 save_source_params(struct app_params *app, FILE *f)
2260 {
2261         struct app_pktq_source_params *p;
2262         size_t i, count;
2263
2264         count = RTE_DIM(app->source_params);
2265         for (i = 0; i < count; i++) {
2266                 p = &app->source_params[i];
2267                 if (!APP_PARAM_VALID(p))
2268                         continue;
2269
2270                 fprintf(f, "[%s]\n", p->name);
2271                 fprintf(f, "%s = %s\n",
2272                         "mempool",
2273                         app->mempool_params[p->mempool_id].name);
2274                 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2275                 fputc('\n', f);
2276         }
2277 }
2278
2279 static void
2280 save_msgq_params(struct app_params *app, FILE *f)
2281 {
2282         struct app_msgq_params *p;
2283         size_t i, count;
2284
2285         count = RTE_DIM(app->msgq_params);
2286         for (i = 0; i < count; i++) {
2287                 p = &app->msgq_params[i];
2288                 if (!APP_PARAM_VALID(p))
2289                         continue;
2290
2291                 fprintf(f, "[%s]\n", p->name);
2292                 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2293                 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2294
2295                 fputc('\n', f);
2296         }
2297 }
2298
2299 static void
2300 save_pipeline_params(struct app_params *app, FILE *f)
2301 {
2302         size_t i, count;
2303
2304         count = RTE_DIM(app->pipeline_params);
2305         for (i = 0; i < count; i++) {
2306                 struct app_pipeline_params *p = &app->pipeline_params[i];
2307
2308                 if (!APP_PARAM_VALID(p))
2309                         continue;
2310
2311                 /* section name */
2312                 fprintf(f, "[%s]\n", p->name);
2313
2314                 /* type */
2315                 fprintf(f, "type = %s\n", p->type);
2316
2317                 /* core */
2318                 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2319                         p->socket_id,
2320                         p->core_id,
2321                         (p->hyper_th_id) ? "h" : "");
2322
2323                 /* pktq_in */
2324                 if (p->n_pktq_in) {
2325                         uint32_t j;
2326
2327                         fprintf(f, "pktq_in =");
2328                         for (j = 0; j < p->n_pktq_in; j++) {
2329                                 struct app_pktq_in_params *pp = &p->pktq_in[j];
2330                                 char *name;
2331
2332                                 switch (pp->type) {
2333                                 case APP_PKTQ_IN_HWQ:
2334                                         name = app->hwq_in_params[pp->id].name;
2335                                         break;
2336                                 case APP_PKTQ_IN_SWQ:
2337                                         name = app->swq_params[pp->id].name;
2338                                         break;
2339                                 case APP_PKTQ_IN_TM:
2340                                         name = app->tm_params[pp->id].name;
2341                                         break;
2342                                 case APP_PKTQ_IN_SOURCE:
2343                                         name = app->source_params[pp->id].name;
2344                                         break;
2345                                 default:
2346                                         APP_CHECK(0, "Error\n");
2347                                 }
2348
2349                                 fprintf(f, " %s", name);
2350                         }
2351                         fprintf(f, "\n");
2352                 }
2353
2354                 /* pktq_in */
2355                 if (p->n_pktq_out) {
2356                         uint32_t j;
2357
2358                         fprintf(f, "pktq_out =");
2359                         for (j = 0; j < p->n_pktq_out; j++) {
2360                                 struct app_pktq_out_params *pp =
2361                                         &p->pktq_out[j];
2362                                 char *name;
2363
2364                                 switch (pp->type) {
2365                                 case APP_PKTQ_OUT_HWQ:
2366                                         name = app->hwq_out_params[pp->id].name;
2367                                         break;
2368                                 case APP_PKTQ_OUT_SWQ:
2369                                         name = app->swq_params[pp->id].name;
2370                                         break;
2371                                 case APP_PKTQ_OUT_TM:
2372                                         name = app->tm_params[pp->id].name;
2373                                         break;
2374                                 case APP_PKTQ_OUT_SINK:
2375                                         name = app->sink_params[pp->id].name;
2376                                         break;
2377                                 default:
2378                                         APP_CHECK(0, "Error\n");
2379                                 }
2380
2381                                 fprintf(f, " %s", name);
2382                         }
2383                         fprintf(f, "\n");
2384                 }
2385
2386                 /* msgq_in */
2387                 if (p->n_msgq_in) {
2388                         uint32_t j;
2389
2390                         fprintf(f, "msgq_in =");
2391                         for (j = 0; j < p->n_msgq_in; j++) {
2392                                 uint32_t id = p->msgq_in[j];
2393                                 char *name = app->msgq_params[id].name;
2394
2395                                 fprintf(f, " %s", name);
2396                         }
2397                         fprintf(f, "\n");
2398                 }
2399
2400                 /* msgq_out */
2401                 if (p->n_msgq_out) {
2402                         uint32_t j;
2403
2404                         fprintf(f, "msgq_out =");
2405                         for (j = 0; j < p->n_msgq_out; j++) {
2406                                 uint32_t id = p->msgq_out[j];
2407                                 char *name = app->msgq_params[id].name;
2408
2409                                 fprintf(f, " %s", name);
2410                         }
2411                         fprintf(f, "\n");
2412                 }
2413
2414                 /* timer_period */
2415                 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2416
2417                 /* args */
2418                 if (p->n_args) {
2419                         uint32_t j;
2420
2421                         for (j = 0; j < p->n_args; j++)
2422                                 fprintf(f, "%s = %s\n", p->args_name[j],
2423                                         p->args_value[j]);
2424                 }
2425
2426                 fprintf(f, "\n");
2427         }
2428 }
2429
2430 void
2431 app_config_save(struct app_params *app, const char *file_name)
2432 {
2433         FILE *file;
2434         char *name, *dir_name;
2435         int status;
2436
2437         name = strdup(file_name);
2438         dir_name = dirname(name);
2439         status = access(dir_name, W_OK);
2440         APP_CHECK((status == 0),
2441                 "Need write access to directory \"%s\" to save configuration\n",
2442                 dir_name);
2443
2444         file = fopen(file_name, "w");
2445         APP_CHECK((file != NULL),
2446                 "Failed to save configuration to file \"%s\"", file_name);
2447
2448         save_eal_params(app, file);
2449         save_pipeline_params(app, file);
2450         save_mempool_params(app, file);
2451         save_links_params(app, file);
2452         save_rxq_params(app, file);
2453         save_txq_params(app, file);
2454         save_swq_params(app, file);
2455         save_tm_params(app, file);
2456         save_source_params(app, file);
2457         save_msgq_params(app, file);
2458
2459         fclose(file);
2460         free(name);
2461 }
2462
2463 int
2464 app_config_init(struct app_params *app)
2465 {
2466         size_t i;
2467
2468         memcpy(app, &app_params_default, sizeof(struct app_params));
2469
2470         for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2471                 memcpy(&app->mempool_params[i],
2472                         &mempool_params_default,
2473                         sizeof(struct app_mempool_params));
2474
2475         for (i = 0; i < RTE_DIM(app->link_params); i++)
2476                 memcpy(&app->link_params[i],
2477                         &link_params_default,
2478                         sizeof(struct app_link_params));
2479
2480         for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2481                 memcpy(&app->hwq_in_params[i],
2482                         &default_hwq_in_params,
2483                         sizeof(default_hwq_in_params));
2484
2485         for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2486                 memcpy(&app->hwq_out_params[i],
2487                         &default_hwq_out_params,
2488                         sizeof(default_hwq_out_params));
2489
2490         for (i = 0; i < RTE_DIM(app->swq_params); i++)
2491                 memcpy(&app->swq_params[i],
2492                         &default_swq_params,
2493                         sizeof(default_swq_params));
2494
2495         for (i = 0; i < RTE_DIM(app->tm_params); i++)
2496                 memcpy(&app->tm_params[i],
2497                         &default_tm_params,
2498                         sizeof(default_tm_params));
2499
2500         for (i = 0; i < RTE_DIM(app->source_params); i++)
2501                 memcpy(&app->source_params[i],
2502                         &default_source_params,
2503                         sizeof(default_source_params));
2504
2505         for (i = 0; i < RTE_DIM(app->sink_params); i++)
2506                 memcpy(&app->sink_params[i],
2507                         &default_sink_params,
2508                         sizeof(default_sink_params));
2509
2510         for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2511                 memcpy(&app->msgq_params[i],
2512                         &default_msgq_params,
2513                         sizeof(default_msgq_params));
2514
2515         for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2516                 memcpy(&app->pipeline_params[i],
2517                         &default_pipeline_params,
2518                         sizeof(default_pipeline_params));
2519
2520         return 0;
2521 }
2522
2523 static char *
2524 filenamedup(const char *filename, const char *suffix)
2525 {
2526         char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2527
2528         if (!s)
2529                 return NULL;
2530
2531         sprintf(s, "%s%s", filename, suffix);
2532         return s;
2533 }
2534
2535 int
2536 app_config_args(struct app_params *app, int argc, char **argv)
2537 {
2538         const char *optname;
2539         int opt, option_index;
2540         int f_present, s_present, p_present, l_present;
2541         int preproc_present, preproc_params_present;
2542         int scaned = 0;
2543
2544         static struct option lgopts[] = {
2545                 { "preproc", 1, 0, 0 },
2546                 { "preproc-args", 1, 0, 0 },
2547                 { NULL,  0, 0, 0 }
2548         };
2549
2550         /* Copy application name */
2551         strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
2552
2553         f_present = 0;
2554         s_present = 0;
2555         p_present = 0;
2556         l_present = 0;
2557         preproc_present = 0;
2558         preproc_params_present = 0;
2559
2560         while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
2561                         &option_index)) != EOF)
2562                 switch (opt) {
2563                 case 'f':
2564                         if (f_present)
2565                                 rte_panic("Error: Config file is provided "
2566                                         "more than once\n");
2567                         f_present = 1;
2568
2569                         if (!strlen(optarg))
2570                                 rte_panic("Error: Config file name is null\n");
2571
2572                         app->config_file = strdup(optarg);
2573                         if (app->config_file == NULL)
2574                                 rte_panic("Error: Memory allocation failure\n");
2575
2576                         break;
2577
2578                 case 's':
2579                         if (s_present)
2580                                 rte_panic("Error: Script file is provided "
2581                                         "more than once\n");
2582                         s_present = 1;
2583
2584                         if (!strlen(optarg))
2585                                 rte_panic("Error: Script file name is null\n");
2586
2587                         app->script_file = strdup(optarg);
2588                         if (app->script_file == NULL)
2589                                 rte_panic("Error: Memory allocation failure\n");
2590
2591                         break;
2592
2593                 case 'p':
2594                         if (p_present)
2595                                 rte_panic("Error: PORT_MASK is provided "
2596                                         "more than once\n");
2597                         p_present = 1;
2598
2599                         if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
2600                                 &scaned) != 1) ||
2601                                 ((size_t) scaned != strlen(optarg)))
2602                                 rte_panic("Error: PORT_MASK is not "
2603                                         "a hexadecimal integer\n");
2604
2605                         if (app->port_mask == 0)
2606                                 rte_panic("Error: PORT_MASK is null\n");
2607
2608                         break;
2609
2610                 case 'l':
2611                         if (l_present)
2612                                 rte_panic("Error: LOG_LEVEL is provided "
2613                                         "more than once\n");
2614                         l_present = 1;
2615
2616                         if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
2617                                 &scaned) != 1) ||
2618                                 ((size_t) scaned != strlen(optarg)) ||
2619                                 (app->log_level >= APP_LOG_LEVELS))
2620                                 rte_panic("Error: LOG_LEVEL invalid value\n");
2621
2622                         break;
2623
2624                 case 0:
2625                         optname = lgopts[option_index].name;
2626
2627                         if (strcmp(optname, "preproc") == 0) {
2628                                 if (preproc_present)
2629                                         rte_panic("Error: Preprocessor argument "
2630                                                 "is provided more than once\n");
2631                                 preproc_present = 1;
2632
2633                                 app->preproc = strdup(optarg);
2634                                 break;
2635                         }
2636
2637                         if (strcmp(optname, "preproc-args") == 0) {
2638                                 if (preproc_params_present)
2639                                         rte_panic("Error: Preprocessor args "
2640                                                 "are provided more than once\n");
2641                                 preproc_params_present = 1;
2642
2643                                 app->preproc_args = strdup(optarg);
2644                                 break;
2645                         }
2646
2647                         app_print_usage(argv[0]);
2648                         break;
2649
2650                 default:
2651                         app_print_usage(argv[0]);
2652                 }
2653
2654         optind = 0; /* reset getopt lib */
2655
2656         /* Check that mandatory args have been provided */
2657         if (!p_present)
2658                 rte_panic("Error: PORT_MASK is not provided\n");
2659
2660         /* Check dependencies between args */
2661         if (preproc_params_present && (preproc_present == 0))
2662                 rte_panic("Error: Preprocessor args specified while "
2663                         "preprocessor is not defined\n");
2664
2665         app->parser_file = preproc_present ?
2666                 filenamedup(app->config_file, ".preproc") :
2667                 strdup(app->config_file);
2668         app->output_file = filenamedup(app->config_file, ".out");
2669
2670         return 0;
2671 }
2672
2673 int
2674 app_config_preproc(struct app_params *app)
2675 {
2676         char buffer[256];
2677         int status;
2678
2679         if (app->preproc == NULL)
2680                 return 0;
2681
2682         status = access(app->config_file, F_OK | R_OK);
2683         APP_CHECK((status == 0), "Unable to open file %s", app->config_file);
2684
2685         snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
2686                 app->preproc,
2687                 app->preproc_args ? app->preproc_args : "",
2688                 app->config_file,
2689                 app->parser_file);
2690
2691         status = system(buffer);
2692         APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
2693                 "Error while preprocessing file \"%s\"\n", app->config_file);
2694
2695         return status;
2696 }