4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 #include <rte_errno.h>
47 #include <rte_cfgfile.h>
48 #include <rte_string_fns.h>
54 * Default config values
57 static struct app_params app_params_default = {
58 .config_file = "./config/ip_pipeline.cfg",
59 .log_level = APP_LOG_LEVEL_HIGH,
67 static const struct app_mempool_params mempool_params_default = {
69 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
70 .pool_size = 32 * 1024,
75 static const struct app_link_params link_params_default = {
86 .rss_proto_ipv4 = ETH_RSS_IPV4,
87 .rss_proto_ipv6 = ETH_RSS_IPV6,
98 .mq_mode = ETH_MQ_RX_NONE,
100 .header_split = 0, /* Header split */
101 .hw_ip_checksum = 0, /* IP checksum offload */
102 .hw_vlan_filter = 0, /* VLAN filtering */
103 .hw_vlan_strip = 0, /* VLAN strip */
104 .hw_vlan_extend = 0, /* Extended VLAN */
105 .jumbo_frame = 0, /* Jumbo frame support */
106 .hw_strip_crc = 0, /* CRC strip by HW */
107 .enable_scatter = 0, /* Scattered packets RX handler */
109 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
110 .split_hdr_size = 0, /* Header split buffer size */
120 .mq_mode = ETH_MQ_TX_NONE,
128 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
140 .rx_free_thresh = 64,
142 .rx_deferred_start = 0,
146 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
161 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
162 ETH_TXQ_FLAGS_NOOFFLOADS,
163 .tx_deferred_start = 0,
167 static const struct app_pktq_swq_params default_swq_params = {
181 .mempool_direct_id = 0,
182 .mempool_indirect_id = 0,
185 struct app_pktq_tm_params default_tm_params = {
187 .file_name = "./config/tm_profile.cfg",
192 struct app_pktq_kni_params default_kni_params = {
206 struct app_pktq_source_params default_source_params = {
211 .n_bytes_per_pkt = 0,
214 struct app_pktq_sink_params default_sink_params = {
220 struct app_msgq_params default_msgq_params = {
226 struct app_pipeline_params default_pipeline_params = {
239 static const char app_usage[] =
240 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
241 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
244 "\t-f CONFIG_FILE: Default config file is %s\n"
245 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
246 "config file when not provided)\n"
247 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
248 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
249 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
250 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
254 app_print_usage(char *prgname)
256 rte_exit(0, app_usage, prgname, app_params_default.config_file);
259 #define APP_PARAM_ADD(set, key) \
261 ssize_t pos = APP_PARAM_FIND(set, key); \
262 ssize_t size = RTE_DIM(set); \
265 for (pos = 0; pos < size; pos++) { \
266 if (!APP_PARAM_VALID(&((set)[pos]))) \
270 APP_CHECK((pos < size), \
271 "Parse error: size of %s is limited to %u elements",\
272 #set, (uint32_t) size); \
274 (set)[pos].name = strdup(key); \
275 APP_CHECK(((set)[pos].name), \
276 "Parse error: no free memory"); \
281 #define APP_PARAM_ADD_LINK_FOR_RXQ(app, rxq_name) \
283 char link_name[APP_PARAM_NAME_SIZE]; \
284 ssize_t link_param_pos; \
285 uint32_t link_id, queue_id; \
287 sscanf((rxq_name), "RXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
288 sprintf(link_name, "LINK%" PRIu32, link_id); \
289 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
293 #define APP_PARAM_ADD_LINK_FOR_TXQ(app, txq_name) \
295 char link_name[APP_PARAM_NAME_SIZE]; \
296 ssize_t link_param_pos; \
297 uint32_t link_id, queue_id; \
299 sscanf((txq_name), "TXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
300 sprintf(link_name, "LINK%" PRIu32, link_id); \
301 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
305 #define APP_PARAM_ADD_LINK_FOR_TM(app, tm_name) \
307 char link_name[APP_PARAM_NAME_SIZE]; \
308 ssize_t link_param_pos; \
311 sscanf((tm_name), "TM%" SCNu32, &link_id); \
312 sprintf(link_name, "LINK%" PRIu32, link_id); \
313 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
317 #define APP_PARAM_ADD_LINK_FOR_KNI(app, kni_name) \
319 char link_name[APP_PARAM_NAME_SIZE]; \
320 ssize_t link_param_pos; \
323 sscanf((kni_name), "KNI%" SCNu32, &link_id); \
324 sprintf(link_name, "LINK%" PRIu32, link_id); \
325 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
329 #define PARSE_CHECK_DUPLICATE_SECTION(obj) \
331 APP_CHECK(((obj)->parsed == 0), \
332 "Parse error: duplicate \"%s\" section", (obj)->name); \
336 #define PARSE_CHECK_DUPLICATE_SECTION_EAL(obj) \
338 APP_CHECK(((obj)->parsed == 0), \
339 "Parse error: duplicate \"%s\" section", "EAL"); \
343 #define PARSE_ERROR(exp, section, entry) \
344 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"", section, entry)
346 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
347 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s", \
348 section, entry, message)
350 #define PARSE_ERROR_NO_ELEMENTS(exp, section, entry) \
351 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
352 "no elements detected", \
355 #define PARSE_ERROR_TOO_MANY_ELEMENTS(exp, section, entry, max) \
356 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
357 "maximum number of elements allowed is %u", \
360 #define PARSE_ERROR_INVALID_ELEMENT(exp, section, entry, value) \
361 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
362 "Invalid element value \"%s\"", \
363 section, entry, value)
365 #define PARSE_ERROR_MALLOC(exp) \
366 APP_CHECK(exp, "Parse error: no free memory")
368 #define PARSE_ERROR_SECTION(exp, section) \
369 APP_CHECK(exp, "Parse error in section \"%s\"", section)
371 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
372 APP_CHECK(exp, "Parse error in section \"%s\": no entries", section)
374 #define PARSE_WARNING_IGNORED(exp, section, entry) \
377 fprintf(stderr, "Parse warning in section \"%s\": " \
378 "entry \"%s\" is ignored", section, entry); \
381 #define PARSE_ERROR_INVALID(exp, section, entry) \
382 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"",\
385 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
386 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"", \
390 validate_name(const char *name, const char *prefix, int num)
394 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
395 if (name[i] != prefix[i])
399 if (prefix[i] != '\0')
410 j = skip_digits(&name[i]);
412 if ((j == 0) || (name[i] != '.'))
418 j = skip_digits(&name[i]);
420 if ((j == 0) || (name[i] != '\0'))
428 parse_eal(struct app_params *app,
429 const char *section_name,
430 struct rte_cfgfile *cfg)
432 struct app_eal_params *p = &app->eal_params;
433 struct rte_cfgfile_entry *entries;
436 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
437 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
439 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
440 PARSE_ERROR_MALLOC(entries != NULL);
442 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
444 PARSE_CHECK_DUPLICATE_SECTION_EAL(p);
446 for (i = 0; i < n_entries; i++) {
447 struct rte_cfgfile_entry *entry = &entries[i];
450 if (strcmp(entry->name, "c") == 0) {
451 PARSE_WARNING_IGNORED(0, section_name, entry->name);
456 if (strcmp(entry->name, "l") == 0) {
457 PARSE_WARNING_IGNORED(0, section_name, entry->name);
462 if (strcmp(entry->name, "lcores") == 0) {
463 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
466 p->coremap = strdup(entry->value);
471 if (strcmp(entry->name, "master_lcore") == 0) {
474 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
477 p->master_lcore_present = 1;
479 status = parser_read_uint32(&p->master_lcore,
481 PARSE_ERROR((status == 0), section_name, entry->name);
486 if (strcmp(entry->name, "n") == 0) {
489 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
492 p->channels_present = 1;
494 status = parser_read_uint32(&p->channels, entry->value);
495 PARSE_ERROR((status == 0), section_name, entry->name);
500 if (strcmp(entry->name, "m") == 0) {
503 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
506 p->memory_present = 1;
508 status = parser_read_uint32(&p->memory, entry->value);
509 PARSE_ERROR((status == 0), section_name, entry->name);
514 if (strcmp(entry->name, "r") == 0) {
517 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
520 p->ranks_present = 1;
522 status = parser_read_uint32(&p->ranks, entry->value);
523 PARSE_ERROR((status == 0), section_name, entry->name);
528 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
529 (strcmp(entry->name, "b") == 0)) {
532 for (i = 0; i < APP_MAX_LINKS; i++) {
533 if (p->pci_blacklist[i])
536 p->pci_blacklist[i] =
537 strdup(entry->value);
538 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
543 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
544 section_name, entry->name,
545 "too many elements");
550 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
551 (strcmp(entry->name, "w") == 0)) {
554 PARSE_ERROR_MESSAGE((app->port_mask != 0),
555 section_name, entry->name, "entry to be "
556 "generated by the application (port_mask "
559 for (i = 0; i < APP_MAX_LINKS; i++) {
560 if (p->pci_whitelist[i])
563 p->pci_whitelist[i] = strdup(entry->value);
564 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
569 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
570 section_name, entry->name,
571 "too many elements");
576 if (strcmp(entry->name, "vdev") == 0) {
579 for (i = 0; i < APP_MAX_LINKS; i++) {
583 p->vdev[i] = strdup(entry->value);
584 PARSE_ERROR_MALLOC(p->vdev[i]);
589 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
590 section_name, entry->name,
591 "too many elements");
596 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
599 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
602 p->vmware_tsc_map_present = 1;
604 val = parser_read_arg_bool(entry->value);
605 PARSE_ERROR((val >= 0), section_name, entry->name);
606 p->vmware_tsc_map = val;
611 if (strcmp(entry->name, "proc_type") == 0) {
612 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
615 p->proc_type = strdup(entry->value);
620 if (strcmp(entry->name, "syslog") == 0) {
621 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
624 p->syslog = strdup(entry->value);
629 if (strcmp(entry->name, "log_level") == 0) {
632 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
635 p->log_level_present = 1;
637 status = parser_read_uint32(&p->log_level,
639 PARSE_ERROR((status == 0), section_name, entry->name);
644 if (strcmp(entry->name, "v") == 0) {
647 PARSE_ERROR_DUPLICATE((p->version_present == 0),
650 p->version_present = 1;
652 val = parser_read_arg_bool(entry->value);
653 PARSE_ERROR((val >= 0), section_name, entry->name);
659 if ((strcmp(entry->name, "help") == 0) ||
660 (strcmp(entry->name, "h") == 0)) {
663 PARSE_ERROR_DUPLICATE((p->help_present == 0),
668 val = parser_read_arg_bool(entry->value);
669 PARSE_ERROR((val >= 0), section_name, entry->name);
675 if (strcmp(entry->name, "no_huge") == 0) {
678 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
681 p->no_huge_present = 1;
683 val = parser_read_arg_bool(entry->value);
684 PARSE_ERROR((val >= 0), section_name, entry->name);
690 if (strcmp(entry->name, "no_pci") == 0) {
693 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
696 p->no_pci_present = 1;
698 val = parser_read_arg_bool(entry->value);
699 PARSE_ERROR((val >= 0), section_name, entry->name);
705 if (strcmp(entry->name, "no_hpet") == 0) {
708 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
711 p->no_hpet_present = 1;
713 val = parser_read_arg_bool(entry->value);
714 PARSE_ERROR((val >= 0), section_name, entry->name);
720 if (strcmp(entry->name, "no_shconf") == 0) {
723 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
726 p->no_shconf_present = 1;
728 val = parser_read_arg_bool(entry->value);
729 PARSE_ERROR((val >= 0), section_name, entry->name);
735 if (strcmp(entry->name, "d") == 0) {
736 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
739 p->add_driver = strdup(entry->value);
744 if (strcmp(entry->name, "socket_mem") == 0) {
745 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
748 p->socket_mem = strdup(entry->value);
753 if (strcmp(entry->name, "huge_dir") == 0) {
754 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
757 p->huge_dir = strdup(entry->value);
762 if (strcmp(entry->name, "file_prefix") == 0) {
763 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
766 p->file_prefix = strdup(entry->value);
771 if (strcmp(entry->name, "base_virtaddr") == 0) {
772 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
775 p->base_virtaddr = strdup(entry->value);
780 if (strcmp(entry->name, "create_uio_dev") == 0) {
783 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
786 p->create_uio_dev_present = 1;
788 val = parser_read_arg_bool(entry->value);
789 PARSE_ERROR((val >= 0), section_name, entry->name);
790 p->create_uio_dev = val;
795 if (strcmp(entry->name, "vfio_intr") == 0) {
796 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
799 p->vfio_intr = strdup(entry->value);
804 if (strcmp(entry->name, "xen_dom0") == 0) {
807 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
810 p->xen_dom0_present = 1;
812 val = parser_read_arg_bool(entry->value);
813 PARSE_ERROR((val >= 0), section_name, entry->name);
819 PARSE_ERROR_INVALID(0, section_name, entry->name);
826 parse_pipeline_pktq_in(struct app_params *app,
827 struct app_pipeline_params *p,
833 enum app_pktq_in_type type;
835 char *name = strtok_r(value, PARSE_DELIMITER, &value);
840 PARSE_ERROR_TOO_MANY_ELEMENTS(
841 (p->n_pktq_in < RTE_DIM(p->pktq_in)),
842 p->name, "pktq_in", (uint32_t)RTE_DIM(p->pktq_in));
844 if (validate_name(name, "RXQ", 2) == 0) {
845 type = APP_PKTQ_IN_HWQ;
846 id = APP_PARAM_ADD(app->hwq_in_params, name);
847 APP_PARAM_ADD_LINK_FOR_RXQ(app, name);
848 } else if (validate_name(name, "SWQ", 1) == 0) {
849 type = APP_PKTQ_IN_SWQ;
850 id = APP_PARAM_ADD(app->swq_params, name);
851 } else if (validate_name(name, "TM", 1) == 0) {
852 type = APP_PKTQ_IN_TM;
853 id = APP_PARAM_ADD(app->tm_params, name);
854 APP_PARAM_ADD_LINK_FOR_TM(app, name);
855 } else if (validate_name(name, "KNI", 1) == 0) {
856 type = APP_PKTQ_IN_KNI;
857 id = APP_PARAM_ADD(app->kni_params, name);
858 APP_PARAM_ADD_LINK_FOR_KNI(app, name);
859 } else if (validate_name(name, "SOURCE", 1) == 0) {
860 type = APP_PKTQ_IN_SOURCE;
861 id = APP_PARAM_ADD(app->source_params, name);
863 PARSE_ERROR_INVALID_ELEMENT(0,
864 p->name, "pktq_in", name);
866 p->pktq_in[p->n_pktq_in].type = type;
867 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
871 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_in > 0), p->name, "pktq_in");
875 parse_pipeline_pktq_out(struct app_params *app,
876 struct app_pipeline_params *p,
882 enum app_pktq_out_type type;
884 char *name = strtok_r(value, PARSE_DELIMITER, &value);
889 PARSE_ERROR_TOO_MANY_ELEMENTS(
890 (p->n_pktq_out < RTE_DIM(p->pktq_out)),
891 p->name, "pktq_out", (uint32_t)RTE_DIM(p->pktq_out));
893 if (validate_name(name, "TXQ", 2) == 0) {
894 type = APP_PKTQ_OUT_HWQ;
895 id = APP_PARAM_ADD(app->hwq_out_params, name);
896 APP_PARAM_ADD_LINK_FOR_TXQ(app, name);
897 } else if (validate_name(name, "SWQ", 1) == 0) {
898 type = APP_PKTQ_OUT_SWQ;
899 id = APP_PARAM_ADD(app->swq_params, name);
900 } else if (validate_name(name, "TM", 1) == 0) {
901 type = APP_PKTQ_OUT_TM;
902 id = APP_PARAM_ADD(app->tm_params, name);
903 APP_PARAM_ADD_LINK_FOR_TM(app, name);
904 } else if (validate_name(name, "KNI", 1) == 0) {
905 type = APP_PKTQ_OUT_KNI;
906 id = APP_PARAM_ADD(app->kni_params, name);
907 APP_PARAM_ADD_LINK_FOR_KNI(app, name);
908 } else if (validate_name(name, "SINK", 1) == 0) {
909 type = APP_PKTQ_OUT_SINK;
910 id = APP_PARAM_ADD(app->sink_params, name);
912 PARSE_ERROR_INVALID_ELEMENT(0,
913 p->name, "pktq_out", name);
915 p->pktq_out[p->n_pktq_out].type = type;
916 p->pktq_out[p->n_pktq_out].id = id;
920 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_out > 0), p->name, "pktq_out");
924 parse_pipeline_msgq_in(struct app_params *app,
925 struct app_pipeline_params *p,
932 char *name = strtok_r(value, PARSE_DELIMITER, &value);
937 PARSE_ERROR_TOO_MANY_ELEMENTS(
938 (p->n_msgq_in < RTE_DIM(p->msgq_in)),
939 p->name, "msgq_in", (uint32_t)(RTE_DIM(p->msgq_in)));
941 PARSE_ERROR_INVALID_ELEMENT(
942 (validate_name(name, "MSGQ", 1) == 0),
943 p->name, "msgq_in", name);
945 idx = APP_PARAM_ADD(app->msgq_params, name);
946 p->msgq_in[p->n_msgq_in] = idx;
950 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_in > 0), p->name, "msgq_in");
954 parse_pipeline_msgq_out(struct app_params *app,
955 struct app_pipeline_params *p,
962 char *name = strtok_r(value, PARSE_DELIMITER, &value);
967 PARSE_ERROR_TOO_MANY_ELEMENTS(
968 (p->n_msgq_out < RTE_DIM(p->msgq_out)),
969 p->name, "msgq_out", (uint32_t)RTE_DIM(p->msgq_out));
971 PARSE_ERROR_INVALID_ELEMENT(
972 (validate_name(name, "MSGQ", 1) == 0),
973 p->name, "msgq_out", name);
975 idx = APP_PARAM_ADD(app->msgq_params, name);
976 p->msgq_out[p->n_msgq_out] = idx;
980 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_out > 0), p->name, "msgq_out");
984 parse_pipeline(struct app_params *app,
985 const char *section_name,
986 struct rte_cfgfile *cfg)
988 char name[CFG_NAME_LEN];
989 struct app_pipeline_params *param;
990 struct rte_cfgfile_entry *entries;
994 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
995 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
997 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
998 PARSE_ERROR_MALLOC(entries != NULL);
1000 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1002 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1003 param = &app->pipeline_params[param_idx];
1004 PARSE_CHECK_DUPLICATE_SECTION(param);
1006 for (i = 0; i < n_entries; i++) {
1007 struct rte_cfgfile_entry *ent = &entries[i];
1009 if (strcmp(ent->name, "type") == 0) {
1010 int w_size = snprintf(param->type, RTE_DIM(param->type),
1013 PARSE_ERROR(((w_size > 0) &&
1014 (w_size < (int)RTE_DIM(param->type))),
1020 if (strcmp(ent->name, "core") == 0) {
1021 int status = parse_pipeline_core(
1022 ¶m->socket_id, ¶m->core_id,
1023 ¶m->hyper_th_id, ent->value);
1025 PARSE_ERROR((status == 0), section_name,
1030 if (strcmp(ent->name, "pktq_in") == 0) {
1031 parse_pipeline_pktq_in(app, param, ent->value);
1036 if (strcmp(ent->name, "pktq_out") == 0) {
1037 parse_pipeline_pktq_out(app, param, ent->value);
1042 if (strcmp(ent->name, "msgq_in") == 0) {
1043 parse_pipeline_msgq_in(app, param, ent->value);
1048 if (strcmp(ent->name, "msgq_out") == 0) {
1049 parse_pipeline_msgq_out(app, param, ent->value);
1054 if (strcmp(ent->name, "timer_period") == 0) {
1055 int status = parser_read_uint32(
1056 ¶m->timer_period,
1059 PARSE_ERROR((status == 0), section_name,
1064 /* pipeline type specific items */
1065 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1066 "Parse error in section \"%s\": too many "
1067 "pipeline specified parameters", section_name);
1069 param->args_name[param->n_args] = strdup(ent->name);
1070 param->args_value[param->n_args] = strdup(ent->value);
1072 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1073 (param->args_value[param->n_args] != NULL),
1074 "Parse error: no free memory");
1079 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1080 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1081 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1082 param->msgq_in[param->n_msgq_in++] = param_idx;
1084 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1085 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1086 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1087 param->msgq_out[param->n_msgq_out++] = param_idx;
1089 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1092 (param->hyper_th_id) ? "h" : "");
1093 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1094 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1096 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1099 (param->hyper_th_id) ? "h" : "");
1100 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1101 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1107 parse_mempool(struct app_params *app,
1108 const char *section_name,
1109 struct rte_cfgfile *cfg)
1111 struct app_mempool_params *param;
1112 struct rte_cfgfile_entry *entries;
1116 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1117 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1119 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1120 PARSE_ERROR_MALLOC(entries != NULL);
1122 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1124 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1125 param = &app->mempool_params[param_idx];
1126 PARSE_CHECK_DUPLICATE_SECTION(param);
1128 for (i = 0; i < n_entries; i++) {
1129 struct rte_cfgfile_entry *ent = &entries[i];
1131 if (strcmp(ent->name, "buffer_size") == 0) {
1132 int status = parser_read_uint32(
1133 ¶m->buffer_size, ent->value);
1135 PARSE_ERROR((status == 0), section_name,
1140 if (strcmp(ent->name, "pool_size") == 0) {
1141 int status = parser_read_uint32(
1142 ¶m->pool_size, ent->value);
1144 PARSE_ERROR((status == 0), section_name,
1149 if (strcmp(ent->name, "cache_size") == 0) {
1150 int status = parser_read_uint32(
1151 ¶m->cache_size, ent->value);
1153 PARSE_ERROR((status == 0), section_name,
1158 if (strcmp(ent->name, "cpu") == 0) {
1159 int status = parser_read_uint32(
1160 ¶m->cpu_socket_id, ent->value);
1162 PARSE_ERROR((status == 0), section_name,
1168 PARSE_ERROR_INVALID(0, section_name, ent->name);
1175 parse_link_rss_qs(struct app_link_params *p,
1181 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1186 if (p->n_rss_qs == RTE_DIM(p->rss_qs))
1189 if (parser_read_uint32(&p->rss_qs[p->n_rss_qs++], token))
1197 parse_link_rss_proto_ipv4(struct app_link_params *p,
1203 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1208 if (strcmp(token, "IP") == 0) {
1209 mask |= ETH_RSS_IPV4;
1212 if (strcmp(token, "FRAG") == 0) {
1213 mask |= ETH_RSS_FRAG_IPV4;
1216 if (strcmp(token, "TCP") == 0) {
1217 mask |= ETH_RSS_NONFRAG_IPV4_TCP;
1220 if (strcmp(token, "UDP") == 0) {
1221 mask |= ETH_RSS_NONFRAG_IPV4_UDP;
1224 if (strcmp(token, "SCTP") == 0) {
1225 mask |= ETH_RSS_NONFRAG_IPV4_SCTP;
1228 if (strcmp(token, "OTHER") == 0) {
1229 mask |= ETH_RSS_NONFRAG_IPV4_OTHER;
1235 p->rss_proto_ipv4 = mask;
1240 parse_link_rss_proto_ipv6(struct app_link_params *p,
1246 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1251 if (strcmp(token, "IP") == 0) {
1252 mask |= ETH_RSS_IPV6;
1255 if (strcmp(token, "FRAG") == 0) {
1256 mask |= ETH_RSS_FRAG_IPV6;
1259 if (strcmp(token, "TCP") == 0) {
1260 mask |= ETH_RSS_NONFRAG_IPV6_TCP;
1263 if (strcmp(token, "UDP") == 0) {
1264 mask |= ETH_RSS_NONFRAG_IPV6_UDP;
1267 if (strcmp(token, "SCTP") == 0) {
1268 mask |= ETH_RSS_NONFRAG_IPV6_SCTP;
1271 if (strcmp(token, "OTHER") == 0) {
1272 mask |= ETH_RSS_NONFRAG_IPV6_OTHER;
1275 if (strcmp(token, "IP_EX") == 0) {
1276 mask |= ETH_RSS_IPV6_EX;
1279 if (strcmp(token, "TCP_EX") == 0) {
1280 mask |= ETH_RSS_IPV6_TCP_EX;
1283 if (strcmp(token, "UDP_EX") == 0) {
1284 mask |= ETH_RSS_IPV6_UDP_EX;
1290 p->rss_proto_ipv6 = mask;
1295 parse_link_rss_proto_l2(struct app_link_params *p,
1301 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1306 if (strcmp(token, "L2") == 0) {
1307 mask |= ETH_RSS_L2_PAYLOAD;
1313 p->rss_proto_l2 = mask;
1318 parse_link(struct app_params *app,
1319 const char *section_name,
1320 struct rte_cfgfile *cfg)
1322 struct app_link_params *param;
1323 struct rte_cfgfile_entry *entries;
1325 int rss_qs_present = 0;
1326 int rss_proto_ipv4_present = 0;
1327 int rss_proto_ipv6_present = 0;
1328 int rss_proto_l2_present = 0;
1329 int pci_bdf_present = 0;
1332 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1333 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1335 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1336 PARSE_ERROR_MALLOC(entries != NULL);
1338 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1340 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1341 param = &app->link_params[param_idx];
1342 PARSE_CHECK_DUPLICATE_SECTION(param);
1344 for (i = 0; i < n_entries; i++) {
1345 struct rte_cfgfile_entry *ent = &entries[i];
1347 if (strcmp(ent->name, "promisc") == 0) {
1348 int status = parser_read_arg_bool(ent->value);
1350 PARSE_ERROR((status != -EINVAL), section_name,
1352 param->promisc = status;
1356 if (strcmp(ent->name, "arp_q") == 0) {
1357 int status = parser_read_uint32(¶m->arp_q,
1360 PARSE_ERROR((status == 0), section_name,
1365 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1366 int status = parser_read_uint32(
1367 ¶m->tcp_syn_q, ent->value);
1369 PARSE_ERROR((status == 0), section_name, ent->name);
1373 if (strcmp(ent->name, "ip_local_q") == 0) {
1374 int status = parser_read_uint32(
1375 ¶m->ip_local_q, ent->value);
1377 PARSE_ERROR((status == 0), section_name,
1382 if (strcmp(ent->name, "tcp_local_q") == 0) {
1383 int status = parser_read_uint32(
1384 ¶m->tcp_local_q, ent->value);
1386 PARSE_ERROR((status == 0), section_name,
1391 if (strcmp(ent->name, "udp_local_q") == 0) {
1392 int status = parser_read_uint32(
1393 ¶m->udp_local_q, ent->value);
1395 PARSE_ERROR((status == 0), section_name,
1400 if (strcmp(ent->name, "sctp_local_q") == 0) {
1401 int status = parser_read_uint32(
1402 ¶m->sctp_local_q, ent->value);
1404 PARSE_ERROR((status == 0), section_name,
1409 if (strcmp(ent->name, "rss_qs") == 0) {
1410 int status = parse_link_rss_qs(param, ent->value);
1412 PARSE_ERROR((status == 0), section_name,
1418 if (strcmp(ent->name, "rss_proto_ipv4") == 0) {
1420 parse_link_rss_proto_ipv4(param, ent->value);
1422 PARSE_ERROR((status != -EINVAL), section_name,
1424 rss_proto_ipv4_present = 1;
1428 if (strcmp(ent->name, "rss_proto_ipv6") == 0) {
1430 parse_link_rss_proto_ipv6(param, ent->value);
1432 PARSE_ERROR((status != -EINVAL), section_name,
1434 rss_proto_ipv6_present = 1;
1438 if (strcmp(ent->name, "rss_proto_l2") == 0) {
1439 int status = parse_link_rss_proto_l2(param, ent->value);
1441 PARSE_ERROR((status != -EINVAL), section_name,
1443 rss_proto_l2_present = 1;
1447 if (strcmp(ent->name, "pci_bdf") == 0) {
1448 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1449 section_name, ent->name);
1451 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1453 pci_bdf_present = 1;
1458 PARSE_ERROR_INVALID(0, section_name, ent->name);
1461 /* Check for mandatory fields */
1463 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1464 section_name, "pci_bdf",
1465 "entry not allowed (port_mask is provided)");
1467 PARSE_ERROR_MESSAGE((pci_bdf_present),
1468 section_name, "pci_bdf",
1469 "this entry is mandatory (port_mask is not "
1472 if (rss_proto_ipv4_present)
1473 PARSE_ERROR_MESSAGE((rss_qs_present),
1474 section_name, "rss_proto_ipv4",
1475 "entry not allowed (rss_qs entry is not provided)");
1476 if (rss_proto_ipv6_present)
1477 PARSE_ERROR_MESSAGE((rss_qs_present),
1478 section_name, "rss_proto_ipv6",
1479 "entry not allowed (rss_qs entry is not provided)");
1480 if (rss_proto_l2_present)
1481 PARSE_ERROR_MESSAGE((rss_qs_present),
1482 section_name, "rss_proto_l2",
1483 "entry not allowed (rss_qs entry is not provided)");
1484 if (rss_proto_ipv4_present |
1485 rss_proto_ipv6_present |
1486 rss_proto_l2_present){
1487 if (rss_proto_ipv4_present == 0)
1488 param->rss_proto_ipv4 = 0;
1489 if (rss_proto_ipv6_present == 0)
1490 param->rss_proto_ipv6 = 0;
1491 if (rss_proto_l2_present == 0)
1492 param->rss_proto_l2 = 0;
1499 parse_rxq(struct app_params *app,
1500 const char *section_name,
1501 struct rte_cfgfile *cfg)
1503 struct app_pktq_hwq_in_params *param;
1504 struct rte_cfgfile_entry *entries;
1508 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1509 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1511 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1512 PARSE_ERROR_MALLOC(entries != NULL);
1514 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1516 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1517 param = &app->hwq_in_params[param_idx];
1518 PARSE_CHECK_DUPLICATE_SECTION(param);
1520 APP_PARAM_ADD_LINK_FOR_RXQ(app, section_name);
1522 for (i = 0; i < n_entries; i++) {
1523 struct rte_cfgfile_entry *ent = &entries[i];
1525 if (strcmp(ent->name, "mempool") == 0) {
1526 int status = validate_name(ent->value,
1530 PARSE_ERROR((status == 0), section_name,
1533 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1534 param->mempool_id = idx;
1538 if (strcmp(ent->name, "size") == 0) {
1539 int status = parser_read_uint32(¶m->size,
1542 PARSE_ERROR((status == 0), section_name,
1547 if (strcmp(ent->name, "burst") == 0) {
1548 int status = parser_read_uint32(¶m->burst,
1551 PARSE_ERROR((status == 0), section_name,
1557 PARSE_ERROR_INVALID(0, section_name, ent->name);
1564 parse_txq(struct app_params *app,
1565 const char *section_name,
1566 struct rte_cfgfile *cfg)
1568 struct app_pktq_hwq_out_params *param;
1569 struct rte_cfgfile_entry *entries;
1573 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1574 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1576 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1577 PARSE_ERROR_MALLOC(entries != NULL);
1579 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1581 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1582 param = &app->hwq_out_params[param_idx];
1583 PARSE_CHECK_DUPLICATE_SECTION(param);
1585 APP_PARAM_ADD_LINK_FOR_TXQ(app, section_name);
1587 for (i = 0; i < n_entries; i++) {
1588 struct rte_cfgfile_entry *ent = &entries[i];
1590 if (strcmp(ent->name, "size") == 0) {
1591 int status = parser_read_uint32(¶m->size,
1594 PARSE_ERROR((status == 0), section_name,
1599 if (strcmp(ent->name, "burst") == 0) {
1600 int status = parser_read_uint32(¶m->burst,
1603 PARSE_ERROR((status == 0), section_name,
1608 if (strcmp(ent->name, "dropless") == 0) {
1609 int status = parser_read_arg_bool(ent->value);
1612 PARSE_ERROR((status != -EINVAL), section_name,
1614 param->dropless = status;
1618 if (strcmp(ent->name, "n_retries") == 0) {
1619 int status = parser_read_uint64(¶m->n_retries,
1622 PARSE_ERROR((status == 0), section_name,
1628 PARSE_ERROR_INVALID(0, section_name, ent->name);
1635 parse_swq(struct app_params *app,
1636 const char *section_name,
1637 struct rte_cfgfile *cfg)
1639 struct app_pktq_swq_params *param;
1640 struct rte_cfgfile_entry *entries;
1642 uint32_t mtu_present = 0;
1643 uint32_t metadata_size_present = 0;
1644 uint32_t mempool_direct_present = 0;
1645 uint32_t mempool_indirect_present = 0;
1649 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1650 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1652 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1653 PARSE_ERROR_MALLOC(entries != NULL);
1655 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1657 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1658 param = &app->swq_params[param_idx];
1659 PARSE_CHECK_DUPLICATE_SECTION(param);
1661 for (i = 0; i < n_entries; i++) {
1662 struct rte_cfgfile_entry *ent = &entries[i];
1664 if (strcmp(ent->name, "size") == 0) {
1665 int status = parser_read_uint32(¶m->size,
1668 PARSE_ERROR((status == 0), section_name,
1673 if (strcmp(ent->name, "burst_read") == 0) {
1674 int status = parser_read_uint32(&
1675 param->burst_read, ent->value);
1677 PARSE_ERROR((status == 0), section_name,
1682 if (strcmp(ent->name, "burst_write") == 0) {
1683 int status = parser_read_uint32(
1684 ¶m->burst_write, ent->value);
1686 PARSE_ERROR((status == 0), section_name,
1691 if (strcmp(ent->name, "dropless") == 0) {
1692 int status = parser_read_arg_bool(ent->value);
1694 PARSE_ERROR((status != -EINVAL), section_name,
1696 param->dropless = status;
1700 if (strcmp(ent->name, "n_retries") == 0) {
1701 int status = parser_read_uint64(¶m->n_retries,
1704 PARSE_ERROR((status == 0), section_name,
1709 if (strcmp(ent->name, "cpu") == 0) {
1710 int status = parser_read_uint32(
1711 ¶m->cpu_socket_id, ent->value);
1713 PARSE_ERROR((status == 0), section_name, ent->name);
1717 if (strcmp(ent->name, "ipv4_frag") == 0) {
1718 int status = parser_read_arg_bool(ent->value);
1720 PARSE_ERROR((status != -EINVAL), section_name,
1723 param->ipv4_frag = status;
1724 if (param->mtu == 0)
1730 if (strcmp(ent->name, "ipv6_frag") == 0) {
1731 int status = parser_read_arg_bool(ent->value);
1733 PARSE_ERROR((status != -EINVAL), section_name,
1735 param->ipv6_frag = status;
1736 if (param->mtu == 0)
1741 if (strcmp(ent->name, "ipv4_ras") == 0) {
1742 int status = parser_read_arg_bool(ent->value);
1744 PARSE_ERROR((status != -EINVAL), section_name,
1746 param->ipv4_ras = status;
1750 if (strcmp(ent->name, "ipv6_ras") == 0) {
1751 int status = parser_read_arg_bool(ent->value);
1753 PARSE_ERROR((status != -EINVAL), section_name,
1755 param->ipv6_ras = status;
1759 if (strcmp(ent->name, "mtu") == 0) {
1760 int status = parser_read_uint32(¶m->mtu,
1763 PARSE_ERROR((status == 0), section_name,
1769 if (strcmp(ent->name, "metadata_size") == 0) {
1770 int status = parser_read_uint32(
1771 ¶m->metadata_size, ent->value);
1773 PARSE_ERROR((status == 0), section_name,
1775 metadata_size_present = 1;
1779 if (strcmp(ent->name, "mempool_direct") == 0) {
1780 int status = validate_name(ent->value,
1784 PARSE_ERROR((status == 0), section_name,
1787 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1788 param->mempool_direct_id = idx;
1790 mempool_direct_present = 1;
1794 if (strcmp(ent->name, "mempool_indirect") == 0) {
1795 int status = validate_name(ent->value,
1799 PARSE_ERROR((status == 0), section_name,
1802 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1803 param->mempool_indirect_id = idx;
1805 mempool_indirect_present = 1;
1810 PARSE_ERROR_INVALID(0, section_name, ent->name);
1813 APP_CHECK(((mtu_present == 0) ||
1814 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1815 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1816 "is off, therefore entry \"mtu\" is not allowed",
1819 APP_CHECK(((metadata_size_present == 0) ||
1820 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1821 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1822 "is off, therefore entry \"metadata_size\" is "
1823 "not allowed", section_name);
1825 APP_CHECK(((mempool_direct_present == 0) ||
1826 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1827 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1828 "is off, therefore entry \"mempool_direct\" is "
1829 "not allowed", section_name);
1831 APP_CHECK(((mempool_indirect_present == 0) ||
1832 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1833 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1834 "is off, therefore entry \"mempool_indirect\" is "
1835 "not allowed", section_name);
1841 parse_tm(struct app_params *app,
1842 const char *section_name,
1843 struct rte_cfgfile *cfg)
1845 struct app_pktq_tm_params *param;
1846 struct rte_cfgfile_entry *entries;
1850 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1851 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1853 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1854 PARSE_ERROR_MALLOC(entries != NULL);
1856 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1858 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1859 param = &app->tm_params[param_idx];
1860 PARSE_CHECK_DUPLICATE_SECTION(param);
1862 APP_PARAM_ADD_LINK_FOR_TM(app, section_name);
1864 for (i = 0; i < n_entries; i++) {
1865 struct rte_cfgfile_entry *ent = &entries[i];
1867 if (strcmp(ent->name, "cfg") == 0) {
1868 param->file_name = strdup(ent->value);
1869 PARSE_ERROR_MALLOC(param->file_name != NULL);
1873 if (strcmp(ent->name, "burst_read") == 0) {
1874 int status = parser_read_uint32(
1875 ¶m->burst_read, ent->value);
1877 PARSE_ERROR((status == 0), section_name,
1882 if (strcmp(ent->name, "burst_write") == 0) {
1883 int status = parser_read_uint32(
1884 ¶m->burst_write, ent->value);
1886 PARSE_ERROR((status == 0), section_name,
1892 PARSE_ERROR_INVALID(0, section_name, ent->name);
1899 parse_kni(struct app_params *app,
1900 const char *section_name,
1901 struct rte_cfgfile *cfg)
1903 struct app_pktq_kni_params *param;
1904 struct rte_cfgfile_entry *entries;
1908 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1909 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1911 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1912 PARSE_ERROR_MALLOC(entries != NULL);
1914 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1916 param_idx = APP_PARAM_ADD(app->kni_params, section_name);
1917 param = &app->kni_params[param_idx];
1918 PARSE_CHECK_DUPLICATE_SECTION(param);
1920 APP_PARAM_ADD_LINK_FOR_KNI(app, section_name);
1922 for (i = 0; i < n_entries; i++) {
1923 struct rte_cfgfile_entry *ent = &entries[i];
1925 if (strcmp(ent->name, "core") == 0) {
1926 int status = parse_pipeline_core(
1929 ¶m->hyper_th_id,
1932 PARSE_ERROR((status == 0), section_name,
1934 param->force_bind = 1;
1938 if (strcmp(ent->name, "mempool") == 0) {
1939 int status = validate_name(ent->value,
1943 PARSE_ERROR((status == 0), section_name,
1946 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1947 param->mempool_id = idx;
1951 if (strcmp(ent->name, "burst_read") == 0) {
1952 int status = parser_read_uint32(¶m->burst_read,
1955 PARSE_ERROR((status == 0), section_name,
1960 if (strcmp(ent->name, "burst_write") == 0) {
1961 int status = parser_read_uint32(¶m->burst_write,
1964 PARSE_ERROR((status == 0), section_name,
1969 if (strcmp(ent->name, "dropless") == 0) {
1970 int status = parser_read_arg_bool(ent->value);
1972 PARSE_ERROR((status != -EINVAL), section_name,
1974 param->dropless = status;
1978 if (strcmp(ent->name, "n_retries") == 0) {
1979 int status = parser_read_uint64(¶m->n_retries,
1982 PARSE_ERROR((status == 0), section_name,
1988 PARSE_ERROR_INVALID(0, section_name, ent->name);
1995 parse_source(struct app_params *app,
1996 const char *section_name,
1997 struct rte_cfgfile *cfg)
1999 struct app_pktq_source_params *param;
2000 struct rte_cfgfile_entry *entries;
2003 uint32_t pcap_file_present = 0;
2004 uint32_t pcap_size_present = 0;
2006 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2007 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2009 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2010 PARSE_ERROR_MALLOC(entries != NULL);
2012 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2014 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2015 param = &app->source_params[param_idx];
2016 PARSE_CHECK_DUPLICATE_SECTION(param);
2018 for (i = 0; i < n_entries; i++) {
2019 struct rte_cfgfile_entry *ent = &entries[i];
2021 if (strcmp(ent->name, "mempool") == 0) {
2022 int status = validate_name(ent->value,
2026 PARSE_ERROR((status == 0), section_name,
2029 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
2030 param->mempool_id = idx;
2034 if (strcmp(ent->name, "burst") == 0) {
2035 int status = parser_read_uint32(¶m->burst,
2038 PARSE_ERROR((status == 0), section_name,
2043 if (strcmp(ent->name, "pcap_file_rd") == 0) {
2044 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2045 section_name, ent->name);
2047 param->file_name = strdup(ent->value);
2049 PARSE_ERROR_MALLOC(param->file_name != NULL);
2050 pcap_file_present = 1;
2055 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2058 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2059 section_name, ent->name);
2061 status = parser_read_uint32(
2062 ¶m->n_bytes_per_pkt, ent->value);
2064 PARSE_ERROR((status == 0), section_name,
2066 pcap_size_present = 1;
2072 PARSE_ERROR_INVALID(0, section_name, ent->name);
2079 parse_sink(struct app_params *app,
2080 const char *section_name,
2081 struct rte_cfgfile *cfg)
2083 struct app_pktq_sink_params *param;
2084 struct rte_cfgfile_entry *entries;
2087 uint32_t pcap_file_present = 0;
2088 uint32_t pcap_n_pkt_present = 0;
2090 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2091 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2093 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2094 PARSE_ERROR_MALLOC(entries != NULL);
2096 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2098 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2099 param = &app->sink_params[param_idx];
2100 PARSE_CHECK_DUPLICATE_SECTION(param);
2102 for (i = 0; i < n_entries; i++) {
2103 struct rte_cfgfile_entry *ent = &entries[i];
2105 if (strcmp(ent->name, "pcap_file_wr") == 0) {
2106 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2107 section_name, ent->name);
2109 param->file_name = strdup(ent->value);
2111 PARSE_ERROR_MALLOC((param->file_name != NULL));
2116 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
2119 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2120 section_name, ent->name);
2122 status = parser_read_uint32(
2123 ¶m->n_pkts_to_dump, ent->value);
2125 PARSE_ERROR((status == 0), section_name,
2132 PARSE_ERROR_INVALID(0, section_name, ent->name);
2139 parse_msgq_req_pipeline(struct app_params *app,
2140 const char *section_name,
2141 struct rte_cfgfile *cfg)
2143 struct app_msgq_params *param;
2144 struct rte_cfgfile_entry *entries;
2148 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2149 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2151 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2152 PARSE_ERROR_MALLOC(entries != NULL);
2154 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2156 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2157 param = &app->msgq_params[param_idx];
2158 PARSE_CHECK_DUPLICATE_SECTION(param);
2160 for (i = 0; i < n_entries; i++) {
2161 struct rte_cfgfile_entry *ent = &entries[i];
2163 if (strcmp(ent->name, "size") == 0) {
2164 int status = parser_read_uint32(¶m->size,
2167 PARSE_ERROR((status == 0), section_name,
2173 PARSE_ERROR_INVALID(0, section_name, ent->name);
2180 parse_msgq_rsp_pipeline(struct app_params *app,
2181 const char *section_name,
2182 struct rte_cfgfile *cfg)
2184 struct app_msgq_params *param;
2185 struct rte_cfgfile_entry *entries;
2189 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2190 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2192 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2193 PARSE_ERROR_MALLOC(entries != NULL);
2195 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2197 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2198 param = &app->msgq_params[param_idx];
2199 PARSE_CHECK_DUPLICATE_SECTION(param);
2201 for (i = 0; i < n_entries; i++) {
2202 struct rte_cfgfile_entry *ent = &entries[i];
2204 if (strcmp(ent->name, "size") == 0) {
2205 int status = parser_read_uint32(¶m->size,
2208 PARSE_ERROR((status == 0), section_name,
2214 PARSE_ERROR_INVALID(0, section_name, ent->name);
2221 parse_msgq(struct app_params *app,
2222 const char *section_name,
2223 struct rte_cfgfile *cfg)
2225 struct app_msgq_params *param;
2226 struct rte_cfgfile_entry *entries;
2230 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2231 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2233 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2234 PARSE_ERROR_MALLOC(entries != NULL);
2236 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2238 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2239 param = &app->msgq_params[param_idx];
2240 PARSE_CHECK_DUPLICATE_SECTION(param);
2242 for (i = 0; i < n_entries; i++) {
2243 struct rte_cfgfile_entry *ent = &entries[i];
2245 if (strcmp(ent->name, "size") == 0) {
2246 int status = parser_read_uint32(¶m->size,
2249 PARSE_ERROR((status == 0), section_name,
2254 if (strcmp(ent->name, "cpu") == 0) {
2255 int status = parser_read_uint32(
2256 ¶m->cpu_socket_id, ent->value);
2258 PARSE_ERROR((status == 0), section_name,
2264 PARSE_ERROR_INVALID(0, section_name, ent->name);
2270 typedef void (*config_section_load)(struct app_params *p,
2271 const char *section_name,
2272 struct rte_cfgfile *cfg);
2274 struct config_section {
2275 const char prefix[CFG_NAME_LEN];
2277 config_section_load load;
2280 static const struct config_section cfg_file_scheme[] = {
2281 {"EAL", 0, parse_eal},
2282 {"PIPELINE", 1, parse_pipeline},
2283 {"MEMPOOL", 1, parse_mempool},
2284 {"LINK", 1, parse_link},
2285 {"RXQ", 2, parse_rxq},
2286 {"TXQ", 2, parse_txq},
2287 {"SWQ", 1, parse_swq},
2288 {"TM", 1, parse_tm},
2289 {"KNI", 1, parse_kni},
2290 {"SOURCE", 1, parse_source},
2291 {"SINK", 1, parse_sink},
2292 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2293 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2294 {"MSGQ", 1, parse_msgq},
2298 create_implicit_mempools(struct app_params *app)
2300 APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2304 create_implicit_links_from_port_mask(struct app_params *app,
2307 uint32_t pmd_id, link_id;
2310 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2311 char name[APP_PARAM_NAME_SIZE];
2314 if ((port_mask & (1LLU << pmd_id)) == 0)
2317 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2318 idx = APP_PARAM_ADD(app->link_params, name);
2320 app->link_params[idx].pmd_id = pmd_id;
2326 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2330 for (i = 0; i < app->n_links; i++) {
2331 struct app_link_params *link = &app->link_params[i];
2333 APP_CHECK((strlen(link->pci_bdf)),
2334 "Parse error: %s pci_bdf is not configured "
2335 "(port_mask is not provided)",
2343 app_config_parse(struct app_params *app, const char *file_name)
2345 struct rte_cfgfile *cfg;
2346 char **section_names;
2347 int i, j, sect_count;
2349 /* Implicit mempools */
2350 create_implicit_mempools(app);
2354 create_implicit_links_from_port_mask(app, app->port_mask);
2356 /* Load application configuration file */
2357 cfg = rte_cfgfile_load(file_name, 0);
2358 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2359 "file %s", file_name);
2361 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2362 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2363 "in file \"%s\" return %d", file_name,
2366 section_names = malloc(sect_count * sizeof(char *));
2367 PARSE_ERROR_MALLOC(section_names != NULL);
2369 for (i = 0; i < sect_count; i++)
2370 section_names[i] = malloc(CFG_NAME_LEN);
2372 rte_cfgfile_sections(cfg, section_names, sect_count);
2374 for (i = 0; i < sect_count; i++) {
2375 const struct config_section *sch_s;
2376 int len, cfg_name_len;
2378 cfg_name_len = strlen(section_names[i]);
2380 /* Find section type */
2381 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2382 sch_s = &cfg_file_scheme[j];
2383 len = strlen(sch_s->prefix);
2385 if (cfg_name_len < len)
2388 /* After section name we expect only '\0' or digit or
2389 * digit dot digit, so protect against false matching,
2390 * for example: "ABC" should match section name
2391 * "ABC0.0", but it should not match section_name
2394 if ((section_names[i][len] != '\0') &&
2395 !isdigit(section_names[i][len]))
2398 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2402 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2403 "Parse error: unknown section %s",
2406 APP_CHECK(validate_name(section_names[i],
2408 sch_s->numbers) == 0,
2409 "Parse error: invalid section name \"%s\"",
2412 sch_s->load(app, section_names[i], cfg);
2415 for (i = 0; i < sect_count; i++)
2416 free(section_names[i]);
2418 free(section_names);
2420 rte_cfgfile_close(cfg);
2422 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2423 APP_PARAM_COUNT(app->link_params, app->n_links);
2424 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2425 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2426 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2427 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2428 APP_PARAM_COUNT(app->kni_params, app->n_pktq_kni);
2429 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2430 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2431 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2432 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2434 if (app->port_mask == 0)
2435 assign_link_pmd_id_from_pci_bdf(app);
2437 /* Save configuration to output file */
2438 app_config_save(app, app->output_file);
2440 /* Load TM configuration files */
2441 app_config_parse_tm(app);
2447 save_eal_params(struct app_params *app, FILE *f)
2449 struct app_eal_params *p = &app->eal_params;
2452 fprintf(f, "[EAL]\n");
2455 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2457 if (p->master_lcore_present)
2458 fprintf(f, "%s = %" PRIu32 "\n",
2459 "master_lcore", p->master_lcore);
2461 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2463 if (p->memory_present)
2464 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2466 if (p->ranks_present)
2467 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2469 for (i = 0; i < APP_MAX_LINKS; i++) {
2470 if (p->pci_blacklist[i] == NULL)
2473 fprintf(f, "%s = %s\n", "pci_blacklist",
2474 p->pci_blacklist[i]);
2477 for (i = 0; i < APP_MAX_LINKS; i++) {
2478 if (p->pci_whitelist[i] == NULL)
2481 fprintf(f, "%s = %s\n", "pci_whitelist",
2482 p->pci_whitelist[i]);
2485 for (i = 0; i < APP_MAX_LINKS; i++) {
2486 if (p->vdev[i] == NULL)
2489 fprintf(f, "%s = %s\n", "vdev",
2493 if (p->vmware_tsc_map_present)
2494 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2495 (p->vmware_tsc_map) ? "yes" : "no");
2498 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2501 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2503 if (p->log_level_present)
2504 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2506 if (p->version_present)
2507 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2509 if (p->help_present)
2510 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2512 if (p->no_huge_present)
2513 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2515 if (p->no_pci_present)
2516 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2518 if (p->no_hpet_present)
2519 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2521 if (p->no_shconf_present)
2522 fprintf(f, "%s = %s\n", "no_shconf",
2523 (p->no_shconf) ? "yes" : "no");
2526 fprintf(f, "%s = %s\n", "d", p->add_driver);
2529 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2532 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2535 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2537 if (p->base_virtaddr)
2538 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2540 if (p->create_uio_dev_present)
2541 fprintf(f, "%s = %s\n", "create_uio_dev",
2542 (p->create_uio_dev) ? "yes" : "no");
2545 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2547 if (p->xen_dom0_present)
2548 fprintf(f, "%s = %s\n", "xen_dom0",
2549 (p->xen_dom0) ? "yes" : "no");
2555 save_mempool_params(struct app_params *app, FILE *f)
2557 struct app_mempool_params *p;
2560 count = RTE_DIM(app->mempool_params);
2561 for (i = 0; i < count; i++) {
2562 p = &app->mempool_params[i];
2563 if (!APP_PARAM_VALID(p))
2566 fprintf(f, "[%s]\n", p->name);
2567 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2568 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2569 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2570 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2577 save_links_params(struct app_params *app, FILE *f)
2579 struct app_link_params *p;
2582 count = RTE_DIM(app->link_params);
2583 for (i = 0; i < count; i++) {
2584 p = &app->link_params[i];
2585 if (!APP_PARAM_VALID(p))
2588 fprintf(f, "[%s]\n", p->name);
2589 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2590 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2591 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2592 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2594 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2595 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2596 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2597 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2604 fprintf(f, "rss_qs = ");
2605 for (j = 0; j < p->n_rss_qs; j++)
2606 fprintf(f, "%" PRIu32 " ", p->rss_qs[j]);
2609 /* rss_proto_ipv4 */
2610 if (p->rss_proto_ipv4) {
2611 fprintf(f, "rss_proto_ipv4 = ");
2612 if (p->rss_proto_ipv4 & ETH_RSS_IPV4)
2614 if (p->rss_proto_ipv4 & ETH_RSS_FRAG_IPV4)
2615 fprintf(f, "FRAG ");
2616 if (p->rss_proto_ipv4 &
2617 ETH_RSS_NONFRAG_IPV4_TCP)
2619 if (p->rss_proto_ipv4 &
2620 ETH_RSS_NONFRAG_IPV4_UDP)
2622 if (p->rss_proto_ipv4 &
2623 ETH_RSS_NONFRAG_IPV4_SCTP)
2624 fprintf(f, "SCTP ");
2625 if (p->rss_proto_ipv4 &
2626 ETH_RSS_NONFRAG_IPV4_OTHER)
2627 fprintf(f, "OTHER ");
2630 fprintf(f, "; rss_proto_ipv4 = <NONE>\n");
2632 /* rss_proto_ipv6 */
2633 if (p->rss_proto_ipv6) {
2634 fprintf(f, "rss_proto_ipv6 = ");
2635 if (p->rss_proto_ipv6 & ETH_RSS_IPV6)
2637 if (p->rss_proto_ipv6 & ETH_RSS_FRAG_IPV6)
2638 fprintf(f, "FRAG ");
2639 if (p->rss_proto_ipv6 &
2640 ETH_RSS_NONFRAG_IPV6_TCP)
2642 if (p->rss_proto_ipv6 &
2643 ETH_RSS_NONFRAG_IPV6_UDP)
2645 if (p->rss_proto_ipv6 &
2646 ETH_RSS_NONFRAG_IPV6_SCTP)
2647 fprintf(f, "SCTP ");
2648 if (p->rss_proto_ipv6 &
2649 ETH_RSS_NONFRAG_IPV6_OTHER)
2650 fprintf(f, "OTHER ");
2651 if (p->rss_proto_ipv6 & ETH_RSS_IPV6_EX)
2652 fprintf(f, "IP_EX ");
2653 if (p->rss_proto_ipv6 &
2654 ETH_RSS_IPV6_TCP_EX)
2655 fprintf(f, "TCP_EX ");
2656 if (p->rss_proto_ipv6 &
2657 ETH_RSS_IPV6_UDP_EX)
2658 fprintf(f, "UDP_EX ");
2661 fprintf(f, "; rss_proto_ipv6 = <NONE>\n");
2664 if (p->rss_proto_l2) {
2665 fprintf(f, "rss_proto_l2 = ");
2666 if (p->rss_proto_l2 & ETH_RSS_L2_PAYLOAD)
2670 fprintf(f, "; rss_proto_l2 = <NONE>\n");
2672 fprintf(f, "; rss_qs = <NONE>\n");
2673 fprintf(f, "; rss_proto_ipv4 = <NONE>\n");
2674 fprintf(f, "; rss_proto_ipv6 = <NONE>\n");
2675 fprintf(f, "; rss_proto_l2 = <NONE>\n");
2678 if (strlen(p->pci_bdf))
2679 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2686 save_rxq_params(struct app_params *app, FILE *f)
2688 struct app_pktq_hwq_in_params *p;
2691 count = RTE_DIM(app->hwq_in_params);
2692 for (i = 0; i < count; i++) {
2693 p = &app->hwq_in_params[i];
2694 if (!APP_PARAM_VALID(p))
2697 fprintf(f, "[%s]\n", p->name);
2698 fprintf(f, "%s = %s\n",
2700 app->mempool_params[p->mempool_id].name);
2701 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2702 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2709 save_txq_params(struct app_params *app, FILE *f)
2711 struct app_pktq_hwq_out_params *p;
2714 count = RTE_DIM(app->hwq_out_params);
2715 for (i = 0; i < count; i++) {
2716 p = &app->hwq_out_params[i];
2717 if (!APP_PARAM_VALID(p))
2720 fprintf(f, "[%s]\n", p->name);
2721 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2722 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2723 fprintf(f, "%s = %s\n",
2725 p->dropless ? "yes" : "no");
2726 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2733 save_swq_params(struct app_params *app, FILE *f)
2735 struct app_pktq_swq_params *p;
2738 count = RTE_DIM(app->swq_params);
2739 for (i = 0; i < count; i++) {
2740 p = &app->swq_params[i];
2741 if (!APP_PARAM_VALID(p))
2744 fprintf(f, "[%s]\n", p->name);
2745 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2746 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2747 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2748 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2749 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2750 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2751 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2752 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2753 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2754 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2755 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2756 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2757 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2758 fprintf(f, "%s = %s\n",
2760 app->mempool_params[p->mempool_direct_id].name);
2761 fprintf(f, "%s = %s\n",
2763 app->mempool_params[p->mempool_indirect_id].name);
2771 save_tm_params(struct app_params *app, FILE *f)
2773 struct app_pktq_tm_params *p;
2776 count = RTE_DIM(app->tm_params);
2777 for (i = 0; i < count; i++) {
2778 p = &app->tm_params[i];
2779 if (!APP_PARAM_VALID(p))
2782 fprintf(f, "[%s]\n", p->name);
2783 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2784 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2785 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2792 save_kni_params(struct app_params *app, FILE *f)
2794 struct app_pktq_kni_params *p;
2797 count = RTE_DIM(app->kni_params);
2798 for (i = 0; i < count; i++) {
2799 p = &app->kni_params[i];
2800 if (!APP_PARAM_VALID(p))
2804 fprintf(f, "[%s]\n", p->name);
2807 if (p->force_bind) {
2808 fprintf(f, "; force_bind = 1\n");
2809 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2812 (p->hyper_th_id) ? "h" : "");
2814 fprintf(f, "; force_bind = 0\n");
2817 fprintf(f, "%s = %s\n", "mempool",
2818 app->mempool_params[p->mempool_id].name);
2821 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2824 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2827 fprintf(f, "%s = %s\n",
2829 p->dropless ? "yes" : "no");
2832 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2839 save_source_params(struct app_params *app, FILE *f)
2841 struct app_pktq_source_params *p;
2844 count = RTE_DIM(app->source_params);
2845 for (i = 0; i < count; i++) {
2846 p = &app->source_params[i];
2847 if (!APP_PARAM_VALID(p))
2850 fprintf(f, "[%s]\n", p->name);
2851 fprintf(f, "%s = %s\n",
2853 app->mempool_params[p->mempool_id].name);
2854 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2855 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2856 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2857 p->n_bytes_per_pkt);
2863 save_sink_params(struct app_params *app, FILE *f)
2865 struct app_pktq_sink_params *p;
2868 count = RTE_DIM(app->sink_params);
2869 for (i = 0; i < count; i++) {
2870 p = &app->sink_params[i];
2871 if (!APP_PARAM_VALID(p))
2874 fprintf(f, "[%s]\n", p->name);
2875 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2876 fprintf(f, "%s = %" PRIu32 "\n",
2877 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2883 save_msgq_params(struct app_params *app, FILE *f)
2885 struct app_msgq_params *p;
2888 count = RTE_DIM(app->msgq_params);
2889 for (i = 0; i < count; i++) {
2890 p = &app->msgq_params[i];
2891 if (!APP_PARAM_VALID(p))
2894 fprintf(f, "[%s]\n", p->name);
2895 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2896 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2903 save_pipeline_params(struct app_params *app, FILE *f)
2907 count = RTE_DIM(app->pipeline_params);
2908 for (i = 0; i < count; i++) {
2909 struct app_pipeline_params *p = &app->pipeline_params[i];
2911 if (!APP_PARAM_VALID(p))
2915 fprintf(f, "[%s]\n", p->name);
2918 fprintf(f, "type = %s\n", p->type);
2921 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2924 (p->hyper_th_id) ? "h" : "");
2930 fprintf(f, "pktq_in =");
2931 for (j = 0; j < p->n_pktq_in; j++) {
2932 struct app_pktq_in_params *pp = &p->pktq_in[j];
2936 case APP_PKTQ_IN_HWQ:
2937 name = app->hwq_in_params[pp->id].name;
2939 case APP_PKTQ_IN_SWQ:
2940 name = app->swq_params[pp->id].name;
2942 case APP_PKTQ_IN_TM:
2943 name = app->tm_params[pp->id].name;
2945 case APP_PKTQ_IN_KNI:
2946 name = app->kni_params[pp->id].name;
2948 case APP_PKTQ_IN_SOURCE:
2949 name = app->source_params[pp->id].name;
2952 APP_CHECK(0, "System error "
2953 "occurred while saving "
2954 "parameter to file");
2957 fprintf(f, " %s", name);
2963 if (p->n_pktq_out) {
2966 fprintf(f, "pktq_out =");
2967 for (j = 0; j < p->n_pktq_out; j++) {
2968 struct app_pktq_out_params *pp =
2973 case APP_PKTQ_OUT_HWQ:
2974 name = app->hwq_out_params[pp->id].name;
2976 case APP_PKTQ_OUT_SWQ:
2977 name = app->swq_params[pp->id].name;
2979 case APP_PKTQ_OUT_TM:
2980 name = app->tm_params[pp->id].name;
2982 case APP_PKTQ_OUT_KNI:
2983 name = app->kni_params[pp->id].name;
2985 case APP_PKTQ_OUT_SINK:
2986 name = app->sink_params[pp->id].name;
2989 APP_CHECK(0, "System error "
2990 "occurred while saving "
2991 "parameter to file");
2994 fprintf(f, " %s", name);
3003 fprintf(f, "msgq_in =");
3004 for (j = 0; j < p->n_msgq_in; j++) {
3005 uint32_t id = p->msgq_in[j];
3006 char *name = app->msgq_params[id].name;
3008 fprintf(f, " %s", name);
3014 if (p->n_msgq_out) {
3017 fprintf(f, "msgq_out =");
3018 for (j = 0; j < p->n_msgq_out; j++) {
3019 uint32_t id = p->msgq_out[j];
3020 char *name = app->msgq_params[id].name;
3022 fprintf(f, " %s", name);
3028 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3034 for (j = 0; j < p->n_args; j++)
3035 fprintf(f, "%s = %s\n", p->args_name[j],
3044 app_config_save(struct app_params *app, const char *file_name)
3047 char *name, *dir_name;
3050 name = strdup(file_name);
3051 dir_name = dirname(name);
3052 status = access(dir_name, W_OK);
3053 APP_CHECK((status == 0),
3054 "Error: need write access privilege to directory "
3055 "\"%s\" to save configuration\n", dir_name);
3057 file = fopen(file_name, "w");
3058 APP_CHECK((file != NULL),
3059 "Error: failed to save configuration to file \"%s\"",
3062 save_eal_params(app, file);
3063 save_pipeline_params(app, file);
3064 save_mempool_params(app, file);
3065 save_links_params(app, file);
3066 save_rxq_params(app, file);
3067 save_txq_params(app, file);
3068 save_swq_params(app, file);
3069 save_tm_params(app, file);
3070 save_kni_params(app, file);
3071 save_source_params(app, file);
3072 save_sink_params(app, file);
3073 save_msgq_params(app, file);
3080 app_config_init(struct app_params *app)
3084 memcpy(app, &app_params_default, sizeof(struct app_params));
3086 /* configure default_source_params */
3087 default_source_params.file_name = strdup("./config/packets.pcap");
3088 PARSE_ERROR_MALLOC(default_source_params.file_name != NULL);
3090 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3091 memcpy(&app->mempool_params[i],
3092 &mempool_params_default,
3093 sizeof(struct app_mempool_params));
3095 for (i = 0; i < RTE_DIM(app->link_params); i++)
3096 memcpy(&app->link_params[i],
3097 &link_params_default,
3098 sizeof(struct app_link_params));
3100 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3101 memcpy(&app->hwq_in_params[i],
3102 &default_hwq_in_params,
3103 sizeof(default_hwq_in_params));
3105 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3106 memcpy(&app->hwq_out_params[i],
3107 &default_hwq_out_params,
3108 sizeof(default_hwq_out_params));
3110 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3111 memcpy(&app->swq_params[i],
3112 &default_swq_params,
3113 sizeof(default_swq_params));
3115 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3116 memcpy(&app->tm_params[i],
3118 sizeof(default_tm_params));
3120 for (i = 0; i < RTE_DIM(app->kni_params); i++)
3121 memcpy(&app->kni_params[i],
3122 &default_kni_params,
3123 sizeof(default_kni_params));
3125 for (i = 0; i < RTE_DIM(app->source_params); i++)
3126 memcpy(&app->source_params[i],
3127 &default_source_params,
3128 sizeof(default_source_params));
3130 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3131 memcpy(&app->sink_params[i],
3132 &default_sink_params,
3133 sizeof(default_sink_params));
3135 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3136 memcpy(&app->msgq_params[i],
3137 &default_msgq_params,
3138 sizeof(default_msgq_params));
3140 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3141 memcpy(&app->pipeline_params[i],
3142 &default_pipeline_params,
3143 sizeof(default_pipeline_params));
3149 filenamedup(const char *filename, const char *suffix)
3151 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3156 sprintf(s, "%s%s", filename, suffix);
3161 app_config_args(struct app_params *app, int argc, char **argv)
3163 const char *optname;
3164 int opt, option_index;
3165 int f_present, s_present, p_present, l_present;
3166 int preproc_present, preproc_params_present;
3169 static struct option lgopts[] = {
3170 { "preproc", 1, 0, 0 },
3171 { "preproc-args", 1, 0, 0 },
3175 /* Copy application name */
3176 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3182 preproc_present = 0;
3183 preproc_params_present = 0;
3185 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3186 &option_index)) != EOF)
3190 rte_panic("Error: Config file is provided "
3191 "more than once\n");
3194 if (!strlen(optarg))
3195 rte_panic("Error: Config file name is null\n");
3197 app->config_file = strdup(optarg);
3198 if (app->config_file == NULL)
3199 rte_panic("Error: Memory allocation failure\n");
3205 rte_panic("Error: Script file is provided "
3206 "more than once\n");
3209 if (!strlen(optarg))
3210 rte_panic("Error: Script file name is null\n");
3212 app->script_file = strdup(optarg);
3213 if (app->script_file == NULL)
3214 rte_panic("Error: Memory allocation failure\n");
3220 rte_panic("Error: PORT_MASK is provided "
3221 "more than once\n");
3224 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3226 ((size_t) scaned != strlen(optarg)))
3227 rte_panic("Error: PORT_MASK is not "
3228 "a hexadecimal integer\n");
3230 if (app->port_mask == 0)
3231 rte_panic("Error: PORT_MASK is null\n");
3237 rte_panic("Error: LOG_LEVEL is provided "
3238 "more than once\n");
3241 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3243 ((size_t) scaned != strlen(optarg)) ||
3244 (app->log_level >= APP_LOG_LEVELS))
3245 rte_panic("Error: LOG_LEVEL invalid value\n");
3250 optname = lgopts[option_index].name;
3252 if (strcmp(optname, "preproc") == 0) {
3253 if (preproc_present)
3254 rte_panic("Error: Preprocessor argument "
3255 "is provided more than once\n");
3256 preproc_present = 1;
3258 app->preproc = strdup(optarg);
3262 if (strcmp(optname, "preproc-args") == 0) {
3263 if (preproc_params_present)
3264 rte_panic("Error: Preprocessor args "
3265 "are provided more than once\n");
3266 preproc_params_present = 1;
3268 app->preproc_args = strdup(optarg);
3272 app_print_usage(argv[0]);
3276 app_print_usage(argv[0]);
3279 optind = 0; /* reset getopt lib */
3281 /* Check dependencies between args */
3282 if (preproc_params_present && (preproc_present == 0))
3283 rte_panic("Error: Preprocessor args specified while "
3284 "preprocessor is not defined\n");
3286 app->parser_file = preproc_present ?
3287 filenamedup(app->config_file, ".preproc") :
3288 strdup(app->config_file);
3289 app->output_file = filenamedup(app->config_file, ".out");
3295 app_config_preproc(struct app_params *app)
3300 if (app->preproc == NULL)
3303 status = access(app->config_file, F_OK | R_OK);
3304 APP_CHECK((status == 0), "Error: Unable to open file %s",
3307 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3309 app->preproc_args ? app->preproc_args : "",
3313 status = system(buffer);
3314 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3315 "Error occurred while pre-processing file \"%s\"\n",