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 = {
93 .mq_mode = ETH_MQ_RX_NONE,
95 .header_split = 0, /* Header split */
96 .hw_ip_checksum = 0, /* IP checksum offload */
97 .hw_vlan_filter = 0, /* VLAN filtering */
98 .hw_vlan_strip = 0, /* VLAN strip */
99 .hw_vlan_extend = 0, /* Extended VLAN */
100 .jumbo_frame = 0, /* Jumbo frame support */
101 .hw_strip_crc = 0, /* CRC strip by HW */
102 .enable_scatter = 0, /* Scattered packets RX handler */
104 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
105 .split_hdr_size = 0, /* Header split buffer size */
108 .mq_mode = ETH_MQ_TX_NONE,
116 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
128 .rx_free_thresh = 64,
130 .rx_deferred_start = 0,
134 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
149 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
150 ETH_TXQ_FLAGS_NOOFFLOADS,
151 .tx_deferred_start = 0,
155 static const struct app_pktq_swq_params default_swq_params = {
169 .mempool_direct_id = 0,
170 .mempool_indirect_id = 0,
173 struct app_pktq_tm_params default_tm_params = {
175 .file_name = "./config/tm_profile.cfg",
180 struct app_pktq_source_params default_source_params = {
185 .n_bytes_per_pkt = 0,
188 struct app_pktq_sink_params default_sink_params = {
194 struct app_msgq_params default_msgq_params = {
200 struct app_pipeline_params default_pipeline_params = {
213 static const char app_usage[] =
214 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
215 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
218 "\t-f CONFIG_FILE: Default config file is %s\n"
219 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
220 "config file when not provided)\n"
221 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
222 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
223 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
224 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
228 app_print_usage(char *prgname)
230 rte_exit(0, app_usage, prgname, app_params_default.config_file);
233 #define skip_white_spaces(pos) \
235 __typeof__(pos) _p = (pos); \
236 for ( ; isspace(*_p); _p++); \
240 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
242 APP_CHECK((result != -EINVAL), \
243 "Parse error: no free memory"); \
244 APP_CHECK((result != -ENOMEM), \
245 "Parse error: too many \"%s\" sections", section_name); \
246 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
247 "Parse error: duplicate \"%s\" section", section_name); \
248 APP_CHECK((result >= 0), \
249 "Parse error in section \"%s\"", section_name); \
253 parser_read_arg_bool(const char *p)
255 p = skip_white_spaces(p);
256 int result = -EINVAL;
258 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
259 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
264 if (((p[0] == 'o') && (p[1] == 'n')) ||
265 ((p[0] == 'O') && (p[1] == 'N'))) {
270 if (((p[0] == 'n') && (p[1] == 'o')) ||
271 ((p[0] == 'N') && (p[1] == 'O'))) {
276 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
277 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
282 p = skip_white_spaces(p);
290 #define PARSE_ERROR(exp, section, entry) \
291 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
293 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
294 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n", \
295 section, entry, message)
298 #define PARSE_ERROR_MALLOC(exp) \
299 APP_CHECK(exp, "Parse error: no free memory\n")
301 #define PARSE_ERROR_SECTION(exp, section) \
302 APP_CHECK(exp, "Parse error in section \"%s\"", section)
304 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
305 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
307 #define PARSE_WARNING_IGNORED(exp, section, entry) \
310 fprintf(stderr, "Parse warning in section \"%s\": " \
311 "entry \"%s\" is ignored\n", section, entry); \
314 #define PARSE_ERROR_INVALID(exp, section, entry) \
315 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
318 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
319 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
323 parser_read_uint64(uint64_t *value, const char *p)
328 p = skip_white_spaces(p);
332 val = strtoul(p, &next, 10);
354 p = skip_white_spaces(p);
363 parser_read_uint32(uint32_t *value, const char *p)
366 int ret = parser_read_uint64(&val, p);
371 if (val > UINT32_MAX)
379 parse_pipeline_core(uint32_t *socket,
387 uint32_t s = 0, c = 0, h = 0, val;
388 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
389 const char *next = skip_white_spaces(entry);
392 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
393 while (*next != '\0') {
394 /* If everything parsed nothing should left */
395 if (s_parsed && c_parsed && h_parsed)
402 if (s_parsed || c_parsed || h_parsed)
409 if (c_parsed || h_parsed)
422 /* If it start from digit it must be only core id. */
423 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
429 for (num_len = 0; *next != '\0'; next++, num_len++) {
430 if (num_len == RTE_DIM(num))
436 num[num_len] = *next;
439 if (num_len == 0 && type != 'h' && type != 'H')
442 if (num_len != 0 && (type == 'h' || type == 'H'))
446 val = strtol(num, NULL, 10);
475 case '0': case '1': case '2': case '3': case '4': case '5':
476 case '6': case '7': case '8': case '9':
478 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
480 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
488 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
493 /* Check input parameters */
501 if (((len & 3) != 0) ||
506 for (c = src; *c != 0; c++) {
507 if ((((*c) >= '0') && ((*c) <= '9')) ||
508 (((*c) >= 'A') && ((*c) <= 'F')) ||
509 (((*c) >= 'a') && ((*c) <= 'f')))
515 /* Convert chars to bytes */
516 for (i = 0; i < *size; i++)
517 dst[i] = get_hex_val(src[2 * i]) * 16 +
518 get_hex_val(src[2 * i + 1]);
524 skip_digits(const char *src)
528 for (i = 0; isdigit(src[i]); i++);
534 validate_name(const char *name, const char *prefix, int num)
538 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
539 if (name[i] != prefix[i])
543 if (prefix[i] != '\0')
554 j = skip_digits(&name[i]);
556 if ((j == 0) || (name[i] != '.'))
562 j = skip_digits(&name[i]);
564 if ((j == 0) || (name[i] != '\0'))
572 parse_eal(struct app_params *app,
573 const char *section_name,
574 struct rte_cfgfile *cfg)
576 struct app_eal_params *p = &app->eal_params;
577 struct rte_cfgfile_entry *entries;
580 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
581 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
583 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
584 PARSE_ERROR_MALLOC(entries != NULL);
586 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
588 for (i = 0; i < n_entries; i++) {
589 struct rte_cfgfile_entry *entry = &entries[i];
592 if (strcmp(entry->name, "c") == 0) {
593 PARSE_WARNING_IGNORED(0, section_name, entry->name);
598 if (strcmp(entry->name, "l") == 0) {
599 PARSE_WARNING_IGNORED(0, section_name, entry->name);
604 if (strcmp(entry->name, "lcores") == 0) {
605 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
608 p->coremap = strdup(entry->value);
613 if (strcmp(entry->name, "master_lcore") == 0) {
616 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
619 p->master_lcore_present = 1;
621 status = parser_read_uint32(&p->master_lcore,
623 PARSE_ERROR((status == 0), section_name, entry->name);
628 if (strcmp(entry->name, "n") == 0) {
631 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
634 p->channels_present = 1;
636 status = parser_read_uint32(&p->channels, entry->value);
637 PARSE_ERROR((status == 0), section_name, entry->name);
642 if (strcmp(entry->name, "m") == 0) {
645 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
648 p->memory_present = 1;
650 status = parser_read_uint32(&p->memory, entry->value);
651 PARSE_ERROR((status == 0), section_name, entry->name);
656 if (strcmp(entry->name, "r") == 0) {
659 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
662 p->ranks_present = 1;
664 status = parser_read_uint32(&p->ranks, entry->value);
665 PARSE_ERROR((status == 0), section_name, entry->name);
670 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
671 (strcmp(entry->name, "b") == 0)) {
674 for (i = 0; i < APP_MAX_LINKS; i++) {
675 if (p->pci_blacklist[i])
678 p->pci_blacklist[i] =
679 strdup(entry->value);
680 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
683 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
684 section_name, entry->name,
685 "too many elements");
690 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
691 (strcmp(entry->name, "w") == 0)) {
694 PARSE_ERROR_MESSAGE((app->port_mask != 0),
695 section_name, entry->name, "entry to be "
696 "generated by the application (port_mask "
699 for (i = 0; i < APP_MAX_LINKS; i++) {
700 if (p->pci_whitelist[i])
703 p->pci_whitelist[i] = strdup(entry->value);
704 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
707 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
708 section_name, entry->name,
709 "too many elements");
714 if (strcmp(entry->name, "vdev") == 0) {
717 for (i = 0; i < APP_MAX_LINKS; i++) {
721 p->vdev[i] = strdup(entry->value);
722 PARSE_ERROR_MALLOC(p->vdev[i]);
725 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
726 section_name, entry->name,
727 "too many elements");
732 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
735 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
738 p->vmware_tsc_map_present = 1;
740 val = parser_read_arg_bool(entry->value);
741 PARSE_ERROR((val >= 0), section_name, entry->name);
742 p->vmware_tsc_map = val;
747 if (strcmp(entry->name, "proc_type") == 0) {
748 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
751 p->proc_type = strdup(entry->value);
756 if (strcmp(entry->name, "syslog") == 0) {
757 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
760 p->syslog = strdup(entry->value);
765 if (strcmp(entry->name, "log_level") == 0) {
768 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
771 p->log_level_present = 1;
773 status = parser_read_uint32(&p->log_level,
775 PARSE_ERROR((status == 0), section_name, entry->name);
780 if (strcmp(entry->name, "v") == 0) {
783 PARSE_ERROR_DUPLICATE((p->version_present == 0),
786 p->version_present = 1;
788 val = parser_read_arg_bool(entry->value);
789 PARSE_ERROR((val >= 0), section_name, entry->name);
795 if ((strcmp(entry->name, "help") == 0) ||
796 (strcmp(entry->name, "h") == 0)) {
799 PARSE_ERROR_DUPLICATE((p->help_present == 0),
804 val = parser_read_arg_bool(entry->value);
805 PARSE_ERROR((val >= 0), section_name, entry->name);
811 if (strcmp(entry->name, "no_huge") == 0) {
814 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
817 p->no_huge_present = 1;
819 val = parser_read_arg_bool(entry->value);
820 PARSE_ERROR((val >= 0), section_name, entry->name);
826 if (strcmp(entry->name, "no_pci") == 0) {
829 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
832 p->no_pci_present = 1;
834 val = parser_read_arg_bool(entry->value);
835 PARSE_ERROR((val >= 0), section_name, entry->name);
841 if (strcmp(entry->name, "no_hpet") == 0) {
844 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
847 p->no_hpet_present = 1;
849 val = parser_read_arg_bool(entry->value);
850 PARSE_ERROR((val >= 0), section_name, entry->name);
856 if (strcmp(entry->name, "no_shconf") == 0) {
859 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
862 p->no_shconf_present = 1;
864 val = parser_read_arg_bool(entry->value);
865 PARSE_ERROR((val >= 0), section_name, entry->name);
871 if (strcmp(entry->name, "d") == 0) {
872 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
875 p->add_driver = strdup(entry->value);
880 if (strcmp(entry->name, "socket_mem") == 0) {
881 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
884 p->socket_mem = strdup(entry->value);
889 if (strcmp(entry->name, "huge_dir") == 0) {
890 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
893 p->huge_dir = strdup(entry->value);
898 if (strcmp(entry->name, "file_prefix") == 0) {
899 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
902 p->file_prefix = strdup(entry->value);
907 if (strcmp(entry->name, "base_virtaddr") == 0) {
908 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
911 p->base_virtaddr = strdup(entry->value);
916 if (strcmp(entry->name, "create_uio_dev") == 0) {
919 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
922 p->create_uio_dev_present = 1;
924 val = parser_read_arg_bool(entry->value);
925 PARSE_ERROR((val >= 0), section_name, entry->name);
926 p->create_uio_dev = val;
931 if (strcmp(entry->name, "vfio_intr") == 0) {
932 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
935 p->vfio_intr = strdup(entry->value);
940 if (strcmp(entry->name, "xen_dom0") == 0) {
943 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
946 p->xen_dom0_present = 1;
948 val = parser_read_arg_bool(entry->value);
949 PARSE_ERROR((val >= 0), section_name, entry->name);
955 PARSE_ERROR_INVALID(0, section_name, entry->name);
962 parse_pipeline_pcap_source(struct app_params *app,
963 struct app_pipeline_params *p,
964 const char *file_name, const char *cp_size)
966 const char *next = NULL;
971 if (file_name && !cp_size) {
973 parse_file = 1; /* parse file path */
974 } else if (cp_size && !file_name) {
976 parse_file = 0; /* parse copy size */
980 char name[APP_PARAM_NAME_SIZE];
983 if (p->n_pktq_in == 0)
986 for (i = 0; i < p->n_pktq_in; i++) {
987 if (p->pktq_in[i].type != APP_PKTQ_IN_SOURCE)
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)
1065 for (i = 0; i < p->n_pktq_out; i++) {
1066 if (p->pktq_out[i].type != APP_PKTQ_OUT_SINK)
1071 while (*next != '\0') {
1074 if (i >= p->n_pktq_out)
1077 id = p->pktq_out[i].id;
1079 end = strchr(next, ' ');
1081 name_len = strlen(next);
1083 name_len = end - next;
1085 if (name_len == 0 || name_len == sizeof(name))
1088 strncpy(name, next, name_len);
1089 name[name_len] = '\0';
1095 app->sink_params[id].file_name = strdup(name);
1096 if (app->sink_params[id].file_name == NULL)
1099 if (parser_read_uint32(
1100 &app->sink_params[id].n_pkts_to_dump,
1102 if (app->sink_params[id].file_name !=
1104 free(app->sink_params[id].
1112 if (i == p->n_pktq_out)
1120 parse_pipeline_pktq_in(struct app_params *app,
1121 struct app_pipeline_params *p,
1124 const char *next = value;
1126 char name[APP_PARAM_NAME_SIZE];
1129 while (*next != '\0') {
1130 enum app_pktq_in_type type;
1135 next = skip_white_spaces(next);
1139 end_space = strchr(next, ' ');
1140 end_tab = strchr(next, ' ');
1142 if (end_space && (!end_tab))
1144 else if ((!end_space) && end_tab)
1146 else if (end_space && end_tab)
1147 end = RTE_MIN(end_space, end_tab);
1152 name_len = strlen(next);
1154 name_len = end - next;
1156 if (name_len == 0 || name_len == sizeof(name))
1159 strncpy(name, next, name_len);
1160 name[name_len] = '\0';
1165 if (validate_name(name, "RXQ", 2) == 0) {
1166 type = APP_PKTQ_IN_HWQ;
1167 id = APP_PARAM_ADD(app->hwq_in_params, name);
1168 } else if (validate_name(name, "SWQ", 1) == 0) {
1169 type = APP_PKTQ_IN_SWQ;
1170 id = APP_PARAM_ADD(app->swq_params, name);
1171 } else if (validate_name(name, "TM", 1) == 0) {
1172 type = APP_PKTQ_IN_TM;
1173 id = APP_PARAM_ADD(app->tm_params, name);
1174 } else if (validate_name(name, "SOURCE", 1) == 0) {
1175 type = APP_PKTQ_IN_SOURCE;
1176 id = APP_PARAM_ADD(app->source_params, name);
1183 p->pktq_in[p->n_pktq_in].type = type;
1184 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1192 parse_pipeline_pktq_out(struct app_params *app,
1193 struct app_pipeline_params *p,
1196 const char *next = value;
1198 char name[APP_PARAM_NAME_SIZE];
1201 while (*next != '\0') {
1202 enum app_pktq_out_type type;
1207 next = skip_white_spaces(next);
1211 end_space = strchr(next, ' ');
1212 end_tab = strchr(next, ' ');
1214 if (end_space && (!end_tab))
1216 else if ((!end_space) && end_tab)
1218 else if (end_space && end_tab)
1219 end = RTE_MIN(end_space, end_tab);
1224 name_len = strlen(next);
1226 name_len = end - next;
1228 if (name_len == 0 || name_len == sizeof(name))
1231 strncpy(name, next, name_len);
1232 name[name_len] = '\0';
1236 if (validate_name(name, "TXQ", 2) == 0) {
1237 type = APP_PKTQ_OUT_HWQ;
1238 id = APP_PARAM_ADD(app->hwq_out_params, name);
1239 } else if (validate_name(name, "SWQ", 1) == 0) {
1240 type = APP_PKTQ_OUT_SWQ;
1241 id = APP_PARAM_ADD(app->swq_params, name);
1242 } else if (validate_name(name, "TM", 1) == 0) {
1243 type = APP_PKTQ_OUT_TM;
1244 id = APP_PARAM_ADD(app->tm_params, name);
1245 } else if (validate_name(name, "SINK", 1) == 0) {
1246 type = APP_PKTQ_OUT_SINK;
1247 id = APP_PARAM_ADD(app->sink_params, name);
1254 p->pktq_out[p->n_pktq_out].type = type;
1255 p->pktq_out[p->n_pktq_out].id = id;
1263 parse_pipeline_msgq_in(struct app_params *app,
1264 struct app_pipeline_params *p,
1267 const char *next = value;
1269 char name[APP_PARAM_NAME_SIZE];
1273 while (*next != '\0') {
1277 next = skip_white_spaces(next);
1281 end_space = strchr(next, ' ');
1282 end_tab = strchr(next, ' ');
1284 if (end_space && (!end_tab))
1286 else if ((!end_space) && end_tab)
1288 else if (end_space && end_tab)
1289 end = RTE_MIN(end_space, end_tab);
1294 name_len = strlen(next);
1296 name_len = end - next;
1298 if (name_len == 0 || name_len == sizeof(name))
1301 strncpy(name, next, name_len);
1302 name[name_len] = '\0';
1307 if (validate_name(name, "MSGQ", 1) != 0)
1310 idx = APP_PARAM_ADD(app->msgq_params, name);
1314 p->msgq_in[p->n_msgq_in] = idx;
1322 parse_pipeline_msgq_out(struct app_params *app,
1323 struct app_pipeline_params *p,
1326 const char *next = value;
1328 char name[APP_PARAM_NAME_SIZE];
1332 while (*next != '\0') {
1336 next = skip_white_spaces(next);
1340 end_space = strchr(next, ' ');
1341 end_tab = strchr(next, ' ');
1343 if (end_space && (!end_tab))
1345 else if ((!end_space) && end_tab)
1347 else if (end_space && end_tab)
1348 end = RTE_MIN(end_space, end_tab);
1353 name_len = strlen(next);
1355 name_len = end - next;
1357 if (name_len == 0 || name_len == sizeof(name))
1360 strncpy(name, next, name_len);
1361 name[name_len] = '\0';
1366 if (validate_name(name, "MSGQ", 1) != 0)
1369 idx = APP_PARAM_ADD(app->msgq_params, name);
1373 p->msgq_out[p->n_msgq_out] = idx;
1381 parse_pipeline(struct app_params *app,
1382 const char *section_name,
1383 struct rte_cfgfile *cfg)
1385 char name[CFG_NAME_LEN];
1386 struct app_pipeline_params *param;
1387 struct rte_cfgfile_entry *entries;
1391 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1392 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1394 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1395 PARSE_ERROR_MALLOC(entries != NULL);
1397 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1399 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1400 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1402 param = &app->pipeline_params[param_idx];
1404 for (i = 0; i < n_entries; i++) {
1405 struct rte_cfgfile_entry *ent = &entries[i];
1407 if (strcmp(ent->name, "type") == 0) {
1408 int w_size = snprintf(param->type, RTE_DIM(param->type),
1411 PARSE_ERROR(((w_size > 0) &&
1412 (w_size < (int)RTE_DIM(param->type))),
1418 if (strcmp(ent->name, "core") == 0) {
1419 int status = parse_pipeline_core(
1420 ¶m->socket_id, ¶m->core_id,
1421 ¶m->hyper_th_id, ent->value);
1423 PARSE_ERROR((status == 0), section_name,
1428 if (strcmp(ent->name, "pktq_in") == 0) {
1429 int status = parse_pipeline_pktq_in(app, param,
1432 PARSE_ERROR((status == 0), section_name,
1437 if (strcmp(ent->name, "pktq_out") == 0) {
1438 int status = parse_pipeline_pktq_out(app, param,
1441 PARSE_ERROR((status == 0), section_name,
1446 if (strcmp(ent->name, "msgq_in") == 0) {
1447 int status = parse_pipeline_msgq_in(app, param,
1450 PARSE_ERROR((status == 0), section_name,
1455 if (strcmp(ent->name, "msgq_out") == 0) {
1456 int status = parse_pipeline_msgq_out(app, param,
1459 PARSE_ERROR((status == 0), section_name,
1464 if (strcmp(ent->name, "timer_period") == 0) {
1465 int status = parser_read_uint32(
1466 ¶m->timer_period,
1469 PARSE_ERROR((status == 0), section_name,
1474 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1475 int status = parse_pipeline_pcap_source(app,
1476 param, ent->value, NULL);
1478 PARSE_ERROR((status == 0), section_name,
1483 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1484 int status = parse_pipeline_pcap_source(app,
1485 param, NULL, ent->value);
1487 PARSE_ERROR((status == 0), section_name,
1492 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1493 int status = parse_pipeline_pcap_sink(app, param,
1496 PARSE_ERROR((status == 0), section_name,
1501 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1502 int status = parse_pipeline_pcap_sink(app, param,
1505 PARSE_ERROR((status == 0), section_name,
1510 /* pipeline type specific items */
1511 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1512 "Parse error in section \"%s\": too many "
1513 "pipeline specified parameters", section_name);
1515 param->args_name[param->n_args] = strdup(ent->name);
1516 param->args_value[param->n_args] = strdup(ent->value);
1518 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1519 (param->args_value[param->n_args] != NULL),
1520 "Parse error: no free memory");
1527 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1528 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1529 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1530 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1531 param->msgq_in[param->n_msgq_in++] = param_idx;
1533 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1534 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1535 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1536 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1537 param->msgq_out[param->n_msgq_out++] = param_idx;
1539 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1542 (param->hyper_th_id) ? "h" : "");
1543 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1544 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1545 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1547 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1550 (param->hyper_th_id) ? "h" : "");
1551 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1552 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1553 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1559 parse_mempool(struct app_params *app,
1560 const char *section_name,
1561 struct rte_cfgfile *cfg)
1563 struct app_mempool_params *param;
1564 struct rte_cfgfile_entry *entries;
1568 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1569 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1571 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1572 PARSE_ERROR_MALLOC(entries != NULL);
1574 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1576 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1577 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1579 param = &app->mempool_params[param_idx];
1581 for (i = 0; i < n_entries; i++) {
1582 struct rte_cfgfile_entry *ent = &entries[i];
1584 if (strcmp(ent->name, "buffer_size") == 0) {
1585 int status = parser_read_uint32(
1586 ¶m->buffer_size, ent->value);
1588 PARSE_ERROR((status == 0), section_name,
1593 if (strcmp(ent->name, "pool_size") == 0) {
1594 int status = parser_read_uint32(
1595 ¶m->pool_size, ent->value);
1597 PARSE_ERROR((status == 0), section_name,
1602 if (strcmp(ent->name, "cache_size") == 0) {
1603 int status = parser_read_uint32(
1604 ¶m->cache_size, ent->value);
1606 PARSE_ERROR((status == 0), section_name,
1611 if (strcmp(ent->name, "cpu") == 0) {
1612 int status = parser_read_uint32(
1613 ¶m->cpu_socket_id, ent->value);
1615 PARSE_ERROR((status == 0), section_name,
1621 PARSE_ERROR_INVALID(0, section_name, ent->name);
1630 parse_link(struct app_params *app,
1631 const char *section_name,
1632 struct rte_cfgfile *cfg)
1634 struct app_link_params *param;
1635 struct rte_cfgfile_entry *entries;
1637 int pci_bdf_present = 0;
1640 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1641 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1643 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1644 PARSE_ERROR_MALLOC(entries != NULL);
1646 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1648 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1649 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1651 param = &app->link_params[param_idx];
1653 for (i = 0; i < n_entries; i++) {
1654 struct rte_cfgfile_entry *ent = &entries[i];
1656 if (strcmp(ent->name, "promisc") == 0) {
1657 int status = parser_read_arg_bool(ent->value);
1659 PARSE_ERROR((status != -EINVAL), section_name,
1661 param->promisc = status;
1665 if (strcmp(ent->name, "arp_q") == 0) {
1666 int status = parser_read_uint32(¶m->arp_q,
1669 PARSE_ERROR((status == 0), section_name,
1674 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1675 int status = parser_read_uint32(
1676 ¶m->tcp_syn_q, ent->value);
1678 PARSE_ERROR((status == 0), section_name, ent->name);
1682 if (strcmp(ent->name, "ip_local_q") == 0) {
1683 int status = parser_read_uint32(
1684 ¶m->ip_local_q, ent->value);
1686 PARSE_ERROR((status == 0), section_name,
1692 if (strcmp(ent->name, "tcp_local_q") == 0) {
1693 int status = parser_read_uint32(
1694 ¶m->tcp_local_q, ent->value);
1696 PARSE_ERROR((status == 0), section_name,
1701 if (strcmp(ent->name, "udp_local_q") == 0) {
1702 int status = parser_read_uint32(
1703 ¶m->udp_local_q, ent->value);
1705 PARSE_ERROR((status == 0), section_name,
1710 if (strcmp(ent->name, "sctp_local_q") == 0) {
1711 int status = parser_read_uint32(
1712 ¶m->sctp_local_q, ent->value);
1714 PARSE_ERROR((status == 0), section_name,
1719 if (strcmp(ent->name, "pci_bdf") == 0) {
1720 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1721 section_name, ent->name);
1723 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1725 pci_bdf_present = 1;
1730 PARSE_ERROR_INVALID(0, section_name, ent->name);
1733 /* Check for mandatory fields */
1735 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1736 section_name, "pci_bdf",
1737 "entry not allowed (port_mask is provided)");
1739 PARSE_ERROR_MESSAGE((pci_bdf_present),
1740 section_name, "pci_bdf",
1741 "this entry is mandatory (port_mask is not "
1750 parse_rxq(struct app_params *app,
1751 const char *section_name,
1752 struct rte_cfgfile *cfg)
1754 struct app_pktq_hwq_in_params *param;
1755 struct rte_cfgfile_entry *entries;
1759 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1760 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1762 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1763 PARSE_ERROR_MALLOC(entries != NULL);
1765 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1767 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1768 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1770 param = &app->hwq_in_params[param_idx];
1772 for (i = 0; i < n_entries; i++) {
1773 struct rte_cfgfile_entry *ent = &entries[i];
1775 if (strcmp(ent->name, "mempool") == 0) {
1776 int status = validate_name(ent->value,
1780 PARSE_ERROR((status == 0), section_name,
1782 idx = APP_PARAM_ADD(app->mempool_params,
1784 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1786 param->mempool_id = idx;
1790 if (strcmp(ent->name, "size") == 0) {
1791 int status = parser_read_uint32(¶m->size,
1794 PARSE_ERROR((status == 0), section_name,
1799 if (strcmp(ent->name, "burst") == 0) {
1800 int status = parser_read_uint32(¶m->burst,
1803 PARSE_ERROR((status == 0), section_name,
1809 PARSE_ERROR_INVALID(0, section_name, ent->name);
1818 parse_txq(struct app_params *app,
1819 const char *section_name,
1820 struct rte_cfgfile *cfg)
1822 struct app_pktq_hwq_out_params *param;
1823 struct rte_cfgfile_entry *entries;
1827 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1828 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1830 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1831 PARSE_ERROR_MALLOC(entries != NULL);
1833 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1835 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1836 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1838 param = &app->hwq_out_params[param_idx];
1840 for (i = 0; i < n_entries; i++) {
1841 struct rte_cfgfile_entry *ent = &entries[i];
1843 if (strcmp(ent->name, "size") == 0) {
1844 int status = parser_read_uint32(¶m->size,
1847 PARSE_ERROR((status == 0), section_name,
1852 if (strcmp(ent->name, "burst") == 0) {
1853 int status = parser_read_uint32(¶m->burst,
1856 PARSE_ERROR((status == 0), section_name,
1861 if (strcmp(ent->name, "dropless") == 0) {
1862 int status = parser_read_arg_bool(ent->value);
1865 PARSE_ERROR((status != -EINVAL), section_name,
1867 param->dropless = status;
1872 PARSE_ERROR_INVALID(0, section_name, ent->name);
1881 parse_swq(struct app_params *app,
1882 const char *section_name,
1883 struct rte_cfgfile *cfg)
1885 struct app_pktq_swq_params *param;
1886 struct rte_cfgfile_entry *entries;
1888 uint32_t mtu_present = 0;
1889 uint32_t metadata_size_present = 0;
1890 uint32_t mempool_direct_present = 0;
1891 uint32_t mempool_indirect_present = 0;
1895 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1896 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1898 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1899 PARSE_ERROR_MALLOC(entries != NULL);
1901 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1903 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1904 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1906 param = &app->swq_params[param_idx];
1908 for (i = 0; i < n_entries; i++) {
1909 struct rte_cfgfile_entry *ent = &entries[i];
1911 if (strcmp(ent->name, "size") == 0) {
1912 int status = parser_read_uint32(¶m->size,
1915 PARSE_ERROR((status == 0), section_name,
1920 if (strcmp(ent->name, "burst_read") == 0) {
1921 int status = parser_read_uint32(&
1922 param->burst_read, ent->value);
1924 PARSE_ERROR((status == 0), section_name,
1929 if (strcmp(ent->name, "burst_write") == 0) {
1930 int status = parser_read_uint32(
1931 ¶m->burst_write, ent->value);
1933 PARSE_ERROR((status == 0), section_name,
1938 if (strcmp(ent->name, "dropless") == 0) {
1939 int status = parser_read_arg_bool(ent->value);
1941 PARSE_ERROR((status != -EINVAL), section_name,
1943 param->dropless = status;
1947 if (strcmp(ent->name, "n_retries") == 0) {
1948 int status = parser_read_uint64(¶m->n_retries,
1951 PARSE_ERROR((status == 0), section_name,
1956 if (strcmp(ent->name, "cpu") == 0) {
1957 int status = parser_read_uint32(
1958 ¶m->cpu_socket_id, ent->value);
1960 PARSE_ERROR((status == 0), section_name, ent->name);
1964 if (strcmp(ent->name, "ipv4_frag") == 0) {
1965 int status = parser_read_arg_bool(ent->value);
1967 PARSE_ERROR((status != -EINVAL), section_name,
1970 param->ipv4_frag = status;
1971 if (param->mtu == 0)
1977 if (strcmp(ent->name, "ipv6_frag") == 0) {
1978 int status = parser_read_arg_bool(ent->value);
1980 PARSE_ERROR((status != -EINVAL), section_name,
1982 param->ipv6_frag = status;
1983 if (param->mtu == 0)
1988 if (strcmp(ent->name, "ipv4_ras") == 0) {
1989 int status = parser_read_arg_bool(ent->value);
1991 PARSE_ERROR((status != -EINVAL), section_name,
1993 param->ipv4_ras = status;
1997 if (strcmp(ent->name, "ipv6_ras") == 0) {
1998 int status = parser_read_arg_bool(ent->value);
2000 PARSE_ERROR((status != -EINVAL), section_name,
2002 param->ipv6_ras = status;
2006 if (strcmp(ent->name, "mtu") == 0) {
2007 int status = parser_read_uint32(¶m->mtu,
2010 PARSE_ERROR((status == 0), section_name,
2016 if (strcmp(ent->name, "metadata_size") == 0) {
2017 int status = parser_read_uint32(
2018 ¶m->metadata_size, ent->value);
2020 PARSE_ERROR((status == 0), section_name,
2022 metadata_size_present = 1;
2026 if (strcmp(ent->name, "mempool_direct") == 0) {
2027 int status = validate_name(ent->value,
2031 PARSE_ERROR((status == 0), section_name,
2034 idx = APP_PARAM_ADD(app->mempool_params,
2036 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2038 param->mempool_direct_id = idx;
2039 mempool_direct_present = 1;
2043 if (strcmp(ent->name, "mempool_indirect") == 0) {
2044 int status = validate_name(ent->value,
2048 PARSE_ERROR((status == 0), section_name,
2050 idx = APP_PARAM_ADD(app->mempool_params,
2052 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2054 param->mempool_indirect_id = idx;
2055 mempool_indirect_present = 1;
2060 PARSE_ERROR_INVALID(0, section_name, ent->name);
2063 APP_CHECK(((mtu_present) &&
2064 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2065 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2066 "is off, therefore entry \"mtu\" is not allowed",
2069 APP_CHECK(((metadata_size_present) &&
2070 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2071 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2072 "is off, therefore entry \"metadata_size\" is "
2073 "not allowed", section_name);
2075 APP_CHECK(((mempool_direct_present) &&
2076 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2077 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2078 "is off, therefore entry \"mempool_direct\" is "
2079 "not allowed", section_name);
2081 APP_CHECK(((mempool_indirect_present) &&
2082 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2083 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2084 "is off, therefore entry \"mempool_indirect\" is "
2085 "not allowed", section_name);
2093 parse_tm(struct app_params *app,
2094 const char *section_name,
2095 struct rte_cfgfile *cfg)
2097 struct app_pktq_tm_params *param;
2098 struct rte_cfgfile_entry *entries;
2102 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2103 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2105 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2106 PARSE_ERROR_MALLOC(entries != NULL);
2108 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2110 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2111 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2113 param = &app->tm_params[param_idx];
2115 for (i = 0; i < n_entries; i++) {
2116 struct rte_cfgfile_entry *ent = &entries[i];
2118 if (strcmp(ent->name, "cfg") == 0) {
2119 param->file_name = strdup(ent->value);
2120 PARSE_ERROR_MALLOC(param->file_name != NULL);
2124 if (strcmp(ent->name, "burst_read") == 0) {
2125 int status = parser_read_uint32(
2126 ¶m->burst_read, ent->value);
2128 PARSE_ERROR((status == 0), section_name,
2133 if (strcmp(ent->name, "burst_write") == 0) {
2134 int status = parser_read_uint32(
2135 ¶m->burst_write, ent->value);
2137 PARSE_ERROR((status == 0), section_name,
2143 PARSE_ERROR_INVALID(0, section_name, ent->name);
2152 parse_source(struct app_params *app,
2153 const char *section_name,
2154 struct rte_cfgfile *cfg)
2156 struct app_pktq_source_params *param;
2157 struct rte_cfgfile_entry *entries;
2161 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2162 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2164 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2165 PARSE_ERROR_MALLOC(entries != NULL);
2167 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2169 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2170 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2172 param = &app->source_params[param_idx];
2174 for (i = 0; i < n_entries; i++) {
2175 struct rte_cfgfile_entry *ent = &entries[i];
2177 if (strcmp(ent->name, "mempool") == 0) {
2178 int status = validate_name(ent->value,
2182 PARSE_ERROR((status == 0), section_name,
2184 idx = APP_PARAM_ADD(app->mempool_params,
2186 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2188 param->mempool_id = idx;
2192 if (strcmp(ent->name, "burst") == 0) {
2193 int status = parser_read_uint32(¶m->burst,
2196 PARSE_ERROR((status == 0), section_name,
2201 if (strcmp(ent->name, "pcap_file_rd")) {
2202 param->file_name = strdup(ent->value);
2204 PARSE_ERROR_MALLOC(param->file_name != NULL);
2208 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2209 int status = parser_read_uint32(
2210 ¶m->n_bytes_per_pkt, ent->value);
2212 PARSE_ERROR((status == 0), section_name,
2217 PARSE_ERROR_INVALID(0, section_name, ent->name);
2226 parse_sink(struct app_params *app,
2227 const char *section_name,
2228 struct rte_cfgfile *cfg)
2230 struct app_pktq_sink_params *param;
2231 struct rte_cfgfile_entry *entries;
2235 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2236 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2238 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2239 PARSE_ERROR_MALLOC(entries != NULL);
2241 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2243 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2244 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2246 param = &app->sink_params[param_idx];
2248 for (i = 0; i < n_entries; i++) {
2249 struct rte_cfgfile_entry *ent = &entries[i];
2251 if (strcmp(ent->name, "pcap_file_wr")) {
2252 param->file_name = strdup(ent->value);
2254 PARSE_ERROR_MALLOC((param->file_name != NULL));
2258 if (strcmp(ent->name, "pcap_n_pkt_wr")) {
2259 int status = parser_read_uint32(
2260 ¶m->n_pkts_to_dump, ent->value);
2262 PARSE_ERROR((status == 0), section_name,
2268 PARSE_ERROR_INVALID(0, section_name, ent->name);
2277 parse_msgq_req_pipeline(struct app_params *app,
2278 const char *section_name,
2279 struct rte_cfgfile *cfg)
2281 struct app_msgq_params *param;
2282 struct rte_cfgfile_entry *entries;
2286 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2287 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2289 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2290 PARSE_ERROR_MALLOC(entries != NULL);
2292 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2294 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2295 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2297 param = &app->msgq_params[param_idx];
2299 for (i = 0; i < n_entries; i++) {
2300 struct rte_cfgfile_entry *ent = &entries[i];
2302 if (strcmp(ent->name, "size") == 0) {
2303 int status = parser_read_uint32(¶m->size,
2306 PARSE_ERROR((status == 0), section_name,
2312 PARSE_ERROR_INVALID(0, section_name, ent->name);
2320 parse_msgq_rsp_pipeline(struct app_params *app,
2321 const char *section_name,
2322 struct rte_cfgfile *cfg)
2324 struct app_msgq_params *param;
2325 struct rte_cfgfile_entry *entries;
2329 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2330 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2332 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2333 PARSE_ERROR_MALLOC(entries != NULL);
2335 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2337 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2338 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2340 param = &app->msgq_params[param_idx];
2342 for (i = 0; i < n_entries; i++) {
2343 struct rte_cfgfile_entry *ent = &entries[i];
2345 if (strcmp(ent->name, "size") == 0) {
2346 int status = parser_read_uint32(¶m->size,
2349 PARSE_ERROR((status == 0), section_name,
2355 PARSE_ERROR_INVALID(0, section_name, ent->name);
2364 parse_msgq(struct app_params *app,
2365 const char *section_name,
2366 struct rte_cfgfile *cfg)
2368 struct app_msgq_params *param;
2369 struct rte_cfgfile_entry *entries;
2373 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2374 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2376 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2377 PARSE_ERROR_MALLOC(entries != NULL);
2379 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2381 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2382 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2384 param = &app->msgq_params[param_idx];
2386 for (i = 0; i < n_entries; i++) {
2387 struct rte_cfgfile_entry *ent = &entries[i];
2389 if (strcmp(ent->name, "size") == 0) {
2390 int status = parser_read_uint32(¶m->size,
2393 PARSE_ERROR((status == 0), section_name,
2398 if (strcmp(ent->name, "cpu") == 0) {
2399 int status = parser_read_uint32(
2400 ¶m->cpu_socket_id, ent->value);
2402 PARSE_ERROR((status == 0), section_name,
2408 PARSE_ERROR_INVALID(0, section_name, ent->name);
2416 typedef void (*config_section_load)(struct app_params *p,
2417 const char *section_name,
2418 struct rte_cfgfile *cfg);
2420 struct config_section {
2421 const char prefix[CFG_NAME_LEN];
2423 config_section_load load;
2426 static const struct config_section cfg_file_scheme[] = {
2427 {"EAL", 0, parse_eal},
2428 {"PIPELINE", 1, parse_pipeline},
2429 {"MEMPOOL", 1, parse_mempool},
2430 {"LINK", 1, parse_link},
2431 {"RXQ", 2, parse_rxq},
2432 {"TXQ", 2, parse_txq},
2433 {"SWQ", 1, parse_swq},
2434 {"TM", 1, parse_tm},
2435 {"SOURCE", 1, parse_source},
2436 {"SINK", 1, parse_sink},
2437 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2438 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2439 {"MSGQ", 1, parse_msgq},
2443 create_implicit_mempools(struct app_params *app)
2447 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2448 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2452 create_implicit_links_from_port_mask(struct app_params *app,
2455 uint32_t pmd_id, link_id;
2458 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2459 char name[APP_PARAM_NAME_SIZE];
2462 if ((port_mask & (1LLU << pmd_id)) == 0)
2465 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2466 idx = APP_PARAM_ADD(app->link_params, name);
2467 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2469 app->link_params[idx].pmd_id = pmd_id;
2475 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2479 for (i = 0; i < app->n_links; i++) {
2480 struct app_link_params *link = &app->link_params[i];
2487 app_config_parse(struct app_params *app, const char *file_name)
2489 struct rte_cfgfile *cfg;
2490 char **section_names;
2491 int i, j, sect_count;
2493 /* Implicit mempools */
2494 create_implicit_mempools(app);
2498 create_implicit_links_from_port_mask(app, app->port_mask);
2500 /* Load application configuration file */
2501 cfg = rte_cfgfile_load(file_name, 0);
2502 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2503 "file %s", file_name);
2505 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2506 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2507 "in file \"%s\" return %d", file_name,
2510 section_names = malloc(sect_count * sizeof(char *));
2511 PARSE_ERROR_MALLOC(section_names != NULL);
2513 for (i = 0; i < sect_count; i++)
2514 section_names[i] = malloc(CFG_NAME_LEN);
2516 rte_cfgfile_sections(cfg, section_names, sect_count);
2518 for (i = 0; i < sect_count; i++) {
2519 const struct config_section *sch_s;
2520 int len, cfg_name_len;
2522 cfg_name_len = strlen(section_names[i]);
2524 /* Find section type */
2525 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2526 sch_s = &cfg_file_scheme[j];
2527 len = strlen(sch_s->prefix);
2529 if (cfg_name_len < len)
2532 /* After section name we expect only '\0' or digit or
2533 * digit dot digit, so protect against false matching,
2534 * for example: "ABC" should match section name
2535 * "ABC0.0", but it should not match section_name
2538 if ((section_names[i][len] != '\0') &&
2539 !isdigit(section_names[i][len]))
2542 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2546 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2547 "Parse error: unknown section %s",
2550 APP_CHECK(validate_name(section_names[i],
2552 sch_s->numbers) == 0,
2553 "Parse error: invalid section name \"%s\"",
2556 sch_s->load(app, section_names[i], cfg);
2559 for (i = 0; i < sect_count; i++)
2560 free(section_names[i]);
2562 free(section_names);
2564 rte_cfgfile_close(cfg);
2566 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2567 APP_PARAM_COUNT(app->link_params, app->n_links);
2568 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2569 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2570 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2571 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2572 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2573 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2574 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2575 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2577 if (app->port_mask == 0)
2578 assign_link_pmd_id_from_pci_bdf(app);
2580 /* Save configuration to output file */
2581 app_config_save(app, app->output_file);
2583 /* Load TM configuration files */
2584 app_config_parse_tm(app);
2590 save_eal_params(struct app_params *app, FILE *f)
2592 struct app_eal_params *p = &app->eal_params;
2595 fprintf(f, "[EAL]\n");
2598 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2600 if (p->master_lcore_present)
2601 fprintf(f, "%s = %" PRIu32 "\n",
2602 "master_lcore", p->master_lcore);
2604 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2606 if (p->memory_present)
2607 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2609 if (p->ranks_present)
2610 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2612 for (i = 0; i < APP_MAX_LINKS; i++) {
2613 if (p->pci_blacklist[i] == NULL)
2616 fprintf(f, "%s = %s\n", "pci_blacklist",
2617 p->pci_blacklist[i]);
2620 for (i = 0; i < APP_MAX_LINKS; i++) {
2621 if (p->pci_whitelist[i] == NULL)
2624 fprintf(f, "%s = %s\n", "pci_whitelist",
2625 p->pci_whitelist[i]);
2628 for (i = 0; i < APP_MAX_LINKS; i++) {
2629 if (p->vdev[i] == NULL)
2632 fprintf(f, "%s = %s\n", "vdev",
2636 if (p->vmware_tsc_map_present)
2637 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2638 (p->vmware_tsc_map) ? "yes" : "no");
2641 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2644 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2646 if (p->log_level_present)
2647 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2649 if (p->version_present)
2650 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2652 if (p->help_present)
2653 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2655 if (p->no_huge_present)
2656 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2658 if (p->no_pci_present)
2659 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2661 if (p->no_hpet_present)
2662 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2664 if (p->no_shconf_present)
2665 fprintf(f, "%s = %s\n", "no_shconf",
2666 (p->no_shconf) ? "yes" : "no");
2669 fprintf(f, "%s = %s\n", "d", p->add_driver);
2672 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2675 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2678 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2680 if (p->base_virtaddr)
2681 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2683 if (p->create_uio_dev_present)
2684 fprintf(f, "%s = %s\n", "create_uio_dev",
2685 (p->create_uio_dev) ? "yes" : "no");
2688 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2690 if (p->xen_dom0_present)
2691 fprintf(f, "%s = %s\n", "xen_dom0",
2692 (p->xen_dom0) ? "yes" : "no");
2698 save_mempool_params(struct app_params *app, FILE *f)
2700 struct app_mempool_params *p;
2703 count = RTE_DIM(app->mempool_params);
2704 for (i = 0; i < count; i++) {
2705 p = &app->mempool_params[i];
2706 if (!APP_PARAM_VALID(p))
2709 fprintf(f, "[%s]\n", p->name);
2710 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2711 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2712 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2713 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2720 save_links_params(struct app_params *app, FILE *f)
2722 struct app_link_params *p;
2725 count = RTE_DIM(app->link_params);
2726 for (i = 0; i < count; i++) {
2727 p = &app->link_params[i];
2728 if (!APP_PARAM_VALID(p))
2731 fprintf(f, "[%s]\n", p->name);
2732 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2733 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2734 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2735 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2737 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2738 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2739 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2740 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2743 if (strlen(p->pci_bdf))
2744 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2751 save_rxq_params(struct app_params *app, FILE *f)
2753 struct app_pktq_hwq_in_params *p;
2756 count = RTE_DIM(app->hwq_in_params);
2757 for (i = 0; i < count; i++) {
2758 p = &app->hwq_in_params[i];
2759 if (!APP_PARAM_VALID(p))
2762 fprintf(f, "[%s]\n", p->name);
2763 fprintf(f, "%s = %s\n",
2765 app->mempool_params[p->mempool_id].name);
2766 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2767 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2774 save_txq_params(struct app_params *app, FILE *f)
2776 struct app_pktq_hwq_out_params *p;
2779 count = RTE_DIM(app->hwq_out_params);
2780 for (i = 0; i < count; i++) {
2781 p = &app->hwq_out_params[i];
2782 if (!APP_PARAM_VALID(p))
2785 fprintf(f, "[%s]\n", p->name);
2786 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2787 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2788 fprintf(f, "%s = %s\n",
2790 p->dropless ? "yes" : "no");
2797 save_swq_params(struct app_params *app, FILE *f)
2799 struct app_pktq_swq_params *p;
2802 count = RTE_DIM(app->swq_params);
2803 for (i = 0; i < count; i++) {
2804 p = &app->swq_params[i];
2805 if (!APP_PARAM_VALID(p))
2808 fprintf(f, "[%s]\n", p->name);
2809 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2810 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2811 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2812 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2813 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2814 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2815 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2816 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2817 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2818 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2819 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2820 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2821 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2822 fprintf(f, "%s = %s\n",
2824 app->mempool_params[p->mempool_direct_id].name);
2825 fprintf(f, "%s = %s\n",
2827 app->mempool_params[p->mempool_indirect_id].name);
2835 save_tm_params(struct app_params *app, FILE *f)
2837 struct app_pktq_tm_params *p;
2840 count = RTE_DIM(app->tm_params);
2841 for (i = 0; i < count; i++) {
2842 p = &app->tm_params[i];
2843 if (!APP_PARAM_VALID(p))
2846 fprintf(f, "[%s]\n", p->name);
2847 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2848 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2849 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2856 save_source_params(struct app_params *app, FILE *f)
2858 struct app_pktq_source_params *p;
2861 count = RTE_DIM(app->source_params);
2862 for (i = 0; i < count; i++) {
2863 p = &app->source_params[i];
2864 if (!APP_PARAM_VALID(p))
2867 fprintf(f, "[%s]\n", p->name);
2868 fprintf(f, "%s = %s\n",
2870 app->mempool_params[p->mempool_id].name);
2871 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2872 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2873 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2874 p->n_bytes_per_pkt);
2880 save_sink_params(struct app_params *app, FILE *f)
2882 struct app_pktq_sink_params *p;
2885 count = RTE_DIM(app->sink_params);
2886 for (i = 0; i < count; i++) {
2887 p = &app->sink_params[i];
2888 if (!APP_PARAM_VALID(p))
2891 fprintf(f, "[%s]\n", p->name);
2892 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2893 fprintf(f, "%s = %" PRIu32 "\n",
2894 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2900 save_msgq_params(struct app_params *app, FILE *f)
2902 struct app_msgq_params *p;
2905 count = RTE_DIM(app->msgq_params);
2906 for (i = 0; i < count; i++) {
2907 p = &app->msgq_params[i];
2908 if (!APP_PARAM_VALID(p))
2911 fprintf(f, "[%s]\n", p->name);
2912 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2913 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2920 save_pipeline_params(struct app_params *app, FILE *f)
2924 count = RTE_DIM(app->pipeline_params);
2925 for (i = 0; i < count; i++) {
2926 struct app_pipeline_params *p = &app->pipeline_params[i];
2928 if (!APP_PARAM_VALID(p))
2932 fprintf(f, "[%s]\n", p->name);
2935 fprintf(f, "type = %s\n", p->type);
2938 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2941 (p->hyper_th_id) ? "h" : "");
2947 fprintf(f, "pktq_in =");
2948 for (j = 0; j < p->n_pktq_in; j++) {
2949 struct app_pktq_in_params *pp = &p->pktq_in[j];
2953 case APP_PKTQ_IN_HWQ:
2954 name = app->hwq_in_params[pp->id].name;
2956 case APP_PKTQ_IN_SWQ:
2957 name = app->swq_params[pp->id].name;
2959 case APP_PKTQ_IN_TM:
2960 name = app->tm_params[pp->id].name;
2962 case APP_PKTQ_IN_SOURCE:
2963 name = app->source_params[pp->id].name;
2966 APP_CHECK(0, "System error "
2967 "occurred while saving "
2968 "parameter to file");
2971 fprintf(f, " %s", name);
2977 if (p->n_pktq_out) {
2980 fprintf(f, "pktq_out =");
2981 for (j = 0; j < p->n_pktq_out; j++) {
2982 struct app_pktq_out_params *pp =
2987 case APP_PKTQ_OUT_HWQ:
2988 name = app->hwq_out_params[pp->id].name;
2990 case APP_PKTQ_OUT_SWQ:
2991 name = app->swq_params[pp->id].name;
2993 case APP_PKTQ_OUT_TM:
2994 name = app->tm_params[pp->id].name;
2996 case APP_PKTQ_OUT_SINK:
2997 name = app->sink_params[pp->id].name;
3000 APP_CHECK(0, "System error "
3001 "occurred while saving "
3002 "parameter to file");
3005 fprintf(f, " %s", name);
3014 fprintf(f, "msgq_in =");
3015 for (j = 0; j < p->n_msgq_in; j++) {
3016 uint32_t id = p->msgq_in[j];
3017 char *name = app->msgq_params[id].name;
3019 fprintf(f, " %s", name);
3025 if (p->n_msgq_out) {
3028 fprintf(f, "msgq_out =");
3029 for (j = 0; j < p->n_msgq_out; j++) {
3030 uint32_t id = p->msgq_out[j];
3031 char *name = app->msgq_params[id].name;
3033 fprintf(f, " %s", name);
3039 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3045 for (j = 0; j < p->n_args; j++)
3046 fprintf(f, "%s = %s\n", p->args_name[j],
3055 app_config_save(struct app_params *app, const char *file_name)
3058 char *name, *dir_name;
3061 name = strdup(file_name);
3062 dir_name = dirname(name);
3063 status = access(dir_name, W_OK);
3064 APP_CHECK((status == 0),
3065 "Error: need write access privilege to directory "
3066 "\"%s\" to save configuration\n", dir_name);
3068 file = fopen(file_name, "w");
3069 APP_CHECK((file != NULL),
3070 "Error: failed to save configuration to file \"%s\"",
3073 save_eal_params(app, file);
3074 save_pipeline_params(app, file);
3075 save_mempool_params(app, file);
3076 save_links_params(app, file);
3077 save_rxq_params(app, file);
3078 save_txq_params(app, file);
3079 save_swq_params(app, file);
3080 save_tm_params(app, file);
3081 save_source_params(app, file);
3082 save_sink_params(app, file);
3083 save_msgq_params(app, file);
3090 app_config_init(struct app_params *app)
3094 memcpy(app, &app_params_default, sizeof(struct app_params));
3096 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3097 memcpy(&app->mempool_params[i],
3098 &mempool_params_default,
3099 sizeof(struct app_mempool_params));
3101 for (i = 0; i < RTE_DIM(app->link_params); i++)
3102 memcpy(&app->link_params[i],
3103 &link_params_default,
3104 sizeof(struct app_link_params));
3106 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3107 memcpy(&app->hwq_in_params[i],
3108 &default_hwq_in_params,
3109 sizeof(default_hwq_in_params));
3111 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3112 memcpy(&app->hwq_out_params[i],
3113 &default_hwq_out_params,
3114 sizeof(default_hwq_out_params));
3116 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3117 memcpy(&app->swq_params[i],
3118 &default_swq_params,
3119 sizeof(default_swq_params));
3121 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3122 memcpy(&app->tm_params[i],
3124 sizeof(default_tm_params));
3126 for (i = 0; i < RTE_DIM(app->source_params); i++)
3127 memcpy(&app->source_params[i],
3128 &default_source_params,
3129 sizeof(default_source_params));
3131 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3132 memcpy(&app->sink_params[i],
3133 &default_sink_params,
3134 sizeof(default_sink_params));
3136 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3137 memcpy(&app->msgq_params[i],
3138 &default_msgq_params,
3139 sizeof(default_msgq_params));
3141 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3142 memcpy(&app->pipeline_params[i],
3143 &default_pipeline_params,
3144 sizeof(default_pipeline_params));
3150 filenamedup(const char *filename, const char *suffix)
3152 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3157 sprintf(s, "%s%s", filename, suffix);
3162 app_config_args(struct app_params *app, int argc, char **argv)
3164 const char *optname;
3165 int opt, option_index;
3166 int f_present, s_present, p_present, l_present;
3167 int preproc_present, preproc_params_present;
3170 static struct option lgopts[] = {
3171 { "preproc", 1, 0, 0 },
3172 { "preproc-args", 1, 0, 0 },
3176 /* Copy application name */
3177 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3183 preproc_present = 0;
3184 preproc_params_present = 0;
3186 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3187 &option_index)) != EOF)
3191 rte_panic("Error: Config file is provided "
3192 "more than once\n");
3195 if (!strlen(optarg))
3196 rte_panic("Error: Config file name is null\n");
3198 app->config_file = strdup(optarg);
3199 if (app->config_file == NULL)
3200 rte_panic("Error: Memory allocation failure\n");
3206 rte_panic("Error: Script file is provided "
3207 "more than once\n");
3210 if (!strlen(optarg))
3211 rte_panic("Error: Script file name is null\n");
3213 app->script_file = strdup(optarg);
3214 if (app->script_file == NULL)
3215 rte_panic("Error: Memory allocation failure\n");
3221 rte_panic("Error: PORT_MASK is provided "
3222 "more than once\n");
3225 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3227 ((size_t) scaned != strlen(optarg)))
3228 rte_panic("Error: PORT_MASK is not "
3229 "a hexadecimal integer\n");
3231 if (app->port_mask == 0)
3232 rte_panic("Error: PORT_MASK is null\n");
3238 rte_panic("Error: LOG_LEVEL is provided "
3239 "more than once\n");
3242 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3244 ((size_t) scaned != strlen(optarg)) ||
3245 (app->log_level >= APP_LOG_LEVELS))
3246 rte_panic("Error: LOG_LEVEL invalid value\n");
3251 optname = lgopts[option_index].name;
3253 if (strcmp(optname, "preproc") == 0) {
3254 if (preproc_present)
3255 rte_panic("Error: Preprocessor argument "
3256 "is provided more than once\n");
3257 preproc_present = 1;
3259 app->preproc = strdup(optarg);
3263 if (strcmp(optname, "preproc-args") == 0) {
3264 if (preproc_params_present)
3265 rte_panic("Error: Preprocessor args "
3266 "are provided more than once\n");
3267 preproc_params_present = 1;
3269 app->preproc_args = strdup(optarg);
3273 app_print_usage(argv[0]);
3277 app_print_usage(argv[0]);
3280 optind = 0; /* reset getopt lib */
3282 /* Check dependencies between args */
3283 if (preproc_params_present && (preproc_present == 0))
3284 rte_panic("Error: Preprocessor args specified while "
3285 "preprocessor is not defined\n");
3287 app->parser_file = preproc_present ?
3288 filenamedup(app->config_file, ".preproc") :
3289 strdup(app->config_file);
3290 app->output_file = filenamedup(app->config_file, ".out");
3296 app_config_preproc(struct app_params *app)
3301 if (app->preproc == NULL)
3304 status = access(app->config_file, F_OK | R_OK);
3305 APP_CHECK((status == 0), "Error: Unable to open file %s",
3308 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3310 app->preproc_args ? app->preproc_args : "",
3314 status = system(buffer);
3315 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3316 "Error occurred while pre-processing file \"%s\"\n",