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 .header_split = 0, /* Header split */
72 .hw_ip_checksum = 0, /* IP checksum offload */
73 .hw_vlan_filter = 0, /* VLAN filtering */
74 .hw_vlan_strip = 0, /* VLAN strip */
75 .hw_vlan_extend = 0, /* Extended VLAN */
76 .jumbo_frame = 0, /* Jumbo frame support */
77 .hw_strip_crc = 1, /* CRC strip by HW */
78 .enable_scatter = 0, /* Scattered packets RX handler */
80 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
81 .split_hdr_size = 0, /* Header split buffer size */
91 .mq_mode = ETH_MQ_TX_NONE,
99 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
111 .rx_free_thresh = 64,
113 .rx_deferred_start = 0,
117 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
132 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
133 ETH_TXQ_FLAGS_NOOFFLOADS,
134 .tx_deferred_start = 0,
138 static const struct app_pktq_swq_params default_swq_params = {
152 .mempool_direct_id = 0,
153 .mempool_indirect_id = 0,
156 struct app_pktq_tm_params default_tm_params = {
158 .file_name = "./config/tm_profile.cfg",
163 struct app_pktq_tap_params default_tap_params = {
172 struct app_pktq_kni_params default_kni_params = {
186 struct app_pktq_source_params default_source_params = {
190 .file_name = "./config/packets.pcap",
191 .n_bytes_per_pkt = 0,
194 struct app_pktq_sink_params default_sink_params = {
200 struct app_msgq_params default_msgq_params = {
206 struct app_pipeline_params default_pipeline_params = {
219 static const char app_usage[] =
220 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
221 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
224 "\t-f CONFIG_FILE: Default config file is %s\n"
225 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
226 "config file when not provided)\n"
227 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
228 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
229 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
230 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
234 app_print_usage(char *prgname)
236 rte_exit(0, app_usage, prgname, app_params_default.config_file);
239 #define APP_PARAM_ADD(set, key) \
241 ssize_t pos = APP_PARAM_FIND(set, key); \
242 ssize_t size = RTE_DIM(set); \
245 for (pos = 0; pos < size; pos++) { \
246 if (!APP_PARAM_VALID(&((set)[pos]))) \
250 APP_CHECK((pos < size), \
251 "Parse error: size of %s is limited to %u elements",\
252 #set, (uint32_t) size); \
254 (set)[pos].name = strdup(key); \
255 APP_CHECK(((set)[pos].name), \
256 "Parse error: no free memory"); \
261 #define APP_PARAM_ADD_LINK_FOR_RXQ(app, rxq_name) \
263 char link_name[APP_PARAM_NAME_SIZE]; \
264 ssize_t link_param_pos; \
265 uint32_t link_id, queue_id; \
267 sscanf((rxq_name), "RXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
268 sprintf(link_name, "LINK%" PRIu32, link_id); \
269 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
273 #define APP_PARAM_ADD_LINK_FOR_TXQ(app, txq_name) \
275 char link_name[APP_PARAM_NAME_SIZE]; \
276 ssize_t link_param_pos; \
277 uint32_t link_id, queue_id; \
279 sscanf((txq_name), "TXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
280 sprintf(link_name, "LINK%" PRIu32, link_id); \
281 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
285 #define APP_PARAM_ADD_LINK_FOR_TM(app, tm_name) \
287 char link_name[APP_PARAM_NAME_SIZE]; \
288 ssize_t link_param_pos; \
291 sscanf((tm_name), "TM%" SCNu32, &link_id); \
292 sprintf(link_name, "LINK%" PRIu32, link_id); \
293 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
297 #define APP_PARAM_ADD_LINK_FOR_KNI(app, kni_name) \
299 char link_name[APP_PARAM_NAME_SIZE]; \
300 ssize_t link_param_pos; \
303 sscanf((kni_name), "KNI%" SCNu32, &link_id); \
304 sprintf(link_name, "LINK%" PRIu32, link_id); \
305 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
309 #define PARSE_CHECK_DUPLICATE_SECTION(obj) \
311 APP_CHECK(((obj)->parsed == 0), \
312 "Parse error: duplicate \"%s\" section", (obj)->name); \
316 #define PARSE_CHECK_DUPLICATE_SECTION_EAL(obj) \
318 APP_CHECK(((obj)->parsed == 0), \
319 "Parse error: duplicate \"%s\" section", "EAL"); \
323 #define PARSE_ERROR(exp, section, entry) \
324 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"", section, entry)
326 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
327 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s", \
328 section, entry, message)
330 #define PARSE_ERROR_NO_ELEMENTS(exp, section, entry) \
331 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
332 "no elements detected", \
335 #define PARSE_ERROR_TOO_MANY_ELEMENTS(exp, section, entry, max) \
336 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
337 "maximum number of elements allowed is %u", \
340 #define PARSE_ERROR_INVALID_ELEMENT(exp, section, entry, value) \
341 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
342 "Invalid element value \"%s\"", \
343 section, entry, value)
345 #define PARSE_ERROR_MALLOC(exp) \
346 APP_CHECK(exp, "Parse error: no free memory")
348 #define PARSE_ERROR_SECTION(exp, section) \
349 APP_CHECK(exp, "Parse error in section \"%s\"", section)
351 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
352 APP_CHECK(exp, "Parse error in section \"%s\": no entries", section)
354 #define PARSE_WARNING_IGNORED(exp, section, entry) \
357 fprintf(stderr, "Parse warning in section \"%s\": " \
358 "entry \"%s\" is ignored", section, entry); \
361 #define PARSE_ERROR_INVALID(exp, section, entry) \
362 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"",\
365 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
366 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"", \
370 validate_name(const char *name, const char *prefix, int num)
374 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
375 if (name[i] != prefix[i])
379 if (prefix[i] != '\0')
390 j = skip_digits(&name[i]);
392 if ((j == 0) || (name[i] != '.'))
398 j = skip_digits(&name[i]);
400 if ((j == 0) || (name[i] != '\0'))
408 parse_eal(struct app_params *app,
409 const char *section_name,
410 struct rte_cfgfile *cfg)
412 struct app_eal_params *p = &app->eal_params;
413 struct rte_cfgfile_entry *entries;
416 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
417 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
419 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
420 PARSE_ERROR_MALLOC(entries != NULL);
422 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
424 PARSE_CHECK_DUPLICATE_SECTION_EAL(p);
426 for (i = 0; i < n_entries; i++) {
427 struct rte_cfgfile_entry *entry = &entries[i];
430 if (strcmp(entry->name, "c") == 0) {
431 PARSE_WARNING_IGNORED(0, section_name, entry->name);
436 if (strcmp(entry->name, "l") == 0) {
437 PARSE_WARNING_IGNORED(0, section_name, entry->name);
442 if (strcmp(entry->name, "lcores") == 0) {
443 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
446 p->coremap = strdup(entry->value);
451 if (strcmp(entry->name, "master_lcore") == 0) {
454 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
457 p->master_lcore_present = 1;
459 status = parser_read_uint32(&p->master_lcore,
461 PARSE_ERROR((status == 0), section_name, entry->name);
466 if (strcmp(entry->name, "n") == 0) {
469 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
472 p->channels_present = 1;
474 status = parser_read_uint32(&p->channels, entry->value);
475 PARSE_ERROR((status == 0), section_name, entry->name);
480 if (strcmp(entry->name, "m") == 0) {
483 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
486 p->memory_present = 1;
488 status = parser_read_uint32(&p->memory, entry->value);
489 PARSE_ERROR((status == 0), section_name, entry->name);
494 if (strcmp(entry->name, "r") == 0) {
497 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
500 p->ranks_present = 1;
502 status = parser_read_uint32(&p->ranks, entry->value);
503 PARSE_ERROR((status == 0), section_name, entry->name);
508 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
509 (strcmp(entry->name, "b") == 0)) {
512 for (i = 0; i < APP_MAX_LINKS; i++) {
513 if (p->pci_blacklist[i])
516 p->pci_blacklist[i] =
517 strdup(entry->value);
518 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
523 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
524 section_name, entry->name,
525 "too many elements");
530 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
531 (strcmp(entry->name, "w") == 0)) {
534 PARSE_ERROR_MESSAGE((app->port_mask != 0),
535 section_name, entry->name, "entry to be "
536 "generated by the application (port_mask "
539 for (i = 0; i < APP_MAX_LINKS; i++) {
540 if (p->pci_whitelist[i])
543 p->pci_whitelist[i] = strdup(entry->value);
544 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
549 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
550 section_name, entry->name,
551 "too many elements");
556 if (strcmp(entry->name, "vdev") == 0) {
559 for (i = 0; i < APP_MAX_LINKS; i++) {
563 p->vdev[i] = strdup(entry->value);
564 PARSE_ERROR_MALLOC(p->vdev[i]);
569 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
570 section_name, entry->name,
571 "too many elements");
576 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
579 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
582 p->vmware_tsc_map_present = 1;
584 val = parser_read_arg_bool(entry->value);
585 PARSE_ERROR((val >= 0), section_name, entry->name);
586 p->vmware_tsc_map = val;
591 if (strcmp(entry->name, "proc_type") == 0) {
592 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
595 p->proc_type = strdup(entry->value);
600 if (strcmp(entry->name, "syslog") == 0) {
601 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
604 p->syslog = strdup(entry->value);
609 if (strcmp(entry->name, "log_level") == 0) {
612 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
615 p->log_level_present = 1;
617 status = parser_read_uint32(&p->log_level,
619 PARSE_ERROR((status == 0), section_name, entry->name);
624 if (strcmp(entry->name, "v") == 0) {
627 PARSE_ERROR_DUPLICATE((p->version_present == 0),
630 p->version_present = 1;
632 val = parser_read_arg_bool(entry->value);
633 PARSE_ERROR((val >= 0), section_name, entry->name);
639 if ((strcmp(entry->name, "help") == 0) ||
640 (strcmp(entry->name, "h") == 0)) {
643 PARSE_ERROR_DUPLICATE((p->help_present == 0),
648 val = parser_read_arg_bool(entry->value);
649 PARSE_ERROR((val >= 0), section_name, entry->name);
655 if (strcmp(entry->name, "no_huge") == 0) {
658 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
661 p->no_huge_present = 1;
663 val = parser_read_arg_bool(entry->value);
664 PARSE_ERROR((val >= 0), section_name, entry->name);
670 if (strcmp(entry->name, "no_pci") == 0) {
673 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
676 p->no_pci_present = 1;
678 val = parser_read_arg_bool(entry->value);
679 PARSE_ERROR((val >= 0), section_name, entry->name);
685 if (strcmp(entry->name, "no_hpet") == 0) {
688 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
691 p->no_hpet_present = 1;
693 val = parser_read_arg_bool(entry->value);
694 PARSE_ERROR((val >= 0), section_name, entry->name);
700 if (strcmp(entry->name, "no_shconf") == 0) {
703 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
706 p->no_shconf_present = 1;
708 val = parser_read_arg_bool(entry->value);
709 PARSE_ERROR((val >= 0), section_name, entry->name);
715 if (strcmp(entry->name, "d") == 0) {
716 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
719 p->add_driver = strdup(entry->value);
724 if (strcmp(entry->name, "socket_mem") == 0) {
725 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
728 p->socket_mem = strdup(entry->value);
733 if (strcmp(entry->name, "huge_dir") == 0) {
734 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
737 p->huge_dir = strdup(entry->value);
742 if (strcmp(entry->name, "file_prefix") == 0) {
743 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
746 p->file_prefix = strdup(entry->value);
751 if (strcmp(entry->name, "base_virtaddr") == 0) {
752 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
755 p->base_virtaddr = strdup(entry->value);
760 if (strcmp(entry->name, "create_uio_dev") == 0) {
763 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
766 p->create_uio_dev_present = 1;
768 val = parser_read_arg_bool(entry->value);
769 PARSE_ERROR((val >= 0), section_name, entry->name);
770 p->create_uio_dev = val;
775 if (strcmp(entry->name, "vfio_intr") == 0) {
776 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
779 p->vfio_intr = strdup(entry->value);
784 PARSE_ERROR_INVALID(0, section_name, entry->name);
791 parse_pipeline_pktq_in(struct app_params *app,
792 struct app_pipeline_params *p,
798 enum app_pktq_in_type type;
800 char *name = strtok_r(value, PARSE_DELIMITER, &value);
805 PARSE_ERROR_TOO_MANY_ELEMENTS(
806 (p->n_pktq_in < RTE_DIM(p->pktq_in)),
807 p->name, "pktq_in", (uint32_t)RTE_DIM(p->pktq_in));
809 if (validate_name(name, "RXQ", 2) == 0) {
810 type = APP_PKTQ_IN_HWQ;
811 id = APP_PARAM_ADD(app->hwq_in_params, name);
812 APP_PARAM_ADD_LINK_FOR_RXQ(app, name);
813 } else if (validate_name(name, "SWQ", 1) == 0) {
814 type = APP_PKTQ_IN_SWQ;
815 id = APP_PARAM_ADD(app->swq_params, name);
816 } else if (validate_name(name, "TM", 1) == 0) {
817 type = APP_PKTQ_IN_TM;
818 id = APP_PARAM_ADD(app->tm_params, name);
819 APP_PARAM_ADD_LINK_FOR_TM(app, name);
820 } else if (validate_name(name, "TAP", 1) == 0) {
821 type = APP_PKTQ_IN_TAP;
822 id = APP_PARAM_ADD(app->tap_params, name);
823 } else if (validate_name(name, "KNI", 1) == 0) {
824 type = APP_PKTQ_IN_KNI;
825 id = APP_PARAM_ADD(app->kni_params, name);
826 APP_PARAM_ADD_LINK_FOR_KNI(app, name);
827 } else if (validate_name(name, "SOURCE", 1) == 0) {
828 type = APP_PKTQ_IN_SOURCE;
829 id = APP_PARAM_ADD(app->source_params, name);
831 PARSE_ERROR_INVALID_ELEMENT(0,
832 p->name, "pktq_in", name);
834 p->pktq_in[p->n_pktq_in].type = type;
835 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
839 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_in > 0), p->name, "pktq_in");
843 parse_pipeline_pktq_out(struct app_params *app,
844 struct app_pipeline_params *p,
850 enum app_pktq_out_type type;
852 char *name = strtok_r(value, PARSE_DELIMITER, &value);
857 PARSE_ERROR_TOO_MANY_ELEMENTS(
858 (p->n_pktq_out < RTE_DIM(p->pktq_out)),
859 p->name, "pktq_out", (uint32_t)RTE_DIM(p->pktq_out));
861 if (validate_name(name, "TXQ", 2) == 0) {
862 type = APP_PKTQ_OUT_HWQ;
863 id = APP_PARAM_ADD(app->hwq_out_params, name);
864 APP_PARAM_ADD_LINK_FOR_TXQ(app, name);
865 } else if (validate_name(name, "SWQ", 1) == 0) {
866 type = APP_PKTQ_OUT_SWQ;
867 id = APP_PARAM_ADD(app->swq_params, name);
868 } else if (validate_name(name, "TM", 1) == 0) {
869 type = APP_PKTQ_OUT_TM;
870 id = APP_PARAM_ADD(app->tm_params, name);
871 APP_PARAM_ADD_LINK_FOR_TM(app, name);
872 } else if (validate_name(name, "TAP", 1) == 0) {
873 type = APP_PKTQ_OUT_TAP;
874 id = APP_PARAM_ADD(app->tap_params, name);
875 } else if (validate_name(name, "KNI", 1) == 0) {
876 type = APP_PKTQ_OUT_KNI;
877 id = APP_PARAM_ADD(app->kni_params, name);
878 APP_PARAM_ADD_LINK_FOR_KNI(app, name);
879 } else if (validate_name(name, "SINK", 1) == 0) {
880 type = APP_PKTQ_OUT_SINK;
881 id = APP_PARAM_ADD(app->sink_params, name);
883 PARSE_ERROR_INVALID_ELEMENT(0,
884 p->name, "pktq_out", name);
886 p->pktq_out[p->n_pktq_out].type = type;
887 p->pktq_out[p->n_pktq_out].id = id;
891 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_out > 0), p->name, "pktq_out");
895 parse_pipeline_msgq_in(struct app_params *app,
896 struct app_pipeline_params *p,
903 char *name = strtok_r(value, PARSE_DELIMITER, &value);
908 PARSE_ERROR_TOO_MANY_ELEMENTS(
909 (p->n_msgq_in < RTE_DIM(p->msgq_in)),
910 p->name, "msgq_in", (uint32_t)(RTE_DIM(p->msgq_in)));
912 PARSE_ERROR_INVALID_ELEMENT(
913 (validate_name(name, "MSGQ", 1) == 0),
914 p->name, "msgq_in", name);
916 idx = APP_PARAM_ADD(app->msgq_params, name);
917 p->msgq_in[p->n_msgq_in] = idx;
921 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_in > 0), p->name, "msgq_in");
925 parse_pipeline_msgq_out(struct app_params *app,
926 struct app_pipeline_params *p,
933 char *name = strtok_r(value, PARSE_DELIMITER, &value);
938 PARSE_ERROR_TOO_MANY_ELEMENTS(
939 (p->n_msgq_out < RTE_DIM(p->msgq_out)),
940 p->name, "msgq_out", (uint32_t)RTE_DIM(p->msgq_out));
942 PARSE_ERROR_INVALID_ELEMENT(
943 (validate_name(name, "MSGQ", 1) == 0),
944 p->name, "msgq_out", name);
946 idx = APP_PARAM_ADD(app->msgq_params, name);
947 p->msgq_out[p->n_msgq_out] = idx;
951 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_out > 0), p->name, "msgq_out");
955 parse_pipeline(struct app_params *app,
956 const char *section_name,
957 struct rte_cfgfile *cfg)
959 char name[CFG_NAME_LEN];
960 struct app_pipeline_params *param;
961 struct rte_cfgfile_entry *entries;
965 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
966 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
968 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
969 PARSE_ERROR_MALLOC(entries != NULL);
971 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
973 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
974 param = &app->pipeline_params[param_idx];
975 PARSE_CHECK_DUPLICATE_SECTION(param);
977 for (i = 0; i < n_entries; i++) {
978 struct rte_cfgfile_entry *ent = &entries[i];
980 if (strcmp(ent->name, "type") == 0) {
981 int w_size = snprintf(param->type, RTE_DIM(param->type),
984 PARSE_ERROR(((w_size > 0) &&
985 (w_size < (int)RTE_DIM(param->type))),
991 if (strcmp(ent->name, "core") == 0) {
992 int status = parse_pipeline_core(
993 ¶m->socket_id, ¶m->core_id,
994 ¶m->hyper_th_id, ent->value);
996 PARSE_ERROR((status == 0), section_name,
1001 if (strcmp(ent->name, "pktq_in") == 0) {
1002 parse_pipeline_pktq_in(app, param, ent->value);
1007 if (strcmp(ent->name, "pktq_out") == 0) {
1008 parse_pipeline_pktq_out(app, param, ent->value);
1013 if (strcmp(ent->name, "msgq_in") == 0) {
1014 parse_pipeline_msgq_in(app, param, ent->value);
1019 if (strcmp(ent->name, "msgq_out") == 0) {
1020 parse_pipeline_msgq_out(app, param, ent->value);
1025 if (strcmp(ent->name, "timer_period") == 0) {
1026 int status = parser_read_uint32(
1027 ¶m->timer_period,
1030 PARSE_ERROR((status == 0), section_name,
1035 /* pipeline type specific items */
1036 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1037 "Parse error in section \"%s\": too many "
1038 "pipeline specified parameters", section_name);
1040 param->args_name[param->n_args] = strdup(ent->name);
1041 param->args_value[param->n_args] = strdup(ent->value);
1043 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1044 (param->args_value[param->n_args] != NULL),
1045 "Parse error: no free memory");
1050 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1051 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1052 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1053 param->msgq_in[param->n_msgq_in++] = param_idx;
1055 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1056 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1057 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1058 param->msgq_out[param->n_msgq_out++] = param_idx;
1060 snprintf(name, sizeof(name), "MSGQ-REQ-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;
1067 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1070 (param->hyper_th_id) ? "h" : "");
1071 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1072 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1078 parse_mempool(struct app_params *app,
1079 const char *section_name,
1080 struct rte_cfgfile *cfg)
1082 struct app_mempool_params *param;
1083 struct rte_cfgfile_entry *entries;
1087 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1088 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1090 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1091 PARSE_ERROR_MALLOC(entries != NULL);
1093 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1095 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1096 param = &app->mempool_params[param_idx];
1097 PARSE_CHECK_DUPLICATE_SECTION(param);
1099 for (i = 0; i < n_entries; i++) {
1100 struct rte_cfgfile_entry *ent = &entries[i];
1102 if (strcmp(ent->name, "buffer_size") == 0) {
1103 int status = parser_read_uint32(
1104 ¶m->buffer_size, ent->value);
1106 PARSE_ERROR((status == 0), section_name,
1111 if (strcmp(ent->name, "pool_size") == 0) {
1112 int status = parser_read_uint32(
1113 ¶m->pool_size, ent->value);
1115 PARSE_ERROR((status == 0), section_name,
1120 if (strcmp(ent->name, "cache_size") == 0) {
1121 int status = parser_read_uint32(
1122 ¶m->cache_size, ent->value);
1124 PARSE_ERROR((status == 0), section_name,
1129 if (strcmp(ent->name, "cpu") == 0) {
1130 int status = parser_read_uint32(
1131 ¶m->cpu_socket_id, ent->value);
1133 PARSE_ERROR((status == 0), section_name,
1139 PARSE_ERROR_INVALID(0, section_name, ent->name);
1146 parse_link_rss_qs(struct app_link_params *p,
1152 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1157 if (p->n_rss_qs == RTE_DIM(p->rss_qs))
1160 if (parser_read_uint32(&p->rss_qs[p->n_rss_qs++], token))
1168 parse_link_rss_proto_ipv4(struct app_link_params *p,
1174 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1179 if (strcmp(token, "IP") == 0) {
1180 mask |= ETH_RSS_IPV4;
1183 if (strcmp(token, "FRAG") == 0) {
1184 mask |= ETH_RSS_FRAG_IPV4;
1187 if (strcmp(token, "TCP") == 0) {
1188 mask |= ETH_RSS_NONFRAG_IPV4_TCP;
1191 if (strcmp(token, "UDP") == 0) {
1192 mask |= ETH_RSS_NONFRAG_IPV4_UDP;
1195 if (strcmp(token, "SCTP") == 0) {
1196 mask |= ETH_RSS_NONFRAG_IPV4_SCTP;
1199 if (strcmp(token, "OTHER") == 0) {
1200 mask |= ETH_RSS_NONFRAG_IPV4_OTHER;
1206 p->rss_proto_ipv4 = mask;
1211 parse_link_rss_proto_ipv6(struct app_link_params *p,
1217 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1222 if (strcmp(token, "IP") == 0) {
1223 mask |= ETH_RSS_IPV6;
1226 if (strcmp(token, "FRAG") == 0) {
1227 mask |= ETH_RSS_FRAG_IPV6;
1230 if (strcmp(token, "TCP") == 0) {
1231 mask |= ETH_RSS_NONFRAG_IPV6_TCP;
1234 if (strcmp(token, "UDP") == 0) {
1235 mask |= ETH_RSS_NONFRAG_IPV6_UDP;
1238 if (strcmp(token, "SCTP") == 0) {
1239 mask |= ETH_RSS_NONFRAG_IPV6_SCTP;
1242 if (strcmp(token, "OTHER") == 0) {
1243 mask |= ETH_RSS_NONFRAG_IPV6_OTHER;
1246 if (strcmp(token, "IP_EX") == 0) {
1247 mask |= ETH_RSS_IPV6_EX;
1250 if (strcmp(token, "TCP_EX") == 0) {
1251 mask |= ETH_RSS_IPV6_TCP_EX;
1254 if (strcmp(token, "UDP_EX") == 0) {
1255 mask |= ETH_RSS_IPV6_UDP_EX;
1261 p->rss_proto_ipv6 = mask;
1266 parse_link_rss_proto_l2(struct app_link_params *p,
1272 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1277 if (strcmp(token, "L2") == 0) {
1278 mask |= ETH_RSS_L2_PAYLOAD;
1284 p->rss_proto_l2 = mask;
1289 parse_link(struct app_params *app,
1290 const char *section_name,
1291 struct rte_cfgfile *cfg)
1293 struct app_link_params *param;
1294 struct rte_cfgfile_entry *entries;
1296 int rss_qs_present = 0;
1297 int rss_proto_ipv4_present = 0;
1298 int rss_proto_ipv6_present = 0;
1299 int rss_proto_l2_present = 0;
1300 int pci_bdf_present = 0;
1303 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1304 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1306 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1307 PARSE_ERROR_MALLOC(entries != NULL);
1309 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1311 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1312 param = &app->link_params[param_idx];
1313 PARSE_CHECK_DUPLICATE_SECTION(param);
1315 for (i = 0; i < n_entries; i++) {
1316 struct rte_cfgfile_entry *ent = &entries[i];
1318 if (strcmp(ent->name, "promisc") == 0) {
1319 int status = parser_read_arg_bool(ent->value);
1321 PARSE_ERROR((status != -EINVAL), section_name,
1323 param->promisc = status;
1327 if (strcmp(ent->name, "arp_q") == 0) {
1328 int status = parser_read_uint32(¶m->arp_q,
1331 PARSE_ERROR((status == 0), section_name,
1336 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1337 int status = parser_read_uint32(
1338 ¶m->tcp_syn_q, ent->value);
1340 PARSE_ERROR((status == 0), section_name, ent->name);
1344 if (strcmp(ent->name, "ip_local_q") == 0) {
1345 int status = parser_read_uint32(
1346 ¶m->ip_local_q, ent->value);
1348 PARSE_ERROR((status == 0), section_name,
1353 if (strcmp(ent->name, "tcp_local_q") == 0) {
1354 int status = parser_read_uint32(
1355 ¶m->tcp_local_q, ent->value);
1357 PARSE_ERROR((status == 0), section_name,
1362 if (strcmp(ent->name, "udp_local_q") == 0) {
1363 int status = parser_read_uint32(
1364 ¶m->udp_local_q, ent->value);
1366 PARSE_ERROR((status == 0), section_name,
1371 if (strcmp(ent->name, "sctp_local_q") == 0) {
1372 int status = parser_read_uint32(
1373 ¶m->sctp_local_q, ent->value);
1375 PARSE_ERROR((status == 0), section_name,
1380 if (strcmp(ent->name, "rss_qs") == 0) {
1381 int status = parse_link_rss_qs(param, ent->value);
1383 PARSE_ERROR((status == 0), section_name,
1389 if (strcmp(ent->name, "rss_proto_ipv4") == 0) {
1391 parse_link_rss_proto_ipv4(param, ent->value);
1393 PARSE_ERROR((status != -EINVAL), section_name,
1395 rss_proto_ipv4_present = 1;
1399 if (strcmp(ent->name, "rss_proto_ipv6") == 0) {
1401 parse_link_rss_proto_ipv6(param, ent->value);
1403 PARSE_ERROR((status != -EINVAL), section_name,
1405 rss_proto_ipv6_present = 1;
1409 if (strcmp(ent->name, "rss_proto_l2") == 0) {
1410 int status = parse_link_rss_proto_l2(param, ent->value);
1412 PARSE_ERROR((status != -EINVAL), section_name,
1414 rss_proto_l2_present = 1;
1418 if (strcmp(ent->name, "pci_bdf") == 0) {
1419 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1420 section_name, ent->name);
1422 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1424 pci_bdf_present = 1;
1429 PARSE_ERROR_INVALID(0, section_name, ent->name);
1432 /* Check for mandatory fields */
1434 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1435 section_name, "pci_bdf",
1436 "entry not allowed (port_mask is provided)");
1438 PARSE_ERROR_MESSAGE((pci_bdf_present),
1439 section_name, "pci_bdf",
1440 "this entry is mandatory (port_mask is not "
1443 if (rss_proto_ipv4_present)
1444 PARSE_ERROR_MESSAGE((rss_qs_present),
1445 section_name, "rss_proto_ipv4",
1446 "entry not allowed (rss_qs entry is not provided)");
1447 if (rss_proto_ipv6_present)
1448 PARSE_ERROR_MESSAGE((rss_qs_present),
1449 section_name, "rss_proto_ipv6",
1450 "entry not allowed (rss_qs entry is not provided)");
1451 if (rss_proto_l2_present)
1452 PARSE_ERROR_MESSAGE((rss_qs_present),
1453 section_name, "rss_proto_l2",
1454 "entry not allowed (rss_qs entry is not provided)");
1455 if (rss_proto_ipv4_present |
1456 rss_proto_ipv6_present |
1457 rss_proto_l2_present){
1458 if (rss_proto_ipv4_present == 0)
1459 param->rss_proto_ipv4 = 0;
1460 if (rss_proto_ipv6_present == 0)
1461 param->rss_proto_ipv6 = 0;
1462 if (rss_proto_l2_present == 0)
1463 param->rss_proto_l2 = 0;
1470 parse_rxq(struct app_params *app,
1471 const char *section_name,
1472 struct rte_cfgfile *cfg)
1474 struct app_pktq_hwq_in_params *param;
1475 struct rte_cfgfile_entry *entries;
1479 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1480 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1482 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1483 PARSE_ERROR_MALLOC(entries != NULL);
1485 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1487 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1488 param = &app->hwq_in_params[param_idx];
1489 PARSE_CHECK_DUPLICATE_SECTION(param);
1491 APP_PARAM_ADD_LINK_FOR_RXQ(app, section_name);
1493 for (i = 0; i < n_entries; i++) {
1494 struct rte_cfgfile_entry *ent = &entries[i];
1496 if (strcmp(ent->name, "mempool") == 0) {
1497 int status = validate_name(ent->value,
1501 PARSE_ERROR((status == 0), section_name,
1504 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1505 param->mempool_id = idx;
1509 if (strcmp(ent->name, "size") == 0) {
1510 int status = parser_read_uint32(¶m->size,
1513 PARSE_ERROR((status == 0), section_name,
1518 if (strcmp(ent->name, "burst") == 0) {
1519 int status = parser_read_uint32(¶m->burst,
1522 PARSE_ERROR((status == 0), section_name,
1528 PARSE_ERROR_INVALID(0, section_name, ent->name);
1535 parse_txq(struct app_params *app,
1536 const char *section_name,
1537 struct rte_cfgfile *cfg)
1539 struct app_pktq_hwq_out_params *param;
1540 struct rte_cfgfile_entry *entries;
1544 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1545 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1547 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1548 PARSE_ERROR_MALLOC(entries != NULL);
1550 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1552 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1553 param = &app->hwq_out_params[param_idx];
1554 PARSE_CHECK_DUPLICATE_SECTION(param);
1556 APP_PARAM_ADD_LINK_FOR_TXQ(app, section_name);
1558 for (i = 0; i < n_entries; i++) {
1559 struct rte_cfgfile_entry *ent = &entries[i];
1561 if (strcmp(ent->name, "size") == 0) {
1562 int status = parser_read_uint32(¶m->size,
1565 PARSE_ERROR((status == 0), section_name,
1570 if (strcmp(ent->name, "burst") == 0) {
1571 int status = parser_read_uint32(¶m->burst,
1574 PARSE_ERROR((status == 0), section_name,
1579 if (strcmp(ent->name, "dropless") == 0) {
1580 int status = parser_read_arg_bool(ent->value);
1583 PARSE_ERROR((status != -EINVAL), section_name,
1585 param->dropless = status;
1589 if (strcmp(ent->name, "n_retries") == 0) {
1590 int status = parser_read_uint64(¶m->n_retries,
1593 PARSE_ERROR((status == 0), section_name,
1599 PARSE_ERROR_INVALID(0, section_name, ent->name);
1606 parse_swq(struct app_params *app,
1607 const char *section_name,
1608 struct rte_cfgfile *cfg)
1610 struct app_pktq_swq_params *param;
1611 struct rte_cfgfile_entry *entries;
1613 uint32_t mtu_present = 0;
1614 uint32_t metadata_size_present = 0;
1615 uint32_t mempool_direct_present = 0;
1616 uint32_t mempool_indirect_present = 0;
1620 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1621 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1623 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1624 PARSE_ERROR_MALLOC(entries != NULL);
1626 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1628 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1629 param = &app->swq_params[param_idx];
1630 PARSE_CHECK_DUPLICATE_SECTION(param);
1632 for (i = 0; i < n_entries; i++) {
1633 struct rte_cfgfile_entry *ent = &entries[i];
1635 if (strcmp(ent->name, "size") == 0) {
1636 int status = parser_read_uint32(¶m->size,
1639 PARSE_ERROR((status == 0), section_name,
1644 if (strcmp(ent->name, "burst_read") == 0) {
1645 int status = parser_read_uint32(&
1646 param->burst_read, ent->value);
1648 PARSE_ERROR((status == 0), section_name,
1653 if (strcmp(ent->name, "burst_write") == 0) {
1654 int status = parser_read_uint32(
1655 ¶m->burst_write, ent->value);
1657 PARSE_ERROR((status == 0), section_name,
1662 if (strcmp(ent->name, "dropless") == 0) {
1663 int status = parser_read_arg_bool(ent->value);
1665 PARSE_ERROR((status != -EINVAL), section_name,
1667 param->dropless = status;
1671 if (strcmp(ent->name, "n_retries") == 0) {
1672 int status = parser_read_uint64(¶m->n_retries,
1675 PARSE_ERROR((status == 0), section_name,
1680 if (strcmp(ent->name, "cpu") == 0) {
1681 int status = parser_read_uint32(
1682 ¶m->cpu_socket_id, ent->value);
1684 PARSE_ERROR((status == 0), section_name, ent->name);
1688 if (strcmp(ent->name, "ipv4_frag") == 0) {
1689 int status = parser_read_arg_bool(ent->value);
1691 PARSE_ERROR((status != -EINVAL), section_name,
1694 param->ipv4_frag = status;
1695 if (param->mtu == 0)
1701 if (strcmp(ent->name, "ipv6_frag") == 0) {
1702 int status = parser_read_arg_bool(ent->value);
1704 PARSE_ERROR((status != -EINVAL), section_name,
1706 param->ipv6_frag = status;
1707 if (param->mtu == 0)
1712 if (strcmp(ent->name, "ipv4_ras") == 0) {
1713 int status = parser_read_arg_bool(ent->value);
1715 PARSE_ERROR((status != -EINVAL), section_name,
1717 param->ipv4_ras = status;
1721 if (strcmp(ent->name, "ipv6_ras") == 0) {
1722 int status = parser_read_arg_bool(ent->value);
1724 PARSE_ERROR((status != -EINVAL), section_name,
1726 param->ipv6_ras = status;
1730 if (strcmp(ent->name, "mtu") == 0) {
1731 int status = parser_read_uint32(¶m->mtu,
1734 PARSE_ERROR((status == 0), section_name,
1740 if (strcmp(ent->name, "metadata_size") == 0) {
1741 int status = parser_read_uint32(
1742 ¶m->metadata_size, ent->value);
1744 PARSE_ERROR((status == 0), section_name,
1746 metadata_size_present = 1;
1750 if (strcmp(ent->name, "mempool_direct") == 0) {
1751 int status = validate_name(ent->value,
1755 PARSE_ERROR((status == 0), section_name,
1758 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1759 param->mempool_direct_id = idx;
1761 mempool_direct_present = 1;
1765 if (strcmp(ent->name, "mempool_indirect") == 0) {
1766 int status = validate_name(ent->value,
1770 PARSE_ERROR((status == 0), section_name,
1773 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1774 param->mempool_indirect_id = idx;
1776 mempool_indirect_present = 1;
1781 PARSE_ERROR_INVALID(0, section_name, ent->name);
1784 APP_CHECK(((mtu_present == 0) ||
1785 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1786 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1787 "is off, therefore entry \"mtu\" is not allowed",
1790 APP_CHECK(((metadata_size_present == 0) ||
1791 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1792 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1793 "is off, therefore entry \"metadata_size\" is "
1794 "not allowed", section_name);
1796 APP_CHECK(((mempool_direct_present == 0) ||
1797 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1798 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1799 "is off, therefore entry \"mempool_direct\" is "
1800 "not allowed", section_name);
1802 APP_CHECK(((mempool_indirect_present == 0) ||
1803 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1804 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1805 "is off, therefore entry \"mempool_indirect\" is "
1806 "not allowed", section_name);
1812 parse_tm(struct app_params *app,
1813 const char *section_name,
1814 struct rte_cfgfile *cfg)
1816 struct app_pktq_tm_params *param;
1817 struct rte_cfgfile_entry *entries;
1821 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1822 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1824 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1825 PARSE_ERROR_MALLOC(entries != NULL);
1827 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1829 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1830 param = &app->tm_params[param_idx];
1831 PARSE_CHECK_DUPLICATE_SECTION(param);
1833 APP_PARAM_ADD_LINK_FOR_TM(app, section_name);
1835 for (i = 0; i < n_entries; i++) {
1836 struct rte_cfgfile_entry *ent = &entries[i];
1838 if (strcmp(ent->name, "cfg") == 0) {
1839 param->file_name = strdup(ent->value);
1840 PARSE_ERROR_MALLOC(param->file_name != NULL);
1844 if (strcmp(ent->name, "burst_read") == 0) {
1845 int status = parser_read_uint32(
1846 ¶m->burst_read, ent->value);
1848 PARSE_ERROR((status == 0), section_name,
1853 if (strcmp(ent->name, "burst_write") == 0) {
1854 int status = parser_read_uint32(
1855 ¶m->burst_write, ent->value);
1857 PARSE_ERROR((status == 0), section_name,
1863 PARSE_ERROR_INVALID(0, section_name, ent->name);
1870 parse_tap(struct app_params *app,
1871 const char *section_name,
1872 struct rte_cfgfile *cfg)
1874 struct app_pktq_tap_params *param;
1875 struct rte_cfgfile_entry *entries;
1879 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1880 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1882 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1883 PARSE_ERROR_MALLOC(entries != NULL);
1885 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1887 param_idx = APP_PARAM_ADD(app->tap_params, section_name);
1888 param = &app->tap_params[param_idx];
1889 PARSE_CHECK_DUPLICATE_SECTION(param);
1891 for (i = 0; i < n_entries; i++) {
1892 struct rte_cfgfile_entry *ent = &entries[i];
1894 if (strcmp(ent->name, "burst_read") == 0) {
1895 int status = parser_read_uint32(
1896 ¶m->burst_read, ent->value);
1898 PARSE_ERROR((status == 0), section_name,
1903 if (strcmp(ent->name, "burst_write") == 0) {
1904 int status = parser_read_uint32(
1905 ¶m->burst_write, ent->value);
1907 PARSE_ERROR((status == 0), section_name,
1912 if (strcmp(ent->name, "dropless") == 0) {
1913 int status = parser_read_arg_bool(ent->value);
1915 PARSE_ERROR((status != -EINVAL), section_name,
1917 param->dropless = status;
1921 if (strcmp(ent->name, "n_retries") == 0) {
1922 int status = parser_read_uint64(¶m->n_retries,
1925 PARSE_ERROR((status == 0), section_name,
1930 if (strcmp(ent->name, "mempool") == 0) {
1931 int status = validate_name(ent->value,
1935 PARSE_ERROR((status == 0), section_name,
1938 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1939 param->mempool_id = idx;
1945 PARSE_ERROR_INVALID(0, section_name, ent->name);
1952 parse_kni(struct app_params *app,
1953 const char *section_name,
1954 struct rte_cfgfile *cfg)
1956 struct app_pktq_kni_params *param;
1957 struct rte_cfgfile_entry *entries;
1961 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1962 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1964 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1965 PARSE_ERROR_MALLOC(entries != NULL);
1967 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1969 param_idx = APP_PARAM_ADD(app->kni_params, section_name);
1970 param = &app->kni_params[param_idx];
1971 PARSE_CHECK_DUPLICATE_SECTION(param);
1973 APP_PARAM_ADD_LINK_FOR_KNI(app, section_name);
1975 for (i = 0; i < n_entries; i++) {
1976 struct rte_cfgfile_entry *ent = &entries[i];
1978 if (strcmp(ent->name, "core") == 0) {
1979 int status = parse_pipeline_core(
1982 ¶m->hyper_th_id,
1985 PARSE_ERROR((status == 0), section_name,
1987 param->force_bind = 1;
1991 if (strcmp(ent->name, "mempool") == 0) {
1992 int status = validate_name(ent->value,
1996 PARSE_ERROR((status == 0), section_name,
1999 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
2000 param->mempool_id = idx;
2004 if (strcmp(ent->name, "burst_read") == 0) {
2005 int status = parser_read_uint32(¶m->burst_read,
2008 PARSE_ERROR((status == 0), section_name,
2013 if (strcmp(ent->name, "burst_write") == 0) {
2014 int status = parser_read_uint32(¶m->burst_write,
2017 PARSE_ERROR((status == 0), section_name,
2022 if (strcmp(ent->name, "dropless") == 0) {
2023 int status = parser_read_arg_bool(ent->value);
2025 PARSE_ERROR((status != -EINVAL), section_name,
2027 param->dropless = status;
2031 if (strcmp(ent->name, "n_retries") == 0) {
2032 int status = parser_read_uint64(¶m->n_retries,
2035 PARSE_ERROR((status == 0), section_name,
2041 PARSE_ERROR_INVALID(0, section_name, ent->name);
2048 parse_source(struct app_params *app,
2049 const char *section_name,
2050 struct rte_cfgfile *cfg)
2052 struct app_pktq_source_params *param;
2053 struct rte_cfgfile_entry *entries;
2056 uint32_t pcap_file_present = 0;
2057 uint32_t pcap_size_present = 0;
2059 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2060 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2062 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2063 PARSE_ERROR_MALLOC(entries != NULL);
2065 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2067 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2068 param = &app->source_params[param_idx];
2069 PARSE_CHECK_DUPLICATE_SECTION(param);
2071 for (i = 0; i < n_entries; i++) {
2072 struct rte_cfgfile_entry *ent = &entries[i];
2074 if (strcmp(ent->name, "mempool") == 0) {
2075 int status = validate_name(ent->value,
2079 PARSE_ERROR((status == 0), section_name,
2082 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
2083 param->mempool_id = idx;
2087 if (strcmp(ent->name, "burst") == 0) {
2088 int status = parser_read_uint32(¶m->burst,
2091 PARSE_ERROR((status == 0), section_name,
2096 if (strcmp(ent->name, "pcap_file_rd") == 0) {
2097 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2098 section_name, ent->name);
2100 param->file_name = strdup(ent->value);
2102 PARSE_ERROR_MALLOC(param->file_name != NULL);
2103 pcap_file_present = 1;
2108 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2111 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2112 section_name, ent->name);
2114 status = parser_read_uint32(
2115 ¶m->n_bytes_per_pkt, ent->value);
2117 PARSE_ERROR((status == 0), section_name,
2119 pcap_size_present = 1;
2125 PARSE_ERROR_INVALID(0, section_name, ent->name);
2132 parse_sink(struct app_params *app,
2133 const char *section_name,
2134 struct rte_cfgfile *cfg)
2136 struct app_pktq_sink_params *param;
2137 struct rte_cfgfile_entry *entries;
2140 uint32_t pcap_file_present = 0;
2141 uint32_t pcap_n_pkt_present = 0;
2143 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2144 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2146 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2147 PARSE_ERROR_MALLOC(entries != NULL);
2149 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2151 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2152 param = &app->sink_params[param_idx];
2153 PARSE_CHECK_DUPLICATE_SECTION(param);
2155 for (i = 0; i < n_entries; i++) {
2156 struct rte_cfgfile_entry *ent = &entries[i];
2158 if (strcmp(ent->name, "pcap_file_wr") == 0) {
2159 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2160 section_name, ent->name);
2162 param->file_name = strdup(ent->value);
2164 PARSE_ERROR_MALLOC((param->file_name != NULL));
2169 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
2172 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2173 section_name, ent->name);
2175 status = parser_read_uint32(
2176 ¶m->n_pkts_to_dump, ent->value);
2178 PARSE_ERROR((status == 0), section_name,
2185 PARSE_ERROR_INVALID(0, section_name, ent->name);
2192 parse_msgq_req_pipeline(struct app_params *app,
2193 const char *section_name,
2194 struct rte_cfgfile *cfg)
2196 struct app_msgq_params *param;
2197 struct rte_cfgfile_entry *entries;
2201 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2202 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2204 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2205 PARSE_ERROR_MALLOC(entries != NULL);
2207 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2209 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2210 param = &app->msgq_params[param_idx];
2211 PARSE_CHECK_DUPLICATE_SECTION(param);
2213 for (i = 0; i < n_entries; i++) {
2214 struct rte_cfgfile_entry *ent = &entries[i];
2216 if (strcmp(ent->name, "size") == 0) {
2217 int status = parser_read_uint32(¶m->size,
2220 PARSE_ERROR((status == 0), section_name,
2226 PARSE_ERROR_INVALID(0, section_name, ent->name);
2233 parse_msgq_rsp_pipeline(struct app_params *app,
2234 const char *section_name,
2235 struct rte_cfgfile *cfg)
2237 struct app_msgq_params *param;
2238 struct rte_cfgfile_entry *entries;
2242 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2243 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2245 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2246 PARSE_ERROR_MALLOC(entries != NULL);
2248 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2250 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2251 param = &app->msgq_params[param_idx];
2252 PARSE_CHECK_DUPLICATE_SECTION(param);
2254 for (i = 0; i < n_entries; i++) {
2255 struct rte_cfgfile_entry *ent = &entries[i];
2257 if (strcmp(ent->name, "size") == 0) {
2258 int status = parser_read_uint32(¶m->size,
2261 PARSE_ERROR((status == 0), section_name,
2267 PARSE_ERROR_INVALID(0, section_name, ent->name);
2274 parse_msgq(struct app_params *app,
2275 const char *section_name,
2276 struct rte_cfgfile *cfg)
2278 struct app_msgq_params *param;
2279 struct rte_cfgfile_entry *entries;
2283 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2284 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2286 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2287 PARSE_ERROR_MALLOC(entries != NULL);
2289 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2291 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2292 param = &app->msgq_params[param_idx];
2293 PARSE_CHECK_DUPLICATE_SECTION(param);
2295 for (i = 0; i < n_entries; i++) {
2296 struct rte_cfgfile_entry *ent = &entries[i];
2298 if (strcmp(ent->name, "size") == 0) {
2299 int status = parser_read_uint32(¶m->size,
2302 PARSE_ERROR((status == 0), section_name,
2307 if (strcmp(ent->name, "cpu") == 0) {
2308 int status = parser_read_uint32(
2309 ¶m->cpu_socket_id, ent->value);
2311 PARSE_ERROR((status == 0), section_name,
2317 PARSE_ERROR_INVALID(0, section_name, ent->name);
2323 typedef void (*config_section_load)(struct app_params *p,
2324 const char *section_name,
2325 struct rte_cfgfile *cfg);
2327 struct config_section {
2328 const char prefix[CFG_NAME_LEN];
2330 config_section_load load;
2333 static const struct config_section cfg_file_scheme[] = {
2334 {"EAL", 0, parse_eal},
2335 {"PIPELINE", 1, parse_pipeline},
2336 {"MEMPOOL", 1, parse_mempool},
2337 {"LINK", 1, parse_link},
2338 {"RXQ", 2, parse_rxq},
2339 {"TXQ", 2, parse_txq},
2340 {"SWQ", 1, parse_swq},
2341 {"TM", 1, parse_tm},
2342 {"TAP", 1, parse_tap},
2343 {"KNI", 1, parse_kni},
2344 {"SOURCE", 1, parse_source},
2345 {"SINK", 1, parse_sink},
2346 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2347 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2348 {"MSGQ", 1, parse_msgq},
2352 create_implicit_mempools(struct app_params *app)
2354 APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2358 create_implicit_links_from_port_mask(struct app_params *app,
2361 uint32_t pmd_id, link_id;
2364 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2365 char name[APP_PARAM_NAME_SIZE];
2368 if ((port_mask & (1LLU << pmd_id)) == 0)
2371 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2372 idx = APP_PARAM_ADD(app->link_params, name);
2374 app->link_params[idx].pmd_id = pmd_id;
2380 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2384 for (i = 0; i < app->n_links; i++) {
2385 struct app_link_params *link = &app->link_params[i];
2387 APP_CHECK((strlen(link->pci_bdf)),
2388 "Parse error: %s pci_bdf is not configured "
2389 "(port_mask is not provided)",
2397 app_config_parse(struct app_params *app, const char *file_name)
2399 struct rte_cfgfile *cfg;
2400 char **section_names;
2401 int i, j, sect_count;
2403 /* Implicit mempools */
2404 create_implicit_mempools(app);
2408 create_implicit_links_from_port_mask(app, app->port_mask);
2410 /* Load application configuration file */
2411 cfg = rte_cfgfile_load(file_name, 0);
2412 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2413 "file %s", file_name);
2415 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2416 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2417 "in file \"%s\" return %d", file_name,
2420 section_names = malloc(sect_count * sizeof(char *));
2421 PARSE_ERROR_MALLOC(section_names != NULL);
2423 for (i = 0; i < sect_count; i++)
2424 section_names[i] = malloc(CFG_NAME_LEN);
2426 rte_cfgfile_sections(cfg, section_names, sect_count);
2428 for (i = 0; i < sect_count; i++) {
2429 const struct config_section *sch_s;
2430 int len, cfg_name_len;
2432 cfg_name_len = strlen(section_names[i]);
2434 /* Find section type */
2435 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2436 sch_s = &cfg_file_scheme[j];
2437 len = strlen(sch_s->prefix);
2439 if (cfg_name_len < len)
2442 /* After section name we expect only '\0' or digit or
2443 * digit dot digit, so protect against false matching,
2444 * for example: "ABC" should match section name
2445 * "ABC0.0", but it should not match section_name
2448 if ((section_names[i][len] != '\0') &&
2449 !isdigit(section_names[i][len]))
2452 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2456 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2457 "Parse error: unknown section %s",
2460 APP_CHECK(validate_name(section_names[i],
2462 sch_s->numbers) == 0,
2463 "Parse error: invalid section name \"%s\"",
2466 sch_s->load(app, section_names[i], cfg);
2469 for (i = 0; i < sect_count; i++)
2470 free(section_names[i]);
2472 free(section_names);
2474 rte_cfgfile_close(cfg);
2476 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2477 APP_PARAM_COUNT(app->link_params, app->n_links);
2478 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2479 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2480 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2481 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2482 APP_PARAM_COUNT(app->tap_params, app->n_pktq_tap);
2483 APP_PARAM_COUNT(app->kni_params, app->n_pktq_kni);
2484 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2485 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2486 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2487 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2489 if (app->port_mask == 0)
2490 assign_link_pmd_id_from_pci_bdf(app);
2492 /* Save configuration to output file */
2493 app_config_save(app, app->output_file);
2495 /* Load TM configuration files */
2496 app_config_parse_tm(app);
2502 save_eal_params(struct app_params *app, FILE *f)
2504 struct app_eal_params *p = &app->eal_params;
2507 fprintf(f, "[EAL]\n");
2510 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2512 if (p->master_lcore_present)
2513 fprintf(f, "%s = %" PRIu32 "\n",
2514 "master_lcore", p->master_lcore);
2516 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2518 if (p->memory_present)
2519 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2521 if (p->ranks_present)
2522 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2524 for (i = 0; i < APP_MAX_LINKS; i++) {
2525 if (p->pci_blacklist[i] == NULL)
2528 fprintf(f, "%s = %s\n", "pci_blacklist",
2529 p->pci_blacklist[i]);
2532 for (i = 0; i < APP_MAX_LINKS; i++) {
2533 if (p->pci_whitelist[i] == NULL)
2536 fprintf(f, "%s = %s\n", "pci_whitelist",
2537 p->pci_whitelist[i]);
2540 for (i = 0; i < APP_MAX_LINKS; i++) {
2541 if (p->vdev[i] == NULL)
2544 fprintf(f, "%s = %s\n", "vdev",
2548 if (p->vmware_tsc_map_present)
2549 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2550 (p->vmware_tsc_map) ? "yes" : "no");
2553 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2556 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2558 if (p->log_level_present)
2559 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2561 if (p->version_present)
2562 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2564 if (p->help_present)
2565 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2567 if (p->no_huge_present)
2568 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2570 if (p->no_pci_present)
2571 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2573 if (p->no_hpet_present)
2574 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2576 if (p->no_shconf_present)
2577 fprintf(f, "%s = %s\n", "no_shconf",
2578 (p->no_shconf) ? "yes" : "no");
2581 fprintf(f, "%s = %s\n", "d", p->add_driver);
2584 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2587 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2590 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2592 if (p->base_virtaddr)
2593 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2595 if (p->create_uio_dev_present)
2596 fprintf(f, "%s = %s\n", "create_uio_dev",
2597 (p->create_uio_dev) ? "yes" : "no");
2600 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2606 save_mempool_params(struct app_params *app, FILE *f)
2608 struct app_mempool_params *p;
2611 count = RTE_DIM(app->mempool_params);
2612 for (i = 0; i < count; i++) {
2613 p = &app->mempool_params[i];
2614 if (!APP_PARAM_VALID(p))
2617 fprintf(f, "[%s]\n", p->name);
2618 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2619 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2620 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2621 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2628 save_links_params(struct app_params *app, FILE *f)
2630 struct app_link_params *p;
2633 count = RTE_DIM(app->link_params);
2634 for (i = 0; i < count; i++) {
2635 p = &app->link_params[i];
2636 if (!APP_PARAM_VALID(p))
2639 fprintf(f, "[%s]\n", p->name);
2640 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2641 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2642 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2643 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2645 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2646 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2647 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2648 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2655 fprintf(f, "rss_qs = ");
2656 for (j = 0; j < p->n_rss_qs; j++)
2657 fprintf(f, "%" PRIu32 " ", p->rss_qs[j]);
2660 /* rss_proto_ipv4 */
2661 if (p->rss_proto_ipv4) {
2662 fprintf(f, "rss_proto_ipv4 = ");
2663 if (p->rss_proto_ipv4 & ETH_RSS_IPV4)
2665 if (p->rss_proto_ipv4 & ETH_RSS_FRAG_IPV4)
2666 fprintf(f, "FRAG ");
2667 if (p->rss_proto_ipv4 &
2668 ETH_RSS_NONFRAG_IPV4_TCP)
2670 if (p->rss_proto_ipv4 &
2671 ETH_RSS_NONFRAG_IPV4_UDP)
2673 if (p->rss_proto_ipv4 &
2674 ETH_RSS_NONFRAG_IPV4_SCTP)
2675 fprintf(f, "SCTP ");
2676 if (p->rss_proto_ipv4 &
2677 ETH_RSS_NONFRAG_IPV4_OTHER)
2678 fprintf(f, "OTHER ");
2681 fprintf(f, "; rss_proto_ipv4 = <NONE>\n");
2683 /* rss_proto_ipv6 */
2684 if (p->rss_proto_ipv6) {
2685 fprintf(f, "rss_proto_ipv6 = ");
2686 if (p->rss_proto_ipv6 & ETH_RSS_IPV6)
2688 if (p->rss_proto_ipv6 & ETH_RSS_FRAG_IPV6)
2689 fprintf(f, "FRAG ");
2690 if (p->rss_proto_ipv6 &
2691 ETH_RSS_NONFRAG_IPV6_TCP)
2693 if (p->rss_proto_ipv6 &
2694 ETH_RSS_NONFRAG_IPV6_UDP)
2696 if (p->rss_proto_ipv6 &
2697 ETH_RSS_NONFRAG_IPV6_SCTP)
2698 fprintf(f, "SCTP ");
2699 if (p->rss_proto_ipv6 &
2700 ETH_RSS_NONFRAG_IPV6_OTHER)
2701 fprintf(f, "OTHER ");
2702 if (p->rss_proto_ipv6 & ETH_RSS_IPV6_EX)
2703 fprintf(f, "IP_EX ");
2704 if (p->rss_proto_ipv6 &
2705 ETH_RSS_IPV6_TCP_EX)
2706 fprintf(f, "TCP_EX ");
2707 if (p->rss_proto_ipv6 &
2708 ETH_RSS_IPV6_UDP_EX)
2709 fprintf(f, "UDP_EX ");
2712 fprintf(f, "; rss_proto_ipv6 = <NONE>\n");
2715 if (p->rss_proto_l2) {
2716 fprintf(f, "rss_proto_l2 = ");
2717 if (p->rss_proto_l2 & ETH_RSS_L2_PAYLOAD)
2721 fprintf(f, "; rss_proto_l2 = <NONE>\n");
2723 fprintf(f, "; rss_qs = <NONE>\n");
2724 fprintf(f, "; rss_proto_ipv4 = <NONE>\n");
2725 fprintf(f, "; rss_proto_ipv6 = <NONE>\n");
2726 fprintf(f, "; rss_proto_l2 = <NONE>\n");
2729 if (strlen(p->pci_bdf))
2730 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2737 save_rxq_params(struct app_params *app, FILE *f)
2739 struct app_pktq_hwq_in_params *p;
2742 count = RTE_DIM(app->hwq_in_params);
2743 for (i = 0; i < count; i++) {
2744 p = &app->hwq_in_params[i];
2745 if (!APP_PARAM_VALID(p))
2748 fprintf(f, "[%s]\n", p->name);
2749 fprintf(f, "%s = %s\n",
2751 app->mempool_params[p->mempool_id].name);
2752 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2753 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2760 save_txq_params(struct app_params *app, FILE *f)
2762 struct app_pktq_hwq_out_params *p;
2765 count = RTE_DIM(app->hwq_out_params);
2766 for (i = 0; i < count; i++) {
2767 p = &app->hwq_out_params[i];
2768 if (!APP_PARAM_VALID(p))
2771 fprintf(f, "[%s]\n", p->name);
2772 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2773 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2774 fprintf(f, "%s = %s\n",
2776 p->dropless ? "yes" : "no");
2777 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2784 save_swq_params(struct app_params *app, FILE *f)
2786 struct app_pktq_swq_params *p;
2789 count = RTE_DIM(app->swq_params);
2790 for (i = 0; i < count; i++) {
2791 p = &app->swq_params[i];
2792 if (!APP_PARAM_VALID(p))
2795 fprintf(f, "[%s]\n", p->name);
2796 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2797 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2798 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2799 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2800 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2801 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2802 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2803 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2804 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2805 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2806 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2807 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2808 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2809 fprintf(f, "%s = %s\n",
2811 app->mempool_params[p->mempool_direct_id].name);
2812 fprintf(f, "%s = %s\n",
2814 app->mempool_params[p->mempool_indirect_id].name);
2822 save_tm_params(struct app_params *app, FILE *f)
2824 struct app_pktq_tm_params *p;
2827 count = RTE_DIM(app->tm_params);
2828 for (i = 0; i < count; i++) {
2829 p = &app->tm_params[i];
2830 if (!APP_PARAM_VALID(p))
2833 fprintf(f, "[%s]\n", p->name);
2834 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2835 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2836 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2843 save_tap_params(struct app_params *app, FILE *f)
2845 struct app_pktq_tap_params *p;
2848 count = RTE_DIM(app->tap_params);
2849 for (i = 0; i < count; i++) {
2850 p = &app->tap_params[i];
2851 if (!APP_PARAM_VALID(p))
2854 fprintf(f, "[%s]\n", p->name);
2855 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2856 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2857 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2858 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2859 fprintf(f, "%s = %s\n", "mempool",
2860 app->mempool_params[p->mempool_id].name);
2867 save_kni_params(struct app_params *app, FILE *f)
2869 struct app_pktq_kni_params *p;
2872 count = RTE_DIM(app->kni_params);
2873 for (i = 0; i < count; i++) {
2874 p = &app->kni_params[i];
2875 if (!APP_PARAM_VALID(p))
2879 fprintf(f, "[%s]\n", p->name);
2882 if (p->force_bind) {
2883 fprintf(f, "; force_bind = 1\n");
2884 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2887 (p->hyper_th_id) ? "h" : "");
2889 fprintf(f, "; force_bind = 0\n");
2892 fprintf(f, "%s = %s\n", "mempool",
2893 app->mempool_params[p->mempool_id].name);
2896 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2899 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2902 fprintf(f, "%s = %s\n",
2904 p->dropless ? "yes" : "no");
2907 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2914 save_source_params(struct app_params *app, FILE *f)
2916 struct app_pktq_source_params *p;
2919 count = RTE_DIM(app->source_params);
2920 for (i = 0; i < count; i++) {
2921 p = &app->source_params[i];
2922 if (!APP_PARAM_VALID(p))
2925 fprintf(f, "[%s]\n", p->name);
2926 fprintf(f, "%s = %s\n",
2928 app->mempool_params[p->mempool_id].name);
2929 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2930 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2931 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2932 p->n_bytes_per_pkt);
2938 save_sink_params(struct app_params *app, FILE *f)
2940 struct app_pktq_sink_params *p;
2943 count = RTE_DIM(app->sink_params);
2944 for (i = 0; i < count; i++) {
2945 p = &app->sink_params[i];
2946 if (!APP_PARAM_VALID(p))
2949 fprintf(f, "[%s]\n", p->name);
2950 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2951 fprintf(f, "%s = %" PRIu32 "\n",
2952 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2958 save_msgq_params(struct app_params *app, FILE *f)
2960 struct app_msgq_params *p;
2963 count = RTE_DIM(app->msgq_params);
2964 for (i = 0; i < count; i++) {
2965 p = &app->msgq_params[i];
2966 if (!APP_PARAM_VALID(p))
2969 fprintf(f, "[%s]\n", p->name);
2970 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2971 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2978 save_pipeline_params(struct app_params *app, FILE *f)
2982 count = RTE_DIM(app->pipeline_params);
2983 for (i = 0; i < count; i++) {
2984 struct app_pipeline_params *p = &app->pipeline_params[i];
2986 if (!APP_PARAM_VALID(p))
2990 fprintf(f, "[%s]\n", p->name);
2993 fprintf(f, "type = %s\n", p->type);
2996 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2999 (p->hyper_th_id) ? "h" : "");
3005 fprintf(f, "pktq_in =");
3006 for (j = 0; j < p->n_pktq_in; j++) {
3007 struct app_pktq_in_params *pp = &p->pktq_in[j];
3011 case APP_PKTQ_IN_HWQ:
3012 name = app->hwq_in_params[pp->id].name;
3014 case APP_PKTQ_IN_SWQ:
3015 name = app->swq_params[pp->id].name;
3017 case APP_PKTQ_IN_TM:
3018 name = app->tm_params[pp->id].name;
3020 case APP_PKTQ_IN_TAP:
3021 name = app->tap_params[pp->id].name;
3023 case APP_PKTQ_IN_KNI:
3024 name = app->kni_params[pp->id].name;
3026 case APP_PKTQ_IN_SOURCE:
3027 name = app->source_params[pp->id].name;
3030 APP_CHECK(0, "System error "
3031 "occurred while saving "
3032 "parameter to file");
3035 fprintf(f, " %s", name);
3041 if (p->n_pktq_out) {
3044 fprintf(f, "pktq_out =");
3045 for (j = 0; j < p->n_pktq_out; j++) {
3046 struct app_pktq_out_params *pp =
3051 case APP_PKTQ_OUT_HWQ:
3052 name = app->hwq_out_params[pp->id].name;
3054 case APP_PKTQ_OUT_SWQ:
3055 name = app->swq_params[pp->id].name;
3057 case APP_PKTQ_OUT_TM:
3058 name = app->tm_params[pp->id].name;
3060 case APP_PKTQ_OUT_TAP:
3061 name = app->tap_params[pp->id].name;
3063 case APP_PKTQ_OUT_KNI:
3064 name = app->kni_params[pp->id].name;
3066 case APP_PKTQ_OUT_SINK:
3067 name = app->sink_params[pp->id].name;
3070 APP_CHECK(0, "System error "
3071 "occurred while saving "
3072 "parameter to file");
3075 fprintf(f, " %s", name);
3084 fprintf(f, "msgq_in =");
3085 for (j = 0; j < p->n_msgq_in; j++) {
3086 uint32_t id = p->msgq_in[j];
3087 char *name = app->msgq_params[id].name;
3089 fprintf(f, " %s", name);
3095 if (p->n_msgq_out) {
3098 fprintf(f, "msgq_out =");
3099 for (j = 0; j < p->n_msgq_out; j++) {
3100 uint32_t id = p->msgq_out[j];
3101 char *name = app->msgq_params[id].name;
3103 fprintf(f, " %s", name);
3109 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3115 for (j = 0; j < p->n_args; j++)
3116 fprintf(f, "%s = %s\n", p->args_name[j],
3125 app_config_save(struct app_params *app, const char *file_name)
3128 char *name, *dir_name;
3131 name = strdup(file_name);
3132 dir_name = dirname(name);
3133 status = access(dir_name, W_OK);
3134 APP_CHECK((status == 0),
3135 "Error: need write access privilege to directory "
3136 "\"%s\" to save configuration\n", dir_name);
3138 file = fopen(file_name, "w");
3139 APP_CHECK((file != NULL),
3140 "Error: failed to save configuration to file \"%s\"",
3143 save_eal_params(app, file);
3144 save_pipeline_params(app, file);
3145 save_mempool_params(app, file);
3146 save_links_params(app, file);
3147 save_rxq_params(app, file);
3148 save_txq_params(app, file);
3149 save_swq_params(app, file);
3150 save_tm_params(app, file);
3151 save_tap_params(app, file);
3152 save_kni_params(app, file);
3153 save_source_params(app, file);
3154 save_sink_params(app, file);
3155 save_msgq_params(app, file);
3162 app_config_init(struct app_params *app)
3166 memcpy(app, &app_params_default, sizeof(struct app_params));
3168 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3169 memcpy(&app->mempool_params[i],
3170 &mempool_params_default,
3171 sizeof(struct app_mempool_params));
3173 for (i = 0; i < RTE_DIM(app->link_params); i++)
3174 memcpy(&app->link_params[i],
3175 &link_params_default,
3176 sizeof(struct app_link_params));
3178 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3179 memcpy(&app->hwq_in_params[i],
3180 &default_hwq_in_params,
3181 sizeof(default_hwq_in_params));
3183 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3184 memcpy(&app->hwq_out_params[i],
3185 &default_hwq_out_params,
3186 sizeof(default_hwq_out_params));
3188 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3189 memcpy(&app->swq_params[i],
3190 &default_swq_params,
3191 sizeof(default_swq_params));
3193 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3194 memcpy(&app->tm_params[i],
3196 sizeof(default_tm_params));
3198 for (i = 0; i < RTE_DIM(app->tap_params); i++)
3199 memcpy(&app->tap_params[i],
3200 &default_tap_params,
3201 sizeof(default_tap_params));
3203 for (i = 0; i < RTE_DIM(app->kni_params); i++)
3204 memcpy(&app->kni_params[i],
3205 &default_kni_params,
3206 sizeof(default_kni_params));
3208 for (i = 0; i < RTE_DIM(app->source_params); i++)
3209 memcpy(&app->source_params[i],
3210 &default_source_params,
3211 sizeof(default_source_params));
3213 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3214 memcpy(&app->sink_params[i],
3215 &default_sink_params,
3216 sizeof(default_sink_params));
3218 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3219 memcpy(&app->msgq_params[i],
3220 &default_msgq_params,
3221 sizeof(default_msgq_params));
3223 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3224 memcpy(&app->pipeline_params[i],
3225 &default_pipeline_params,
3226 sizeof(default_pipeline_params));
3232 filenamedup(const char *filename, const char *suffix)
3234 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3239 sprintf(s, "%s%s", filename, suffix);
3244 app_config_args(struct app_params *app, int argc, char **argv)
3246 const char *optname;
3247 int opt, option_index;
3248 int f_present, s_present, p_present, l_present;
3249 int preproc_present, preproc_params_present;
3252 static struct option lgopts[] = {
3253 { "preproc", 1, 0, 0 },
3254 { "preproc-args", 1, 0, 0 },
3258 /* Copy application name */
3259 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3265 preproc_present = 0;
3266 preproc_params_present = 0;
3268 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3269 &option_index)) != EOF)
3273 rte_panic("Error: Config file is provided "
3274 "more than once\n");
3277 if (!strlen(optarg))
3278 rte_panic("Error: Config file name is null\n");
3280 app->config_file = strdup(optarg);
3281 if (app->config_file == NULL)
3282 rte_panic("Error: Memory allocation failure\n");
3288 rte_panic("Error: Script file is provided "
3289 "more than once\n");
3292 if (!strlen(optarg))
3293 rte_panic("Error: Script file name is null\n");
3295 app->script_file = strdup(optarg);
3296 if (app->script_file == NULL)
3297 rte_panic("Error: Memory allocation failure\n");
3303 rte_panic("Error: PORT_MASK is provided "
3304 "more than once\n");
3307 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3309 ((size_t) scaned != strlen(optarg)))
3310 rte_panic("Error: PORT_MASK is not "
3311 "a hexadecimal integer\n");
3313 if (app->port_mask == 0)
3314 rte_panic("Error: PORT_MASK is null\n");
3320 rte_panic("Error: LOG_LEVEL is provided "
3321 "more than once\n");
3324 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3326 ((size_t) scaned != strlen(optarg)) ||
3327 (app->log_level >= APP_LOG_LEVELS))
3328 rte_panic("Error: LOG_LEVEL invalid value\n");
3333 optname = lgopts[option_index].name;
3335 if (strcmp(optname, "preproc") == 0) {
3336 if (preproc_present)
3337 rte_panic("Error: Preprocessor argument "
3338 "is provided more than once\n");
3339 preproc_present = 1;
3341 app->preproc = strdup(optarg);
3345 if (strcmp(optname, "preproc-args") == 0) {
3346 if (preproc_params_present)
3347 rte_panic("Error: Preprocessor args "
3348 "are provided more than once\n");
3349 preproc_params_present = 1;
3351 app->preproc_args = strdup(optarg);
3355 app_print_usage(argv[0]);
3359 app_print_usage(argv[0]);
3362 optind = 1; /* reset getopt lib */
3364 /* Check dependencies between args */
3365 if (preproc_params_present && (preproc_present == 0))
3366 rte_panic("Error: Preprocessor args specified while "
3367 "preprocessor is not defined\n");
3369 app->parser_file = preproc_present ?
3370 filenamedup(app->config_file, ".preproc") :
3371 strdup(app->config_file);
3372 app->output_file = filenamedup(app->config_file, ".out");
3378 app_config_preproc(struct app_params *app)
3383 if (app->preproc == NULL)
3386 status = access(app->config_file, F_OK | R_OK);
3387 APP_CHECK((status == 0), "Error: Unable to open file %s",
3390 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3392 app->preproc_args ? app->preproc_args : "",
3396 status = system(buffer);
3397 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3398 "Error occurred while pre-processing file \"%s\"\n",