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_source_params default_source_params = {
197 .n_bytes_per_pkt = 0,
200 struct app_pktq_sink_params default_sink_params = {
206 struct app_msgq_params default_msgq_params = {
212 struct app_pipeline_params default_pipeline_params = {
225 static const char app_usage[] =
226 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
227 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
230 "\t-f CONFIG_FILE: Default config file is %s\n"
231 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
232 "config file when not provided)\n"
233 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
234 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
235 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
236 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
240 app_print_usage(char *prgname)
242 rte_exit(0, app_usage, prgname, app_params_default.config_file);
245 #define APP_PARAM_ADD(set, key) \
247 ssize_t pos = APP_PARAM_FIND(set, key); \
248 ssize_t size = RTE_DIM(set); \
251 for (pos = 0; pos < size; pos++) { \
252 if (!APP_PARAM_VALID(&((set)[pos]))) \
256 APP_CHECK((pos < size), \
257 "Parse error: size of %s is limited to %u elements",\
258 #set, (uint32_t) size); \
260 (set)[pos].name = strdup(key); \
261 APP_CHECK(((set)[pos].name), \
262 "Parse error: no free memory"); \
267 #define APP_PARAM_ADD_LINK_FOR_RXQ(app, rxq_name) \
269 char link_name[APP_PARAM_NAME_SIZE]; \
270 ssize_t link_param_pos; \
271 uint32_t link_id, queue_id; \
273 sscanf((rxq_name), "RXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
274 sprintf(link_name, "LINK%" PRIu32, link_id); \
275 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
279 #define APP_PARAM_ADD_LINK_FOR_TXQ(app, txq_name) \
281 char link_name[APP_PARAM_NAME_SIZE]; \
282 ssize_t link_param_pos; \
283 uint32_t link_id, queue_id; \
285 sscanf((txq_name), "TXQ%" SCNu32 ".%" SCNu32, &link_id, &queue_id);\
286 sprintf(link_name, "LINK%" PRIu32, link_id); \
287 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
291 #define APP_PARAM_ADD_LINK_FOR_TM(app, tm_name) \
293 char link_name[APP_PARAM_NAME_SIZE]; \
294 ssize_t link_param_pos; \
297 sscanf((tm_name), "TM%" SCNu32, &link_id); \
298 sprintf(link_name, "LINK%" PRIu32, link_id); \
299 link_param_pos = APP_PARAM_ADD((app)->link_params, link_name); \
303 #define PARSE_CHECK_DUPLICATE_SECTION(obj) \
305 APP_CHECK(((obj)->parsed == 0), \
306 "Parse error: duplicate \"%s\" section", (obj)->name); \
310 #define PARSE_CHECK_DUPLICATE_SECTION_EAL(obj) \
312 APP_CHECK(((obj)->parsed == 0), \
313 "Parse error: duplicate \"%s\" section", "EAL"); \
317 #define PARSE_ERROR(exp, section, entry) \
318 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"", section, entry)
320 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
321 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s", \
322 section, entry, message)
324 #define PARSE_ERROR_NO_ELEMENTS(exp, section, entry) \
325 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
326 "no elements detected", \
329 #define PARSE_ERROR_TOO_MANY_ELEMENTS(exp, section, entry, max) \
330 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
331 "maximum number of elements allowed is %u", \
334 #define PARSE_ERROR_INVALID_ELEMENT(exp, section, entry, value) \
335 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": " \
336 "Invalid element value \"%s\"", \
337 section, entry, value)
339 #define PARSE_ERROR_MALLOC(exp) \
340 APP_CHECK(exp, "Parse error: no free memory")
342 #define PARSE_ERROR_SECTION(exp, section) \
343 APP_CHECK(exp, "Parse error in section \"%s\"", section)
345 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
346 APP_CHECK(exp, "Parse error in section \"%s\": no entries", section)
348 #define PARSE_WARNING_IGNORED(exp, section, entry) \
351 fprintf(stderr, "Parse warning in section \"%s\": " \
352 "entry \"%s\" is ignored", section, entry); \
355 #define PARSE_ERROR_INVALID(exp, section, entry) \
356 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"",\
359 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
360 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"", \
364 validate_name(const char *name, const char *prefix, int num)
368 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
369 if (name[i] != prefix[i])
373 if (prefix[i] != '\0')
384 j = skip_digits(&name[i]);
386 if ((j == 0) || (name[i] != '.'))
392 j = skip_digits(&name[i]);
394 if ((j == 0) || (name[i] != '\0'))
402 parse_eal(struct app_params *app,
403 const char *section_name,
404 struct rte_cfgfile *cfg)
406 struct app_eal_params *p = &app->eal_params;
407 struct rte_cfgfile_entry *entries;
410 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
411 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
413 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
414 PARSE_ERROR_MALLOC(entries != NULL);
416 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
418 PARSE_CHECK_DUPLICATE_SECTION_EAL(p);
420 for (i = 0; i < n_entries; i++) {
421 struct rte_cfgfile_entry *entry = &entries[i];
424 if (strcmp(entry->name, "c") == 0) {
425 PARSE_WARNING_IGNORED(0, section_name, entry->name);
430 if (strcmp(entry->name, "l") == 0) {
431 PARSE_WARNING_IGNORED(0, section_name, entry->name);
436 if (strcmp(entry->name, "lcores") == 0) {
437 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
440 p->coremap = strdup(entry->value);
445 if (strcmp(entry->name, "master_lcore") == 0) {
448 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
451 p->master_lcore_present = 1;
453 status = parser_read_uint32(&p->master_lcore,
455 PARSE_ERROR((status == 0), section_name, entry->name);
460 if (strcmp(entry->name, "n") == 0) {
463 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
466 p->channels_present = 1;
468 status = parser_read_uint32(&p->channels, entry->value);
469 PARSE_ERROR((status == 0), section_name, entry->name);
474 if (strcmp(entry->name, "m") == 0) {
477 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
480 p->memory_present = 1;
482 status = parser_read_uint32(&p->memory, entry->value);
483 PARSE_ERROR((status == 0), section_name, entry->name);
488 if (strcmp(entry->name, "r") == 0) {
491 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
494 p->ranks_present = 1;
496 status = parser_read_uint32(&p->ranks, entry->value);
497 PARSE_ERROR((status == 0), section_name, entry->name);
502 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
503 (strcmp(entry->name, "b") == 0)) {
506 for (i = 0; i < APP_MAX_LINKS; i++) {
507 if (p->pci_blacklist[i])
510 p->pci_blacklist[i] =
511 strdup(entry->value);
512 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
517 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
518 section_name, entry->name,
519 "too many elements");
524 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
525 (strcmp(entry->name, "w") == 0)) {
528 PARSE_ERROR_MESSAGE((app->port_mask != 0),
529 section_name, entry->name, "entry to be "
530 "generated by the application (port_mask "
533 for (i = 0; i < APP_MAX_LINKS; i++) {
534 if (p->pci_whitelist[i])
537 p->pci_whitelist[i] = strdup(entry->value);
538 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
543 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
544 section_name, entry->name,
545 "too many elements");
550 if (strcmp(entry->name, "vdev") == 0) {
553 for (i = 0; i < APP_MAX_LINKS; i++) {
557 p->vdev[i] = strdup(entry->value);
558 PARSE_ERROR_MALLOC(p->vdev[i]);
563 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
564 section_name, entry->name,
565 "too many elements");
570 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
573 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
576 p->vmware_tsc_map_present = 1;
578 val = parser_read_arg_bool(entry->value);
579 PARSE_ERROR((val >= 0), section_name, entry->name);
580 p->vmware_tsc_map = val;
585 if (strcmp(entry->name, "proc_type") == 0) {
586 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
589 p->proc_type = strdup(entry->value);
594 if (strcmp(entry->name, "syslog") == 0) {
595 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
598 p->syslog = strdup(entry->value);
603 if (strcmp(entry->name, "log_level") == 0) {
606 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
609 p->log_level_present = 1;
611 status = parser_read_uint32(&p->log_level,
613 PARSE_ERROR((status == 0), section_name, entry->name);
618 if (strcmp(entry->name, "v") == 0) {
621 PARSE_ERROR_DUPLICATE((p->version_present == 0),
624 p->version_present = 1;
626 val = parser_read_arg_bool(entry->value);
627 PARSE_ERROR((val >= 0), section_name, entry->name);
633 if ((strcmp(entry->name, "help") == 0) ||
634 (strcmp(entry->name, "h") == 0)) {
637 PARSE_ERROR_DUPLICATE((p->help_present == 0),
642 val = parser_read_arg_bool(entry->value);
643 PARSE_ERROR((val >= 0), section_name, entry->name);
649 if (strcmp(entry->name, "no_huge") == 0) {
652 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
655 p->no_huge_present = 1;
657 val = parser_read_arg_bool(entry->value);
658 PARSE_ERROR((val >= 0), section_name, entry->name);
664 if (strcmp(entry->name, "no_pci") == 0) {
667 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
670 p->no_pci_present = 1;
672 val = parser_read_arg_bool(entry->value);
673 PARSE_ERROR((val >= 0), section_name, entry->name);
679 if (strcmp(entry->name, "no_hpet") == 0) {
682 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
685 p->no_hpet_present = 1;
687 val = parser_read_arg_bool(entry->value);
688 PARSE_ERROR((val >= 0), section_name, entry->name);
694 if (strcmp(entry->name, "no_shconf") == 0) {
697 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
700 p->no_shconf_present = 1;
702 val = parser_read_arg_bool(entry->value);
703 PARSE_ERROR((val >= 0), section_name, entry->name);
709 if (strcmp(entry->name, "d") == 0) {
710 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
713 p->add_driver = strdup(entry->value);
718 if (strcmp(entry->name, "socket_mem") == 0) {
719 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
722 p->socket_mem = strdup(entry->value);
727 if (strcmp(entry->name, "huge_dir") == 0) {
728 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
731 p->huge_dir = strdup(entry->value);
736 if (strcmp(entry->name, "file_prefix") == 0) {
737 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
740 p->file_prefix = strdup(entry->value);
745 if (strcmp(entry->name, "base_virtaddr") == 0) {
746 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
749 p->base_virtaddr = strdup(entry->value);
754 if (strcmp(entry->name, "create_uio_dev") == 0) {
757 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
760 p->create_uio_dev_present = 1;
762 val = parser_read_arg_bool(entry->value);
763 PARSE_ERROR((val >= 0), section_name, entry->name);
764 p->create_uio_dev = val;
769 if (strcmp(entry->name, "vfio_intr") == 0) {
770 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
773 p->vfio_intr = strdup(entry->value);
778 if (strcmp(entry->name, "xen_dom0") == 0) {
781 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
784 p->xen_dom0_present = 1;
786 val = parser_read_arg_bool(entry->value);
787 PARSE_ERROR((val >= 0), section_name, entry->name);
793 PARSE_ERROR_INVALID(0, section_name, entry->name);
800 parse_pipeline_pktq_in(struct app_params *app,
801 struct app_pipeline_params *p,
807 enum app_pktq_in_type type;
809 char *name = strtok_r(value, PARSE_DELIMITER, &value);
814 PARSE_ERROR_TOO_MANY_ELEMENTS(
815 (p->n_pktq_in < RTE_DIM(p->pktq_in)),
816 p->name, "pktq_in", (uint32_t)RTE_DIM(p->pktq_in));
818 if (validate_name(name, "RXQ", 2) == 0) {
819 type = APP_PKTQ_IN_HWQ;
820 id = APP_PARAM_ADD(app->hwq_in_params, name);
821 APP_PARAM_ADD_LINK_FOR_RXQ(app, name);
822 } else if (validate_name(name, "SWQ", 1) == 0) {
823 type = APP_PKTQ_IN_SWQ;
824 id = APP_PARAM_ADD(app->swq_params, name);
825 } else if (validate_name(name, "TM", 1) == 0) {
826 type = APP_PKTQ_IN_TM;
827 id = APP_PARAM_ADD(app->tm_params, name);
828 APP_PARAM_ADD_LINK_FOR_TM(app, name);
829 } else if (validate_name(name, "SOURCE", 1) == 0) {
830 type = APP_PKTQ_IN_SOURCE;
831 id = APP_PARAM_ADD(app->source_params, name);
833 PARSE_ERROR_INVALID_ELEMENT(0,
834 p->name, "pktq_in", name);
836 p->pktq_in[p->n_pktq_in].type = type;
837 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
841 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_in > 0), p->name, "pktq_in");
845 parse_pipeline_pktq_out(struct app_params *app,
846 struct app_pipeline_params *p,
852 enum app_pktq_out_type type;
854 char *name = strtok_r(value, PARSE_DELIMITER, &value);
859 PARSE_ERROR_TOO_MANY_ELEMENTS(
860 (p->n_pktq_out < RTE_DIM(p->pktq_out)),
861 p->name, "pktq_out", (uint32_t)RTE_DIM(p->pktq_out));
863 if (validate_name(name, "TXQ", 2) == 0) {
864 type = APP_PKTQ_OUT_HWQ;
865 id = APP_PARAM_ADD(app->hwq_out_params, name);
866 APP_PARAM_ADD_LINK_FOR_TXQ(app, name);
867 } else if (validate_name(name, "SWQ", 1) == 0) {
868 type = APP_PKTQ_OUT_SWQ;
869 id = APP_PARAM_ADD(app->swq_params, name);
870 } else if (validate_name(name, "TM", 1) == 0) {
871 type = APP_PKTQ_OUT_TM;
872 id = APP_PARAM_ADD(app->tm_params, name);
873 APP_PARAM_ADD_LINK_FOR_TM(app, name);
874 } else if (validate_name(name, "SINK", 1) == 0) {
875 type = APP_PKTQ_OUT_SINK;
876 id = APP_PARAM_ADD(app->sink_params, name);
878 PARSE_ERROR_INVALID_ELEMENT(0,
879 p->name, "pktq_out", name);
881 p->pktq_out[p->n_pktq_out].type = type;
882 p->pktq_out[p->n_pktq_out].id = id;
886 PARSE_ERROR_NO_ELEMENTS((p->n_pktq_out > 0), p->name, "pktq_out");
890 parse_pipeline_msgq_in(struct app_params *app,
891 struct app_pipeline_params *p,
898 char *name = strtok_r(value, PARSE_DELIMITER, &value);
903 PARSE_ERROR_TOO_MANY_ELEMENTS(
904 (p->n_msgq_in < RTE_DIM(p->msgq_in)),
905 p->name, "msgq_in", (uint32_t)(RTE_DIM(p->msgq_in)));
907 PARSE_ERROR_INVALID_ELEMENT(
908 (validate_name(name, "MSGQ", 1) == 0),
909 p->name, "msgq_in", name);
911 idx = APP_PARAM_ADD(app->msgq_params, name);
912 p->msgq_in[p->n_msgq_in] = idx;
916 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_in > 0), p->name, "msgq_in");
920 parse_pipeline_msgq_out(struct app_params *app,
921 struct app_pipeline_params *p,
928 char *name = strtok_r(value, PARSE_DELIMITER, &value);
933 PARSE_ERROR_TOO_MANY_ELEMENTS(
934 (p->n_msgq_out < RTE_DIM(p->msgq_out)),
935 p->name, "msgq_out", (uint32_t)RTE_DIM(p->msgq_out));
937 PARSE_ERROR_INVALID_ELEMENT(
938 (validate_name(name, "MSGQ", 1) == 0),
939 p->name, "msgq_out", name);
941 idx = APP_PARAM_ADD(app->msgq_params, name);
942 p->msgq_out[p->n_msgq_out] = idx;
946 PARSE_ERROR_NO_ELEMENTS((p->n_msgq_out > 0), p->name, "msgq_out");
950 parse_pipeline(struct app_params *app,
951 const char *section_name,
952 struct rte_cfgfile *cfg)
954 char name[CFG_NAME_LEN];
955 struct app_pipeline_params *param;
956 struct rte_cfgfile_entry *entries;
960 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
961 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
963 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
964 PARSE_ERROR_MALLOC(entries != NULL);
966 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
968 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
969 param = &app->pipeline_params[param_idx];
970 PARSE_CHECK_DUPLICATE_SECTION(param);
972 for (i = 0; i < n_entries; i++) {
973 struct rte_cfgfile_entry *ent = &entries[i];
975 if (strcmp(ent->name, "type") == 0) {
976 int w_size = snprintf(param->type, RTE_DIM(param->type),
979 PARSE_ERROR(((w_size > 0) &&
980 (w_size < (int)RTE_DIM(param->type))),
986 if (strcmp(ent->name, "core") == 0) {
987 int status = parse_pipeline_core(
988 ¶m->socket_id, ¶m->core_id,
989 ¶m->hyper_th_id, ent->value);
991 PARSE_ERROR((status == 0), section_name,
996 if (strcmp(ent->name, "pktq_in") == 0) {
997 parse_pipeline_pktq_in(app, param, ent->value);
1002 if (strcmp(ent->name, "pktq_out") == 0) {
1003 parse_pipeline_pktq_out(app, param, ent->value);
1008 if (strcmp(ent->name, "msgq_in") == 0) {
1009 parse_pipeline_msgq_in(app, param, ent->value);
1014 if (strcmp(ent->name, "msgq_out") == 0) {
1015 parse_pipeline_msgq_out(app, param, ent->value);
1020 if (strcmp(ent->name, "timer_period") == 0) {
1021 int status = parser_read_uint32(
1022 ¶m->timer_period,
1025 PARSE_ERROR((status == 0), section_name,
1030 /* pipeline type specific items */
1031 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1032 "Parse error in section \"%s\": too many "
1033 "pipeline specified parameters", section_name);
1035 param->args_name[param->n_args] = strdup(ent->name);
1036 param->args_value[param->n_args] = strdup(ent->value);
1038 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1039 (param->args_value[param->n_args] != NULL),
1040 "Parse error: no free memory");
1045 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1046 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1047 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1048 param->msgq_in[param->n_msgq_in++] = param_idx;
1050 snprintf(name, sizeof(name), "MSGQ-RSP-%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_out[param->n_msgq_out++] = param_idx;
1055 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1058 (param->hyper_th_id) ? "h" : "");
1059 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1060 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1062 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1065 (param->hyper_th_id) ? "h" : "");
1066 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1067 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1073 parse_mempool(struct app_params *app,
1074 const char *section_name,
1075 struct rte_cfgfile *cfg)
1077 struct app_mempool_params *param;
1078 struct rte_cfgfile_entry *entries;
1082 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1083 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1085 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1086 PARSE_ERROR_MALLOC(entries != NULL);
1088 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1090 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1091 param = &app->mempool_params[param_idx];
1092 PARSE_CHECK_DUPLICATE_SECTION(param);
1094 for (i = 0; i < n_entries; i++) {
1095 struct rte_cfgfile_entry *ent = &entries[i];
1097 if (strcmp(ent->name, "buffer_size") == 0) {
1098 int status = parser_read_uint32(
1099 ¶m->buffer_size, ent->value);
1101 PARSE_ERROR((status == 0), section_name,
1106 if (strcmp(ent->name, "pool_size") == 0) {
1107 int status = parser_read_uint32(
1108 ¶m->pool_size, ent->value);
1110 PARSE_ERROR((status == 0), section_name,
1115 if (strcmp(ent->name, "cache_size") == 0) {
1116 int status = parser_read_uint32(
1117 ¶m->cache_size, ent->value);
1119 PARSE_ERROR((status == 0), section_name,
1124 if (strcmp(ent->name, "cpu") == 0) {
1125 int status = parser_read_uint32(
1126 ¶m->cpu_socket_id, ent->value);
1128 PARSE_ERROR((status == 0), section_name,
1134 PARSE_ERROR_INVALID(0, section_name, ent->name);
1141 parse_link_rss_qs(struct app_link_params *p,
1147 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1152 if (p->n_rss_qs == RTE_DIM(p->rss_qs))
1155 if (parser_read_uint32(&p->rss_qs[p->n_rss_qs++], token))
1163 parse_link_rss_proto_ipv4(struct app_link_params *p,
1169 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1174 if (strcmp(token, "IP") == 0) {
1175 mask |= ETH_RSS_IPV4;
1178 if (strcmp(token, "FRAG") == 0) {
1179 mask |= ETH_RSS_FRAG_IPV4;
1182 if (strcmp(token, "TCP") == 0) {
1183 mask |= ETH_RSS_NONFRAG_IPV4_TCP;
1186 if (strcmp(token, "UDP") == 0) {
1187 mask |= ETH_RSS_NONFRAG_IPV4_UDP;
1190 if (strcmp(token, "SCTP") == 0) {
1191 mask |= ETH_RSS_NONFRAG_IPV4_SCTP;
1194 if (strcmp(token, "OTHER") == 0) {
1195 mask |= ETH_RSS_NONFRAG_IPV4_OTHER;
1201 p->rss_proto_ipv4 = mask;
1206 parse_link_rss_proto_ipv6(struct app_link_params *p,
1212 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1217 if (strcmp(token, "IP") == 0) {
1218 mask |= ETH_RSS_IPV6;
1221 if (strcmp(token, "FRAG") == 0) {
1222 mask |= ETH_RSS_FRAG_IPV6;
1225 if (strcmp(token, "TCP") == 0) {
1226 mask |= ETH_RSS_NONFRAG_IPV6_TCP;
1229 if (strcmp(token, "UDP") == 0) {
1230 mask |= ETH_RSS_NONFRAG_IPV6_UDP;
1233 if (strcmp(token, "SCTP") == 0) {
1234 mask |= ETH_RSS_NONFRAG_IPV6_SCTP;
1237 if (strcmp(token, "OTHER") == 0) {
1238 mask |= ETH_RSS_NONFRAG_IPV6_OTHER;
1241 if (strcmp(token, "IP_EX") == 0) {
1242 mask |= ETH_RSS_IPV6_EX;
1245 if (strcmp(token, "TCP_EX") == 0) {
1246 mask |= ETH_RSS_IPV6_TCP_EX;
1249 if (strcmp(token, "UDP_EX") == 0) {
1250 mask |= ETH_RSS_IPV6_UDP_EX;
1256 p->rss_proto_ipv6 = mask;
1261 parse_link_rss_proto_l2(struct app_link_params *p,
1267 char *token = strtok_r(value, PARSE_DELIMITER, &value);
1272 if (strcmp(token, "L2") == 0) {
1273 mask |= ETH_RSS_L2_PAYLOAD;
1279 p->rss_proto_l2 = mask;
1284 parse_link(struct app_params *app,
1285 const char *section_name,
1286 struct rte_cfgfile *cfg)
1288 struct app_link_params *param;
1289 struct rte_cfgfile_entry *entries;
1291 int rss_qs_present = 0;
1292 int rss_proto_ipv4_present = 0;
1293 int rss_proto_ipv6_present = 0;
1294 int rss_proto_l2_present = 0;
1295 int pci_bdf_present = 0;
1298 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1299 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1301 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1302 PARSE_ERROR_MALLOC(entries != NULL);
1304 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1306 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1307 param = &app->link_params[param_idx];
1308 PARSE_CHECK_DUPLICATE_SECTION(param);
1310 for (i = 0; i < n_entries; i++) {
1311 struct rte_cfgfile_entry *ent = &entries[i];
1313 if (strcmp(ent->name, "promisc") == 0) {
1314 int status = parser_read_arg_bool(ent->value);
1316 PARSE_ERROR((status != -EINVAL), section_name,
1318 param->promisc = status;
1322 if (strcmp(ent->name, "arp_q") == 0) {
1323 int status = parser_read_uint32(¶m->arp_q,
1326 PARSE_ERROR((status == 0), section_name,
1331 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1332 int status = parser_read_uint32(
1333 ¶m->tcp_syn_q, ent->value);
1335 PARSE_ERROR((status == 0), section_name, ent->name);
1339 if (strcmp(ent->name, "ip_local_q") == 0) {
1340 int status = parser_read_uint32(
1341 ¶m->ip_local_q, ent->value);
1343 PARSE_ERROR((status == 0), section_name,
1348 if (strcmp(ent->name, "tcp_local_q") == 0) {
1349 int status = parser_read_uint32(
1350 ¶m->tcp_local_q, ent->value);
1352 PARSE_ERROR((status == 0), section_name,
1357 if (strcmp(ent->name, "udp_local_q") == 0) {
1358 int status = parser_read_uint32(
1359 ¶m->udp_local_q, ent->value);
1361 PARSE_ERROR((status == 0), section_name,
1366 if (strcmp(ent->name, "sctp_local_q") == 0) {
1367 int status = parser_read_uint32(
1368 ¶m->sctp_local_q, ent->value);
1370 PARSE_ERROR((status == 0), section_name,
1375 if (strcmp(ent->name, "rss_qs") == 0) {
1376 int status = parse_link_rss_qs(param, ent->value);
1378 PARSE_ERROR((status == 0), section_name,
1384 if (strcmp(ent->name, "rss_proto_ipv4") == 0) {
1386 parse_link_rss_proto_ipv4(param, ent->value);
1388 PARSE_ERROR((status != -EINVAL), section_name,
1390 rss_proto_ipv4_present = 1;
1394 if (strcmp(ent->name, "rss_proto_ipv6") == 0) {
1396 parse_link_rss_proto_ipv6(param, ent->value);
1398 PARSE_ERROR((status != -EINVAL), section_name,
1400 rss_proto_ipv6_present = 1;
1404 if (strcmp(ent->name, "rss_proto_l2") == 0) {
1405 int status = parse_link_rss_proto_l2(param, ent->value);
1407 PARSE_ERROR((status != -EINVAL), section_name,
1409 rss_proto_l2_present = 1;
1413 if (strcmp(ent->name, "pci_bdf") == 0) {
1414 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1415 section_name, ent->name);
1417 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1419 pci_bdf_present = 1;
1424 PARSE_ERROR_INVALID(0, section_name, ent->name);
1427 /* Check for mandatory fields */
1429 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1430 section_name, "pci_bdf",
1431 "entry not allowed (port_mask is provided)");
1433 PARSE_ERROR_MESSAGE((pci_bdf_present),
1434 section_name, "pci_bdf",
1435 "this entry is mandatory (port_mask is not "
1438 if (rss_proto_ipv4_present)
1439 PARSE_ERROR_MESSAGE((rss_qs_present),
1440 section_name, "rss_proto_ipv4",
1441 "entry not allowed (rss_qs entry is not provided)");
1442 if (rss_proto_ipv6_present)
1443 PARSE_ERROR_MESSAGE((rss_qs_present),
1444 section_name, "rss_proto_ipv6",
1445 "entry not allowed (rss_qs entry is not provided)");
1446 if (rss_proto_l2_present)
1447 PARSE_ERROR_MESSAGE((rss_qs_present),
1448 section_name, "rss_proto_l2",
1449 "entry not allowed (rss_qs entry is not provided)");
1450 if (rss_proto_ipv4_present |
1451 rss_proto_ipv6_present |
1452 rss_proto_l2_present){
1453 if (rss_proto_ipv4_present == 0)
1454 param->rss_proto_ipv4 = 0;
1455 if (rss_proto_ipv6_present == 0)
1456 param->rss_proto_ipv6 = 0;
1457 if (rss_proto_l2_present == 0)
1458 param->rss_proto_l2 = 0;
1465 parse_rxq(struct app_params *app,
1466 const char *section_name,
1467 struct rte_cfgfile *cfg)
1469 struct app_pktq_hwq_in_params *param;
1470 struct rte_cfgfile_entry *entries;
1474 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1475 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1477 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1478 PARSE_ERROR_MALLOC(entries != NULL);
1480 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1482 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1483 param = &app->hwq_in_params[param_idx];
1484 PARSE_CHECK_DUPLICATE_SECTION(param);
1486 APP_PARAM_ADD_LINK_FOR_RXQ(app, section_name);
1488 for (i = 0; i < n_entries; i++) {
1489 struct rte_cfgfile_entry *ent = &entries[i];
1491 if (strcmp(ent->name, "mempool") == 0) {
1492 int status = validate_name(ent->value,
1496 PARSE_ERROR((status == 0), section_name,
1499 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1500 param->mempool_id = idx;
1504 if (strcmp(ent->name, "size") == 0) {
1505 int status = parser_read_uint32(¶m->size,
1508 PARSE_ERROR((status == 0), section_name,
1513 if (strcmp(ent->name, "burst") == 0) {
1514 int status = parser_read_uint32(¶m->burst,
1517 PARSE_ERROR((status == 0), section_name,
1523 PARSE_ERROR_INVALID(0, section_name, ent->name);
1530 parse_txq(struct app_params *app,
1531 const char *section_name,
1532 struct rte_cfgfile *cfg)
1534 struct app_pktq_hwq_out_params *param;
1535 struct rte_cfgfile_entry *entries;
1539 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1540 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1542 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1543 PARSE_ERROR_MALLOC(entries != NULL);
1545 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1547 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1548 param = &app->hwq_out_params[param_idx];
1549 PARSE_CHECK_DUPLICATE_SECTION(param);
1551 APP_PARAM_ADD_LINK_FOR_TXQ(app, section_name);
1553 for (i = 0; i < n_entries; i++) {
1554 struct rte_cfgfile_entry *ent = &entries[i];
1556 if (strcmp(ent->name, "size") == 0) {
1557 int status = parser_read_uint32(¶m->size,
1560 PARSE_ERROR((status == 0), section_name,
1565 if (strcmp(ent->name, "burst") == 0) {
1566 int status = parser_read_uint32(¶m->burst,
1569 PARSE_ERROR((status == 0), section_name,
1574 if (strcmp(ent->name, "dropless") == 0) {
1575 int status = parser_read_arg_bool(ent->value);
1578 PARSE_ERROR((status != -EINVAL), section_name,
1580 param->dropless = status;
1585 PARSE_ERROR_INVALID(0, section_name, ent->name);
1592 parse_swq(struct app_params *app,
1593 const char *section_name,
1594 struct rte_cfgfile *cfg)
1596 struct app_pktq_swq_params *param;
1597 struct rte_cfgfile_entry *entries;
1599 uint32_t mtu_present = 0;
1600 uint32_t metadata_size_present = 0;
1601 uint32_t mempool_direct_present = 0;
1602 uint32_t mempool_indirect_present = 0;
1606 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1607 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1609 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1610 PARSE_ERROR_MALLOC(entries != NULL);
1612 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1614 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1615 param = &app->swq_params[param_idx];
1616 PARSE_CHECK_DUPLICATE_SECTION(param);
1618 for (i = 0; i < n_entries; i++) {
1619 struct rte_cfgfile_entry *ent = &entries[i];
1621 if (strcmp(ent->name, "size") == 0) {
1622 int status = parser_read_uint32(¶m->size,
1625 PARSE_ERROR((status == 0), section_name,
1630 if (strcmp(ent->name, "burst_read") == 0) {
1631 int status = parser_read_uint32(&
1632 param->burst_read, ent->value);
1634 PARSE_ERROR((status == 0), section_name,
1639 if (strcmp(ent->name, "burst_write") == 0) {
1640 int status = parser_read_uint32(
1641 ¶m->burst_write, ent->value);
1643 PARSE_ERROR((status == 0), section_name,
1648 if (strcmp(ent->name, "dropless") == 0) {
1649 int status = parser_read_arg_bool(ent->value);
1651 PARSE_ERROR((status != -EINVAL), section_name,
1653 param->dropless = status;
1657 if (strcmp(ent->name, "n_retries") == 0) {
1658 int status = parser_read_uint64(¶m->n_retries,
1661 PARSE_ERROR((status == 0), section_name,
1666 if (strcmp(ent->name, "cpu") == 0) {
1667 int status = parser_read_uint32(
1668 ¶m->cpu_socket_id, ent->value);
1670 PARSE_ERROR((status == 0), section_name, ent->name);
1674 if (strcmp(ent->name, "ipv4_frag") == 0) {
1675 int status = parser_read_arg_bool(ent->value);
1677 PARSE_ERROR((status != -EINVAL), section_name,
1680 param->ipv4_frag = status;
1681 if (param->mtu == 0)
1687 if (strcmp(ent->name, "ipv6_frag") == 0) {
1688 int status = parser_read_arg_bool(ent->value);
1690 PARSE_ERROR((status != -EINVAL), section_name,
1692 param->ipv6_frag = status;
1693 if (param->mtu == 0)
1698 if (strcmp(ent->name, "ipv4_ras") == 0) {
1699 int status = parser_read_arg_bool(ent->value);
1701 PARSE_ERROR((status != -EINVAL), section_name,
1703 param->ipv4_ras = status;
1707 if (strcmp(ent->name, "ipv6_ras") == 0) {
1708 int status = parser_read_arg_bool(ent->value);
1710 PARSE_ERROR((status != -EINVAL), section_name,
1712 param->ipv6_ras = status;
1716 if (strcmp(ent->name, "mtu") == 0) {
1717 int status = parser_read_uint32(¶m->mtu,
1720 PARSE_ERROR((status == 0), section_name,
1726 if (strcmp(ent->name, "metadata_size") == 0) {
1727 int status = parser_read_uint32(
1728 ¶m->metadata_size, ent->value);
1730 PARSE_ERROR((status == 0), section_name,
1732 metadata_size_present = 1;
1736 if (strcmp(ent->name, "mempool_direct") == 0) {
1737 int status = validate_name(ent->value,
1741 PARSE_ERROR((status == 0), section_name,
1744 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1745 param->mempool_direct_id = idx;
1747 mempool_direct_present = 1;
1751 if (strcmp(ent->name, "mempool_indirect") == 0) {
1752 int status = validate_name(ent->value,
1756 PARSE_ERROR((status == 0), section_name,
1759 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1760 param->mempool_indirect_id = idx;
1762 mempool_indirect_present = 1;
1767 PARSE_ERROR_INVALID(0, section_name, ent->name);
1770 APP_CHECK(((mtu_present == 0) ||
1771 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1772 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1773 "is off, therefore entry \"mtu\" is not allowed",
1776 APP_CHECK(((metadata_size_present == 0) ||
1777 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1778 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1779 "is off, therefore entry \"metadata_size\" is "
1780 "not allowed", section_name);
1782 APP_CHECK(((mempool_direct_present == 0) ||
1783 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1784 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1785 "is off, therefore entry \"mempool_direct\" is "
1786 "not allowed", section_name);
1788 APP_CHECK(((mempool_indirect_present == 0) ||
1789 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1790 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1791 "is off, therefore entry \"mempool_indirect\" is "
1792 "not allowed", section_name);
1798 parse_tm(struct app_params *app,
1799 const char *section_name,
1800 struct rte_cfgfile *cfg)
1802 struct app_pktq_tm_params *param;
1803 struct rte_cfgfile_entry *entries;
1807 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1808 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1810 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1811 PARSE_ERROR_MALLOC(entries != NULL);
1813 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1815 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1816 param = &app->tm_params[param_idx];
1817 PARSE_CHECK_DUPLICATE_SECTION(param);
1819 APP_PARAM_ADD_LINK_FOR_TXQ(app, section_name);
1821 for (i = 0; i < n_entries; i++) {
1822 struct rte_cfgfile_entry *ent = &entries[i];
1824 if (strcmp(ent->name, "cfg") == 0) {
1825 param->file_name = strdup(ent->value);
1826 PARSE_ERROR_MALLOC(param->file_name != NULL);
1830 if (strcmp(ent->name, "burst_read") == 0) {
1831 int status = parser_read_uint32(
1832 ¶m->burst_read, ent->value);
1834 PARSE_ERROR((status == 0), section_name,
1839 if (strcmp(ent->name, "burst_write") == 0) {
1840 int status = parser_read_uint32(
1841 ¶m->burst_write, ent->value);
1843 PARSE_ERROR((status == 0), section_name,
1849 PARSE_ERROR_INVALID(0, section_name, ent->name);
1856 parse_source(struct app_params *app,
1857 const char *section_name,
1858 struct rte_cfgfile *cfg)
1860 struct app_pktq_source_params *param;
1861 struct rte_cfgfile_entry *entries;
1864 uint32_t pcap_file_present = 0;
1865 uint32_t pcap_size_present = 0;
1867 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1868 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1870 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1871 PARSE_ERROR_MALLOC(entries != NULL);
1873 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1875 param_idx = APP_PARAM_ADD(app->source_params, section_name);
1876 param = &app->source_params[param_idx];
1877 PARSE_CHECK_DUPLICATE_SECTION(param);
1879 for (i = 0; i < n_entries; i++) {
1880 struct rte_cfgfile_entry *ent = &entries[i];
1882 if (strcmp(ent->name, "mempool") == 0) {
1883 int status = validate_name(ent->value,
1887 PARSE_ERROR((status == 0), section_name,
1890 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1891 param->mempool_id = idx;
1895 if (strcmp(ent->name, "burst") == 0) {
1896 int status = parser_read_uint32(¶m->burst,
1899 PARSE_ERROR((status == 0), section_name,
1904 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1905 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
1906 section_name, ent->name);
1908 param->file_name = strdup(ent->value);
1910 PARSE_ERROR_MALLOC(param->file_name != NULL);
1911 pcap_file_present = 1;
1916 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1919 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
1920 section_name, ent->name);
1922 status = parser_read_uint32(
1923 ¶m->n_bytes_per_pkt, ent->value);
1925 PARSE_ERROR((status == 0), section_name,
1927 pcap_size_present = 1;
1933 PARSE_ERROR_INVALID(0, section_name, ent->name);
1940 parse_sink(struct app_params *app,
1941 const char *section_name,
1942 struct rte_cfgfile *cfg)
1944 struct app_pktq_sink_params *param;
1945 struct rte_cfgfile_entry *entries;
1948 uint32_t pcap_file_present = 0;
1949 uint32_t pcap_n_pkt_present = 0;
1951 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1952 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1954 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1955 PARSE_ERROR_MALLOC(entries != NULL);
1957 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1959 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
1960 param = &app->sink_params[param_idx];
1961 PARSE_CHECK_DUPLICATE_SECTION(param);
1963 for (i = 0; i < n_entries; i++) {
1964 struct rte_cfgfile_entry *ent = &entries[i];
1966 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1967 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
1968 section_name, ent->name);
1970 param->file_name = strdup(ent->value);
1972 PARSE_ERROR_MALLOC((param->file_name != NULL));
1977 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1980 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
1981 section_name, ent->name);
1983 status = parser_read_uint32(
1984 ¶m->n_pkts_to_dump, ent->value);
1986 PARSE_ERROR((status == 0), section_name,
1993 PARSE_ERROR_INVALID(0, section_name, ent->name);
2000 parse_msgq_req_pipeline(struct app_params *app,
2001 const char *section_name,
2002 struct rte_cfgfile *cfg)
2004 struct app_msgq_params *param;
2005 struct rte_cfgfile_entry *entries;
2009 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2010 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2012 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2013 PARSE_ERROR_MALLOC(entries != NULL);
2015 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2017 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2018 param = &app->msgq_params[param_idx];
2019 PARSE_CHECK_DUPLICATE_SECTION(param);
2021 for (i = 0; i < n_entries; i++) {
2022 struct rte_cfgfile_entry *ent = &entries[i];
2024 if (strcmp(ent->name, "size") == 0) {
2025 int status = parser_read_uint32(¶m->size,
2028 PARSE_ERROR((status == 0), section_name,
2034 PARSE_ERROR_INVALID(0, section_name, ent->name);
2041 parse_msgq_rsp_pipeline(struct app_params *app,
2042 const char *section_name,
2043 struct rte_cfgfile *cfg)
2045 struct app_msgq_params *param;
2046 struct rte_cfgfile_entry *entries;
2050 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2051 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2053 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2054 PARSE_ERROR_MALLOC(entries != NULL);
2056 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2058 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2059 param = &app->msgq_params[param_idx];
2060 PARSE_CHECK_DUPLICATE_SECTION(param);
2062 for (i = 0; i < n_entries; i++) {
2063 struct rte_cfgfile_entry *ent = &entries[i];
2065 if (strcmp(ent->name, "size") == 0) {
2066 int status = parser_read_uint32(¶m->size,
2069 PARSE_ERROR((status == 0), section_name,
2075 PARSE_ERROR_INVALID(0, section_name, ent->name);
2082 parse_msgq(struct app_params *app,
2083 const char *section_name,
2084 struct rte_cfgfile *cfg)
2086 struct app_msgq_params *param;
2087 struct rte_cfgfile_entry *entries;
2091 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2092 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2094 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2095 PARSE_ERROR_MALLOC(entries != NULL);
2097 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2099 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2100 param = &app->msgq_params[param_idx];
2101 PARSE_CHECK_DUPLICATE_SECTION(param);
2103 for (i = 0; i < n_entries; i++) {
2104 struct rte_cfgfile_entry *ent = &entries[i];
2106 if (strcmp(ent->name, "size") == 0) {
2107 int status = parser_read_uint32(¶m->size,
2110 PARSE_ERROR((status == 0), section_name,
2115 if (strcmp(ent->name, "cpu") == 0) {
2116 int status = parser_read_uint32(
2117 ¶m->cpu_socket_id, ent->value);
2119 PARSE_ERROR((status == 0), section_name,
2125 PARSE_ERROR_INVALID(0, section_name, ent->name);
2131 typedef void (*config_section_load)(struct app_params *p,
2132 const char *section_name,
2133 struct rte_cfgfile *cfg);
2135 struct config_section {
2136 const char prefix[CFG_NAME_LEN];
2138 config_section_load load;
2141 static const struct config_section cfg_file_scheme[] = {
2142 {"EAL", 0, parse_eal},
2143 {"PIPELINE", 1, parse_pipeline},
2144 {"MEMPOOL", 1, parse_mempool},
2145 {"LINK", 1, parse_link},
2146 {"RXQ", 2, parse_rxq},
2147 {"TXQ", 2, parse_txq},
2148 {"SWQ", 1, parse_swq},
2149 {"TM", 1, parse_tm},
2150 {"SOURCE", 1, parse_source},
2151 {"SINK", 1, parse_sink},
2152 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2153 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2154 {"MSGQ", 1, parse_msgq},
2158 create_implicit_mempools(struct app_params *app)
2160 APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2164 create_implicit_links_from_port_mask(struct app_params *app,
2167 uint32_t pmd_id, link_id;
2170 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2171 char name[APP_PARAM_NAME_SIZE];
2174 if ((port_mask & (1LLU << pmd_id)) == 0)
2177 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2178 idx = APP_PARAM_ADD(app->link_params, name);
2180 app->link_params[idx].pmd_id = pmd_id;
2186 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2190 for (i = 0; i < app->n_links; i++) {
2191 struct app_link_params *link = &app->link_params[i];
2193 APP_CHECK((strlen(link->pci_bdf)),
2194 "Parse error: %s pci_bdf is not configured "
2195 "(port_mask is not provided)",
2203 app_config_parse(struct app_params *app, const char *file_name)
2205 struct rte_cfgfile *cfg;
2206 char **section_names;
2207 int i, j, sect_count;
2209 /* Implicit mempools */
2210 create_implicit_mempools(app);
2214 create_implicit_links_from_port_mask(app, app->port_mask);
2216 /* Load application configuration file */
2217 cfg = rte_cfgfile_load(file_name, 0);
2218 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2219 "file %s", file_name);
2221 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2222 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2223 "in file \"%s\" return %d", file_name,
2226 section_names = malloc(sect_count * sizeof(char *));
2227 PARSE_ERROR_MALLOC(section_names != NULL);
2229 for (i = 0; i < sect_count; i++)
2230 section_names[i] = malloc(CFG_NAME_LEN);
2232 rte_cfgfile_sections(cfg, section_names, sect_count);
2234 for (i = 0; i < sect_count; i++) {
2235 const struct config_section *sch_s;
2236 int len, cfg_name_len;
2238 cfg_name_len = strlen(section_names[i]);
2240 /* Find section type */
2241 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2242 sch_s = &cfg_file_scheme[j];
2243 len = strlen(sch_s->prefix);
2245 if (cfg_name_len < len)
2248 /* After section name we expect only '\0' or digit or
2249 * digit dot digit, so protect against false matching,
2250 * for example: "ABC" should match section name
2251 * "ABC0.0", but it should not match section_name
2254 if ((section_names[i][len] != '\0') &&
2255 !isdigit(section_names[i][len]))
2258 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2262 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2263 "Parse error: unknown section %s",
2266 APP_CHECK(validate_name(section_names[i],
2268 sch_s->numbers) == 0,
2269 "Parse error: invalid section name \"%s\"",
2272 sch_s->load(app, section_names[i], cfg);
2275 for (i = 0; i < sect_count; i++)
2276 free(section_names[i]);
2278 free(section_names);
2280 rte_cfgfile_close(cfg);
2282 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2283 APP_PARAM_COUNT(app->link_params, app->n_links);
2284 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2285 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2286 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2287 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2288 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2289 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2290 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2291 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2293 if (app->port_mask == 0)
2294 assign_link_pmd_id_from_pci_bdf(app);
2296 /* Save configuration to output file */
2297 app_config_save(app, app->output_file);
2299 /* Load TM configuration files */
2300 app_config_parse_tm(app);
2306 save_eal_params(struct app_params *app, FILE *f)
2308 struct app_eal_params *p = &app->eal_params;
2311 fprintf(f, "[EAL]\n");
2314 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2316 if (p->master_lcore_present)
2317 fprintf(f, "%s = %" PRIu32 "\n",
2318 "master_lcore", p->master_lcore);
2320 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2322 if (p->memory_present)
2323 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2325 if (p->ranks_present)
2326 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2328 for (i = 0; i < APP_MAX_LINKS; i++) {
2329 if (p->pci_blacklist[i] == NULL)
2332 fprintf(f, "%s = %s\n", "pci_blacklist",
2333 p->pci_blacklist[i]);
2336 for (i = 0; i < APP_MAX_LINKS; i++) {
2337 if (p->pci_whitelist[i] == NULL)
2340 fprintf(f, "%s = %s\n", "pci_whitelist",
2341 p->pci_whitelist[i]);
2344 for (i = 0; i < APP_MAX_LINKS; i++) {
2345 if (p->vdev[i] == NULL)
2348 fprintf(f, "%s = %s\n", "vdev",
2352 if (p->vmware_tsc_map_present)
2353 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2354 (p->vmware_tsc_map) ? "yes" : "no");
2357 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2360 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2362 if (p->log_level_present)
2363 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2365 if (p->version_present)
2366 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2368 if (p->help_present)
2369 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2371 if (p->no_huge_present)
2372 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2374 if (p->no_pci_present)
2375 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2377 if (p->no_hpet_present)
2378 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2380 if (p->no_shconf_present)
2381 fprintf(f, "%s = %s\n", "no_shconf",
2382 (p->no_shconf) ? "yes" : "no");
2385 fprintf(f, "%s = %s\n", "d", p->add_driver);
2388 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2391 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2394 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2396 if (p->base_virtaddr)
2397 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2399 if (p->create_uio_dev_present)
2400 fprintf(f, "%s = %s\n", "create_uio_dev",
2401 (p->create_uio_dev) ? "yes" : "no");
2404 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2406 if (p->xen_dom0_present)
2407 fprintf(f, "%s = %s\n", "xen_dom0",
2408 (p->xen_dom0) ? "yes" : "no");
2414 save_mempool_params(struct app_params *app, FILE *f)
2416 struct app_mempool_params *p;
2419 count = RTE_DIM(app->mempool_params);
2420 for (i = 0; i < count; i++) {
2421 p = &app->mempool_params[i];
2422 if (!APP_PARAM_VALID(p))
2425 fprintf(f, "[%s]\n", p->name);
2426 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2427 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2428 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2429 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2436 save_links_params(struct app_params *app, FILE *f)
2438 struct app_link_params *p;
2441 count = RTE_DIM(app->link_params);
2442 for (i = 0; i < count; i++) {
2443 p = &app->link_params[i];
2444 if (!APP_PARAM_VALID(p))
2447 fprintf(f, "[%s]\n", p->name);
2448 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2449 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2450 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2451 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2453 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2454 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2455 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2456 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2463 fprintf(f, "rss_qs = ");
2464 for (j = 0; j < p->n_rss_qs; j++)
2465 fprintf(f, "%" PRIu32 " ", p->rss_qs[j]);
2468 /* rss_proto_ipv4 */
2469 if (p->rss_proto_ipv4) {
2470 fprintf(f, "rss_proto_ipv4 = ");
2471 if (p->rss_proto_ipv4 & ETH_RSS_IPV4)
2473 if (p->rss_proto_ipv4 & ETH_RSS_FRAG_IPV4)
2474 fprintf(f, "FRAG ");
2475 if (p->rss_proto_ipv4 &
2476 ETH_RSS_NONFRAG_IPV4_TCP)
2478 if (p->rss_proto_ipv4 &
2479 ETH_RSS_NONFRAG_IPV4_UDP)
2481 if (p->rss_proto_ipv4 &
2482 ETH_RSS_NONFRAG_IPV4_SCTP)
2483 fprintf(f, "SCTP ");
2484 if (p->rss_proto_ipv4 &
2485 ETH_RSS_NONFRAG_IPV4_OTHER)
2486 fprintf(f, "OTHER ");
2489 fprintf(f, "; rss_proto_ipv4 = <NONE>\n");
2491 /* rss_proto_ipv6 */
2492 if (p->rss_proto_ipv6) {
2493 fprintf(f, "rss_proto_ipv6 = ");
2494 if (p->rss_proto_ipv6 & ETH_RSS_IPV6)
2496 if (p->rss_proto_ipv6 & ETH_RSS_FRAG_IPV6)
2497 fprintf(f, "FRAG ");
2498 if (p->rss_proto_ipv6 &
2499 ETH_RSS_NONFRAG_IPV6_TCP)
2501 if (p->rss_proto_ipv6 &
2502 ETH_RSS_NONFRAG_IPV6_UDP)
2504 if (p->rss_proto_ipv6 &
2505 ETH_RSS_NONFRAG_IPV6_SCTP)
2506 fprintf(f, "SCTP ");
2507 if (p->rss_proto_ipv6 &
2508 ETH_RSS_NONFRAG_IPV6_OTHER)
2509 fprintf(f, "OTHER ");
2510 if (p->rss_proto_ipv6 & ETH_RSS_IPV6_EX)
2511 fprintf(f, "IP_EX ");
2512 if (p->rss_proto_ipv6 &
2513 ETH_RSS_IPV6_TCP_EX)
2514 fprintf(f, "TCP_EX ");
2515 if (p->rss_proto_ipv6 &
2516 ETH_RSS_IPV6_UDP_EX)
2517 fprintf(f, "UDP_EX ");
2520 fprintf(f, "; rss_proto_ipv6 = <NONE>\n");
2523 if (p->rss_proto_l2) {
2524 fprintf(f, "rss_proto_l2 = ");
2525 if (p->rss_proto_l2 & ETH_RSS_L2_PAYLOAD)
2529 fprintf(f, "; rss_proto_l2 = <NONE>\n");
2531 fprintf(f, "; rss_qs = <NONE>\n");
2532 fprintf(f, "; rss_proto_ipv4 = <NONE>\n");
2533 fprintf(f, "; rss_proto_ipv6 = <NONE>\n");
2534 fprintf(f, "; rss_proto_l2 = <NONE>\n");
2537 if (strlen(p->pci_bdf))
2538 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2545 save_rxq_params(struct app_params *app, FILE *f)
2547 struct app_pktq_hwq_in_params *p;
2550 count = RTE_DIM(app->hwq_in_params);
2551 for (i = 0; i < count; i++) {
2552 p = &app->hwq_in_params[i];
2553 if (!APP_PARAM_VALID(p))
2556 fprintf(f, "[%s]\n", p->name);
2557 fprintf(f, "%s = %s\n",
2559 app->mempool_params[p->mempool_id].name);
2560 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2561 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2568 save_txq_params(struct app_params *app, FILE *f)
2570 struct app_pktq_hwq_out_params *p;
2573 count = RTE_DIM(app->hwq_out_params);
2574 for (i = 0; i < count; i++) {
2575 p = &app->hwq_out_params[i];
2576 if (!APP_PARAM_VALID(p))
2579 fprintf(f, "[%s]\n", p->name);
2580 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2581 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2582 fprintf(f, "%s = %s\n",
2584 p->dropless ? "yes" : "no");
2591 save_swq_params(struct app_params *app, FILE *f)
2593 struct app_pktq_swq_params *p;
2596 count = RTE_DIM(app->swq_params);
2597 for (i = 0; i < count; i++) {
2598 p = &app->swq_params[i];
2599 if (!APP_PARAM_VALID(p))
2602 fprintf(f, "[%s]\n", p->name);
2603 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2604 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2605 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2606 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2607 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2608 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2609 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2610 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2611 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2612 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2613 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2614 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2615 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2616 fprintf(f, "%s = %s\n",
2618 app->mempool_params[p->mempool_direct_id].name);
2619 fprintf(f, "%s = %s\n",
2621 app->mempool_params[p->mempool_indirect_id].name);
2629 save_tm_params(struct app_params *app, FILE *f)
2631 struct app_pktq_tm_params *p;
2634 count = RTE_DIM(app->tm_params);
2635 for (i = 0; i < count; i++) {
2636 p = &app->tm_params[i];
2637 if (!APP_PARAM_VALID(p))
2640 fprintf(f, "[%s]\n", p->name);
2641 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2642 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2643 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2650 save_source_params(struct app_params *app, FILE *f)
2652 struct app_pktq_source_params *p;
2655 count = RTE_DIM(app->source_params);
2656 for (i = 0; i < count; i++) {
2657 p = &app->source_params[i];
2658 if (!APP_PARAM_VALID(p))
2661 fprintf(f, "[%s]\n", p->name);
2662 fprintf(f, "%s = %s\n",
2664 app->mempool_params[p->mempool_id].name);
2665 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2666 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2667 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2668 p->n_bytes_per_pkt);
2674 save_sink_params(struct app_params *app, FILE *f)
2676 struct app_pktq_sink_params *p;
2679 count = RTE_DIM(app->sink_params);
2680 for (i = 0; i < count; i++) {
2681 p = &app->sink_params[i];
2682 if (!APP_PARAM_VALID(p))
2685 fprintf(f, "[%s]\n", p->name);
2686 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2687 fprintf(f, "%s = %" PRIu32 "\n",
2688 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2694 save_msgq_params(struct app_params *app, FILE *f)
2696 struct app_msgq_params *p;
2699 count = RTE_DIM(app->msgq_params);
2700 for (i = 0; i < count; i++) {
2701 p = &app->msgq_params[i];
2702 if (!APP_PARAM_VALID(p))
2705 fprintf(f, "[%s]\n", p->name);
2706 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2707 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2714 save_pipeline_params(struct app_params *app, FILE *f)
2718 count = RTE_DIM(app->pipeline_params);
2719 for (i = 0; i < count; i++) {
2720 struct app_pipeline_params *p = &app->pipeline_params[i];
2722 if (!APP_PARAM_VALID(p))
2726 fprintf(f, "[%s]\n", p->name);
2729 fprintf(f, "type = %s\n", p->type);
2732 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2735 (p->hyper_th_id) ? "h" : "");
2741 fprintf(f, "pktq_in =");
2742 for (j = 0; j < p->n_pktq_in; j++) {
2743 struct app_pktq_in_params *pp = &p->pktq_in[j];
2747 case APP_PKTQ_IN_HWQ:
2748 name = app->hwq_in_params[pp->id].name;
2750 case APP_PKTQ_IN_SWQ:
2751 name = app->swq_params[pp->id].name;
2753 case APP_PKTQ_IN_TM:
2754 name = app->tm_params[pp->id].name;
2756 case APP_PKTQ_IN_SOURCE:
2757 name = app->source_params[pp->id].name;
2760 APP_CHECK(0, "System error "
2761 "occurred while saving "
2762 "parameter to file");
2765 fprintf(f, " %s", name);
2771 if (p->n_pktq_out) {
2774 fprintf(f, "pktq_out =");
2775 for (j = 0; j < p->n_pktq_out; j++) {
2776 struct app_pktq_out_params *pp =
2781 case APP_PKTQ_OUT_HWQ:
2782 name = app->hwq_out_params[pp->id].name;
2784 case APP_PKTQ_OUT_SWQ:
2785 name = app->swq_params[pp->id].name;
2787 case APP_PKTQ_OUT_TM:
2788 name = app->tm_params[pp->id].name;
2790 case APP_PKTQ_OUT_SINK:
2791 name = app->sink_params[pp->id].name;
2794 APP_CHECK(0, "System error "
2795 "occurred while saving "
2796 "parameter to file");
2799 fprintf(f, " %s", name);
2808 fprintf(f, "msgq_in =");
2809 for (j = 0; j < p->n_msgq_in; j++) {
2810 uint32_t id = p->msgq_in[j];
2811 char *name = app->msgq_params[id].name;
2813 fprintf(f, " %s", name);
2819 if (p->n_msgq_out) {
2822 fprintf(f, "msgq_out =");
2823 for (j = 0; j < p->n_msgq_out; j++) {
2824 uint32_t id = p->msgq_out[j];
2825 char *name = app->msgq_params[id].name;
2827 fprintf(f, " %s", name);
2833 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2839 for (j = 0; j < p->n_args; j++)
2840 fprintf(f, "%s = %s\n", p->args_name[j],
2849 app_config_save(struct app_params *app, const char *file_name)
2852 char *name, *dir_name;
2855 name = strdup(file_name);
2856 dir_name = dirname(name);
2857 status = access(dir_name, W_OK);
2858 APP_CHECK((status == 0),
2859 "Error: need write access privilege to directory "
2860 "\"%s\" to save configuration\n", dir_name);
2862 file = fopen(file_name, "w");
2863 APP_CHECK((file != NULL),
2864 "Error: failed to save configuration to file \"%s\"",
2867 save_eal_params(app, file);
2868 save_pipeline_params(app, file);
2869 save_mempool_params(app, file);
2870 save_links_params(app, file);
2871 save_rxq_params(app, file);
2872 save_txq_params(app, file);
2873 save_swq_params(app, file);
2874 save_tm_params(app, file);
2875 save_source_params(app, file);
2876 save_sink_params(app, file);
2877 save_msgq_params(app, file);
2884 app_config_init(struct app_params *app)
2888 memcpy(app, &app_params_default, sizeof(struct app_params));
2890 /* configure default_source_params */
2891 default_source_params.file_name = strdup("./config/packets.pcap");
2892 PARSE_ERROR_MALLOC(default_source_params.file_name != NULL);
2894 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2895 memcpy(&app->mempool_params[i],
2896 &mempool_params_default,
2897 sizeof(struct app_mempool_params));
2899 for (i = 0; i < RTE_DIM(app->link_params); i++)
2900 memcpy(&app->link_params[i],
2901 &link_params_default,
2902 sizeof(struct app_link_params));
2904 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2905 memcpy(&app->hwq_in_params[i],
2906 &default_hwq_in_params,
2907 sizeof(default_hwq_in_params));
2909 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2910 memcpy(&app->hwq_out_params[i],
2911 &default_hwq_out_params,
2912 sizeof(default_hwq_out_params));
2914 for (i = 0; i < RTE_DIM(app->swq_params); i++)
2915 memcpy(&app->swq_params[i],
2916 &default_swq_params,
2917 sizeof(default_swq_params));
2919 for (i = 0; i < RTE_DIM(app->tm_params); i++)
2920 memcpy(&app->tm_params[i],
2922 sizeof(default_tm_params));
2924 for (i = 0; i < RTE_DIM(app->source_params); i++)
2925 memcpy(&app->source_params[i],
2926 &default_source_params,
2927 sizeof(default_source_params));
2929 for (i = 0; i < RTE_DIM(app->sink_params); i++)
2930 memcpy(&app->sink_params[i],
2931 &default_sink_params,
2932 sizeof(default_sink_params));
2934 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2935 memcpy(&app->msgq_params[i],
2936 &default_msgq_params,
2937 sizeof(default_msgq_params));
2939 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2940 memcpy(&app->pipeline_params[i],
2941 &default_pipeline_params,
2942 sizeof(default_pipeline_params));
2948 filenamedup(const char *filename, const char *suffix)
2950 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2955 sprintf(s, "%s%s", filename, suffix);
2960 app_config_args(struct app_params *app, int argc, char **argv)
2962 const char *optname;
2963 int opt, option_index;
2964 int f_present, s_present, p_present, l_present;
2965 int preproc_present, preproc_params_present;
2968 static struct option lgopts[] = {
2969 { "preproc", 1, 0, 0 },
2970 { "preproc-args", 1, 0, 0 },
2974 /* Copy application name */
2975 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
2981 preproc_present = 0;
2982 preproc_params_present = 0;
2984 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
2985 &option_index)) != EOF)
2989 rte_panic("Error: Config file is provided "
2990 "more than once\n");
2993 if (!strlen(optarg))
2994 rte_panic("Error: Config file name is null\n");
2996 app->config_file = strdup(optarg);
2997 if (app->config_file == NULL)
2998 rte_panic("Error: Memory allocation failure\n");
3004 rte_panic("Error: Script file is provided "
3005 "more than once\n");
3008 if (!strlen(optarg))
3009 rte_panic("Error: Script file name is null\n");
3011 app->script_file = strdup(optarg);
3012 if (app->script_file == NULL)
3013 rte_panic("Error: Memory allocation failure\n");
3019 rte_panic("Error: PORT_MASK is provided "
3020 "more than once\n");
3023 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3025 ((size_t) scaned != strlen(optarg)))
3026 rte_panic("Error: PORT_MASK is not "
3027 "a hexadecimal integer\n");
3029 if (app->port_mask == 0)
3030 rte_panic("Error: PORT_MASK is null\n");
3036 rte_panic("Error: LOG_LEVEL is provided "
3037 "more than once\n");
3040 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3042 ((size_t) scaned != strlen(optarg)) ||
3043 (app->log_level >= APP_LOG_LEVELS))
3044 rte_panic("Error: LOG_LEVEL invalid value\n");
3049 optname = lgopts[option_index].name;
3051 if (strcmp(optname, "preproc") == 0) {
3052 if (preproc_present)
3053 rte_panic("Error: Preprocessor argument "
3054 "is provided more than once\n");
3055 preproc_present = 1;
3057 app->preproc = strdup(optarg);
3061 if (strcmp(optname, "preproc-args") == 0) {
3062 if (preproc_params_present)
3063 rte_panic("Error: Preprocessor args "
3064 "are provided more than once\n");
3065 preproc_params_present = 1;
3067 app->preproc_args = strdup(optarg);
3071 app_print_usage(argv[0]);
3075 app_print_usage(argv[0]);
3078 optind = 0; /* reset getopt lib */
3080 /* Check dependencies between args */
3081 if (preproc_params_present && (preproc_present == 0))
3082 rte_panic("Error: Preprocessor args specified while "
3083 "preprocessor is not defined\n");
3085 app->parser_file = preproc_present ?
3086 filenamedup(app->config_file, ".preproc") :
3087 strdup(app->config_file);
3088 app->output_file = filenamedup(app->config_file, ".out");
3094 app_config_preproc(struct app_params *app)
3099 if (app->preproc == NULL)
3102 status = access(app->config_file, F_OK | R_OK);
3103 APP_CHECK((status == 0), "Error: Unable to open file %s",
3106 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3108 app->preproc_args ? app->preproc_args : "",
3112 status = system(buffer);
3113 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3114 "Error occurred while pre-processing file \"%s\"\n",