4 * Copyright(c) 2010-2015 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.
45 #include <rte_errno.h>
46 #include <rte_cfgfile.h>
47 #include <rte_string_fns.h>
52 * Default config values
55 static struct app_params app_params_default = {
56 .config_file = "./config/ip_pipeline.cfg",
57 .log_level = APP_LOG_LEVEL_HIGH,
64 static const struct app_mempool_params mempool_params_default = {
66 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
67 .pool_size = 32 * 1024,
72 static const struct app_link_params link_params_default = {
90 .mq_mode = ETH_MQ_RX_NONE,
92 .header_split = 0, /* Header split */
93 .hw_ip_checksum = 0, /* IP checksum offload */
94 .hw_vlan_filter = 0, /* VLAN filtering */
95 .hw_vlan_strip = 0, /* VLAN strip */
96 .hw_vlan_extend = 0, /* Extended VLAN */
97 .jumbo_frame = 0, /* Jumbo frame support */
98 .hw_strip_crc = 0, /* CRC strip by HW */
99 .enable_scatter = 0, /* Scattered packets RX handler */
101 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
102 .split_hdr_size = 0, /* Header split buffer size */
105 .mq_mode = ETH_MQ_TX_NONE,
113 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
125 .rx_free_thresh = 64,
127 .rx_deferred_start = 0,
131 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
146 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
147 ETH_TXQ_FLAGS_NOOFFLOADS,
148 .tx_deferred_start = 0,
152 static const struct app_pktq_swq_params default_swq_params = {
166 .mempool_direct_id = 0,
167 .mempool_indirect_id = 0,
170 struct app_pktq_tm_params default_tm_params = {
172 .file_name = "./config/tm_profile.cfg",
177 struct app_pktq_source_params default_source_params = {
183 struct app_pktq_sink_params default_sink_params = {
187 struct app_msgq_params default_msgq_params = {
193 struct app_pipeline_params default_pipeline_params = {
206 static const char app_usage[] =
207 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] -p PORT_MASK "
208 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
211 "\t-f CONFIG_FILE: Default config file is %s\n"
212 "\t-p PORT_MASK: Mask of NIC port IDs in hexadecimal format\n"
213 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
214 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
215 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
216 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
220 app_print_usage(char *prgname)
222 rte_exit(0, app_usage, prgname, app_params_default.config_file);
225 #define skip_white_spaces(pos) \
227 __typeof__(pos) _p = (pos); \
228 for ( ; isspace(*_p); _p++); \
232 #define PARSER_IMPLICIT_PARAM_ADD_CHECK(result, section_name) \
234 APP_CHECK((result != -EINVAL), \
235 "CFG: [%s] name too long", section_name); \
236 APP_CHECK(result != -ENOMEM, \
237 "CFG: [%s] too much sections", section_name); \
238 APP_CHECK(result >= 0, \
239 "CFG: [%s] Unknown error while adding '%s'", \
240 section_name, section_name); \
243 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
245 APP_CHECK((result != -EINVAL), \
246 "CFG: [%s] name too long", section_name); \
247 APP_CHECK((result != -ENOMEM), \
248 "CFG: [%s] too much sections", section_name); \
249 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
250 "CFG: [%s] duplicate section", section_name); \
251 APP_CHECK((result >= 0), \
252 "CFG: [%s] Unknown error while adding '%s'", \
253 section_name, section_name); \
257 parser_read_arg_bool(const char *p)
259 p = skip_white_spaces(p);
260 int result = -EINVAL;
262 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
263 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
268 if (((p[0] == 'o') && (p[1] == 'n')) ||
269 ((p[0] == 'O') && (p[1] == 'N'))) {
274 if (((p[0] == 'n') && (p[1] == 'o')) ||
275 ((p[0] == 'N') && (p[1] == 'O'))) {
280 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
281 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
286 p = skip_white_spaces(p);
294 #define PARSE_ERROR(exp, section, entry) \
295 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
297 #define PARSE_ERROR_MALLOC(exp) \
298 APP_CHECK(exp, "Parse error: no free memory\n")
300 #define PARSE_ERROR_SECTION(exp, section) \
301 APP_CHECK(exp, "Parse error in section \"%s\"", section)
303 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
304 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
306 #define PARSE_WARNING_IGNORED(exp, section, entry) \
309 fprintf(stderr, "Parse warning in section \"%s\": " \
310 "entry \"%s\" is ignored\n", section, entry); \
313 #define PARSE_ERROR_INVALID(exp, section, entry) \
314 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
317 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
318 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
322 parser_read_uint64(uint64_t *value, const char *p)
327 p = skip_white_spaces(p);
331 val = strtoul(p, &next, 10);
353 p = skip_white_spaces(p);
362 parser_read_uint32(uint32_t *value, const char *p)
365 int ret = parser_read_uint64(&val, p);
369 else if (val > UINT32_MAX)
377 parse_pipeline_core(uint32_t *socket,
385 uint32_t s = 0, c = 0, h = 0, val;
386 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
387 const char *next = skip_white_spaces(entry);
390 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
391 while (*next != '\0') {
392 /* If everything parsed nothing should left */
393 if (s_parsed && c_parsed && h_parsed)
400 if (s_parsed || c_parsed || h_parsed)
407 if (c_parsed || h_parsed)
420 /* If it start from digit it must be only core id. */
421 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
427 for (num_len = 0; *next != '\0'; next++, num_len++) {
428 if (num_len == RTE_DIM(num))
434 num[num_len] = *next;
437 if (num_len == 0 && type != 'h' && type != 'H')
440 if (num_len != 0 && (type == 'h' || type == 'H'))
444 val = strtol(num, NULL, 10);
473 case '0': case '1': case '2': case '3': case '4': case '5':
474 case '6': case '7': case '8': case '9':
476 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
478 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
486 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
491 /* Check input parameters */
499 if (((len & 3) != 0) ||
504 for (c = src; *c != 0; c++) {
505 if ((((*c) >= '0') && ((*c) <= '9')) ||
506 (((*c) >= 'A') && ((*c) <= 'F')) ||
507 (((*c) >= 'a') && ((*c) <= 'f')))
513 /* Convert chars to bytes */
514 for (i = 0; i < *size; i++)
515 dst[i] = get_hex_val(src[2 * i]) * 16 +
516 get_hex_val(src[2 * i + 1]);
522 skip_digits(const char *src)
526 for (i = 0; isdigit(src[i]); i++);
532 validate_name(const char *name, const char *prefix, int num)
536 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
537 if (name[i] != prefix[i])
541 if (prefix[i] != '\0')
552 j = skip_digits(&name[i]);
554 if ((j == 0) || (name[i] != '.'))
560 j = skip_digits(&name[i]);
562 if ((j == 0) || (name[i] != '\0'))
570 parse_eal(struct app_params *app,
571 const char *section_name,
572 struct rte_cfgfile *cfg)
574 struct app_eal_params *p = &app->eal_params;
575 struct rte_cfgfile_entry *entries;
578 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
579 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
581 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
582 PARSE_ERROR_MALLOC(entries != NULL);
584 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
586 for (i = 0; i < n_entries; i++) {
587 struct rte_cfgfile_entry *entry = &entries[i];
590 if (strcmp(entry->name, "c") == 0) {
591 PARSE_WARNING_IGNORED(0, section_name, entry->name);
596 if (strcmp(entry->name, "l") == 0) {
597 PARSE_WARNING_IGNORED(0, section_name, entry->name);
602 if (strcmp(entry->name, "lcores") == 0) {
603 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
606 p->coremap = strdup(entry->value);
611 if (strcmp(entry->name, "master_lcore") == 0) {
614 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
617 p->master_lcore_present = 1;
619 status = parser_read_uint32(&p->master_lcore,
621 PARSE_ERROR((status == 0), section_name, entry->name);
626 if (strcmp(entry->name, "n") == 0) {
629 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
632 p->channels_present = 1;
634 status = parser_read_uint32(&p->channels, entry->value);
635 PARSE_ERROR((status == 0), section_name, entry->name);
640 if (strcmp(entry->name, "m") == 0) {
643 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
646 p->memory_present = 1;
648 status = parser_read_uint32(&p->memory, entry->value);
649 PARSE_ERROR((status == 0), section_name, entry->name);
654 if (strcmp(entry->name, "r") == 0) {
657 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
660 p->ranks_present = 1;
662 status = parser_read_uint32(&p->ranks, entry->value);
663 PARSE_ERROR((status == 0), section_name, entry->name);
668 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
669 (strcmp(entry->name, "b") == 0)) {
670 PARSE_ERROR_DUPLICATE((p->pci_blacklist == NULL),
673 p->pci_blacklist = strdup(entry->value);
678 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
679 (strcmp(entry->name, "w") == 0)) {
680 PARSE_ERROR_DUPLICATE((p->pci_whitelist == NULL),
683 p->pci_whitelist = strdup(entry->value);
688 if (strcmp(entry->name, "vdev") == 0) {
689 PARSE_ERROR_DUPLICATE((p->vdev == NULL),
692 p->vdev = strdup(entry->value);
697 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
700 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
703 p->vmware_tsc_map_present = 1;
705 val = parser_read_arg_bool(entry->value);
706 PARSE_ERROR((val >= 0), section_name, entry->name);
707 p->vmware_tsc_map = val;
712 if (strcmp(entry->name, "proc_type") == 0) {
713 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
716 p->proc_type = strdup(entry->value);
721 if (strcmp(entry->name, "syslog") == 0) {
722 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
725 p->syslog = strdup(entry->value);
730 if (strcmp(entry->name, "log_level") == 0) {
733 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
736 p->log_level_present = 1;
738 status = parser_read_uint32(&p->log_level,
740 PARSE_ERROR((status == 0), section_name, entry->name);
745 if (strcmp(entry->name, "v") == 0) {
748 PARSE_ERROR_DUPLICATE((p->version_present == 0),
751 p->version_present = 1;
753 val = parser_read_arg_bool(entry->value);
754 PARSE_ERROR((val >= 0), section_name, entry->name);
760 if ((strcmp(entry->name, "help") == 0) ||
761 (strcmp(entry->name, "h") == 0)) {
764 PARSE_ERROR_DUPLICATE((p->help_present == 0),
769 val = parser_read_arg_bool(entry->value);
770 PARSE_ERROR((val >= 0), section_name, entry->name);
776 if (strcmp(entry->name, "no_huge") == 0) {
779 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
782 p->no_huge_present = 1;
784 val = parser_read_arg_bool(entry->value);
785 PARSE_ERROR((val >= 0), section_name, entry->name);
791 if (strcmp(entry->name, "no_pci") == 0) {
794 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
797 p->no_pci_present = 1;
799 val = parser_read_arg_bool(entry->value);
800 PARSE_ERROR((val >= 0), section_name, entry->name);
806 if (strcmp(entry->name, "no_hpet") == 0) {
809 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
812 p->no_hpet_present = 1;
814 val = parser_read_arg_bool(entry->value);
815 PARSE_ERROR((val >= 0), section_name, entry->name);
821 if (strcmp(entry->name, "no_shconf") == 0) {
824 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
827 p->no_shconf_present = 1;
829 val = parser_read_arg_bool(entry->value);
830 PARSE_ERROR((val >= 0), section_name, entry->name);
836 if (strcmp(entry->name, "d") == 0) {
837 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
840 p->add_driver = strdup(entry->value);
845 if (strcmp(entry->name, "socket_mem") == 0) {
846 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
849 p->socket_mem = strdup(entry->value);
854 if (strcmp(entry->name, "huge_dir") == 0) {
855 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
858 p->huge_dir = strdup(entry->value);
863 if (strcmp(entry->name, "file_prefix") == 0) {
864 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
867 p->file_prefix = strdup(entry->value);
872 if (strcmp(entry->name, "base_virtaddr") == 0) {
873 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
876 p->base_virtaddr = strdup(entry->value);
881 if (strcmp(entry->name, "create_uio_dev") == 0) {
884 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
887 p->create_uio_dev_present = 1;
889 val = parser_read_arg_bool(entry->value);
890 PARSE_ERROR((val >= 0), section_name, entry->name);
891 p->create_uio_dev = val;
896 if (strcmp(entry->name, "vfio_intr") == 0) {
897 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
900 p->vfio_intr = strdup(entry->value);
905 if (strcmp(entry->name, "xen_dom0") == 0) {
908 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
911 p->xen_dom0_present = 1;
913 val = parser_read_arg_bool(entry->value);
914 PARSE_ERROR((val >= 0), section_name, entry->name);
920 PARSE_ERROR_INVALID(0, section_name, entry->name);
927 parse_pipeline_pktq_in(struct app_params *app,
928 struct app_pipeline_params *p,
931 const char *next = value;
933 char name[APP_PARAM_NAME_SIZE];
936 while (*next != '\0') {
937 enum app_pktq_in_type type;
940 end = strchr(next, ' ');
942 name_len = strlen(next);
944 name_len = end - next;
946 if (name_len == 0 || name_len == sizeof(name))
949 strncpy(name, next, name_len);
950 name[name_len] = '\0';
955 if (validate_name(name, "RXQ", 2) == 0) {
956 type = APP_PKTQ_IN_HWQ;
957 id = APP_PARAM_ADD(app->hwq_in_params, name);
958 } else if (validate_name(name, "SWQ", 1) == 0) {
959 type = APP_PKTQ_IN_SWQ;
960 id = APP_PARAM_ADD(app->swq_params, name);
961 } else if (validate_name(name, "TM", 1) == 0) {
962 type = APP_PKTQ_IN_TM;
963 id = APP_PARAM_ADD(app->tm_params, name);
964 } else if (validate_name(name, "SOURCE", 1) == 0) {
965 type = APP_PKTQ_IN_SOURCE;
966 id = APP_PARAM_ADD(app->source_params, name);
973 p->pktq_in[p->n_pktq_in].type = type;
974 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
982 parse_pipeline_pktq_out(struct app_params *app,
983 struct app_pipeline_params *p,
986 const char *next = value;
988 char name[APP_PARAM_NAME_SIZE];
991 while (*next != '\0') {
992 enum app_pktq_out_type type;
995 end = strchr(next, ' ');
997 name_len = strlen(next);
999 name_len = end - next;
1001 if (name_len == 0 || name_len == sizeof(name))
1004 strncpy(name, next, name_len);
1005 name[name_len] = '\0';
1010 if (validate_name(name, "TXQ", 2) == 0) {
1011 type = APP_PKTQ_OUT_HWQ;
1012 id = APP_PARAM_ADD(app->hwq_out_params, name);
1013 } else if (validate_name(name, "SWQ", 1) == 0) {
1014 type = APP_PKTQ_OUT_SWQ;
1015 id = APP_PARAM_ADD(app->swq_params, name);
1016 } else if (validate_name(name, "TM", 1) == 0) {
1017 type = APP_PKTQ_OUT_TM;
1018 id = APP_PARAM_ADD(app->tm_params, name);
1019 } else if (validate_name(name, "SINK", 1) == 0) {
1020 type = APP_PKTQ_OUT_SINK;
1021 id = APP_PARAM_ADD(app->sink_params, name);
1028 p->pktq_out[p->n_pktq_out].type = type;
1029 p->pktq_out[p->n_pktq_out].id = id;
1037 parse_pipeline_msgq_in(struct app_params *app,
1038 struct app_pipeline_params *p,
1041 const char *next = value;
1043 char name[APP_PARAM_NAME_SIZE];
1047 while (*next != '\0') {
1048 end = strchr(next, ' ');
1050 name_len = strlen(next);
1052 name_len = end - next;
1054 if (name_len == 0 || name_len == sizeof(name))
1057 strncpy(name, next, name_len);
1058 name[name_len] = '\0';
1063 if (validate_name(name, "MSGQ", 1) != 0)
1066 idx = APP_PARAM_ADD(app->msgq_params, name);
1070 p->msgq_in[p->n_msgq_in] = idx;
1078 parse_pipeline_msgq_out(struct app_params *app,
1079 struct app_pipeline_params *p,
1082 const char *next = value;
1084 char name[APP_PARAM_NAME_SIZE];
1088 while (*next != '\0') {
1089 end = strchr(next, ' ');
1091 name_len = strlen(next);
1093 name_len = end - next;
1095 if (name_len == 0 || name_len == sizeof(name))
1098 strncpy(name, next, name_len);
1099 name[name_len] = '\0';
1104 if (validate_name(name, "MSGQ", 1) != 0)
1107 idx = APP_PARAM_ADD(app->msgq_params, name);
1111 p->msgq_out[p->n_msgq_out] = idx;
1120 parse_pipeline(struct app_params *app,
1121 const char *section_name,
1122 struct rte_cfgfile *cfg)
1124 char name[CFG_NAME_LEN];
1125 struct app_pipeline_params *param;
1126 struct rte_cfgfile_entry *entries;
1128 int n_entries, ret, i;
1130 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1131 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1133 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1134 PARSE_ERROR_MALLOC(entries != NULL);
1136 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1138 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1139 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1141 param = &app->pipeline_params[param_idx];
1144 for (i = 0; i < n_entries; i++) {
1145 struct rte_cfgfile_entry *ent = &entries[i];
1147 if (strcmp(ent->name, "type") == 0) {
1148 ret = snprintf(param->type,
1149 RTE_DIM(param->type),
1152 if ((ret > 0) && (ret < (int)RTE_DIM(param->type)))
1156 } else if (strcmp(ent->name, "core") == 0)
1157 ret = parse_pipeline_core(¶m->socket_id,
1159 ¶m->hyper_th_id,
1161 else if (strcmp(ent->name, "pktq_in") == 0)
1162 ret = parse_pipeline_pktq_in(app, param, ent->value);
1163 else if (strcmp(ent->name, "pktq_out") == 0)
1164 ret = parse_pipeline_pktq_out(app, param, ent->value);
1165 else if (strcmp(ent->name, "msgq_in") == 0)
1166 ret = parse_pipeline_msgq_in(app, param, ent->value);
1167 else if (strcmp(ent->name, "msgq_out") == 0)
1168 ret = parse_pipeline_msgq_out(app, param, ent->value);
1169 else if (strcmp(ent->name, "timer_period") == 0)
1170 ret = parser_read_uint32(¶m->timer_period,
1173 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1174 "CFG: [%s] out of memory",
1177 param->args_name[param->n_args] = strdup(ent->name);
1178 param->args_value[param->n_args] = strdup(ent->value);
1180 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1181 (param->args_value[param->n_args] != NULL),
1182 "CFG: [%s] out of memory",
1190 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1196 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1197 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1198 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1199 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1200 param->msgq_in[param->n_msgq_in++] = param_idx;
1202 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1203 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1204 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1205 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1206 param->msgq_out[param->n_msgq_out++] = param_idx;
1208 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1211 (param->hyper_th_id) ? "h" : "");
1212 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1213 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1214 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1216 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1219 (param->hyper_th_id) ? "h" : "");
1220 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1221 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1222 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1228 parse_mempool(struct app_params *app,
1229 const char *section_name,
1230 struct rte_cfgfile *cfg)
1232 struct app_mempool_params *param;
1233 struct rte_cfgfile_entry *entries;
1235 int n_entries, ret, i;
1237 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1238 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1240 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1241 PARSE_ERROR_MALLOC(entries != NULL);
1243 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1245 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1246 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1248 param = &app->mempool_params[param_idx];
1251 for (i = 0; i < n_entries; i++) {
1252 struct rte_cfgfile_entry *ent = &entries[i];
1255 if (strcmp(ent->name, "buffer_size") == 0)
1256 ret = parser_read_uint32(¶m->buffer_size,
1258 else if (strcmp(ent->name, "pool_size") == 0)
1259 ret = parser_read_uint32(¶m->pool_size,
1261 else if (strcmp(ent->name, "cache_size") == 0)
1262 ret = parser_read_uint32(¶m->cache_size,
1264 else if (strcmp(ent->name, "cpu") == 0)
1265 ret = parser_read_uint32(¶m->cpu_socket_id,
1268 APP_CHECK(ret != -ESRCH,
1269 "CFG: [%s] entry '%s': unknown entry\n",
1273 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1283 parse_link(struct app_params *app,
1284 const char *section_name,
1285 struct rte_cfgfile *cfg)
1287 struct app_link_params *param;
1288 struct rte_cfgfile_entry *entries;
1289 int n_entries, ret, i;
1292 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1293 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1295 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1296 PARSE_ERROR_MALLOC(entries != NULL);
1298 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1300 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1301 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1303 param = &app->link_params[param_idx];
1306 for (i = 0; i < n_entries; i++) {
1307 struct rte_cfgfile_entry *ent = &entries[i];
1310 if (strcmp(ent->name, "promisc") == 0) {
1311 ret = parser_read_arg_bool(ent->value);
1313 param->promisc = ret;
1316 } else if (strcmp(ent->name, "arp_q") == 0)
1317 ret = parser_read_uint32(¶m->arp_q,
1319 else if (strcmp(ent->name, "tcp_syn_q") == 0)
1320 ret = parser_read_uint32(¶m->tcp_syn_local_q,
1322 else if (strcmp(ent->name, "ip_local_q") == 0)
1323 ret = parser_read_uint32(¶m->ip_local_q,
1325 else if (strcmp(ent->name, "tcp_local_q") == 0)
1326 ret = parser_read_uint32(¶m->tcp_local_q,
1328 else if (strcmp(ent->name, "udp_local_q") == 0)
1329 ret = parser_read_uint32(¶m->udp_local_q,
1331 else if (strcmp(ent->name, "sctp_local_q") == 0)
1332 ret = parser_read_uint32(¶m->sctp_local_q,
1335 APP_CHECK(ret != -ESRCH,
1336 "CFG: [%s] entry '%s': unknown entry\n",
1340 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1350 parse_rxq(struct app_params *app,
1351 const char *section_name,
1352 struct rte_cfgfile *cfg)
1354 struct app_pktq_hwq_in_params *param;
1355 struct rte_cfgfile_entry *entries;
1356 int n_entries, ret, i;
1359 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1360 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1362 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1363 PARSE_ERROR_MALLOC(entries != NULL);
1365 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1367 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1368 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1370 param = &app->hwq_in_params[param_idx];
1373 for (i = 0; i < n_entries; i++) {
1374 struct rte_cfgfile_entry *ent = &entries[i];
1377 if (strcmp(ent->name, "mempool") == 0) {
1378 int status = validate_name(ent->value, "MEMPOOL", 1);
1381 APP_CHECK((status == 0),
1382 "CFG: [%s] entry '%s': invalid mempool\n",
1386 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1387 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1388 param->mempool_id = idx;
1390 } else if (strcmp(ent->name, "size") == 0)
1391 ret = parser_read_uint32(¶m->size,
1393 else if (strcmp(ent->name, "burst") == 0)
1394 ret = parser_read_uint32(¶m->burst,
1397 APP_CHECK(ret != -ESRCH,
1398 "CFG: [%s] entry '%s': unknown entry\n",
1402 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1412 parse_txq(struct app_params *app,
1413 const char *section_name,
1414 struct rte_cfgfile *cfg)
1416 struct app_pktq_hwq_out_params *param;
1417 struct rte_cfgfile_entry *entries;
1418 int n_entries, ret, i;
1421 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1422 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1424 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1425 PARSE_ERROR_MALLOC(entries != NULL);
1427 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1429 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1430 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1432 param = &app->hwq_out_params[param_idx];
1435 for (i = 0; i < n_entries; i++) {
1436 struct rte_cfgfile_entry *ent = &entries[i];
1439 if (strcmp(ent->name, "size") == 0)
1440 ret = parser_read_uint32(¶m->size, ent->value);
1441 else if (strcmp(ent->name, "burst") == 0)
1442 ret = parser_read_uint32(¶m->burst, ent->value);
1443 else if (strcmp(ent->name, "dropless") == 0) {
1444 ret = parser_read_arg_bool(ent->value);
1446 param->dropless = ret;
1451 APP_CHECK(ret != -ESRCH,
1452 "CFG: [%s] entry '%s': unknown entry\n",
1456 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1466 parse_swq(struct app_params *app,
1467 const char *section_name,
1468 struct rte_cfgfile *cfg)
1470 struct app_pktq_swq_params *param;
1471 struct rte_cfgfile_entry *entries;
1472 int n_entries, ret, i;
1473 unsigned frag_entries = 0;
1476 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1477 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1479 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1480 PARSE_ERROR_MALLOC(entries != NULL);
1482 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1484 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1485 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1487 param = &app->swq_params[param_idx];
1490 for (i = 0; i < n_entries; i++) {
1491 struct rte_cfgfile_entry *ent = &entries[i];
1494 if (strcmp(ent->name, "size") == 0)
1495 ret = parser_read_uint32(¶m->size,
1497 else if (strcmp(ent->name, "burst_read") == 0)
1498 ret = parser_read_uint32(¶m->burst_read,
1500 else if (strcmp(ent->name, "burst_write") == 0)
1501 ret = parser_read_uint32(¶m->burst_write,
1503 else if (strcmp(ent->name, "dropless") == 0) {
1504 ret = parser_read_arg_bool(ent->value);
1506 param->dropless = ret;
1509 } else if (strcmp(ent->name, "n_retries") == 0)
1510 ret = parser_read_uint64(¶m->n_retries,
1512 else if (strcmp(ent->name, "cpu") == 0)
1513 ret = parser_read_uint32(¶m->cpu_socket_id,
1515 else if (strcmp(ent->name, "ipv4_frag") == 0) {
1516 ret = parser_read_arg_bool(ent->value);
1518 param->ipv4_frag = ret;
1519 if (param->mtu == 0)
1523 } else if (strcmp(ent->name, "ipv6_frag") == 0) {
1524 ret = parser_read_arg_bool(ent->value);
1526 param->ipv6_frag = ret;
1527 if (param->mtu == 0)
1531 } else if (strcmp(ent->name, "ipv4_ras") == 0) {
1532 ret = parser_read_arg_bool(ent->value);
1534 param->ipv4_ras = ret;
1537 } else if (strcmp(ent->name, "ipv6_ras") == 0) {
1538 ret = parser_read_arg_bool(ent->value);
1540 param->ipv6_ras = ret;
1543 } else if (strcmp(ent->name, "mtu") == 0) {
1545 ret = parser_read_uint32(¶m->mtu,
1547 } else if (strcmp(ent->name, "metadata_size") == 0) {
1549 ret = parser_read_uint32(¶m->metadata_size,
1551 } else if (strcmp(ent->name, "mempool_direct") == 0) {
1552 int status = validate_name(ent->value, "MEMPOOL", 1);
1555 APP_CHECK((status == 0),
1556 "CFG: [%s] entry '%s': invalid mempool\n",
1560 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1561 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1562 param->mempool_direct_id = idx;
1565 } else if (strcmp(ent->name, "mempool_indirect") == 0) {
1566 int status = validate_name(ent->value, "MEMPOOL", 1);
1569 APP_CHECK((status == 0),
1570 "CFG: [%s] entry '%s': invalid mempool\n",
1574 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1575 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1576 param->mempool_indirect_id = idx;
1581 APP_CHECK(ret != -ESRCH,
1582 "CFG: [%s] entry '%s': unknown entry\n",
1586 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1592 if (frag_entries == 1) {
1593 APP_CHECK(((param->ipv4_frag == 1) || (param->ipv6_frag == 1)),
1594 "CFG: [%s] ipv4/ipv6 frag is off : unsupported entries on this"
1603 parse_tm(struct app_params *app,
1604 const char *section_name,
1605 struct rte_cfgfile *cfg)
1607 struct app_pktq_tm_params *param;
1608 struct rte_cfgfile_entry *entries;
1609 int n_entries, ret, i;
1612 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1613 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1615 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1616 PARSE_ERROR_MALLOC(entries != NULL);
1618 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1620 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1621 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
1623 param = &app->tm_params[param_idx];
1626 for (i = 0; i < n_entries; i++) {
1627 struct rte_cfgfile_entry *ent = &entries[i];
1630 if (strcmp(ent->name, "cfg") == 0) {
1631 param->file_name = strdup(ent->value);
1632 if (param->file_name == NULL)
1636 } else if (strcmp(ent->name, "burst_read") == 0)
1637 ret = parser_read_uint32(¶m->burst_read,
1639 else if (strcmp(ent->name, "burst_write") == 0)
1640 ret = parser_read_uint32(¶m->burst_write,
1643 APP_CHECK(ret != -ESRCH,
1644 "CFG: [%s] entry '%s': unknown entry\n",
1647 APP_CHECK(ret != -EBADF,
1648 "CFG: [%s] entry '%s': TM cfg parse error '%s'\n",
1653 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1663 parse_source(struct app_params *app,
1664 const char *section_name,
1665 struct rte_cfgfile *cfg)
1667 struct app_pktq_source_params *param;
1668 struct rte_cfgfile_entry *entries;
1669 int n_entries, ret, i;
1672 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1673 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1675 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1676 PARSE_ERROR_MALLOC(entries != NULL);
1678 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1680 param_idx = APP_PARAM_ADD(app->source_params, section_name);
1681 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
1683 param = &app->source_params[param_idx];
1686 for (i = 0; i < n_entries; i++) {
1687 struct rte_cfgfile_entry *ent = &entries[i];
1690 if (strcmp(ent->name, "mempool") == 0) {
1691 int status = validate_name(ent->value, "MEMPOOL", 1);
1694 APP_CHECK((status == 0),
1695 "CFG: [%s] entry '%s': invalid mempool\n",
1699 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1700 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1701 param->mempool_id = idx;
1703 } else if (strcmp(ent->name, "burst") == 0)
1704 ret = parser_read_uint32(¶m->burst, ent->value);
1706 APP_CHECK(ret != -ESRCH,
1707 "CFG: [%s] entry '%s': unknown entry\n",
1711 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1721 parse_msgq_req_pipeline(struct app_params *app,
1722 const char *section_name,
1723 struct rte_cfgfile *cfg)
1725 struct app_msgq_params *param;
1726 struct rte_cfgfile_entry *entries;
1727 int n_entries, ret, i;
1730 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1731 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1733 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1734 PARSE_ERROR_MALLOC(entries != NULL);
1736 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1738 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1739 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1741 param = &app->msgq_params[param_idx];
1744 for (i = 0; i < n_entries; i++) {
1745 struct rte_cfgfile_entry *ent = &entries[i];
1748 if (strcmp(ent->name, "size") == 0)
1749 ret = parser_read_uint32(¶m->size, ent->value);
1751 APP_CHECK(ret != -ESRCH,
1752 "CFG: [%s] entry '%s': unknown entry\n",
1756 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1766 parse_msgq_rsp_pipeline(struct app_params *app,
1767 const char *section_name,
1768 struct rte_cfgfile *cfg)
1770 struct app_msgq_params *param;
1771 struct rte_cfgfile_entry *entries;
1772 int n_entries, ret, i;
1775 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1776 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1778 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1779 PARSE_ERROR_MALLOC(entries != NULL);
1781 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1783 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1784 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1786 param = &app->msgq_params[param_idx];
1789 for (i = 0; i < n_entries; i++) {
1790 struct rte_cfgfile_entry *ent = &entries[i];
1793 if (strcmp(ent->name, "size") == 0)
1794 ret = parser_read_uint32(¶m->size, ent->value);
1796 APP_CHECK(ret != -ESRCH,
1797 "CFG: [%s] entry '%s': unknown entry\n",
1801 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1811 parse_msgq(struct app_params *app,
1812 const char *section_name,
1813 struct rte_cfgfile *cfg)
1815 struct app_msgq_params *param;
1816 struct rte_cfgfile_entry *entries;
1817 int n_entries, ret, i;
1820 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1821 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1823 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1824 PARSE_ERROR_MALLOC(entries != NULL);
1826 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1828 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1829 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1831 param = &app->msgq_params[param_idx];
1834 for (i = 0; i < n_entries; i++) {
1835 struct rte_cfgfile_entry *ent = &entries[i];
1838 if (strcmp(ent->name, "size") == 0)
1839 ret = parser_read_uint32(¶m->size,
1841 else if (strcmp(ent->name, "cpu") == 0)
1842 ret = parser_read_uint32(¶m->cpu_socket_id,
1845 APP_CHECK(ret != -ESRCH,
1846 "CFG: [%s] entry '%s': unknown entry\n",
1850 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1859 typedef void (*config_section_load)(struct app_params *p,
1860 const char *section_name,
1861 struct rte_cfgfile *cfg);
1863 struct config_section {
1864 const char prefix[CFG_NAME_LEN];
1866 config_section_load load;
1869 static const struct config_section cfg_file_scheme[] = {
1870 {"EAL", 0, parse_eal},
1871 {"PIPELINE", 1, parse_pipeline},
1872 {"MEMPOOL", 1, parse_mempool},
1873 {"LINK", 1, parse_link},
1874 {"RXQ", 2, parse_rxq},
1875 {"TXQ", 2, parse_txq},
1876 {"SWQ", 1, parse_swq},
1877 {"TM", 1, parse_tm},
1878 {"SOURCE", 1, parse_source},
1879 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
1880 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
1881 {"MSGQ", 1, parse_msgq},
1885 create_implicit_mempools(struct app_params *app)
1889 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
1890 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, "start-up");
1894 parse_port_mask(struct app_params *app, uint64_t port_mask)
1896 uint32_t pmd_id, link_id;
1899 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
1900 char name[APP_PARAM_NAME_SIZE];
1903 if ((port_mask & (1LLU << pmd_id)) == 0)
1906 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
1907 idx = APP_PARAM_ADD(app->link_params, name);
1908 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, name);
1910 app->link_params[idx].pmd_id = pmd_id;
1916 app_config_parse(struct app_params *app, const char *file_name)
1918 struct rte_cfgfile *cfg;
1919 char **section_names;
1920 int i, j, sect_count;
1922 /* Implicit mempools */
1923 create_implicit_mempools(app);
1926 parse_port_mask(app, app->port_mask);
1928 /* Load application configuration file */
1929 cfg = rte_cfgfile_load(file_name, 0);
1930 APP_CHECK(cfg != NULL, "Unable to load config file %s", file_name);
1932 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
1933 APP_CHECK(sect_count > 0, "Number of sections return %d", sect_count);
1935 section_names = malloc(sect_count * sizeof(char *));
1936 APP_CHECK(section_names != NULL, "Failed to allocate memory");
1938 for (i = 0; i < sect_count; i++)
1939 section_names[i] = malloc(CFG_NAME_LEN);
1941 rte_cfgfile_sections(cfg, section_names, sect_count);
1943 for (i = 0; i < sect_count; i++) {
1944 const struct config_section *sch_s;
1945 int len, cfg_name_len;
1947 cfg_name_len = strlen(section_names[i]);
1949 /* Find section type */
1950 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
1951 sch_s = &cfg_file_scheme[j];
1952 len = strlen(sch_s->prefix);
1954 if (cfg_name_len < len)
1957 /* After section name we expect only '\0' or digit or
1958 * digit dot digit, so protect against false matching,
1959 * for example: "ABC" should match section name
1960 * "ABC0.0", but it should not match section_name
1963 if ((section_names[i][len] != '\0') &&
1964 !isdigit(section_names[i][len]))
1967 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
1971 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
1972 "Unknown section %s",
1975 APP_CHECK(validate_name(section_names[i],
1977 sch_s->numbers) == 0,
1978 "Invalid section name '%s'",
1981 sch_s->load(app, section_names[i], cfg);
1984 for (i = 0; i < sect_count; i++)
1985 free(section_names[i]);
1987 free(section_names);
1989 rte_cfgfile_close(cfg);
1991 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
1992 APP_PARAM_COUNT(app->link_params, app->n_links);
1993 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
1994 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
1995 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
1996 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
1997 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
1998 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
1999 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2000 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2002 /* Save configuration to output file */
2003 app_config_save(app, app->output_file);
2005 /* Load TM configuration files */
2006 app_config_parse_tm(app);
2012 save_eal_params(struct app_params *app, FILE *f)
2014 struct app_eal_params *p = &app->eal_params;
2016 fprintf(f, "[EAL]\n");
2019 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2021 if (p->master_lcore_present)
2022 fprintf(f, "%s = %" PRIu32 "\n",
2023 "master_lcore", p->master_lcore);
2025 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2027 if (p->memory_present)
2028 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2030 if (p->ranks_present)
2031 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2033 if (p->pci_blacklist)
2034 fprintf(f, "%s = %s\n", "pci_blacklist", p->pci_blacklist);
2036 if (p->pci_whitelist)
2037 fprintf(f, "%s = %s\n", "pci_whitelist", p->pci_whitelist);
2040 fprintf(f, "%s = %s\n", "vdev", p->vdev);
2042 if (p->vmware_tsc_map_present)
2043 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2044 (p->vmware_tsc_map) ? "yes" : "no");
2047 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2050 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2052 if (p->log_level_present)
2053 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2055 if (p->version_present)
2056 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2058 if (p->help_present)
2059 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2061 if (p->no_huge_present)
2062 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2064 if (p->no_pci_present)
2065 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2067 if (p->no_hpet_present)
2068 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2070 if (p->no_shconf_present)
2071 fprintf(f, "%s = %s\n", "no_shconf",
2072 (p->no_shconf) ? "yes" : "no");
2075 fprintf(f, "%s = %s\n", "d", p->add_driver);
2078 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2081 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2084 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2086 if (p->base_virtaddr)
2087 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2089 if (p->create_uio_dev_present)
2090 fprintf(f, "%s = %s\n", "create_uio_dev",
2091 (p->create_uio_dev) ? "yes" : "no");
2094 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2096 if (p->xen_dom0_present)
2097 fprintf(f, "%s = %s\n", "xen_dom0",
2098 (p->xen_dom0) ? "yes" : "no");
2104 save_mempool_params(struct app_params *app, FILE *f)
2106 struct app_mempool_params *p;
2109 count = RTE_DIM(app->mempool_params);
2110 for (i = 0; i < count; i++) {
2111 p = &app->mempool_params[i];
2112 if (!APP_PARAM_VALID(p))
2115 fprintf(f, "[%s]\n", p->name);
2116 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2117 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2118 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2119 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2126 save_links_params(struct app_params *app, FILE *f)
2128 struct app_link_params *p;
2131 count = RTE_DIM(app->link_params);
2132 for (i = 0; i < count; i++) {
2133 p = &app->link_params[i];
2134 if (!APP_PARAM_VALID(p))
2137 fprintf(f, "[%s]\n", p->name);
2138 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2139 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2140 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2141 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_local_q",
2142 p->tcp_syn_local_q);
2143 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2144 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2145 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2146 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2154 save_rxq_params(struct app_params *app, FILE *f)
2156 struct app_pktq_hwq_in_params *p;
2159 count = RTE_DIM(app->hwq_in_params);
2160 for (i = 0; i < count; i++) {
2161 p = &app->hwq_in_params[i];
2162 if (!APP_PARAM_VALID(p))
2165 fprintf(f, "[%s]\n", p->name);
2166 fprintf(f, "%s = %s\n",
2168 app->mempool_params[p->mempool_id].name);
2169 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2170 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2177 save_txq_params(struct app_params *app, FILE *f)
2179 struct app_pktq_hwq_out_params *p;
2182 count = RTE_DIM(app->hwq_out_params);
2183 for (i = 0; i < count; i++) {
2184 p = &app->hwq_out_params[i];
2185 if (!APP_PARAM_VALID(p))
2188 fprintf(f, "[%s]\n", p->name);
2189 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2190 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2191 fprintf(f, "%s = %s\n",
2193 p->dropless ? "yes" : "no");
2200 save_swq_params(struct app_params *app, FILE *f)
2202 struct app_pktq_swq_params *p;
2205 count = RTE_DIM(app->swq_params);
2206 for (i = 0; i < count; i++) {
2207 p = &app->swq_params[i];
2208 if (!APP_PARAM_VALID(p))
2211 fprintf(f, "[%s]\n", p->name);
2212 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2213 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2214 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2215 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2216 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2217 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2218 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2219 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2220 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2221 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2222 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2223 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2224 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2225 fprintf(f, "%s = %s\n",
2227 app->mempool_params[p->mempool_direct_id].name);
2228 fprintf(f, "%s = %s\n",
2230 app->mempool_params[p->mempool_indirect_id].name);
2238 save_tm_params(struct app_params *app, FILE *f)
2240 struct app_pktq_tm_params *p;
2243 count = RTE_DIM(app->tm_params);
2244 for (i = 0; i < count; i++) {
2245 p = &app->tm_params[i];
2246 if (!APP_PARAM_VALID(p))
2249 fprintf(f, "[%s]\n", p->name);
2250 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2251 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2252 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2259 save_source_params(struct app_params *app, FILE *f)
2261 struct app_pktq_source_params *p;
2264 count = RTE_DIM(app->source_params);
2265 for (i = 0; i < count; i++) {
2266 p = &app->source_params[i];
2267 if (!APP_PARAM_VALID(p))
2270 fprintf(f, "[%s]\n", p->name);
2271 fprintf(f, "%s = %s\n",
2273 app->mempool_params[p->mempool_id].name);
2274 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2280 save_msgq_params(struct app_params *app, FILE *f)
2282 struct app_msgq_params *p;
2285 count = RTE_DIM(app->msgq_params);
2286 for (i = 0; i < count; i++) {
2287 p = &app->msgq_params[i];
2288 if (!APP_PARAM_VALID(p))
2291 fprintf(f, "[%s]\n", p->name);
2292 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2293 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2300 save_pipeline_params(struct app_params *app, FILE *f)
2304 count = RTE_DIM(app->pipeline_params);
2305 for (i = 0; i < count; i++) {
2306 struct app_pipeline_params *p = &app->pipeline_params[i];
2308 if (!APP_PARAM_VALID(p))
2312 fprintf(f, "[%s]\n", p->name);
2315 fprintf(f, "type = %s\n", p->type);
2318 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2321 (p->hyper_th_id) ? "h" : "");
2327 fprintf(f, "pktq_in =");
2328 for (j = 0; j < p->n_pktq_in; j++) {
2329 struct app_pktq_in_params *pp = &p->pktq_in[j];
2333 case APP_PKTQ_IN_HWQ:
2334 name = app->hwq_in_params[pp->id].name;
2336 case APP_PKTQ_IN_SWQ:
2337 name = app->swq_params[pp->id].name;
2339 case APP_PKTQ_IN_TM:
2340 name = app->tm_params[pp->id].name;
2342 case APP_PKTQ_IN_SOURCE:
2343 name = app->source_params[pp->id].name;
2346 APP_CHECK(0, "Error\n");
2349 fprintf(f, " %s", name);
2355 if (p->n_pktq_out) {
2358 fprintf(f, "pktq_out =");
2359 for (j = 0; j < p->n_pktq_out; j++) {
2360 struct app_pktq_out_params *pp =
2365 case APP_PKTQ_OUT_HWQ:
2366 name = app->hwq_out_params[pp->id].name;
2368 case APP_PKTQ_OUT_SWQ:
2369 name = app->swq_params[pp->id].name;
2371 case APP_PKTQ_OUT_TM:
2372 name = app->tm_params[pp->id].name;
2374 case APP_PKTQ_OUT_SINK:
2375 name = app->sink_params[pp->id].name;
2378 APP_CHECK(0, "Error\n");
2381 fprintf(f, " %s", name);
2390 fprintf(f, "msgq_in =");
2391 for (j = 0; j < p->n_msgq_in; j++) {
2392 uint32_t id = p->msgq_in[j];
2393 char *name = app->msgq_params[id].name;
2395 fprintf(f, " %s", name);
2404 fprintf(f, "msgq_out =");
2405 for (j = 0; j < p->n_msgq_out; j++) {
2406 uint32_t id = p->msgq_out[j];
2407 char *name = app->msgq_params[id].name;
2409 fprintf(f, " %s", name);
2415 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2421 for (j = 0; j < p->n_args; j++)
2422 fprintf(f, "%s = %s\n", p->args_name[j],
2431 app_config_save(struct app_params *app, const char *file_name)
2434 char *name, *dir_name;
2437 name = strdup(file_name);
2438 dir_name = dirname(name);
2439 status = access(dir_name, W_OK);
2440 APP_CHECK((status == 0),
2441 "Need write access to directory \"%s\" to save configuration\n",
2444 file = fopen(file_name, "w");
2445 APP_CHECK((file != NULL),
2446 "Failed to save configuration to file \"%s\"", file_name);
2448 save_eal_params(app, file);
2449 save_pipeline_params(app, file);
2450 save_mempool_params(app, file);
2451 save_links_params(app, file);
2452 save_rxq_params(app, file);
2453 save_txq_params(app, file);
2454 save_swq_params(app, file);
2455 save_tm_params(app, file);
2456 save_source_params(app, file);
2457 save_msgq_params(app, file);
2464 app_config_init(struct app_params *app)
2468 memcpy(app, &app_params_default, sizeof(struct app_params));
2470 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2471 memcpy(&app->mempool_params[i],
2472 &mempool_params_default,
2473 sizeof(struct app_mempool_params));
2475 for (i = 0; i < RTE_DIM(app->link_params); i++)
2476 memcpy(&app->link_params[i],
2477 &link_params_default,
2478 sizeof(struct app_link_params));
2480 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2481 memcpy(&app->hwq_in_params[i],
2482 &default_hwq_in_params,
2483 sizeof(default_hwq_in_params));
2485 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2486 memcpy(&app->hwq_out_params[i],
2487 &default_hwq_out_params,
2488 sizeof(default_hwq_out_params));
2490 for (i = 0; i < RTE_DIM(app->swq_params); i++)
2491 memcpy(&app->swq_params[i],
2492 &default_swq_params,
2493 sizeof(default_swq_params));
2495 for (i = 0; i < RTE_DIM(app->tm_params); i++)
2496 memcpy(&app->tm_params[i],
2498 sizeof(default_tm_params));
2500 for (i = 0; i < RTE_DIM(app->source_params); i++)
2501 memcpy(&app->source_params[i],
2502 &default_source_params,
2503 sizeof(default_source_params));
2505 for (i = 0; i < RTE_DIM(app->sink_params); i++)
2506 memcpy(&app->sink_params[i],
2507 &default_sink_params,
2508 sizeof(default_sink_params));
2510 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2511 memcpy(&app->msgq_params[i],
2512 &default_msgq_params,
2513 sizeof(default_msgq_params));
2515 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2516 memcpy(&app->pipeline_params[i],
2517 &default_pipeline_params,
2518 sizeof(default_pipeline_params));
2524 filenamedup(const char *filename, const char *suffix)
2526 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2531 sprintf(s, "%s%s", filename, suffix);
2536 app_config_args(struct app_params *app, int argc, char **argv)
2538 const char *optname;
2539 int opt, option_index;
2540 int f_present, s_present, p_present, l_present;
2541 int preproc_present, preproc_params_present;
2544 static struct option lgopts[] = {
2545 { "preproc", 1, 0, 0 },
2546 { "preproc-args", 1, 0, 0 },
2550 /* Copy application name */
2551 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
2557 preproc_present = 0;
2558 preproc_params_present = 0;
2560 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
2561 &option_index)) != EOF)
2565 rte_panic("Error: Config file is provided "
2566 "more than once\n");
2569 if (!strlen(optarg))
2570 rte_panic("Error: Config file name is null\n");
2572 app->config_file = strdup(optarg);
2573 if (app->config_file == NULL)
2574 rte_panic("Error: Memory allocation failure\n");
2580 rte_panic("Error: Script file is provided "
2581 "more than once\n");
2584 if (!strlen(optarg))
2585 rte_panic("Error: Script file name is null\n");
2587 app->script_file = strdup(optarg);
2588 if (app->script_file == NULL)
2589 rte_panic("Error: Memory allocation failure\n");
2595 rte_panic("Error: PORT_MASK is provided "
2596 "more than once\n");
2599 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
2601 ((size_t) scaned != strlen(optarg)))
2602 rte_panic("Error: PORT_MASK is not "
2603 "a hexadecimal integer\n");
2605 if (app->port_mask == 0)
2606 rte_panic("Error: PORT_MASK is null\n");
2612 rte_panic("Error: LOG_LEVEL is provided "
2613 "more than once\n");
2616 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
2618 ((size_t) scaned != strlen(optarg)) ||
2619 (app->log_level >= APP_LOG_LEVELS))
2620 rte_panic("Error: LOG_LEVEL invalid value\n");
2625 optname = lgopts[option_index].name;
2627 if (strcmp(optname, "preproc") == 0) {
2628 if (preproc_present)
2629 rte_panic("Error: Preprocessor argument "
2630 "is provided more than once\n");
2631 preproc_present = 1;
2633 app->preproc = strdup(optarg);
2637 if (strcmp(optname, "preproc-args") == 0) {
2638 if (preproc_params_present)
2639 rte_panic("Error: Preprocessor args "
2640 "are provided more than once\n");
2641 preproc_params_present = 1;
2643 app->preproc_args = strdup(optarg);
2647 app_print_usage(argv[0]);
2651 app_print_usage(argv[0]);
2654 optind = 0; /* reset getopt lib */
2656 /* Check that mandatory args have been provided */
2658 rte_panic("Error: PORT_MASK is not provided\n");
2660 /* Check dependencies between args */
2661 if (preproc_params_present && (preproc_present == 0))
2662 rte_panic("Error: Preprocessor args specified while "
2663 "preprocessor is not defined\n");
2665 app->parser_file = preproc_present ?
2666 filenamedup(app->config_file, ".preproc") :
2667 strdup(app->config_file);
2668 app->output_file = filenamedup(app->config_file, ".out");
2674 app_config_preproc(struct app_params *app)
2679 if (app->preproc == NULL)
2682 status = access(app->config_file, F_OK | R_OK);
2683 APP_CHECK((status == 0), "Unable to open file %s", app->config_file);
2685 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
2687 app->preproc_args ? app->preproc_args : "",
2691 status = system(buffer);
2692 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
2693 "Error while preprocessing file \"%s\"\n", app->config_file);