4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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,
66 static const struct app_mempool_params mempool_params_default = {
68 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
69 .pool_size = 32 * 1024,
74 static const struct app_link_params link_params_default = {
92 .mq_mode = ETH_MQ_RX_NONE,
94 .header_split = 0, /* Header split */
95 .hw_ip_checksum = 0, /* IP checksum offload */
96 .hw_vlan_filter = 0, /* VLAN filtering */
97 .hw_vlan_strip = 0, /* VLAN strip */
98 .hw_vlan_extend = 0, /* Extended VLAN */
99 .jumbo_frame = 0, /* Jumbo frame support */
100 .hw_strip_crc = 0, /* CRC strip by HW */
101 .enable_scatter = 0, /* Scattered packets RX handler */
103 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
104 .split_hdr_size = 0, /* Header split buffer size */
107 .mq_mode = ETH_MQ_TX_NONE,
115 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
127 .rx_free_thresh = 64,
129 .rx_deferred_start = 0,
133 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
148 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
149 ETH_TXQ_FLAGS_NOOFFLOADS,
150 .tx_deferred_start = 0,
154 static const struct app_pktq_swq_params default_swq_params = {
168 .mempool_direct_id = 0,
169 .mempool_indirect_id = 0,
172 struct app_pktq_tm_params default_tm_params = {
174 .file_name = "./config/tm_profile.cfg",
179 struct app_pktq_source_params default_source_params = {
184 .n_bytes_per_pkt = 0,
187 struct app_pktq_sink_params default_sink_params = {
193 struct app_msgq_params default_msgq_params = {
199 struct app_pipeline_params default_pipeline_params = {
212 static const char app_usage[] =
213 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
214 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
217 "\t-f CONFIG_FILE: Default config file is %s\n"
218 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
219 "config file when not provided)\n"
220 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
221 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
222 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
223 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
227 app_print_usage(char *prgname)
229 rte_exit(0, app_usage, prgname, app_params_default.config_file);
232 #define skip_white_spaces(pos) \
234 __typeof__(pos) _p = (pos); \
235 for ( ; isspace(*_p); _p++); \
239 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
241 APP_CHECK((result != -EINVAL), \
242 "Parse error: no free memory"); \
243 APP_CHECK((result != -ENOMEM), \
244 "Parse error: too many \"%s\" sections", section_name); \
245 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
246 "Parse error: duplicate \"%s\" section", section_name); \
247 APP_CHECK((result >= 0), \
248 "Parse error in section \"%s\"", section_name); \
252 parser_read_arg_bool(const char *p)
254 p = skip_white_spaces(p);
255 int result = -EINVAL;
257 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
258 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
263 if (((p[0] == 'o') && (p[1] == 'n')) ||
264 ((p[0] == 'O') && (p[1] == 'N'))) {
269 if (((p[0] == 'n') && (p[1] == 'o')) ||
270 ((p[0] == 'N') && (p[1] == 'O'))) {
275 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
276 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
281 p = skip_white_spaces(p);
289 #define PARSE_ERROR(exp, section, entry) \
290 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
292 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
293 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n", \
294 section, entry, message)
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);
370 if (val > UINT32_MAX)
378 parse_pipeline_core(uint32_t *socket,
386 uint32_t s = 0, c = 0, h = 0, val;
387 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
388 const char *next = skip_white_spaces(entry);
391 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
392 while (*next != '\0') {
393 /* If everything parsed nothing should left */
394 if (s_parsed && c_parsed && h_parsed)
401 if (s_parsed || c_parsed || h_parsed)
408 if (c_parsed || h_parsed)
421 /* If it start from digit it must be only core id. */
422 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
428 for (num_len = 0; *next != '\0'; next++, num_len++) {
429 if (num_len == RTE_DIM(num))
435 num[num_len] = *next;
438 if (num_len == 0 && type != 'h' && type != 'H')
441 if (num_len != 0 && (type == 'h' || type == 'H'))
445 val = strtol(num, NULL, 10);
474 case '0': case '1': case '2': case '3': case '4': case '5':
475 case '6': case '7': case '8': case '9':
477 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
479 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
487 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
492 /* Check input parameters */
500 if (((len & 3) != 0) ||
505 for (c = src; *c != 0; c++) {
506 if ((((*c) >= '0') && ((*c) <= '9')) ||
507 (((*c) >= 'A') && ((*c) <= 'F')) ||
508 (((*c) >= 'a') && ((*c) <= 'f')))
514 /* Convert chars to bytes */
515 for (i = 0; i < *size; i++)
516 dst[i] = get_hex_val(src[2 * i]) * 16 +
517 get_hex_val(src[2 * i + 1]);
523 skip_digits(const char *src)
527 for (i = 0; isdigit(src[i]); i++);
533 validate_name(const char *name, const char *prefix, int num)
537 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
538 if (name[i] != prefix[i])
542 if (prefix[i] != '\0')
553 j = skip_digits(&name[i]);
555 if ((j == 0) || (name[i] != '.'))
561 j = skip_digits(&name[i]);
563 if ((j == 0) || (name[i] != '\0'))
571 parse_eal(struct app_params *app,
572 const char *section_name,
573 struct rte_cfgfile *cfg)
575 struct app_eal_params *p = &app->eal_params;
576 struct rte_cfgfile_entry *entries;
579 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
580 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
582 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
583 PARSE_ERROR_MALLOC(entries != NULL);
585 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
587 for (i = 0; i < n_entries; i++) {
588 struct rte_cfgfile_entry *entry = &entries[i];
591 if (strcmp(entry->name, "c") == 0) {
592 PARSE_WARNING_IGNORED(0, section_name, entry->name);
597 if (strcmp(entry->name, "l") == 0) {
598 PARSE_WARNING_IGNORED(0, section_name, entry->name);
603 if (strcmp(entry->name, "lcores") == 0) {
604 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
607 p->coremap = strdup(entry->value);
612 if (strcmp(entry->name, "master_lcore") == 0) {
615 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
618 p->master_lcore_present = 1;
620 status = parser_read_uint32(&p->master_lcore,
622 PARSE_ERROR((status == 0), section_name, entry->name);
627 if (strcmp(entry->name, "n") == 0) {
630 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
633 p->channels_present = 1;
635 status = parser_read_uint32(&p->channels, entry->value);
636 PARSE_ERROR((status == 0), section_name, entry->name);
641 if (strcmp(entry->name, "m") == 0) {
644 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
647 p->memory_present = 1;
649 status = parser_read_uint32(&p->memory, entry->value);
650 PARSE_ERROR((status == 0), section_name, entry->name);
655 if (strcmp(entry->name, "r") == 0) {
658 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
661 p->ranks_present = 1;
663 status = parser_read_uint32(&p->ranks, entry->value);
664 PARSE_ERROR((status == 0), section_name, entry->name);
669 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
670 (strcmp(entry->name, "b") == 0)) {
673 for (i = 0; i < APP_MAX_LINKS; i++) {
674 if (p->pci_blacklist[i])
677 p->pci_blacklist[i] =
678 strdup(entry->value);
679 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
684 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
685 section_name, entry->name,
686 "too many elements");
691 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
692 (strcmp(entry->name, "w") == 0)) {
695 PARSE_ERROR_MESSAGE((app->port_mask != 0),
696 section_name, entry->name, "entry to be "
697 "generated by the application (port_mask "
700 for (i = 0; i < APP_MAX_LINKS; i++) {
701 if (p->pci_whitelist[i])
704 p->pci_whitelist[i] = strdup(entry->value);
705 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
710 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
711 section_name, entry->name,
712 "too many elements");
717 if (strcmp(entry->name, "vdev") == 0) {
720 for (i = 0; i < APP_MAX_LINKS; i++) {
724 p->vdev[i] = strdup(entry->value);
725 PARSE_ERROR_MALLOC(p->vdev[i]);
730 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
731 section_name, entry->name,
732 "too many elements");
737 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
740 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
743 p->vmware_tsc_map_present = 1;
745 val = parser_read_arg_bool(entry->value);
746 PARSE_ERROR((val >= 0), section_name, entry->name);
747 p->vmware_tsc_map = val;
752 if (strcmp(entry->name, "proc_type") == 0) {
753 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
756 p->proc_type = strdup(entry->value);
761 if (strcmp(entry->name, "syslog") == 0) {
762 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
765 p->syslog = strdup(entry->value);
770 if (strcmp(entry->name, "log_level") == 0) {
773 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
776 p->log_level_present = 1;
778 status = parser_read_uint32(&p->log_level,
780 PARSE_ERROR((status == 0), section_name, entry->name);
785 if (strcmp(entry->name, "v") == 0) {
788 PARSE_ERROR_DUPLICATE((p->version_present == 0),
791 p->version_present = 1;
793 val = parser_read_arg_bool(entry->value);
794 PARSE_ERROR((val >= 0), section_name, entry->name);
800 if ((strcmp(entry->name, "help") == 0) ||
801 (strcmp(entry->name, "h") == 0)) {
804 PARSE_ERROR_DUPLICATE((p->help_present == 0),
809 val = parser_read_arg_bool(entry->value);
810 PARSE_ERROR((val >= 0), section_name, entry->name);
816 if (strcmp(entry->name, "no_huge") == 0) {
819 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
822 p->no_huge_present = 1;
824 val = parser_read_arg_bool(entry->value);
825 PARSE_ERROR((val >= 0), section_name, entry->name);
831 if (strcmp(entry->name, "no_pci") == 0) {
834 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
837 p->no_pci_present = 1;
839 val = parser_read_arg_bool(entry->value);
840 PARSE_ERROR((val >= 0), section_name, entry->name);
846 if (strcmp(entry->name, "no_hpet") == 0) {
849 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
852 p->no_hpet_present = 1;
854 val = parser_read_arg_bool(entry->value);
855 PARSE_ERROR((val >= 0), section_name, entry->name);
861 if (strcmp(entry->name, "no_shconf") == 0) {
864 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
867 p->no_shconf_present = 1;
869 val = parser_read_arg_bool(entry->value);
870 PARSE_ERROR((val >= 0), section_name, entry->name);
876 if (strcmp(entry->name, "d") == 0) {
877 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
880 p->add_driver = strdup(entry->value);
885 if (strcmp(entry->name, "socket_mem") == 0) {
886 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
889 p->socket_mem = strdup(entry->value);
894 if (strcmp(entry->name, "huge_dir") == 0) {
895 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
898 p->huge_dir = strdup(entry->value);
903 if (strcmp(entry->name, "file_prefix") == 0) {
904 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
907 p->file_prefix = strdup(entry->value);
912 if (strcmp(entry->name, "base_virtaddr") == 0) {
913 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
916 p->base_virtaddr = strdup(entry->value);
921 if (strcmp(entry->name, "create_uio_dev") == 0) {
924 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
927 p->create_uio_dev_present = 1;
929 val = parser_read_arg_bool(entry->value);
930 PARSE_ERROR((val >= 0), section_name, entry->name);
931 p->create_uio_dev = val;
936 if (strcmp(entry->name, "vfio_intr") == 0) {
937 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
940 p->vfio_intr = strdup(entry->value);
945 if (strcmp(entry->name, "xen_dom0") == 0) {
948 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
951 p->xen_dom0_present = 1;
953 val = parser_read_arg_bool(entry->value);
954 PARSE_ERROR((val >= 0), section_name, entry->name);
960 PARSE_ERROR_INVALID(0, section_name, entry->name);
967 parse_pipeline_pcap_source(struct app_params *app,
968 struct app_pipeline_params *p,
969 const char *file_name, const char *cp_size)
971 const char *next = NULL;
976 if (file_name && !cp_size) {
978 parse_file = 1; /* parse file path */
979 } else if (cp_size && !file_name) {
981 parse_file = 0; /* parse copy size */
985 char name[APP_PARAM_NAME_SIZE];
988 if (p->n_pktq_in == 0)
992 while (*next != '\0') {
995 if (i >= p->n_pktq_in)
998 id = p->pktq_in[i].id;
1000 end = strchr(next, ' ');
1002 name_len = strlen(next);
1004 name_len = end - next;
1006 if (name_len == 0 || name_len == sizeof(name))
1009 strncpy(name, next, name_len);
1010 name[name_len] = '\0';
1016 app->source_params[id].file_name = strdup(name);
1017 if (app->source_params[id].file_name == NULL)
1020 if (parser_read_uint32(
1021 &app->source_params[id].n_bytes_per_pkt,
1023 if (app->source_params[id].
1025 free(app->source_params[id].
1033 if (i == p->n_pktq_in)
1041 parse_pipeline_pcap_sink(struct app_params *app,
1042 struct app_pipeline_params *p,
1043 const char *file_name, const char *n_pkts_to_dump)
1045 const char *next = NULL;
1050 if (file_name && !n_pkts_to_dump) {
1052 parse_file = 1; /* parse file path */
1053 } else if (n_pkts_to_dump && !file_name) {
1054 next = n_pkts_to_dump;
1055 parse_file = 0; /* parse copy size */
1059 char name[APP_PARAM_NAME_SIZE];
1062 if (p->n_pktq_out == 0)
1066 while (*next != '\0') {
1069 if (i >= p->n_pktq_out)
1072 id = p->pktq_out[i].id;
1074 end = strchr(next, ' ');
1076 name_len = strlen(next);
1078 name_len = end - next;
1080 if (name_len == 0 || name_len == sizeof(name))
1083 strncpy(name, next, name_len);
1084 name[name_len] = '\0';
1090 app->sink_params[id].file_name = strdup(name);
1091 if (app->sink_params[id].file_name == NULL)
1094 if (parser_read_uint32(
1095 &app->sink_params[id].n_pkts_to_dump,
1097 if (app->sink_params[id].file_name !=
1099 free(app->sink_params[id].
1107 if (i == p->n_pktq_out)
1115 parse_pipeline_pktq_in(struct app_params *app,
1116 struct app_pipeline_params *p,
1119 const char *next = value;
1121 char name[APP_PARAM_NAME_SIZE];
1124 while (*next != '\0') {
1125 enum app_pktq_in_type type;
1130 next = skip_white_spaces(next);
1134 end_space = strchr(next, ' ');
1135 end_tab = strchr(next, ' ');
1137 if (end_space && (!end_tab))
1139 else if ((!end_space) && end_tab)
1141 else if (end_space && end_tab)
1142 end = RTE_MIN(end_space, end_tab);
1147 name_len = strlen(next);
1149 name_len = end - next;
1151 if (name_len == 0 || name_len == sizeof(name))
1154 strncpy(name, next, name_len);
1155 name[name_len] = '\0';
1160 if (validate_name(name, "RXQ", 2) == 0) {
1161 type = APP_PKTQ_IN_HWQ;
1162 id = APP_PARAM_ADD(app->hwq_in_params, name);
1163 } else if (validate_name(name, "SWQ", 1) == 0) {
1164 type = APP_PKTQ_IN_SWQ;
1165 id = APP_PARAM_ADD(app->swq_params, name);
1166 } else if (validate_name(name, "TM", 1) == 0) {
1167 type = APP_PKTQ_IN_TM;
1168 id = APP_PARAM_ADD(app->tm_params, name);
1169 } else if (validate_name(name, "SOURCE", 1) == 0) {
1170 type = APP_PKTQ_IN_SOURCE;
1171 id = APP_PARAM_ADD(app->source_params, name);
1178 p->pktq_in[p->n_pktq_in].type = type;
1179 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1187 parse_pipeline_pktq_out(struct app_params *app,
1188 struct app_pipeline_params *p,
1191 const char *next = value;
1193 char name[APP_PARAM_NAME_SIZE];
1196 while (*next != '\0') {
1197 enum app_pktq_out_type type;
1202 next = skip_white_spaces(next);
1206 end_space = strchr(next, ' ');
1207 end_tab = strchr(next, ' ');
1209 if (end_space && (!end_tab))
1211 else if ((!end_space) && end_tab)
1213 else if (end_space && end_tab)
1214 end = RTE_MIN(end_space, end_tab);
1219 name_len = strlen(next);
1221 name_len = end - next;
1223 if (name_len == 0 || name_len == sizeof(name))
1226 strncpy(name, next, name_len);
1227 name[name_len] = '\0';
1231 if (validate_name(name, "TXQ", 2) == 0) {
1232 type = APP_PKTQ_OUT_HWQ;
1233 id = APP_PARAM_ADD(app->hwq_out_params, name);
1234 } else if (validate_name(name, "SWQ", 1) == 0) {
1235 type = APP_PKTQ_OUT_SWQ;
1236 id = APP_PARAM_ADD(app->swq_params, name);
1237 } else if (validate_name(name, "TM", 1) == 0) {
1238 type = APP_PKTQ_OUT_TM;
1239 id = APP_PARAM_ADD(app->tm_params, name);
1240 } else if (validate_name(name, "SINK", 1) == 0) {
1241 type = APP_PKTQ_OUT_SINK;
1242 id = APP_PARAM_ADD(app->sink_params, name);
1249 p->pktq_out[p->n_pktq_out].type = type;
1250 p->pktq_out[p->n_pktq_out].id = id;
1258 parse_pipeline_msgq_in(struct app_params *app,
1259 struct app_pipeline_params *p,
1262 const char *next = value;
1264 char name[APP_PARAM_NAME_SIZE];
1268 while (*next != '\0') {
1272 next = skip_white_spaces(next);
1276 end_space = strchr(next, ' ');
1277 end_tab = strchr(next, ' ');
1279 if (end_space && (!end_tab))
1281 else if ((!end_space) && end_tab)
1283 else if (end_space && end_tab)
1284 end = RTE_MIN(end_space, end_tab);
1289 name_len = strlen(next);
1291 name_len = end - next;
1293 if (name_len == 0 || name_len == sizeof(name))
1296 strncpy(name, next, name_len);
1297 name[name_len] = '\0';
1302 if (validate_name(name, "MSGQ", 1) != 0)
1305 idx = APP_PARAM_ADD(app->msgq_params, name);
1309 p->msgq_in[p->n_msgq_in] = idx;
1317 parse_pipeline_msgq_out(struct app_params *app,
1318 struct app_pipeline_params *p,
1321 const char *next = value;
1323 char name[APP_PARAM_NAME_SIZE];
1327 while (*next != '\0') {
1331 next = skip_white_spaces(next);
1335 end_space = strchr(next, ' ');
1336 end_tab = strchr(next, ' ');
1338 if (end_space && (!end_tab))
1340 else if ((!end_space) && end_tab)
1342 else if (end_space && end_tab)
1343 end = RTE_MIN(end_space, end_tab);
1348 name_len = strlen(next);
1350 name_len = end - next;
1352 if (name_len == 0 || name_len == sizeof(name))
1355 strncpy(name, next, name_len);
1356 name[name_len] = '\0';
1361 if (validate_name(name, "MSGQ", 1) != 0)
1364 idx = APP_PARAM_ADD(app->msgq_params, name);
1368 p->msgq_out[p->n_msgq_out] = idx;
1376 parse_pipeline(struct app_params *app,
1377 const char *section_name,
1378 struct rte_cfgfile *cfg)
1380 char name[CFG_NAME_LEN];
1381 struct app_pipeline_params *param;
1382 struct rte_cfgfile_entry *entries;
1386 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1387 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1389 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1390 PARSE_ERROR_MALLOC(entries != NULL);
1392 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1394 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1395 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1397 param = &app->pipeline_params[param_idx];
1399 for (i = 0; i < n_entries; i++) {
1400 struct rte_cfgfile_entry *ent = &entries[i];
1402 if (strcmp(ent->name, "type") == 0) {
1403 int w_size = snprintf(param->type, RTE_DIM(param->type),
1406 PARSE_ERROR(((w_size > 0) &&
1407 (w_size < (int)RTE_DIM(param->type))),
1413 if (strcmp(ent->name, "core") == 0) {
1414 int status = parse_pipeline_core(
1415 ¶m->socket_id, ¶m->core_id,
1416 ¶m->hyper_th_id, ent->value);
1418 PARSE_ERROR((status == 0), section_name,
1423 if (strcmp(ent->name, "pktq_in") == 0) {
1424 int status = parse_pipeline_pktq_in(app, param,
1427 PARSE_ERROR((status == 0), section_name,
1432 if (strcmp(ent->name, "pktq_out") == 0) {
1433 int status = parse_pipeline_pktq_out(app, param,
1436 PARSE_ERROR((status == 0), section_name,
1441 if (strcmp(ent->name, "msgq_in") == 0) {
1442 int status = parse_pipeline_msgq_in(app, param,
1445 PARSE_ERROR((status == 0), section_name,
1450 if (strcmp(ent->name, "msgq_out") == 0) {
1451 int status = parse_pipeline_msgq_out(app, param,
1454 PARSE_ERROR((status == 0), section_name,
1459 if (strcmp(ent->name, "timer_period") == 0) {
1460 int status = parser_read_uint32(
1461 ¶m->timer_period,
1464 PARSE_ERROR((status == 0), section_name,
1469 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1472 #ifndef RTE_PORT_PCAP
1473 PARSE_ERROR_INVALID(0, section_name, ent->name);
1476 status = parse_pipeline_pcap_source(app,
1477 param, ent->value, NULL);
1479 PARSE_ERROR((status == 0), section_name,
1484 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1487 #ifndef RTE_PORT_PCAP
1488 PARSE_ERROR_INVALID(0, section_name, ent->name);
1491 status = parse_pipeline_pcap_source(app,
1492 param, NULL, ent->value);
1494 PARSE_ERROR((status == 0), section_name,
1499 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1502 #ifndef RTE_PORT_PCAP
1503 PARSE_ERROR_INVALID(0, section_name, ent->name);
1506 status = parse_pipeline_pcap_sink(app, param,
1509 PARSE_ERROR((status == 0), section_name,
1514 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1517 #ifndef RTE_PORT_PCAP
1518 PARSE_ERROR_INVALID(0, section_name, ent->name);
1521 status = parse_pipeline_pcap_sink(app, param,
1524 PARSE_ERROR((status == 0), section_name,
1529 /* pipeline type specific items */
1530 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1531 "Parse error in section \"%s\": too many "
1532 "pipeline specified parameters", section_name);
1534 param->args_name[param->n_args] = strdup(ent->name);
1535 param->args_value[param->n_args] = strdup(ent->value);
1537 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1538 (param->args_value[param->n_args] != NULL),
1539 "Parse error: no free memory");
1546 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1547 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1548 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1549 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1550 param->msgq_in[param->n_msgq_in++] = param_idx;
1552 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1553 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1554 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1555 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1556 param->msgq_out[param->n_msgq_out++] = param_idx;
1558 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1561 (param->hyper_th_id) ? "h" : "");
1562 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1563 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1564 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1566 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1569 (param->hyper_th_id) ? "h" : "");
1570 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1571 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1572 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1578 parse_mempool(struct app_params *app,
1579 const char *section_name,
1580 struct rte_cfgfile *cfg)
1582 struct app_mempool_params *param;
1583 struct rte_cfgfile_entry *entries;
1587 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1588 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1590 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1591 PARSE_ERROR_MALLOC(entries != NULL);
1593 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1595 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1596 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1598 param = &app->mempool_params[param_idx];
1600 for (i = 0; i < n_entries; i++) {
1601 struct rte_cfgfile_entry *ent = &entries[i];
1603 if (strcmp(ent->name, "buffer_size") == 0) {
1604 int status = parser_read_uint32(
1605 ¶m->buffer_size, ent->value);
1607 PARSE_ERROR((status == 0), section_name,
1612 if (strcmp(ent->name, "pool_size") == 0) {
1613 int status = parser_read_uint32(
1614 ¶m->pool_size, ent->value);
1616 PARSE_ERROR((status == 0), section_name,
1621 if (strcmp(ent->name, "cache_size") == 0) {
1622 int status = parser_read_uint32(
1623 ¶m->cache_size, ent->value);
1625 PARSE_ERROR((status == 0), section_name,
1630 if (strcmp(ent->name, "cpu") == 0) {
1631 int status = parser_read_uint32(
1632 ¶m->cpu_socket_id, ent->value);
1634 PARSE_ERROR((status == 0), section_name,
1640 PARSE_ERROR_INVALID(0, section_name, ent->name);
1649 parse_link(struct app_params *app,
1650 const char *section_name,
1651 struct rte_cfgfile *cfg)
1653 struct app_link_params *param;
1654 struct rte_cfgfile_entry *entries;
1656 int pci_bdf_present = 0;
1659 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1660 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1662 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1663 PARSE_ERROR_MALLOC(entries != NULL);
1665 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1667 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1668 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1670 param = &app->link_params[param_idx];
1672 for (i = 0; i < n_entries; i++) {
1673 struct rte_cfgfile_entry *ent = &entries[i];
1675 if (strcmp(ent->name, "promisc") == 0) {
1676 int status = parser_read_arg_bool(ent->value);
1678 PARSE_ERROR((status != -EINVAL), section_name,
1680 param->promisc = status;
1684 if (strcmp(ent->name, "arp_q") == 0) {
1685 int status = parser_read_uint32(¶m->arp_q,
1688 PARSE_ERROR((status == 0), section_name,
1693 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1694 int status = parser_read_uint32(
1695 ¶m->tcp_syn_q, ent->value);
1697 PARSE_ERROR((status == 0), section_name, ent->name);
1701 if (strcmp(ent->name, "ip_local_q") == 0) {
1702 int status = parser_read_uint32(
1703 ¶m->ip_local_q, ent->value);
1705 PARSE_ERROR((status == 0), section_name,
1711 if (strcmp(ent->name, "tcp_local_q") == 0) {
1712 int status = parser_read_uint32(
1713 ¶m->tcp_local_q, ent->value);
1715 PARSE_ERROR((status == 0), section_name,
1720 if (strcmp(ent->name, "udp_local_q") == 0) {
1721 int status = parser_read_uint32(
1722 ¶m->udp_local_q, ent->value);
1724 PARSE_ERROR((status == 0), section_name,
1729 if (strcmp(ent->name, "sctp_local_q") == 0) {
1730 int status = parser_read_uint32(
1731 ¶m->sctp_local_q, ent->value);
1733 PARSE_ERROR((status == 0), section_name,
1738 if (strcmp(ent->name, "pci_bdf") == 0) {
1739 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1740 section_name, ent->name);
1742 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1744 pci_bdf_present = 1;
1749 PARSE_ERROR_INVALID(0, section_name, ent->name);
1752 /* Check for mandatory fields */
1754 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1755 section_name, "pci_bdf",
1756 "entry not allowed (port_mask is provided)");
1758 PARSE_ERROR_MESSAGE((pci_bdf_present),
1759 section_name, "pci_bdf",
1760 "this entry is mandatory (port_mask is not "
1769 parse_rxq(struct app_params *app,
1770 const char *section_name,
1771 struct rte_cfgfile *cfg)
1773 struct app_pktq_hwq_in_params *param;
1774 struct rte_cfgfile_entry *entries;
1778 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1779 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1781 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1782 PARSE_ERROR_MALLOC(entries != NULL);
1784 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1786 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1787 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1789 param = &app->hwq_in_params[param_idx];
1791 for (i = 0; i < n_entries; i++) {
1792 struct rte_cfgfile_entry *ent = &entries[i];
1794 if (strcmp(ent->name, "mempool") == 0) {
1795 int status = validate_name(ent->value,
1799 PARSE_ERROR((status == 0), section_name,
1801 idx = APP_PARAM_ADD(app->mempool_params,
1803 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1805 param->mempool_id = idx;
1809 if (strcmp(ent->name, "size") == 0) {
1810 int status = parser_read_uint32(¶m->size,
1813 PARSE_ERROR((status == 0), section_name,
1818 if (strcmp(ent->name, "burst") == 0) {
1819 int status = parser_read_uint32(¶m->burst,
1822 PARSE_ERROR((status == 0), section_name,
1828 PARSE_ERROR_INVALID(0, section_name, ent->name);
1837 parse_txq(struct app_params *app,
1838 const char *section_name,
1839 struct rte_cfgfile *cfg)
1841 struct app_pktq_hwq_out_params *param;
1842 struct rte_cfgfile_entry *entries;
1846 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1847 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1849 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1850 PARSE_ERROR_MALLOC(entries != NULL);
1852 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1854 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1855 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1857 param = &app->hwq_out_params[param_idx];
1859 for (i = 0; i < n_entries; i++) {
1860 struct rte_cfgfile_entry *ent = &entries[i];
1862 if (strcmp(ent->name, "size") == 0) {
1863 int status = parser_read_uint32(¶m->size,
1866 PARSE_ERROR((status == 0), section_name,
1871 if (strcmp(ent->name, "burst") == 0) {
1872 int status = parser_read_uint32(¶m->burst,
1875 PARSE_ERROR((status == 0), section_name,
1880 if (strcmp(ent->name, "dropless") == 0) {
1881 int status = parser_read_arg_bool(ent->value);
1884 PARSE_ERROR((status != -EINVAL), section_name,
1886 param->dropless = status;
1891 PARSE_ERROR_INVALID(0, section_name, ent->name);
1900 parse_swq(struct app_params *app,
1901 const char *section_name,
1902 struct rte_cfgfile *cfg)
1904 struct app_pktq_swq_params *param;
1905 struct rte_cfgfile_entry *entries;
1907 uint32_t mtu_present = 0;
1908 uint32_t metadata_size_present = 0;
1909 uint32_t mempool_direct_present = 0;
1910 uint32_t mempool_indirect_present = 0;
1914 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1915 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1917 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1918 PARSE_ERROR_MALLOC(entries != NULL);
1920 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1922 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1923 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1925 param = &app->swq_params[param_idx];
1927 for (i = 0; i < n_entries; i++) {
1928 struct rte_cfgfile_entry *ent = &entries[i];
1930 if (strcmp(ent->name, "size") == 0) {
1931 int status = parser_read_uint32(¶m->size,
1934 PARSE_ERROR((status == 0), section_name,
1939 if (strcmp(ent->name, "burst_read") == 0) {
1940 int status = parser_read_uint32(&
1941 param->burst_read, ent->value);
1943 PARSE_ERROR((status == 0), section_name,
1948 if (strcmp(ent->name, "burst_write") == 0) {
1949 int status = parser_read_uint32(
1950 ¶m->burst_write, ent->value);
1952 PARSE_ERROR((status == 0), section_name,
1957 if (strcmp(ent->name, "dropless") == 0) {
1958 int status = parser_read_arg_bool(ent->value);
1960 PARSE_ERROR((status != -EINVAL), section_name,
1962 param->dropless = status;
1966 if (strcmp(ent->name, "n_retries") == 0) {
1967 int status = parser_read_uint64(¶m->n_retries,
1970 PARSE_ERROR((status == 0), section_name,
1975 if (strcmp(ent->name, "cpu") == 0) {
1976 int status = parser_read_uint32(
1977 ¶m->cpu_socket_id, ent->value);
1979 PARSE_ERROR((status == 0), section_name, ent->name);
1983 if (strcmp(ent->name, "ipv4_frag") == 0) {
1984 int status = parser_read_arg_bool(ent->value);
1986 PARSE_ERROR((status != -EINVAL), section_name,
1989 param->ipv4_frag = status;
1990 if (param->mtu == 0)
1996 if (strcmp(ent->name, "ipv6_frag") == 0) {
1997 int status = parser_read_arg_bool(ent->value);
1999 PARSE_ERROR((status != -EINVAL), section_name,
2001 param->ipv6_frag = status;
2002 if (param->mtu == 0)
2007 if (strcmp(ent->name, "ipv4_ras") == 0) {
2008 int status = parser_read_arg_bool(ent->value);
2010 PARSE_ERROR((status != -EINVAL), section_name,
2012 param->ipv4_ras = status;
2016 if (strcmp(ent->name, "ipv6_ras") == 0) {
2017 int status = parser_read_arg_bool(ent->value);
2019 PARSE_ERROR((status != -EINVAL), section_name,
2021 param->ipv6_ras = status;
2025 if (strcmp(ent->name, "mtu") == 0) {
2026 int status = parser_read_uint32(¶m->mtu,
2029 PARSE_ERROR((status == 0), section_name,
2035 if (strcmp(ent->name, "metadata_size") == 0) {
2036 int status = parser_read_uint32(
2037 ¶m->metadata_size, ent->value);
2039 PARSE_ERROR((status == 0), section_name,
2041 metadata_size_present = 1;
2045 if (strcmp(ent->name, "mempool_direct") == 0) {
2046 int status = validate_name(ent->value,
2050 PARSE_ERROR((status == 0), section_name,
2053 idx = APP_PARAM_ADD(app->mempool_params,
2055 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2057 param->mempool_direct_id = idx;
2058 mempool_direct_present = 1;
2062 if (strcmp(ent->name, "mempool_indirect") == 0) {
2063 int status = validate_name(ent->value,
2067 PARSE_ERROR((status == 0), section_name,
2069 idx = APP_PARAM_ADD(app->mempool_params,
2071 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2073 param->mempool_indirect_id = idx;
2074 mempool_indirect_present = 1;
2079 PARSE_ERROR_INVALID(0, section_name, ent->name);
2082 APP_CHECK(((mtu_present) &&
2083 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2084 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2085 "is off, therefore entry \"mtu\" is not allowed",
2088 APP_CHECK(((metadata_size_present) &&
2089 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2090 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2091 "is off, therefore entry \"metadata_size\" is "
2092 "not allowed", section_name);
2094 APP_CHECK(((mempool_direct_present) &&
2095 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2096 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2097 "is off, therefore entry \"mempool_direct\" is "
2098 "not allowed", section_name);
2100 APP_CHECK(((mempool_indirect_present) &&
2101 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2102 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2103 "is off, therefore entry \"mempool_indirect\" is "
2104 "not allowed", section_name);
2112 parse_tm(struct app_params *app,
2113 const char *section_name,
2114 struct rte_cfgfile *cfg)
2116 struct app_pktq_tm_params *param;
2117 struct rte_cfgfile_entry *entries;
2121 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2122 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2124 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2125 PARSE_ERROR_MALLOC(entries != NULL);
2127 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2129 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2130 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2132 param = &app->tm_params[param_idx];
2134 for (i = 0; i < n_entries; i++) {
2135 struct rte_cfgfile_entry *ent = &entries[i];
2137 if (strcmp(ent->name, "cfg") == 0) {
2138 param->file_name = strdup(ent->value);
2139 PARSE_ERROR_MALLOC(param->file_name != NULL);
2143 if (strcmp(ent->name, "burst_read") == 0) {
2144 int status = parser_read_uint32(
2145 ¶m->burst_read, ent->value);
2147 PARSE_ERROR((status == 0), section_name,
2152 if (strcmp(ent->name, "burst_write") == 0) {
2153 int status = parser_read_uint32(
2154 ¶m->burst_write, ent->value);
2156 PARSE_ERROR((status == 0), section_name,
2162 PARSE_ERROR_INVALID(0, section_name, ent->name);
2171 parse_source(struct app_params *app,
2172 const char *section_name,
2173 struct rte_cfgfile *cfg)
2175 struct app_pktq_source_params *param;
2176 struct rte_cfgfile_entry *entries;
2179 uint32_t pcap_file_present = 0;
2180 uint32_t pcap_size_present = 0;
2182 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2183 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2185 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2186 PARSE_ERROR_MALLOC(entries != NULL);
2188 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2190 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2191 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2193 param = &app->source_params[param_idx];
2195 for (i = 0; i < n_entries; i++) {
2196 struct rte_cfgfile_entry *ent = &entries[i];
2198 if (strcmp(ent->name, "mempool") == 0) {
2199 int status = validate_name(ent->value,
2203 PARSE_ERROR((status == 0), section_name,
2205 idx = APP_PARAM_ADD(app->mempool_params,
2207 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2209 param->mempool_id = idx;
2213 if (strcmp(ent->name, "burst") == 0) {
2214 int status = parser_read_uint32(¶m->burst,
2217 PARSE_ERROR((status == 0), section_name,
2222 if (strcmp(ent->name, "pcap_file_rd")) {
2223 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2224 section_name, ent->name);
2226 param->file_name = strdup(ent->value);
2228 PARSE_ERROR_MALLOC(param->file_name != NULL);
2229 pcap_file_present = 1;
2234 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2237 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2238 section_name, ent->name);
2240 status = parser_read_uint32(
2241 ¶m->n_bytes_per_pkt, ent->value);
2243 PARSE_ERROR((status == 0), section_name,
2245 pcap_size_present = 1;
2251 PARSE_ERROR_INVALID(0, section_name, ent->name);
2260 parse_sink(struct app_params *app,
2261 const char *section_name,
2262 struct rte_cfgfile *cfg)
2264 struct app_pktq_sink_params *param;
2265 struct rte_cfgfile_entry *entries;
2268 uint32_t pcap_file_present = 0;
2269 uint32_t pcap_n_pkt_present = 0;
2271 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2272 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2274 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2275 PARSE_ERROR_MALLOC(entries != NULL);
2277 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2279 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2280 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2282 param = &app->sink_params[param_idx];
2284 for (i = 0; i < n_entries; i++) {
2285 struct rte_cfgfile_entry *ent = &entries[i];
2287 if (strcmp(ent->name, "pcap_file_wr")) {
2288 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2289 section_name, ent->name);
2291 param->file_name = strdup(ent->value);
2293 PARSE_ERROR_MALLOC((param->file_name != NULL));
2298 if (strcmp(ent->name, "pcap_n_pkt_wr")) {
2301 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2302 section_name, ent->name);
2304 status = parser_read_uint32(
2305 ¶m->n_pkts_to_dump, ent->value);
2307 PARSE_ERROR((status == 0), section_name,
2314 PARSE_ERROR_INVALID(0, section_name, ent->name);
2323 parse_msgq_req_pipeline(struct app_params *app,
2324 const char *section_name,
2325 struct rte_cfgfile *cfg)
2327 struct app_msgq_params *param;
2328 struct rte_cfgfile_entry *entries;
2332 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2333 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2335 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2336 PARSE_ERROR_MALLOC(entries != NULL);
2338 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2340 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2341 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2343 param = &app->msgq_params[param_idx];
2345 for (i = 0; i < n_entries; i++) {
2346 struct rte_cfgfile_entry *ent = &entries[i];
2348 if (strcmp(ent->name, "size") == 0) {
2349 int status = parser_read_uint32(¶m->size,
2352 PARSE_ERROR((status == 0), section_name,
2358 PARSE_ERROR_INVALID(0, section_name, ent->name);
2366 parse_msgq_rsp_pipeline(struct app_params *app,
2367 const char *section_name,
2368 struct rte_cfgfile *cfg)
2370 struct app_msgq_params *param;
2371 struct rte_cfgfile_entry *entries;
2375 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2376 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2378 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2379 PARSE_ERROR_MALLOC(entries != NULL);
2381 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2383 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2384 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2386 param = &app->msgq_params[param_idx];
2388 for (i = 0; i < n_entries; i++) {
2389 struct rte_cfgfile_entry *ent = &entries[i];
2391 if (strcmp(ent->name, "size") == 0) {
2392 int status = parser_read_uint32(¶m->size,
2395 PARSE_ERROR((status == 0), section_name,
2401 PARSE_ERROR_INVALID(0, section_name, ent->name);
2410 parse_msgq(struct app_params *app,
2411 const char *section_name,
2412 struct rte_cfgfile *cfg)
2414 struct app_msgq_params *param;
2415 struct rte_cfgfile_entry *entries;
2419 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2420 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2422 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2423 PARSE_ERROR_MALLOC(entries != NULL);
2425 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2427 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2428 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2430 param = &app->msgq_params[param_idx];
2432 for (i = 0; i < n_entries; i++) {
2433 struct rte_cfgfile_entry *ent = &entries[i];
2435 if (strcmp(ent->name, "size") == 0) {
2436 int status = parser_read_uint32(¶m->size,
2439 PARSE_ERROR((status == 0), section_name,
2444 if (strcmp(ent->name, "cpu") == 0) {
2445 int status = parser_read_uint32(
2446 ¶m->cpu_socket_id, ent->value);
2448 PARSE_ERROR((status == 0), section_name,
2454 PARSE_ERROR_INVALID(0, section_name, ent->name);
2462 typedef void (*config_section_load)(struct app_params *p,
2463 const char *section_name,
2464 struct rte_cfgfile *cfg);
2466 struct config_section {
2467 const char prefix[CFG_NAME_LEN];
2469 config_section_load load;
2472 static const struct config_section cfg_file_scheme[] = {
2473 {"EAL", 0, parse_eal},
2474 {"PIPELINE", 1, parse_pipeline},
2475 {"MEMPOOL", 1, parse_mempool},
2476 {"LINK", 1, parse_link},
2477 {"RXQ", 2, parse_rxq},
2478 {"TXQ", 2, parse_txq},
2479 {"SWQ", 1, parse_swq},
2480 {"TM", 1, parse_tm},
2481 {"SOURCE", 1, parse_source},
2482 {"SINK", 1, parse_sink},
2483 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2484 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2485 {"MSGQ", 1, parse_msgq},
2489 create_implicit_mempools(struct app_params *app)
2493 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2494 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2498 create_implicit_links_from_port_mask(struct app_params *app,
2501 uint32_t pmd_id, link_id;
2504 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2505 char name[APP_PARAM_NAME_SIZE];
2508 if ((port_mask & (1LLU << pmd_id)) == 0)
2511 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2512 idx = APP_PARAM_ADD(app->link_params, name);
2513 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2515 app->link_params[idx].pmd_id = pmd_id;
2521 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2525 for (i = 0; i < app->n_links; i++) {
2526 struct app_link_params *link = &app->link_params[i];
2533 app_config_parse(struct app_params *app, const char *file_name)
2535 struct rte_cfgfile *cfg;
2536 char **section_names;
2537 int i, j, sect_count;
2539 /* Implicit mempools */
2540 create_implicit_mempools(app);
2544 create_implicit_links_from_port_mask(app, app->port_mask);
2546 /* Load application configuration file */
2547 cfg = rte_cfgfile_load(file_name, 0);
2548 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2549 "file %s", file_name);
2551 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2552 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2553 "in file \"%s\" return %d", file_name,
2556 section_names = malloc(sect_count * sizeof(char *));
2557 PARSE_ERROR_MALLOC(section_names != NULL);
2559 for (i = 0; i < sect_count; i++)
2560 section_names[i] = malloc(CFG_NAME_LEN);
2562 rte_cfgfile_sections(cfg, section_names, sect_count);
2564 for (i = 0; i < sect_count; i++) {
2565 const struct config_section *sch_s;
2566 int len, cfg_name_len;
2568 cfg_name_len = strlen(section_names[i]);
2570 /* Find section type */
2571 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2572 sch_s = &cfg_file_scheme[j];
2573 len = strlen(sch_s->prefix);
2575 if (cfg_name_len < len)
2578 /* After section name we expect only '\0' or digit or
2579 * digit dot digit, so protect against false matching,
2580 * for example: "ABC" should match section name
2581 * "ABC0.0", but it should not match section_name
2584 if ((section_names[i][len] != '\0') &&
2585 !isdigit(section_names[i][len]))
2588 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2592 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2593 "Parse error: unknown section %s",
2596 APP_CHECK(validate_name(section_names[i],
2598 sch_s->numbers) == 0,
2599 "Parse error: invalid section name \"%s\"",
2602 sch_s->load(app, section_names[i], cfg);
2605 for (i = 0; i < sect_count; i++)
2606 free(section_names[i]);
2608 free(section_names);
2610 rte_cfgfile_close(cfg);
2612 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2613 APP_PARAM_COUNT(app->link_params, app->n_links);
2614 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2615 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2616 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2617 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2618 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2619 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2620 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2621 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2623 #ifdef RTE_PORT_PCAP
2624 for (i = 0; i < (int)app->n_pktq_source; i++) {
2625 struct app_pktq_source_params *p = &app->source_params[i];
2627 APP_CHECK((p->file_name), "Parse error: missing "
2628 "mandatory field \"pcap_file_rd\" for \"%s\"",
2632 for (i = 0; i < (int)app->n_pktq_source; i++) {
2633 struct app_pktq_source_params *p = &app->source_params[i];
2635 APP_CHECK((!p->file_name), "Parse error: invalid field "
2636 "\"pcap_file_rd\" for \"%s\"", p->name);
2640 if (app->port_mask == 0)
2641 assign_link_pmd_id_from_pci_bdf(app);
2643 /* Save configuration to output file */
2644 app_config_save(app, app->output_file);
2646 /* Load TM configuration files */
2647 app_config_parse_tm(app);
2653 save_eal_params(struct app_params *app, FILE *f)
2655 struct app_eal_params *p = &app->eal_params;
2658 fprintf(f, "[EAL]\n");
2661 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2663 if (p->master_lcore_present)
2664 fprintf(f, "%s = %" PRIu32 "\n",
2665 "master_lcore", p->master_lcore);
2667 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2669 if (p->memory_present)
2670 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2672 if (p->ranks_present)
2673 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2675 for (i = 0; i < APP_MAX_LINKS; i++) {
2676 if (p->pci_blacklist[i] == NULL)
2679 fprintf(f, "%s = %s\n", "pci_blacklist",
2680 p->pci_blacklist[i]);
2683 for (i = 0; i < APP_MAX_LINKS; i++) {
2684 if (p->pci_whitelist[i] == NULL)
2687 fprintf(f, "%s = %s\n", "pci_whitelist",
2688 p->pci_whitelist[i]);
2691 for (i = 0; i < APP_MAX_LINKS; i++) {
2692 if (p->vdev[i] == NULL)
2695 fprintf(f, "%s = %s\n", "vdev",
2699 if (p->vmware_tsc_map_present)
2700 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2701 (p->vmware_tsc_map) ? "yes" : "no");
2704 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2707 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2709 if (p->log_level_present)
2710 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2712 if (p->version_present)
2713 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2715 if (p->help_present)
2716 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2718 if (p->no_huge_present)
2719 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2721 if (p->no_pci_present)
2722 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2724 if (p->no_hpet_present)
2725 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2727 if (p->no_shconf_present)
2728 fprintf(f, "%s = %s\n", "no_shconf",
2729 (p->no_shconf) ? "yes" : "no");
2732 fprintf(f, "%s = %s\n", "d", p->add_driver);
2735 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2738 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2741 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2743 if (p->base_virtaddr)
2744 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2746 if (p->create_uio_dev_present)
2747 fprintf(f, "%s = %s\n", "create_uio_dev",
2748 (p->create_uio_dev) ? "yes" : "no");
2751 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2753 if (p->xen_dom0_present)
2754 fprintf(f, "%s = %s\n", "xen_dom0",
2755 (p->xen_dom0) ? "yes" : "no");
2761 save_mempool_params(struct app_params *app, FILE *f)
2763 struct app_mempool_params *p;
2766 count = RTE_DIM(app->mempool_params);
2767 for (i = 0; i < count; i++) {
2768 p = &app->mempool_params[i];
2769 if (!APP_PARAM_VALID(p))
2772 fprintf(f, "[%s]\n", p->name);
2773 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2774 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2775 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2776 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2783 save_links_params(struct app_params *app, FILE *f)
2785 struct app_link_params *p;
2788 count = RTE_DIM(app->link_params);
2789 for (i = 0; i < count; i++) {
2790 p = &app->link_params[i];
2791 if (!APP_PARAM_VALID(p))
2794 fprintf(f, "[%s]\n", p->name);
2795 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2796 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2797 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2798 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2800 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2801 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2802 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2803 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2806 if (strlen(p->pci_bdf))
2807 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2814 save_rxq_params(struct app_params *app, FILE *f)
2816 struct app_pktq_hwq_in_params *p;
2819 count = RTE_DIM(app->hwq_in_params);
2820 for (i = 0; i < count; i++) {
2821 p = &app->hwq_in_params[i];
2822 if (!APP_PARAM_VALID(p))
2825 fprintf(f, "[%s]\n", p->name);
2826 fprintf(f, "%s = %s\n",
2828 app->mempool_params[p->mempool_id].name);
2829 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2830 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2837 save_txq_params(struct app_params *app, FILE *f)
2839 struct app_pktq_hwq_out_params *p;
2842 count = RTE_DIM(app->hwq_out_params);
2843 for (i = 0; i < count; i++) {
2844 p = &app->hwq_out_params[i];
2845 if (!APP_PARAM_VALID(p))
2848 fprintf(f, "[%s]\n", p->name);
2849 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2850 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2851 fprintf(f, "%s = %s\n",
2853 p->dropless ? "yes" : "no");
2860 save_swq_params(struct app_params *app, FILE *f)
2862 struct app_pktq_swq_params *p;
2865 count = RTE_DIM(app->swq_params);
2866 for (i = 0; i < count; i++) {
2867 p = &app->swq_params[i];
2868 if (!APP_PARAM_VALID(p))
2871 fprintf(f, "[%s]\n", p->name);
2872 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2873 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2874 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2875 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2876 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2877 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2878 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2879 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2880 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2881 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2882 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2883 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2884 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2885 fprintf(f, "%s = %s\n",
2887 app->mempool_params[p->mempool_direct_id].name);
2888 fprintf(f, "%s = %s\n",
2890 app->mempool_params[p->mempool_indirect_id].name);
2898 save_tm_params(struct app_params *app, FILE *f)
2900 struct app_pktq_tm_params *p;
2903 count = RTE_DIM(app->tm_params);
2904 for (i = 0; i < count; i++) {
2905 p = &app->tm_params[i];
2906 if (!APP_PARAM_VALID(p))
2909 fprintf(f, "[%s]\n", p->name);
2910 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2911 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2912 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2919 save_source_params(struct app_params *app, FILE *f)
2921 struct app_pktq_source_params *p;
2924 count = RTE_DIM(app->source_params);
2925 for (i = 0; i < count; i++) {
2926 p = &app->source_params[i];
2927 if (!APP_PARAM_VALID(p))
2930 fprintf(f, "[%s]\n", p->name);
2931 fprintf(f, "%s = %s\n",
2933 app->mempool_params[p->mempool_id].name);
2934 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2935 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2936 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2937 p->n_bytes_per_pkt);
2943 save_sink_params(struct app_params *app, FILE *f)
2945 struct app_pktq_sink_params *p;
2948 count = RTE_DIM(app->sink_params);
2949 for (i = 0; i < count; i++) {
2950 p = &app->sink_params[i];
2951 if (!APP_PARAM_VALID(p))
2954 fprintf(f, "[%s]\n", p->name);
2955 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2956 fprintf(f, "%s = %" PRIu32 "\n",
2957 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2963 save_msgq_params(struct app_params *app, FILE *f)
2965 struct app_msgq_params *p;
2968 count = RTE_DIM(app->msgq_params);
2969 for (i = 0; i < count; i++) {
2970 p = &app->msgq_params[i];
2971 if (!APP_PARAM_VALID(p))
2974 fprintf(f, "[%s]\n", p->name);
2975 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2976 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2983 save_pipeline_params(struct app_params *app, FILE *f)
2987 count = RTE_DIM(app->pipeline_params);
2988 for (i = 0; i < count; i++) {
2989 struct app_pipeline_params *p = &app->pipeline_params[i];
2991 if (!APP_PARAM_VALID(p))
2995 fprintf(f, "[%s]\n", p->name);
2998 fprintf(f, "type = %s\n", p->type);
3001 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
3004 (p->hyper_th_id) ? "h" : "");
3010 fprintf(f, "pktq_in =");
3011 for (j = 0; j < p->n_pktq_in; j++) {
3012 struct app_pktq_in_params *pp = &p->pktq_in[j];
3016 case APP_PKTQ_IN_HWQ:
3017 name = app->hwq_in_params[pp->id].name;
3019 case APP_PKTQ_IN_SWQ:
3020 name = app->swq_params[pp->id].name;
3022 case APP_PKTQ_IN_TM:
3023 name = app->tm_params[pp->id].name;
3025 case APP_PKTQ_IN_SOURCE:
3026 name = app->source_params[pp->id].name;
3029 APP_CHECK(0, "System error "
3030 "occurred while saving "
3031 "parameter to file");
3034 fprintf(f, " %s", name);
3040 if (p->n_pktq_out) {
3043 fprintf(f, "pktq_out =");
3044 for (j = 0; j < p->n_pktq_out; j++) {
3045 struct app_pktq_out_params *pp =
3050 case APP_PKTQ_OUT_HWQ:
3051 name = app->hwq_out_params[pp->id].name;
3053 case APP_PKTQ_OUT_SWQ:
3054 name = app->swq_params[pp->id].name;
3056 case APP_PKTQ_OUT_TM:
3057 name = app->tm_params[pp->id].name;
3059 case APP_PKTQ_OUT_SINK:
3060 name = app->sink_params[pp->id].name;
3063 APP_CHECK(0, "System error "
3064 "occurred while saving "
3065 "parameter to file");
3068 fprintf(f, " %s", name);
3077 fprintf(f, "msgq_in =");
3078 for (j = 0; j < p->n_msgq_in; j++) {
3079 uint32_t id = p->msgq_in[j];
3080 char *name = app->msgq_params[id].name;
3082 fprintf(f, " %s", name);
3088 if (p->n_msgq_out) {
3091 fprintf(f, "msgq_out =");
3092 for (j = 0; j < p->n_msgq_out; j++) {
3093 uint32_t id = p->msgq_out[j];
3094 char *name = app->msgq_params[id].name;
3096 fprintf(f, " %s", name);
3102 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3108 for (j = 0; j < p->n_args; j++)
3109 fprintf(f, "%s = %s\n", p->args_name[j],
3118 app_config_save(struct app_params *app, const char *file_name)
3121 char *name, *dir_name;
3124 name = strdup(file_name);
3125 dir_name = dirname(name);
3126 status = access(dir_name, W_OK);
3127 APP_CHECK((status == 0),
3128 "Error: need write access privilege to directory "
3129 "\"%s\" to save configuration\n", dir_name);
3131 file = fopen(file_name, "w");
3132 APP_CHECK((file != NULL),
3133 "Error: failed to save configuration to file \"%s\"",
3136 save_eal_params(app, file);
3137 save_pipeline_params(app, file);
3138 save_mempool_params(app, file);
3139 save_links_params(app, file);
3140 save_rxq_params(app, file);
3141 save_txq_params(app, file);
3142 save_swq_params(app, file);
3143 save_tm_params(app, file);
3144 save_source_params(app, file);
3145 save_sink_params(app, file);
3146 save_msgq_params(app, file);
3153 app_config_init(struct app_params *app)
3157 memcpy(app, &app_params_default, sizeof(struct app_params));
3159 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3160 memcpy(&app->mempool_params[i],
3161 &mempool_params_default,
3162 sizeof(struct app_mempool_params));
3164 for (i = 0; i < RTE_DIM(app->link_params); i++)
3165 memcpy(&app->link_params[i],
3166 &link_params_default,
3167 sizeof(struct app_link_params));
3169 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3170 memcpy(&app->hwq_in_params[i],
3171 &default_hwq_in_params,
3172 sizeof(default_hwq_in_params));
3174 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3175 memcpy(&app->hwq_out_params[i],
3176 &default_hwq_out_params,
3177 sizeof(default_hwq_out_params));
3179 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3180 memcpy(&app->swq_params[i],
3181 &default_swq_params,
3182 sizeof(default_swq_params));
3184 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3185 memcpy(&app->tm_params[i],
3187 sizeof(default_tm_params));
3189 for (i = 0; i < RTE_DIM(app->source_params); i++)
3190 memcpy(&app->source_params[i],
3191 &default_source_params,
3192 sizeof(default_source_params));
3194 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3195 memcpy(&app->sink_params[i],
3196 &default_sink_params,
3197 sizeof(default_sink_params));
3199 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3200 memcpy(&app->msgq_params[i],
3201 &default_msgq_params,
3202 sizeof(default_msgq_params));
3204 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3205 memcpy(&app->pipeline_params[i],
3206 &default_pipeline_params,
3207 sizeof(default_pipeline_params));
3213 filenamedup(const char *filename, const char *suffix)
3215 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3220 sprintf(s, "%s%s", filename, suffix);
3225 app_config_args(struct app_params *app, int argc, char **argv)
3227 const char *optname;
3228 int opt, option_index;
3229 int f_present, s_present, p_present, l_present;
3230 int preproc_present, preproc_params_present;
3233 static struct option lgopts[] = {
3234 { "preproc", 1, 0, 0 },
3235 { "preproc-args", 1, 0, 0 },
3239 /* Copy application name */
3240 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3246 preproc_present = 0;
3247 preproc_params_present = 0;
3249 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3250 &option_index)) != EOF)
3254 rte_panic("Error: Config file is provided "
3255 "more than once\n");
3258 if (!strlen(optarg))
3259 rte_panic("Error: Config file name is null\n");
3261 app->config_file = strdup(optarg);
3262 if (app->config_file == NULL)
3263 rte_panic("Error: Memory allocation failure\n");
3269 rte_panic("Error: Script file is provided "
3270 "more than once\n");
3273 if (!strlen(optarg))
3274 rte_panic("Error: Script file name is null\n");
3276 app->script_file = strdup(optarg);
3277 if (app->script_file == NULL)
3278 rte_panic("Error: Memory allocation failure\n");
3284 rte_panic("Error: PORT_MASK is provided "
3285 "more than once\n");
3288 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3290 ((size_t) scaned != strlen(optarg)))
3291 rte_panic("Error: PORT_MASK is not "
3292 "a hexadecimal integer\n");
3294 if (app->port_mask == 0)
3295 rte_panic("Error: PORT_MASK is null\n");
3301 rte_panic("Error: LOG_LEVEL is provided "
3302 "more than once\n");
3305 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3307 ((size_t) scaned != strlen(optarg)) ||
3308 (app->log_level >= APP_LOG_LEVELS))
3309 rte_panic("Error: LOG_LEVEL invalid value\n");
3314 optname = lgopts[option_index].name;
3316 if (strcmp(optname, "preproc") == 0) {
3317 if (preproc_present)
3318 rte_panic("Error: Preprocessor argument "
3319 "is provided more than once\n");
3320 preproc_present = 1;
3322 app->preproc = strdup(optarg);
3326 if (strcmp(optname, "preproc-args") == 0) {
3327 if (preproc_params_present)
3328 rte_panic("Error: Preprocessor args "
3329 "are provided more than once\n");
3330 preproc_params_present = 1;
3332 app->preproc_args = strdup(optarg);
3336 app_print_usage(argv[0]);
3340 app_print_usage(argv[0]);
3343 optind = 0; /* reset getopt lib */
3345 /* Check dependencies between args */
3346 if (preproc_params_present && (preproc_present == 0))
3347 rte_panic("Error: Preprocessor args specified while "
3348 "preprocessor is not defined\n");
3350 app->parser_file = preproc_present ?
3351 filenamedup(app->config_file, ".preproc") :
3352 strdup(app->config_file);
3353 app->output_file = filenamedup(app->config_file, ".out");
3359 app_config_preproc(struct app_params *app)
3364 if (app->preproc == NULL)
3367 status = access(app->config_file, F_OK | R_OK);
3368 APP_CHECK((status == 0), "Error: Unable to open file %s",
3371 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3373 app->preproc_args ? app->preproc_args : "",
3377 status = system(buffer);
3378 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3379 "Error occurred while pre-processing file \"%s\"\n",