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>
53 * Default config values
56 static struct app_params app_params_default = {
57 .config_file = "./config/ip_pipeline.cfg",
58 .log_level = APP_LOG_LEVEL_HIGH,
65 static const struct app_mempool_params mempool_params_default = {
67 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
68 .pool_size = 32 * 1024,
73 static const struct app_link_params link_params_default = {
91 .mq_mode = ETH_MQ_RX_NONE,
93 .header_split = 0, /* Header split */
94 .hw_ip_checksum = 0, /* IP checksum offload */
95 .hw_vlan_filter = 0, /* VLAN filtering */
96 .hw_vlan_strip = 0, /* VLAN strip */
97 .hw_vlan_extend = 0, /* Extended VLAN */
98 .jumbo_frame = 0, /* Jumbo frame support */
99 .hw_strip_crc = 0, /* CRC strip by HW */
100 .enable_scatter = 0, /* Scattered packets RX handler */
102 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
103 .split_hdr_size = 0, /* Header split buffer size */
106 .mq_mode = ETH_MQ_TX_NONE,
114 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
126 .rx_free_thresh = 64,
128 .rx_deferred_start = 0,
132 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
147 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
148 ETH_TXQ_FLAGS_NOOFFLOADS,
149 .tx_deferred_start = 0,
153 static const struct app_pktq_swq_params default_swq_params = {
167 .mempool_direct_id = 0,
168 .mempool_indirect_id = 0,
171 struct app_pktq_tm_params default_tm_params = {
173 .file_name = "./config/tm_profile.cfg",
178 struct app_pktq_source_params default_source_params = {
184 struct app_pktq_sink_params default_sink_params = {
188 struct app_msgq_params default_msgq_params = {
194 struct app_pipeline_params default_pipeline_params = {
207 static const char app_usage[] =
208 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] -p PORT_MASK "
209 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
212 "\t-f CONFIG_FILE: Default config file is %s\n"
213 "\t-p PORT_MASK: Mask of NIC port IDs in hexadecimal format\n"
214 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
215 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
216 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
217 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
221 app_print_usage(char *prgname)
223 rte_exit(0, app_usage, prgname, app_params_default.config_file);
226 #define skip_white_spaces(pos) \
228 __typeof__(pos) _p = (pos); \
229 for ( ; isspace(*_p); _p++); \
233 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
235 APP_CHECK((result != -EINVAL), \
236 "Parse error: no free memory"); \
237 APP_CHECK((result != -ENOMEM), \
238 "Parse error: too many \"%s\" sections", section_name); \
239 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
240 "Parse error: duplicate \"%s\" section", section_name); \
241 APP_CHECK((result >= 0), \
242 "Parse error in section \"%s\"", section_name); \
246 parser_read_arg_bool(const char *p)
248 p = skip_white_spaces(p);
249 int result = -EINVAL;
251 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
252 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
257 if (((p[0] == 'o') && (p[1] == 'n')) ||
258 ((p[0] == 'O') && (p[1] == 'N'))) {
263 if (((p[0] == 'n') && (p[1] == 'o')) ||
264 ((p[0] == 'N') && (p[1] == 'O'))) {
269 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
270 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
275 p = skip_white_spaces(p);
283 #define PARSE_ERROR(exp, section, entry) \
284 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
286 #define PARSE_ERROR_MALLOC(exp) \
287 APP_CHECK(exp, "Parse error: no free memory\n")
289 #define PARSE_ERROR_SECTION(exp, section) \
290 APP_CHECK(exp, "Parse error in section \"%s\"", section)
292 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
293 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
295 #define PARSE_WARNING_IGNORED(exp, section, entry) \
298 fprintf(stderr, "Parse warning in section \"%s\": " \
299 "entry \"%s\" is ignored\n", section, entry); \
302 #define PARSE_ERROR_INVALID(exp, section, entry) \
303 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
306 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
307 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
311 parser_read_uint64(uint64_t *value, const char *p)
316 p = skip_white_spaces(p);
320 val = strtoul(p, &next, 10);
342 p = skip_white_spaces(p);
351 parser_read_uint32(uint32_t *value, const char *p)
354 int ret = parser_read_uint64(&val, p);
359 if (val > UINT32_MAX)
367 parse_pipeline_core(uint32_t *socket,
375 uint32_t s = 0, c = 0, h = 0, val;
376 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
377 const char *next = skip_white_spaces(entry);
380 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
381 while (*next != '\0') {
382 /* If everything parsed nothing should left */
383 if (s_parsed && c_parsed && h_parsed)
390 if (s_parsed || c_parsed || h_parsed)
397 if (c_parsed || h_parsed)
410 /* If it start from digit it must be only core id. */
411 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
417 for (num_len = 0; *next != '\0'; next++, num_len++) {
418 if (num_len == RTE_DIM(num))
424 num[num_len] = *next;
427 if (num_len == 0 && type != 'h' && type != 'H')
430 if (num_len != 0 && (type == 'h' || type == 'H'))
434 val = strtol(num, NULL, 10);
463 case '0': case '1': case '2': case '3': case '4': case '5':
464 case '6': case '7': case '8': case '9':
466 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
468 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
476 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
481 /* Check input parameters */
489 if (((len & 3) != 0) ||
494 for (c = src; *c != 0; c++) {
495 if ((((*c) >= '0') && ((*c) <= '9')) ||
496 (((*c) >= 'A') && ((*c) <= 'F')) ||
497 (((*c) >= 'a') && ((*c) <= 'f')))
503 /* Convert chars to bytes */
504 for (i = 0; i < *size; i++)
505 dst[i] = get_hex_val(src[2 * i]) * 16 +
506 get_hex_val(src[2 * i + 1]);
512 skip_digits(const char *src)
516 for (i = 0; isdigit(src[i]); i++);
522 validate_name(const char *name, const char *prefix, int num)
526 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
527 if (name[i] != prefix[i])
531 if (prefix[i] != '\0')
542 j = skip_digits(&name[i]);
544 if ((j == 0) || (name[i] != '.'))
550 j = skip_digits(&name[i]);
552 if ((j == 0) || (name[i] != '\0'))
560 parse_eal(struct app_params *app,
561 const char *section_name,
562 struct rte_cfgfile *cfg)
564 struct app_eal_params *p = &app->eal_params;
565 struct rte_cfgfile_entry *entries;
568 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
569 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
571 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
572 PARSE_ERROR_MALLOC(entries != NULL);
574 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
576 for (i = 0; i < n_entries; i++) {
577 struct rte_cfgfile_entry *entry = &entries[i];
580 if (strcmp(entry->name, "c") == 0) {
581 PARSE_WARNING_IGNORED(0, section_name, entry->name);
586 if (strcmp(entry->name, "l") == 0) {
587 PARSE_WARNING_IGNORED(0, section_name, entry->name);
592 if (strcmp(entry->name, "lcores") == 0) {
593 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
596 p->coremap = strdup(entry->value);
601 if (strcmp(entry->name, "master_lcore") == 0) {
604 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
607 p->master_lcore_present = 1;
609 status = parser_read_uint32(&p->master_lcore,
611 PARSE_ERROR((status == 0), section_name, entry->name);
616 if (strcmp(entry->name, "n") == 0) {
619 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
622 p->channels_present = 1;
624 status = parser_read_uint32(&p->channels, entry->value);
625 PARSE_ERROR((status == 0), section_name, entry->name);
630 if (strcmp(entry->name, "m") == 0) {
633 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
636 p->memory_present = 1;
638 status = parser_read_uint32(&p->memory, entry->value);
639 PARSE_ERROR((status == 0), section_name, entry->name);
644 if (strcmp(entry->name, "r") == 0) {
647 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
650 p->ranks_present = 1;
652 status = parser_read_uint32(&p->ranks, entry->value);
653 PARSE_ERROR((status == 0), section_name, entry->name);
658 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
659 (strcmp(entry->name, "b") == 0)) {
660 PARSE_ERROR_DUPLICATE((p->pci_blacklist == NULL),
663 p->pci_blacklist = strdup(entry->value);
668 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
669 (strcmp(entry->name, "w") == 0)) {
670 PARSE_ERROR_DUPLICATE((p->pci_whitelist == NULL),
673 p->pci_whitelist = strdup(entry->value);
678 if (strcmp(entry->name, "vdev") == 0) {
679 PARSE_ERROR_DUPLICATE((p->vdev == NULL),
682 p->vdev = strdup(entry->value);
687 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
690 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
693 p->vmware_tsc_map_present = 1;
695 val = parser_read_arg_bool(entry->value);
696 PARSE_ERROR((val >= 0), section_name, entry->name);
697 p->vmware_tsc_map = val;
702 if (strcmp(entry->name, "proc_type") == 0) {
703 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
706 p->proc_type = strdup(entry->value);
711 if (strcmp(entry->name, "syslog") == 0) {
712 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
715 p->syslog = strdup(entry->value);
720 if (strcmp(entry->name, "log_level") == 0) {
723 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
726 p->log_level_present = 1;
728 status = parser_read_uint32(&p->log_level,
730 PARSE_ERROR((status == 0), section_name, entry->name);
735 if (strcmp(entry->name, "v") == 0) {
738 PARSE_ERROR_DUPLICATE((p->version_present == 0),
741 p->version_present = 1;
743 val = parser_read_arg_bool(entry->value);
744 PARSE_ERROR((val >= 0), section_name, entry->name);
750 if ((strcmp(entry->name, "help") == 0) ||
751 (strcmp(entry->name, "h") == 0)) {
754 PARSE_ERROR_DUPLICATE((p->help_present == 0),
759 val = parser_read_arg_bool(entry->value);
760 PARSE_ERROR((val >= 0), section_name, entry->name);
766 if (strcmp(entry->name, "no_huge") == 0) {
769 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
772 p->no_huge_present = 1;
774 val = parser_read_arg_bool(entry->value);
775 PARSE_ERROR((val >= 0), section_name, entry->name);
781 if (strcmp(entry->name, "no_pci") == 0) {
784 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
787 p->no_pci_present = 1;
789 val = parser_read_arg_bool(entry->value);
790 PARSE_ERROR((val >= 0), section_name, entry->name);
796 if (strcmp(entry->name, "no_hpet") == 0) {
799 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
802 p->no_hpet_present = 1;
804 val = parser_read_arg_bool(entry->value);
805 PARSE_ERROR((val >= 0), section_name, entry->name);
811 if (strcmp(entry->name, "no_shconf") == 0) {
814 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
817 p->no_shconf_present = 1;
819 val = parser_read_arg_bool(entry->value);
820 PARSE_ERROR((val >= 0), section_name, entry->name);
826 if (strcmp(entry->name, "d") == 0) {
827 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
830 p->add_driver = strdup(entry->value);
835 if (strcmp(entry->name, "socket_mem") == 0) {
836 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
839 p->socket_mem = strdup(entry->value);
844 if (strcmp(entry->name, "huge_dir") == 0) {
845 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
848 p->huge_dir = strdup(entry->value);
853 if (strcmp(entry->name, "file_prefix") == 0) {
854 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
857 p->file_prefix = strdup(entry->value);
862 if (strcmp(entry->name, "base_virtaddr") == 0) {
863 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
866 p->base_virtaddr = strdup(entry->value);
871 if (strcmp(entry->name, "create_uio_dev") == 0) {
874 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
877 p->create_uio_dev_present = 1;
879 val = parser_read_arg_bool(entry->value);
880 PARSE_ERROR((val >= 0), section_name, entry->name);
881 p->create_uio_dev = val;
886 if (strcmp(entry->name, "vfio_intr") == 0) {
887 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
890 p->vfio_intr = strdup(entry->value);
895 if (strcmp(entry->name, "xen_dom0") == 0) {
898 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
901 p->xen_dom0_present = 1;
903 val = parser_read_arg_bool(entry->value);
904 PARSE_ERROR((val >= 0), section_name, entry->name);
910 PARSE_ERROR_INVALID(0, section_name, entry->name);
917 parse_pipeline_pktq_in(struct app_params *app,
918 struct app_pipeline_params *p,
921 const char *next = value;
923 char name[APP_PARAM_NAME_SIZE];
926 while (*next != '\0') {
927 enum app_pktq_in_type type;
932 next = skip_white_spaces(next);
936 end_space = strchr(next, ' ');
937 end_tab = strchr(next, ' ');
939 if (end_space && (!end_tab))
941 else if ((!end_space) && end_tab)
943 else if (end_space && end_tab)
944 end = RTE_MIN(end_space, end_tab);
949 name_len = strlen(next);
951 name_len = end - next;
953 if (name_len == 0 || name_len == sizeof(name))
956 strncpy(name, next, name_len);
957 name[name_len] = '\0';
962 if (validate_name(name, "RXQ", 2) == 0) {
963 type = APP_PKTQ_IN_HWQ;
964 id = APP_PARAM_ADD(app->hwq_in_params, name);
965 } else if (validate_name(name, "SWQ", 1) == 0) {
966 type = APP_PKTQ_IN_SWQ;
967 id = APP_PARAM_ADD(app->swq_params, name);
968 } else if (validate_name(name, "TM", 1) == 0) {
969 type = APP_PKTQ_IN_TM;
970 id = APP_PARAM_ADD(app->tm_params, name);
971 } else if (validate_name(name, "SOURCE", 1) == 0) {
972 type = APP_PKTQ_IN_SOURCE;
973 id = APP_PARAM_ADD(app->source_params, name);
980 p->pktq_in[p->n_pktq_in].type = type;
981 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
989 parse_pipeline_pktq_out(struct app_params *app,
990 struct app_pipeline_params *p,
993 const char *next = value;
995 char name[APP_PARAM_NAME_SIZE];
998 while (*next != '\0') {
999 enum app_pktq_out_type type;
1004 next = skip_white_spaces(next);
1008 end_space = strchr(next, ' ');
1009 end_tab = strchr(next, ' ');
1011 if (end_space && (!end_tab))
1013 else if ((!end_space) && end_tab)
1015 else if (end_space && end_tab)
1016 end = RTE_MIN(end_space, end_tab);
1021 name_len = strlen(next);
1023 name_len = end - next;
1025 if (name_len == 0 || name_len == sizeof(name))
1028 strncpy(name, next, name_len);
1029 name[name_len] = '\0';
1033 if (validate_name(name, "TXQ", 2) == 0) {
1034 type = APP_PKTQ_OUT_HWQ;
1035 id = APP_PARAM_ADD(app->hwq_out_params, name);
1036 } else if (validate_name(name, "SWQ", 1) == 0) {
1037 type = APP_PKTQ_OUT_SWQ;
1038 id = APP_PARAM_ADD(app->swq_params, name);
1039 } else if (validate_name(name, "TM", 1) == 0) {
1040 type = APP_PKTQ_OUT_TM;
1041 id = APP_PARAM_ADD(app->tm_params, name);
1042 } else if (validate_name(name, "SINK", 1) == 0) {
1043 type = APP_PKTQ_OUT_SINK;
1044 id = APP_PARAM_ADD(app->sink_params, name);
1051 p->pktq_out[p->n_pktq_out].type = type;
1052 p->pktq_out[p->n_pktq_out].id = id;
1060 parse_pipeline_msgq_in(struct app_params *app,
1061 struct app_pipeline_params *p,
1064 const char *next = value;
1066 char name[APP_PARAM_NAME_SIZE];
1070 while (*next != '\0') {
1074 next = skip_white_spaces(next);
1078 end_space = strchr(next, ' ');
1079 end_tab = strchr(next, ' ');
1081 if (end_space && (!end_tab))
1083 else if ((!end_space) && end_tab)
1085 else if (end_space && end_tab)
1086 end = RTE_MIN(end_space, end_tab);
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_in[p->n_msgq_in] = idx;
1119 parse_pipeline_msgq_out(struct app_params *app,
1120 struct app_pipeline_params *p,
1123 const char *next = value;
1125 char name[APP_PARAM_NAME_SIZE];
1129 while (*next != '\0') {
1133 next = skip_white_spaces(next);
1137 end_space = strchr(next, ' ');
1138 end_tab = strchr(next, ' ');
1140 if (end_space && (!end_tab))
1142 else if ((!end_space) && end_tab)
1144 else if (end_space && end_tab)
1145 end = RTE_MIN(end_space, end_tab);
1150 name_len = strlen(next);
1152 name_len = end - next;
1154 if (name_len == 0 || name_len == sizeof(name))
1157 strncpy(name, next, name_len);
1158 name[name_len] = '\0';
1163 if (validate_name(name, "MSGQ", 1) != 0)
1166 idx = APP_PARAM_ADD(app->msgq_params, name);
1170 p->msgq_out[p->n_msgq_out] = idx;
1178 parse_pipeline(struct app_params *app,
1179 const char *section_name,
1180 struct rte_cfgfile *cfg)
1182 char name[CFG_NAME_LEN];
1183 struct app_pipeline_params *param;
1184 struct rte_cfgfile_entry *entries;
1188 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1189 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1191 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1192 PARSE_ERROR_MALLOC(entries != NULL);
1194 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1196 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1197 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1199 param = &app->pipeline_params[param_idx];
1201 for (i = 0; i < n_entries; i++) {
1202 struct rte_cfgfile_entry *ent = &entries[i];
1204 if (strcmp(ent->name, "type") == 0) {
1205 int w_size = snprintf(param->type, RTE_DIM(param->type),
1208 PARSE_ERROR(((w_size > 0) &&
1209 (w_size < (int)RTE_DIM(param->type))),
1215 if (strcmp(ent->name, "core") == 0) {
1216 int status = parse_pipeline_core(
1217 ¶m->socket_id, ¶m->core_id,
1218 ¶m->hyper_th_id, ent->value);
1220 PARSE_ERROR((status == 0), section_name,
1225 if (strcmp(ent->name, "pktq_in") == 0) {
1226 int status = parse_pipeline_pktq_in(app, param,
1229 PARSE_ERROR((status == 0), section_name,
1234 if (strcmp(ent->name, "pktq_out") == 0) {
1235 int status = parse_pipeline_pktq_out(app, param,
1238 PARSE_ERROR((status == 0), section_name,
1243 if (strcmp(ent->name, "msgq_in") == 0) {
1244 int status = parse_pipeline_msgq_in(app, param,
1247 PARSE_ERROR((status == 0), section_name,
1252 if (strcmp(ent->name, "msgq_out") == 0) {
1253 int status = parse_pipeline_msgq_out(app, param,
1256 PARSE_ERROR((status == 0), section_name,
1261 if (strcmp(ent->name, "timer_period") == 0) {
1262 int status = parser_read_uint32(
1263 ¶m->timer_period,
1266 PARSE_ERROR((status == 0), section_name,
1271 /* pipeline type specific items */
1272 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1273 "Parse error in section \"%s\": too many "
1274 "pipeline specified parameters", section_name);
1276 param->args_name[param->n_args] = strdup(ent->name);
1277 param->args_value[param->n_args] = strdup(ent->value);
1279 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1280 (param->args_value[param->n_args] != NULL),
1281 "Parse error: no free memory");
1288 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1289 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1290 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1291 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1292 param->msgq_in[param->n_msgq_in++] = param_idx;
1294 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1295 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1296 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1297 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1298 param->msgq_out[param->n_msgq_out++] = param_idx;
1300 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1303 (param->hyper_th_id) ? "h" : "");
1304 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1305 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1306 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1308 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1311 (param->hyper_th_id) ? "h" : "");
1312 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1313 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1314 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1320 parse_mempool(struct app_params *app,
1321 const char *section_name,
1322 struct rte_cfgfile *cfg)
1324 struct app_mempool_params *param;
1325 struct rte_cfgfile_entry *entries;
1329 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1330 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1332 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1333 PARSE_ERROR_MALLOC(entries != NULL);
1335 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1337 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1338 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1340 param = &app->mempool_params[param_idx];
1342 for (i = 0; i < n_entries; i++) {
1343 struct rte_cfgfile_entry *ent = &entries[i];
1345 if (strcmp(ent->name, "buffer_size") == 0) {
1346 int status = parser_read_uint32(
1347 ¶m->buffer_size, ent->value);
1349 PARSE_ERROR((status == 0), section_name,
1354 if (strcmp(ent->name, "pool_size") == 0) {
1355 int status = parser_read_uint32(
1356 ¶m->pool_size, ent->value);
1358 PARSE_ERROR((status == 0), section_name,
1363 if (strcmp(ent->name, "cache_size") == 0) {
1364 int status = parser_read_uint32(
1365 ¶m->cache_size, ent->value);
1367 PARSE_ERROR((status == 0), section_name,
1372 if (strcmp(ent->name, "cpu") == 0) {
1373 int status = parser_read_uint32(
1374 ¶m->cpu_socket_id, ent->value);
1376 PARSE_ERROR((status == 0), section_name,
1382 PARSE_ERROR_INVALID(0, section_name, ent->name);
1391 parse_link(struct app_params *app,
1392 const char *section_name,
1393 struct rte_cfgfile *cfg)
1395 struct app_link_params *param;
1396 struct rte_cfgfile_entry *entries;
1400 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1401 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1403 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1404 PARSE_ERROR_MALLOC(entries != NULL);
1406 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1408 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1409 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1411 param = &app->link_params[param_idx];
1413 for (i = 0; i < n_entries; i++) {
1414 struct rte_cfgfile_entry *ent = &entries[i];
1416 if (strcmp(ent->name, "promisc") == 0) {
1417 int status = parser_read_arg_bool(ent->value);
1419 PARSE_ERROR((status != -EINVAL), section_name,
1421 param->promisc = status;
1425 if (strcmp(ent->name, "arp_q") == 0) {
1426 int status = parser_read_uint32(¶m->arp_q,
1429 PARSE_ERROR((status == 0), section_name,
1434 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1435 int status = parser_read_uint32(
1436 ¶m->tcp_syn_local_q, ent->value);
1438 PARSE_ERROR((status == 0), section_name, ent->name);
1442 if (strcmp(ent->name, "ip_local_q") == 0) {
1443 int status = parser_read_uint32(
1444 ¶m->ip_local_q, ent->value);
1446 PARSE_ERROR((status == 0), section_name,
1452 if (strcmp(ent->name, "tcp_local_q") == 0) {
1453 int status = parser_read_uint32(
1454 ¶m->tcp_local_q, ent->value);
1456 PARSE_ERROR((status == 0), section_name,
1461 if (strcmp(ent->name, "udp_local_q") == 0) {
1462 int status = parser_read_uint32(
1463 ¶m->udp_local_q, ent->value);
1465 PARSE_ERROR((status == 0), section_name,
1470 if (strcmp(ent->name, "sctp_local_q") == 0) {
1471 int status = parser_read_uint32(
1472 ¶m->sctp_local_q, ent->value);
1474 PARSE_ERROR((status == 0), section_name,
1480 PARSE_ERROR_INVALID(0, section_name, ent->name);
1489 parse_rxq(struct app_params *app,
1490 const char *section_name,
1491 struct rte_cfgfile *cfg)
1493 struct app_pktq_hwq_in_params *param;
1494 struct rte_cfgfile_entry *entries;
1498 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1499 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1501 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1502 PARSE_ERROR_MALLOC(entries != NULL);
1504 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1506 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1507 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1509 param = &app->hwq_in_params[param_idx];
1511 for (i = 0; i < n_entries; i++) {
1512 struct rte_cfgfile_entry *ent = &entries[i];
1514 if (strcmp(ent->name, "mempool") == 0) {
1515 int status = validate_name(ent->value,
1519 PARSE_ERROR((status == 0), section_name,
1521 idx = APP_PARAM_ADD(app->mempool_params,
1523 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1525 param->mempool_id = idx;
1529 if (strcmp(ent->name, "size") == 0) {
1530 int status = parser_read_uint32(¶m->size,
1533 PARSE_ERROR((status == 0), section_name,
1538 if (strcmp(ent->name, "burst") == 0) {
1539 int status = parser_read_uint32(¶m->burst,
1542 PARSE_ERROR((status == 0), section_name,
1548 PARSE_ERROR_INVALID(0, section_name, ent->name);
1557 parse_txq(struct app_params *app,
1558 const char *section_name,
1559 struct rte_cfgfile *cfg)
1561 struct app_pktq_hwq_out_params *param;
1562 struct rte_cfgfile_entry *entries;
1566 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1567 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1569 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1570 PARSE_ERROR_MALLOC(entries != NULL);
1572 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1574 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1575 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1577 param = &app->hwq_out_params[param_idx];
1579 for (i = 0; i < n_entries; i++) {
1580 struct rte_cfgfile_entry *ent = &entries[i];
1582 if (strcmp(ent->name, "size") == 0) {
1583 int status = parser_read_uint32(¶m->size,
1586 PARSE_ERROR((status == 0), section_name,
1591 if (strcmp(ent->name, "burst") == 0) {
1592 int status = parser_read_uint32(¶m->burst,
1595 PARSE_ERROR((status == 0), section_name,
1600 if (strcmp(ent->name, "dropless") == 0) {
1601 int status = parser_read_arg_bool(ent->value);
1604 PARSE_ERROR((status != -EINVAL), section_name,
1606 param->dropless = status;
1611 PARSE_ERROR_INVALID(0, section_name, ent->name);
1620 parse_swq(struct app_params *app,
1621 const char *section_name,
1622 struct rte_cfgfile *cfg)
1624 struct app_pktq_swq_params *param;
1625 struct rte_cfgfile_entry *entries;
1627 uint32_t mtu_present = 0;
1628 uint32_t metadata_size_present = 0;
1629 uint32_t mempool_direct_present = 0;
1630 uint32_t mempool_indirect_present = 0;
1634 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1635 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1637 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1638 PARSE_ERROR_MALLOC(entries != NULL);
1640 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1642 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1643 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1645 param = &app->swq_params[param_idx];
1647 for (i = 0; i < n_entries; i++) {
1648 struct rte_cfgfile_entry *ent = &entries[i];
1650 if (strcmp(ent->name, "size") == 0) {
1651 int status = parser_read_uint32(¶m->size,
1654 PARSE_ERROR((status == 0), section_name,
1659 if (strcmp(ent->name, "burst_read") == 0) {
1660 int status = parser_read_uint32(&
1661 param->burst_read, ent->value);
1663 PARSE_ERROR((status == 0), section_name,
1668 if (strcmp(ent->name, "burst_write") == 0) {
1669 int status = parser_read_uint32(
1670 ¶m->burst_write, ent->value);
1672 PARSE_ERROR((status == 0), section_name,
1677 if (strcmp(ent->name, "dropless") == 0) {
1678 int status = parser_read_arg_bool(ent->value);
1680 PARSE_ERROR((status != -EINVAL), section_name,
1682 param->dropless = status;
1686 if (strcmp(ent->name, "n_retries") == 0) {
1687 int status = parser_read_uint64(¶m->n_retries,
1690 PARSE_ERROR((status == 0), section_name,
1695 if (strcmp(ent->name, "cpu") == 0) {
1696 int status = parser_read_uint32(
1697 ¶m->cpu_socket_id, ent->value);
1699 PARSE_ERROR((status == 0), section_name, ent->name);
1703 if (strcmp(ent->name, "ipv4_frag") == 0) {
1704 int status = parser_read_arg_bool(ent->value);
1706 PARSE_ERROR((status != -EINVAL), section_name,
1709 param->ipv4_frag = status;
1710 if (param->mtu == 0)
1716 if (strcmp(ent->name, "ipv6_frag") == 0) {
1717 int status = parser_read_arg_bool(ent->value);
1719 PARSE_ERROR((status != -EINVAL), section_name,
1721 param->ipv6_frag = status;
1722 if (param->mtu == 0)
1727 if (strcmp(ent->name, "ipv4_ras") == 0) {
1728 int status = parser_read_arg_bool(ent->value);
1730 PARSE_ERROR((status != -EINVAL), section_name,
1732 param->ipv4_ras = status;
1736 if (strcmp(ent->name, "ipv6_ras") == 0) {
1737 int status = parser_read_arg_bool(ent->value);
1739 PARSE_ERROR((status != -EINVAL), section_name,
1741 param->ipv6_ras = status;
1745 if (strcmp(ent->name, "mtu") == 0) {
1746 int status = parser_read_uint32(¶m->mtu,
1749 PARSE_ERROR((status == 0), section_name,
1755 if (strcmp(ent->name, "metadata_size") == 0) {
1756 int status = parser_read_uint32(
1757 ¶m->metadata_size, ent->value);
1759 PARSE_ERROR((status == 0), section_name,
1761 metadata_size_present = 1;
1765 if (strcmp(ent->name, "mempool_direct") == 0) {
1766 int status = validate_name(ent->value,
1770 PARSE_ERROR((status == 0), section_name,
1773 idx = APP_PARAM_ADD(app->mempool_params,
1775 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1777 param->mempool_direct_id = idx;
1778 mempool_direct_present = 1;
1782 if (strcmp(ent->name, "mempool_indirect") == 0) {
1783 int status = validate_name(ent->value,
1787 PARSE_ERROR((status == 0), section_name,
1789 idx = APP_PARAM_ADD(app->mempool_params,
1791 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1793 param->mempool_indirect_id = idx;
1794 mempool_indirect_present = 1;
1799 PARSE_ERROR_INVALID(0, section_name, ent->name);
1802 APP_CHECK(((mtu_present) &&
1803 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1804 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1805 "is off, therefore entry \"mtu\" is not allowed",
1808 APP_CHECK(((metadata_size_present) &&
1809 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1810 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1811 "is off, therefore entry \"metadata_size\" is "
1812 "not allowed", section_name);
1814 APP_CHECK(((mempool_direct_present) &&
1815 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1816 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1817 "is off, therefore entry \"mempool_direct\" is "
1818 "not allowed", section_name);
1820 APP_CHECK(((mempool_indirect_present) &&
1821 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1822 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1823 "is off, therefore entry \"mempool_indirect\" is "
1824 "not allowed", section_name);
1832 parse_tm(struct app_params *app,
1833 const char *section_name,
1834 struct rte_cfgfile *cfg)
1836 struct app_pktq_tm_params *param;
1837 struct rte_cfgfile_entry *entries;
1841 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1842 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1844 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1845 PARSE_ERROR_MALLOC(entries != NULL);
1847 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1849 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1850 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
1852 param = &app->tm_params[param_idx];
1854 for (i = 0; i < n_entries; i++) {
1855 struct rte_cfgfile_entry *ent = &entries[i];
1857 if (strcmp(ent->name, "cfg") == 0) {
1858 param->file_name = strdup(ent->value);
1859 PARSE_ERROR_MALLOC(param->file_name != NULL);
1863 if (strcmp(ent->name, "burst_read") == 0) {
1864 int status = parser_read_uint32(
1865 ¶m->burst_read, ent->value);
1867 PARSE_ERROR((status == 0), section_name,
1872 if (strcmp(ent->name, "burst_write") == 0) {
1873 int status = parser_read_uint32(
1874 ¶m->burst_write, ent->value);
1876 PARSE_ERROR((status == 0), section_name,
1882 PARSE_ERROR_INVALID(0, section_name, ent->name);
1891 parse_source(struct app_params *app,
1892 const char *section_name,
1893 struct rte_cfgfile *cfg)
1895 struct app_pktq_source_params *param;
1896 struct rte_cfgfile_entry *entries;
1900 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1901 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1903 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1904 PARSE_ERROR_MALLOC(entries != NULL);
1906 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1908 param_idx = APP_PARAM_ADD(app->source_params, section_name);
1909 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
1911 param = &app->source_params[param_idx];
1913 for (i = 0; i < n_entries; i++) {
1914 struct rte_cfgfile_entry *ent = &entries[i];
1916 if (strcmp(ent->name, "mempool") == 0) {
1917 int status = validate_name(ent->value,
1921 PARSE_ERROR((status == 0), section_name,
1923 idx = APP_PARAM_ADD(app->mempool_params,
1925 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1927 param->mempool_id = idx;
1931 if (strcmp(ent->name, "burst") == 0) {
1932 int status = parser_read_uint32(¶m->burst,
1935 PARSE_ERROR((status == 0), section_name,
1941 PARSE_ERROR_INVALID(0, section_name, ent->name);
1950 parse_msgq_req_pipeline(struct app_params *app,
1951 const char *section_name,
1952 struct rte_cfgfile *cfg)
1954 struct app_msgq_params *param;
1955 struct rte_cfgfile_entry *entries;
1959 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1960 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1962 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1963 PARSE_ERROR_MALLOC(entries != NULL);
1965 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1967 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1968 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1970 param = &app->msgq_params[param_idx];
1972 for (i = 0; i < n_entries; i++) {
1973 struct rte_cfgfile_entry *ent = &entries[i];
1975 if (strcmp(ent->name, "size") == 0) {
1976 int status = parser_read_uint32(¶m->size,
1979 PARSE_ERROR((status == 0), section_name,
1985 PARSE_ERROR_INVALID(0, section_name, ent->name);
1993 parse_msgq_rsp_pipeline(struct app_params *app,
1994 const char *section_name,
1995 struct rte_cfgfile *cfg)
1997 struct app_msgq_params *param;
1998 struct rte_cfgfile_entry *entries;
2002 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2003 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2005 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2006 PARSE_ERROR_MALLOC(entries != NULL);
2008 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2010 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2011 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2013 param = &app->msgq_params[param_idx];
2015 for (i = 0; i < n_entries; i++) {
2016 struct rte_cfgfile_entry *ent = &entries[i];
2018 if (strcmp(ent->name, "size") == 0) {
2019 int status = parser_read_uint32(¶m->size,
2022 PARSE_ERROR((status == 0), section_name,
2028 PARSE_ERROR_INVALID(0, section_name, ent->name);
2037 parse_msgq(struct app_params *app,
2038 const char *section_name,
2039 struct rte_cfgfile *cfg)
2041 struct app_msgq_params *param;
2042 struct rte_cfgfile_entry *entries;
2046 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2047 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2049 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2050 PARSE_ERROR_MALLOC(entries != NULL);
2052 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2054 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2055 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2057 param = &app->msgq_params[param_idx];
2059 for (i = 0; i < n_entries; i++) {
2060 struct rte_cfgfile_entry *ent = &entries[i];
2062 if (strcmp(ent->name, "size") == 0) {
2063 int status = parser_read_uint32(¶m->size,
2066 PARSE_ERROR((status == 0), section_name,
2071 if (strcmp(ent->name, "cpu") == 0) {
2072 int status = parser_read_uint32(
2073 ¶m->cpu_socket_id, ent->value);
2075 PARSE_ERROR((status == 0), section_name,
2081 PARSE_ERROR_INVALID(0, section_name, ent->name);
2089 typedef void (*config_section_load)(struct app_params *p,
2090 const char *section_name,
2091 struct rte_cfgfile *cfg);
2093 struct config_section {
2094 const char prefix[CFG_NAME_LEN];
2096 config_section_load load;
2099 static const struct config_section cfg_file_scheme[] = {
2100 {"EAL", 0, parse_eal},
2101 {"PIPELINE", 1, parse_pipeline},
2102 {"MEMPOOL", 1, parse_mempool},
2103 {"LINK", 1, parse_link},
2104 {"RXQ", 2, parse_rxq},
2105 {"TXQ", 2, parse_txq},
2106 {"SWQ", 1, parse_swq},
2107 {"TM", 1, parse_tm},
2108 {"SOURCE", 1, parse_source},
2109 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2110 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2111 {"MSGQ", 1, parse_msgq},
2115 create_implicit_mempools(struct app_params *app)
2119 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2120 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2124 parse_port_mask(struct app_params *app, uint64_t port_mask)
2126 uint32_t pmd_id, link_id;
2129 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2130 char name[APP_PARAM_NAME_SIZE];
2133 if ((port_mask & (1LLU << pmd_id)) == 0)
2136 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2137 idx = APP_PARAM_ADD(app->link_params, name);
2138 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2140 app->link_params[idx].pmd_id = pmd_id;
2146 app_config_parse(struct app_params *app, const char *file_name)
2148 struct rte_cfgfile *cfg;
2149 char **section_names;
2150 int i, j, sect_count;
2152 /* Implicit mempools */
2153 create_implicit_mempools(app);
2156 parse_port_mask(app, app->port_mask);
2158 /* Load application configuration file */
2159 cfg = rte_cfgfile_load(file_name, 0);
2160 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2161 "file %s", file_name);
2163 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2164 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2165 "in file \"%s\" return %d", file_name,
2168 section_names = malloc(sect_count * sizeof(char *));
2169 PARSE_ERROR_MALLOC(section_names != NULL);
2171 for (i = 0; i < sect_count; i++)
2172 section_names[i] = malloc(CFG_NAME_LEN);
2174 rte_cfgfile_sections(cfg, section_names, sect_count);
2176 for (i = 0; i < sect_count; i++) {
2177 const struct config_section *sch_s;
2178 int len, cfg_name_len;
2180 cfg_name_len = strlen(section_names[i]);
2182 /* Find section type */
2183 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2184 sch_s = &cfg_file_scheme[j];
2185 len = strlen(sch_s->prefix);
2187 if (cfg_name_len < len)
2190 /* After section name we expect only '\0' or digit or
2191 * digit dot digit, so protect against false matching,
2192 * for example: "ABC" should match section name
2193 * "ABC0.0", but it should not match section_name
2196 if ((section_names[i][len] != '\0') &&
2197 !isdigit(section_names[i][len]))
2200 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2204 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2205 "Parse error: unknown section %s",
2208 APP_CHECK(validate_name(section_names[i],
2210 sch_s->numbers) == 0,
2211 "Parse error: invalid section name \"%s\"",
2214 sch_s->load(app, section_names[i], cfg);
2217 for (i = 0; i < sect_count; i++)
2218 free(section_names[i]);
2220 free(section_names);
2222 rte_cfgfile_close(cfg);
2224 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2225 APP_PARAM_COUNT(app->link_params, app->n_links);
2226 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2227 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2228 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2229 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2230 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2231 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2232 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2233 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2235 /* Save configuration to output file */
2236 app_config_save(app, app->output_file);
2238 /* Load TM configuration files */
2239 app_config_parse_tm(app);
2245 save_eal_params(struct app_params *app, FILE *f)
2247 struct app_eal_params *p = &app->eal_params;
2249 fprintf(f, "[EAL]\n");
2252 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2254 if (p->master_lcore_present)
2255 fprintf(f, "%s = %" PRIu32 "\n",
2256 "master_lcore", p->master_lcore);
2258 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2260 if (p->memory_present)
2261 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2263 if (p->ranks_present)
2264 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2266 if (p->pci_blacklist)
2267 fprintf(f, "%s = %s\n", "pci_blacklist", p->pci_blacklist);
2269 if (p->pci_whitelist)
2270 fprintf(f, "%s = %s\n", "pci_whitelist", p->pci_whitelist);
2273 fprintf(f, "%s = %s\n", "vdev", p->vdev);
2275 if (p->vmware_tsc_map_present)
2276 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2277 (p->vmware_tsc_map) ? "yes" : "no");
2280 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2283 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2285 if (p->log_level_present)
2286 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2288 if (p->version_present)
2289 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2291 if (p->help_present)
2292 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2294 if (p->no_huge_present)
2295 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2297 if (p->no_pci_present)
2298 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2300 if (p->no_hpet_present)
2301 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2303 if (p->no_shconf_present)
2304 fprintf(f, "%s = %s\n", "no_shconf",
2305 (p->no_shconf) ? "yes" : "no");
2308 fprintf(f, "%s = %s\n", "d", p->add_driver);
2311 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2314 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2317 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2319 if (p->base_virtaddr)
2320 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2322 if (p->create_uio_dev_present)
2323 fprintf(f, "%s = %s\n", "create_uio_dev",
2324 (p->create_uio_dev) ? "yes" : "no");
2327 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2329 if (p->xen_dom0_present)
2330 fprintf(f, "%s = %s\n", "xen_dom0",
2331 (p->xen_dom0) ? "yes" : "no");
2337 save_mempool_params(struct app_params *app, FILE *f)
2339 struct app_mempool_params *p;
2342 count = RTE_DIM(app->mempool_params);
2343 for (i = 0; i < count; i++) {
2344 p = &app->mempool_params[i];
2345 if (!APP_PARAM_VALID(p))
2348 fprintf(f, "[%s]\n", p->name);
2349 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2350 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2351 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2352 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2359 save_links_params(struct app_params *app, FILE *f)
2361 struct app_link_params *p;
2364 count = RTE_DIM(app->link_params);
2365 for (i = 0; i < count; i++) {
2366 p = &app->link_params[i];
2367 if (!APP_PARAM_VALID(p))
2370 fprintf(f, "[%s]\n", p->name);
2371 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2372 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2373 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2374 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_local_q",
2375 p->tcp_syn_local_q);
2376 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2377 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2378 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2379 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2387 save_rxq_params(struct app_params *app, FILE *f)
2389 struct app_pktq_hwq_in_params *p;
2392 count = RTE_DIM(app->hwq_in_params);
2393 for (i = 0; i < count; i++) {
2394 p = &app->hwq_in_params[i];
2395 if (!APP_PARAM_VALID(p))
2398 fprintf(f, "[%s]\n", p->name);
2399 fprintf(f, "%s = %s\n",
2401 app->mempool_params[p->mempool_id].name);
2402 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2403 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2410 save_txq_params(struct app_params *app, FILE *f)
2412 struct app_pktq_hwq_out_params *p;
2415 count = RTE_DIM(app->hwq_out_params);
2416 for (i = 0; i < count; i++) {
2417 p = &app->hwq_out_params[i];
2418 if (!APP_PARAM_VALID(p))
2421 fprintf(f, "[%s]\n", p->name);
2422 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2423 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2424 fprintf(f, "%s = %s\n",
2426 p->dropless ? "yes" : "no");
2433 save_swq_params(struct app_params *app, FILE *f)
2435 struct app_pktq_swq_params *p;
2438 count = RTE_DIM(app->swq_params);
2439 for (i = 0; i < count; i++) {
2440 p = &app->swq_params[i];
2441 if (!APP_PARAM_VALID(p))
2444 fprintf(f, "[%s]\n", p->name);
2445 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2446 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2447 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2448 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2449 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2450 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2451 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2452 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2453 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2454 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2455 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2456 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2457 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2458 fprintf(f, "%s = %s\n",
2460 app->mempool_params[p->mempool_direct_id].name);
2461 fprintf(f, "%s = %s\n",
2463 app->mempool_params[p->mempool_indirect_id].name);
2471 save_tm_params(struct app_params *app, FILE *f)
2473 struct app_pktq_tm_params *p;
2476 count = RTE_DIM(app->tm_params);
2477 for (i = 0; i < count; i++) {
2478 p = &app->tm_params[i];
2479 if (!APP_PARAM_VALID(p))
2482 fprintf(f, "[%s]\n", p->name);
2483 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2484 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2485 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2492 save_source_params(struct app_params *app, FILE *f)
2494 struct app_pktq_source_params *p;
2497 count = RTE_DIM(app->source_params);
2498 for (i = 0; i < count; i++) {
2499 p = &app->source_params[i];
2500 if (!APP_PARAM_VALID(p))
2503 fprintf(f, "[%s]\n", p->name);
2504 fprintf(f, "%s = %s\n",
2506 app->mempool_params[p->mempool_id].name);
2507 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2513 save_msgq_params(struct app_params *app, FILE *f)
2515 struct app_msgq_params *p;
2518 count = RTE_DIM(app->msgq_params);
2519 for (i = 0; i < count; i++) {
2520 p = &app->msgq_params[i];
2521 if (!APP_PARAM_VALID(p))
2524 fprintf(f, "[%s]\n", p->name);
2525 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2526 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2533 save_pipeline_params(struct app_params *app, FILE *f)
2537 count = RTE_DIM(app->pipeline_params);
2538 for (i = 0; i < count; i++) {
2539 struct app_pipeline_params *p = &app->pipeline_params[i];
2541 if (!APP_PARAM_VALID(p))
2545 fprintf(f, "[%s]\n", p->name);
2548 fprintf(f, "type = %s\n", p->type);
2551 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2554 (p->hyper_th_id) ? "h" : "");
2560 fprintf(f, "pktq_in =");
2561 for (j = 0; j < p->n_pktq_in; j++) {
2562 struct app_pktq_in_params *pp = &p->pktq_in[j];
2566 case APP_PKTQ_IN_HWQ:
2567 name = app->hwq_in_params[pp->id].name;
2569 case APP_PKTQ_IN_SWQ:
2570 name = app->swq_params[pp->id].name;
2572 case APP_PKTQ_IN_TM:
2573 name = app->tm_params[pp->id].name;
2575 case APP_PKTQ_IN_SOURCE:
2576 name = app->source_params[pp->id].name;
2579 APP_CHECK(0, "System error "
2580 "occurred while saving "
2581 "parameter to file");
2584 fprintf(f, " %s", name);
2590 if (p->n_pktq_out) {
2593 fprintf(f, "pktq_out =");
2594 for (j = 0; j < p->n_pktq_out; j++) {
2595 struct app_pktq_out_params *pp =
2600 case APP_PKTQ_OUT_HWQ:
2601 name = app->hwq_out_params[pp->id].name;
2603 case APP_PKTQ_OUT_SWQ:
2604 name = app->swq_params[pp->id].name;
2606 case APP_PKTQ_OUT_TM:
2607 name = app->tm_params[pp->id].name;
2609 case APP_PKTQ_OUT_SINK:
2610 name = app->sink_params[pp->id].name;
2613 APP_CHECK(0, "System error "
2614 "occurred while saving "
2615 "parameter to file");
2618 fprintf(f, " %s", name);
2627 fprintf(f, "msgq_in =");
2628 for (j = 0; j < p->n_msgq_in; j++) {
2629 uint32_t id = p->msgq_in[j];
2630 char *name = app->msgq_params[id].name;
2632 fprintf(f, " %s", name);
2638 if (p->n_msgq_out) {
2641 fprintf(f, "msgq_out =");
2642 for (j = 0; j < p->n_msgq_out; j++) {
2643 uint32_t id = p->msgq_out[j];
2644 char *name = app->msgq_params[id].name;
2646 fprintf(f, " %s", name);
2652 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2658 for (j = 0; j < p->n_args; j++)
2659 fprintf(f, "%s = %s\n", p->args_name[j],
2668 app_config_save(struct app_params *app, const char *file_name)
2671 char *name, *dir_name;
2674 name = strdup(file_name);
2675 dir_name = dirname(name);
2676 status = access(dir_name, W_OK);
2677 APP_CHECK((status == 0),
2678 "Error: need write access privilege to directory "
2679 "\"%s\" to save configuration\n", dir_name);
2681 file = fopen(file_name, "w");
2682 APP_CHECK((file != NULL),
2683 "Error: failed to save configuration to file \"%s\"",
2686 save_eal_params(app, file);
2687 save_pipeline_params(app, file);
2688 save_mempool_params(app, file);
2689 save_links_params(app, file);
2690 save_rxq_params(app, file);
2691 save_txq_params(app, file);
2692 save_swq_params(app, file);
2693 save_tm_params(app, file);
2694 save_source_params(app, file);
2695 save_msgq_params(app, file);
2702 app_config_init(struct app_params *app)
2706 memcpy(app, &app_params_default, sizeof(struct app_params));
2708 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2709 memcpy(&app->mempool_params[i],
2710 &mempool_params_default,
2711 sizeof(struct app_mempool_params));
2713 for (i = 0; i < RTE_DIM(app->link_params); i++)
2714 memcpy(&app->link_params[i],
2715 &link_params_default,
2716 sizeof(struct app_link_params));
2718 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2719 memcpy(&app->hwq_in_params[i],
2720 &default_hwq_in_params,
2721 sizeof(default_hwq_in_params));
2723 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2724 memcpy(&app->hwq_out_params[i],
2725 &default_hwq_out_params,
2726 sizeof(default_hwq_out_params));
2728 for (i = 0; i < RTE_DIM(app->swq_params); i++)
2729 memcpy(&app->swq_params[i],
2730 &default_swq_params,
2731 sizeof(default_swq_params));
2733 for (i = 0; i < RTE_DIM(app->tm_params); i++)
2734 memcpy(&app->tm_params[i],
2736 sizeof(default_tm_params));
2738 for (i = 0; i < RTE_DIM(app->source_params); i++)
2739 memcpy(&app->source_params[i],
2740 &default_source_params,
2741 sizeof(default_source_params));
2743 for (i = 0; i < RTE_DIM(app->sink_params); i++)
2744 memcpy(&app->sink_params[i],
2745 &default_sink_params,
2746 sizeof(default_sink_params));
2748 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2749 memcpy(&app->msgq_params[i],
2750 &default_msgq_params,
2751 sizeof(default_msgq_params));
2753 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2754 memcpy(&app->pipeline_params[i],
2755 &default_pipeline_params,
2756 sizeof(default_pipeline_params));
2762 filenamedup(const char *filename, const char *suffix)
2764 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2769 sprintf(s, "%s%s", filename, suffix);
2774 app_config_args(struct app_params *app, int argc, char **argv)
2776 const char *optname;
2777 int opt, option_index;
2778 int f_present, s_present, p_present, l_present;
2779 int preproc_present, preproc_params_present;
2782 static struct option lgopts[] = {
2783 { "preproc", 1, 0, 0 },
2784 { "preproc-args", 1, 0, 0 },
2788 /* Copy application name */
2789 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
2795 preproc_present = 0;
2796 preproc_params_present = 0;
2798 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
2799 &option_index)) != EOF)
2803 rte_panic("Error: Config file is provided "
2804 "more than once\n");
2807 if (!strlen(optarg))
2808 rte_panic("Error: Config file name is null\n");
2810 app->config_file = strdup(optarg);
2811 if (app->config_file == NULL)
2812 rte_panic("Error: Memory allocation failure\n");
2818 rte_panic("Error: Script file is provided "
2819 "more than once\n");
2822 if (!strlen(optarg))
2823 rte_panic("Error: Script file name is null\n");
2825 app->script_file = strdup(optarg);
2826 if (app->script_file == NULL)
2827 rte_panic("Error: Memory allocation failure\n");
2833 rte_panic("Error: PORT_MASK is provided "
2834 "more than once\n");
2837 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
2839 ((size_t) scaned != strlen(optarg)))
2840 rte_panic("Error: PORT_MASK is not "
2841 "a hexadecimal integer\n");
2843 if (app->port_mask == 0)
2844 rte_panic("Error: PORT_MASK is null\n");
2850 rte_panic("Error: LOG_LEVEL is provided "
2851 "more than once\n");
2854 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
2856 ((size_t) scaned != strlen(optarg)) ||
2857 (app->log_level >= APP_LOG_LEVELS))
2858 rte_panic("Error: LOG_LEVEL invalid value\n");
2863 optname = lgopts[option_index].name;
2865 if (strcmp(optname, "preproc") == 0) {
2866 if (preproc_present)
2867 rte_panic("Error: Preprocessor argument "
2868 "is provided more than once\n");
2869 preproc_present = 1;
2871 app->preproc = strdup(optarg);
2875 if (strcmp(optname, "preproc-args") == 0) {
2876 if (preproc_params_present)
2877 rte_panic("Error: Preprocessor args "
2878 "are provided more than once\n");
2879 preproc_params_present = 1;
2881 app->preproc_args = strdup(optarg);
2885 app_print_usage(argv[0]);
2889 app_print_usage(argv[0]);
2892 optind = 0; /* reset getopt lib */
2894 /* Check that mandatory args have been provided */
2896 rte_panic("Error: PORT_MASK is not provided\n");
2898 /* Check dependencies between args */
2899 if (preproc_params_present && (preproc_present == 0))
2900 rte_panic("Error: Preprocessor args specified while "
2901 "preprocessor is not defined\n");
2903 app->parser_file = preproc_present ?
2904 filenamedup(app->config_file, ".preproc") :
2905 strdup(app->config_file);
2906 app->output_file = filenamedup(app->config_file, ".out");
2912 app_config_preproc(struct app_params *app)
2917 if (app->preproc == NULL)
2920 status = access(app->config_file, F_OK | R_OK);
2921 APP_CHECK((status == 0), "Error: Unable to open file %s",
2924 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
2926 app->preproc_args ? app->preproc_args : "",
2930 status = system(buffer);
2931 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
2932 "Error occurred while pre-processing file \"%s\"\n",