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]);
685 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
686 section_name, entry->name,
687 "too many elements");
692 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
693 (strcmp(entry->name, "w") == 0)) {
696 PARSE_ERROR_MESSAGE((app->port_mask != 0),
697 section_name, entry->name, "entry to be "
698 "generated by the application (port_mask "
701 for (i = 0; i < APP_MAX_LINKS; i++) {
702 if (p->pci_whitelist[i])
705 p->pci_whitelist[i] = strdup(entry->value);
706 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
711 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
712 section_name, entry->name,
713 "too many elements");
718 if (strcmp(entry->name, "vdev") == 0) {
721 for (i = 0; i < APP_MAX_LINKS; i++) {
725 p->vdev[i] = strdup(entry->value);
726 PARSE_ERROR_MALLOC(p->vdev[i]);
731 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
732 section_name, entry->name,
733 "too many elements");
738 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
741 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
744 p->vmware_tsc_map_present = 1;
746 val = parser_read_arg_bool(entry->value);
747 PARSE_ERROR((val >= 0), section_name, entry->name);
748 p->vmware_tsc_map = val;
753 if (strcmp(entry->name, "proc_type") == 0) {
754 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
757 p->proc_type = strdup(entry->value);
762 if (strcmp(entry->name, "syslog") == 0) {
763 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
766 p->syslog = strdup(entry->value);
771 if (strcmp(entry->name, "log_level") == 0) {
774 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
777 p->log_level_present = 1;
779 status = parser_read_uint32(&p->log_level,
781 PARSE_ERROR((status == 0), section_name, entry->name);
786 if (strcmp(entry->name, "v") == 0) {
789 PARSE_ERROR_DUPLICATE((p->version_present == 0),
792 p->version_present = 1;
794 val = parser_read_arg_bool(entry->value);
795 PARSE_ERROR((val >= 0), section_name, entry->name);
801 if ((strcmp(entry->name, "help") == 0) ||
802 (strcmp(entry->name, "h") == 0)) {
805 PARSE_ERROR_DUPLICATE((p->help_present == 0),
810 val = parser_read_arg_bool(entry->value);
811 PARSE_ERROR((val >= 0), section_name, entry->name);
817 if (strcmp(entry->name, "no_huge") == 0) {
820 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
823 p->no_huge_present = 1;
825 val = parser_read_arg_bool(entry->value);
826 PARSE_ERROR((val >= 0), section_name, entry->name);
832 if (strcmp(entry->name, "no_pci") == 0) {
835 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
838 p->no_pci_present = 1;
840 val = parser_read_arg_bool(entry->value);
841 PARSE_ERROR((val >= 0), section_name, entry->name);
847 if (strcmp(entry->name, "no_hpet") == 0) {
850 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
853 p->no_hpet_present = 1;
855 val = parser_read_arg_bool(entry->value);
856 PARSE_ERROR((val >= 0), section_name, entry->name);
862 if (strcmp(entry->name, "no_shconf") == 0) {
865 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
868 p->no_shconf_present = 1;
870 val = parser_read_arg_bool(entry->value);
871 PARSE_ERROR((val >= 0), section_name, entry->name);
877 if (strcmp(entry->name, "d") == 0) {
878 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
881 p->add_driver = strdup(entry->value);
886 if (strcmp(entry->name, "socket_mem") == 0) {
887 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
890 p->socket_mem = strdup(entry->value);
895 if (strcmp(entry->name, "huge_dir") == 0) {
896 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
899 p->huge_dir = strdup(entry->value);
904 if (strcmp(entry->name, "file_prefix") == 0) {
905 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
908 p->file_prefix = strdup(entry->value);
913 if (strcmp(entry->name, "base_virtaddr") == 0) {
914 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
917 p->base_virtaddr = strdup(entry->value);
922 if (strcmp(entry->name, "create_uio_dev") == 0) {
925 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
928 p->create_uio_dev_present = 1;
930 val = parser_read_arg_bool(entry->value);
931 PARSE_ERROR((val >= 0), section_name, entry->name);
932 p->create_uio_dev = val;
937 if (strcmp(entry->name, "vfio_intr") == 0) {
938 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
941 p->vfio_intr = strdup(entry->value);
946 if (strcmp(entry->name, "xen_dom0") == 0) {
949 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
952 p->xen_dom0_present = 1;
954 val = parser_read_arg_bool(entry->value);
955 PARSE_ERROR((val >= 0), section_name, entry->name);
961 PARSE_ERROR_INVALID(0, section_name, entry->name);
968 parse_pipeline_pcap_source(struct app_params *app,
969 struct app_pipeline_params *p,
970 const char *file_name, const char *cp_size)
972 const char *next = NULL;
977 if (file_name && !cp_size) {
979 parse_file = 1; /* parse file path */
980 } else if (cp_size && !file_name) {
982 parse_file = 0; /* parse copy size */
986 char name[APP_PARAM_NAME_SIZE];
989 if (p->n_pktq_in == 0)
992 for (i = 0; i < p->n_pktq_in; i++) {
993 if (p->pktq_in[i].type != APP_PKTQ_IN_SOURCE)
998 while (*next != '\0') {
1001 if (i >= p->n_pktq_in)
1004 id = p->pktq_in[i].id;
1006 end = strchr(next, ' ');
1008 name_len = strlen(next);
1010 name_len = end - next;
1012 if (name_len == 0 || name_len == sizeof(name))
1015 strncpy(name, next, name_len);
1016 name[name_len] = '\0';
1022 app->source_params[id].file_name = strdup(name);
1023 if (app->source_params[id].file_name == NULL)
1026 if (parser_read_uint32(
1027 &app->source_params[id].n_bytes_per_pkt,
1029 if (app->source_params[id].
1031 free(app->source_params[id].
1039 if (i == p->n_pktq_in)
1047 parse_pipeline_pcap_sink(struct app_params *app,
1048 struct app_pipeline_params *p,
1049 const char *file_name, const char *n_pkts_to_dump)
1051 const char *next = NULL;
1056 if (file_name && !n_pkts_to_dump) {
1058 parse_file = 1; /* parse file path */
1059 } else if (n_pkts_to_dump && !file_name) {
1060 next = n_pkts_to_dump;
1061 parse_file = 0; /* parse copy size */
1065 char name[APP_PARAM_NAME_SIZE];
1068 if (p->n_pktq_out == 0)
1071 for (i = 0; i < p->n_pktq_out; i++) {
1072 if (p->pktq_out[i].type != APP_PKTQ_OUT_SINK)
1077 while (*next != '\0') {
1080 if (i >= p->n_pktq_out)
1083 id = p->pktq_out[i].id;
1085 end = strchr(next, ' ');
1087 name_len = strlen(next);
1089 name_len = end - next;
1091 if (name_len == 0 || name_len == sizeof(name))
1094 strncpy(name, next, name_len);
1095 name[name_len] = '\0';
1101 app->sink_params[id].file_name = strdup(name);
1102 if (app->sink_params[id].file_name == NULL)
1105 if (parser_read_uint32(
1106 &app->sink_params[id].n_pkts_to_dump,
1108 if (app->sink_params[id].file_name !=
1110 free(app->sink_params[id].
1118 if (i == p->n_pktq_out)
1126 parse_pipeline_pktq_in(struct app_params *app,
1127 struct app_pipeline_params *p,
1130 const char *next = value;
1132 char name[APP_PARAM_NAME_SIZE];
1135 while (*next != '\0') {
1136 enum app_pktq_in_type type;
1141 next = skip_white_spaces(next);
1145 end_space = strchr(next, ' ');
1146 end_tab = strchr(next, ' ');
1148 if (end_space && (!end_tab))
1150 else if ((!end_space) && end_tab)
1152 else if (end_space && end_tab)
1153 end = RTE_MIN(end_space, end_tab);
1158 name_len = strlen(next);
1160 name_len = end - next;
1162 if (name_len == 0 || name_len == sizeof(name))
1165 strncpy(name, next, name_len);
1166 name[name_len] = '\0';
1171 if (validate_name(name, "RXQ", 2) == 0) {
1172 type = APP_PKTQ_IN_HWQ;
1173 id = APP_PARAM_ADD(app->hwq_in_params, name);
1174 } else if (validate_name(name, "SWQ", 1) == 0) {
1175 type = APP_PKTQ_IN_SWQ;
1176 id = APP_PARAM_ADD(app->swq_params, name);
1177 } else if (validate_name(name, "TM", 1) == 0) {
1178 type = APP_PKTQ_IN_TM;
1179 id = APP_PARAM_ADD(app->tm_params, name);
1180 } else if (validate_name(name, "SOURCE", 1) == 0) {
1181 type = APP_PKTQ_IN_SOURCE;
1182 id = APP_PARAM_ADD(app->source_params, name);
1189 p->pktq_in[p->n_pktq_in].type = type;
1190 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1198 parse_pipeline_pktq_out(struct app_params *app,
1199 struct app_pipeline_params *p,
1202 const char *next = value;
1204 char name[APP_PARAM_NAME_SIZE];
1207 while (*next != '\0') {
1208 enum app_pktq_out_type type;
1213 next = skip_white_spaces(next);
1217 end_space = strchr(next, ' ');
1218 end_tab = strchr(next, ' ');
1220 if (end_space && (!end_tab))
1222 else if ((!end_space) && end_tab)
1224 else if (end_space && end_tab)
1225 end = RTE_MIN(end_space, end_tab);
1230 name_len = strlen(next);
1232 name_len = end - next;
1234 if (name_len == 0 || name_len == sizeof(name))
1237 strncpy(name, next, name_len);
1238 name[name_len] = '\0';
1242 if (validate_name(name, "TXQ", 2) == 0) {
1243 type = APP_PKTQ_OUT_HWQ;
1244 id = APP_PARAM_ADD(app->hwq_out_params, name);
1245 } else if (validate_name(name, "SWQ", 1) == 0) {
1246 type = APP_PKTQ_OUT_SWQ;
1247 id = APP_PARAM_ADD(app->swq_params, name);
1248 } else if (validate_name(name, "TM", 1) == 0) {
1249 type = APP_PKTQ_OUT_TM;
1250 id = APP_PARAM_ADD(app->tm_params, name);
1251 } else if (validate_name(name, "SINK", 1) == 0) {
1252 type = APP_PKTQ_OUT_SINK;
1253 id = APP_PARAM_ADD(app->sink_params, name);
1260 p->pktq_out[p->n_pktq_out].type = type;
1261 p->pktq_out[p->n_pktq_out].id = id;
1269 parse_pipeline_msgq_in(struct app_params *app,
1270 struct app_pipeline_params *p,
1273 const char *next = value;
1275 char name[APP_PARAM_NAME_SIZE];
1279 while (*next != '\0') {
1283 next = skip_white_spaces(next);
1287 end_space = strchr(next, ' ');
1288 end_tab = strchr(next, ' ');
1290 if (end_space && (!end_tab))
1292 else if ((!end_space) && end_tab)
1294 else if (end_space && end_tab)
1295 end = RTE_MIN(end_space, end_tab);
1300 name_len = strlen(next);
1302 name_len = end - next;
1304 if (name_len == 0 || name_len == sizeof(name))
1307 strncpy(name, next, name_len);
1308 name[name_len] = '\0';
1313 if (validate_name(name, "MSGQ", 1) != 0)
1316 idx = APP_PARAM_ADD(app->msgq_params, name);
1320 p->msgq_in[p->n_msgq_in] = idx;
1328 parse_pipeline_msgq_out(struct app_params *app,
1329 struct app_pipeline_params *p,
1332 const char *next = value;
1334 char name[APP_PARAM_NAME_SIZE];
1338 while (*next != '\0') {
1342 next = skip_white_spaces(next);
1346 end_space = strchr(next, ' ');
1347 end_tab = strchr(next, ' ');
1349 if (end_space && (!end_tab))
1351 else if ((!end_space) && end_tab)
1353 else if (end_space && end_tab)
1354 end = RTE_MIN(end_space, end_tab);
1359 name_len = strlen(next);
1361 name_len = end - next;
1363 if (name_len == 0 || name_len == sizeof(name))
1366 strncpy(name, next, name_len);
1367 name[name_len] = '\0';
1372 if (validate_name(name, "MSGQ", 1) != 0)
1375 idx = APP_PARAM_ADD(app->msgq_params, name);
1379 p->msgq_out[p->n_msgq_out] = idx;
1387 parse_pipeline(struct app_params *app,
1388 const char *section_name,
1389 struct rte_cfgfile *cfg)
1391 char name[CFG_NAME_LEN];
1392 struct app_pipeline_params *param;
1393 struct rte_cfgfile_entry *entries;
1397 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1398 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1400 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1401 PARSE_ERROR_MALLOC(entries != NULL);
1403 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1405 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1406 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1408 param = &app->pipeline_params[param_idx];
1410 for (i = 0; i < n_entries; i++) {
1411 struct rte_cfgfile_entry *ent = &entries[i];
1413 if (strcmp(ent->name, "type") == 0) {
1414 int w_size = snprintf(param->type, RTE_DIM(param->type),
1417 PARSE_ERROR(((w_size > 0) &&
1418 (w_size < (int)RTE_DIM(param->type))),
1424 if (strcmp(ent->name, "core") == 0) {
1425 int status = parse_pipeline_core(
1426 ¶m->socket_id, ¶m->core_id,
1427 ¶m->hyper_th_id, ent->value);
1429 PARSE_ERROR((status == 0), section_name,
1434 if (strcmp(ent->name, "pktq_in") == 0) {
1435 int status = parse_pipeline_pktq_in(app, param,
1438 PARSE_ERROR((status == 0), section_name,
1443 if (strcmp(ent->name, "pktq_out") == 0) {
1444 int status = parse_pipeline_pktq_out(app, param,
1447 PARSE_ERROR((status == 0), section_name,
1452 if (strcmp(ent->name, "msgq_in") == 0) {
1453 int status = parse_pipeline_msgq_in(app, param,
1456 PARSE_ERROR((status == 0), section_name,
1461 if (strcmp(ent->name, "msgq_out") == 0) {
1462 int status = parse_pipeline_msgq_out(app, param,
1465 PARSE_ERROR((status == 0), section_name,
1470 if (strcmp(ent->name, "timer_period") == 0) {
1471 int status = parser_read_uint32(
1472 ¶m->timer_period,
1475 PARSE_ERROR((status == 0), section_name,
1480 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1481 int status = parse_pipeline_pcap_source(app,
1482 param, ent->value, NULL);
1484 PARSE_ERROR((status == 0), section_name,
1489 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1490 int status = parse_pipeline_pcap_source(app,
1491 param, NULL, ent->value);
1493 PARSE_ERROR((status == 0), section_name,
1498 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1499 int status = parse_pipeline_pcap_sink(app, param,
1502 PARSE_ERROR((status == 0), section_name,
1507 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1508 int status = parse_pipeline_pcap_sink(app, param,
1511 PARSE_ERROR((status == 0), section_name,
1516 /* pipeline type specific items */
1517 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1518 "Parse error in section \"%s\": too many "
1519 "pipeline specified parameters", section_name);
1521 param->args_name[param->n_args] = strdup(ent->name);
1522 param->args_value[param->n_args] = strdup(ent->value);
1524 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1525 (param->args_value[param->n_args] != NULL),
1526 "Parse error: no free memory");
1533 snprintf(name, sizeof(name), "MSGQ-REQ-%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_in[param->n_msgq_in++] = param_idx;
1539 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1540 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1541 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1542 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1543 param->msgq_out[param->n_msgq_out++] = param_idx;
1545 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1548 (param->hyper_th_id) ? "h" : "");
1549 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1550 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1551 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1553 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1556 (param->hyper_th_id) ? "h" : "");
1557 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1558 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1559 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1565 parse_mempool(struct app_params *app,
1566 const char *section_name,
1567 struct rte_cfgfile *cfg)
1569 struct app_mempool_params *param;
1570 struct rte_cfgfile_entry *entries;
1574 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1575 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1577 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1578 PARSE_ERROR_MALLOC(entries != NULL);
1580 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1582 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1583 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1585 param = &app->mempool_params[param_idx];
1587 for (i = 0; i < n_entries; i++) {
1588 struct rte_cfgfile_entry *ent = &entries[i];
1590 if (strcmp(ent->name, "buffer_size") == 0) {
1591 int status = parser_read_uint32(
1592 ¶m->buffer_size, ent->value);
1594 PARSE_ERROR((status == 0), section_name,
1599 if (strcmp(ent->name, "pool_size") == 0) {
1600 int status = parser_read_uint32(
1601 ¶m->pool_size, ent->value);
1603 PARSE_ERROR((status == 0), section_name,
1608 if (strcmp(ent->name, "cache_size") == 0) {
1609 int status = parser_read_uint32(
1610 ¶m->cache_size, ent->value);
1612 PARSE_ERROR((status == 0), section_name,
1617 if (strcmp(ent->name, "cpu") == 0) {
1618 int status = parser_read_uint32(
1619 ¶m->cpu_socket_id, ent->value);
1621 PARSE_ERROR((status == 0), section_name,
1627 PARSE_ERROR_INVALID(0, section_name, ent->name);
1636 parse_link(struct app_params *app,
1637 const char *section_name,
1638 struct rte_cfgfile *cfg)
1640 struct app_link_params *param;
1641 struct rte_cfgfile_entry *entries;
1643 int pci_bdf_present = 0;
1646 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1647 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1649 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1650 PARSE_ERROR_MALLOC(entries != NULL);
1652 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1654 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1655 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1657 param = &app->link_params[param_idx];
1659 for (i = 0; i < n_entries; i++) {
1660 struct rte_cfgfile_entry *ent = &entries[i];
1662 if (strcmp(ent->name, "promisc") == 0) {
1663 int status = parser_read_arg_bool(ent->value);
1665 PARSE_ERROR((status != -EINVAL), section_name,
1667 param->promisc = status;
1671 if (strcmp(ent->name, "arp_q") == 0) {
1672 int status = parser_read_uint32(¶m->arp_q,
1675 PARSE_ERROR((status == 0), section_name,
1680 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1681 int status = parser_read_uint32(
1682 ¶m->tcp_syn_q, ent->value);
1684 PARSE_ERROR((status == 0), section_name, ent->name);
1688 if (strcmp(ent->name, "ip_local_q") == 0) {
1689 int status = parser_read_uint32(
1690 ¶m->ip_local_q, ent->value);
1692 PARSE_ERROR((status == 0), section_name,
1698 if (strcmp(ent->name, "tcp_local_q") == 0) {
1699 int status = parser_read_uint32(
1700 ¶m->tcp_local_q, ent->value);
1702 PARSE_ERROR((status == 0), section_name,
1707 if (strcmp(ent->name, "udp_local_q") == 0) {
1708 int status = parser_read_uint32(
1709 ¶m->udp_local_q, ent->value);
1711 PARSE_ERROR((status == 0), section_name,
1716 if (strcmp(ent->name, "sctp_local_q") == 0) {
1717 int status = parser_read_uint32(
1718 ¶m->sctp_local_q, ent->value);
1720 PARSE_ERROR((status == 0), section_name,
1725 if (strcmp(ent->name, "pci_bdf") == 0) {
1726 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1727 section_name, ent->name);
1729 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1731 pci_bdf_present = 1;
1736 PARSE_ERROR_INVALID(0, section_name, ent->name);
1739 /* Check for mandatory fields */
1741 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1742 section_name, "pci_bdf",
1743 "entry not allowed (port_mask is provided)");
1745 PARSE_ERROR_MESSAGE((pci_bdf_present),
1746 section_name, "pci_bdf",
1747 "this entry is mandatory (port_mask is not "
1756 parse_rxq(struct app_params *app,
1757 const char *section_name,
1758 struct rte_cfgfile *cfg)
1760 struct app_pktq_hwq_in_params *param;
1761 struct rte_cfgfile_entry *entries;
1765 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1766 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1768 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1769 PARSE_ERROR_MALLOC(entries != NULL);
1771 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1773 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1774 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1776 param = &app->hwq_in_params[param_idx];
1778 for (i = 0; i < n_entries; i++) {
1779 struct rte_cfgfile_entry *ent = &entries[i];
1781 if (strcmp(ent->name, "mempool") == 0) {
1782 int status = validate_name(ent->value,
1786 PARSE_ERROR((status == 0), section_name,
1788 idx = APP_PARAM_ADD(app->mempool_params,
1790 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1792 param->mempool_id = idx;
1796 if (strcmp(ent->name, "size") == 0) {
1797 int status = parser_read_uint32(¶m->size,
1800 PARSE_ERROR((status == 0), section_name,
1805 if (strcmp(ent->name, "burst") == 0) {
1806 int status = parser_read_uint32(¶m->burst,
1809 PARSE_ERROR((status == 0), section_name,
1815 PARSE_ERROR_INVALID(0, section_name, ent->name);
1824 parse_txq(struct app_params *app,
1825 const char *section_name,
1826 struct rte_cfgfile *cfg)
1828 struct app_pktq_hwq_out_params *param;
1829 struct rte_cfgfile_entry *entries;
1833 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1834 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1836 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1837 PARSE_ERROR_MALLOC(entries != NULL);
1839 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1841 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1842 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1844 param = &app->hwq_out_params[param_idx];
1846 for (i = 0; i < n_entries; i++) {
1847 struct rte_cfgfile_entry *ent = &entries[i];
1849 if (strcmp(ent->name, "size") == 0) {
1850 int status = parser_read_uint32(¶m->size,
1853 PARSE_ERROR((status == 0), section_name,
1858 if (strcmp(ent->name, "burst") == 0) {
1859 int status = parser_read_uint32(¶m->burst,
1862 PARSE_ERROR((status == 0), section_name,
1867 if (strcmp(ent->name, "dropless") == 0) {
1868 int status = parser_read_arg_bool(ent->value);
1871 PARSE_ERROR((status != -EINVAL), section_name,
1873 param->dropless = status;
1878 PARSE_ERROR_INVALID(0, section_name, ent->name);
1887 parse_swq(struct app_params *app,
1888 const char *section_name,
1889 struct rte_cfgfile *cfg)
1891 struct app_pktq_swq_params *param;
1892 struct rte_cfgfile_entry *entries;
1894 uint32_t mtu_present = 0;
1895 uint32_t metadata_size_present = 0;
1896 uint32_t mempool_direct_present = 0;
1897 uint32_t mempool_indirect_present = 0;
1901 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1902 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1904 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1905 PARSE_ERROR_MALLOC(entries != NULL);
1907 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1909 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1910 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1912 param = &app->swq_params[param_idx];
1914 for (i = 0; i < n_entries; i++) {
1915 struct rte_cfgfile_entry *ent = &entries[i];
1917 if (strcmp(ent->name, "size") == 0) {
1918 int status = parser_read_uint32(¶m->size,
1921 PARSE_ERROR((status == 0), section_name,
1926 if (strcmp(ent->name, "burst_read") == 0) {
1927 int status = parser_read_uint32(&
1928 param->burst_read, ent->value);
1930 PARSE_ERROR((status == 0), section_name,
1935 if (strcmp(ent->name, "burst_write") == 0) {
1936 int status = parser_read_uint32(
1937 ¶m->burst_write, ent->value);
1939 PARSE_ERROR((status == 0), section_name,
1944 if (strcmp(ent->name, "dropless") == 0) {
1945 int status = parser_read_arg_bool(ent->value);
1947 PARSE_ERROR((status != -EINVAL), section_name,
1949 param->dropless = status;
1953 if (strcmp(ent->name, "n_retries") == 0) {
1954 int status = parser_read_uint64(¶m->n_retries,
1957 PARSE_ERROR((status == 0), section_name,
1962 if (strcmp(ent->name, "cpu") == 0) {
1963 int status = parser_read_uint32(
1964 ¶m->cpu_socket_id, ent->value);
1966 PARSE_ERROR((status == 0), section_name, ent->name);
1970 if (strcmp(ent->name, "ipv4_frag") == 0) {
1971 int status = parser_read_arg_bool(ent->value);
1973 PARSE_ERROR((status != -EINVAL), section_name,
1976 param->ipv4_frag = status;
1977 if (param->mtu == 0)
1983 if (strcmp(ent->name, "ipv6_frag") == 0) {
1984 int status = parser_read_arg_bool(ent->value);
1986 PARSE_ERROR((status != -EINVAL), section_name,
1988 param->ipv6_frag = status;
1989 if (param->mtu == 0)
1994 if (strcmp(ent->name, "ipv4_ras") == 0) {
1995 int status = parser_read_arg_bool(ent->value);
1997 PARSE_ERROR((status != -EINVAL), section_name,
1999 param->ipv4_ras = status;
2003 if (strcmp(ent->name, "ipv6_ras") == 0) {
2004 int status = parser_read_arg_bool(ent->value);
2006 PARSE_ERROR((status != -EINVAL), section_name,
2008 param->ipv6_ras = status;
2012 if (strcmp(ent->name, "mtu") == 0) {
2013 int status = parser_read_uint32(¶m->mtu,
2016 PARSE_ERROR((status == 0), section_name,
2022 if (strcmp(ent->name, "metadata_size") == 0) {
2023 int status = parser_read_uint32(
2024 ¶m->metadata_size, ent->value);
2026 PARSE_ERROR((status == 0), section_name,
2028 metadata_size_present = 1;
2032 if (strcmp(ent->name, "mempool_direct") == 0) {
2033 int status = validate_name(ent->value,
2037 PARSE_ERROR((status == 0), section_name,
2040 idx = APP_PARAM_ADD(app->mempool_params,
2042 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2044 param->mempool_direct_id = idx;
2045 mempool_direct_present = 1;
2049 if (strcmp(ent->name, "mempool_indirect") == 0) {
2050 int status = validate_name(ent->value,
2054 PARSE_ERROR((status == 0), section_name,
2056 idx = APP_PARAM_ADD(app->mempool_params,
2058 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2060 param->mempool_indirect_id = idx;
2061 mempool_indirect_present = 1;
2066 PARSE_ERROR_INVALID(0, section_name, ent->name);
2069 APP_CHECK(((mtu_present) &&
2070 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2071 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2072 "is off, therefore entry \"mtu\" is not allowed",
2075 APP_CHECK(((metadata_size_present) &&
2076 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2077 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2078 "is off, therefore entry \"metadata_size\" is "
2079 "not allowed", section_name);
2081 APP_CHECK(((mempool_direct_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_direct\" is "
2085 "not allowed", section_name);
2087 APP_CHECK(((mempool_indirect_present) &&
2088 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2089 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2090 "is off, therefore entry \"mempool_indirect\" is "
2091 "not allowed", section_name);
2099 parse_tm(struct app_params *app,
2100 const char *section_name,
2101 struct rte_cfgfile *cfg)
2103 struct app_pktq_tm_params *param;
2104 struct rte_cfgfile_entry *entries;
2108 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2109 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2111 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2112 PARSE_ERROR_MALLOC(entries != NULL);
2114 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2116 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2117 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2119 param = &app->tm_params[param_idx];
2121 for (i = 0; i < n_entries; i++) {
2122 struct rte_cfgfile_entry *ent = &entries[i];
2124 if (strcmp(ent->name, "cfg") == 0) {
2125 param->file_name = strdup(ent->value);
2126 PARSE_ERROR_MALLOC(param->file_name != NULL);
2130 if (strcmp(ent->name, "burst_read") == 0) {
2131 int status = parser_read_uint32(
2132 ¶m->burst_read, ent->value);
2134 PARSE_ERROR((status == 0), section_name,
2139 if (strcmp(ent->name, "burst_write") == 0) {
2140 int status = parser_read_uint32(
2141 ¶m->burst_write, ent->value);
2143 PARSE_ERROR((status == 0), section_name,
2149 PARSE_ERROR_INVALID(0, section_name, ent->name);
2158 parse_source(struct app_params *app,
2159 const char *section_name,
2160 struct rte_cfgfile *cfg)
2162 struct app_pktq_source_params *param;
2163 struct rte_cfgfile_entry *entries;
2167 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2168 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2170 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2171 PARSE_ERROR_MALLOC(entries != NULL);
2173 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2175 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2176 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2178 param = &app->source_params[param_idx];
2180 for (i = 0; i < n_entries; i++) {
2181 struct rte_cfgfile_entry *ent = &entries[i];
2183 if (strcmp(ent->name, "mempool") == 0) {
2184 int status = validate_name(ent->value,
2188 PARSE_ERROR((status == 0), section_name,
2190 idx = APP_PARAM_ADD(app->mempool_params,
2192 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2194 param->mempool_id = idx;
2198 if (strcmp(ent->name, "burst") == 0) {
2199 int status = parser_read_uint32(¶m->burst,
2202 PARSE_ERROR((status == 0), section_name,
2207 if (strcmp(ent->name, "pcap_file_rd")) {
2208 param->file_name = strdup(ent->value);
2210 PARSE_ERROR_MALLOC(param->file_name != NULL);
2214 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2215 int status = parser_read_uint32(
2216 ¶m->n_bytes_per_pkt, ent->value);
2218 PARSE_ERROR((status == 0), section_name,
2223 PARSE_ERROR_INVALID(0, section_name, ent->name);
2232 parse_sink(struct app_params *app,
2233 const char *section_name,
2234 struct rte_cfgfile *cfg)
2236 struct app_pktq_sink_params *param;
2237 struct rte_cfgfile_entry *entries;
2241 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2242 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2244 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2245 PARSE_ERROR_MALLOC(entries != NULL);
2247 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2249 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2250 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2252 param = &app->sink_params[param_idx];
2254 for (i = 0; i < n_entries; i++) {
2255 struct rte_cfgfile_entry *ent = &entries[i];
2257 if (strcmp(ent->name, "pcap_file_wr")) {
2258 param->file_name = strdup(ent->value);
2260 PARSE_ERROR_MALLOC((param->file_name != NULL));
2264 if (strcmp(ent->name, "pcap_n_pkt_wr")) {
2265 int status = parser_read_uint32(
2266 ¶m->n_pkts_to_dump, ent->value);
2268 PARSE_ERROR((status == 0), section_name,
2274 PARSE_ERROR_INVALID(0, section_name, ent->name);
2283 parse_msgq_req_pipeline(struct app_params *app,
2284 const char *section_name,
2285 struct rte_cfgfile *cfg)
2287 struct app_msgq_params *param;
2288 struct rte_cfgfile_entry *entries;
2292 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2293 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2295 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2296 PARSE_ERROR_MALLOC(entries != NULL);
2298 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2300 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2301 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2303 param = &app->msgq_params[param_idx];
2305 for (i = 0; i < n_entries; i++) {
2306 struct rte_cfgfile_entry *ent = &entries[i];
2308 if (strcmp(ent->name, "size") == 0) {
2309 int status = parser_read_uint32(¶m->size,
2312 PARSE_ERROR((status == 0), section_name,
2318 PARSE_ERROR_INVALID(0, section_name, ent->name);
2326 parse_msgq_rsp_pipeline(struct app_params *app,
2327 const char *section_name,
2328 struct rte_cfgfile *cfg)
2330 struct app_msgq_params *param;
2331 struct rte_cfgfile_entry *entries;
2335 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2336 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2338 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2339 PARSE_ERROR_MALLOC(entries != NULL);
2341 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2343 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2344 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2346 param = &app->msgq_params[param_idx];
2348 for (i = 0; i < n_entries; i++) {
2349 struct rte_cfgfile_entry *ent = &entries[i];
2351 if (strcmp(ent->name, "size") == 0) {
2352 int status = parser_read_uint32(¶m->size,
2355 PARSE_ERROR((status == 0), section_name,
2361 PARSE_ERROR_INVALID(0, section_name, ent->name);
2370 parse_msgq(struct app_params *app,
2371 const char *section_name,
2372 struct rte_cfgfile *cfg)
2374 struct app_msgq_params *param;
2375 struct rte_cfgfile_entry *entries;
2379 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2380 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2382 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2383 PARSE_ERROR_MALLOC(entries != NULL);
2385 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2387 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2388 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2390 param = &app->msgq_params[param_idx];
2392 for (i = 0; i < n_entries; i++) {
2393 struct rte_cfgfile_entry *ent = &entries[i];
2395 if (strcmp(ent->name, "size") == 0) {
2396 int status = parser_read_uint32(¶m->size,
2399 PARSE_ERROR((status == 0), section_name,
2404 if (strcmp(ent->name, "cpu") == 0) {
2405 int status = parser_read_uint32(
2406 ¶m->cpu_socket_id, ent->value);
2408 PARSE_ERROR((status == 0), section_name,
2414 PARSE_ERROR_INVALID(0, section_name, ent->name);
2422 typedef void (*config_section_load)(struct app_params *p,
2423 const char *section_name,
2424 struct rte_cfgfile *cfg);
2426 struct config_section {
2427 const char prefix[CFG_NAME_LEN];
2429 config_section_load load;
2432 static const struct config_section cfg_file_scheme[] = {
2433 {"EAL", 0, parse_eal},
2434 {"PIPELINE", 1, parse_pipeline},
2435 {"MEMPOOL", 1, parse_mempool},
2436 {"LINK", 1, parse_link},
2437 {"RXQ", 2, parse_rxq},
2438 {"TXQ", 2, parse_txq},
2439 {"SWQ", 1, parse_swq},
2440 {"TM", 1, parse_tm},
2441 {"SOURCE", 1, parse_source},
2442 {"SINK", 1, parse_sink},
2443 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2444 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2445 {"MSGQ", 1, parse_msgq},
2449 create_implicit_mempools(struct app_params *app)
2453 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2454 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2458 create_implicit_links_from_port_mask(struct app_params *app,
2461 uint32_t pmd_id, link_id;
2464 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2465 char name[APP_PARAM_NAME_SIZE];
2468 if ((port_mask & (1LLU << pmd_id)) == 0)
2471 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2472 idx = APP_PARAM_ADD(app->link_params, name);
2473 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2475 app->link_params[idx].pmd_id = pmd_id;
2481 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2485 for (i = 0; i < app->n_links; i++) {
2486 struct app_link_params *link = &app->link_params[i];
2493 app_config_parse(struct app_params *app, const char *file_name)
2495 struct rte_cfgfile *cfg;
2496 char **section_names;
2497 int i, j, sect_count;
2499 /* Implicit mempools */
2500 create_implicit_mempools(app);
2504 create_implicit_links_from_port_mask(app, app->port_mask);
2506 /* Load application configuration file */
2507 cfg = rte_cfgfile_load(file_name, 0);
2508 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2509 "file %s", file_name);
2511 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2512 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2513 "in file \"%s\" return %d", file_name,
2516 section_names = malloc(sect_count * sizeof(char *));
2517 PARSE_ERROR_MALLOC(section_names != NULL);
2519 for (i = 0; i < sect_count; i++)
2520 section_names[i] = malloc(CFG_NAME_LEN);
2522 rte_cfgfile_sections(cfg, section_names, sect_count);
2524 for (i = 0; i < sect_count; i++) {
2525 const struct config_section *sch_s;
2526 int len, cfg_name_len;
2528 cfg_name_len = strlen(section_names[i]);
2530 /* Find section type */
2531 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2532 sch_s = &cfg_file_scheme[j];
2533 len = strlen(sch_s->prefix);
2535 if (cfg_name_len < len)
2538 /* After section name we expect only '\0' or digit or
2539 * digit dot digit, so protect against false matching,
2540 * for example: "ABC" should match section name
2541 * "ABC0.0", but it should not match section_name
2544 if ((section_names[i][len] != '\0') &&
2545 !isdigit(section_names[i][len]))
2548 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2552 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2553 "Parse error: unknown section %s",
2556 APP_CHECK(validate_name(section_names[i],
2558 sch_s->numbers) == 0,
2559 "Parse error: invalid section name \"%s\"",
2562 sch_s->load(app, section_names[i], cfg);
2565 for (i = 0; i < sect_count; i++)
2566 free(section_names[i]);
2568 free(section_names);
2570 rte_cfgfile_close(cfg);
2572 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2573 APP_PARAM_COUNT(app->link_params, app->n_links);
2574 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2575 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2576 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2577 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2578 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2579 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2580 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2581 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2583 if (app->port_mask == 0)
2584 assign_link_pmd_id_from_pci_bdf(app);
2586 /* Save configuration to output file */
2587 app_config_save(app, app->output_file);
2589 /* Load TM configuration files */
2590 app_config_parse_tm(app);
2596 save_eal_params(struct app_params *app, FILE *f)
2598 struct app_eal_params *p = &app->eal_params;
2601 fprintf(f, "[EAL]\n");
2604 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2606 if (p->master_lcore_present)
2607 fprintf(f, "%s = %" PRIu32 "\n",
2608 "master_lcore", p->master_lcore);
2610 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2612 if (p->memory_present)
2613 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2615 if (p->ranks_present)
2616 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2618 for (i = 0; i < APP_MAX_LINKS; i++) {
2619 if (p->pci_blacklist[i] == NULL)
2622 fprintf(f, "%s = %s\n", "pci_blacklist",
2623 p->pci_blacklist[i]);
2626 for (i = 0; i < APP_MAX_LINKS; i++) {
2627 if (p->pci_whitelist[i] == NULL)
2630 fprintf(f, "%s = %s\n", "pci_whitelist",
2631 p->pci_whitelist[i]);
2634 for (i = 0; i < APP_MAX_LINKS; i++) {
2635 if (p->vdev[i] == NULL)
2638 fprintf(f, "%s = %s\n", "vdev",
2642 if (p->vmware_tsc_map_present)
2643 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2644 (p->vmware_tsc_map) ? "yes" : "no");
2647 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2650 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2652 if (p->log_level_present)
2653 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2655 if (p->version_present)
2656 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2658 if (p->help_present)
2659 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2661 if (p->no_huge_present)
2662 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2664 if (p->no_pci_present)
2665 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2667 if (p->no_hpet_present)
2668 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2670 if (p->no_shconf_present)
2671 fprintf(f, "%s = %s\n", "no_shconf",
2672 (p->no_shconf) ? "yes" : "no");
2675 fprintf(f, "%s = %s\n", "d", p->add_driver);
2678 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2681 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2684 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2686 if (p->base_virtaddr)
2687 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2689 if (p->create_uio_dev_present)
2690 fprintf(f, "%s = %s\n", "create_uio_dev",
2691 (p->create_uio_dev) ? "yes" : "no");
2694 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2696 if (p->xen_dom0_present)
2697 fprintf(f, "%s = %s\n", "xen_dom0",
2698 (p->xen_dom0) ? "yes" : "no");
2704 save_mempool_params(struct app_params *app, FILE *f)
2706 struct app_mempool_params *p;
2709 count = RTE_DIM(app->mempool_params);
2710 for (i = 0; i < count; i++) {
2711 p = &app->mempool_params[i];
2712 if (!APP_PARAM_VALID(p))
2715 fprintf(f, "[%s]\n", p->name);
2716 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2717 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2718 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2719 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2726 save_links_params(struct app_params *app, FILE *f)
2728 struct app_link_params *p;
2731 count = RTE_DIM(app->link_params);
2732 for (i = 0; i < count; i++) {
2733 p = &app->link_params[i];
2734 if (!APP_PARAM_VALID(p))
2737 fprintf(f, "[%s]\n", p->name);
2738 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2739 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2740 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2741 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2743 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2744 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2745 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2746 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2749 if (strlen(p->pci_bdf))
2750 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2757 save_rxq_params(struct app_params *app, FILE *f)
2759 struct app_pktq_hwq_in_params *p;
2762 count = RTE_DIM(app->hwq_in_params);
2763 for (i = 0; i < count; i++) {
2764 p = &app->hwq_in_params[i];
2765 if (!APP_PARAM_VALID(p))
2768 fprintf(f, "[%s]\n", p->name);
2769 fprintf(f, "%s = %s\n",
2771 app->mempool_params[p->mempool_id].name);
2772 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2773 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2780 save_txq_params(struct app_params *app, FILE *f)
2782 struct app_pktq_hwq_out_params *p;
2785 count = RTE_DIM(app->hwq_out_params);
2786 for (i = 0; i < count; i++) {
2787 p = &app->hwq_out_params[i];
2788 if (!APP_PARAM_VALID(p))
2791 fprintf(f, "[%s]\n", p->name);
2792 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2793 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2794 fprintf(f, "%s = %s\n",
2796 p->dropless ? "yes" : "no");
2803 save_swq_params(struct app_params *app, FILE *f)
2805 struct app_pktq_swq_params *p;
2808 count = RTE_DIM(app->swq_params);
2809 for (i = 0; i < count; i++) {
2810 p = &app->swq_params[i];
2811 if (!APP_PARAM_VALID(p))
2814 fprintf(f, "[%s]\n", p->name);
2815 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2816 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2817 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2818 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2819 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2820 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2821 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2822 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2823 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2824 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2825 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2826 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2827 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2828 fprintf(f, "%s = %s\n",
2830 app->mempool_params[p->mempool_direct_id].name);
2831 fprintf(f, "%s = %s\n",
2833 app->mempool_params[p->mempool_indirect_id].name);
2841 save_tm_params(struct app_params *app, FILE *f)
2843 struct app_pktq_tm_params *p;
2846 count = RTE_DIM(app->tm_params);
2847 for (i = 0; i < count; i++) {
2848 p = &app->tm_params[i];
2849 if (!APP_PARAM_VALID(p))
2852 fprintf(f, "[%s]\n", p->name);
2853 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2854 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2855 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2862 save_source_params(struct app_params *app, FILE *f)
2864 struct app_pktq_source_params *p;
2867 count = RTE_DIM(app->source_params);
2868 for (i = 0; i < count; i++) {
2869 p = &app->source_params[i];
2870 if (!APP_PARAM_VALID(p))
2873 fprintf(f, "[%s]\n", p->name);
2874 fprintf(f, "%s = %s\n",
2876 app->mempool_params[p->mempool_id].name);
2877 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2878 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2879 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2880 p->n_bytes_per_pkt);
2886 save_sink_params(struct app_params *app, FILE *f)
2888 struct app_pktq_sink_params *p;
2891 count = RTE_DIM(app->sink_params);
2892 for (i = 0; i < count; i++) {
2893 p = &app->sink_params[i];
2894 if (!APP_PARAM_VALID(p))
2897 fprintf(f, "[%s]\n", p->name);
2898 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2899 fprintf(f, "%s = %" PRIu32 "\n",
2900 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2906 save_msgq_params(struct app_params *app, FILE *f)
2908 struct app_msgq_params *p;
2911 count = RTE_DIM(app->msgq_params);
2912 for (i = 0; i < count; i++) {
2913 p = &app->msgq_params[i];
2914 if (!APP_PARAM_VALID(p))
2917 fprintf(f, "[%s]\n", p->name);
2918 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2919 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2926 save_pipeline_params(struct app_params *app, FILE *f)
2930 count = RTE_DIM(app->pipeline_params);
2931 for (i = 0; i < count; i++) {
2932 struct app_pipeline_params *p = &app->pipeline_params[i];
2934 if (!APP_PARAM_VALID(p))
2938 fprintf(f, "[%s]\n", p->name);
2941 fprintf(f, "type = %s\n", p->type);
2944 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2947 (p->hyper_th_id) ? "h" : "");
2953 fprintf(f, "pktq_in =");
2954 for (j = 0; j < p->n_pktq_in; j++) {
2955 struct app_pktq_in_params *pp = &p->pktq_in[j];
2959 case APP_PKTQ_IN_HWQ:
2960 name = app->hwq_in_params[pp->id].name;
2962 case APP_PKTQ_IN_SWQ:
2963 name = app->swq_params[pp->id].name;
2965 case APP_PKTQ_IN_TM:
2966 name = app->tm_params[pp->id].name;
2968 case APP_PKTQ_IN_SOURCE:
2969 name = app->source_params[pp->id].name;
2972 APP_CHECK(0, "System error "
2973 "occurred while saving "
2974 "parameter to file");
2977 fprintf(f, " %s", name);
2983 if (p->n_pktq_out) {
2986 fprintf(f, "pktq_out =");
2987 for (j = 0; j < p->n_pktq_out; j++) {
2988 struct app_pktq_out_params *pp =
2993 case APP_PKTQ_OUT_HWQ:
2994 name = app->hwq_out_params[pp->id].name;
2996 case APP_PKTQ_OUT_SWQ:
2997 name = app->swq_params[pp->id].name;
2999 case APP_PKTQ_OUT_TM:
3000 name = app->tm_params[pp->id].name;
3002 case APP_PKTQ_OUT_SINK:
3003 name = app->sink_params[pp->id].name;
3006 APP_CHECK(0, "System error "
3007 "occurred while saving "
3008 "parameter to file");
3011 fprintf(f, " %s", name);
3020 fprintf(f, "msgq_in =");
3021 for (j = 0; j < p->n_msgq_in; j++) {
3022 uint32_t id = p->msgq_in[j];
3023 char *name = app->msgq_params[id].name;
3025 fprintf(f, " %s", name);
3031 if (p->n_msgq_out) {
3034 fprintf(f, "msgq_out =");
3035 for (j = 0; j < p->n_msgq_out; j++) {
3036 uint32_t id = p->msgq_out[j];
3037 char *name = app->msgq_params[id].name;
3039 fprintf(f, " %s", name);
3045 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3051 for (j = 0; j < p->n_args; j++)
3052 fprintf(f, "%s = %s\n", p->args_name[j],
3061 app_config_save(struct app_params *app, const char *file_name)
3064 char *name, *dir_name;
3067 name = strdup(file_name);
3068 dir_name = dirname(name);
3069 status = access(dir_name, W_OK);
3070 APP_CHECK((status == 0),
3071 "Error: need write access privilege to directory "
3072 "\"%s\" to save configuration\n", dir_name);
3074 file = fopen(file_name, "w");
3075 APP_CHECK((file != NULL),
3076 "Error: failed to save configuration to file \"%s\"",
3079 save_eal_params(app, file);
3080 save_pipeline_params(app, file);
3081 save_mempool_params(app, file);
3082 save_links_params(app, file);
3083 save_rxq_params(app, file);
3084 save_txq_params(app, file);
3085 save_swq_params(app, file);
3086 save_tm_params(app, file);
3087 save_source_params(app, file);
3088 save_sink_params(app, file);
3089 save_msgq_params(app, file);
3096 app_config_init(struct app_params *app)
3100 memcpy(app, &app_params_default, sizeof(struct app_params));
3102 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3103 memcpy(&app->mempool_params[i],
3104 &mempool_params_default,
3105 sizeof(struct app_mempool_params));
3107 for (i = 0; i < RTE_DIM(app->link_params); i++)
3108 memcpy(&app->link_params[i],
3109 &link_params_default,
3110 sizeof(struct app_link_params));
3112 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3113 memcpy(&app->hwq_in_params[i],
3114 &default_hwq_in_params,
3115 sizeof(default_hwq_in_params));
3117 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3118 memcpy(&app->hwq_out_params[i],
3119 &default_hwq_out_params,
3120 sizeof(default_hwq_out_params));
3122 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3123 memcpy(&app->swq_params[i],
3124 &default_swq_params,
3125 sizeof(default_swq_params));
3127 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3128 memcpy(&app->tm_params[i],
3130 sizeof(default_tm_params));
3132 for (i = 0; i < RTE_DIM(app->source_params); i++)
3133 memcpy(&app->source_params[i],
3134 &default_source_params,
3135 sizeof(default_source_params));
3137 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3138 memcpy(&app->sink_params[i],
3139 &default_sink_params,
3140 sizeof(default_sink_params));
3142 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3143 memcpy(&app->msgq_params[i],
3144 &default_msgq_params,
3145 sizeof(default_msgq_params));
3147 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3148 memcpy(&app->pipeline_params[i],
3149 &default_pipeline_params,
3150 sizeof(default_pipeline_params));
3156 filenamedup(const char *filename, const char *suffix)
3158 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3163 sprintf(s, "%s%s", filename, suffix);
3168 app_config_args(struct app_params *app, int argc, char **argv)
3170 const char *optname;
3171 int opt, option_index;
3172 int f_present, s_present, p_present, l_present;
3173 int preproc_present, preproc_params_present;
3176 static struct option lgopts[] = {
3177 { "preproc", 1, 0, 0 },
3178 { "preproc-args", 1, 0, 0 },
3182 /* Copy application name */
3183 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3189 preproc_present = 0;
3190 preproc_params_present = 0;
3192 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3193 &option_index)) != EOF)
3197 rte_panic("Error: Config file is provided "
3198 "more than once\n");
3201 if (!strlen(optarg))
3202 rte_panic("Error: Config file name is null\n");
3204 app->config_file = strdup(optarg);
3205 if (app->config_file == NULL)
3206 rte_panic("Error: Memory allocation failure\n");
3212 rte_panic("Error: Script file is provided "
3213 "more than once\n");
3216 if (!strlen(optarg))
3217 rte_panic("Error: Script file name is null\n");
3219 app->script_file = strdup(optarg);
3220 if (app->script_file == NULL)
3221 rte_panic("Error: Memory allocation failure\n");
3227 rte_panic("Error: PORT_MASK is provided "
3228 "more than once\n");
3231 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3233 ((size_t) scaned != strlen(optarg)))
3234 rte_panic("Error: PORT_MASK is not "
3235 "a hexadecimal integer\n");
3237 if (app->port_mask == 0)
3238 rte_panic("Error: PORT_MASK is null\n");
3244 rte_panic("Error: LOG_LEVEL is provided "
3245 "more than once\n");
3248 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3250 ((size_t) scaned != strlen(optarg)) ||
3251 (app->log_level >= APP_LOG_LEVELS))
3252 rte_panic("Error: LOG_LEVEL invalid value\n");
3257 optname = lgopts[option_index].name;
3259 if (strcmp(optname, "preproc") == 0) {
3260 if (preproc_present)
3261 rte_panic("Error: Preprocessor argument "
3262 "is provided more than once\n");
3263 preproc_present = 1;
3265 app->preproc = strdup(optarg);
3269 if (strcmp(optname, "preproc-args") == 0) {
3270 if (preproc_params_present)
3271 rte_panic("Error: Preprocessor args "
3272 "are provided more than once\n");
3273 preproc_params_present = 1;
3275 app->preproc_args = strdup(optarg);
3279 app_print_usage(argv[0]);
3283 app_print_usage(argv[0]);
3286 optind = 0; /* reset getopt lib */
3288 /* Check dependencies between args */
3289 if (preproc_params_present && (preproc_present == 0))
3290 rte_panic("Error: Preprocessor args specified while "
3291 "preprocessor is not defined\n");
3293 app->parser_file = preproc_present ?
3294 filenamedup(app->config_file, ".preproc") :
3295 strdup(app->config_file);
3296 app->output_file = filenamedup(app->config_file, ".out");
3302 app_config_preproc(struct app_params *app)
3307 if (app->preproc == NULL)
3310 status = access(app->config_file, F_OK | R_OK);
3311 APP_CHECK((status == 0), "Error: Unable to open file %s",
3314 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3316 app->preproc_args ? app->preproc_args : "",
3320 status = system(buffer);
3321 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3322 "Error occurred while pre-processing file \"%s\"\n",