4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
46 #include <rte_errno.h>
47 #include <rte_cfgfile.h>
48 #include <rte_string_fns.h>
54 * Default config values
57 static struct app_params app_params_default = {
58 .config_file = "./config/ip_pipeline.cfg",
59 .log_level = APP_LOG_LEVEL_HIGH,
67 static const struct app_mempool_params mempool_params_default = {
69 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
70 .pool_size = 32 * 1024,
75 static const struct app_link_params link_params_default = {
93 .mq_mode = ETH_MQ_RX_NONE,
95 .header_split = 0, /* Header split */
96 .hw_ip_checksum = 0, /* IP checksum offload */
97 .hw_vlan_filter = 0, /* VLAN filtering */
98 .hw_vlan_strip = 0, /* VLAN strip */
99 .hw_vlan_extend = 0, /* Extended VLAN */
100 .jumbo_frame = 0, /* Jumbo frame support */
101 .hw_strip_crc = 0, /* CRC strip by HW */
102 .enable_scatter = 0, /* Scattered packets RX handler */
104 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
105 .split_hdr_size = 0, /* Header split buffer size */
108 .mq_mode = ETH_MQ_TX_NONE,
116 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
128 .rx_free_thresh = 64,
130 .rx_deferred_start = 0,
134 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
149 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
150 ETH_TXQ_FLAGS_NOOFFLOADS,
151 .tx_deferred_start = 0,
155 static const struct app_pktq_swq_params default_swq_params = {
169 .mempool_direct_id = 0,
170 .mempool_indirect_id = 0,
173 struct app_pktq_tm_params default_tm_params = {
175 .file_name = "./config/tm_profile.cfg",
180 struct app_pktq_source_params default_source_params = {
185 .n_bytes_per_pkt = 0,
188 struct app_pktq_sink_params default_sink_params = {
194 struct app_msgq_params default_msgq_params = {
200 struct app_pipeline_params default_pipeline_params = {
213 static const char app_usage[] =
214 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
215 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
218 "\t-f CONFIG_FILE: Default config file is %s\n"
219 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
220 "config file when not provided)\n"
221 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
222 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
223 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
224 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
228 app_print_usage(char *prgname)
230 rte_exit(0, app_usage, prgname, app_params_default.config_file);
233 #define APP_PARAM_ADD(set, key) \
235 ssize_t pos = APP_PARAM_FIND(set, key); \
236 ssize_t size = RTE_DIM(set); \
239 for (pos = 0; pos < size; pos++) { \
240 if (!APP_PARAM_VALID(&((set)[pos]))) \
244 APP_CHECK((pos < size), \
245 "Parse error: size of %s is limited to %u elements",\
246 #set, (uint32_t) size); \
248 (set)[pos].name = strdup(key); \
249 APP_CHECK(((set)[pos].name), \
250 "Parse error: no free memory"); \
255 #define APP_PARAM_ADD_LINK_FOR_RXQ(app, rxq_name) \
257 char link_name[APP_PARAM_NAME_SIZE]; \
258 ssize_t link_param_pos; \
259 uint32_t link_id, queue_id; \
261 sscanf((rxq_name), "RXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
262 sprintf(link_name, "LINK%" PRIu32, link_id); \
263 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
267 #define APP_PARAM_ADD_LINK_FOR_TXQ(app, txq_name) \
269 char link_name[APP_PARAM_NAME_SIZE]; \
270 ssize_t link_param_pos; \
271 uint32_t link_id, queue_id; \
273 sscanf((txq_name), "TXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
274 sprintf(link_name, "LINK%" PRIu32, link_id); \
275 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
279 #define APP_PARAM_ADD_LINK_FOR_TM(app, tm_name) \
281 char link_name[APP_PARAM_NAME_SIZE]; \
282 ssize_t link_param_pos; \
285 sscanf((tm_name), "TM%" SCNu32, &link_id); \
286 sprintf(link_name, "LINK%" PRIu32, link_id); \
287 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
291 #define PARSE_CHECK_DUPLICATE_SECTION(obj) \
293 APP_CHECK(((obj)->parsed == 0), \
294 "Parse error: duplicate \"%s\" section", (obj)->name); \
298 #define PARSE_CHECK_DUPLICATE_SECTION_EAL(obj) \
300 APP_CHECK(((obj)->parsed == 0), \
301 "Parse error: duplicate \"%s\" section", "EAL"); \
305 #define PARSE_ERROR(exp, section, entry) \
306 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"", section, entry)
308 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
309 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s", \
310 section, entry, message)
312 #define PARSE_ERROR_NO_ELEMENTS(exp, section, entry) \
313 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
314 "no elements detected", \
317 #define PARSE_ERROR_TOO_MANY_ELEMENTS(exp, section, entry, max) \
318 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
319 "maximum number of elements allowed is %u", \
322 #define PARSE_ERROR_INVALID_ELEMENT(exp, section, entry, value) \
323 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
324 "Invalid element value \"%s\"", \
325 section, entry, value)
327 #define PARSE_ERROR_MALLOC(exp) \
328 APP_CHECK(exp, "Parse error: no free memory")
330 #define PARSE_ERROR_SECTION(exp, section) \
331 APP_CHECK(exp, "Parse error in section \"%s\"", section)
333 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
334 APP_CHECK(exp, "Parse error in section \"%s\": no entries", section)
336 #define PARSE_WARNING_IGNORED(exp, section, entry) \
339 fprintf(stderr, "Parse warning in section \"%s\": " \
340 "entry \"%s\" is ignored", section, entry); \
343 #define PARSE_ERROR_INVALID(exp, section, entry) \
344 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"",\
347 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
348 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"", \
352 validate_name(const char *name, const char *prefix, int num)
356 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
357 if (name[i] != prefix[i])
361 if (prefix[i] != '\0')
372 j = skip_digits(&name[i]);
374 if ((j == 0) || (name[i] != '.'))
380 j = skip_digits(&name[i]);
382 if ((j == 0) || (name[i] != '\0'))
390 parse_eal(struct app_params *app,
391 const char *section_name,
392 struct rte_cfgfile *cfg)
394 struct app_eal_params *p = &app->eal_params;
395 struct rte_cfgfile_entry *entries;
398 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
399 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
401 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
402 PARSE_ERROR_MALLOC(entries != NULL);
404 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
406 PARSE_CHECK_DUPLICATE_SECTION_EAL(p);
408 for (i = 0; i < n_entries; i++) {
409 struct rte_cfgfile_entry *entry = &entries[i];
412 if (strcmp(entry->name, "c") == 0) {
413 PARSE_WARNING_IGNORED(0, section_name, entry->name);
418 if (strcmp(entry->name, "l") == 0) {
419 PARSE_WARNING_IGNORED(0, section_name, entry->name);
424 if (strcmp(entry->name, "lcores") == 0) {
425 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
428 p->coremap = strdup(entry->value);
433 if (strcmp(entry->name, "master_lcore") == 0) {
436 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
439 p->master_lcore_present = 1;
441 status = parser_read_uint32(&p->master_lcore,
443 PARSE_ERROR((status == 0), section_name, entry->name);
448 if (strcmp(entry->name, "n") == 0) {
451 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
454 p->channels_present = 1;
456 status = parser_read_uint32(&p->channels, entry->value);
457 PARSE_ERROR((status == 0), section_name, entry->name);
462 if (strcmp(entry->name, "m") == 0) {
465 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
468 p->memory_present = 1;
470 status = parser_read_uint32(&p->memory, entry->value);
471 PARSE_ERROR((status == 0), section_name, entry->name);
476 if (strcmp(entry->name, "r") == 0) {
479 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
482 p->ranks_present = 1;
484 status = parser_read_uint32(&p->ranks, entry->value);
485 PARSE_ERROR((status == 0), section_name, entry->name);
490 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
491 (strcmp(entry->name, "b") == 0)) {
494 for (i = 0; i < APP_MAX_LINKS; i++) {
495 if (p->pci_blacklist[i])
498 p->pci_blacklist[i] =
499 strdup(entry->value);
500 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
505 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
506 section_name, entry->name,
507 "too many elements");
512 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
513 (strcmp(entry->name, "w") == 0)) {
516 PARSE_ERROR_MESSAGE((app->port_mask != 0),
517 section_name, entry->name, "entry to be "
518 "generated by the application (port_mask "
521 for (i = 0; i < APP_MAX_LINKS; i++) {
522 if (p->pci_whitelist[i])
525 p->pci_whitelist[i] = strdup(entry->value);
526 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
531 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
532 section_name, entry->name,
533 "too many elements");
538 if (strcmp(entry->name, "vdev") == 0) {
541 for (i = 0; i < APP_MAX_LINKS; i++) {
545 p->vdev[i] = strdup(entry->value);
546 PARSE_ERROR_MALLOC(p->vdev[i]);
551 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
552 section_name, entry->name,
553 "too many elements");
558 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
561 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
564 p->vmware_tsc_map_present = 1;
566 val = parser_read_arg_bool(entry->value);
567 PARSE_ERROR((val >= 0), section_name, entry->name);
568 p->vmware_tsc_map = val;
573 if (strcmp(entry->name, "proc_type") == 0) {
574 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
577 p->proc_type = strdup(entry->value);
582 if (strcmp(entry->name, "syslog") == 0) {
583 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
586 p->syslog = strdup(entry->value);
591 if (strcmp(entry->name, "log_level") == 0) {
594 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
597 p->log_level_present = 1;
599 status = parser_read_uint32(&p->log_level,
601 PARSE_ERROR((status == 0), section_name, entry->name);
606 if (strcmp(entry->name, "v") == 0) {
609 PARSE_ERROR_DUPLICATE((p->version_present == 0),
612 p->version_present = 1;
614 val = parser_read_arg_bool(entry->value);
615 PARSE_ERROR((val >= 0), section_name, entry->name);
621 if ((strcmp(entry->name, "help") == 0) ||
622 (strcmp(entry->name, "h") == 0)) {
625 PARSE_ERROR_DUPLICATE((p->help_present == 0),
630 val = parser_read_arg_bool(entry->value);
631 PARSE_ERROR((val >= 0), section_name, entry->name);
637 if (strcmp(entry->name, "no_huge") == 0) {
640 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
643 p->no_huge_present = 1;
645 val = parser_read_arg_bool(entry->value);
646 PARSE_ERROR((val >= 0), section_name, entry->name);
652 if (strcmp(entry->name, "no_pci") == 0) {
655 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
658 p->no_pci_present = 1;
660 val = parser_read_arg_bool(entry->value);
661 PARSE_ERROR((val >= 0), section_name, entry->name);
667 if (strcmp(entry->name, "no_hpet") == 0) {
670 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
673 p->no_hpet_present = 1;
675 val = parser_read_arg_bool(entry->value);
676 PARSE_ERROR((val >= 0), section_name, entry->name);
682 if (strcmp(entry->name, "no_shconf") == 0) {
685 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
688 p->no_shconf_present = 1;
690 val = parser_read_arg_bool(entry->value);
691 PARSE_ERROR((val >= 0), section_name, entry->name);
697 if (strcmp(entry->name, "d") == 0) {
698 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
701 p->add_driver = strdup(entry->value);
706 if (strcmp(entry->name, "socket_mem") == 0) {
707 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
710 p->socket_mem = strdup(entry->value);
715 if (strcmp(entry->name, "huge_dir") == 0) {
716 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
719 p->huge_dir = strdup(entry->value);
724 if (strcmp(entry->name, "file_prefix") == 0) {
725 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
728 p->file_prefix = strdup(entry->value);
733 if (strcmp(entry->name, "base_virtaddr") == 0) {
734 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
737 p->base_virtaddr = strdup(entry->value);
742 if (strcmp(entry->name, "create_uio_dev") == 0) {
745 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
748 p->create_uio_dev_present = 1;
750 val = parser_read_arg_bool(entry->value);
751 PARSE_ERROR((val >= 0), section_name, entry->name);
752 p->create_uio_dev = val;
757 if (strcmp(entry->name, "vfio_intr") == 0) {
758 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
761 p->vfio_intr = strdup(entry->value);
766 if (strcmp(entry->name, "xen_dom0") == 0) {
769 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
772 p->xen_dom0_present = 1;
774 val = parser_read_arg_bool(entry->value);
775 PARSE_ERROR((val >= 0), section_name, entry->name);
781 PARSE_ERROR_INVALID(0, section_name, entry->name);
788 parse_pipeline_pktq_in(struct app_params *app,
789 struct app_pipeline_params *p,
795 enum app_pktq_in_type type;
797 char *name = strtok_r(value, PARSE_DELIMITER, &value);
802 PARSE_ERROR_TOO_MANY_ELEMENTS(
803 (p->n_pktq_in < RTE_DIM(p->pktq_in)),
804 p->name, "pktq_in", (uint32_t)RTE_DIM(p->pktq_in));
806 if (validate_name(name, "RXQ", 2) == 0) {
807 type = APP_PKTQ_IN_HWQ;
808 id = APP_PARAM_ADD(app->hwq_in_params, name);
809 APP_PARAM_ADD_LINK_FOR_RXQ(app, name);
810 } else if (validate_name(name, "SWQ", 1) == 0) {
811 type = APP_PKTQ_IN_SWQ;
812 id = APP_PARAM_ADD(app->swq_params, name);
813 } else if (validate_name(name, "TM", 1) == 0) {
814 type = APP_PKTQ_IN_TM;
815 id = APP_PARAM_ADD(app->tm_params, name);
816 APP_PARAM_ADD_LINK_FOR_TM(app, name);
817 } else if (validate_name(name, "SOURCE", 1) == 0) {
818 type = APP_PKTQ_IN_SOURCE;
819 id = APP_PARAM_ADD(app->source_params, name);
821 PARSE_ERROR_INVALID_ELEMENT(0,
822 p->name, "pktq_in", name);
824 p->pktq_in[p->n_pktq_in].type = type;
825 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
829 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_in > 0), p->name, "pktq_in");
833 parse_pipeline_pktq_out(struct app_params *app,
834 struct app_pipeline_params *p,
840 enum app_pktq_out_type type;
842 char *name = strtok_r(value, PARSE_DELIMITER, &value);
847 PARSE_ERROR_TOO_MANY_ELEMENTS(
848 (p->n_pktq_out < RTE_DIM(p->pktq_out)),
849 p->name, "pktq_out", (uint32_t)RTE_DIM(p->pktq_out));
851 if (validate_name(name, "TXQ", 2) == 0) {
852 type = APP_PKTQ_OUT_HWQ;
853 id = APP_PARAM_ADD(app->hwq_out_params, name);
854 APP_PARAM_ADD_LINK_FOR_TXQ(app, name);
855 } else if (validate_name(name, "SWQ", 1) == 0) {
856 type = APP_PKTQ_OUT_SWQ;
857 id = APP_PARAM_ADD(app->swq_params, name);
858 } else if (validate_name(name, "TM", 1) == 0) {
859 type = APP_PKTQ_OUT_TM;
860 id = APP_PARAM_ADD(app->tm_params, name);
861 APP_PARAM_ADD_LINK_FOR_TM(app, name);
862 } else if (validate_name(name, "SINK", 1) == 0) {
863 type = APP_PKTQ_OUT_SINK;
864 id = APP_PARAM_ADD(app->sink_params, name);
866 PARSE_ERROR_INVALID_ELEMENT(0,
867 p->name, "pktq_out", name);
869 p->pktq_out[p->n_pktq_out].type = type;
870 p->pktq_out[p->n_pktq_out].id = id;
874 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_out > 0), p->name, "pktq_out");
878 parse_pipeline_msgq_in(struct app_params *app,
879 struct app_pipeline_params *p,
886 char *name = strtok_r(value, PARSE_DELIMITER, &value);
891 PARSE_ERROR_TOO_MANY_ELEMENTS(
892 (p->n_msgq_in < RTE_DIM(p->msgq_in)),
893 p->name, "msgq_in", (uint32_t)(RTE_DIM(p->msgq_in)));
895 PARSE_ERROR_INVALID_ELEMENT(
896 (validate_name(name, "MSGQ", 1) == 0),
897 p->name, "msgq_in", name);
899 idx = APP_PARAM_ADD(app->msgq_params, name);
900 p->msgq_in[p->n_msgq_in] = idx;
904 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_in > 0), p->name, "msgq_in");
908 parse_pipeline_msgq_out(struct app_params *app,
909 struct app_pipeline_params *p,
916 char *name = strtok_r(value, PARSE_DELIMITER, &value);
921 PARSE_ERROR_TOO_MANY_ELEMENTS(
922 (p->n_msgq_out < RTE_DIM(p->msgq_out)),
923 p->name, "msgq_out", (uint32_t)RTE_DIM(p->msgq_out));
925 PARSE_ERROR_INVALID_ELEMENT(
926 (validate_name(name, "MSGQ", 1) == 0),
927 p->name, "msgq_out", name);
929 idx = APP_PARAM_ADD(app->msgq_params, name);
930 p->msgq_out[p->n_msgq_out] = idx;
934 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_out > 0), p->name, "msgq_out");
938 parse_pipeline(struct app_params *app,
939 const char *section_name,
940 struct rte_cfgfile *cfg)
942 char name[CFG_NAME_LEN];
943 struct app_pipeline_params *param;
944 struct rte_cfgfile_entry *entries;
948 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
949 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
951 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
952 PARSE_ERROR_MALLOC(entries != NULL);
954 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
956 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
957 param = &app->pipeline_params[param_idx];
958 PARSE_CHECK_DUPLICATE_SECTION(param);
960 for (i = 0; i < n_entries; i++) {
961 struct rte_cfgfile_entry *ent = &entries[i];
963 if (strcmp(ent->name, "type") == 0) {
964 int w_size = snprintf(param->type, RTE_DIM(param->type),
967 PARSE_ERROR(((w_size > 0) &&
968 (w_size < (int)RTE_DIM(param->type))),
974 if (strcmp(ent->name, "core") == 0) {
975 int status = parse_pipeline_core(
976 ¶m->socket_id, ¶m->core_id,
977 ¶m->hyper_th_id, ent->value);
979 PARSE_ERROR((status == 0), section_name,
984 if (strcmp(ent->name, "pktq_in") == 0) {
985 parse_pipeline_pktq_in(app, param, ent->value);
990 if (strcmp(ent->name, "pktq_out") == 0) {
991 parse_pipeline_pktq_out(app, param, ent->value);
996 if (strcmp(ent->name, "msgq_in") == 0) {
997 parse_pipeline_msgq_in(app, param, ent->value);
1002 if (strcmp(ent->name, "msgq_out") == 0) {
1003 parse_pipeline_msgq_out(app, param, ent->value);
1008 if (strcmp(ent->name, "timer_period") == 0) {
1009 int status = parser_read_uint32(
1010 ¶m->timer_period,
1013 PARSE_ERROR((status == 0), section_name,
1018 /* pipeline type specific items */
1019 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1020 "Parse error in section \"%s\": too many "
1021 "pipeline specified parameters", section_name);
1023 param->args_name[param->n_args] = strdup(ent->name);
1024 param->args_value[param->n_args] = strdup(ent->value);
1026 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1027 (param->args_value[param->n_args] != NULL),
1028 "Parse error: no free memory");
1033 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1034 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1035 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1036 param->msgq_in[param->n_msgq_in++] = param_idx;
1038 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1039 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1040 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1041 param->msgq_out[param->n_msgq_out++] = param_idx;
1043 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1046 (param->hyper_th_id) ? "h" : "");
1047 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1048 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1050 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1053 (param->hyper_th_id) ? "h" : "");
1054 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1055 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1061 parse_mempool(struct app_params *app,
1062 const char *section_name,
1063 struct rte_cfgfile *cfg)
1065 struct app_mempool_params *param;
1066 struct rte_cfgfile_entry *entries;
1070 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1071 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1073 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1074 PARSE_ERROR_MALLOC(entries != NULL);
1076 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1078 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1079 param = &app->mempool_params[param_idx];
1080 PARSE_CHECK_DUPLICATE_SECTION(param);
1082 for (i = 0; i < n_entries; i++) {
1083 struct rte_cfgfile_entry *ent = &entries[i];
1085 if (strcmp(ent->name, "buffer_size") == 0) {
1086 int status = parser_read_uint32(
1087 ¶m->buffer_size, ent->value);
1089 PARSE_ERROR((status == 0), section_name,
1094 if (strcmp(ent->name, "pool_size") == 0) {
1095 int status = parser_read_uint32(
1096 ¶m->pool_size, ent->value);
1098 PARSE_ERROR((status == 0), section_name,
1103 if (strcmp(ent->name, "cache_size") == 0) {
1104 int status = parser_read_uint32(
1105 ¶m->cache_size, ent->value);
1107 PARSE_ERROR((status == 0), section_name,
1112 if (strcmp(ent->name, "cpu") == 0) {
1113 int status = parser_read_uint32(
1114 ¶m->cpu_socket_id, ent->value);
1116 PARSE_ERROR((status == 0), section_name,
1122 PARSE_ERROR_INVALID(0, section_name, ent->name);
1129 parse_link(struct app_params *app,
1130 const char *section_name,
1131 struct rte_cfgfile *cfg)
1133 struct app_link_params *param;
1134 struct rte_cfgfile_entry *entries;
1136 int pci_bdf_present = 0;
1139 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1140 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1142 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1143 PARSE_ERROR_MALLOC(entries != NULL);
1145 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1147 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1148 param = &app->link_params[param_idx];
1149 PARSE_CHECK_DUPLICATE_SECTION(param);
1151 for (i = 0; i < n_entries; i++) {
1152 struct rte_cfgfile_entry *ent = &entries[i];
1154 if (strcmp(ent->name, "promisc") == 0) {
1155 int status = parser_read_arg_bool(ent->value);
1157 PARSE_ERROR((status != -EINVAL), section_name,
1159 param->promisc = status;
1163 if (strcmp(ent->name, "arp_q") == 0) {
1164 int status = parser_read_uint32(¶m->arp_q,
1167 PARSE_ERROR((status == 0), section_name,
1172 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1173 int status = parser_read_uint32(
1174 ¶m->tcp_syn_q, ent->value);
1176 PARSE_ERROR((status == 0), section_name, ent->name);
1180 if (strcmp(ent->name, "ip_local_q") == 0) {
1181 int status = parser_read_uint32(
1182 ¶m->ip_local_q, ent->value);
1184 PARSE_ERROR((status == 0), section_name,
1190 if (strcmp(ent->name, "tcp_local_q") == 0) {
1191 int status = parser_read_uint32(
1192 ¶m->tcp_local_q, ent->value);
1194 PARSE_ERROR((status == 0), section_name,
1199 if (strcmp(ent->name, "udp_local_q") == 0) {
1200 int status = parser_read_uint32(
1201 ¶m->udp_local_q, ent->value);
1203 PARSE_ERROR((status == 0), section_name,
1208 if (strcmp(ent->name, "sctp_local_q") == 0) {
1209 int status = parser_read_uint32(
1210 ¶m->sctp_local_q, ent->value);
1212 PARSE_ERROR((status == 0), section_name,
1217 if (strcmp(ent->name, "pci_bdf") == 0) {
1218 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1219 section_name, ent->name);
1221 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1223 pci_bdf_present = 1;
1228 PARSE_ERROR_INVALID(0, section_name, ent->name);
1231 /* Check for mandatory fields */
1233 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1234 section_name, "pci_bdf",
1235 "entry not allowed (port_mask is provided)");
1237 PARSE_ERROR_MESSAGE((pci_bdf_present),
1238 section_name, "pci_bdf",
1239 "this entry is mandatory (port_mask is not "
1246 parse_rxq(struct app_params *app,
1247 const char *section_name,
1248 struct rte_cfgfile *cfg)
1250 struct app_pktq_hwq_in_params *param;
1251 struct rte_cfgfile_entry *entries;
1255 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1256 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1258 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1259 PARSE_ERROR_MALLOC(entries != NULL);
1261 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1263 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1264 param = &app->hwq_in_params[param_idx];
1265 PARSE_CHECK_DUPLICATE_SECTION(param);
1267 APP_PARAM_ADD_LINK_FOR_RXQ(app, section_name);
1269 for (i = 0; i < n_entries; i++) {
1270 struct rte_cfgfile_entry *ent = &entries[i];
1272 if (strcmp(ent->name, "mempool") == 0) {
1273 int status = validate_name(ent->value,
1277 PARSE_ERROR((status == 0), section_name,
1280 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1281 param->mempool_id = idx;
1285 if (strcmp(ent->name, "size") == 0) {
1286 int status = parser_read_uint32(¶m->size,
1289 PARSE_ERROR((status == 0), section_name,
1294 if (strcmp(ent->name, "burst") == 0) {
1295 int status = parser_read_uint32(¶m->burst,
1298 PARSE_ERROR((status == 0), section_name,
1304 PARSE_ERROR_INVALID(0, section_name, ent->name);
1311 parse_txq(struct app_params *app,
1312 const char *section_name,
1313 struct rte_cfgfile *cfg)
1315 struct app_pktq_hwq_out_params *param;
1316 struct rte_cfgfile_entry *entries;
1320 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1321 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1323 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1324 PARSE_ERROR_MALLOC(entries != NULL);
1326 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1328 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1329 param = &app->hwq_out_params[param_idx];
1330 PARSE_CHECK_DUPLICATE_SECTION(param);
1332 APP_PARAM_ADD_LINK_FOR_TXQ(app, section_name);
1334 for (i = 0; i < n_entries; i++) {
1335 struct rte_cfgfile_entry *ent = &entries[i];
1337 if (strcmp(ent->name, "size") == 0) {
1338 int status = parser_read_uint32(¶m->size,
1341 PARSE_ERROR((status == 0), section_name,
1346 if (strcmp(ent->name, "burst") == 0) {
1347 int status = parser_read_uint32(¶m->burst,
1350 PARSE_ERROR((status == 0), section_name,
1355 if (strcmp(ent->name, "dropless") == 0) {
1356 int status = parser_read_arg_bool(ent->value);
1359 PARSE_ERROR((status != -EINVAL), section_name,
1361 param->dropless = status;
1366 PARSE_ERROR_INVALID(0, section_name, ent->name);
1373 parse_swq(struct app_params *app,
1374 const char *section_name,
1375 struct rte_cfgfile *cfg)
1377 struct app_pktq_swq_params *param;
1378 struct rte_cfgfile_entry *entries;
1380 uint32_t mtu_present = 0;
1381 uint32_t metadata_size_present = 0;
1382 uint32_t mempool_direct_present = 0;
1383 uint32_t mempool_indirect_present = 0;
1387 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1388 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1390 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1391 PARSE_ERROR_MALLOC(entries != NULL);
1393 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1395 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1396 param = &app->swq_params[param_idx];
1397 PARSE_CHECK_DUPLICATE_SECTION(param);
1399 for (i = 0; i < n_entries; i++) {
1400 struct rte_cfgfile_entry *ent = &entries[i];
1402 if (strcmp(ent->name, "size") == 0) {
1403 int status = parser_read_uint32(¶m->size,
1406 PARSE_ERROR((status == 0), section_name,
1411 if (strcmp(ent->name, "burst_read") == 0) {
1412 int status = parser_read_uint32(&
1413 param->burst_read, ent->value);
1415 PARSE_ERROR((status == 0), section_name,
1420 if (strcmp(ent->name, "burst_write") == 0) {
1421 int status = parser_read_uint32(
1422 ¶m->burst_write, ent->value);
1424 PARSE_ERROR((status == 0), section_name,
1429 if (strcmp(ent->name, "dropless") == 0) {
1430 int status = parser_read_arg_bool(ent->value);
1432 PARSE_ERROR((status != -EINVAL), section_name,
1434 param->dropless = status;
1438 if (strcmp(ent->name, "n_retries") == 0) {
1439 int status = parser_read_uint64(¶m->n_retries,
1442 PARSE_ERROR((status == 0), section_name,
1447 if (strcmp(ent->name, "cpu") == 0) {
1448 int status = parser_read_uint32(
1449 ¶m->cpu_socket_id, ent->value);
1451 PARSE_ERROR((status == 0), section_name, ent->name);
1455 if (strcmp(ent->name, "ipv4_frag") == 0) {
1456 int status = parser_read_arg_bool(ent->value);
1458 PARSE_ERROR((status != -EINVAL), section_name,
1461 param->ipv4_frag = status;
1462 if (param->mtu == 0)
1468 if (strcmp(ent->name, "ipv6_frag") == 0) {
1469 int status = parser_read_arg_bool(ent->value);
1471 PARSE_ERROR((status != -EINVAL), section_name,
1473 param->ipv6_frag = status;
1474 if (param->mtu == 0)
1479 if (strcmp(ent->name, "ipv4_ras") == 0) {
1480 int status = parser_read_arg_bool(ent->value);
1482 PARSE_ERROR((status != -EINVAL), section_name,
1484 param->ipv4_ras = status;
1488 if (strcmp(ent->name, "ipv6_ras") == 0) {
1489 int status = parser_read_arg_bool(ent->value);
1491 PARSE_ERROR((status != -EINVAL), section_name,
1493 param->ipv6_ras = status;
1497 if (strcmp(ent->name, "mtu") == 0) {
1498 int status = parser_read_uint32(¶m->mtu,
1501 PARSE_ERROR((status == 0), section_name,
1507 if (strcmp(ent->name, "metadata_size") == 0) {
1508 int status = parser_read_uint32(
1509 ¶m->metadata_size, ent->value);
1511 PARSE_ERROR((status == 0), section_name,
1513 metadata_size_present = 1;
1517 if (strcmp(ent->name, "mempool_direct") == 0) {
1518 int status = validate_name(ent->value,
1522 PARSE_ERROR((status == 0), section_name,
1525 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1526 param->mempool_direct_id = idx;
1528 mempool_direct_present = 1;
1532 if (strcmp(ent->name, "mempool_indirect") == 0) {
1533 int status = validate_name(ent->value,
1537 PARSE_ERROR((status == 0), section_name,
1540 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1541 param->mempool_indirect_id = idx;
1543 mempool_indirect_present = 1;
1548 PARSE_ERROR_INVALID(0, section_name, ent->name);
1551 APP_CHECK(((mtu_present == 0) ||
1552 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1553 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1554 "is off, therefore entry \"mtu\" is not allowed",
1557 APP_CHECK(((metadata_size_present == 0) ||
1558 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1559 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1560 "is off, therefore entry \"metadata_size\" is "
1561 "not allowed", section_name);
1563 APP_CHECK(((mempool_direct_present == 0) ||
1564 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1565 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1566 "is off, therefore entry \"mempool_direct\" is "
1567 "not allowed", section_name);
1569 APP_CHECK(((mempool_indirect_present == 0) ||
1570 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1571 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1572 "is off, therefore entry \"mempool_indirect\" is "
1573 "not allowed", section_name);
1579 parse_tm(struct app_params *app,
1580 const char *section_name,
1581 struct rte_cfgfile *cfg)
1583 struct app_pktq_tm_params *param;
1584 struct rte_cfgfile_entry *entries;
1588 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1589 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1591 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1592 PARSE_ERROR_MALLOC(entries != NULL);
1594 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1596 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1597 param = &app->tm_params[param_idx];
1598 PARSE_CHECK_DUPLICATE_SECTION(param);
1600 APP_PARAM_ADD_LINK_FOR_TXQ(app, section_name);
1602 for (i = 0; i < n_entries; i++) {
1603 struct rte_cfgfile_entry *ent = &entries[i];
1605 if (strcmp(ent->name, "cfg") == 0) {
1606 param->file_name = strdup(ent->value);
1607 PARSE_ERROR_MALLOC(param->file_name != NULL);
1611 if (strcmp(ent->name, "burst_read") == 0) {
1612 int status = parser_read_uint32(
1613 ¶m->burst_read, ent->value);
1615 PARSE_ERROR((status == 0), section_name,
1620 if (strcmp(ent->name, "burst_write") == 0) {
1621 int status = parser_read_uint32(
1622 ¶m->burst_write, ent->value);
1624 PARSE_ERROR((status == 0), section_name,
1630 PARSE_ERROR_INVALID(0, section_name, ent->name);
1637 parse_source(struct app_params *app,
1638 const char *section_name,
1639 struct rte_cfgfile *cfg)
1641 struct app_pktq_source_params *param;
1642 struct rte_cfgfile_entry *entries;
1645 uint32_t pcap_file_present = 0;
1646 uint32_t pcap_size_present = 0;
1648 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1649 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1651 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1652 PARSE_ERROR_MALLOC(entries != NULL);
1654 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1656 param_idx = APP_PARAM_ADD(app->source_params, section_name);
1657 param = &app->source_params[param_idx];
1658 PARSE_CHECK_DUPLICATE_SECTION(param);
1660 for (i = 0; i < n_entries; i++) {
1661 struct rte_cfgfile_entry *ent = &entries[i];
1663 if (strcmp(ent->name, "mempool") == 0) {
1664 int status = validate_name(ent->value,
1668 PARSE_ERROR((status == 0), section_name,
1671 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1672 param->mempool_id = idx;
1676 if (strcmp(ent->name, "burst") == 0) {
1677 int status = parser_read_uint32(¶m->burst,
1680 PARSE_ERROR((status == 0), section_name,
1685 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1686 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
1687 section_name, ent->name);
1689 param->file_name = strdup(ent->value);
1691 PARSE_ERROR_MALLOC(param->file_name != NULL);
1692 pcap_file_present = 1;
1697 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1700 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
1701 section_name, ent->name);
1703 status = parser_read_uint32(
1704 ¶m->n_bytes_per_pkt, ent->value);
1706 PARSE_ERROR((status == 0), section_name,
1708 pcap_size_present = 1;
1714 PARSE_ERROR_INVALID(0, section_name, ent->name);
1721 parse_sink(struct app_params *app,
1722 const char *section_name,
1723 struct rte_cfgfile *cfg)
1725 struct app_pktq_sink_params *param;
1726 struct rte_cfgfile_entry *entries;
1729 uint32_t pcap_file_present = 0;
1730 uint32_t pcap_n_pkt_present = 0;
1732 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1733 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1735 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1736 PARSE_ERROR_MALLOC(entries != NULL);
1738 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1740 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
1741 param = &app->sink_params[param_idx];
1742 PARSE_CHECK_DUPLICATE_SECTION(param);
1744 for (i = 0; i < n_entries; i++) {
1745 struct rte_cfgfile_entry *ent = &entries[i];
1747 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1748 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
1749 section_name, ent->name);
1751 param->file_name = strdup(ent->value);
1753 PARSE_ERROR_MALLOC((param->file_name != NULL));
1758 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1761 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
1762 section_name, ent->name);
1764 status = parser_read_uint32(
1765 ¶m->n_pkts_to_dump, ent->value);
1767 PARSE_ERROR((status == 0), section_name,
1774 PARSE_ERROR_INVALID(0, section_name, ent->name);
1781 parse_msgq_req_pipeline(struct app_params *app,
1782 const char *section_name,
1783 struct rte_cfgfile *cfg)
1785 struct app_msgq_params *param;
1786 struct rte_cfgfile_entry *entries;
1790 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1791 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1793 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1794 PARSE_ERROR_MALLOC(entries != NULL);
1796 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1798 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1799 param = &app->msgq_params[param_idx];
1800 PARSE_CHECK_DUPLICATE_SECTION(param);
1802 for (i = 0; i < n_entries; i++) {
1803 struct rte_cfgfile_entry *ent = &entries[i];
1805 if (strcmp(ent->name, "size") == 0) {
1806 int status = parser_read_uint32(¶m->size,
1809 PARSE_ERROR((status == 0), section_name,
1815 PARSE_ERROR_INVALID(0, section_name, ent->name);
1822 parse_msgq_rsp_pipeline(struct app_params *app,
1823 const char *section_name,
1824 struct rte_cfgfile *cfg)
1826 struct app_msgq_params *param;
1827 struct rte_cfgfile_entry *entries;
1831 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1832 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1834 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1835 PARSE_ERROR_MALLOC(entries != NULL);
1837 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1839 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1840 param = &app->msgq_params[param_idx];
1841 PARSE_CHECK_DUPLICATE_SECTION(param);
1843 for (i = 0; i < n_entries; i++) {
1844 struct rte_cfgfile_entry *ent = &entries[i];
1846 if (strcmp(ent->name, "size") == 0) {
1847 int status = parser_read_uint32(¶m->size,
1850 PARSE_ERROR((status == 0), section_name,
1856 PARSE_ERROR_INVALID(0, section_name, ent->name);
1863 parse_msgq(struct app_params *app,
1864 const char *section_name,
1865 struct rte_cfgfile *cfg)
1867 struct app_msgq_params *param;
1868 struct rte_cfgfile_entry *entries;
1872 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1873 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1875 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1876 PARSE_ERROR_MALLOC(entries != NULL);
1878 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1880 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1881 param = &app->msgq_params[param_idx];
1882 PARSE_CHECK_DUPLICATE_SECTION(param);
1884 for (i = 0; i < n_entries; i++) {
1885 struct rte_cfgfile_entry *ent = &entries[i];
1887 if (strcmp(ent->name, "size") == 0) {
1888 int status = parser_read_uint32(¶m->size,
1891 PARSE_ERROR((status == 0), section_name,
1896 if (strcmp(ent->name, "cpu") == 0) {
1897 int status = parser_read_uint32(
1898 ¶m->cpu_socket_id, ent->value);
1900 PARSE_ERROR((status == 0), section_name,
1906 PARSE_ERROR_INVALID(0, section_name, ent->name);
1912 typedef void (*config_section_load)(struct app_params *p,
1913 const char *section_name,
1914 struct rte_cfgfile *cfg);
1916 struct config_section {
1917 const char prefix[CFG_NAME_LEN];
1919 config_section_load load;
1922 static const struct config_section cfg_file_scheme[] = {
1923 {"EAL", 0, parse_eal},
1924 {"PIPELINE", 1, parse_pipeline},
1925 {"MEMPOOL", 1, parse_mempool},
1926 {"LINK", 1, parse_link},
1927 {"RXQ", 2, parse_rxq},
1928 {"TXQ", 2, parse_txq},
1929 {"SWQ", 1, parse_swq},
1930 {"TM", 1, parse_tm},
1931 {"SOURCE", 1, parse_source},
1932 {"SINK", 1, parse_sink},
1933 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
1934 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
1935 {"MSGQ", 1, parse_msgq},
1939 create_implicit_mempools(struct app_params *app)
1941 APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
1945 create_implicit_links_from_port_mask(struct app_params *app,
1948 uint32_t pmd_id, link_id;
1951 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
1952 char name[APP_PARAM_NAME_SIZE];
1955 if ((port_mask & (1LLU << pmd_id)) == 0)
1958 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
1959 idx = APP_PARAM_ADD(app->link_params, name);
1961 app->link_params[idx].pmd_id = pmd_id;
1967 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
1971 for (i = 0; i < app->n_links; i++) {
1972 struct app_link_params *link = &app->link_params[i];
1974 APP_CHECK((strlen(link->pci_bdf)),
1975 "Parse error: %s pci_bdf is not configured "
1976 "(port_mask is not provided)",
1984 app_config_parse(struct app_params *app, const char *file_name)
1986 struct rte_cfgfile *cfg;
1987 char **section_names;
1988 int i, j, sect_count;
1990 /* Implicit mempools */
1991 create_implicit_mempools(app);
1995 create_implicit_links_from_port_mask(app, app->port_mask);
1997 /* Load application configuration file */
1998 cfg = rte_cfgfile_load(file_name, 0);
1999 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2000 "file %s", file_name);
2002 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2003 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2004 "in file \"%s\" return %d", file_name,
2007 section_names = malloc(sect_count * sizeof(char *));
2008 PARSE_ERROR_MALLOC(section_names != NULL);
2010 for (i = 0; i < sect_count; i++)
2011 section_names[i] = malloc(CFG_NAME_LEN);
2013 rte_cfgfile_sections(cfg, section_names, sect_count);
2015 for (i = 0; i < sect_count; i++) {
2016 const struct config_section *sch_s;
2017 int len, cfg_name_len;
2019 cfg_name_len = strlen(section_names[i]);
2021 /* Find section type */
2022 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2023 sch_s = &cfg_file_scheme[j];
2024 len = strlen(sch_s->prefix);
2026 if (cfg_name_len < len)
2029 /* After section name we expect only '\0' or digit or
2030 * digit dot digit, so protect against false matching,
2031 * for example: "ABC" should match section name
2032 * "ABC0.0", but it should not match section_name
2035 if ((section_names[i][len] != '\0') &&
2036 !isdigit(section_names[i][len]))
2039 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2043 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2044 "Parse error: unknown section %s",
2047 APP_CHECK(validate_name(section_names[i],
2049 sch_s->numbers) == 0,
2050 "Parse error: invalid section name \"%s\"",
2053 sch_s->load(app, section_names[i], cfg);
2056 for (i = 0; i < sect_count; i++)
2057 free(section_names[i]);
2059 free(section_names);
2061 rte_cfgfile_close(cfg);
2063 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2064 APP_PARAM_COUNT(app->link_params, app->n_links);
2065 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2066 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2067 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2068 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2069 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2070 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2071 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2072 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2074 if (app->port_mask == 0)
2075 assign_link_pmd_id_from_pci_bdf(app);
2077 /* Save configuration to output file */
2078 app_config_save(app, app->output_file);
2080 /* Load TM configuration files */
2081 app_config_parse_tm(app);
2087 save_eal_params(struct app_params *app, FILE *f)
2089 struct app_eal_params *p = &app->eal_params;
2092 fprintf(f, "[EAL]\n");
2095 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2097 if (p->master_lcore_present)
2098 fprintf(f, "%s = %" PRIu32 "\n",
2099 "master_lcore", p->master_lcore);
2101 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2103 if (p->memory_present)
2104 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2106 if (p->ranks_present)
2107 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2109 for (i = 0; i < APP_MAX_LINKS; i++) {
2110 if (p->pci_blacklist[i] == NULL)
2113 fprintf(f, "%s = %s\n", "pci_blacklist",
2114 p->pci_blacklist[i]);
2117 for (i = 0; i < APP_MAX_LINKS; i++) {
2118 if (p->pci_whitelist[i] == NULL)
2121 fprintf(f, "%s = %s\n", "pci_whitelist",
2122 p->pci_whitelist[i]);
2125 for (i = 0; i < APP_MAX_LINKS; i++) {
2126 if (p->vdev[i] == NULL)
2129 fprintf(f, "%s = %s\n", "vdev",
2133 if (p->vmware_tsc_map_present)
2134 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2135 (p->vmware_tsc_map) ? "yes" : "no");
2138 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2141 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2143 if (p->log_level_present)
2144 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2146 if (p->version_present)
2147 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2149 if (p->help_present)
2150 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2152 if (p->no_huge_present)
2153 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2155 if (p->no_pci_present)
2156 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2158 if (p->no_hpet_present)
2159 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2161 if (p->no_shconf_present)
2162 fprintf(f, "%s = %s\n", "no_shconf",
2163 (p->no_shconf) ? "yes" : "no");
2166 fprintf(f, "%s = %s\n", "d", p->add_driver);
2169 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2172 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2175 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2177 if (p->base_virtaddr)
2178 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2180 if (p->create_uio_dev_present)
2181 fprintf(f, "%s = %s\n", "create_uio_dev",
2182 (p->create_uio_dev) ? "yes" : "no");
2185 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2187 if (p->xen_dom0_present)
2188 fprintf(f, "%s = %s\n", "xen_dom0",
2189 (p->xen_dom0) ? "yes" : "no");
2195 save_mempool_params(struct app_params *app, FILE *f)
2197 struct app_mempool_params *p;
2200 count = RTE_DIM(app->mempool_params);
2201 for (i = 0; i < count; i++) {
2202 p = &app->mempool_params[i];
2203 if (!APP_PARAM_VALID(p))
2206 fprintf(f, "[%s]\n", p->name);
2207 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2208 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2209 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2210 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2217 save_links_params(struct app_params *app, FILE *f)
2219 struct app_link_params *p;
2222 count = RTE_DIM(app->link_params);
2223 for (i = 0; i < count; i++) {
2224 p = &app->link_params[i];
2225 if (!APP_PARAM_VALID(p))
2228 fprintf(f, "[%s]\n", p->name);
2229 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2230 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2231 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2232 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2234 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2235 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2236 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2237 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2240 if (strlen(p->pci_bdf))
2241 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2248 save_rxq_params(struct app_params *app, FILE *f)
2250 struct app_pktq_hwq_in_params *p;
2253 count = RTE_DIM(app->hwq_in_params);
2254 for (i = 0; i < count; i++) {
2255 p = &app->hwq_in_params[i];
2256 if (!APP_PARAM_VALID(p))
2259 fprintf(f, "[%s]\n", p->name);
2260 fprintf(f, "%s = %s\n",
2262 app->mempool_params[p->mempool_id].name);
2263 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2264 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2271 save_txq_params(struct app_params *app, FILE *f)
2273 struct app_pktq_hwq_out_params *p;
2276 count = RTE_DIM(app->hwq_out_params);
2277 for (i = 0; i < count; i++) {
2278 p = &app->hwq_out_params[i];
2279 if (!APP_PARAM_VALID(p))
2282 fprintf(f, "[%s]\n", p->name);
2283 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2284 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2285 fprintf(f, "%s = %s\n",
2287 p->dropless ? "yes" : "no");
2294 save_swq_params(struct app_params *app, FILE *f)
2296 struct app_pktq_swq_params *p;
2299 count = RTE_DIM(app->swq_params);
2300 for (i = 0; i < count; i++) {
2301 p = &app->swq_params[i];
2302 if (!APP_PARAM_VALID(p))
2305 fprintf(f, "[%s]\n", p->name);
2306 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2307 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2308 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2309 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2310 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2311 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2312 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2313 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2314 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2315 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2316 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2317 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2318 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2319 fprintf(f, "%s = %s\n",
2321 app->mempool_params[p->mempool_direct_id].name);
2322 fprintf(f, "%s = %s\n",
2324 app->mempool_params[p->mempool_indirect_id].name);
2332 save_tm_params(struct app_params *app, FILE *f)
2334 struct app_pktq_tm_params *p;
2337 count = RTE_DIM(app->tm_params);
2338 for (i = 0; i < count; i++) {
2339 p = &app->tm_params[i];
2340 if (!APP_PARAM_VALID(p))
2343 fprintf(f, "[%s]\n", p->name);
2344 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2345 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2346 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2353 save_source_params(struct app_params *app, FILE *f)
2355 struct app_pktq_source_params *p;
2358 count = RTE_DIM(app->source_params);
2359 for (i = 0; i < count; i++) {
2360 p = &app->source_params[i];
2361 if (!APP_PARAM_VALID(p))
2364 fprintf(f, "[%s]\n", p->name);
2365 fprintf(f, "%s = %s\n",
2367 app->mempool_params[p->mempool_id].name);
2368 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2369 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2370 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2371 p->n_bytes_per_pkt);
2377 save_sink_params(struct app_params *app, FILE *f)
2379 struct app_pktq_sink_params *p;
2382 count = RTE_DIM(app->sink_params);
2383 for (i = 0; i < count; i++) {
2384 p = &app->sink_params[i];
2385 if (!APP_PARAM_VALID(p))
2388 fprintf(f, "[%s]\n", p->name);
2389 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2390 fprintf(f, "%s = %" PRIu32 "\n",
2391 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2397 save_msgq_params(struct app_params *app, FILE *f)
2399 struct app_msgq_params *p;
2402 count = RTE_DIM(app->msgq_params);
2403 for (i = 0; i < count; i++) {
2404 p = &app->msgq_params[i];
2405 if (!APP_PARAM_VALID(p))
2408 fprintf(f, "[%s]\n", p->name);
2409 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2410 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2417 save_pipeline_params(struct app_params *app, FILE *f)
2421 count = RTE_DIM(app->pipeline_params);
2422 for (i = 0; i < count; i++) {
2423 struct app_pipeline_params *p = &app->pipeline_params[i];
2425 if (!APP_PARAM_VALID(p))
2429 fprintf(f, "[%s]\n", p->name);
2432 fprintf(f, "type = %s\n", p->type);
2435 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2438 (p->hyper_th_id) ? "h" : "");
2444 fprintf(f, "pktq_in =");
2445 for (j = 0; j < p->n_pktq_in; j++) {
2446 struct app_pktq_in_params *pp = &p->pktq_in[j];
2450 case APP_PKTQ_IN_HWQ:
2451 name = app->hwq_in_params[pp->id].name;
2453 case APP_PKTQ_IN_SWQ:
2454 name = app->swq_params[pp->id].name;
2456 case APP_PKTQ_IN_TM:
2457 name = app->tm_params[pp->id].name;
2459 case APP_PKTQ_IN_SOURCE:
2460 name = app->source_params[pp->id].name;
2463 APP_CHECK(0, "System error "
2464 "occurred while saving "
2465 "parameter to file");
2468 fprintf(f, " %s", name);
2474 if (p->n_pktq_out) {
2477 fprintf(f, "pktq_out =");
2478 for (j = 0; j < p->n_pktq_out; j++) {
2479 struct app_pktq_out_params *pp =
2484 case APP_PKTQ_OUT_HWQ:
2485 name = app->hwq_out_params[pp->id].name;
2487 case APP_PKTQ_OUT_SWQ:
2488 name = app->swq_params[pp->id].name;
2490 case APP_PKTQ_OUT_TM:
2491 name = app->tm_params[pp->id].name;
2493 case APP_PKTQ_OUT_SINK:
2494 name = app->sink_params[pp->id].name;
2497 APP_CHECK(0, "System error "
2498 "occurred while saving "
2499 "parameter to file");
2502 fprintf(f, " %s", name);
2511 fprintf(f, "msgq_in =");
2512 for (j = 0; j < p->n_msgq_in; j++) {
2513 uint32_t id = p->msgq_in[j];
2514 char *name = app->msgq_params[id].name;
2516 fprintf(f, " %s", name);
2522 if (p->n_msgq_out) {
2525 fprintf(f, "msgq_out =");
2526 for (j = 0; j < p->n_msgq_out; j++) {
2527 uint32_t id = p->msgq_out[j];
2528 char *name = app->msgq_params[id].name;
2530 fprintf(f, " %s", name);
2536 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2542 for (j = 0; j < p->n_args; j++)
2543 fprintf(f, "%s = %s\n", p->args_name[j],
2552 app_config_save(struct app_params *app, const char *file_name)
2555 char *name, *dir_name;
2558 name = strdup(file_name);
2559 dir_name = dirname(name);
2560 status = access(dir_name, W_OK);
2561 APP_CHECK((status == 0),
2562 "Error: need write access privilege to directory "
2563 "\"%s\" to save configuration\n", dir_name);
2565 file = fopen(file_name, "w");
2566 APP_CHECK((file != NULL),
2567 "Error: failed to save configuration to file \"%s\"",
2570 save_eal_params(app, file);
2571 save_pipeline_params(app, file);
2572 save_mempool_params(app, file);
2573 save_links_params(app, file);
2574 save_rxq_params(app, file);
2575 save_txq_params(app, file);
2576 save_swq_params(app, file);
2577 save_tm_params(app, file);
2578 save_source_params(app, file);
2579 save_sink_params(app, file);
2580 save_msgq_params(app, file);
2587 app_config_init(struct app_params *app)
2591 memcpy(app, &app_params_default, sizeof(struct app_params));
2593 /* configure default_source_params */
2594 default_source_params.file_name = strdup("./config/packets.pcap");
2595 PARSE_ERROR_MALLOC(default_source_params.file_name != NULL);
2597 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2598 memcpy(&app->mempool_params[i],
2599 &mempool_params_default,
2600 sizeof(struct app_mempool_params));
2602 for (i = 0; i < RTE_DIM(app->link_params); i++)
2603 memcpy(&app->link_params[i],
2604 &link_params_default,
2605 sizeof(struct app_link_params));
2607 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2608 memcpy(&app->hwq_in_params[i],
2609 &default_hwq_in_params,
2610 sizeof(default_hwq_in_params));
2612 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2613 memcpy(&app->hwq_out_params[i],
2614 &default_hwq_out_params,
2615 sizeof(default_hwq_out_params));
2617 for (i = 0; i < RTE_DIM(app->swq_params); i++)
2618 memcpy(&app->swq_params[i],
2619 &default_swq_params,
2620 sizeof(default_swq_params));
2622 for (i = 0; i < RTE_DIM(app->tm_params); i++)
2623 memcpy(&app->tm_params[i],
2625 sizeof(default_tm_params));
2627 for (i = 0; i < RTE_DIM(app->source_params); i++)
2628 memcpy(&app->source_params[i],
2629 &default_source_params,
2630 sizeof(default_source_params));
2632 for (i = 0; i < RTE_DIM(app->sink_params); i++)
2633 memcpy(&app->sink_params[i],
2634 &default_sink_params,
2635 sizeof(default_sink_params));
2637 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2638 memcpy(&app->msgq_params[i],
2639 &default_msgq_params,
2640 sizeof(default_msgq_params));
2642 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2643 memcpy(&app->pipeline_params[i],
2644 &default_pipeline_params,
2645 sizeof(default_pipeline_params));
2651 filenamedup(const char *filename, const char *suffix)
2653 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2658 sprintf(s, "%s%s", filename, suffix);
2663 app_config_args(struct app_params *app, int argc, char **argv)
2665 const char *optname;
2666 int opt, option_index;
2667 int f_present, s_present, p_present, l_present;
2668 int preproc_present, preproc_params_present;
2671 static struct option lgopts[] = {
2672 { "preproc", 1, 0, 0 },
2673 { "preproc-args", 1, 0, 0 },
2677 /* Copy application name */
2678 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
2684 preproc_present = 0;
2685 preproc_params_present = 0;
2687 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
2688 &option_index)) != EOF)
2692 rte_panic("Error: Config file is provided "
2693 "more than once\n");
2696 if (!strlen(optarg))
2697 rte_panic("Error: Config file name is null\n");
2699 app->config_file = strdup(optarg);
2700 if (app->config_file == NULL)
2701 rte_panic("Error: Memory allocation failure\n");
2707 rte_panic("Error: Script file is provided "
2708 "more than once\n");
2711 if (!strlen(optarg))
2712 rte_panic("Error: Script file name is null\n");
2714 app->script_file = strdup(optarg);
2715 if (app->script_file == NULL)
2716 rte_panic("Error: Memory allocation failure\n");
2722 rte_panic("Error: PORT_MASK is provided "
2723 "more than once\n");
2726 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
2728 ((size_t) scaned != strlen(optarg)))
2729 rte_panic("Error: PORT_MASK is not "
2730 "a hexadecimal integer\n");
2732 if (app->port_mask == 0)
2733 rte_panic("Error: PORT_MASK is null\n");
2739 rte_panic("Error: LOG_LEVEL is provided "
2740 "more than once\n");
2743 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
2745 ((size_t) scaned != strlen(optarg)) ||
2746 (app->log_level >= APP_LOG_LEVELS))
2747 rte_panic("Error: LOG_LEVEL invalid value\n");
2752 optname = lgopts[option_index].name;
2754 if (strcmp(optname, "preproc") == 0) {
2755 if (preproc_present)
2756 rte_panic("Error: Preprocessor argument "
2757 "is provided more than once\n");
2758 preproc_present = 1;
2760 app->preproc = strdup(optarg);
2764 if (strcmp(optname, "preproc-args") == 0) {
2765 if (preproc_params_present)
2766 rte_panic("Error: Preprocessor args "
2767 "are provided more than once\n");
2768 preproc_params_present = 1;
2770 app->preproc_args = strdup(optarg);
2774 app_print_usage(argv[0]);
2778 app_print_usage(argv[0]);
2781 optind = 0; /* reset getopt lib */
2783 /* Check dependencies between args */
2784 if (preproc_params_present && (preproc_present == 0))
2785 rte_panic("Error: Preprocessor args specified while "
2786 "preprocessor is not defined\n");
2788 app->parser_file = preproc_present ?
2789 filenamedup(app->config_file, ".preproc") :
2790 strdup(app->config_file);
2791 app->output_file = filenamedup(app->config_file, ".out");
2797 app_config_preproc(struct app_params *app)
2802 if (app->preproc == NULL)
2805 status = access(app->config_file, F_OK | R_OK);
2806 APP_CHECK((status == 0), "Error: Unable to open file %s",
2809 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
2811 app->preproc_args ? app->preproc_args : "",
2815 status = system(buffer);
2816 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
2817 "Error occurred while pre-processing file \"%s\"\n",