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>
36 * Default config values
39 static struct app_params app_params_default = {
40 .config_file = "./config/ip_pipeline.cfg",
41 .log_level = APP_LOG_LEVEL_HIGH,
49 static const struct app_mempool_params mempool_params_default = {
51 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
52 .pool_size = 32 * 1024,
57 static const struct app_link_params link_params_default = {
68 .ipv6 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
77 .mq_mode = ETH_MQ_RX_NONE,
79 .header_split = 0, /* Header split */
80 .hw_ip_checksum = 0, /* IP checksum offload */
81 .hw_vlan_filter = 0, /* VLAN filtering */
82 .hw_vlan_strip = 0, /* VLAN strip */
83 .hw_vlan_extend = 0, /* Extended VLAN */
84 .jumbo_frame = 0, /* Jumbo frame support */
85 .hw_strip_crc = 0, /* CRC strip by HW */
86 .enable_scatter = 0, /* Scattered packets RX handler */
88 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
89 .split_hdr_size = 0, /* Header split buffer size */
92 .mq_mode = ETH_MQ_TX_NONE,
97 .lsc = 1, /**< lsc interrupt feature enabled */
105 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
117 .rx_free_thresh = 64,
119 .rx_deferred_start = 0,
123 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
138 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
139 ETH_TXQ_FLAGS_NOOFFLOADS,
140 .tx_deferred_start = 0,
144 static const struct app_pktq_swq_params default_swq_params = {
158 .mempool_direct_id = 0,
159 .mempool_indirect_id = 0,
162 struct app_pktq_tm_params default_tm_params = {
164 .file_name = "./config/tm_profile.cfg",
169 struct app_pktq_source_params default_source_params = {
174 .n_bytes_per_pkt = 0,
177 struct app_pktq_sink_params default_sink_params = {
183 struct app_msgq_params default_msgq_params = {
189 struct app_pipeline_params default_pipeline_params = {
202 static const char app_usage[] =
203 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
204 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
207 "\t-f CONFIG_FILE: Default config file is %s\n"
208 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
209 "config file when not provided)\n"
210 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
211 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
212 "\t--disable-hw-csum Disable TCP/UDP HW checksum\n"
213 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
214 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
218 app_print_usage(char *prgname)
220 rte_exit(0, app_usage, prgname, app_params_default.config_file);
223 #define skip_white_spaces(pos) \
225 __typeof__(pos) _p = (pos); \
226 for ( ; isspace(*_p); _p++); \
230 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
232 APP_CHECK((result != -EINVAL), \
233 "Parse error: no free memory"); \
234 APP_CHECK((result != -ENOMEM), \
235 "Parse error: too many \"%s\" sections", section_name); \
236 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
237 "Parse error: duplicate \"%s\" section", section_name); \
238 APP_CHECK((result >= 0), \
239 "Parse error in section \"%s\"", section_name); \
243 parser_read_arg_bool(const char *p)
245 p = skip_white_spaces(p);
246 int result = -EINVAL;
248 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
249 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
254 if (((p[0] == 'o') && (p[1] == 'n')) ||
255 ((p[0] == 'O') && (p[1] == 'N'))) {
260 if (((p[0] == 'n') && (p[1] == 'o')) ||
261 ((p[0] == 'N') && (p[1] == 'O'))) {
266 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
267 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
272 p = skip_white_spaces(p);
280 #define PARSE_ERROR(exp, section, entry) \
281 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
283 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
284 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n", \
285 section, entry, message)
288 #define PARSE_ERROR_MALLOC(exp) \
289 APP_CHECK(exp, "Parse error: no free memory\n")
291 #define PARSE_ERROR_SECTION(exp, section) \
292 APP_CHECK(exp, "Parse error in section \"%s\"", section)
294 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
295 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
297 #define PARSE_WARNING_IGNORED(exp, section, entry) \
300 fprintf(stderr, "Parse warning in section \"%s\": " \
301 "entry \"%s\" is ignored\n", section, entry); \
304 #define PARSE_ERROR_INVALID(exp, section, entry) \
305 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
308 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
309 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
313 parser_read_uint64(uint64_t *value, const char *p)
318 p = skip_white_spaces(p);
322 val = strtoul(p, &next, 10);
344 p = skip_white_spaces(p);
353 parser_read_uint32(uint32_t *value, const char *p)
356 int ret = parser_read_uint64(&val, p);
361 if (val > UINT32_MAX)
369 parse_pipeline_core(uint32_t *socket,
377 uint32_t s = 0, c = 0, h = 0, val;
378 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
379 const char *next = skip_white_spaces(entry);
382 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
383 while (*next != '\0') {
384 /* If everything parsed nothing should left */
385 if (s_parsed && c_parsed && h_parsed)
392 if (s_parsed || c_parsed || h_parsed)
399 if (c_parsed || h_parsed)
412 /* If it start from digit it must be only core id. */
413 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
419 for (num_len = 0; *next != '\0'; next++, num_len++) {
420 if (num_len == RTE_DIM(num))
426 num[num_len] = *next;
429 if (num_len == 0 && type != 'h' && type != 'H')
432 if (num_len != 0 && (type == 'h' || type == 'H'))
434 if(num_len < sizeof(num))
436 val = strtol(num, NULL, 10);
465 case '0': case '1': case '2': case '3': case '4': case '5':
466 case '6': case '7': case '8': case '9':
468 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
470 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
478 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
483 /* Check input parameters */
491 if (((len & 3) != 0) ||
496 for (c = src; *c != 0; c++) {
497 if ((((*c) >= '0') && ((*c) <= '9')) ||
498 (((*c) >= 'A') && ((*c) <= 'F')) ||
499 (((*c) >= 'a') && ((*c) <= 'f')))
505 /* Convert chars to bytes */
506 for (i = 0; i < *size; i++)
507 dst[i] = get_hex_val(src[2 * i]) * 16 +
508 get_hex_val(src[2 * i + 1]);
514 skip_digits(const char *src)
518 for (i = 0; isdigit(src[i]); i++);
524 validate_name(const char *name, const char *prefix, int num)
528 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
529 if (name[i] != prefix[i])
533 if (prefix[i] != '\0')
544 j = skip_digits(&name[i]);
546 if ((j == 0) || (name[i] != '.'))
552 j = skip_digits(&name[i]);
554 if ((j == 0) || (name[i] != '\0'))
562 parse_eal(struct app_params *app,
563 const char *section_name,
564 struct rte_cfgfile *cfg)
566 struct app_eal_params *p = &app->eal_params;
567 struct rte_cfgfile_entry *entries;
570 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
571 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
573 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
574 PARSE_ERROR_MALLOC(entries != NULL);
576 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
578 for (i = 0; i < n_entries; i++) {
579 struct rte_cfgfile_entry *entry = &entries[i];
582 if (strcmp(entry->name, "c") == 0) {
583 PARSE_WARNING_IGNORED(0, section_name, entry->name);
588 if (strcmp(entry->name, "l") == 0) {
589 PARSE_WARNING_IGNORED(0, section_name, entry->name);
594 if (strcmp(entry->name, "lcores") == 0) {
595 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
598 p->coremap = strdup(entry->value);
603 if (strcmp(entry->name, "master_lcore") == 0) {
606 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
609 p->master_lcore_present = 1;
611 status = parser_read_uint32(&p->master_lcore,
613 PARSE_ERROR((status == 0), section_name, entry->name);
618 if (strcmp(entry->name, "n") == 0) {
621 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
624 p->channels_present = 1;
626 status = parser_read_uint32(&p->channels, entry->value);
627 PARSE_ERROR((status == 0), section_name, entry->name);
632 if (strcmp(entry->name, "m") == 0) {
635 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
638 p->memory_present = 1;
640 status = parser_read_uint32(&p->memory, entry->value);
641 PARSE_ERROR((status == 0), section_name, entry->name);
646 if (strcmp(entry->name, "r") == 0) {
649 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
652 p->ranks_present = 1;
654 status = parser_read_uint32(&p->ranks, entry->value);
655 PARSE_ERROR((status == 0), section_name, entry->name);
660 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
661 (strcmp(entry->name, "b") == 0)) {
664 for (i = 0; i < APP_MAX_LINKS; i++) {
665 if (p->pci_blacklist[i])
668 p->pci_blacklist[i] =
669 strdup(entry->value);
670 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
675 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
676 section_name, entry->name,
677 "too many elements");
682 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
683 (strcmp(entry->name, "w") == 0)) {
686 PARSE_ERROR_MESSAGE((app->port_mask != 0),
687 section_name, entry->name, "entry to be "
688 "generated by the application (port_mask "
691 for (i = 0; i < APP_MAX_LINKS; i++) {
692 if (p->pci_whitelist[i])
695 p->pci_whitelist[i] = strdup(entry->value);
696 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
701 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
702 section_name, entry->name,
703 "too many elements");
708 if (strcmp(entry->name, "vdev") == 0) {
711 for (i = 0; i < APP_MAX_LINKS; i++) {
715 p->vdev[i] = strdup(entry->value);
716 PARSE_ERROR_MALLOC(p->vdev[i]);
721 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
722 section_name, entry->name,
723 "too many elements");
728 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
731 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
734 p->vmware_tsc_map_present = 1;
736 val = parser_read_arg_bool(entry->value);
737 PARSE_ERROR((val >= 0), section_name, entry->name);
738 p->vmware_tsc_map = val;
743 if (strcmp(entry->name, "proc_type") == 0) {
744 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
747 p->proc_type = strdup(entry->value);
752 if (strcmp(entry->name, "syslog") == 0) {
753 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
756 p->syslog = strdup(entry->value);
761 if (strcmp(entry->name, "log_level") == 0) {
764 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
767 p->log_level_present = 1;
769 status = parser_read_uint32(&p->log_level,
771 PARSE_ERROR((status == 0), section_name, entry->name);
776 if (strcmp(entry->name, "v") == 0) {
779 PARSE_ERROR_DUPLICATE((p->version_present == 0),
782 p->version_present = 1;
784 val = parser_read_arg_bool(entry->value);
785 PARSE_ERROR((val >= 0), section_name, entry->name);
791 if ((strcmp(entry->name, "help") == 0) ||
792 (strcmp(entry->name, "h") == 0)) {
795 PARSE_ERROR_DUPLICATE((p->help_present == 0),
800 val = parser_read_arg_bool(entry->value);
801 PARSE_ERROR((val >= 0), section_name, entry->name);
807 if (strcmp(entry->name, "no_huge") == 0) {
810 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
813 p->no_huge_present = 1;
815 val = parser_read_arg_bool(entry->value);
816 PARSE_ERROR((val >= 0), section_name, entry->name);
822 if (strcmp(entry->name, "no_pci") == 0) {
825 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
828 p->no_pci_present = 1;
830 val = parser_read_arg_bool(entry->value);
831 PARSE_ERROR((val >= 0), section_name, entry->name);
837 if (strcmp(entry->name, "no_hpet") == 0) {
840 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
843 p->no_hpet_present = 1;
845 val = parser_read_arg_bool(entry->value);
846 PARSE_ERROR((val >= 0), section_name, entry->name);
852 if (strcmp(entry->name, "no_shconf") == 0) {
855 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
858 p->no_shconf_present = 1;
860 val = parser_read_arg_bool(entry->value);
861 PARSE_ERROR((val >= 0), section_name, entry->name);
867 if (strcmp(entry->name, "d") == 0) {
868 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
871 p->add_driver = strdup(entry->value);
876 if (strcmp(entry->name, "socket_mem") == 0) {
877 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
880 p->socket_mem = strdup(entry->value);
885 if (strcmp(entry->name, "huge_dir") == 0) {
886 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
889 p->huge_dir = strdup(entry->value);
894 if (strcmp(entry->name, "file_prefix") == 0) {
895 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
898 p->file_prefix = strdup(entry->value);
903 if (strcmp(entry->name, "base_virtaddr") == 0) {
904 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
907 p->base_virtaddr = strdup(entry->value);
912 if (strcmp(entry->name, "create_uio_dev") == 0) {
915 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
918 p->create_uio_dev_present = 1;
920 val = parser_read_arg_bool(entry->value);
921 PARSE_ERROR((val >= 0), section_name, entry->name);
922 p->create_uio_dev = val;
927 if (strcmp(entry->name, "vfio_intr") == 0) {
928 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
931 p->vfio_intr = strdup(entry->value);
936 if (strcmp(entry->name, "xen_dom0") == 0) {
939 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
942 p->xen_dom0_present = 1;
944 val = parser_read_arg_bool(entry->value);
945 PARSE_ERROR((val >= 0), section_name, entry->name);
951 PARSE_ERROR_INVALID(0, section_name, entry->name);
958 parse_pipeline_pcap_source(struct app_params *app,
959 struct app_pipeline_params *p,
960 const char *file_name, const char *cp_size)
962 const char *next = NULL;
967 if (file_name && !cp_size) {
969 parse_file = 1; /* parse file path */
970 } else if (cp_size && !file_name) {
972 parse_file = 0; /* parse copy size */
976 char name[APP_PARAM_NAME_SIZE];
979 if (p->n_pktq_in == 0)
983 while (*next != '\0') {
986 if (i >= p->n_pktq_in)
989 id = p->pktq_in[i].id;
991 end = strchr(next, ' ');
993 name_len = strlen(next);
995 name_len = end - next;
997 if (name_len == 0 || name_len == sizeof(name))
1000 strncpy(name, next, name_len);
1001 name[name_len] = '\0';
1007 app->source_params[id].file_name = strdup(name);
1008 if (app->source_params[id].file_name == NULL)
1011 if (parser_read_uint32(
1012 &app->source_params[id].n_bytes_per_pkt,
1014 if (app->source_params[id].
1016 free(app->source_params[id].
1024 if (i == p->n_pktq_in)
1032 parse_pipeline_pcap_sink(struct app_params *app,
1033 struct app_pipeline_params *p,
1034 const char *file_name, const char *n_pkts_to_dump)
1036 const char *next = NULL;
1041 if (file_name && !n_pkts_to_dump) {
1043 parse_file = 1; /* parse file path */
1044 } else if (n_pkts_to_dump && !file_name) {
1045 next = n_pkts_to_dump;
1046 parse_file = 0; /* parse copy size */
1050 char name[APP_PARAM_NAME_SIZE];
1053 if (p->n_pktq_out == 0)
1057 while (*next != '\0') {
1060 if (i >= p->n_pktq_out)
1063 id = p->pktq_out[i].id;
1065 end = strchr(next, ' ');
1067 name_len = strlen(next);
1069 name_len = end - next;
1071 if (name_len == 0 || name_len == sizeof(name))
1074 strncpy(name, next, name_len);
1075 name[name_len] = '\0';
1081 app->sink_params[id].file_name = strdup(name);
1082 if (app->sink_params[id].file_name == NULL)
1085 if (parser_read_uint32(
1086 &app->sink_params[id].n_pkts_to_dump,
1088 if (app->sink_params[id].file_name !=
1090 free(app->sink_params[id].
1098 if (i == p->n_pktq_out)
1106 parse_pipeline_pktq_in(struct app_params *app,
1107 struct app_pipeline_params *p,
1110 const char *next = value;
1114 char name[APP_PARAM_NAME_SIZE];
1117 while (*next != '\0') {
1118 enum app_pktq_in_type type;
1123 next = skip_white_spaces(next);
1127 end_space = strchr(next, ' ');
1128 end_tab = strchr(next, ' ');
1130 if (end_space && (!end_tab))
1132 else if ((!end_space) && end_tab)
1134 else if (end_space && end_tab)
1135 end = RTE_MIN(end_space, end_tab);
1140 name_len = strlen(next);
1142 name_len = end - next;
1144 if (name_len == 0 || name_len == sizeof(name))
1147 strncpy(name, next, name_len);
1148 name[name_len] = '\0';
1153 if (validate_name(name, "RXQ", 2) == 0) {
1154 type = APP_PKTQ_IN_HWQ;
1155 id = APP_PARAM_ADD(app->hwq_in_params, name);
1156 } else if (validate_name(name, "SWQ", 1) == 0) {
1157 type = APP_PKTQ_IN_SWQ;
1158 id = APP_PARAM_ADD(app->swq_params, name);
1159 } else if (validate_name(name, "TM", 1) == 0) {
1160 type = APP_PKTQ_IN_TM;
1161 id = APP_PARAM_ADD(app->tm_params, name);
1162 } else if (validate_name(name, "SOURCE", 1) == 0) {
1163 type = APP_PKTQ_IN_SOURCE;
1164 id = APP_PARAM_ADD(app->source_params, name);
1171 p->pktq_in[p->n_pktq_in].type = type;
1172 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1180 parse_pipeline_pktq_out(struct app_params *app,
1181 struct app_pipeline_params *p,
1184 const char *next = value;
1188 char name[APP_PARAM_NAME_SIZE];
1191 while (*next != '\0') {
1192 enum app_pktq_out_type type;
1197 next = skip_white_spaces(next);
1201 end_space = strchr(next, ' ');
1202 end_tab = strchr(next, ' ');
1204 if (end_space && (!end_tab))
1206 else if ((!end_space) && end_tab)
1208 else if (end_space && end_tab)
1209 end = RTE_MIN(end_space, end_tab);
1214 name_len = strlen(next);
1216 name_len = end - next;
1218 if (name_len == 0 || name_len == sizeof(name))
1221 strncpy(name, next, name_len);
1222 name[name_len] = '\0';
1226 if (validate_name(name, "TXQ", 2) == 0) {
1227 type = APP_PKTQ_OUT_HWQ;
1228 id = APP_PARAM_ADD(app->hwq_out_params, name);
1229 } else if (validate_name(name, "SWQ", 1) == 0) {
1230 type = APP_PKTQ_OUT_SWQ;
1231 id = APP_PARAM_ADD(app->swq_params, name);
1232 } else if (validate_name(name, "TM", 1) == 0) {
1233 type = APP_PKTQ_OUT_TM;
1234 id = APP_PARAM_ADD(app->tm_params, name);
1235 } else if (validate_name(name, "SINK", 1) == 0) {
1236 type = APP_PKTQ_OUT_SINK;
1237 id = APP_PARAM_ADD(app->sink_params, name);
1244 p->pktq_out[p->n_pktq_out].type = type;
1245 p->pktq_out[p->n_pktq_out].id = id;
1253 parse_pipeline_msgq_in(struct app_params *app,
1254 struct app_pipeline_params *p,
1257 const char *next = value;
1261 char name[APP_PARAM_NAME_SIZE];
1265 while (*next != '\0') {
1269 next = skip_white_spaces(next);
1273 end_space = strchr(next, ' ');
1274 end_tab = strchr(next, ' ');
1276 if (end_space && (!end_tab))
1278 else if ((!end_space) && end_tab)
1280 else if (end_space && end_tab)
1281 end = RTE_MIN(end_space, end_tab);
1286 name_len = strlen(next);
1288 name_len = end - next;
1290 if (name_len == 0 || name_len == sizeof(name))
1293 strncpy(name, next, name_len);
1294 name[name_len] = '\0';
1299 if (validate_name(name, "MSGQ", 1) != 0)
1302 idx = APP_PARAM_ADD(app->msgq_params, name);
1306 p->msgq_in[p->n_msgq_in] = idx;
1314 parse_pipeline_msgq_out(struct app_params *app,
1315 struct app_pipeline_params *p,
1318 const char *next = value;
1322 char name[APP_PARAM_NAME_SIZE];
1326 while (*next != '\0') {
1330 next = skip_white_spaces(next);
1334 end_space = strchr(next, ' ');
1335 end_tab = strchr(next, ' ');
1337 if (end_space && (!end_tab))
1339 else if ((!end_space) && end_tab)
1341 else if (end_space && end_tab)
1342 end = RTE_MIN(end_space, end_tab);
1347 name_len = strlen(next);
1349 name_len = end - next;
1351 if (name_len == 0 || name_len == sizeof(name))
1354 strncpy(name, next, name_len);
1355 name[name_len] = '\0';
1360 if (validate_name(name, "MSGQ", 1) != 0)
1363 idx = APP_PARAM_ADD(app->msgq_params, name);
1367 p->msgq_out[p->n_msgq_out] = idx;
1375 parse_pipeline(struct app_params *app,
1376 const char *section_name,
1377 struct rte_cfgfile *cfg)
1379 char name[CFG_NAME_LEN];
1380 struct app_pipeline_params *param;
1381 struct rte_cfgfile_entry *entries;
1385 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1386 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1388 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1389 PARSE_ERROR_MALLOC(entries != NULL);
1391 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1393 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1394 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1396 param = &app->pipeline_params[param_idx];
1398 for (i = 0; i < n_entries; i++) {
1399 struct rte_cfgfile_entry *ent = &entries[i];
1401 if (strcmp(ent->name, "type") == 0) {
1402 int w_size = snprintf(param->type, RTE_DIM(param->type),
1405 PARSE_ERROR(((w_size > 0) &&
1406 (w_size < (int)RTE_DIM(param->type))),
1412 if (strcmp(ent->name, "core") == 0) {
1413 int status = parse_pipeline_core(
1414 ¶m->socket_id, ¶m->core_id,
1415 ¶m->hyper_th_id, ent->value);
1417 PARSE_ERROR((status == 0), section_name,
1422 if (strcmp(ent->name, "pktq_in") == 0) {
1423 int status = parse_pipeline_pktq_in(app, param,
1426 PARSE_ERROR((status == 0), section_name,
1431 if (strcmp(ent->name, "pktq_out") == 0) {
1432 int status = parse_pipeline_pktq_out(app, param,
1435 PARSE_ERROR((status == 0), section_name,
1440 if (strcmp(ent->name, "msgq_in") == 0) {
1441 int status = parse_pipeline_msgq_in(app, param,
1444 PARSE_ERROR((status == 0), section_name,
1449 if (strcmp(ent->name, "msgq_out") == 0) {
1450 int status = parse_pipeline_msgq_out(app, param,
1453 PARSE_ERROR((status == 0), section_name,
1458 if (strcmp(ent->name, "timer_period") == 0) {
1459 int status = parser_read_uint32(
1460 ¶m->timer_period,
1463 PARSE_ERROR((status == 0), section_name,
1468 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1471 #ifndef RTE_PORT_PCAP
1472 PARSE_ERROR_INVALID(0, section_name, ent->name);
1475 status = parse_pipeline_pcap_source(app,
1476 param, ent->value, NULL);
1478 PARSE_ERROR((status == 0), section_name,
1483 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1486 #ifndef RTE_PORT_PCAP
1487 PARSE_ERROR_INVALID(0, section_name, ent->name);
1490 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) {
1501 #ifndef RTE_PORT_PCAP
1502 PARSE_ERROR_INVALID(0, section_name, ent->name);
1505 status = parse_pipeline_pcap_sink(app, param,
1508 PARSE_ERROR((status == 0), section_name,
1513 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1516 #ifndef RTE_PORT_PCAP
1517 PARSE_ERROR_INVALID(0, section_name, ent->name);
1520 status = parse_pipeline_pcap_sink(app, param,
1523 PARSE_ERROR((status == 0), section_name,
1528 /* pipeline type specific items */
1529 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1530 "Parse error in section \"%s\": too many "
1531 "pipeline specified parameters", section_name);
1533 param->args_name[param->n_args] = strdup(ent->name);
1534 param->args_value[param->n_args] = strdup(ent->value);
1536 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1537 (param->args_value[param->n_args] != NULL),
1538 "Parse error: no free memory");
1545 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1546 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1547 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1548 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1549 param->msgq_in[param->n_msgq_in++] = param_idx;
1551 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1552 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1553 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1554 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1555 param->msgq_out[param->n_msgq_out++] = param_idx;
1557 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1560 (param->hyper_th_id) ? "h" : "");
1561 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1562 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1563 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1565 snprintf(name, sizeof(name), "MSGQ-RSP-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;
1577 parse_mempool(struct app_params *app,
1578 const char *section_name,
1579 struct rte_cfgfile *cfg)
1581 struct app_mempool_params *param;
1582 struct rte_cfgfile_entry *entries;
1586 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1587 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1589 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1590 PARSE_ERROR_MALLOC(entries != NULL);
1592 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1594 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1595 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1597 param = &app->mempool_params[param_idx];
1599 for (i = 0; i < n_entries; i++) {
1600 struct rte_cfgfile_entry *ent = &entries[i];
1602 if (strcmp(ent->name, "buffer_size") == 0) {
1603 int status = parser_read_uint32(
1604 ¶m->buffer_size, ent->value);
1606 PARSE_ERROR((status == 0), section_name,
1611 if (strcmp(ent->name, "pool_size") == 0) {
1612 int status = parser_read_uint32(
1613 ¶m->pool_size, ent->value);
1615 PARSE_ERROR((status == 0), section_name,
1620 if (strcmp(ent->name, "cache_size") == 0) {
1621 int status = parser_read_uint32(
1622 ¶m->cache_size, ent->value);
1624 PARSE_ERROR((status == 0), section_name,
1629 if (strcmp(ent->name, "cpu") == 0) {
1630 int status = parser_read_uint32(
1631 ¶m->cpu_socket_id, ent->value);
1633 PARSE_ERROR((status == 0), section_name,
1639 PARSE_ERROR_INVALID(0, section_name, ent->name);
1648 parse_link(struct app_params *app,
1649 const char *section_name,
1650 struct rte_cfgfile *cfg)
1652 struct app_link_params *param;
1653 struct rte_cfgfile_entry *entries;
1655 int pci_bdf_present = 0;
1658 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1659 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1661 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1662 PARSE_ERROR_MALLOC(entries != NULL);
1664 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1666 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1667 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1669 param = &app->link_params[param_idx];
1671 for (i = 0; i < n_entries; i++) {
1672 struct rte_cfgfile_entry *ent = &entries[i];
1674 if (strcmp(ent->name, "promisc") == 0) {
1675 int status = parser_read_arg_bool(ent->value);
1677 PARSE_ERROR((status != -EINVAL), section_name,
1679 param->promisc = status;
1683 if (strcmp(ent->name, "arp_q") == 0) {
1684 int status = parser_read_uint32(¶m->arp_q,
1687 PARSE_ERROR((status == 0), section_name,
1692 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1693 int status = parser_read_uint32(
1694 ¶m->tcp_syn_q, ent->value);
1696 PARSE_ERROR((status == 0), section_name, ent->name);
1700 if (strcmp(ent->name, "ip_local_q") == 0) {
1701 int status = parser_read_uint32(
1702 ¶m->ip_local_q, ent->value);
1704 PARSE_ERROR((status == 0), section_name,
1710 if (strcmp(ent->name, "tcp_local_q") == 0) {
1711 int status = parser_read_uint32(
1712 ¶m->tcp_local_q, ent->value);
1714 PARSE_ERROR((status == 0), section_name,
1719 if (strcmp(ent->name, "udp_local_q") == 0) {
1720 int status = parser_read_uint32(
1721 ¶m->udp_local_q, ent->value);
1723 PARSE_ERROR((status == 0), section_name,
1728 if (strcmp(ent->name, "sctp_local_q") == 0) {
1729 int status = parser_read_uint32(
1730 ¶m->sctp_local_q, ent->value);
1732 PARSE_ERROR((status == 0), section_name,
1737 if (strcmp(ent->name, "pci_bdf") == 0) {
1738 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1739 section_name, ent->name);
1741 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1743 pci_bdf_present = 1;
1748 PARSE_ERROR_INVALID(0, section_name, ent->name);
1751 /* Check for mandatory fields */
1753 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1754 section_name, "pci_bdf",
1755 "entry not allowed (port_mask is provided)");
1757 PARSE_ERROR_MESSAGE((pci_bdf_present),
1758 section_name, "pci_bdf",
1759 "this entry is mandatory (port_mask is not "
1768 parse_rxq(struct app_params *app,
1769 const char *section_name,
1770 struct rte_cfgfile *cfg)
1772 struct app_pktq_hwq_in_params *param;
1773 struct rte_cfgfile_entry *entries;
1777 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1778 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1780 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1781 PARSE_ERROR_MALLOC(entries != NULL);
1783 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1785 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1786 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1788 param = &app->hwq_in_params[param_idx];
1790 for (i = 0; i < n_entries; i++) {
1791 struct rte_cfgfile_entry *ent = &entries[i];
1793 if (strcmp(ent->name, "mempool") == 0) {
1794 int status = validate_name(ent->value,
1798 PARSE_ERROR((status == 0), section_name,
1800 idx = APP_PARAM_ADD(app->mempool_params,
1802 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1804 param->mempool_id = idx;
1808 if (strcmp(ent->name, "size") == 0) {
1809 int status = parser_read_uint32(¶m->size,
1812 PARSE_ERROR((status == 0), section_name,
1817 if (strcmp(ent->name, "burst") == 0) {
1818 int status = parser_read_uint32(¶m->burst,
1821 PARSE_ERROR((status == 0), section_name,
1827 PARSE_ERROR_INVALID(0, section_name, ent->name);
1836 parse_txq(struct app_params *app,
1837 const char *section_name,
1838 struct rte_cfgfile *cfg)
1840 struct app_pktq_hwq_out_params *param;
1841 struct rte_cfgfile_entry *entries;
1845 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1846 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1848 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1849 PARSE_ERROR_MALLOC(entries != NULL);
1851 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1853 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1854 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1856 param = &app->hwq_out_params[param_idx];
1858 for (i = 0; i < n_entries; i++) {
1859 struct rte_cfgfile_entry *ent = &entries[i];
1861 if (strcmp(ent->name, "size") == 0) {
1862 int status = parser_read_uint32(¶m->size,
1865 PARSE_ERROR((status == 0), section_name,
1870 if (strcmp(ent->name, "burst") == 0) {
1871 int status = parser_read_uint32(¶m->burst,
1874 PARSE_ERROR((status == 0), section_name,
1879 if (strcmp(ent->name, "dropless") == 0) {
1880 int status = parser_read_arg_bool(ent->value);
1883 PARSE_ERROR((status != -EINVAL), section_name,
1885 param->dropless = status;
1890 PARSE_ERROR_INVALID(0, section_name, ent->name);
1899 parse_swq(struct app_params *app,
1900 const char *section_name,
1901 struct rte_cfgfile *cfg)
1903 struct app_pktq_swq_params *param;
1904 struct rte_cfgfile_entry *entries;
1906 uint32_t mtu_present = 0;
1907 uint32_t metadata_size_present = 0;
1908 uint32_t mempool_direct_present = 0;
1909 uint32_t mempool_indirect_present = 0;
1913 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1914 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1916 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1917 PARSE_ERROR_MALLOC(entries != NULL);
1919 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1921 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1922 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1924 param = &app->swq_params[param_idx];
1926 for (i = 0; i < n_entries; i++) {
1927 struct rte_cfgfile_entry *ent = &entries[i];
1929 if (strcmp(ent->name, "size") == 0) {
1930 int status = parser_read_uint32(¶m->size,
1933 PARSE_ERROR((status == 0), section_name,
1938 if (strcmp(ent->name, "burst_read") == 0) {
1939 int status = parser_read_uint32(&
1940 param->burst_read, ent->value);
1942 PARSE_ERROR((status == 0), section_name,
1947 if (strcmp(ent->name, "burst_write") == 0) {
1948 int status = parser_read_uint32(
1949 ¶m->burst_write, ent->value);
1951 PARSE_ERROR((status == 0), section_name,
1956 if (strcmp(ent->name, "dropless") == 0) {
1957 int status = parser_read_arg_bool(ent->value);
1959 PARSE_ERROR((status != -EINVAL), section_name,
1961 param->dropless = status;
1965 if (strcmp(ent->name, "n_retries") == 0) {
1966 int status = parser_read_uint64(¶m->n_retries,
1969 PARSE_ERROR((status == 0), section_name,
1974 if (strcmp(ent->name, "cpu") == 0) {
1975 int status = parser_read_uint32(
1976 ¶m->cpu_socket_id, ent->value);
1978 PARSE_ERROR((status == 0), section_name, ent->name);
1982 if (strcmp(ent->name, "ipv4_frag") == 0) {
1983 int status = parser_read_arg_bool(ent->value);
1985 PARSE_ERROR((status != -EINVAL), section_name,
1988 param->ipv4_frag = status;
1989 if (param->mtu == 0)
1995 if (strcmp(ent->name, "ipv6_frag") == 0) {
1996 int status = parser_read_arg_bool(ent->value);
1998 PARSE_ERROR((status != -EINVAL), section_name,
2000 param->ipv6_frag = status;
2001 if (param->mtu == 0)
2006 if (strcmp(ent->name, "ipv4_ras") == 0) {
2007 int status = parser_read_arg_bool(ent->value);
2009 PARSE_ERROR((status != -EINVAL), section_name,
2011 param->ipv4_ras = status;
2015 if (strcmp(ent->name, "ipv6_ras") == 0) {
2016 int status = parser_read_arg_bool(ent->value);
2018 PARSE_ERROR((status != -EINVAL), section_name,
2020 param->ipv6_ras = status;
2024 if (strcmp(ent->name, "mtu") == 0) {
2025 int status = parser_read_uint32(¶m->mtu,
2028 PARSE_ERROR((status == 0), section_name,
2034 if (strcmp(ent->name, "metadata_size") == 0) {
2035 int status = parser_read_uint32(
2036 ¶m->metadata_size, ent->value);
2038 PARSE_ERROR((status == 0), section_name,
2040 metadata_size_present = 1;
2044 if (strcmp(ent->name, "mempool_direct") == 0) {
2045 int status = validate_name(ent->value,
2049 PARSE_ERROR((status == 0), section_name,
2052 idx = APP_PARAM_ADD(app->mempool_params,
2054 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2056 param->mempool_direct_id = idx;
2057 mempool_direct_present = 1;
2061 if (strcmp(ent->name, "mempool_indirect") == 0) {
2062 int status = validate_name(ent->value,
2066 PARSE_ERROR((status == 0), section_name,
2068 idx = APP_PARAM_ADD(app->mempool_params,
2070 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2072 param->mempool_indirect_id = idx;
2073 mempool_indirect_present = 1;
2078 PARSE_ERROR_INVALID(0, section_name, ent->name);
2081 APP_CHECK(((mtu_present) &&
2082 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2083 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2084 "is off, therefore entry \"mtu\" is not allowed",
2087 APP_CHECK(((metadata_size_present) &&
2088 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2089 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2090 "is off, therefore entry \"metadata_size\" is "
2091 "not allowed", section_name);
2093 APP_CHECK(((mempool_direct_present) &&
2094 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2095 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2096 "is off, therefore entry \"mempool_direct\" is "
2097 "not allowed", section_name);
2099 APP_CHECK(((mempool_indirect_present) &&
2100 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2101 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2102 "is off, therefore entry \"mempool_indirect\" is "
2103 "not allowed", section_name);
2111 parse_tm(struct app_params *app,
2112 const char *section_name,
2113 struct rte_cfgfile *cfg)
2115 struct app_pktq_tm_params *param;
2116 struct rte_cfgfile_entry *entries;
2120 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2121 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2123 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2124 PARSE_ERROR_MALLOC(entries != NULL);
2126 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2128 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2129 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2131 param = &app->tm_params[param_idx];
2133 for (i = 0; i < n_entries; i++) {
2134 struct rte_cfgfile_entry *ent = &entries[i];
2136 if (strcmp(ent->name, "cfg") == 0) {
2137 param->file_name = strdup(ent->value);
2138 PARSE_ERROR_MALLOC(param->file_name != NULL);
2142 if (strcmp(ent->name, "burst_read") == 0) {
2143 int status = parser_read_uint32(
2144 ¶m->burst_read, ent->value);
2146 PARSE_ERROR((status == 0), section_name,
2151 if (strcmp(ent->name, "burst_write") == 0) {
2152 int status = parser_read_uint32(
2153 ¶m->burst_write, ent->value);
2155 PARSE_ERROR((status == 0), section_name,
2161 PARSE_ERROR_INVALID(0, section_name, ent->name);
2170 parse_source(struct app_params *app,
2171 const char *section_name,
2172 struct rte_cfgfile *cfg)
2174 struct app_pktq_source_params *param;
2175 struct rte_cfgfile_entry *entries;
2178 uint32_t pcap_file_present = 0;
2179 uint32_t pcap_size_present = 0;
2181 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2182 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2184 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2185 PARSE_ERROR_MALLOC(entries != NULL);
2187 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2189 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2190 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2192 param = &app->source_params[param_idx];
2194 for (i = 0; i < n_entries; i++) {
2195 struct rte_cfgfile_entry *ent = &entries[i];
2197 if (strcmp(ent->name, "mempool") == 0) {
2198 int status = validate_name(ent->value,
2202 PARSE_ERROR((status == 0), section_name,
2204 idx = APP_PARAM_ADD(app->mempool_params,
2206 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2208 param->mempool_id = idx;
2212 if (strcmp(ent->name, "burst") == 0) {
2213 int status = parser_read_uint32(¶m->burst,
2216 PARSE_ERROR((status == 0), section_name,
2221 if (strcmp(ent->name, "pcap_file_rd")) {
2222 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2223 section_name, ent->name);
2225 param->file_name = strdup(ent->value);
2227 PARSE_ERROR_MALLOC(param->file_name != NULL);
2228 pcap_file_present = 1;
2233 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2236 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2237 section_name, ent->name);
2239 status = parser_read_uint32(
2240 ¶m->n_bytes_per_pkt, ent->value);
2242 PARSE_ERROR((status == 0), section_name,
2244 pcap_size_present = 1;
2250 PARSE_ERROR_INVALID(0, section_name, ent->name);
2259 parse_sink(struct app_params *app,
2260 const char *section_name,
2261 struct rte_cfgfile *cfg)
2263 struct app_pktq_sink_params *param;
2264 struct rte_cfgfile_entry *entries;
2267 uint32_t pcap_file_present = 0;
2268 uint32_t pcap_n_pkt_present = 0;
2270 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2271 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2273 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2274 PARSE_ERROR_MALLOC(entries != NULL);
2276 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2278 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2279 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2281 param = &app->sink_params[param_idx];
2283 for (i = 0; i < n_entries; i++) {
2284 struct rte_cfgfile_entry *ent = &entries[i];
2286 if (strcmp(ent->name, "pcap_file_wr")) {
2287 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2288 section_name, ent->name);
2290 param->file_name = strdup(ent->value);
2292 PARSE_ERROR_MALLOC((param->file_name != NULL));
2297 if (strcmp(ent->name, "pcap_n_pkt_wr")) {
2300 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2301 section_name, ent->name);
2303 status = parser_read_uint32(
2304 ¶m->n_pkts_to_dump, ent->value);
2306 PARSE_ERROR((status == 0), section_name,
2313 PARSE_ERROR_INVALID(0, section_name, ent->name);
2322 parse_msgq_req_pipeline(struct app_params *app,
2323 const char *section_name,
2324 struct rte_cfgfile *cfg)
2326 struct app_msgq_params *param;
2327 struct rte_cfgfile_entry *entries;
2331 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2332 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2334 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2335 PARSE_ERROR_MALLOC(entries != NULL);
2337 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2339 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2340 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2342 param = &app->msgq_params[param_idx];
2344 for (i = 0; i < n_entries; i++) {
2345 struct rte_cfgfile_entry *ent = &entries[i];
2347 if (strcmp(ent->name, "size") == 0) {
2348 int status = parser_read_uint32(¶m->size,
2351 PARSE_ERROR((status == 0), section_name,
2357 PARSE_ERROR_INVALID(0, section_name, ent->name);
2365 parse_msgq_rsp_pipeline(struct app_params *app,
2366 const char *section_name,
2367 struct rte_cfgfile *cfg)
2369 struct app_msgq_params *param;
2370 struct rte_cfgfile_entry *entries;
2374 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2375 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2377 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2378 PARSE_ERROR_MALLOC(entries != NULL);
2380 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2382 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2383 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2385 param = &app->msgq_params[param_idx];
2387 for (i = 0; i < n_entries; i++) {
2388 struct rte_cfgfile_entry *ent = &entries[i];
2390 if (strcmp(ent->name, "size") == 0) {
2391 int status = parser_read_uint32(¶m->size,
2394 PARSE_ERROR((status == 0), section_name,
2400 PARSE_ERROR_INVALID(0, section_name, ent->name);
2409 parse_msgq(struct app_params *app,
2410 const char *section_name,
2411 struct rte_cfgfile *cfg)
2413 struct app_msgq_params *param;
2414 struct rte_cfgfile_entry *entries;
2418 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2419 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2421 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2422 PARSE_ERROR_MALLOC(entries != NULL);
2424 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2426 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2427 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2429 param = &app->msgq_params[param_idx];
2431 for (i = 0; i < n_entries; i++) {
2432 struct rte_cfgfile_entry *ent = &entries[i];
2434 if (strcmp(ent->name, "size") == 0) {
2435 int status = parser_read_uint32(¶m->size,
2438 PARSE_ERROR((status == 0), section_name,
2443 if (strcmp(ent->name, "cpu") == 0) {
2444 int status = parser_read_uint32(
2445 ¶m->cpu_socket_id, ent->value);
2447 PARSE_ERROR((status == 0), section_name,
2453 PARSE_ERROR_INVALID(0, section_name, ent->name);
2461 typedef void (*config_section_load)(struct app_params *p,
2462 const char *section_name,
2463 struct rte_cfgfile *cfg);
2465 struct config_section {
2466 const char prefix[CFG_NAME_LEN];
2468 config_section_load load;
2471 static const struct config_section cfg_file_scheme[] = {
2472 {"EAL", 0, parse_eal},
2473 {"PIPELINE", 1, parse_pipeline},
2474 {"MEMPOOL", 1, parse_mempool},
2475 {"LINK", 1, parse_link},
2476 {"RXQ", 2, parse_rxq},
2477 {"TXQ", 2, parse_txq},
2478 {"SWQ", 1, parse_swq},
2479 {"TM", 1, parse_tm},
2480 {"SOURCE", 1, parse_source},
2481 {"SINK", 1, parse_sink},
2482 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2483 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2484 {"MSGQ", 1, parse_msgq},
2488 create_implicit_mempools(struct app_params *app)
2492 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2493 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2497 create_implicit_links_from_port_mask(struct app_params *app,
2500 uint32_t pmd_id, link_id;
2503 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2504 char name[APP_PARAM_NAME_SIZE];
2507 if ((port_mask & (1LLU << pmd_id)) == 0)
2510 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2511 idx = APP_PARAM_ADD(app->link_params, name);
2512 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2514 app->link_params[idx].pmd_id = pmd_id;
2520 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2524 for (i = 0; i < app->n_links; i++) {
2525 struct app_link_params *link = &app->link_params[i];
2532 app_config_parse(struct app_params *app, const char *file_name)
2534 struct rte_cfgfile *cfg;
2535 char **section_names;
2536 int i, j, sect_count;
2538 /* Implicit mempools */
2539 create_implicit_mempools(app);
2543 create_implicit_links_from_port_mask(app, app->port_mask);
2545 /* Load application configuration file */
2546 cfg = rte_cfgfile_load(file_name, 0);
2547 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2548 "file %s", file_name);
2550 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2551 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2552 "in file \"%s\" return %d", file_name,
2555 section_names = malloc(sect_count * sizeof(char *));
2556 PARSE_ERROR_MALLOC(section_names != NULL);
2558 for (i = 0; i < sect_count; i++)
2559 section_names[i] = malloc(CFG_NAME_LEN);
2561 rte_cfgfile_sections(cfg, section_names, sect_count);
2563 for (i = 0; i < sect_count; i++) {
2564 const struct config_section *sch_s;
2565 int len, cfg_name_len;
2567 cfg_name_len = strlen(section_names[i]);
2569 /* Find section type */
2570 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2571 sch_s = &cfg_file_scheme[j];
2572 len = strlen(sch_s->prefix);
2574 if (cfg_name_len < len)
2577 /* After section name we expect only '\0' or digit or
2578 * digit dot digit, so protect against false matching,
2579 * for example: "ABC" should match section name
2580 * "ABC0.0", but it should not match section_name
2583 if ((section_names[i][len] != '\0') &&
2584 !isdigit(section_names[i][len]))
2587 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2591 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2592 "Parse error: unknown section %s",
2595 APP_CHECK(validate_name(section_names[i],
2597 sch_s->numbers) == 0,
2598 "Parse error: invalid section name \"%s\"",
2601 sch_s->load(app, section_names[i], cfg);
2604 for (i = 0; i < sect_count; i++)
2605 free(section_names[i]);
2607 free(section_names);
2609 rte_cfgfile_close(cfg);
2611 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2612 APP_PARAM_COUNT(app->link_params, app->n_links);
2613 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2614 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2615 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2616 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2617 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2618 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2619 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2620 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2622 #ifdef RTE_PORT_PCAP
2623 for (i = 0; i < (int)app->n_pktq_source; i++) {
2624 struct app_pktq_source_params *p = &app->source_params[i];
2626 APP_CHECK((p->file_name), "Parse error: missing "
2627 "mandatory field \"pcap_file_rd\" for \"%s\"",
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: invalid field "
2635 "\"pcap_file_rd\" for \"%s\"", p->name);
2639 if (app->port_mask == 0)
2640 assign_link_pmd_id_from_pci_bdf(app);
2642 /* Save configuration to output file */
2643 app_config_save(app, app->output_file);
2645 /* Load TM configuration files */
2646 app_config_parse_tm(app);
2652 save_eal_params(struct app_params *app, FILE *f)
2654 struct app_eal_params *p = &app->eal_params;
2657 fprintf(f, "[EAL]\n");
2660 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2662 if (p->master_lcore_present)
2663 fprintf(f, "%s = %" PRIu32 "\n",
2664 "master_lcore", p->master_lcore);
2666 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2668 if (p->memory_present)
2669 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2671 if (p->ranks_present)
2672 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2674 for (i = 0; i < APP_MAX_LINKS; i++) {
2675 if (p->pci_blacklist[i] == NULL)
2678 fprintf(f, "%s = %s\n", "pci_blacklist",
2679 p->pci_blacklist[i]);
2682 for (i = 0; i < APP_MAX_LINKS; i++) {
2683 if (p->pci_whitelist[i] == NULL)
2686 fprintf(f, "%s = %s\n", "pci_whitelist",
2687 p->pci_whitelist[i]);
2690 for (i = 0; i < APP_MAX_LINKS; i++) {
2691 if (p->vdev[i] == NULL)
2694 fprintf(f, "%s = %s\n", "vdev",
2698 if (p->vmware_tsc_map_present)
2699 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2700 (p->vmware_tsc_map) ? "yes" : "no");
2703 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2706 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2708 if (p->log_level_present)
2709 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2711 if (p->version_present)
2712 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2714 if (p->help_present)
2715 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2717 if (p->no_huge_present)
2718 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2720 if (p->no_pci_present)
2721 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2723 if (p->no_hpet_present)
2724 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2726 if (p->no_shconf_present)
2727 fprintf(f, "%s = %s\n", "no_shconf",
2728 (p->no_shconf) ? "yes" : "no");
2731 fprintf(f, "%s = %s\n", "d", p->add_driver);
2734 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2737 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2740 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2742 if (p->base_virtaddr)
2743 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2745 if (p->create_uio_dev_present)
2746 fprintf(f, "%s = %s\n", "create_uio_dev",
2747 (p->create_uio_dev) ? "yes" : "no");
2750 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2752 if (p->xen_dom0_present)
2753 fprintf(f, "%s = %s\n", "xen_dom0",
2754 (p->xen_dom0) ? "yes" : "no");
2760 save_mempool_params(struct app_params *app, FILE *f)
2762 struct app_mempool_params *p;
2765 count = RTE_DIM(app->mempool_params);
2766 for (i = 0; i < count; i++) {
2767 p = &app->mempool_params[i];
2768 if (!APP_PARAM_VALID(p))
2771 fprintf(f, "[%s]\n", p->name);
2772 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2773 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2774 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2775 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2782 save_links_params(struct app_params *app, FILE *f)
2784 struct app_link_params *p;
2787 count = RTE_DIM(app->link_params);
2788 for (i = 0; i < count; i++) {
2789 p = &app->link_params[i];
2790 if (!APP_PARAM_VALID(p))
2793 fprintf(f, "[%s]\n", p->name);
2794 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2795 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2796 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2797 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2799 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2800 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2801 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2802 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2805 if (strlen(p->pci_bdf))
2806 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2813 save_rxq_params(struct app_params *app, FILE *f)
2815 struct app_pktq_hwq_in_params *p;
2818 count = RTE_DIM(app->hwq_in_params);
2819 for (i = 0; i < count; i++) {
2820 p = &app->hwq_in_params[i];
2821 if (!APP_PARAM_VALID(p))
2824 fprintf(f, "[%s]\n", p->name);
2825 fprintf(f, "%s = %s\n",
2827 app->mempool_params[p->mempool_id].name);
2828 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2829 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2836 save_txq_params(struct app_params *app, FILE *f)
2838 struct app_pktq_hwq_out_params *p;
2841 count = RTE_DIM(app->hwq_out_params);
2842 for (i = 0; i < count; i++) {
2843 p = &app->hwq_out_params[i];
2844 if (!APP_PARAM_VALID(p))
2847 fprintf(f, "[%s]\n", p->name);
2848 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2849 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2850 fprintf(f, "%s = %s\n",
2852 p->dropless ? "yes" : "no");
2859 save_swq_params(struct app_params *app, FILE *f)
2861 struct app_pktq_swq_params *p;
2864 count = RTE_DIM(app->swq_params);
2865 for (i = 0; i < count; i++) {
2866 p = &app->swq_params[i];
2867 if (!APP_PARAM_VALID(p))
2870 fprintf(f, "[%s]\n", p->name);
2871 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2872 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2873 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2874 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2875 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2876 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2877 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2878 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2879 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2880 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2881 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2882 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2883 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2884 fprintf(f, "%s = %s\n",
2886 app->mempool_params[p->mempool_direct_id].name);
2887 fprintf(f, "%s = %s\n",
2889 app->mempool_params[p->mempool_indirect_id].name);
2897 save_tm_params(struct app_params *app, FILE *f)
2899 struct app_pktq_tm_params *p;
2902 count = RTE_DIM(app->tm_params);
2903 for (i = 0; i < count; i++) {
2904 p = &app->tm_params[i];
2905 if (!APP_PARAM_VALID(p))
2908 fprintf(f, "[%s]\n", p->name);
2909 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2910 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2911 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2918 save_source_params(struct app_params *app, FILE *f)
2920 struct app_pktq_source_params *p;
2923 count = RTE_DIM(app->source_params);
2924 for (i = 0; i < count; i++) {
2925 p = &app->source_params[i];
2926 if (!APP_PARAM_VALID(p))
2929 fprintf(f, "[%s]\n", p->name);
2930 fprintf(f, "%s = %s\n",
2932 app->mempool_params[p->mempool_id].name);
2933 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2934 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2935 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2936 p->n_bytes_per_pkt);
2942 save_sink_params(struct app_params *app, FILE *f)
2944 struct app_pktq_sink_params *p;
2947 count = RTE_DIM(app->sink_params);
2948 for (i = 0; i < count; i++) {
2949 p = &app->sink_params[i];
2950 if (!APP_PARAM_VALID(p))
2953 fprintf(f, "[%s]\n", p->name);
2954 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2955 fprintf(f, "%s = %" PRIu32 "\n",
2956 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2962 save_msgq_params(struct app_params *app, FILE *f)
2964 struct app_msgq_params *p;
2967 count = RTE_DIM(app->msgq_params);
2968 for (i = 0; i < count; i++) {
2969 p = &app->msgq_params[i];
2970 if (!APP_PARAM_VALID(p))
2973 fprintf(f, "[%s]\n", p->name);
2974 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2975 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2982 save_pipeline_params(struct app_params *app, FILE *f)
2986 count = RTE_DIM(app->pipeline_params);
2987 for (i = 0; i < count; i++) {
2988 struct app_pipeline_params *p = &app->pipeline_params[i];
2990 if (!APP_PARAM_VALID(p))
2994 fprintf(f, "[%s]\n", p->name);
2997 fprintf(f, "type = %s\n", p->type);
3000 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
3003 (p->hyper_th_id) ? "h" : "");
3009 fprintf(f, "pktq_in =");
3010 for (j = 0; j < p->n_pktq_in; j++) {
3011 struct app_pktq_in_params *pp = &p->pktq_in[j];
3015 case APP_PKTQ_IN_HWQ:
3016 name = app->hwq_in_params[pp->id].name;
3018 case APP_PKTQ_IN_SWQ:
3019 name = app->swq_params[pp->id].name;
3021 case APP_PKTQ_IN_TM:
3022 name = app->tm_params[pp->id].name;
3024 case APP_PKTQ_IN_SOURCE:
3025 name = app->source_params[pp->id].name;
3028 APP_CHECK(0, "System error "
3029 "occurred while saving "
3030 "parameter to file");
3033 fprintf(f, " %s", name);
3039 if (p->n_pktq_out) {
3042 fprintf(f, "pktq_out =");
3043 for (j = 0; j < p->n_pktq_out; j++) {
3044 struct app_pktq_out_params *pp =
3049 case APP_PKTQ_OUT_HWQ:
3050 name = app->hwq_out_params[pp->id].name;
3052 case APP_PKTQ_OUT_SWQ:
3053 name = app->swq_params[pp->id].name;
3055 case APP_PKTQ_OUT_TM:
3056 name = app->tm_params[pp->id].name;
3058 case APP_PKTQ_OUT_SINK:
3059 name = app->sink_params[pp->id].name;
3062 APP_CHECK(0, "System error "
3063 "occurred while saving "
3064 "parameter to file");
3067 fprintf(f, " %s", name);
3076 fprintf(f, "msgq_in =");
3077 for (j = 0; j < p->n_msgq_in; j++) {
3078 uint32_t id = p->msgq_in[j];
3079 char *name = app->msgq_params[id].name;
3081 fprintf(f, " %s", name);
3087 if (p->n_msgq_out) {
3090 fprintf(f, "msgq_out =");
3091 for (j = 0; j < p->n_msgq_out; j++) {
3092 uint32_t id = p->msgq_out[j];
3093 char *name = app->msgq_params[id].name;
3095 fprintf(f, " %s", name);
3101 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3107 for (j = 0; j < p->n_args; j++)
3108 fprintf(f, "%s = %s\n", p->args_name[j],
3117 app_config_save(struct app_params *app, const char *file_name)
3120 char *name, *dir_name;
3123 name = strdup(file_name);
3124 dir_name = dirname(name);
3125 status = access(dir_name, W_OK);
3126 APP_CHECK((status == 0),
3127 "Error: need write access privilege to directory "
3128 "\"%s\" to save configuration\n", dir_name);
3130 file = fopen(file_name, "w");
3131 APP_CHECK((file != NULL),
3132 "Error: failed to save configuration to file \"%s\"",
3135 save_eal_params(app, file);
3136 save_pipeline_params(app, file);
3137 save_mempool_params(app, file);
3138 save_links_params(app, file);
3139 save_rxq_params(app, file);
3140 save_txq_params(app, file);
3141 save_swq_params(app, file);
3142 save_tm_params(app, file);
3143 save_source_params(app, file);
3144 save_sink_params(app, file);
3145 save_msgq_params(app, file);
3152 app_config_init(struct app_params *app)
3156 memcpy(app, &app_params_default, sizeof(struct app_params));
3158 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3159 memcpy(&app->mempool_params[i],
3160 &mempool_params_default,
3161 sizeof(struct app_mempool_params));
3163 for (i = 0; i < RTE_DIM(app->link_params); i++)
3164 memcpy(&app->link_params[i],
3165 &link_params_default,
3166 sizeof(struct app_link_params));
3168 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3169 memcpy(&app->hwq_in_params[i],
3170 &default_hwq_in_params,
3171 sizeof(default_hwq_in_params));
3173 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3174 memcpy(&app->hwq_out_params[i],
3175 &default_hwq_out_params,
3176 sizeof(default_hwq_out_params));
3178 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3179 memcpy(&app->swq_params[i],
3180 &default_swq_params,
3181 sizeof(default_swq_params));
3183 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3184 memcpy(&app->tm_params[i],
3186 sizeof(default_tm_params));
3188 for (i = 0; i < RTE_DIM(app->source_params); i++)
3189 memcpy(&app->source_params[i],
3190 &default_source_params,
3191 sizeof(default_source_params));
3193 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3194 memcpy(&app->sink_params[i],
3195 &default_sink_params,
3196 sizeof(default_sink_params));
3198 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3199 memcpy(&app->msgq_params[i],
3200 &default_msgq_params,
3201 sizeof(default_msgq_params));
3203 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3204 memcpy(&app->pipeline_params[i],
3205 &default_pipeline_params,
3206 sizeof(default_pipeline_params));
3212 filenamedup(const char *filename, const char *suffix)
3214 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3219 sprintf(s, "%s%s", filename, suffix);
3224 app_config_args(struct app_params *app, int argc, char **argv)
3226 const char *optname;
3227 int opt, option_index;
3228 int f_present, s_present, p_present, l_present;
3229 int preproc_present, preproc_params_present, disable_csum_present;
3231 int flow_dir_present;
3234 static struct option lgopts[] = {
3235 { "disable-hw-csum", 0, 0, 0 },
3236 { "preproc", 1, 0, 0 },
3237 { "preproc-args", 1, 0, 0 },
3238 { "hwlb", 1, 0, 0 },
3239 { "flow_dir", 0, 0, 0 },
3243 /* Copy application name */
3244 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3250 disable_csum_present = 0;
3251 preproc_present = 0;
3252 preproc_params_present = 0;
3253 app->header_csum_req =1; //Default enable haeader checksum
3255 flow_dir_present = 0;
3258 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3259 &option_index)) != EOF)
3263 rte_panic("Error: Config file is provided "
3264 "more than once\n");
3267 if (!strlen(optarg))
3268 rte_panic("Error: Config file name is null\n");
3270 app->config_file = strdup(optarg);
3271 if (app->config_file == NULL)
3272 rte_panic("Error: Memory allocation failure\n");
3278 rte_panic("Error: Script file is provided "
3279 "more than once\n");
3282 if (!strlen(optarg))
3283 rte_panic("Error: Script file name is null\n");
3285 app->script_file = strdup(optarg);
3286 if (app->script_file == NULL)
3287 rte_panic("Error: Memory allocation failure\n");
3293 rte_panic("Error: PORT_MASK is provided "
3294 "more than once\n");
3297 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3299 ((size_t) scaned != strlen(optarg)))
3300 rte_panic("Error: PORT_MASK is not "
3301 "a hexadecimal integer\n");
3303 if (app->port_mask == 0)
3304 rte_panic("Error: PORT_MASK is null\n");
3310 rte_panic("Error: LOG_LEVEL is provided "
3311 "more than once\n");
3314 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3316 ((size_t) scaned != strlen(optarg)) ||
3317 (app->log_level >= APP_LOG_LEVELS))
3318 rte_panic("Error: LOG_LEVEL invalid value\n");
3323 optname = lgopts[option_index].name;
3325 if (strcmp(optname, "hwlb") == 0) {
3327 rte_panic("Error: hwlb argument "
3328 "is provided more than once\n");
3330 printf(" HWLB is configured\n");
3332 app->n_hwlb_q = atoi(optarg);
3335 rte_panic("HWQs for HWLB must be atleast 1\n");
3337 printf("No of HWQs for HWLB are %d\n",app->n_hwlb_q);
3342 if (strcmp(optname, "flow_dir") == 0) {
3343 if (flow_dir_present)
3344 rte_panic("Error: flow_dir argument "
3345 "is provided more than once\n");
3346 flow_dir_present = 1;
3347 printf(" FLOW DIR is configured\n");
3349 enable_flow_dir = 1;
3354 if (strcmp(optname, "disable-hw-csum") == 0) {
3355 if (disable_csum_present)
3356 rte_panic("Error: disable-hw-csum argument "
3357 "is provided more than once\n");
3359 printf("Disable TCP/UDP HW checksumi\n");
3360 app->header_csum_req = 0;
3361 disable_csum_present = 1;
3365 if (strcmp(optname, "preproc") == 0) {
3366 if (preproc_present)
3367 rte_panic("Error: Preprocessor argument "
3368 "is provided more than once\n");
3369 preproc_present = 1;
3371 app->preproc = strdup(optarg);
3375 if (strcmp(optname, "preproc-args") == 0) {
3376 if (preproc_params_present)
3377 rte_panic("Error: Preprocessor args "
3378 "are provided more than once\n");
3379 preproc_params_present = 1;
3381 app->preproc_args = strdup(optarg);
3385 app_print_usage(argv[0]);
3389 app_print_usage(argv[0]);
3392 optind = 0; /* reset getopt lib */
3394 /* Check dependencies between args */
3395 if (preproc_params_present && (preproc_present == 0))
3396 rte_panic("Error: Preprocessor args specified while "
3397 "preprocessor is not defined\n");
3399 app->parser_file = preproc_present ?
3400 filenamedup(app->config_file, ".preproc") :
3401 strdup(app->config_file);
3402 app->output_file = filenamedup(app->config_file, ".out");
3408 app_config_preproc(struct app_params *app)
3413 if (app->preproc == NULL)
3416 status = access(app->config_file, F_OK | R_OK);
3417 APP_CHECK((status == 0), "Error: Unable to open file %s",
3420 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3422 app->preproc_args ? app->preproc_args : "",
3426 status = system(buffer);
3427 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3428 "Error occurred while pre-processing file \"%s\"\n",