2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
28 #include <rte_errno.h>
29 #include <rte_cfgfile.h>
30 #include <rte_string_fns.h>
37 * Default config values
39 uint32_t rest_support = 1;
41 static struct app_params app_params_default = {
42 .config_file = "./config/ip_pipeline.cfg",
43 .log_level = APP_LOG_LEVEL_HIGH,
51 static const struct app_mempool_params mempool_params_default = {
53 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
54 .pool_size = 32 * 1024,
59 static const struct app_link_params link_params_default = {
70 .ipv6 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
79 .mq_mode = ETH_MQ_RX_NONE,
81 .header_split = 0, /* Header split */
82 .hw_ip_checksum = 0, /* IP checksum offload */
83 .hw_vlan_filter = 0, /* VLAN filtering */
84 .hw_vlan_strip = 0, /* VLAN strip */
85 .hw_vlan_extend = 0, /* Extended VLAN */
86 .jumbo_frame = 0, /* Jumbo frame support */
87 .hw_strip_crc = 0, /* CRC strip by HW */
88 .enable_scatter = 0, /* Scattered packets RX handler */
90 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
91 .split_hdr_size = 0, /* Header split buffer size */
94 .mq_mode = ETH_MQ_TX_NONE,
99 .lsc = 1, /**< lsc interrupt feature enabled */
107 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
119 .rx_free_thresh = 64,
121 .rx_deferred_start = 0,
125 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
140 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
141 ETH_TXQ_FLAGS_NOOFFLOADS,
142 .tx_deferred_start = 0,
146 static const struct app_pktq_swq_params default_swq_params = {
160 .mempool_direct_id = 0,
161 .mempool_indirect_id = 0,
164 struct app_pktq_tm_params default_tm_params = {
166 .file_name = "./config/tm_profile.cfg",
171 struct app_pktq_source_params default_source_params = {
176 .n_bytes_per_pkt = 0,
179 struct app_pktq_sink_params default_sink_params = {
185 struct app_msgq_params default_msgq_params = {
191 struct app_pipeline_params default_pipeline_params = {
204 static const char app_usage[] =
205 "Usage: %s [--version] [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
206 "[-l LOG_LEVEL] [--disable-hw-csum] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
209 "\t-f CONFIG_FILE: Default config file is %s\n"
210 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
211 "config file when not provided)\n"
212 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
213 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
214 "\t--version application version\n"
215 "\t--disable-hw-csum Disable TCP/UDP HW checksum\n"
216 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
217 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
221 app_print_usage(char *prgname)
223 rte_exit(0, app_usage, prgname, app_params_default.config_file);
226 #define skip_white_spaces(pos) \
228 __typeof__(pos) _p = (pos); \
229 for ( ; isspace(*_p); _p++); \
233 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
235 APP_CHECK((result != -EINVAL), \
236 "Parse error: no free memory"); \
237 APP_CHECK((result != -ENOMEM), \
238 "Parse error: too many \"%s\" sections", section_name); \
239 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
240 "Parse error: duplicate \"%s\" section", section_name); \
241 APP_CHECK((result >= 0), \
242 "Parse error in section \"%s\"", section_name); \
245 uint32_t is_rest_support(void)
251 parser_read_arg_bool(const char *p)
253 p = skip_white_spaces(p);
254 int result = -EINVAL;
256 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
257 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
262 if (((p[0] == 'o') && (p[1] == 'n')) ||
263 ((p[0] == 'O') && (p[1] == 'N'))) {
268 if (((p[0] == 'n') && (p[1] == 'o')) ||
269 ((p[0] == 'N') && (p[1] == 'O'))) {
274 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
275 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
280 p = skip_white_spaces(p);
288 #define PARSE_ERROR(exp, section, entry) \
289 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
291 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
292 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n", \
293 section, entry, message)
296 #define PARSE_ERROR_MALLOC(exp) \
297 APP_CHECK(exp, "Parse error: no free memory\n")
299 #define PARSE_ERROR_SECTION(exp, section) \
300 APP_CHECK(exp, "Parse error in section \"%s\"", section)
302 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
303 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
305 #define PARSE_WARNING_IGNORED(exp, section, entry) \
308 fprintf(stderr, "Parse warning in section \"%s\": " \
309 "entry \"%s\" is ignored\n", section, entry); \
312 #define PARSE_ERROR_INVALID(exp, section, entry) \
313 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
316 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
317 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
321 parser_read_uint64(uint64_t *value, const char *p)
326 p = skip_white_spaces(p);
330 val = strtoul(p, &next, 10);
352 p = skip_white_spaces(p);
361 parser_read_uint32(uint32_t *value, const char *p)
364 int ret = parser_read_uint64(&val, p);
369 if (val > UINT32_MAX)
377 parse_pipeline_core(uint32_t *socket,
385 uint32_t s = 0, c = 0, h = 0, val;
386 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
387 const char *next = skip_white_spaces(entry);
390 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
391 while (*next != '\0') {
392 /* If everything parsed nothing should left */
393 if (s_parsed && c_parsed && h_parsed)
400 if (s_parsed || c_parsed || h_parsed)
407 if (c_parsed || h_parsed)
420 /* If it start from digit it must be only core id. */
421 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
427 for (num_len = 0; *next != '\0'; next++, num_len++) {
428 if (num_len == RTE_DIM(num))
434 num[num_len] = *next;
437 if (num_len == 0 && type != 'h' && type != 'H')
440 if (num_len != 0 && (type == 'h' || type == 'H'))
442 if(num_len < sizeof(num))
444 val = strtol(num, NULL, 10);
473 case '0': case '1': case '2': case '3': case '4': case '5':
474 case '6': case '7': case '8': case '9':
476 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
478 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
486 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
491 /* Check input parameters */
499 if (((len & 3) != 0) ||
504 for (c = src; *c != 0; c++) {
505 if ((((*c) >= '0') && ((*c) <= '9')) ||
506 (((*c) >= 'A') && ((*c) <= 'F')) ||
507 (((*c) >= 'a') && ((*c) <= 'f')))
513 /* Convert chars to bytes */
514 for (i = 0; i < *size; i++)
515 dst[i] = get_hex_val(src[2 * i]) * 16 +
516 get_hex_val(src[2 * i + 1]);
522 skip_digits(const char *src)
526 for (i = 0; isdigit(src[i]); i++);
532 validate_name(const char *name, const char *prefix, int num)
536 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
537 if (name[i] != prefix[i])
541 if (prefix[i] != '\0')
552 j = skip_digits(&name[i]);
554 if ((j == 0) || (name[i] != '.'))
560 j = skip_digits(&name[i]);
562 if ((j == 0) || (name[i] != '\0'))
570 parse_eal(struct app_params *app,
571 const char *section_name,
572 struct rte_cfgfile *cfg)
574 struct app_eal_params *p = &app->eal_params;
575 struct rte_cfgfile_entry *entries;
578 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
579 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
581 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
582 PARSE_ERROR_MALLOC(entries != NULL);
584 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
586 for (i = 0; i < n_entries; i++) {
587 struct rte_cfgfile_entry *entry = &entries[i];
590 if (strcmp(entry->name, "c") == 0) {
591 PARSE_WARNING_IGNORED(0, section_name, entry->name);
596 if (strcmp(entry->name, "l") == 0) {
597 PARSE_WARNING_IGNORED(0, section_name, entry->name);
602 if (strcmp(entry->name, "lcores") == 0) {
603 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
606 p->coremap = strdup(entry->value);
611 if (strcmp(entry->name, "master_lcore") == 0) {
614 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
617 p->master_lcore_present = 1;
619 status = parser_read_uint32(&p->master_lcore,
621 PARSE_ERROR((status == 0), section_name, entry->name);
626 if (strcmp(entry->name, "n") == 0) {
629 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
632 p->channels_present = 1;
634 status = parser_read_uint32(&p->channels, entry->value);
635 PARSE_ERROR((status == 0), section_name, entry->name);
640 if (strcmp(entry->name, "m") == 0) {
643 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
646 p->memory_present = 1;
648 status = parser_read_uint32(&p->memory, entry->value);
649 PARSE_ERROR((status == 0), section_name, entry->name);
654 if (strcmp(entry->name, "r") == 0) {
657 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
660 p->ranks_present = 1;
662 status = parser_read_uint32(&p->ranks, entry->value);
663 PARSE_ERROR((status == 0), section_name, entry->name);
668 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
669 (strcmp(entry->name, "b") == 0)) {
672 for (i = 0; i < APP_MAX_LINKS; i++) {
673 if (p->pci_blacklist[i])
676 p->pci_blacklist[i] =
677 strdup(entry->value);
678 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]);
709 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
710 section_name, entry->name,
711 "too many elements");
716 if (strcmp(entry->name, "vdev") == 0) {
719 for (i = 0; i < APP_MAX_LINKS; i++) {
723 p->vdev[i] = strdup(entry->value);
724 PARSE_ERROR_MALLOC(p->vdev[i]);
729 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
730 section_name, entry->name,
731 "too many elements");
736 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
739 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
742 p->vmware_tsc_map_present = 1;
744 val = parser_read_arg_bool(entry->value);
745 PARSE_ERROR((val >= 0), section_name, entry->name);
746 p->vmware_tsc_map = val;
751 if (strcmp(entry->name, "proc_type") == 0) {
752 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
755 p->proc_type = strdup(entry->value);
760 if (strcmp(entry->name, "syslog") == 0) {
761 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
764 p->syslog = strdup(entry->value);
769 if (strcmp(entry->name, "log_level") == 0) {
772 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
775 p->log_level_present = 1;
777 status = parser_read_uint32(&p->log_level,
779 PARSE_ERROR((status == 0), section_name, entry->name);
784 if (strcmp(entry->name, "v") == 0) {
787 PARSE_ERROR_DUPLICATE((p->version_present == 0),
790 p->version_present = 1;
792 val = parser_read_arg_bool(entry->value);
793 PARSE_ERROR((val >= 0), section_name, entry->name);
799 if ((strcmp(entry->name, "help") == 0) ||
800 (strcmp(entry->name, "h") == 0)) {
803 PARSE_ERROR_DUPLICATE((p->help_present == 0),
808 val = parser_read_arg_bool(entry->value);
809 PARSE_ERROR((val >= 0), section_name, entry->name);
815 if (strcmp(entry->name, "no_huge") == 0) {
818 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
821 p->no_huge_present = 1;
823 val = parser_read_arg_bool(entry->value);
824 PARSE_ERROR((val >= 0), section_name, entry->name);
830 if (strcmp(entry->name, "no_pci") == 0) {
833 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
836 p->no_pci_present = 1;
838 val = parser_read_arg_bool(entry->value);
839 PARSE_ERROR((val >= 0), section_name, entry->name);
845 if (strcmp(entry->name, "no_hpet") == 0) {
848 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
851 p->no_hpet_present = 1;
853 val = parser_read_arg_bool(entry->value);
854 PARSE_ERROR((val >= 0), section_name, entry->name);
860 if (strcmp(entry->name, "no_shconf") == 0) {
863 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
866 p->no_shconf_present = 1;
868 val = parser_read_arg_bool(entry->value);
869 PARSE_ERROR((val >= 0), section_name, entry->name);
875 if (strcmp(entry->name, "d") == 0) {
876 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
879 p->add_driver = strdup(entry->value);
884 if (strcmp(entry->name, "socket_mem") == 0) {
885 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
888 p->socket_mem = strdup(entry->value);
893 if (strcmp(entry->name, "huge_dir") == 0) {
894 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
897 p->huge_dir = strdup(entry->value);
902 if (strcmp(entry->name, "file_prefix") == 0) {
903 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
906 p->file_prefix = strdup(entry->value);
911 if (strcmp(entry->name, "base_virtaddr") == 0) {
912 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
915 p->base_virtaddr = strdup(entry->value);
920 if (strcmp(entry->name, "create_uio_dev") == 0) {
923 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
926 p->create_uio_dev_present = 1;
928 val = parser_read_arg_bool(entry->value);
929 PARSE_ERROR((val >= 0), section_name, entry->name);
930 p->create_uio_dev = val;
935 if (strcmp(entry->name, "vfio_intr") == 0) {
936 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
939 p->vfio_intr = strdup(entry->value);
944 if (strcmp(entry->name, "xen_dom0") == 0) {
947 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
950 p->xen_dom0_present = 1;
952 val = parser_read_arg_bool(entry->value);
953 PARSE_ERROR((val >= 0), section_name, entry->name);
959 PARSE_ERROR_INVALID(0, section_name, entry->name);
966 parse_pipeline_pcap_source(struct app_params *app,
967 struct app_pipeline_params *p,
968 const char *file_name, const char *cp_size)
970 const char *next = NULL;
975 if (file_name && !cp_size) {
977 parse_file = 1; /* parse file path */
978 } else if (cp_size && !file_name) {
980 parse_file = 0; /* parse copy size */
984 char name[APP_PARAM_NAME_SIZE];
987 if (p->n_pktq_in == 0)
991 while (*next != '\0') {
994 if (i >= p->n_pktq_in)
997 id = p->pktq_in[i].id;
999 end = strchr(next, ' ');
1001 name_len = strlen(next);
1003 name_len = end - next;
1005 if (name_len == 0 || name_len == sizeof(name))
1008 strncpy(name, next, name_len);
1009 name[name_len] = '\0';
1015 app->source_params[id].file_name = strdup(name);
1016 if (app->source_params[id].file_name == NULL)
1019 if (parser_read_uint32(
1020 &app->source_params[id].n_bytes_per_pkt,
1022 if (app->source_params[id].
1024 free(app->source_params[id].
1032 if (i == p->n_pktq_in)
1040 parse_pipeline_pcap_sink(struct app_params *app,
1041 struct app_pipeline_params *p,
1042 const char *file_name, const char *n_pkts_to_dump)
1044 const char *next = NULL;
1049 if (file_name && !n_pkts_to_dump) {
1051 parse_file = 1; /* parse file path */
1052 } else if (n_pkts_to_dump && !file_name) {
1053 next = n_pkts_to_dump;
1054 parse_file = 0; /* parse copy size */
1058 char name[APP_PARAM_NAME_SIZE];
1061 if (p->n_pktq_out == 0)
1065 while (*next != '\0') {
1068 if (i >= p->n_pktq_out)
1071 id = p->pktq_out[i].id;
1073 end = strchr(next, ' ');
1075 name_len = strlen(next);
1077 name_len = end - next;
1079 if (name_len == 0 || name_len == sizeof(name))
1082 strncpy(name, next, name_len);
1083 name[name_len] = '\0';
1089 app->sink_params[id].file_name = strdup(name);
1090 if (app->sink_params[id].file_name == NULL)
1093 if (parser_read_uint32(
1094 &app->sink_params[id].n_pkts_to_dump,
1096 if (app->sink_params[id].file_name !=
1098 free(app->sink_params[id].
1106 if (i == p->n_pktq_out)
1114 parse_pipeline_pktq_in(struct app_params *app,
1115 struct app_pipeline_params *p,
1118 const char *next = value;
1122 char name[APP_PARAM_NAME_SIZE];
1125 while (*next != '\0') {
1126 enum app_pktq_in_type type;
1131 next = skip_white_spaces(next);
1135 end_space = strchr(next, ' ');
1136 end_tab = strchr(next, ' ');
1138 if (end_space && (!end_tab))
1140 else if ((!end_space) && end_tab)
1142 else if (end_space && end_tab)
1143 end = RTE_MIN(end_space, end_tab);
1148 name_len = strlen(next);
1150 name_len = end - next;
1152 if (name_len == 0 || name_len == sizeof(name))
1155 strncpy(name, next, name_len);
1156 name[name_len] = '\0';
1161 if (validate_name(name, "RXQ", 2) == 0) {
1162 type = APP_PKTQ_IN_HWQ;
1163 id = APP_PARAM_ADD(app->hwq_in_params, name);
1164 } else if (validate_name(name, "SWQ", 1) == 0) {
1165 type = APP_PKTQ_IN_SWQ;
1166 id = APP_PARAM_ADD(app->swq_params, name);
1167 } else if (validate_name(name, "TM", 1) == 0) {
1168 type = APP_PKTQ_IN_TM;
1169 id = APP_PARAM_ADD(app->tm_params, name);
1170 } else if (validate_name(name, "SOURCE", 1) == 0) {
1171 type = APP_PKTQ_IN_SOURCE;
1172 id = APP_PARAM_ADD(app->source_params, name);
1179 p->pktq_in[p->n_pktq_in].type = type;
1180 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1188 parse_pipeline_pktq_out(struct app_params *app,
1189 struct app_pipeline_params *p,
1192 const char *next = value;
1196 char name[APP_PARAM_NAME_SIZE];
1199 while (*next != '\0') {
1200 enum app_pktq_out_type type;
1205 next = skip_white_spaces(next);
1209 end_space = strchr(next, ' ');
1210 end_tab = strchr(next, ' ');
1212 if (end_space && (!end_tab))
1214 else if ((!end_space) && end_tab)
1216 else if (end_space && end_tab)
1217 end = RTE_MIN(end_space, end_tab);
1222 name_len = strlen(next);
1224 name_len = end - next;
1226 if (name_len == 0 || name_len == sizeof(name))
1229 strncpy(name, next, name_len);
1230 name[name_len] = '\0';
1234 if (validate_name(name, "TXQ", 2) == 0) {
1235 type = APP_PKTQ_OUT_HWQ;
1236 id = APP_PARAM_ADD(app->hwq_out_params, name);
1237 } else if (validate_name(name, "SWQ", 1) == 0) {
1238 type = APP_PKTQ_OUT_SWQ;
1239 id = APP_PARAM_ADD(app->swq_params, name);
1240 } else if (validate_name(name, "TM", 1) == 0) {
1241 type = APP_PKTQ_OUT_TM;
1242 id = APP_PARAM_ADD(app->tm_params, name);
1243 } else if (validate_name(name, "SINK", 1) == 0) {
1244 type = APP_PKTQ_OUT_SINK;
1245 id = APP_PARAM_ADD(app->sink_params, name);
1252 p->pktq_out[p->n_pktq_out].type = type;
1253 p->pktq_out[p->n_pktq_out].id = id;
1261 parse_pipeline_msgq_in(struct app_params *app,
1262 struct app_pipeline_params *p,
1265 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;
1330 char name[APP_PARAM_NAME_SIZE];
1334 while (*next != '\0') {
1338 next = skip_white_spaces(next);
1342 end_space = strchr(next, ' ');
1343 end_tab = strchr(next, ' ');
1345 if (end_space && (!end_tab))
1347 else if ((!end_space) && end_tab)
1349 else if (end_space && end_tab)
1350 end = RTE_MIN(end_space, end_tab);
1355 name_len = strlen(next);
1357 name_len = end - next;
1359 if (name_len == 0 || name_len == sizeof(name))
1362 strncpy(name, next, name_len);
1363 name[name_len] = '\0';
1368 if (validate_name(name, "MSGQ", 1) != 0)
1371 idx = APP_PARAM_ADD(app->msgq_params, name);
1375 p->msgq_out[p->n_msgq_out] = idx;
1383 parse_pipeline(struct app_params *app,
1384 const char *section_name,
1385 struct rte_cfgfile *cfg)
1387 char name[CFG_NAME_LEN];
1388 struct app_pipeline_params *param;
1389 struct rte_cfgfile_entry *entries;
1393 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1394 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1396 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1397 PARSE_ERROR_MALLOC(entries != NULL);
1399 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1401 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1402 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1404 param = &app->pipeline_params[param_idx];
1406 for (i = 0; i < n_entries; i++) {
1407 struct rte_cfgfile_entry *ent = &entries[i];
1409 if (strcmp(ent->name, "type") == 0) {
1410 int w_size = snprintf(param->type, RTE_DIM(param->type),
1413 PARSE_ERROR(((w_size > 0) &&
1414 (w_size < (int)RTE_DIM(param->type))),
1420 if (strcmp(ent->name, "core") == 0) {
1421 int status = parse_pipeline_core(
1422 ¶m->socket_id, ¶m->core_id,
1423 ¶m->hyper_th_id, ent->value);
1425 PARSE_ERROR((status == 0), section_name,
1430 if (strcmp(ent->name, "pktq_in") == 0) {
1431 int status = parse_pipeline_pktq_in(app, param,
1434 PARSE_ERROR((status == 0), section_name,
1439 if (strcmp(ent->name, "pktq_out") == 0) {
1440 int status = parse_pipeline_pktq_out(app, param,
1443 PARSE_ERROR((status == 0), section_name,
1448 if (strcmp(ent->name, "msgq_in") == 0) {
1449 int status = parse_pipeline_msgq_in(app, param,
1452 PARSE_ERROR((status == 0), section_name,
1457 if (strcmp(ent->name, "msgq_out") == 0) {
1458 int status = parse_pipeline_msgq_out(app, param,
1461 PARSE_ERROR((status == 0), section_name,
1466 if (strcmp(ent->name, "timer_period") == 0) {
1467 int status = parser_read_uint32(
1468 ¶m->timer_period,
1471 PARSE_ERROR((status == 0), section_name,
1476 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1479 #ifndef RTE_PORT_PCAP
1480 PARSE_ERROR_INVALID(0, section_name, ent->name);
1483 status = parse_pipeline_pcap_source(app,
1484 param, ent->value, NULL);
1486 PARSE_ERROR((status == 0), section_name,
1491 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1494 #ifndef RTE_PORT_PCAP
1495 PARSE_ERROR_INVALID(0, section_name, ent->name);
1498 status = parse_pipeline_pcap_source(app,
1499 param, NULL, ent->value);
1501 PARSE_ERROR((status == 0), section_name,
1506 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1509 #ifndef RTE_PORT_PCAP
1510 PARSE_ERROR_INVALID(0, section_name, ent->name);
1513 status = parse_pipeline_pcap_sink(app, param,
1516 PARSE_ERROR((status == 0), section_name,
1521 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1524 #ifndef RTE_PORT_PCAP
1525 PARSE_ERROR_INVALID(0, section_name, ent->name);
1528 status = parse_pipeline_pcap_sink(app, param,
1531 PARSE_ERROR((status == 0), section_name,
1536 /* pipeline type specific items */
1537 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1538 "Parse error in section \"%s\": too many "
1539 "pipeline specified parameters", section_name);
1541 param->args_name[param->n_args] = strdup(ent->name);
1542 param->args_value[param->n_args] = strdup(ent->value);
1544 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1545 (param->args_value[param->n_args] != NULL),
1546 "Parse error: no free memory");
1553 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1554 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1555 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1556 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1557 param->msgq_in[param->n_msgq_in++] = param_idx;
1559 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1560 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1561 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1562 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1563 param->msgq_out[param->n_msgq_out++] = param_idx;
1565 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1568 (param->hyper_th_id) ? "h" : "");
1569 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1570 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1571 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1573 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1576 (param->hyper_th_id) ? "h" : "");
1577 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1578 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1579 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1585 parse_mempool(struct app_params *app,
1586 const char *section_name,
1587 struct rte_cfgfile *cfg)
1589 struct app_mempool_params *param;
1590 struct rte_cfgfile_entry *entries;
1594 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1595 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1597 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1598 PARSE_ERROR_MALLOC(entries != NULL);
1600 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1602 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1603 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1605 param = &app->mempool_params[param_idx];
1607 for (i = 0; i < n_entries; i++) {
1608 struct rte_cfgfile_entry *ent = &entries[i];
1610 if (strcmp(ent->name, "buffer_size") == 0) {
1611 int status = parser_read_uint32(
1612 ¶m->buffer_size, ent->value);
1614 PARSE_ERROR((status == 0), section_name,
1619 if (strcmp(ent->name, "pool_size") == 0) {
1620 int status = parser_read_uint32(
1621 ¶m->pool_size, ent->value);
1623 PARSE_ERROR((status == 0), section_name,
1628 if (strcmp(ent->name, "cache_size") == 0) {
1629 int status = parser_read_uint32(
1630 ¶m->cache_size, ent->value);
1632 PARSE_ERROR((status == 0), section_name,
1637 if (strcmp(ent->name, "cpu") == 0) {
1638 int status = parser_read_uint32(
1639 ¶m->cpu_socket_id, ent->value);
1641 PARSE_ERROR((status == 0), section_name,
1647 PARSE_ERROR_INVALID(0, section_name, ent->name);
1656 parse_link(struct app_params *app,
1657 const char *section_name,
1658 struct rte_cfgfile *cfg)
1660 struct app_link_params *param;
1661 struct rte_cfgfile_entry *entries;
1663 int pci_bdf_present = 0;
1666 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1667 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1669 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1670 PARSE_ERROR_MALLOC(entries != NULL);
1672 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1674 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1675 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1677 param = &app->link_params[param_idx];
1679 for (i = 0; i < n_entries; i++) {
1680 struct rte_cfgfile_entry *ent = &entries[i];
1682 if (strcmp(ent->name, "promisc") == 0) {
1683 int status = parser_read_arg_bool(ent->value);
1685 PARSE_ERROR((status != -EINVAL), section_name,
1687 param->promisc = status;
1691 if (strcmp(ent->name, "arp_q") == 0) {
1692 int status = parser_read_uint32(¶m->arp_q,
1695 PARSE_ERROR((status == 0), section_name,
1700 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1701 int status = parser_read_uint32(
1702 ¶m->tcp_syn_q, ent->value);
1704 PARSE_ERROR((status == 0), section_name, ent->name);
1708 if (strcmp(ent->name, "ip_local_q") == 0) {
1709 int status = parser_read_uint32(
1710 ¶m->ip_local_q, ent->value);
1712 PARSE_ERROR((status == 0), section_name,
1718 if (strcmp(ent->name, "tcp_local_q") == 0) {
1719 int status = parser_read_uint32(
1720 ¶m->tcp_local_q, ent->value);
1722 PARSE_ERROR((status == 0), section_name,
1727 if (strcmp(ent->name, "udp_local_q") == 0) {
1728 int status = parser_read_uint32(
1729 ¶m->udp_local_q, ent->value);
1731 PARSE_ERROR((status == 0), section_name,
1736 if (strcmp(ent->name, "sctp_local_q") == 0) {
1737 int status = parser_read_uint32(
1738 ¶m->sctp_local_q, ent->value);
1740 PARSE_ERROR((status == 0), section_name,
1745 if (strcmp(ent->name, "pci_bdf") == 0) {
1746 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1747 section_name, ent->name);
1749 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1751 pci_bdf_present = 1;
1756 PARSE_ERROR_INVALID(0, section_name, ent->name);
1759 /* Check for mandatory fields */
1761 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1762 section_name, "pci_bdf",
1763 "entry not allowed (port_mask is provided)");
1765 PARSE_ERROR_MESSAGE((pci_bdf_present),
1766 section_name, "pci_bdf",
1767 "this entry is mandatory (port_mask is not "
1776 parse_rxq(struct app_params *app,
1777 const char *section_name,
1778 struct rte_cfgfile *cfg)
1780 struct app_pktq_hwq_in_params *param;
1781 struct rte_cfgfile_entry *entries;
1785 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1786 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1788 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1789 PARSE_ERROR_MALLOC(entries != NULL);
1791 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1793 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1794 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1796 param = &app->hwq_in_params[param_idx];
1798 for (i = 0; i < n_entries; i++) {
1799 struct rte_cfgfile_entry *ent = &entries[i];
1801 if (strcmp(ent->name, "mempool") == 0) {
1802 int status = validate_name(ent->value,
1806 PARSE_ERROR((status == 0), section_name,
1808 idx = APP_PARAM_ADD(app->mempool_params,
1810 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1812 param->mempool_id = idx;
1816 if (strcmp(ent->name, "size") == 0) {
1817 int status = parser_read_uint32(¶m->size,
1820 PARSE_ERROR((status == 0), section_name,
1825 if (strcmp(ent->name, "burst") == 0) {
1826 int status = parser_read_uint32(¶m->burst,
1829 PARSE_ERROR((status == 0), section_name,
1835 PARSE_ERROR_INVALID(0, section_name, ent->name);
1844 parse_txq(struct app_params *app,
1845 const char *section_name,
1846 struct rte_cfgfile *cfg)
1848 struct app_pktq_hwq_out_params *param;
1849 struct rte_cfgfile_entry *entries;
1853 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1854 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1856 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1857 PARSE_ERROR_MALLOC(entries != NULL);
1859 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1861 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1862 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1864 param = &app->hwq_out_params[param_idx];
1866 for (i = 0; i < n_entries; i++) {
1867 struct rte_cfgfile_entry *ent = &entries[i];
1869 if (strcmp(ent->name, "size") == 0) {
1870 int status = parser_read_uint32(¶m->size,
1873 PARSE_ERROR((status == 0), section_name,
1878 if (strcmp(ent->name, "burst") == 0) {
1879 int status = parser_read_uint32(¶m->burst,
1882 PARSE_ERROR((status == 0), section_name,
1887 if (strcmp(ent->name, "dropless") == 0) {
1888 int status = parser_read_arg_bool(ent->value);
1891 PARSE_ERROR((status != -EINVAL), section_name,
1893 param->dropless = status;
1898 PARSE_ERROR_INVALID(0, section_name, ent->name);
1907 parse_swq(struct app_params *app,
1908 const char *section_name,
1909 struct rte_cfgfile *cfg)
1911 struct app_pktq_swq_params *param;
1912 struct rte_cfgfile_entry *entries;
1914 uint32_t mtu_present = 0;
1915 uint32_t metadata_size_present = 0;
1916 uint32_t mempool_direct_present = 0;
1917 uint32_t mempool_indirect_present = 0;
1921 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1922 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1924 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1925 PARSE_ERROR_MALLOC(entries != NULL);
1927 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1929 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1930 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1932 param = &app->swq_params[param_idx];
1934 for (i = 0; i < n_entries; i++) {
1935 struct rte_cfgfile_entry *ent = &entries[i];
1937 if (strcmp(ent->name, "size") == 0) {
1938 int status = parser_read_uint32(¶m->size,
1941 PARSE_ERROR((status == 0), section_name,
1946 if (strcmp(ent->name, "burst_read") == 0) {
1947 int status = parser_read_uint32(&
1948 param->burst_read, ent->value);
1950 PARSE_ERROR((status == 0), section_name,
1955 if (strcmp(ent->name, "burst_write") == 0) {
1956 int status = parser_read_uint32(
1957 ¶m->burst_write, ent->value);
1959 PARSE_ERROR((status == 0), section_name,
1964 if (strcmp(ent->name, "dropless") == 0) {
1965 int status = parser_read_arg_bool(ent->value);
1967 PARSE_ERROR((status != -EINVAL), section_name,
1969 param->dropless = status;
1973 if (strcmp(ent->name, "n_retries") == 0) {
1974 int status = parser_read_uint64(¶m->n_retries,
1977 PARSE_ERROR((status == 0), section_name,
1982 if (strcmp(ent->name, "cpu") == 0) {
1983 int status = parser_read_uint32(
1984 ¶m->cpu_socket_id, ent->value);
1986 PARSE_ERROR((status == 0), section_name, ent->name);
1990 if (strcmp(ent->name, "ipv4_frag") == 0) {
1991 int status = parser_read_arg_bool(ent->value);
1993 PARSE_ERROR((status != -EINVAL), section_name,
1996 param->ipv4_frag = status;
1997 if (param->mtu == 0)
2003 if (strcmp(ent->name, "ipv6_frag") == 0) {
2004 int status = parser_read_arg_bool(ent->value);
2006 PARSE_ERROR((status != -EINVAL), section_name,
2008 param->ipv6_frag = status;
2009 if (param->mtu == 0)
2014 if (strcmp(ent->name, "ipv4_ras") == 0) {
2015 int status = parser_read_arg_bool(ent->value);
2017 PARSE_ERROR((status != -EINVAL), section_name,
2019 param->ipv4_ras = status;
2023 if (strcmp(ent->name, "ipv6_ras") == 0) {
2024 int status = parser_read_arg_bool(ent->value);
2026 PARSE_ERROR((status != -EINVAL), section_name,
2028 param->ipv6_ras = status;
2032 if (strcmp(ent->name, "mtu") == 0) {
2033 int status = parser_read_uint32(¶m->mtu,
2036 PARSE_ERROR((status == 0), section_name,
2042 if (strcmp(ent->name, "metadata_size") == 0) {
2043 int status = parser_read_uint32(
2044 ¶m->metadata_size, ent->value);
2046 PARSE_ERROR((status == 0), section_name,
2048 metadata_size_present = 1;
2052 if (strcmp(ent->name, "mempool_direct") == 0) {
2053 int status = validate_name(ent->value,
2057 PARSE_ERROR((status == 0), section_name,
2060 idx = APP_PARAM_ADD(app->mempool_params,
2062 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2064 param->mempool_direct_id = idx;
2065 mempool_direct_present = 1;
2069 if (strcmp(ent->name, "mempool_indirect") == 0) {
2070 int status = validate_name(ent->value,
2074 PARSE_ERROR((status == 0), section_name,
2076 idx = APP_PARAM_ADD(app->mempool_params,
2078 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2080 param->mempool_indirect_id = idx;
2081 mempool_indirect_present = 1;
2086 PARSE_ERROR_INVALID(0, section_name, ent->name);
2089 APP_CHECK(((mtu_present) &&
2090 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2091 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2092 "is off, therefore entry \"mtu\" is not allowed",
2095 APP_CHECK(((metadata_size_present) &&
2096 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2097 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2098 "is off, therefore entry \"metadata_size\" is "
2099 "not allowed", section_name);
2101 APP_CHECK(((mempool_direct_present) &&
2102 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2103 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2104 "is off, therefore entry \"mempool_direct\" is "
2105 "not allowed", section_name);
2107 APP_CHECK(((mempool_indirect_present) &&
2108 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2109 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2110 "is off, therefore entry \"mempool_indirect\" is "
2111 "not allowed", section_name);
2119 parse_tm(struct app_params *app,
2120 const char *section_name,
2121 struct rte_cfgfile *cfg)
2123 struct app_pktq_tm_params *param;
2124 struct rte_cfgfile_entry *entries;
2128 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2129 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2131 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2132 PARSE_ERROR_MALLOC(entries != NULL);
2134 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2136 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2137 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2139 param = &app->tm_params[param_idx];
2141 for (i = 0; i < n_entries; i++) {
2142 struct rte_cfgfile_entry *ent = &entries[i];
2144 if (strcmp(ent->name, "cfg") == 0) {
2145 param->file_name = strdup(ent->value);
2146 PARSE_ERROR_MALLOC(param->file_name != NULL);
2150 if (strcmp(ent->name, "burst_read") == 0) {
2151 int status = parser_read_uint32(
2152 ¶m->burst_read, ent->value);
2154 PARSE_ERROR((status == 0), section_name,
2159 if (strcmp(ent->name, "burst_write") == 0) {
2160 int status = parser_read_uint32(
2161 ¶m->burst_write, ent->value);
2163 PARSE_ERROR((status == 0), section_name,
2169 PARSE_ERROR_INVALID(0, section_name, ent->name);
2178 parse_source(struct app_params *app,
2179 const char *section_name,
2180 struct rte_cfgfile *cfg)
2182 struct app_pktq_source_params *param;
2183 struct rte_cfgfile_entry *entries;
2186 uint32_t pcap_file_present = 0;
2187 uint32_t pcap_size_present = 0;
2189 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2190 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2192 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2193 PARSE_ERROR_MALLOC(entries != NULL);
2195 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2197 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2198 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2200 param = &app->source_params[param_idx];
2202 for (i = 0; i < n_entries; i++) {
2203 struct rte_cfgfile_entry *ent = &entries[i];
2205 if (strcmp(ent->name, "mempool") == 0) {
2206 int status = validate_name(ent->value,
2210 PARSE_ERROR((status == 0), section_name,
2212 idx = APP_PARAM_ADD(app->mempool_params,
2214 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2216 param->mempool_id = idx;
2220 if (strcmp(ent->name, "burst") == 0) {
2221 int status = parser_read_uint32(¶m->burst,
2224 PARSE_ERROR((status == 0), section_name,
2229 if (strcmp(ent->name, "pcap_file_rd")) {
2230 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2231 section_name, ent->name);
2233 param->file_name = strdup(ent->value);
2235 PARSE_ERROR_MALLOC(param->file_name != NULL);
2236 pcap_file_present = 1;
2241 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2244 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2245 section_name, ent->name);
2247 status = parser_read_uint32(
2248 ¶m->n_bytes_per_pkt, ent->value);
2250 PARSE_ERROR((status == 0), section_name,
2252 pcap_size_present = 1;
2258 PARSE_ERROR_INVALID(0, section_name, ent->name);
2267 parse_sink(struct app_params *app,
2268 const char *section_name,
2269 struct rte_cfgfile *cfg)
2271 struct app_pktq_sink_params *param;
2272 struct rte_cfgfile_entry *entries;
2275 uint32_t pcap_file_present = 0;
2276 uint32_t pcap_n_pkt_present = 0;
2278 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2279 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2281 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2282 PARSE_ERROR_MALLOC(entries != NULL);
2284 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2286 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2287 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2289 param = &app->sink_params[param_idx];
2291 for (i = 0; i < n_entries; i++) {
2292 struct rte_cfgfile_entry *ent = &entries[i];
2294 if (strcmp(ent->name, "pcap_file_wr")) {
2295 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2296 section_name, ent->name);
2298 param->file_name = strdup(ent->value);
2300 PARSE_ERROR_MALLOC((param->file_name != NULL));
2305 if (strcmp(ent->name, "pcap_n_pkt_wr")) {
2308 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2309 section_name, ent->name);
2311 status = parser_read_uint32(
2312 ¶m->n_pkts_to_dump, ent->value);
2314 PARSE_ERROR((status == 0), section_name,
2321 PARSE_ERROR_INVALID(0, section_name, ent->name);
2330 parse_msgq_req_pipeline(struct app_params *app,
2331 const char *section_name,
2332 struct rte_cfgfile *cfg)
2334 struct app_msgq_params *param;
2335 struct rte_cfgfile_entry *entries;
2339 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2340 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2342 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2343 PARSE_ERROR_MALLOC(entries != NULL);
2345 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2347 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2348 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2350 param = &app->msgq_params[param_idx];
2352 for (i = 0; i < n_entries; i++) {
2353 struct rte_cfgfile_entry *ent = &entries[i];
2355 if (strcmp(ent->name, "size") == 0) {
2356 int status = parser_read_uint32(¶m->size,
2359 PARSE_ERROR((status == 0), section_name,
2365 PARSE_ERROR_INVALID(0, section_name, ent->name);
2373 parse_msgq_rsp_pipeline(struct app_params *app,
2374 const char *section_name,
2375 struct rte_cfgfile *cfg)
2377 struct app_msgq_params *param;
2378 struct rte_cfgfile_entry *entries;
2382 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2383 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2385 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2386 PARSE_ERROR_MALLOC(entries != NULL);
2388 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2390 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2391 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2393 param = &app->msgq_params[param_idx];
2395 for (i = 0; i < n_entries; i++) {
2396 struct rte_cfgfile_entry *ent = &entries[i];
2398 if (strcmp(ent->name, "size") == 0) {
2399 int status = parser_read_uint32(¶m->size,
2402 PARSE_ERROR((status == 0), section_name,
2408 PARSE_ERROR_INVALID(0, section_name, ent->name);
2417 parse_msgq(struct app_params *app,
2418 const char *section_name,
2419 struct rte_cfgfile *cfg)
2421 struct app_msgq_params *param;
2422 struct rte_cfgfile_entry *entries;
2426 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2427 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2429 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2430 PARSE_ERROR_MALLOC(entries != NULL);
2432 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2434 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2435 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2437 param = &app->msgq_params[param_idx];
2439 for (i = 0; i < n_entries; i++) {
2440 struct rte_cfgfile_entry *ent = &entries[i];
2442 if (strcmp(ent->name, "size") == 0) {
2443 int status = parser_read_uint32(¶m->size,
2446 PARSE_ERROR((status == 0), section_name,
2451 if (strcmp(ent->name, "cpu") == 0) {
2452 int status = parser_read_uint32(
2453 ¶m->cpu_socket_id, ent->value);
2455 PARSE_ERROR((status == 0), section_name,
2461 PARSE_ERROR_INVALID(0, section_name, ent->name);
2469 typedef void (*config_section_load)(struct app_params *p,
2470 const char *section_name,
2471 struct rte_cfgfile *cfg);
2473 struct config_section {
2474 const char prefix[CFG_NAME_LEN];
2476 config_section_load load;
2479 static const struct config_section cfg_file_scheme[] = {
2480 {"EAL", 0, parse_eal},
2481 {"PIPELINE", 1, parse_pipeline},
2482 {"MEMPOOL", 1, parse_mempool},
2483 {"LINK", 1, parse_link},
2484 {"RXQ", 2, parse_rxq},
2485 {"TXQ", 2, parse_txq},
2486 {"SWQ", 1, parse_swq},
2487 {"TM", 1, parse_tm},
2488 {"SOURCE", 1, parse_source},
2489 {"SINK", 1, parse_sink},
2490 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2491 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2492 {"MSGQ", 1, parse_msgq},
2496 create_implicit_mempools(struct app_params *app)
2500 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2501 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2505 create_implicit_links_from_port_mask(struct app_params *app,
2508 uint32_t pmd_id, link_id;
2511 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2512 char name[APP_PARAM_NAME_SIZE];
2515 if ((port_mask & (1LLU << pmd_id)) == 0)
2518 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2519 idx = APP_PARAM_ADD(app->link_params, name);
2520 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2522 app->link_params[idx].pmd_id = pmd_id;
2528 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2532 for (i = 0; i < app->n_links; i++) {
2533 struct app_link_params *link = &app->link_params[i];
2540 app_config_parse(struct app_params *app, const char *file_name)
2542 struct rte_cfgfile *cfg;
2543 char **section_names;
2544 int i, j, sect_count;
2546 /* Implicit mempools */
2547 create_implicit_mempools(app);
2551 create_implicit_links_from_port_mask(app, app->port_mask);
2553 /* Load application configuration file */
2554 cfg = rte_cfgfile_load(file_name, 0);
2555 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2556 "file %s", file_name);
2558 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2559 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2560 "in file \"%s\" return %d", file_name,
2563 section_names = malloc(sect_count * sizeof(char *));
2564 PARSE_ERROR_MALLOC(section_names != NULL);
2566 for (i = 0; i < sect_count; i++)
2567 section_names[i] = malloc(CFG_NAME_LEN);
2569 rte_cfgfile_sections(cfg, section_names, sect_count);
2571 for (i = 0; i < sect_count; i++) {
2572 const struct config_section *sch_s;
2573 int len, cfg_name_len;
2575 cfg_name_len = strlen(section_names[i]);
2577 /* Find section type */
2578 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2579 sch_s = &cfg_file_scheme[j];
2580 len = strlen(sch_s->prefix);
2582 if (cfg_name_len < len)
2585 /* After section name we expect only '\0' or digit or
2586 * digit dot digit, so protect against false matching,
2587 * for example: "ABC" should match section name
2588 * "ABC0.0", but it should not match section_name
2591 if ((section_names[i][len] != '\0') &&
2592 !isdigit(section_names[i][len]))
2595 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2599 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2600 "Parse error: unknown section %s",
2603 APP_CHECK(validate_name(section_names[i],
2605 sch_s->numbers) == 0,
2606 "Parse error: invalid section name \"%s\"",
2609 sch_s->load(app, section_names[i], cfg);
2612 for (i = 0; i < sect_count; i++)
2613 free(section_names[i]);
2615 free(section_names);
2617 rte_cfgfile_close(cfg);
2619 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2620 APP_PARAM_COUNT(app->link_params, app->n_links);
2621 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2622 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2623 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2624 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2625 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2626 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2627 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2628 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2630 #ifdef RTE_PORT_PCAP
2631 for (i = 0; i < (int)app->n_pktq_source; i++) {
2632 struct app_pktq_source_params *p = &app->source_params[i];
2634 APP_CHECK((p->file_name), "Parse error: missing "
2635 "mandatory field \"pcap_file_rd\" for \"%s\"",
2639 for (i = 0; i < (int)app->n_pktq_source; i++) {
2640 struct app_pktq_source_params *p = &app->source_params[i];
2642 APP_CHECK((!p->file_name), "Parse error: invalid field "
2643 "\"pcap_file_rd\" for \"%s\"", p->name);
2647 if (app->port_mask == 0)
2648 assign_link_pmd_id_from_pci_bdf(app);
2650 /* Save configuration to output file */
2651 app_config_save(app, app->output_file);
2653 /* Load TM configuration files */
2654 app_config_parse_tm(app);
2660 save_eal_params(struct app_params *app, FILE *f)
2662 struct app_eal_params *p = &app->eal_params;
2665 fprintf(f, "[EAL]\n");
2668 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2670 if (p->master_lcore_present)
2671 fprintf(f, "%s = %" PRIu32 "\n",
2672 "master_lcore", p->master_lcore);
2674 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2676 if (p->memory_present)
2677 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2679 if (p->ranks_present)
2680 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2682 for (i = 0; i < APP_MAX_LINKS; i++) {
2683 if (p->pci_blacklist[i] == NULL)
2686 fprintf(f, "%s = %s\n", "pci_blacklist",
2687 p->pci_blacklist[i]);
2690 for (i = 0; i < APP_MAX_LINKS; i++) {
2691 if (p->pci_whitelist[i] == NULL)
2694 fprintf(f, "%s = %s\n", "pci_whitelist",
2695 p->pci_whitelist[i]);
2698 for (i = 0; i < APP_MAX_LINKS; i++) {
2699 if (p->vdev[i] == NULL)
2702 fprintf(f, "%s = %s\n", "vdev",
2706 if (p->vmware_tsc_map_present)
2707 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2708 (p->vmware_tsc_map) ? "yes" : "no");
2711 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2714 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2716 if (p->log_level_present)
2717 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2719 if (p->version_present)
2720 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2722 if (p->help_present)
2723 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2725 if (p->no_huge_present)
2726 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2728 if (p->no_pci_present)
2729 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2731 if (p->no_hpet_present)
2732 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2734 if (p->no_shconf_present)
2735 fprintf(f, "%s = %s\n", "no_shconf",
2736 (p->no_shconf) ? "yes" : "no");
2739 fprintf(f, "%s = %s\n", "d", p->add_driver);
2742 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2745 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2748 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2750 if (p->base_virtaddr)
2751 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2753 if (p->create_uio_dev_present)
2754 fprintf(f, "%s = %s\n", "create_uio_dev",
2755 (p->create_uio_dev) ? "yes" : "no");
2758 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2760 if (p->xen_dom0_present)
2761 fprintf(f, "%s = %s\n", "xen_dom0",
2762 (p->xen_dom0) ? "yes" : "no");
2768 save_mempool_params(struct app_params *app, FILE *f)
2770 struct app_mempool_params *p;
2773 count = RTE_DIM(app->mempool_params);
2774 for (i = 0; i < count; i++) {
2775 p = &app->mempool_params[i];
2776 if (!APP_PARAM_VALID(p))
2779 fprintf(f, "[%s]\n", p->name);
2780 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2781 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2782 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2783 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2790 save_links_params(struct app_params *app, FILE *f)
2792 struct app_link_params *p;
2795 count = RTE_DIM(app->link_params);
2796 for (i = 0; i < count; i++) {
2797 p = &app->link_params[i];
2798 if (!APP_PARAM_VALID(p))
2801 fprintf(f, "[%s]\n", p->name);
2802 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2803 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2804 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2805 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2807 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2808 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2809 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2810 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2813 if (strlen(p->pci_bdf))
2814 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2821 save_rxq_params(struct app_params *app, FILE *f)
2823 struct app_pktq_hwq_in_params *p;
2826 count = RTE_DIM(app->hwq_in_params);
2827 for (i = 0; i < count; i++) {
2828 p = &app->hwq_in_params[i];
2829 if (!APP_PARAM_VALID(p))
2832 fprintf(f, "[%s]\n", p->name);
2833 fprintf(f, "%s = %s\n",
2835 app->mempool_params[p->mempool_id].name);
2836 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2837 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2844 save_txq_params(struct app_params *app, FILE *f)
2846 struct app_pktq_hwq_out_params *p;
2849 count = RTE_DIM(app->hwq_out_params);
2850 for (i = 0; i < count; i++) {
2851 p = &app->hwq_out_params[i];
2852 if (!APP_PARAM_VALID(p))
2855 fprintf(f, "[%s]\n", p->name);
2856 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2857 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2858 fprintf(f, "%s = %s\n",
2860 p->dropless ? "yes" : "no");
2867 save_swq_params(struct app_params *app, FILE *f)
2869 struct app_pktq_swq_params *p;
2872 count = RTE_DIM(app->swq_params);
2873 for (i = 0; i < count; i++) {
2874 p = &app->swq_params[i];
2875 if (!APP_PARAM_VALID(p))
2878 fprintf(f, "[%s]\n", p->name);
2879 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2880 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2881 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2882 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2883 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2884 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2885 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2886 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2887 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2888 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2889 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2890 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2891 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2892 fprintf(f, "%s = %s\n",
2894 app->mempool_params[p->mempool_direct_id].name);
2895 fprintf(f, "%s = %s\n",
2897 app->mempool_params[p->mempool_indirect_id].name);
2905 save_tm_params(struct app_params *app, FILE *f)
2907 struct app_pktq_tm_params *p;
2910 count = RTE_DIM(app->tm_params);
2911 for (i = 0; i < count; i++) {
2912 p = &app->tm_params[i];
2913 if (!APP_PARAM_VALID(p))
2916 fprintf(f, "[%s]\n", p->name);
2917 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2918 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2919 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2926 save_source_params(struct app_params *app, FILE *f)
2928 struct app_pktq_source_params *p;
2931 count = RTE_DIM(app->source_params);
2932 for (i = 0; i < count; i++) {
2933 p = &app->source_params[i];
2934 if (!APP_PARAM_VALID(p))
2937 fprintf(f, "[%s]\n", p->name);
2938 fprintf(f, "%s = %s\n",
2940 app->mempool_params[p->mempool_id].name);
2941 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2942 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2943 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2944 p->n_bytes_per_pkt);
2950 save_sink_params(struct app_params *app, FILE *f)
2952 struct app_pktq_sink_params *p;
2955 count = RTE_DIM(app->sink_params);
2956 for (i = 0; i < count; i++) {
2957 p = &app->sink_params[i];
2958 if (!APP_PARAM_VALID(p))
2961 fprintf(f, "[%s]\n", p->name);
2962 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2963 fprintf(f, "%s = %" PRIu32 "\n",
2964 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2970 save_msgq_params(struct app_params *app, FILE *f)
2972 struct app_msgq_params *p;
2975 count = RTE_DIM(app->msgq_params);
2976 for (i = 0; i < count; i++) {
2977 p = &app->msgq_params[i];
2978 if (!APP_PARAM_VALID(p))
2981 fprintf(f, "[%s]\n", p->name);
2982 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2983 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2990 save_pipeline_params(struct app_params *app, FILE *f)
2994 count = RTE_DIM(app->pipeline_params);
2995 for (i = 0; i < count; i++) {
2996 struct app_pipeline_params *p = &app->pipeline_params[i];
2998 if (!APP_PARAM_VALID(p))
3002 fprintf(f, "[%s]\n", p->name);
3005 fprintf(f, "type = %s\n", p->type);
3008 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
3011 (p->hyper_th_id) ? "h" : "");
3017 fprintf(f, "pktq_in =");
3018 for (j = 0; j < p->n_pktq_in; j++) {
3019 struct app_pktq_in_params *pp = &p->pktq_in[j];
3023 case APP_PKTQ_IN_HWQ:
3024 name = app->hwq_in_params[pp->id].name;
3026 case APP_PKTQ_IN_SWQ:
3027 name = app->swq_params[pp->id].name;
3029 case APP_PKTQ_IN_TM:
3030 name = app->tm_params[pp->id].name;
3032 case APP_PKTQ_IN_SOURCE:
3033 name = app->source_params[pp->id].name;
3036 APP_CHECK(0, "System error "
3037 "occurred while saving "
3038 "parameter to file");
3041 fprintf(f, " %s", name);
3047 if (p->n_pktq_out) {
3050 fprintf(f, "pktq_out =");
3051 for (j = 0; j < p->n_pktq_out; j++) {
3052 struct app_pktq_out_params *pp =
3057 case APP_PKTQ_OUT_HWQ:
3058 name = app->hwq_out_params[pp->id].name;
3060 case APP_PKTQ_OUT_SWQ:
3061 name = app->swq_params[pp->id].name;
3063 case APP_PKTQ_OUT_TM:
3064 name = app->tm_params[pp->id].name;
3066 case APP_PKTQ_OUT_SINK:
3067 name = app->sink_params[pp->id].name;
3070 APP_CHECK(0, "System error "
3071 "occurred while saving "
3072 "parameter to file");
3075 fprintf(f, " %s", name);
3084 fprintf(f, "msgq_in =");
3085 for (j = 0; j < p->n_msgq_in; j++) {
3086 uint32_t id = p->msgq_in[j];
3087 char *name = app->msgq_params[id].name;
3089 fprintf(f, " %s", name);
3095 if (p->n_msgq_out) {
3098 fprintf(f, "msgq_out =");
3099 for (j = 0; j < p->n_msgq_out; j++) {
3100 uint32_t id = p->msgq_out[j];
3101 char *name = app->msgq_params[id].name;
3103 fprintf(f, " %s", name);
3109 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3115 for (j = 0; j < p->n_args; j++)
3116 fprintf(f, "%s = %s\n", p->args_name[j],
3125 app_config_save(struct app_params *app, const char *file_name)
3128 char *name, *dir_name;
3131 name = strdup(file_name);
3132 dir_name = dirname(name);
3133 status = access(dir_name, W_OK);
3134 APP_CHECK((status == 0),
3135 "Error: need write access privilege to directory "
3136 "\"%s\" to save configuration\n", dir_name);
3138 file = fopen(file_name, "w");
3139 APP_CHECK((file != NULL),
3140 "Error: failed to save configuration to file \"%s\"",
3143 save_eal_params(app, file);
3144 save_pipeline_params(app, file);
3145 save_mempool_params(app, file);
3146 save_links_params(app, file);
3147 save_rxq_params(app, file);
3148 save_txq_params(app, file);
3149 save_swq_params(app, file);
3150 save_tm_params(app, file);
3151 save_source_params(app, file);
3152 save_sink_params(app, file);
3153 save_msgq_params(app, file);
3160 app_config_init(struct app_params *app)
3164 memcpy(app, &app_params_default, sizeof(struct app_params));
3166 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3167 memcpy(&app->mempool_params[i],
3168 &mempool_params_default,
3169 sizeof(struct app_mempool_params));
3171 for (i = 0; i < RTE_DIM(app->link_params); i++)
3172 memcpy(&app->link_params[i],
3173 &link_params_default,
3174 sizeof(struct app_link_params));
3176 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3177 memcpy(&app->hwq_in_params[i],
3178 &default_hwq_in_params,
3179 sizeof(default_hwq_in_params));
3181 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3182 memcpy(&app->hwq_out_params[i],
3183 &default_hwq_out_params,
3184 sizeof(default_hwq_out_params));
3186 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3187 memcpy(&app->swq_params[i],
3188 &default_swq_params,
3189 sizeof(default_swq_params));
3191 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3192 memcpy(&app->tm_params[i],
3194 sizeof(default_tm_params));
3196 for (i = 0; i < RTE_DIM(app->source_params); i++)
3197 memcpy(&app->source_params[i],
3198 &default_source_params,
3199 sizeof(default_source_params));
3201 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3202 memcpy(&app->sink_params[i],
3203 &default_sink_params,
3204 sizeof(default_sink_params));
3206 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3207 memcpy(&app->msgq_params[i],
3208 &default_msgq_params,
3209 sizeof(default_msgq_params));
3211 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3212 memcpy(&app->pipeline_params[i],
3213 &default_pipeline_params,
3214 sizeof(default_pipeline_params));
3220 filenamedup(const char *filename, const char *suffix)
3222 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3227 sprintf(s, "%s%s", filename, suffix);
3232 app_config_args(struct app_params *app, int argc, char **argv)
3234 const char *optname;
3235 int opt, option_index;
3236 int f_present, s_present, p_present, l_present, v_present;
3237 int preproc_present, preproc_params_present, disable_csum_present;
3239 int flow_dir_present;
3242 static struct option lgopts[] = {
3243 { "disable-hw-csum", 0, 0, 0 },
3244 { "preproc", 1, 0, 0 },
3245 { "preproc-args", 1, 0, 0 },
3246 { "hwlb", 1, 0, 0 },
3247 { "flow_dir", 0, 0, 0 },
3248 { "version", 0, 0, 0 },
3252 /* Copy application name */
3253 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3260 disable_csum_present = 0;
3261 preproc_present = 0;
3262 preproc_params_present = 0;
3263 app->header_csum_req =1; //Default enable haeader checksum
3265 flow_dir_present = 0;
3268 while ((opt = getopt_long(argc, argv, "f:v:s:p:l:", lgopts,
3269 &option_index)) != EOF)
3273 rte_panic("Error: Config file is provided "
3274 "more than once\n");
3277 /* REST API not needed as user has supplied the config file */
3280 if (!strlen(optarg))
3281 rte_panic("Error: Config file name is null\n");
3283 app->config_file = strdup(optarg);
3284 if (app->config_file == NULL)
3285 rte_panic("Error: Memory allocation failure\n");
3292 rte_panic("Error: Script file is provided "
3293 "more than once\n");
3296 if (!strlen(optarg))
3297 rte_panic("Error: Script file name is null\n");
3299 app->script_file = strdup(optarg);
3300 if (app->script_file == NULL)
3301 rte_panic("Error: Memory allocation failure\n");
3307 rte_panic("Error: PORT_MASK is provided "
3308 "more than once\n");
3311 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3313 ((size_t) scaned != strlen(optarg)))
3314 rte_panic("Error: PORT_MASK is not "
3315 "a hexadecimal integer\n");
3317 if (app->port_mask == 0)
3318 rte_panic("Error: PORT_MASK is null\n");
3324 rte_panic("Error: LOG_LEVEL is provided "
3325 "more than once\n");
3328 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3330 ((size_t) scaned != strlen(optarg)) ||
3331 (app->log_level >= APP_LOG_LEVELS))
3332 rte_panic("Error: LOG_LEVEL invalid value\n");
3337 optname = lgopts[option_index].name;
3339 if (strcmp(optname, "version") == 0) {
3341 rte_panic("Error: VERSION is provided "
3342 "more than once\n");
3344 printf("Version: %s\n", VERSION_STR);
3348 if (strcmp(optname, "hwlb") == 0) {
3350 rte_panic("Error: hwlb argument "
3351 "is provided more than once\n");
3353 printf(" HWLB is configured\n");
3355 app->n_hwlb_q = atoi(optarg);
3358 rte_panic("HWQs for HWLB must be atleast 1\n");
3360 printf("No of HWQs for HWLB are %d\n",app->n_hwlb_q);
3365 if (strcmp(optname, "flow_dir") == 0) {
3366 if (flow_dir_present)
3367 rte_panic("Error: flow_dir argument "
3368 "is provided more than once\n");
3369 flow_dir_present = 1;
3370 printf(" FLOW DIR is configured\n");
3372 enable_flow_dir = 1;
3377 if (strcmp(optname, "disable-hw-csum") == 0) {
3378 if (disable_csum_present)
3379 rte_panic("Error: disable-hw-csum argument "
3380 "is provided more than once\n");
3382 printf("Disable TCP/UDP HW checksumi\n");
3383 app->header_csum_req = 0;
3384 disable_csum_present = 1;
3388 if (strcmp(optname, "preproc") == 0) {
3389 if (preproc_present)
3390 rte_panic("Error: Preprocessor argument "
3391 "is provided more than once\n");
3392 preproc_present = 1;
3394 app->preproc = strdup(optarg);
3398 if (strcmp(optname, "preproc-args") == 0) {
3399 if (preproc_params_present)
3400 rte_panic("Error: Preprocessor args "
3401 "are provided more than once\n");
3402 preproc_params_present = 1;
3404 app->preproc_args = strdup(optarg);
3408 app_print_usage(argv[0]);
3412 app_print_usage(argv[0]);
3415 optind = 0; /* reset getopt lib */
3417 /* Check dependencies between args */
3418 if (preproc_params_present && (preproc_present == 0))
3419 rte_panic("Error: Preprocessor args specified while "
3420 "preprocessor is not defined\n");
3422 app->parser_file = preproc_present ?
3423 filenamedup(app->config_file, ".preproc") :
3424 strdup(app->config_file);
3425 app->output_file = filenamedup(app->config_file, ".out");
3431 app_config_preproc(struct app_params *app)
3436 if (app->preproc == NULL)
3439 status = access(app->config_file, F_OK | R_OK);
3440 APP_CHECK((status == 0), "Error: Unable to open file %s",
3443 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3445 app->preproc_args ? app->preproc_args : "",
3449 status = system(buffer);
3450 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3451 "Error occurred while pre-processing file \"%s\"\n",