1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
17 #include <rte_errno.h>
18 #include <rte_cfgfile.h>
19 #include <rte_string_fns.h>
25 * Default config values
28 static struct app_params app_params_default = {
29 .config_file = "./config/ip_pipeline.cfg",
30 .log_level = APP_LOG_LEVEL_HIGH,
38 static const struct app_mempool_params mempool_params_default = {
40 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
41 .pool_size = 32 * 1024,
46 static const struct app_link_params link_params_default = {
57 .rss_proto_ipv4 = ETH_RSS_IPV4,
58 .rss_proto_ipv6 = ETH_RSS_IPV6,
69 .mq_mode = ETH_MQ_RX_NONE,
71 .ignore_offload_bitfield = 1,
72 .offloads = DEV_RX_OFFLOAD_CRC_STRIP,
74 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
75 .split_hdr_size = 0, /* Header split buffer size */
85 .mq_mode = ETH_MQ_TX_NONE,
93 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
105 .rx_free_thresh = 64,
107 .rx_deferred_start = 0,
111 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
126 .txq_flags = ETH_TXQ_FLAGS_IGNORE,
127 .tx_deferred_start = 0,
131 static const struct app_pktq_swq_params default_swq_params = {
145 .mempool_direct_id = 0,
146 .mempool_indirect_id = 0,
149 struct app_pktq_tm_params default_tm_params = {
151 .file_name = "./config/tm_profile.cfg",
156 struct app_pktq_tap_params default_tap_params = {
165 struct app_pktq_kni_params default_kni_params = {
179 struct app_pktq_source_params default_source_params = {
183 .file_name = "./config/packets.pcap",
184 .n_bytes_per_pkt = 0,
187 struct app_pktq_sink_params default_sink_params = {
193 struct app_msgq_params default_msgq_params = {
199 struct app_pipeline_params default_pipeline_params = {
212 static const char app_usage[] =
213 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
214 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
217 "\t-f CONFIG_FILE: Default config file is %s\n"
218 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
219 "config file when not provided)\n"
220 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
221 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
222 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
223 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
227 app_print_usage(char *prgname)
229 rte_exit(0, app_usage, prgname, app_params_default.config_file);
232 #define APP_PARAM_ADD(set, key) \
234 ssize_t pos = APP_PARAM_FIND(set, key); \
235 ssize_t size = RTE_DIM(set); \
238 for (pos = 0; pos < size; pos++) { \
239 if (!APP_PARAM_VALID(&((set)[pos]))) \
243 APP_CHECK((pos < size), \
244 "Parse error: size of %s is limited to %u elements",\
245 #set, (uint32_t) size); \
247 (set)[pos].name = strdup(key); \
248 APP_CHECK(((set)[pos].name), \
249 "Parse error: no free memory"); \
254 #define APP_PARAM_ADD_LINK_FOR_RXQ(app, rxq_name) \
256 char link_name[APP_PARAM_NAME_SIZE]; \
257 ssize_t link_param_pos; \
258 uint32_t link_id, queue_id; \
260 sscanf((rxq_name), "RXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
261 sprintf(link_name, "LINK%" PRIu32, link_id); \
262 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
266 #define APP_PARAM_ADD_LINK_FOR_TXQ(app, txq_name) \
268 char link_name[APP_PARAM_NAME_SIZE]; \
269 ssize_t link_param_pos; \
270 uint32_t link_id, queue_id; \
272 sscanf((txq_name), "TXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
273 sprintf(link_name, "LINK%" PRIu32, link_id); \
274 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
278 #define APP_PARAM_ADD_LINK_FOR_TM(app, tm_name) \
280 char link_name[APP_PARAM_NAME_SIZE]; \
281 ssize_t link_param_pos; \
284 sscanf((tm_name), "TM%" SCNu32, &link_id); \
285 sprintf(link_name, "LINK%" PRIu32, link_id); \
286 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
290 #define APP_PARAM_ADD_LINK_FOR_KNI(app, kni_name) \
292 char link_name[APP_PARAM_NAME_SIZE]; \
293 ssize_t link_param_pos; \
296 sscanf((kni_name), "KNI%" SCNu32, &link_id); \
297 sprintf(link_name, "LINK%" PRIu32, link_id); \
298 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
302 #define PARSE_CHECK_DUPLICATE_SECTION(obj) \
304 APP_CHECK(((obj)->parsed == 0), \
305 "Parse error: duplicate \"%s\" section", (obj)->name); \
309 #define PARSE_CHECK_DUPLICATE_SECTION_EAL(obj) \
311 APP_CHECK(((obj)->parsed == 0), \
312 "Parse error: duplicate \"%s\" section", "EAL"); \
316 #define PARSE_ERROR(exp, section, entry) \
317 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"", section, entry)
319 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
320 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s", \
321 section, entry, message)
323 #define PARSE_ERROR_NO_ELEMENTS(exp, section, entry) \
324 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
325 "no elements detected", \
328 #define PARSE_ERROR_TOO_MANY_ELEMENTS(exp, section, entry, max) \
329 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
330 "maximum number of elements allowed is %u", \
333 #define PARSE_ERROR_INVALID_ELEMENT(exp, section, entry, value) \
334 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
335 "Invalid element value \"%s\"", \
336 section, entry, value)
338 #define PARSE_ERROR_MALLOC(exp) \
339 APP_CHECK(exp, "Parse error: no free memory")
341 #define PARSE_ERROR_SECTION(exp, section) \
342 APP_CHECK(exp, "Parse error in section \"%s\"", section)
344 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
345 APP_CHECK(exp, "Parse error in section \"%s\": no entries", section)
347 #define PARSE_WARNING_IGNORED(exp, section, entry) \
350 fprintf(stderr, "Parse warning in section \"%s\": " \
351 "entry \"%s\" is ignored", section, entry); \
354 #define PARSE_ERROR_INVALID(exp, section, entry) \
355 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"",\
358 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
359 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"", \
363 validate_name(const char *name, const char *prefix, int num)
367 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
368 if (name[i] != prefix[i])
372 if (prefix[i] != '\0')
383 j = skip_digits(&name[i]);
385 if ((j == 0) || (name[i] != '.'))
391 j = skip_digits(&name[i]);
393 if ((j == 0) || (name[i] != '\0'))
401 parse_eal(struct app_params *app,
402 const char *section_name,
403 struct rte_cfgfile *cfg)
405 struct app_eal_params *p = &app->eal_params;
406 struct rte_cfgfile_entry *entries;
409 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
410 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
412 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
413 PARSE_ERROR_MALLOC(entries != NULL);
415 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
417 PARSE_CHECK_DUPLICATE_SECTION_EAL(p);
419 for (i = 0; i < n_entries; i++) {
420 struct rte_cfgfile_entry *entry = &entries[i];
423 if (strcmp(entry->name, "c") == 0) {
424 PARSE_WARNING_IGNORED(0, section_name, entry->name);
429 if (strcmp(entry->name, "l") == 0) {
430 PARSE_WARNING_IGNORED(0, section_name, entry->name);
435 if (strcmp(entry->name, "lcores") == 0) {
436 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
439 p->coremap = strdup(entry->value);
444 if (strcmp(entry->name, "master_lcore") == 0) {
447 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
450 p->master_lcore_present = 1;
452 status = parser_read_uint32(&p->master_lcore,
454 PARSE_ERROR((status == 0), section_name, entry->name);
459 if (strcmp(entry->name, "n") == 0) {
462 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
465 p->channels_present = 1;
467 status = parser_read_uint32(&p->channels, entry->value);
468 PARSE_ERROR((status == 0), section_name, entry->name);
473 if (strcmp(entry->name, "m") == 0) {
476 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
479 p->memory_present = 1;
481 status = parser_read_uint32(&p->memory, entry->value);
482 PARSE_ERROR((status == 0), section_name, entry->name);
487 if (strcmp(entry->name, "r") == 0) {
490 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
493 p->ranks_present = 1;
495 status = parser_read_uint32(&p->ranks, entry->value);
496 PARSE_ERROR((status == 0), section_name, entry->name);
501 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
502 (strcmp(entry->name, "b") == 0)) {
505 for (i = 0; i < APP_MAX_LINKS; i++) {
506 if (p->pci_blacklist[i])
509 p->pci_blacklist[i] =
510 strdup(entry->value);
511 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
516 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
517 section_name, entry->name,
518 "too many elements");
523 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
524 (strcmp(entry->name, "w") == 0)) {
527 PARSE_ERROR_MESSAGE((app->port_mask != 0),
528 section_name, entry->name, "entry to be "
529 "generated by the application (port_mask "
532 for (i = 0; i < APP_MAX_LINKS; i++) {
533 if (p->pci_whitelist[i])
536 p->pci_whitelist[i] = strdup(entry->value);
537 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
542 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
543 section_name, entry->name,
544 "too many elements");
549 if (strcmp(entry->name, "vdev") == 0) {
552 for (i = 0; i < APP_MAX_LINKS; i++) {
556 p->vdev[i] = strdup(entry->value);
557 PARSE_ERROR_MALLOC(p->vdev[i]);
562 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
563 section_name, entry->name,
564 "too many elements");
569 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
572 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
575 p->vmware_tsc_map_present = 1;
577 val = parser_read_arg_bool(entry->value);
578 PARSE_ERROR((val >= 0), section_name, entry->name);
579 p->vmware_tsc_map = val;
584 if (strcmp(entry->name, "proc_type") == 0) {
585 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
588 p->proc_type = strdup(entry->value);
593 if (strcmp(entry->name, "syslog") == 0) {
594 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
597 p->syslog = strdup(entry->value);
602 if (strcmp(entry->name, "log_level") == 0) {
605 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
608 p->log_level_present = 1;
610 status = parser_read_uint32(&p->log_level,
612 PARSE_ERROR((status == 0), section_name, entry->name);
617 if (strcmp(entry->name, "v") == 0) {
620 PARSE_ERROR_DUPLICATE((p->version_present == 0),
623 p->version_present = 1;
625 val = parser_read_arg_bool(entry->value);
626 PARSE_ERROR((val >= 0), section_name, entry->name);
632 if ((strcmp(entry->name, "help") == 0) ||
633 (strcmp(entry->name, "h") == 0)) {
636 PARSE_ERROR_DUPLICATE((p->help_present == 0),
641 val = parser_read_arg_bool(entry->value);
642 PARSE_ERROR((val >= 0), section_name, entry->name);
648 if (strcmp(entry->name, "no_huge") == 0) {
651 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
654 p->no_huge_present = 1;
656 val = parser_read_arg_bool(entry->value);
657 PARSE_ERROR((val >= 0), section_name, entry->name);
663 if (strcmp(entry->name, "no_pci") == 0) {
666 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
669 p->no_pci_present = 1;
671 val = parser_read_arg_bool(entry->value);
672 PARSE_ERROR((val >= 0), section_name, entry->name);
678 if (strcmp(entry->name, "no_hpet") == 0) {
681 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
684 p->no_hpet_present = 1;
686 val = parser_read_arg_bool(entry->value);
687 PARSE_ERROR((val >= 0), section_name, entry->name);
693 if (strcmp(entry->name, "no_shconf") == 0) {
696 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
699 p->no_shconf_present = 1;
701 val = parser_read_arg_bool(entry->value);
702 PARSE_ERROR((val >= 0), section_name, entry->name);
708 if (strcmp(entry->name, "d") == 0) {
709 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
712 p->add_driver = strdup(entry->value);
717 if (strcmp(entry->name, "socket_mem") == 0) {
718 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
721 p->socket_mem = strdup(entry->value);
726 if (strcmp(entry->name, "huge_dir") == 0) {
727 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
730 p->huge_dir = strdup(entry->value);
735 if (strcmp(entry->name, "file_prefix") == 0) {
736 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
739 p->file_prefix = strdup(entry->value);
744 if (strcmp(entry->name, "base_virtaddr") == 0) {
745 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
748 p->base_virtaddr = strdup(entry->value);
753 if (strcmp(entry->name, "create_uio_dev") == 0) {
756 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
759 p->create_uio_dev_present = 1;
761 val = parser_read_arg_bool(entry->value);
762 PARSE_ERROR((val >= 0), section_name, entry->name);
763 p->create_uio_dev = val;
768 if (strcmp(entry->name, "vfio_intr") == 0) {
769 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
772 p->vfio_intr = strdup(entry->value);
777 PARSE_ERROR_INVALID(0, section_name, entry->name);
784 parse_pipeline_pktq_in(struct app_params *app,
785 struct app_pipeline_params *p,
791 enum app_pktq_in_type type;
793 char *name = strtok_r(value, PARSE_DELIMITER, &value);
798 PARSE_ERROR_TOO_MANY_ELEMENTS(
799 (p->n_pktq_in < RTE_DIM(p->pktq_in)),
800 p->name, "pktq_in", (uint32_t)RTE_DIM(p->pktq_in));
802 if (validate_name(name, "RXQ", 2) == 0) {
803 type = APP_PKTQ_IN_HWQ;
804 id = APP_PARAM_ADD(app->hwq_in_params, name);
805 APP_PARAM_ADD_LINK_FOR_RXQ(app, name);
806 } else if (validate_name(name, "SWQ", 1) == 0) {
807 type = APP_PKTQ_IN_SWQ;
808 id = APP_PARAM_ADD(app->swq_params, name);
809 } else if (validate_name(name, "TM", 1) == 0) {
810 type = APP_PKTQ_IN_TM;
811 id = APP_PARAM_ADD(app->tm_params, name);
812 APP_PARAM_ADD_LINK_FOR_TM(app, name);
813 } else if (validate_name(name, "TAP", 1) == 0) {
814 type = APP_PKTQ_IN_TAP;
815 id = APP_PARAM_ADD(app->tap_params, name);
816 } else if (validate_name(name, "KNI", 1) == 0) {
817 type = APP_PKTQ_IN_KNI;
818 id = APP_PARAM_ADD(app->kni_params, name);
819 APP_PARAM_ADD_LINK_FOR_KNI(app, name);
820 } else if (validate_name(name, "SOURCE", 1) == 0) {
821 type = APP_PKTQ_IN_SOURCE;
822 id = APP_PARAM_ADD(app->source_params, name);
824 PARSE_ERROR_INVALID_ELEMENT(0,
825 p->name, "pktq_in", name);
827 p->pktq_in[p->n_pktq_in].type = type;
828 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
832 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_in > 0), p->name, "pktq_in");
836 parse_pipeline_pktq_out(struct app_params *app,
837 struct app_pipeline_params *p,
843 enum app_pktq_out_type type;
845 char *name = strtok_r(value, PARSE_DELIMITER, &value);
850 PARSE_ERROR_TOO_MANY_ELEMENTS(
851 (p->n_pktq_out < RTE_DIM(p->pktq_out)),
852 p->name, "pktq_out", (uint32_t)RTE_DIM(p->pktq_out));
854 if (validate_name(name, "TXQ", 2) == 0) {
855 type = APP_PKTQ_OUT_HWQ;
856 id = APP_PARAM_ADD(app->hwq_out_params, name);
857 APP_PARAM_ADD_LINK_FOR_TXQ(app, name);
858 } else if (validate_name(name, "SWQ", 1) == 0) {
859 type = APP_PKTQ_OUT_SWQ;
860 id = APP_PARAM_ADD(app->swq_params, name);
861 } else if (validate_name(name, "TM", 1) == 0) {
862 type = APP_PKTQ_OUT_TM;
863 id = APP_PARAM_ADD(app->tm_params, name);
864 APP_PARAM_ADD_LINK_FOR_TM(app, name);
865 } else if (validate_name(name, "TAP", 1) == 0) {
866 type = APP_PKTQ_OUT_TAP;
867 id = APP_PARAM_ADD(app->tap_params, name);
868 } else if (validate_name(name, "KNI", 1) == 0) {
869 type = APP_PKTQ_OUT_KNI;
870 id = APP_PARAM_ADD(app->kni_params, name);
871 APP_PARAM_ADD_LINK_FOR_KNI(app, name);
872 } else if (validate_name(name, "SINK", 1) == 0) {
873 type = APP_PKTQ_OUT_SINK;
874 id = APP_PARAM_ADD(app->sink_params, name);
876 PARSE_ERROR_INVALID_ELEMENT(0,
877 p->name, "pktq_out", name);
879 p->pktq_out[p->n_pktq_out].type = type;
880 p->pktq_out[p->n_pktq_out].id = id;
884 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_out > 0), p->name, "pktq_out");
888 parse_pipeline_msgq_in(struct app_params *app,
889 struct app_pipeline_params *p,
896 char *name = strtok_r(value, PARSE_DELIMITER, &value);
901 PARSE_ERROR_TOO_MANY_ELEMENTS(
902 (p->n_msgq_in < RTE_DIM(p->msgq_in)),
903 p->name, "msgq_in", (uint32_t)(RTE_DIM(p->msgq_in)));
905 PARSE_ERROR_INVALID_ELEMENT(
906 (validate_name(name, "MSGQ", 1) == 0),
907 p->name, "msgq_in", name);
909 idx = APP_PARAM_ADD(app->msgq_params, name);
910 p->msgq_in[p->n_msgq_in] = idx;
914 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_in > 0), p->name, "msgq_in");
918 parse_pipeline_msgq_out(struct app_params *app,
919 struct app_pipeline_params *p,
926 char *name = strtok_r(value, PARSE_DELIMITER, &value);
931 PARSE_ERROR_TOO_MANY_ELEMENTS(
932 (p->n_msgq_out < RTE_DIM(p->msgq_out)),
933 p->name, "msgq_out", (uint32_t)RTE_DIM(p->msgq_out));
935 PARSE_ERROR_INVALID_ELEMENT(
936 (validate_name(name, "MSGQ", 1) == 0),
937 p->name, "msgq_out", name);
939 idx = APP_PARAM_ADD(app->msgq_params, name);
940 p->msgq_out[p->n_msgq_out] = idx;
944 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_out > 0), p->name, "msgq_out");
948 parse_pipeline(struct app_params *app,
949 const char *section_name,
950 struct rte_cfgfile *cfg)
952 char name[CFG_NAME_LEN];
953 struct app_pipeline_params *param;
954 struct rte_cfgfile_entry *entries;
958 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
959 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
961 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
962 PARSE_ERROR_MALLOC(entries != NULL);
964 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
966 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
967 param = &app->pipeline_params[param_idx];
968 PARSE_CHECK_DUPLICATE_SECTION(param);
970 for (i = 0; i < n_entries; i++) {
971 struct rte_cfgfile_entry *ent = &entries[i];
973 if (strcmp(ent->name, "type") == 0) {
974 int w_size = snprintf(param->type, RTE_DIM(param->type),
977 PARSE_ERROR(((w_size > 0) &&
978 (w_size < (int)RTE_DIM(param->type))),
984 if (strcmp(ent->name, "core") == 0) {
985 int status = parse_pipeline_core(
986 ¶m->socket_id, ¶m->core_id,
987 ¶m->hyper_th_id, ent->value);
989 PARSE_ERROR((status == 0), section_name,
994 if (strcmp(ent->name, "pktq_in") == 0) {
995 parse_pipeline_pktq_in(app, param, ent->value);
1000 if (strcmp(ent->name, "pktq_out") == 0) {
1001 parse_pipeline_pktq_out(app, param, ent->value);
1006 if (strcmp(ent->name, "msgq_in") == 0) {
1007 parse_pipeline_msgq_in(app, param, ent->value);
1012 if (strcmp(ent->name, "msgq_out") == 0) {
1013 parse_pipeline_msgq_out(app, param, ent->value);
1018 if (strcmp(ent->name, "timer_period") == 0) {
1019 int status = parser_read_uint32(
1020 ¶m->timer_period,
1023 PARSE_ERROR((status == 0), section_name,
1028 /* pipeline type specific items */
1029 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1030 "Parse error in section \"%s\": too many "
1031 "pipeline specified parameters", section_name);
1033 param->args_name[param->n_args] = strdup(ent->name);
1034 param->args_value[param->n_args] = strdup(ent->value);
1036 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1037 (param->args_value[param->n_args] != NULL),
1038 "Parse error: no free memory");
1043 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1044 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1045 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1046 param->msgq_in[param->n_msgq_in++] = param_idx;
1048 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1049 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1050 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1051 param->msgq_out[param->n_msgq_out++] = param_idx;
1053 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1056 (param->hyper_th_id) ? "h" : "");
1057 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1058 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1060 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1063 (param->hyper_th_id) ? "h" : "");
1064 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1065 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1071 parse_mempool(struct app_params *app,
1072 const char *section_name,
1073 struct rte_cfgfile *cfg)
1075 struct app_mempool_params *param;
1076 struct rte_cfgfile_entry *entries;
1080 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1081 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1083 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1084 PARSE_ERROR_MALLOC(entries != NULL);
1086 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1088 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1089 param = &app->mempool_params[param_idx];
1090 PARSE_CHECK_DUPLICATE_SECTION(param);
1092 for (i = 0; i < n_entries; i++) {
1093 struct rte_cfgfile_entry *ent = &entries[i];
1095 if (strcmp(ent->name, "buffer_size") == 0) {
1096 int status = parser_read_uint32(
1097 ¶m->buffer_size, ent->value);
1099 PARSE_ERROR((status == 0), section_name,
1104 if (strcmp(ent->name, "pool_size") == 0) {
1105 int status = parser_read_uint32(
1106 ¶m->pool_size, ent->value);
1108 PARSE_ERROR((status == 0), section_name,
1113 if (strcmp(ent->name, "cache_size") == 0) {
1114 int status = parser_read_uint32(
1115 ¶m->cache_size, ent->value);
1117 PARSE_ERROR((status == 0), section_name,
1122 if (strcmp(ent->name, "cpu") == 0) {
1123 int status = parser_read_uint32(
1124 ¶m->cpu_socket_id, ent->value);
1126 PARSE_ERROR((status == 0), section_name,
1132 PARSE_ERROR_INVALID(0, section_name, ent->name);
1139 parse_link_rss_qs(struct app_link_params *p,
1145 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1150 if (p->n_rss_qs == RTE_DIM(p->rss_qs))
1153 if (parser_read_uint32(&p->rss_qs[p->n_rss_qs++], token))
1161 parse_link_rss_proto_ipv4(struct app_link_params *p,
1167 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1172 if (strcmp(token, "IP") == 0) {
1173 mask |= ETH_RSS_IPV4;
1176 if (strcmp(token, "FRAG") == 0) {
1177 mask |= ETH_RSS_FRAG_IPV4;
1180 if (strcmp(token, "TCP") == 0) {
1181 mask |= ETH_RSS_NONFRAG_IPV4_TCP;
1184 if (strcmp(token, "UDP") == 0) {
1185 mask |= ETH_RSS_NONFRAG_IPV4_UDP;
1188 if (strcmp(token, "SCTP") == 0) {
1189 mask |= ETH_RSS_NONFRAG_IPV4_SCTP;
1192 if (strcmp(token, "OTHER") == 0) {
1193 mask |= ETH_RSS_NONFRAG_IPV4_OTHER;
1199 p->rss_proto_ipv4 = mask;
1204 parse_link_rss_proto_ipv6(struct app_link_params *p,
1210 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1215 if (strcmp(token, "IP") == 0) {
1216 mask |= ETH_RSS_IPV6;
1219 if (strcmp(token, "FRAG") == 0) {
1220 mask |= ETH_RSS_FRAG_IPV6;
1223 if (strcmp(token, "TCP") == 0) {
1224 mask |= ETH_RSS_NONFRAG_IPV6_TCP;
1227 if (strcmp(token, "UDP") == 0) {
1228 mask |= ETH_RSS_NONFRAG_IPV6_UDP;
1231 if (strcmp(token, "SCTP") == 0) {
1232 mask |= ETH_RSS_NONFRAG_IPV6_SCTP;
1235 if (strcmp(token, "OTHER") == 0) {
1236 mask |= ETH_RSS_NONFRAG_IPV6_OTHER;
1239 if (strcmp(token, "IP_EX") == 0) {
1240 mask |= ETH_RSS_IPV6_EX;
1243 if (strcmp(token, "TCP_EX") == 0) {
1244 mask |= ETH_RSS_IPV6_TCP_EX;
1247 if (strcmp(token, "UDP_EX") == 0) {
1248 mask |= ETH_RSS_IPV6_UDP_EX;
1254 p->rss_proto_ipv6 = mask;
1259 parse_link_rss_proto_l2(struct app_link_params *p,
1265 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1270 if (strcmp(token, "L2") == 0) {
1271 mask |= ETH_RSS_L2_PAYLOAD;
1277 p->rss_proto_l2 = mask;
1282 parse_link(struct app_params *app,
1283 const char *section_name,
1284 struct rte_cfgfile *cfg)
1286 struct app_link_params *param;
1287 struct rte_cfgfile_entry *entries;
1289 int rss_qs_present = 0;
1290 int rss_proto_ipv4_present = 0;
1291 int rss_proto_ipv6_present = 0;
1292 int rss_proto_l2_present = 0;
1293 int pci_bdf_present = 0;
1296 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1297 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1299 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1300 PARSE_ERROR_MALLOC(entries != NULL);
1302 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1304 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1305 param = &app->link_params[param_idx];
1306 PARSE_CHECK_DUPLICATE_SECTION(param);
1308 for (i = 0; i < n_entries; i++) {
1309 struct rte_cfgfile_entry *ent = &entries[i];
1311 if (strcmp(ent->name, "promisc") == 0) {
1312 int status = parser_read_arg_bool(ent->value);
1314 PARSE_ERROR((status != -EINVAL), section_name,
1316 param->promisc = status;
1320 if (strcmp(ent->name, "arp_q") == 0) {
1321 int status = parser_read_uint32(¶m->arp_q,
1324 PARSE_ERROR((status == 0), section_name,
1329 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1330 int status = parser_read_uint32(
1331 ¶m->tcp_syn_q, ent->value);
1333 PARSE_ERROR((status == 0), section_name, ent->name);
1337 if (strcmp(ent->name, "ip_local_q") == 0) {
1338 int status = parser_read_uint32(
1339 ¶m->ip_local_q, ent->value);
1341 PARSE_ERROR((status == 0), section_name,
1346 if (strcmp(ent->name, "tcp_local_q") == 0) {
1347 int status = parser_read_uint32(
1348 ¶m->tcp_local_q, ent->value);
1350 PARSE_ERROR((status == 0), section_name,
1355 if (strcmp(ent->name, "udp_local_q") == 0) {
1356 int status = parser_read_uint32(
1357 ¶m->udp_local_q, ent->value);
1359 PARSE_ERROR((status == 0), section_name,
1364 if (strcmp(ent->name, "sctp_local_q") == 0) {
1365 int status = parser_read_uint32(
1366 ¶m->sctp_local_q, ent->value);
1368 PARSE_ERROR((status == 0), section_name,
1373 if (strcmp(ent->name, "rss_qs") == 0) {
1374 int status = parse_link_rss_qs(param, ent->value);
1376 PARSE_ERROR((status == 0), section_name,
1382 if (strcmp(ent->name, "rss_proto_ipv4") == 0) {
1384 parse_link_rss_proto_ipv4(param, ent->value);
1386 PARSE_ERROR((status != -EINVAL), section_name,
1388 rss_proto_ipv4_present = 1;
1392 if (strcmp(ent->name, "rss_proto_ipv6") == 0) {
1394 parse_link_rss_proto_ipv6(param, ent->value);
1396 PARSE_ERROR((status != -EINVAL), section_name,
1398 rss_proto_ipv6_present = 1;
1402 if (strcmp(ent->name, "rss_proto_l2") == 0) {
1403 int status = parse_link_rss_proto_l2(param, ent->value);
1405 PARSE_ERROR((status != -EINVAL), section_name,
1407 rss_proto_l2_present = 1;
1411 if (strcmp(ent->name, "pci_bdf") == 0) {
1412 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1413 section_name, ent->name);
1415 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1417 pci_bdf_present = 1;
1422 PARSE_ERROR_INVALID(0, section_name, ent->name);
1425 /* Check for mandatory fields */
1427 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1428 section_name, "pci_bdf",
1429 "entry not allowed (port_mask is provided)");
1431 PARSE_ERROR_MESSAGE((pci_bdf_present),
1432 section_name, "pci_bdf",
1433 "this entry is mandatory (port_mask is not "
1436 if (rss_proto_ipv4_present)
1437 PARSE_ERROR_MESSAGE((rss_qs_present),
1438 section_name, "rss_proto_ipv4",
1439 "entry not allowed (rss_qs entry is not provided)");
1440 if (rss_proto_ipv6_present)
1441 PARSE_ERROR_MESSAGE((rss_qs_present),
1442 section_name, "rss_proto_ipv6",
1443 "entry not allowed (rss_qs entry is not provided)");
1444 if (rss_proto_l2_present)
1445 PARSE_ERROR_MESSAGE((rss_qs_present),
1446 section_name, "rss_proto_l2",
1447 "entry not allowed (rss_qs entry is not provided)");
1448 if (rss_proto_ipv4_present |
1449 rss_proto_ipv6_present |
1450 rss_proto_l2_present){
1451 if (rss_proto_ipv4_present == 0)
1452 param->rss_proto_ipv4 = 0;
1453 if (rss_proto_ipv6_present == 0)
1454 param->rss_proto_ipv6 = 0;
1455 if (rss_proto_l2_present == 0)
1456 param->rss_proto_l2 = 0;
1463 parse_rxq(struct app_params *app,
1464 const char *section_name,
1465 struct rte_cfgfile *cfg)
1467 struct app_pktq_hwq_in_params *param;
1468 struct rte_cfgfile_entry *entries;
1472 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1473 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1475 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1476 PARSE_ERROR_MALLOC(entries != NULL);
1478 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1480 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1481 param = &app->hwq_in_params[param_idx];
1482 PARSE_CHECK_DUPLICATE_SECTION(param);
1484 APP_PARAM_ADD_LINK_FOR_RXQ(app, section_name);
1486 for (i = 0; i < n_entries; i++) {
1487 struct rte_cfgfile_entry *ent = &entries[i];
1489 if (strcmp(ent->name, "mempool") == 0) {
1490 int status = validate_name(ent->value,
1494 PARSE_ERROR((status == 0), section_name,
1497 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1498 param->mempool_id = idx;
1502 if (strcmp(ent->name, "size") == 0) {
1503 int status = parser_read_uint32(¶m->size,
1506 PARSE_ERROR((status == 0), section_name,
1511 if (strcmp(ent->name, "burst") == 0) {
1512 int status = parser_read_uint32(¶m->burst,
1515 PARSE_ERROR((status == 0), section_name,
1521 PARSE_ERROR_INVALID(0, section_name, ent->name);
1528 parse_txq(struct app_params *app,
1529 const char *section_name,
1530 struct rte_cfgfile *cfg)
1532 struct app_pktq_hwq_out_params *param;
1533 struct rte_cfgfile_entry *entries;
1537 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1538 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1540 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1541 PARSE_ERROR_MALLOC(entries != NULL);
1543 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1545 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1546 param = &app->hwq_out_params[param_idx];
1547 PARSE_CHECK_DUPLICATE_SECTION(param);
1549 APP_PARAM_ADD_LINK_FOR_TXQ(app, section_name);
1551 for (i = 0; i < n_entries; i++) {
1552 struct rte_cfgfile_entry *ent = &entries[i];
1554 if (strcmp(ent->name, "size") == 0) {
1555 int status = parser_read_uint32(¶m->size,
1558 PARSE_ERROR((status == 0), section_name,
1563 if (strcmp(ent->name, "burst") == 0) {
1564 int status = parser_read_uint32(¶m->burst,
1567 PARSE_ERROR((status == 0), section_name,
1572 if (strcmp(ent->name, "dropless") == 0) {
1573 int status = parser_read_arg_bool(ent->value);
1576 PARSE_ERROR((status != -EINVAL), section_name,
1578 param->dropless = status;
1582 if (strcmp(ent->name, "n_retries") == 0) {
1583 int status = parser_read_uint64(¶m->n_retries,
1586 PARSE_ERROR((status == 0), section_name,
1592 PARSE_ERROR_INVALID(0, section_name, ent->name);
1599 parse_swq(struct app_params *app,
1600 const char *section_name,
1601 struct rte_cfgfile *cfg)
1603 struct app_pktq_swq_params *param;
1604 struct rte_cfgfile_entry *entries;
1606 uint32_t mtu_present = 0;
1607 uint32_t metadata_size_present = 0;
1608 uint32_t mempool_direct_present = 0;
1609 uint32_t mempool_indirect_present = 0;
1613 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1614 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1616 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1617 PARSE_ERROR_MALLOC(entries != NULL);
1619 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1621 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1622 param = &app->swq_params[param_idx];
1623 PARSE_CHECK_DUPLICATE_SECTION(param);
1625 for (i = 0; i < n_entries; i++) {
1626 struct rte_cfgfile_entry *ent = &entries[i];
1628 if (strcmp(ent->name, "size") == 0) {
1629 int status = parser_read_uint32(¶m->size,
1632 PARSE_ERROR((status == 0), section_name,
1637 if (strcmp(ent->name, "burst_read") == 0) {
1638 int status = parser_read_uint32(&
1639 param->burst_read, ent->value);
1641 PARSE_ERROR((status == 0), section_name,
1646 if (strcmp(ent->name, "burst_write") == 0) {
1647 int status = parser_read_uint32(
1648 ¶m->burst_write, ent->value);
1650 PARSE_ERROR((status == 0), section_name,
1655 if (strcmp(ent->name, "dropless") == 0) {
1656 int status = parser_read_arg_bool(ent->value);
1658 PARSE_ERROR((status != -EINVAL), section_name,
1660 param->dropless = status;
1664 if (strcmp(ent->name, "n_retries") == 0) {
1665 int status = parser_read_uint64(¶m->n_retries,
1668 PARSE_ERROR((status == 0), section_name,
1673 if (strcmp(ent->name, "cpu") == 0) {
1674 int status = parser_read_uint32(
1675 ¶m->cpu_socket_id, ent->value);
1677 PARSE_ERROR((status == 0), section_name, ent->name);
1681 if (strcmp(ent->name, "ipv4_frag") == 0) {
1682 int status = parser_read_arg_bool(ent->value);
1684 PARSE_ERROR((status != -EINVAL), section_name,
1687 param->ipv4_frag = status;
1688 if (param->mtu == 0)
1694 if (strcmp(ent->name, "ipv6_frag") == 0) {
1695 int status = parser_read_arg_bool(ent->value);
1697 PARSE_ERROR((status != -EINVAL), section_name,
1699 param->ipv6_frag = status;
1700 if (param->mtu == 0)
1705 if (strcmp(ent->name, "ipv4_ras") == 0) {
1706 int status = parser_read_arg_bool(ent->value);
1708 PARSE_ERROR((status != -EINVAL), section_name,
1710 param->ipv4_ras = status;
1714 if (strcmp(ent->name, "ipv6_ras") == 0) {
1715 int status = parser_read_arg_bool(ent->value);
1717 PARSE_ERROR((status != -EINVAL), section_name,
1719 param->ipv6_ras = status;
1723 if (strcmp(ent->name, "mtu") == 0) {
1724 int status = parser_read_uint32(¶m->mtu,
1727 PARSE_ERROR((status == 0), section_name,
1733 if (strcmp(ent->name, "metadata_size") == 0) {
1734 int status = parser_read_uint32(
1735 ¶m->metadata_size, ent->value);
1737 PARSE_ERROR((status == 0), section_name,
1739 metadata_size_present = 1;
1743 if (strcmp(ent->name, "mempool_direct") == 0) {
1744 int status = validate_name(ent->value,
1748 PARSE_ERROR((status == 0), section_name,
1751 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1752 param->mempool_direct_id = idx;
1754 mempool_direct_present = 1;
1758 if (strcmp(ent->name, "mempool_indirect") == 0) {
1759 int status = validate_name(ent->value,
1763 PARSE_ERROR((status == 0), section_name,
1766 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1767 param->mempool_indirect_id = idx;
1769 mempool_indirect_present = 1;
1774 PARSE_ERROR_INVALID(0, section_name, ent->name);
1777 APP_CHECK(((mtu_present == 0) ||
1778 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1779 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1780 "is off, therefore entry \"mtu\" is not allowed",
1783 APP_CHECK(((metadata_size_present == 0) ||
1784 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1785 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1786 "is off, therefore entry \"metadata_size\" is "
1787 "not allowed", section_name);
1789 APP_CHECK(((mempool_direct_present == 0) ||
1790 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1791 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1792 "is off, therefore entry \"mempool_direct\" is "
1793 "not allowed", section_name);
1795 APP_CHECK(((mempool_indirect_present == 0) ||
1796 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1797 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1798 "is off, therefore entry \"mempool_indirect\" is "
1799 "not allowed", section_name);
1805 parse_tm(struct app_params *app,
1806 const char *section_name,
1807 struct rte_cfgfile *cfg)
1809 struct app_pktq_tm_params *param;
1810 struct rte_cfgfile_entry *entries;
1814 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1815 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1817 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1818 PARSE_ERROR_MALLOC(entries != NULL);
1820 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1822 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1823 param = &app->tm_params[param_idx];
1824 PARSE_CHECK_DUPLICATE_SECTION(param);
1826 APP_PARAM_ADD_LINK_FOR_TM(app, section_name);
1828 for (i = 0; i < n_entries; i++) {
1829 struct rte_cfgfile_entry *ent = &entries[i];
1831 if (strcmp(ent->name, "cfg") == 0) {
1832 param->file_name = strdup(ent->value);
1833 PARSE_ERROR_MALLOC(param->file_name != NULL);
1837 if (strcmp(ent->name, "burst_read") == 0) {
1838 int status = parser_read_uint32(
1839 ¶m->burst_read, ent->value);
1841 PARSE_ERROR((status == 0), section_name,
1846 if (strcmp(ent->name, "burst_write") == 0) {
1847 int status = parser_read_uint32(
1848 ¶m->burst_write, ent->value);
1850 PARSE_ERROR((status == 0), section_name,
1856 PARSE_ERROR_INVALID(0, section_name, ent->name);
1863 parse_tap(struct app_params *app,
1864 const char *section_name,
1865 struct rte_cfgfile *cfg)
1867 struct app_pktq_tap_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->tap_params, section_name);
1881 param = &app->tap_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, "burst_read") == 0) {
1888 int status = parser_read_uint32(
1889 ¶m->burst_read, ent->value);
1891 PARSE_ERROR((status == 0), section_name,
1896 if (strcmp(ent->name, "burst_write") == 0) {
1897 int status = parser_read_uint32(
1898 ¶m->burst_write, ent->value);
1900 PARSE_ERROR((status == 0), section_name,
1905 if (strcmp(ent->name, "dropless") == 0) {
1906 int status = parser_read_arg_bool(ent->value);
1908 PARSE_ERROR((status != -EINVAL), section_name,
1910 param->dropless = status;
1914 if (strcmp(ent->name, "n_retries") == 0) {
1915 int status = parser_read_uint64(¶m->n_retries,
1918 PARSE_ERROR((status == 0), section_name,
1923 if (strcmp(ent->name, "mempool") == 0) {
1924 int status = validate_name(ent->value,
1928 PARSE_ERROR((status == 0), section_name,
1931 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1932 param->mempool_id = idx;
1938 PARSE_ERROR_INVALID(0, section_name, ent->name);
1945 parse_kni(struct app_params *app,
1946 const char *section_name,
1947 struct rte_cfgfile *cfg)
1949 struct app_pktq_kni_params *param;
1950 struct rte_cfgfile_entry *entries;
1954 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1955 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1957 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1958 PARSE_ERROR_MALLOC(entries != NULL);
1960 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1962 param_idx = APP_PARAM_ADD(app->kni_params, section_name);
1963 param = &app->kni_params[param_idx];
1964 PARSE_CHECK_DUPLICATE_SECTION(param);
1966 APP_PARAM_ADD_LINK_FOR_KNI(app, section_name);
1968 for (i = 0; i < n_entries; i++) {
1969 struct rte_cfgfile_entry *ent = &entries[i];
1971 if (strcmp(ent->name, "core") == 0) {
1972 int status = parse_pipeline_core(
1975 ¶m->hyper_th_id,
1978 PARSE_ERROR((status == 0), section_name,
1980 param->force_bind = 1;
1984 if (strcmp(ent->name, "mempool") == 0) {
1985 int status = validate_name(ent->value,
1989 PARSE_ERROR((status == 0), section_name,
1992 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1993 param->mempool_id = idx;
1997 if (strcmp(ent->name, "burst_read") == 0) {
1998 int status = parser_read_uint32(¶m->burst_read,
2001 PARSE_ERROR((status == 0), section_name,
2006 if (strcmp(ent->name, "burst_write") == 0) {
2007 int status = parser_read_uint32(¶m->burst_write,
2010 PARSE_ERROR((status == 0), section_name,
2015 if (strcmp(ent->name, "dropless") == 0) {
2016 int status = parser_read_arg_bool(ent->value);
2018 PARSE_ERROR((status != -EINVAL), section_name,
2020 param->dropless = status;
2024 if (strcmp(ent->name, "n_retries") == 0) {
2025 int status = parser_read_uint64(¶m->n_retries,
2028 PARSE_ERROR((status == 0), section_name,
2034 PARSE_ERROR_INVALID(0, section_name, ent->name);
2041 parse_source(struct app_params *app,
2042 const char *section_name,
2043 struct rte_cfgfile *cfg)
2045 struct app_pktq_source_params *param;
2046 struct rte_cfgfile_entry *entries;
2049 uint32_t pcap_file_present = 0;
2050 uint32_t pcap_size_present = 0;
2052 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2053 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2055 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2056 PARSE_ERROR_MALLOC(entries != NULL);
2058 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2060 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2061 param = &app->source_params[param_idx];
2062 PARSE_CHECK_DUPLICATE_SECTION(param);
2064 for (i = 0; i < n_entries; i++) {
2065 struct rte_cfgfile_entry *ent = &entries[i];
2067 if (strcmp(ent->name, "mempool") == 0) {
2068 int status = validate_name(ent->value,
2072 PARSE_ERROR((status == 0), section_name,
2075 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
2076 param->mempool_id = idx;
2080 if (strcmp(ent->name, "burst") == 0) {
2081 int status = parser_read_uint32(¶m->burst,
2084 PARSE_ERROR((status == 0), section_name,
2089 if (strcmp(ent->name, "pcap_file_rd") == 0) {
2090 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2091 section_name, ent->name);
2093 param->file_name = strdup(ent->value);
2095 PARSE_ERROR_MALLOC(param->file_name != NULL);
2096 pcap_file_present = 1;
2101 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2104 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2105 section_name, ent->name);
2107 status = parser_read_uint32(
2108 ¶m->n_bytes_per_pkt, ent->value);
2110 PARSE_ERROR((status == 0), section_name,
2112 pcap_size_present = 1;
2118 PARSE_ERROR_INVALID(0, section_name, ent->name);
2125 parse_sink(struct app_params *app,
2126 const char *section_name,
2127 struct rte_cfgfile *cfg)
2129 struct app_pktq_sink_params *param;
2130 struct rte_cfgfile_entry *entries;
2133 uint32_t pcap_file_present = 0;
2134 uint32_t pcap_n_pkt_present = 0;
2136 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2137 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2139 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2140 PARSE_ERROR_MALLOC(entries != NULL);
2142 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2144 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2145 param = &app->sink_params[param_idx];
2146 PARSE_CHECK_DUPLICATE_SECTION(param);
2148 for (i = 0; i < n_entries; i++) {
2149 struct rte_cfgfile_entry *ent = &entries[i];
2151 if (strcmp(ent->name, "pcap_file_wr") == 0) {
2152 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2153 section_name, ent->name);
2155 param->file_name = strdup(ent->value);
2157 PARSE_ERROR_MALLOC((param->file_name != NULL));
2162 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
2165 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2166 section_name, ent->name);
2168 status = parser_read_uint32(
2169 ¶m->n_pkts_to_dump, ent->value);
2171 PARSE_ERROR((status == 0), section_name,
2178 PARSE_ERROR_INVALID(0, section_name, ent->name);
2185 parse_msgq_req_pipeline(struct app_params *app,
2186 const char *section_name,
2187 struct rte_cfgfile *cfg)
2189 struct app_msgq_params *param;
2190 struct rte_cfgfile_entry *entries;
2194 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2195 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2197 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2198 PARSE_ERROR_MALLOC(entries != NULL);
2200 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2202 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2203 param = &app->msgq_params[param_idx];
2204 PARSE_CHECK_DUPLICATE_SECTION(param);
2206 for (i = 0; i < n_entries; i++) {
2207 struct rte_cfgfile_entry *ent = &entries[i];
2209 if (strcmp(ent->name, "size") == 0) {
2210 int status = parser_read_uint32(¶m->size,
2213 PARSE_ERROR((status == 0), section_name,
2219 PARSE_ERROR_INVALID(0, section_name, ent->name);
2226 parse_msgq_rsp_pipeline(struct app_params *app,
2227 const char *section_name,
2228 struct rte_cfgfile *cfg)
2230 struct app_msgq_params *param;
2231 struct rte_cfgfile_entry *entries;
2235 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2236 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2238 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2239 PARSE_ERROR_MALLOC(entries != NULL);
2241 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2243 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2244 param = &app->msgq_params[param_idx];
2245 PARSE_CHECK_DUPLICATE_SECTION(param);
2247 for (i = 0; i < n_entries; i++) {
2248 struct rte_cfgfile_entry *ent = &entries[i];
2250 if (strcmp(ent->name, "size") == 0) {
2251 int status = parser_read_uint32(¶m->size,
2254 PARSE_ERROR((status == 0), section_name,
2260 PARSE_ERROR_INVALID(0, section_name, ent->name);
2267 parse_msgq(struct app_params *app,
2268 const char *section_name,
2269 struct rte_cfgfile *cfg)
2271 struct app_msgq_params *param;
2272 struct rte_cfgfile_entry *entries;
2276 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2277 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2279 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2280 PARSE_ERROR_MALLOC(entries != NULL);
2282 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2284 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2285 param = &app->msgq_params[param_idx];
2286 PARSE_CHECK_DUPLICATE_SECTION(param);
2288 for (i = 0; i < n_entries; i++) {
2289 struct rte_cfgfile_entry *ent = &entries[i];
2291 if (strcmp(ent->name, "size") == 0) {
2292 int status = parser_read_uint32(¶m->size,
2295 PARSE_ERROR((status == 0), section_name,
2300 if (strcmp(ent->name, "cpu") == 0) {
2301 int status = parser_read_uint32(
2302 ¶m->cpu_socket_id, ent->value);
2304 PARSE_ERROR((status == 0), section_name,
2310 PARSE_ERROR_INVALID(0, section_name, ent->name);
2316 typedef void (*config_section_load)(struct app_params *p,
2317 const char *section_name,
2318 struct rte_cfgfile *cfg);
2320 struct config_section {
2321 const char prefix[CFG_NAME_LEN];
2323 config_section_load load;
2326 static const struct config_section cfg_file_scheme[] = {
2327 {"EAL", 0, parse_eal},
2328 {"PIPELINE", 1, parse_pipeline},
2329 {"MEMPOOL", 1, parse_mempool},
2330 {"LINK", 1, parse_link},
2331 {"RXQ", 2, parse_rxq},
2332 {"TXQ", 2, parse_txq},
2333 {"SWQ", 1, parse_swq},
2334 {"TM", 1, parse_tm},
2335 {"TAP", 1, parse_tap},
2336 {"KNI", 1, parse_kni},
2337 {"SOURCE", 1, parse_source},
2338 {"SINK", 1, parse_sink},
2339 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2340 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2341 {"MSGQ", 1, parse_msgq},
2345 create_implicit_mempools(struct app_params *app)
2347 APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2351 create_implicit_links_from_port_mask(struct app_params *app,
2354 uint32_t pmd_id, link_id;
2357 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2358 char name[APP_PARAM_NAME_SIZE];
2361 if ((port_mask & (1LLU << pmd_id)) == 0)
2364 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2365 idx = APP_PARAM_ADD(app->link_params, name);
2367 app->link_params[idx].pmd_id = pmd_id;
2373 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2377 for (i = 0; i < app->n_links; i++) {
2378 struct app_link_params *link = &app->link_params[i];
2380 APP_CHECK((strlen(link->pci_bdf)),
2381 "Parse error: %s pci_bdf is not configured "
2382 "(port_mask is not provided)",
2390 app_config_parse(struct app_params *app, const char *file_name)
2392 struct rte_cfgfile *cfg;
2393 char **section_names;
2394 int i, j, sect_count;
2396 /* Implicit mempools */
2397 create_implicit_mempools(app);
2401 create_implicit_links_from_port_mask(app, app->port_mask);
2403 /* Load application configuration file */
2404 cfg = rte_cfgfile_load(file_name, 0);
2405 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2406 "file %s", file_name);
2408 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2409 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2410 "in file \"%s\" return %d", file_name,
2413 section_names = malloc(sect_count * sizeof(char *));
2414 PARSE_ERROR_MALLOC(section_names != NULL);
2416 for (i = 0; i < sect_count; i++)
2417 section_names[i] = malloc(CFG_NAME_LEN);
2419 rte_cfgfile_sections(cfg, section_names, sect_count);
2421 for (i = 0; i < sect_count; i++) {
2422 const struct config_section *sch_s;
2423 int len, cfg_name_len;
2425 cfg_name_len = strlen(section_names[i]);
2427 /* Find section type */
2428 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2429 sch_s = &cfg_file_scheme[j];
2430 len = strlen(sch_s->prefix);
2432 if (cfg_name_len < len)
2435 /* After section name we expect only '\0' or digit or
2436 * digit dot digit, so protect against false matching,
2437 * for example: "ABC" should match section name
2438 * "ABC0.0", but it should not match section_name
2441 if ((section_names[i][len] != '\0') &&
2442 !isdigit(section_names[i][len]))
2445 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2449 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2450 "Parse error: unknown section %s",
2453 APP_CHECK(validate_name(section_names[i],
2455 sch_s->numbers) == 0,
2456 "Parse error: invalid section name \"%s\"",
2459 sch_s->load(app, section_names[i], cfg);
2462 for (i = 0; i < sect_count; i++)
2463 free(section_names[i]);
2465 free(section_names);
2467 rte_cfgfile_close(cfg);
2469 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2470 APP_PARAM_COUNT(app->link_params, app->n_links);
2471 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2472 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2473 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2474 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2475 APP_PARAM_COUNT(app->tap_params, app->n_pktq_tap);
2476 APP_PARAM_COUNT(app->kni_params, app->n_pktq_kni);
2477 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2478 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2479 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2480 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2482 if (app->port_mask == 0)
2483 assign_link_pmd_id_from_pci_bdf(app);
2485 /* Save configuration to output file */
2486 app_config_save(app, app->output_file);
2488 /* Load TM configuration files */
2489 app_config_parse_tm(app);
2495 save_eal_params(struct app_params *app, FILE *f)
2497 struct app_eal_params *p = &app->eal_params;
2500 fprintf(f, "[EAL]\n");
2503 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2505 if (p->master_lcore_present)
2506 fprintf(f, "%s = %" PRIu32 "\n",
2507 "master_lcore", p->master_lcore);
2509 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2511 if (p->memory_present)
2512 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2514 if (p->ranks_present)
2515 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2517 for (i = 0; i < APP_MAX_LINKS; i++) {
2518 if (p->pci_blacklist[i] == NULL)
2521 fprintf(f, "%s = %s\n", "pci_blacklist",
2522 p->pci_blacklist[i]);
2525 for (i = 0; i < APP_MAX_LINKS; i++) {
2526 if (p->pci_whitelist[i] == NULL)
2529 fprintf(f, "%s = %s\n", "pci_whitelist",
2530 p->pci_whitelist[i]);
2533 for (i = 0; i < APP_MAX_LINKS; i++) {
2534 if (p->vdev[i] == NULL)
2537 fprintf(f, "%s = %s\n", "vdev",
2541 if (p->vmware_tsc_map_present)
2542 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2543 (p->vmware_tsc_map) ? "yes" : "no");
2546 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2549 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2551 if (p->log_level_present)
2552 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2554 if (p->version_present)
2555 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2557 if (p->help_present)
2558 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2560 if (p->no_huge_present)
2561 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2563 if (p->no_pci_present)
2564 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2566 if (p->no_hpet_present)
2567 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2569 if (p->no_shconf_present)
2570 fprintf(f, "%s = %s\n", "no_shconf",
2571 (p->no_shconf) ? "yes" : "no");
2574 fprintf(f, "%s = %s\n", "d", p->add_driver);
2577 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2580 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2583 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2585 if (p->base_virtaddr)
2586 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2588 if (p->create_uio_dev_present)
2589 fprintf(f, "%s = %s\n", "create_uio_dev",
2590 (p->create_uio_dev) ? "yes" : "no");
2593 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2599 save_mempool_params(struct app_params *app, FILE *f)
2601 struct app_mempool_params *p;
2604 count = RTE_DIM(app->mempool_params);
2605 for (i = 0; i < count; i++) {
2606 p = &app->mempool_params[i];
2607 if (!APP_PARAM_VALID(p))
2610 fprintf(f, "[%s]\n", p->name);
2611 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2612 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2613 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2614 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2621 save_links_params(struct app_params *app, FILE *f)
2623 struct app_link_params *p;
2626 count = RTE_DIM(app->link_params);
2627 for (i = 0; i < count; i++) {
2628 p = &app->link_params[i];
2629 if (!APP_PARAM_VALID(p))
2632 fprintf(f, "[%s]\n", p->name);
2633 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2634 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2635 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2636 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2638 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2639 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2640 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2641 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2648 fprintf(f, "rss_qs = ");
2649 for (j = 0; j < p->n_rss_qs; j++)
2650 fprintf(f, "%" PRIu32 " ", p->rss_qs[j]);
2653 /* rss_proto_ipv4 */
2654 if (p->rss_proto_ipv4) {
2655 fprintf(f, "rss_proto_ipv4 = ");
2656 if (p->rss_proto_ipv4 & ETH_RSS_IPV4)
2658 if (p->rss_proto_ipv4 & ETH_RSS_FRAG_IPV4)
2659 fprintf(f, "FRAG ");
2660 if (p->rss_proto_ipv4 &
2661 ETH_RSS_NONFRAG_IPV4_TCP)
2663 if (p->rss_proto_ipv4 &
2664 ETH_RSS_NONFRAG_IPV4_UDP)
2666 if (p->rss_proto_ipv4 &
2667 ETH_RSS_NONFRAG_IPV4_SCTP)
2668 fprintf(f, "SCTP ");
2669 if (p->rss_proto_ipv4 &
2670 ETH_RSS_NONFRAG_IPV4_OTHER)
2671 fprintf(f, "OTHER ");
2674 fprintf(f, "; rss_proto_ipv4 = <NONE>\n");
2676 /* rss_proto_ipv6 */
2677 if (p->rss_proto_ipv6) {
2678 fprintf(f, "rss_proto_ipv6 = ");
2679 if (p->rss_proto_ipv6 & ETH_RSS_IPV6)
2681 if (p->rss_proto_ipv6 & ETH_RSS_FRAG_IPV6)
2682 fprintf(f, "FRAG ");
2683 if (p->rss_proto_ipv6 &
2684 ETH_RSS_NONFRAG_IPV6_TCP)
2686 if (p->rss_proto_ipv6 &
2687 ETH_RSS_NONFRAG_IPV6_UDP)
2689 if (p->rss_proto_ipv6 &
2690 ETH_RSS_NONFRAG_IPV6_SCTP)
2691 fprintf(f, "SCTP ");
2692 if (p->rss_proto_ipv6 &
2693 ETH_RSS_NONFRAG_IPV6_OTHER)
2694 fprintf(f, "OTHER ");
2695 if (p->rss_proto_ipv6 & ETH_RSS_IPV6_EX)
2696 fprintf(f, "IP_EX ");
2697 if (p->rss_proto_ipv6 &
2698 ETH_RSS_IPV6_TCP_EX)
2699 fprintf(f, "TCP_EX ");
2700 if (p->rss_proto_ipv6 &
2701 ETH_RSS_IPV6_UDP_EX)
2702 fprintf(f, "UDP_EX ");
2705 fprintf(f, "; rss_proto_ipv6 = <NONE>\n");
2708 if (p->rss_proto_l2) {
2709 fprintf(f, "rss_proto_l2 = ");
2710 if (p->rss_proto_l2 & ETH_RSS_L2_PAYLOAD)
2714 fprintf(f, "; rss_proto_l2 = <NONE>\n");
2716 fprintf(f, "; rss_qs = <NONE>\n");
2717 fprintf(f, "; rss_proto_ipv4 = <NONE>\n");
2718 fprintf(f, "; rss_proto_ipv6 = <NONE>\n");
2719 fprintf(f, "; rss_proto_l2 = <NONE>\n");
2722 if (strlen(p->pci_bdf))
2723 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2730 save_rxq_params(struct app_params *app, FILE *f)
2732 struct app_pktq_hwq_in_params *p;
2735 count = RTE_DIM(app->hwq_in_params);
2736 for (i = 0; i < count; i++) {
2737 p = &app->hwq_in_params[i];
2738 if (!APP_PARAM_VALID(p))
2741 fprintf(f, "[%s]\n", p->name);
2742 fprintf(f, "%s = %s\n",
2744 app->mempool_params[p->mempool_id].name);
2745 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2746 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2753 save_txq_params(struct app_params *app, FILE *f)
2755 struct app_pktq_hwq_out_params *p;
2758 count = RTE_DIM(app->hwq_out_params);
2759 for (i = 0; i < count; i++) {
2760 p = &app->hwq_out_params[i];
2761 if (!APP_PARAM_VALID(p))
2764 fprintf(f, "[%s]\n", p->name);
2765 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2766 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2767 fprintf(f, "%s = %s\n",
2769 p->dropless ? "yes" : "no");
2770 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2777 save_swq_params(struct app_params *app, FILE *f)
2779 struct app_pktq_swq_params *p;
2782 count = RTE_DIM(app->swq_params);
2783 for (i = 0; i < count; i++) {
2784 p = &app->swq_params[i];
2785 if (!APP_PARAM_VALID(p))
2788 fprintf(f, "[%s]\n", p->name);
2789 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2790 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2791 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2792 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2793 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2794 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2795 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2796 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2797 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2798 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2799 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2800 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2801 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2802 fprintf(f, "%s = %s\n",
2804 app->mempool_params[p->mempool_direct_id].name);
2805 fprintf(f, "%s = %s\n",
2807 app->mempool_params[p->mempool_indirect_id].name);
2815 save_tm_params(struct app_params *app, FILE *f)
2817 struct app_pktq_tm_params *p;
2820 count = RTE_DIM(app->tm_params);
2821 for (i = 0; i < count; i++) {
2822 p = &app->tm_params[i];
2823 if (!APP_PARAM_VALID(p))
2826 fprintf(f, "[%s]\n", p->name);
2827 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2828 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2829 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2836 save_tap_params(struct app_params *app, FILE *f)
2838 struct app_pktq_tap_params *p;
2841 count = RTE_DIM(app->tap_params);
2842 for (i = 0; i < count; i++) {
2843 p = &app->tap_params[i];
2844 if (!APP_PARAM_VALID(p))
2847 fprintf(f, "[%s]\n", p->name);
2848 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2849 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2850 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2851 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2852 fprintf(f, "%s = %s\n", "mempool",
2853 app->mempool_params[p->mempool_id].name);
2860 save_kni_params(struct app_params *app, FILE *f)
2862 struct app_pktq_kni_params *p;
2865 count = RTE_DIM(app->kni_params);
2866 for (i = 0; i < count; i++) {
2867 p = &app->kni_params[i];
2868 if (!APP_PARAM_VALID(p))
2872 fprintf(f, "[%s]\n", p->name);
2875 if (p->force_bind) {
2876 fprintf(f, "; force_bind = 1\n");
2877 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2880 (p->hyper_th_id) ? "h" : "");
2882 fprintf(f, "; force_bind = 0\n");
2885 fprintf(f, "%s = %s\n", "mempool",
2886 app->mempool_params[p->mempool_id].name);
2889 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2892 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2895 fprintf(f, "%s = %s\n",
2897 p->dropless ? "yes" : "no");
2900 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2907 save_source_params(struct app_params *app, FILE *f)
2909 struct app_pktq_source_params *p;
2912 count = RTE_DIM(app->source_params);
2913 for (i = 0; i < count; i++) {
2914 p = &app->source_params[i];
2915 if (!APP_PARAM_VALID(p))
2918 fprintf(f, "[%s]\n", p->name);
2919 fprintf(f, "%s = %s\n",
2921 app->mempool_params[p->mempool_id].name);
2922 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2923 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2924 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2925 p->n_bytes_per_pkt);
2931 save_sink_params(struct app_params *app, FILE *f)
2933 struct app_pktq_sink_params *p;
2936 count = RTE_DIM(app->sink_params);
2937 for (i = 0; i < count; i++) {
2938 p = &app->sink_params[i];
2939 if (!APP_PARAM_VALID(p))
2942 fprintf(f, "[%s]\n", p->name);
2943 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2944 fprintf(f, "%s = %" PRIu32 "\n",
2945 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2951 save_msgq_params(struct app_params *app, FILE *f)
2953 struct app_msgq_params *p;
2956 count = RTE_DIM(app->msgq_params);
2957 for (i = 0; i < count; i++) {
2958 p = &app->msgq_params[i];
2959 if (!APP_PARAM_VALID(p))
2962 fprintf(f, "[%s]\n", p->name);
2963 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2964 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2971 save_pipeline_params(struct app_params *app, FILE *f)
2975 count = RTE_DIM(app->pipeline_params);
2976 for (i = 0; i < count; i++) {
2977 struct app_pipeline_params *p = &app->pipeline_params[i];
2979 if (!APP_PARAM_VALID(p))
2983 fprintf(f, "[%s]\n", p->name);
2986 fprintf(f, "type = %s\n", p->type);
2989 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2992 (p->hyper_th_id) ? "h" : "");
2998 fprintf(f, "pktq_in =");
2999 for (j = 0; j < p->n_pktq_in; j++) {
3000 struct app_pktq_in_params *pp = &p->pktq_in[j];
3004 case APP_PKTQ_IN_HWQ:
3005 name = app->hwq_in_params[pp->id].name;
3007 case APP_PKTQ_IN_SWQ:
3008 name = app->swq_params[pp->id].name;
3010 case APP_PKTQ_IN_TM:
3011 name = app->tm_params[pp->id].name;
3013 case APP_PKTQ_IN_TAP:
3014 name = app->tap_params[pp->id].name;
3016 case APP_PKTQ_IN_KNI:
3017 name = app->kni_params[pp->id].name;
3019 case APP_PKTQ_IN_SOURCE:
3020 name = app->source_params[pp->id].name;
3023 APP_CHECK(0, "System error "
3024 "occurred while saving "
3025 "parameter to file");
3028 fprintf(f, " %s", name);
3034 if (p->n_pktq_out) {
3037 fprintf(f, "pktq_out =");
3038 for (j = 0; j < p->n_pktq_out; j++) {
3039 struct app_pktq_out_params *pp =
3044 case APP_PKTQ_OUT_HWQ:
3045 name = app->hwq_out_params[pp->id].name;
3047 case APP_PKTQ_OUT_SWQ:
3048 name = app->swq_params[pp->id].name;
3050 case APP_PKTQ_OUT_TM:
3051 name = app->tm_params[pp->id].name;
3053 case APP_PKTQ_OUT_TAP:
3054 name = app->tap_params[pp->id].name;
3056 case APP_PKTQ_OUT_KNI:
3057 name = app->kni_params[pp->id].name;
3059 case APP_PKTQ_OUT_SINK:
3060 name = app->sink_params[pp->id].name;
3063 APP_CHECK(0, "System error "
3064 "occurred while saving "
3065 "parameter to file");
3068 fprintf(f, " %s", name);
3077 fprintf(f, "msgq_in =");
3078 for (j = 0; j < p->n_msgq_in; j++) {
3079 uint32_t id = p->msgq_in[j];
3080 char *name = app->msgq_params[id].name;
3082 fprintf(f, " %s", name);
3088 if (p->n_msgq_out) {
3091 fprintf(f, "msgq_out =");
3092 for (j = 0; j < p->n_msgq_out; j++) {
3093 uint32_t id = p->msgq_out[j];
3094 char *name = app->msgq_params[id].name;
3096 fprintf(f, " %s", name);
3102 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3108 for (j = 0; j < p->n_args; j++)
3109 fprintf(f, "%s = %s\n", p->args_name[j],
3118 app_config_save(struct app_params *app, const char *file_name)
3121 char *name, *dir_name;
3124 name = strdup(file_name);
3125 dir_name = dirname(name);
3126 status = access(dir_name, W_OK);
3127 APP_CHECK((status == 0),
3128 "Error: need write access privilege to directory "
3129 "\"%s\" to save configuration\n", dir_name);
3131 file = fopen(file_name, "w");
3132 APP_CHECK((file != NULL),
3133 "Error: failed to save configuration to file \"%s\"",
3136 save_eal_params(app, file);
3137 save_pipeline_params(app, file);
3138 save_mempool_params(app, file);
3139 save_links_params(app, file);
3140 save_rxq_params(app, file);
3141 save_txq_params(app, file);
3142 save_swq_params(app, file);
3143 save_tm_params(app, file);
3144 save_tap_params(app, file);
3145 save_kni_params(app, file);
3146 save_source_params(app, file);
3147 save_sink_params(app, file);
3148 save_msgq_params(app, file);
3155 app_config_init(struct app_params *app)
3159 memcpy(app, &app_params_default, sizeof(struct app_params));
3161 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3162 memcpy(&app->mempool_params[i],
3163 &mempool_params_default,
3164 sizeof(struct app_mempool_params));
3166 for (i = 0; i < RTE_DIM(app->link_params); i++)
3167 memcpy(&app->link_params[i],
3168 &link_params_default,
3169 sizeof(struct app_link_params));
3171 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3172 memcpy(&app->hwq_in_params[i],
3173 &default_hwq_in_params,
3174 sizeof(default_hwq_in_params));
3176 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3177 memcpy(&app->hwq_out_params[i],
3178 &default_hwq_out_params,
3179 sizeof(default_hwq_out_params));
3181 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3182 memcpy(&app->swq_params[i],
3183 &default_swq_params,
3184 sizeof(default_swq_params));
3186 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3187 memcpy(&app->tm_params[i],
3189 sizeof(default_tm_params));
3191 for (i = 0; i < RTE_DIM(app->tap_params); i++)
3192 memcpy(&app->tap_params[i],
3193 &default_tap_params,
3194 sizeof(default_tap_params));
3196 for (i = 0; i < RTE_DIM(app->kni_params); i++)
3197 memcpy(&app->kni_params[i],
3198 &default_kni_params,
3199 sizeof(default_kni_params));
3201 for (i = 0; i < RTE_DIM(app->source_params); i++)
3202 memcpy(&app->source_params[i],
3203 &default_source_params,
3204 sizeof(default_source_params));
3206 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3207 memcpy(&app->sink_params[i],
3208 &default_sink_params,
3209 sizeof(default_sink_params));
3211 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3212 memcpy(&app->msgq_params[i],
3213 &default_msgq_params,
3214 sizeof(default_msgq_params));
3216 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3217 memcpy(&app->pipeline_params[i],
3218 &default_pipeline_params,
3219 sizeof(default_pipeline_params));
3225 filenamedup(const char *filename, const char *suffix)
3227 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3232 sprintf(s, "%s%s", filename, suffix);
3237 app_config_args(struct app_params *app, int argc, char **argv)
3239 const char *optname;
3240 int opt, option_index;
3241 int f_present, s_present, p_present, l_present;
3242 int preproc_present, preproc_params_present;
3245 static struct option lgopts[] = {
3246 { "preproc", 1, 0, 0 },
3247 { "preproc-args", 1, 0, 0 },
3251 /* Copy application name */
3252 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3258 preproc_present = 0;
3259 preproc_params_present = 0;
3261 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3262 &option_index)) != EOF)
3266 rte_panic("Error: Config file is provided "
3267 "more than once\n");
3270 if (!strlen(optarg))
3271 rte_panic("Error: Config file name is null\n");
3273 app->config_file = strdup(optarg);
3274 if (app->config_file == NULL)
3275 rte_panic("Error: Memory allocation failure\n");
3281 rte_panic("Error: Script file is provided "
3282 "more than once\n");
3285 if (!strlen(optarg))
3286 rte_panic("Error: Script file name is null\n");
3288 app->script_file = strdup(optarg);
3289 if (app->script_file == NULL)
3290 rte_panic("Error: Memory allocation failure\n");
3296 rte_panic("Error: PORT_MASK is provided "
3297 "more than once\n");
3300 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3302 ((size_t) scaned != strlen(optarg)))
3303 rte_panic("Error: PORT_MASK is not "
3304 "a hexadecimal integer\n");
3306 if (app->port_mask == 0)
3307 rte_panic("Error: PORT_MASK is null\n");
3313 rte_panic("Error: LOG_LEVEL is provided "
3314 "more than once\n");
3317 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3319 ((size_t) scaned != strlen(optarg)) ||
3320 (app->log_level >= APP_LOG_LEVELS))
3321 rte_panic("Error: LOG_LEVEL invalid value\n");
3326 optname = lgopts[option_index].name;
3328 if (strcmp(optname, "preproc") == 0) {
3329 if (preproc_present)
3330 rte_panic("Error: Preprocessor argument "
3331 "is provided more than once\n");
3332 preproc_present = 1;
3334 app->preproc = strdup(optarg);
3338 if (strcmp(optname, "preproc-args") == 0) {
3339 if (preproc_params_present)
3340 rte_panic("Error: Preprocessor args "
3341 "are provided more than once\n");
3342 preproc_params_present = 1;
3344 app->preproc_args = strdup(optarg);
3348 app_print_usage(argv[0]);
3352 app_print_usage(argv[0]);
3355 optind = 1; /* reset getopt lib */
3357 /* Check dependencies between args */
3358 if (preproc_params_present && (preproc_present == 0))
3359 rte_panic("Error: Preprocessor args specified while "
3360 "preprocessor is not defined\n");
3362 app->parser_file = preproc_present ?
3363 filenamedup(app->config_file, ".preproc") :
3364 strdup(app->config_file);
3365 app->output_file = filenamedup(app->config_file, ".out");
3371 app_config_preproc(struct app_params *app)
3376 if (app->preproc == NULL)
3379 status = access(app->config_file, F_OK | R_OK);
3380 APP_CHECK((status == 0), "Error: Unable to open file %s",
3383 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3385 app->preproc_args ? app->preproc_args : "",
3389 status = system(buffer);
3390 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3391 "Error occurred while pre-processing file \"%s\"\n",