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
38 uint32_t rest_support = 1;
40 static struct app_params app_params_default = {
41 .config_file = "./config/ip_pipeline.cfg",
42 .log_level = APP_LOG_LEVEL_HIGH,
50 static const struct app_mempool_params mempool_params_default = {
52 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
53 .pool_size = 32 * 1024,
58 static const struct app_link_params link_params_default = {
69 .ipv6 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
78 .mq_mode = ETH_MQ_RX_NONE,
80 .header_split = 0, /* Header split */
81 .hw_ip_checksum = 0, /* IP checksum offload */
82 .hw_vlan_filter = 0, /* VLAN filtering */
83 .hw_vlan_strip = 0, /* VLAN strip */
84 .hw_vlan_extend = 0, /* Extended VLAN */
85 .jumbo_frame = 0, /* Jumbo frame support */
86 .hw_strip_crc = 0, /* CRC strip by HW */
87 .enable_scatter = 0, /* Scattered packets RX handler */
89 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
90 .split_hdr_size = 0, /* Header split buffer size */
93 .mq_mode = ETH_MQ_TX_NONE,
98 .lsc = 1, /**< lsc interrupt feature enabled */
106 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
118 .rx_free_thresh = 64,
120 .rx_deferred_start = 0,
124 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
139 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
140 ETH_TXQ_FLAGS_NOOFFLOADS,
141 .tx_deferred_start = 0,
145 static const struct app_pktq_swq_params default_swq_params = {
159 .mempool_direct_id = 0,
160 .mempool_indirect_id = 0,
163 struct app_pktq_tm_params default_tm_params = {
165 .file_name = "./config/tm_profile.cfg",
170 struct app_pktq_source_params default_source_params = {
175 .n_bytes_per_pkt = 0,
178 struct app_pktq_sink_params default_sink_params = {
184 struct app_msgq_params default_msgq_params = {
190 struct app_pipeline_params default_pipeline_params = {
203 static const char app_usage[] =
204 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
205 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
208 "\t-f CONFIG_FILE: Default config file is %s\n"
209 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
210 "config file when not provided)\n"
211 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
212 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
213 "\t--disable-hw-csum Disable TCP/UDP HW checksum\n"
214 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
215 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
219 app_print_usage(char *prgname)
221 rte_exit(0, app_usage, prgname, app_params_default.config_file);
224 #define skip_white_spaces(pos) \
226 __typeof__(pos) _p = (pos); \
227 for ( ; isspace(*_p); _p++); \
231 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
233 APP_CHECK((result != -EINVAL), \
234 "Parse error: no free memory"); \
235 APP_CHECK((result != -ENOMEM), \
236 "Parse error: too many \"%s\" sections", section_name); \
237 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
238 "Parse error: duplicate \"%s\" section", section_name); \
239 APP_CHECK((result >= 0), \
240 "Parse error in section \"%s\"", section_name); \
243 uint32_t is_rest_support(void)
249 parser_read_arg_bool(const char *p)
251 p = skip_white_spaces(p);
252 int result = -EINVAL;
254 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
255 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
260 if (((p[0] == 'o') && (p[1] == 'n')) ||
261 ((p[0] == 'O') && (p[1] == 'N'))) {
266 if (((p[0] == 'n') && (p[1] == 'o')) ||
267 ((p[0] == 'N') && (p[1] == 'O'))) {
272 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
273 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
278 p = skip_white_spaces(p);
286 #define PARSE_ERROR(exp, section, entry) \
287 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
289 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
290 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n", \
291 section, entry, message)
294 #define PARSE_ERROR_MALLOC(exp) \
295 APP_CHECK(exp, "Parse error: no free memory\n")
297 #define PARSE_ERROR_SECTION(exp, section) \
298 APP_CHECK(exp, "Parse error in section \"%s\"", section)
300 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
301 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
303 #define PARSE_WARNING_IGNORED(exp, section, entry) \
306 fprintf(stderr, "Parse warning in section \"%s\": " \
307 "entry \"%s\" is ignored\n", section, entry); \
310 #define PARSE_ERROR_INVALID(exp, section, entry) \
311 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
314 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
315 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
319 parser_read_uint64(uint64_t *value, const char *p)
324 p = skip_white_spaces(p);
328 val = strtoul(p, &next, 10);
350 p = skip_white_spaces(p);
359 parser_read_uint32(uint32_t *value, const char *p)
362 int ret = parser_read_uint64(&val, p);
367 if (val > UINT32_MAX)
375 parse_pipeline_core(uint32_t *socket,
383 uint32_t s = 0, c = 0, h = 0, val;
384 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
385 const char *next = skip_white_spaces(entry);
388 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
389 while (*next != '\0') {
390 /* If everything parsed nothing should left */
391 if (s_parsed && c_parsed && h_parsed)
398 if (s_parsed || c_parsed || h_parsed)
405 if (c_parsed || h_parsed)
418 /* If it start from digit it must be only core id. */
419 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
425 for (num_len = 0; *next != '\0'; next++, num_len++) {
426 if (num_len == RTE_DIM(num))
432 num[num_len] = *next;
435 if (num_len == 0 && type != 'h' && type != 'H')
438 if (num_len != 0 && (type == 'h' || type == 'H'))
440 if(num_len < sizeof(num))
442 val = strtol(num, NULL, 10);
471 case '0': case '1': case '2': case '3': case '4': case '5':
472 case '6': case '7': case '8': case '9':
474 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
476 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
484 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
489 /* Check input parameters */
497 if (((len & 3) != 0) ||
502 for (c = src; *c != 0; c++) {
503 if ((((*c) >= '0') && ((*c) <= '9')) ||
504 (((*c) >= 'A') && ((*c) <= 'F')) ||
505 (((*c) >= 'a') && ((*c) <= 'f')))
511 /* Convert chars to bytes */
512 for (i = 0; i < *size; i++)
513 dst[i] = get_hex_val(src[2 * i]) * 16 +
514 get_hex_val(src[2 * i + 1]);
520 skip_digits(const char *src)
524 for (i = 0; isdigit(src[i]); i++);
530 validate_name(const char *name, const char *prefix, int num)
534 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
535 if (name[i] != prefix[i])
539 if (prefix[i] != '\0')
550 j = skip_digits(&name[i]);
552 if ((j == 0) || (name[i] != '.'))
558 j = skip_digits(&name[i]);
560 if ((j == 0) || (name[i] != '\0'))
568 parse_eal(struct app_params *app,
569 const char *section_name,
570 struct rte_cfgfile *cfg)
572 struct app_eal_params *p = &app->eal_params;
573 struct rte_cfgfile_entry *entries;
576 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
577 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
579 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
580 PARSE_ERROR_MALLOC(entries != NULL);
582 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
584 for (i = 0; i < n_entries; i++) {
585 struct rte_cfgfile_entry *entry = &entries[i];
588 if (strcmp(entry->name, "c") == 0) {
589 PARSE_WARNING_IGNORED(0, section_name, entry->name);
594 if (strcmp(entry->name, "l") == 0) {
595 PARSE_WARNING_IGNORED(0, section_name, entry->name);
600 if (strcmp(entry->name, "lcores") == 0) {
601 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
604 p->coremap = strdup(entry->value);
609 if (strcmp(entry->name, "master_lcore") == 0) {
612 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
615 p->master_lcore_present = 1;
617 status = parser_read_uint32(&p->master_lcore,
619 PARSE_ERROR((status == 0), section_name, entry->name);
624 if (strcmp(entry->name, "n") == 0) {
627 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
630 p->channels_present = 1;
632 status = parser_read_uint32(&p->channels, entry->value);
633 PARSE_ERROR((status == 0), section_name, entry->name);
638 if (strcmp(entry->name, "m") == 0) {
641 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
644 p->memory_present = 1;
646 status = parser_read_uint32(&p->memory, entry->value);
647 PARSE_ERROR((status == 0), section_name, entry->name);
652 if (strcmp(entry->name, "r") == 0) {
655 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
658 p->ranks_present = 1;
660 status = parser_read_uint32(&p->ranks, entry->value);
661 PARSE_ERROR((status == 0), section_name, entry->name);
666 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
667 (strcmp(entry->name, "b") == 0)) {
670 for (i = 0; i < APP_MAX_LINKS; i++) {
671 if (p->pci_blacklist[i])
674 p->pci_blacklist[i] =
675 strdup(entry->value);
676 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
681 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
682 section_name, entry->name,
683 "too many elements");
688 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
689 (strcmp(entry->name, "w") == 0)) {
692 PARSE_ERROR_MESSAGE((app->port_mask != 0),
693 section_name, entry->name, "entry to be "
694 "generated by the application (port_mask "
697 for (i = 0; i < APP_MAX_LINKS; i++) {
698 if (p->pci_whitelist[i])
701 p->pci_whitelist[i] = strdup(entry->value);
702 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
707 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
708 section_name, entry->name,
709 "too many elements");
714 if (strcmp(entry->name, "vdev") == 0) {
717 for (i = 0; i < APP_MAX_LINKS; i++) {
721 p->vdev[i] = strdup(entry->value);
722 PARSE_ERROR_MALLOC(p->vdev[i]);
727 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
728 section_name, entry->name,
729 "too many elements");
734 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
737 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
740 p->vmware_tsc_map_present = 1;
742 val = parser_read_arg_bool(entry->value);
743 PARSE_ERROR((val >= 0), section_name, entry->name);
744 p->vmware_tsc_map = val;
749 if (strcmp(entry->name, "proc_type") == 0) {
750 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
753 p->proc_type = strdup(entry->value);
758 if (strcmp(entry->name, "syslog") == 0) {
759 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
762 p->syslog = strdup(entry->value);
767 if (strcmp(entry->name, "log_level") == 0) {
770 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
773 p->log_level_present = 1;
775 status = parser_read_uint32(&p->log_level,
777 PARSE_ERROR((status == 0), section_name, entry->name);
782 if (strcmp(entry->name, "v") == 0) {
785 PARSE_ERROR_DUPLICATE((p->version_present == 0),
788 p->version_present = 1;
790 val = parser_read_arg_bool(entry->value);
791 PARSE_ERROR((val >= 0), section_name, entry->name);
797 if ((strcmp(entry->name, "help") == 0) ||
798 (strcmp(entry->name, "h") == 0)) {
801 PARSE_ERROR_DUPLICATE((p->help_present == 0),
806 val = parser_read_arg_bool(entry->value);
807 PARSE_ERROR((val >= 0), section_name, entry->name);
813 if (strcmp(entry->name, "no_huge") == 0) {
816 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
819 p->no_huge_present = 1;
821 val = parser_read_arg_bool(entry->value);
822 PARSE_ERROR((val >= 0), section_name, entry->name);
828 if (strcmp(entry->name, "no_pci") == 0) {
831 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
834 p->no_pci_present = 1;
836 val = parser_read_arg_bool(entry->value);
837 PARSE_ERROR((val >= 0), section_name, entry->name);
843 if (strcmp(entry->name, "no_hpet") == 0) {
846 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
849 p->no_hpet_present = 1;
851 val = parser_read_arg_bool(entry->value);
852 PARSE_ERROR((val >= 0), section_name, entry->name);
858 if (strcmp(entry->name, "no_shconf") == 0) {
861 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
864 p->no_shconf_present = 1;
866 val = parser_read_arg_bool(entry->value);
867 PARSE_ERROR((val >= 0), section_name, entry->name);
873 if (strcmp(entry->name, "d") == 0) {
874 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
877 p->add_driver = strdup(entry->value);
882 if (strcmp(entry->name, "socket_mem") == 0) {
883 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
886 p->socket_mem = strdup(entry->value);
891 if (strcmp(entry->name, "huge_dir") == 0) {
892 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
895 p->huge_dir = strdup(entry->value);
900 if (strcmp(entry->name, "file_prefix") == 0) {
901 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
904 p->file_prefix = strdup(entry->value);
909 if (strcmp(entry->name, "base_virtaddr") == 0) {
910 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
913 p->base_virtaddr = strdup(entry->value);
918 if (strcmp(entry->name, "create_uio_dev") == 0) {
921 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
924 p->create_uio_dev_present = 1;
926 val = parser_read_arg_bool(entry->value);
927 PARSE_ERROR((val >= 0), section_name, entry->name);
928 p->create_uio_dev = val;
933 if (strcmp(entry->name, "vfio_intr") == 0) {
934 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
937 p->vfio_intr = strdup(entry->value);
942 if (strcmp(entry->name, "xen_dom0") == 0) {
945 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
948 p->xen_dom0_present = 1;
950 val = parser_read_arg_bool(entry->value);
951 PARSE_ERROR((val >= 0), section_name, entry->name);
957 PARSE_ERROR_INVALID(0, section_name, entry->name);
964 parse_pipeline_pcap_source(struct app_params *app,
965 struct app_pipeline_params *p,
966 const char *file_name, const char *cp_size)
968 const char *next = NULL;
973 if (file_name && !cp_size) {
975 parse_file = 1; /* parse file path */
976 } else if (cp_size && !file_name) {
978 parse_file = 0; /* parse copy size */
982 char name[APP_PARAM_NAME_SIZE];
985 if (p->n_pktq_in == 0)
989 while (*next != '\0') {
992 if (i >= p->n_pktq_in)
995 id = p->pktq_in[i].id;
997 end = strchr(next, ' ');
999 name_len = strlen(next);
1001 name_len = end - next;
1003 if (name_len == 0 || name_len == sizeof(name))
1006 strncpy(name, next, name_len);
1007 name[name_len] = '\0';
1013 app->source_params[id].file_name = strdup(name);
1014 if (app->source_params[id].file_name == NULL)
1017 if (parser_read_uint32(
1018 &app->source_params[id].n_bytes_per_pkt,
1020 if (app->source_params[id].
1022 free(app->source_params[id].
1030 if (i == p->n_pktq_in)
1038 parse_pipeline_pcap_sink(struct app_params *app,
1039 struct app_pipeline_params *p,
1040 const char *file_name, const char *n_pkts_to_dump)
1042 const char *next = NULL;
1047 if (file_name && !n_pkts_to_dump) {
1049 parse_file = 1; /* parse file path */
1050 } else if (n_pkts_to_dump && !file_name) {
1051 next = n_pkts_to_dump;
1052 parse_file = 0; /* parse copy size */
1056 char name[APP_PARAM_NAME_SIZE];
1059 if (p->n_pktq_out == 0)
1063 while (*next != '\0') {
1066 if (i >= p->n_pktq_out)
1069 id = p->pktq_out[i].id;
1071 end = strchr(next, ' ');
1073 name_len = strlen(next);
1075 name_len = end - next;
1077 if (name_len == 0 || name_len == sizeof(name))
1080 strncpy(name, next, name_len);
1081 name[name_len] = '\0';
1087 app->sink_params[id].file_name = strdup(name);
1088 if (app->sink_params[id].file_name == NULL)
1091 if (parser_read_uint32(
1092 &app->sink_params[id].n_pkts_to_dump,
1094 if (app->sink_params[id].file_name !=
1096 free(app->sink_params[id].
1104 if (i == p->n_pktq_out)
1112 parse_pipeline_pktq_in(struct app_params *app,
1113 struct app_pipeline_params *p,
1116 const char *next = value;
1120 char name[APP_PARAM_NAME_SIZE];
1123 while (*next != '\0') {
1124 enum app_pktq_in_type type;
1129 next = skip_white_spaces(next);
1133 end_space = strchr(next, ' ');
1134 end_tab = strchr(next, ' ');
1136 if (end_space && (!end_tab))
1138 else if ((!end_space) && end_tab)
1140 else if (end_space && end_tab)
1141 end = RTE_MIN(end_space, end_tab);
1146 name_len = strlen(next);
1148 name_len = end - next;
1150 if (name_len == 0 || name_len == sizeof(name))
1153 strncpy(name, next, name_len);
1154 name[name_len] = '\0';
1159 if (validate_name(name, "RXQ", 2) == 0) {
1160 type = APP_PKTQ_IN_HWQ;
1161 id = APP_PARAM_ADD(app->hwq_in_params, name);
1162 } else if (validate_name(name, "SWQ", 1) == 0) {
1163 type = APP_PKTQ_IN_SWQ;
1164 id = APP_PARAM_ADD(app->swq_params, name);
1165 } else if (validate_name(name, "TM", 1) == 0) {
1166 type = APP_PKTQ_IN_TM;
1167 id = APP_PARAM_ADD(app->tm_params, name);
1168 } else if (validate_name(name, "SOURCE", 1) == 0) {
1169 type = APP_PKTQ_IN_SOURCE;
1170 id = APP_PARAM_ADD(app->source_params, name);
1177 p->pktq_in[p->n_pktq_in].type = type;
1178 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1186 parse_pipeline_pktq_out(struct app_params *app,
1187 struct app_pipeline_params *p,
1190 const char *next = value;
1194 char name[APP_PARAM_NAME_SIZE];
1197 while (*next != '\0') {
1198 enum app_pktq_out_type type;
1203 next = skip_white_spaces(next);
1207 end_space = strchr(next, ' ');
1208 end_tab = strchr(next, ' ');
1210 if (end_space && (!end_tab))
1212 else if ((!end_space) && end_tab)
1214 else if (end_space && end_tab)
1215 end = RTE_MIN(end_space, end_tab);
1220 name_len = strlen(next);
1222 name_len = end - next;
1224 if (name_len == 0 || name_len == sizeof(name))
1227 strncpy(name, next, name_len);
1228 name[name_len] = '\0';
1232 if (validate_name(name, "TXQ", 2) == 0) {
1233 type = APP_PKTQ_OUT_HWQ;
1234 id = APP_PARAM_ADD(app->hwq_out_params, name);
1235 } else if (validate_name(name, "SWQ", 1) == 0) {
1236 type = APP_PKTQ_OUT_SWQ;
1237 id = APP_PARAM_ADD(app->swq_params, name);
1238 } else if (validate_name(name, "TM", 1) == 0) {
1239 type = APP_PKTQ_OUT_TM;
1240 id = APP_PARAM_ADD(app->tm_params, name);
1241 } else if (validate_name(name, "SINK", 1) == 0) {
1242 type = APP_PKTQ_OUT_SINK;
1243 id = APP_PARAM_ADD(app->sink_params, name);
1250 p->pktq_out[p->n_pktq_out].type = type;
1251 p->pktq_out[p->n_pktq_out].id = id;
1259 parse_pipeline_msgq_in(struct app_params *app,
1260 struct app_pipeline_params *p,
1263 const char *next = value;
1267 char name[APP_PARAM_NAME_SIZE];
1271 while (*next != '\0') {
1275 next = skip_white_spaces(next);
1279 end_space = strchr(next, ' ');
1280 end_tab = strchr(next, ' ');
1282 if (end_space && (!end_tab))
1284 else if ((!end_space) && end_tab)
1286 else if (end_space && end_tab)
1287 end = RTE_MIN(end_space, end_tab);
1292 name_len = strlen(next);
1294 name_len = end - next;
1296 if (name_len == 0 || name_len == sizeof(name))
1299 strncpy(name, next, name_len);
1300 name[name_len] = '\0';
1305 if (validate_name(name, "MSGQ", 1) != 0)
1308 idx = APP_PARAM_ADD(app->msgq_params, name);
1312 p->msgq_in[p->n_msgq_in] = idx;
1320 parse_pipeline_msgq_out(struct app_params *app,
1321 struct app_pipeline_params *p,
1324 const char *next = value;
1328 char name[APP_PARAM_NAME_SIZE];
1332 while (*next != '\0') {
1336 next = skip_white_spaces(next);
1340 end_space = strchr(next, ' ');
1341 end_tab = strchr(next, ' ');
1343 if (end_space && (!end_tab))
1345 else if ((!end_space) && end_tab)
1347 else if (end_space && end_tab)
1348 end = RTE_MIN(end_space, end_tab);
1353 name_len = strlen(next);
1355 name_len = end - next;
1357 if (name_len == 0 || name_len == sizeof(name))
1360 strncpy(name, next, name_len);
1361 name[name_len] = '\0';
1366 if (validate_name(name, "MSGQ", 1) != 0)
1369 idx = APP_PARAM_ADD(app->msgq_params, name);
1373 p->msgq_out[p->n_msgq_out] = idx;
1381 parse_pipeline(struct app_params *app,
1382 const char *section_name,
1383 struct rte_cfgfile *cfg)
1385 char name[CFG_NAME_LEN];
1386 struct app_pipeline_params *param;
1387 struct rte_cfgfile_entry *entries;
1391 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1392 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1394 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1395 PARSE_ERROR_MALLOC(entries != NULL);
1397 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1399 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1400 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1402 param = &app->pipeline_params[param_idx];
1404 for (i = 0; i < n_entries; i++) {
1405 struct rte_cfgfile_entry *ent = &entries[i];
1407 if (strcmp(ent->name, "type") == 0) {
1408 int w_size = snprintf(param->type, RTE_DIM(param->type),
1411 PARSE_ERROR(((w_size > 0) &&
1412 (w_size < (int)RTE_DIM(param->type))),
1418 if (strcmp(ent->name, "core") == 0) {
1419 int status = parse_pipeline_core(
1420 ¶m->socket_id, ¶m->core_id,
1421 ¶m->hyper_th_id, ent->value);
1423 PARSE_ERROR((status == 0), section_name,
1428 if (strcmp(ent->name, "pktq_in") == 0) {
1429 int status = parse_pipeline_pktq_in(app, param,
1432 PARSE_ERROR((status == 0), section_name,
1437 if (strcmp(ent->name, "pktq_out") == 0) {
1438 int status = parse_pipeline_pktq_out(app, param,
1441 PARSE_ERROR((status == 0), section_name,
1446 if (strcmp(ent->name, "msgq_in") == 0) {
1447 int status = parse_pipeline_msgq_in(app, param,
1450 PARSE_ERROR((status == 0), section_name,
1455 if (strcmp(ent->name, "msgq_out") == 0) {
1456 int status = parse_pipeline_msgq_out(app, param,
1459 PARSE_ERROR((status == 0), section_name,
1464 if (strcmp(ent->name, "timer_period") == 0) {
1465 int status = parser_read_uint32(
1466 ¶m->timer_period,
1469 PARSE_ERROR((status == 0), section_name,
1474 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1477 #ifndef RTE_PORT_PCAP
1478 PARSE_ERROR_INVALID(0, section_name, ent->name);
1481 status = parse_pipeline_pcap_source(app,
1482 param, ent->value, NULL);
1484 PARSE_ERROR((status == 0), section_name,
1489 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1492 #ifndef RTE_PORT_PCAP
1493 PARSE_ERROR_INVALID(0, section_name, ent->name);
1496 status = parse_pipeline_pcap_source(app,
1497 param, NULL, ent->value);
1499 PARSE_ERROR((status == 0), section_name,
1504 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1507 #ifndef RTE_PORT_PCAP
1508 PARSE_ERROR_INVALID(0, section_name, ent->name);
1511 status = parse_pipeline_pcap_sink(app, param,
1514 PARSE_ERROR((status == 0), section_name,
1519 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1522 #ifndef RTE_PORT_PCAP
1523 PARSE_ERROR_INVALID(0, section_name, ent->name);
1526 status = parse_pipeline_pcap_sink(app, param,
1529 PARSE_ERROR((status == 0), section_name,
1534 /* pipeline type specific items */
1535 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1536 "Parse error in section \"%s\": too many "
1537 "pipeline specified parameters", section_name);
1539 param->args_name[param->n_args] = strdup(ent->name);
1540 param->args_value[param->n_args] = strdup(ent->value);
1542 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1543 (param->args_value[param->n_args] != NULL),
1544 "Parse error: no free memory");
1551 snprintf(name, sizeof(name), "MSGQ-REQ-%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_in[param->n_msgq_in++] = param_idx;
1557 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1558 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1559 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1560 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1561 param->msgq_out[param->n_msgq_out++] = param_idx;
1563 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1566 (param->hyper_th_id) ? "h" : "");
1567 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1568 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1569 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1571 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1574 (param->hyper_th_id) ? "h" : "");
1575 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1576 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1577 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1583 parse_mempool(struct app_params *app,
1584 const char *section_name,
1585 struct rte_cfgfile *cfg)
1587 struct app_mempool_params *param;
1588 struct rte_cfgfile_entry *entries;
1592 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1593 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1595 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1596 PARSE_ERROR_MALLOC(entries != NULL);
1598 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1600 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1601 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1603 param = &app->mempool_params[param_idx];
1605 for (i = 0; i < n_entries; i++) {
1606 struct rte_cfgfile_entry *ent = &entries[i];
1608 if (strcmp(ent->name, "buffer_size") == 0) {
1609 int status = parser_read_uint32(
1610 ¶m->buffer_size, ent->value);
1612 PARSE_ERROR((status == 0), section_name,
1617 if (strcmp(ent->name, "pool_size") == 0) {
1618 int status = parser_read_uint32(
1619 ¶m->pool_size, ent->value);
1621 PARSE_ERROR((status == 0), section_name,
1626 if (strcmp(ent->name, "cache_size") == 0) {
1627 int status = parser_read_uint32(
1628 ¶m->cache_size, ent->value);
1630 PARSE_ERROR((status == 0), section_name,
1635 if (strcmp(ent->name, "cpu") == 0) {
1636 int status = parser_read_uint32(
1637 ¶m->cpu_socket_id, ent->value);
1639 PARSE_ERROR((status == 0), section_name,
1645 PARSE_ERROR_INVALID(0, section_name, ent->name);
1654 parse_link(struct app_params *app,
1655 const char *section_name,
1656 struct rte_cfgfile *cfg)
1658 struct app_link_params *param;
1659 struct rte_cfgfile_entry *entries;
1661 int pci_bdf_present = 0;
1664 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1665 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1667 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1668 PARSE_ERROR_MALLOC(entries != NULL);
1670 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1672 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1673 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1675 param = &app->link_params[param_idx];
1677 for (i = 0; i < n_entries; i++) {
1678 struct rte_cfgfile_entry *ent = &entries[i];
1680 if (strcmp(ent->name, "promisc") == 0) {
1681 int status = parser_read_arg_bool(ent->value);
1683 PARSE_ERROR((status != -EINVAL), section_name,
1685 param->promisc = status;
1689 if (strcmp(ent->name, "arp_q") == 0) {
1690 int status = parser_read_uint32(¶m->arp_q,
1693 PARSE_ERROR((status == 0), section_name,
1698 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1699 int status = parser_read_uint32(
1700 ¶m->tcp_syn_q, ent->value);
1702 PARSE_ERROR((status == 0), section_name, ent->name);
1706 if (strcmp(ent->name, "ip_local_q") == 0) {
1707 int status = parser_read_uint32(
1708 ¶m->ip_local_q, ent->value);
1710 PARSE_ERROR((status == 0), section_name,
1716 if (strcmp(ent->name, "tcp_local_q") == 0) {
1717 int status = parser_read_uint32(
1718 ¶m->tcp_local_q, ent->value);
1720 PARSE_ERROR((status == 0), section_name,
1725 if (strcmp(ent->name, "udp_local_q") == 0) {
1726 int status = parser_read_uint32(
1727 ¶m->udp_local_q, ent->value);
1729 PARSE_ERROR((status == 0), section_name,
1734 if (strcmp(ent->name, "sctp_local_q") == 0) {
1735 int status = parser_read_uint32(
1736 ¶m->sctp_local_q, ent->value);
1738 PARSE_ERROR((status == 0), section_name,
1743 if (strcmp(ent->name, "pci_bdf") == 0) {
1744 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1745 section_name, ent->name);
1747 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1749 pci_bdf_present = 1;
1754 PARSE_ERROR_INVALID(0, section_name, ent->name);
1757 /* Check for mandatory fields */
1759 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1760 section_name, "pci_bdf",
1761 "entry not allowed (port_mask is provided)");
1763 PARSE_ERROR_MESSAGE((pci_bdf_present),
1764 section_name, "pci_bdf",
1765 "this entry is mandatory (port_mask is not "
1774 parse_rxq(struct app_params *app,
1775 const char *section_name,
1776 struct rte_cfgfile *cfg)
1778 struct app_pktq_hwq_in_params *param;
1779 struct rte_cfgfile_entry *entries;
1783 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1784 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1786 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1787 PARSE_ERROR_MALLOC(entries != NULL);
1789 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1791 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1792 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1794 param = &app->hwq_in_params[param_idx];
1796 for (i = 0; i < n_entries; i++) {
1797 struct rte_cfgfile_entry *ent = &entries[i];
1799 if (strcmp(ent->name, "mempool") == 0) {
1800 int status = validate_name(ent->value,
1804 PARSE_ERROR((status == 0), section_name,
1806 idx = APP_PARAM_ADD(app->mempool_params,
1808 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1810 param->mempool_id = idx;
1814 if (strcmp(ent->name, "size") == 0) {
1815 int status = parser_read_uint32(¶m->size,
1818 PARSE_ERROR((status == 0), section_name,
1823 if (strcmp(ent->name, "burst") == 0) {
1824 int status = parser_read_uint32(¶m->burst,
1827 PARSE_ERROR((status == 0), section_name,
1833 PARSE_ERROR_INVALID(0, section_name, ent->name);
1842 parse_txq(struct app_params *app,
1843 const char *section_name,
1844 struct rte_cfgfile *cfg)
1846 struct app_pktq_hwq_out_params *param;
1847 struct rte_cfgfile_entry *entries;
1851 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1852 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1854 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1855 PARSE_ERROR_MALLOC(entries != NULL);
1857 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1859 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1860 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1862 param = &app->hwq_out_params[param_idx];
1864 for (i = 0; i < n_entries; i++) {
1865 struct rte_cfgfile_entry *ent = &entries[i];
1867 if (strcmp(ent->name, "size") == 0) {
1868 int status = parser_read_uint32(¶m->size,
1871 PARSE_ERROR((status == 0), section_name,
1876 if (strcmp(ent->name, "burst") == 0) {
1877 int status = parser_read_uint32(¶m->burst,
1880 PARSE_ERROR((status == 0), section_name,
1885 if (strcmp(ent->name, "dropless") == 0) {
1886 int status = parser_read_arg_bool(ent->value);
1889 PARSE_ERROR((status != -EINVAL), section_name,
1891 param->dropless = status;
1896 PARSE_ERROR_INVALID(0, section_name, ent->name);
1905 parse_swq(struct app_params *app,
1906 const char *section_name,
1907 struct rte_cfgfile *cfg)
1909 struct app_pktq_swq_params *param;
1910 struct rte_cfgfile_entry *entries;
1912 uint32_t mtu_present = 0;
1913 uint32_t metadata_size_present = 0;
1914 uint32_t mempool_direct_present = 0;
1915 uint32_t mempool_indirect_present = 0;
1919 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1920 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1922 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1923 PARSE_ERROR_MALLOC(entries != NULL);
1925 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1927 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1928 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1930 param = &app->swq_params[param_idx];
1932 for (i = 0; i < n_entries; i++) {
1933 struct rte_cfgfile_entry *ent = &entries[i];
1935 if (strcmp(ent->name, "size") == 0) {
1936 int status = parser_read_uint32(¶m->size,
1939 PARSE_ERROR((status == 0), section_name,
1944 if (strcmp(ent->name, "burst_read") == 0) {
1945 int status = parser_read_uint32(&
1946 param->burst_read, ent->value);
1948 PARSE_ERROR((status == 0), section_name,
1953 if (strcmp(ent->name, "burst_write") == 0) {
1954 int status = parser_read_uint32(
1955 ¶m->burst_write, ent->value);
1957 PARSE_ERROR((status == 0), section_name,
1962 if (strcmp(ent->name, "dropless") == 0) {
1963 int status = parser_read_arg_bool(ent->value);
1965 PARSE_ERROR((status != -EINVAL), section_name,
1967 param->dropless = status;
1971 if (strcmp(ent->name, "n_retries") == 0) {
1972 int status = parser_read_uint64(¶m->n_retries,
1975 PARSE_ERROR((status == 0), section_name,
1980 if (strcmp(ent->name, "cpu") == 0) {
1981 int status = parser_read_uint32(
1982 ¶m->cpu_socket_id, ent->value);
1984 PARSE_ERROR((status == 0), section_name, ent->name);
1988 if (strcmp(ent->name, "ipv4_frag") == 0) {
1989 int status = parser_read_arg_bool(ent->value);
1991 PARSE_ERROR((status != -EINVAL), section_name,
1994 param->ipv4_frag = status;
1995 if (param->mtu == 0)
2001 if (strcmp(ent->name, "ipv6_frag") == 0) {
2002 int status = parser_read_arg_bool(ent->value);
2004 PARSE_ERROR((status != -EINVAL), section_name,
2006 param->ipv6_frag = status;
2007 if (param->mtu == 0)
2012 if (strcmp(ent->name, "ipv4_ras") == 0) {
2013 int status = parser_read_arg_bool(ent->value);
2015 PARSE_ERROR((status != -EINVAL), section_name,
2017 param->ipv4_ras = status;
2021 if (strcmp(ent->name, "ipv6_ras") == 0) {
2022 int status = parser_read_arg_bool(ent->value);
2024 PARSE_ERROR((status != -EINVAL), section_name,
2026 param->ipv6_ras = status;
2030 if (strcmp(ent->name, "mtu") == 0) {
2031 int status = parser_read_uint32(¶m->mtu,
2034 PARSE_ERROR((status == 0), section_name,
2040 if (strcmp(ent->name, "metadata_size") == 0) {
2041 int status = parser_read_uint32(
2042 ¶m->metadata_size, ent->value);
2044 PARSE_ERROR((status == 0), section_name,
2046 metadata_size_present = 1;
2050 if (strcmp(ent->name, "mempool_direct") == 0) {
2051 int status = validate_name(ent->value,
2055 PARSE_ERROR((status == 0), section_name,
2058 idx = APP_PARAM_ADD(app->mempool_params,
2060 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2062 param->mempool_direct_id = idx;
2063 mempool_direct_present = 1;
2067 if (strcmp(ent->name, "mempool_indirect") == 0) {
2068 int status = validate_name(ent->value,
2072 PARSE_ERROR((status == 0), section_name,
2074 idx = APP_PARAM_ADD(app->mempool_params,
2076 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2078 param->mempool_indirect_id = idx;
2079 mempool_indirect_present = 1;
2084 PARSE_ERROR_INVALID(0, section_name, ent->name);
2087 APP_CHECK(((mtu_present) &&
2088 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2089 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2090 "is off, therefore entry \"mtu\" is not allowed",
2093 APP_CHECK(((metadata_size_present) &&
2094 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2095 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2096 "is off, therefore entry \"metadata_size\" is "
2097 "not allowed", section_name);
2099 APP_CHECK(((mempool_direct_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_direct\" is "
2103 "not allowed", section_name);
2105 APP_CHECK(((mempool_indirect_present) &&
2106 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2107 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2108 "is off, therefore entry \"mempool_indirect\" is "
2109 "not allowed", section_name);
2117 parse_tm(struct app_params *app,
2118 const char *section_name,
2119 struct rte_cfgfile *cfg)
2121 struct app_pktq_tm_params *param;
2122 struct rte_cfgfile_entry *entries;
2126 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2127 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2129 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2130 PARSE_ERROR_MALLOC(entries != NULL);
2132 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2134 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2135 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2137 param = &app->tm_params[param_idx];
2139 for (i = 0; i < n_entries; i++) {
2140 struct rte_cfgfile_entry *ent = &entries[i];
2142 if (strcmp(ent->name, "cfg") == 0) {
2143 param->file_name = strdup(ent->value);
2144 PARSE_ERROR_MALLOC(param->file_name != NULL);
2148 if (strcmp(ent->name, "burst_read") == 0) {
2149 int status = parser_read_uint32(
2150 ¶m->burst_read, ent->value);
2152 PARSE_ERROR((status == 0), section_name,
2157 if (strcmp(ent->name, "burst_write") == 0) {
2158 int status = parser_read_uint32(
2159 ¶m->burst_write, ent->value);
2161 PARSE_ERROR((status == 0), section_name,
2167 PARSE_ERROR_INVALID(0, section_name, ent->name);
2176 parse_source(struct app_params *app,
2177 const char *section_name,
2178 struct rte_cfgfile *cfg)
2180 struct app_pktq_source_params *param;
2181 struct rte_cfgfile_entry *entries;
2184 uint32_t pcap_file_present = 0;
2185 uint32_t pcap_size_present = 0;
2187 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2188 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2190 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2191 PARSE_ERROR_MALLOC(entries != NULL);
2193 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2195 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2196 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2198 param = &app->source_params[param_idx];
2200 for (i = 0; i < n_entries; i++) {
2201 struct rte_cfgfile_entry *ent = &entries[i];
2203 if (strcmp(ent->name, "mempool") == 0) {
2204 int status = validate_name(ent->value,
2208 PARSE_ERROR((status == 0), section_name,
2210 idx = APP_PARAM_ADD(app->mempool_params,
2212 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2214 param->mempool_id = idx;
2218 if (strcmp(ent->name, "burst") == 0) {
2219 int status = parser_read_uint32(¶m->burst,
2222 PARSE_ERROR((status == 0), section_name,
2227 if (strcmp(ent->name, "pcap_file_rd")) {
2228 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2229 section_name, ent->name);
2231 param->file_name = strdup(ent->value);
2233 PARSE_ERROR_MALLOC(param->file_name != NULL);
2234 pcap_file_present = 1;
2239 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2242 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2243 section_name, ent->name);
2245 status = parser_read_uint32(
2246 ¶m->n_bytes_per_pkt, ent->value);
2248 PARSE_ERROR((status == 0), section_name,
2250 pcap_size_present = 1;
2256 PARSE_ERROR_INVALID(0, section_name, ent->name);
2265 parse_sink(struct app_params *app,
2266 const char *section_name,
2267 struct rte_cfgfile *cfg)
2269 struct app_pktq_sink_params *param;
2270 struct rte_cfgfile_entry *entries;
2273 uint32_t pcap_file_present = 0;
2274 uint32_t pcap_n_pkt_present = 0;
2276 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2277 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2279 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2280 PARSE_ERROR_MALLOC(entries != NULL);
2282 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2284 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2285 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2287 param = &app->sink_params[param_idx];
2289 for (i = 0; i < n_entries; i++) {
2290 struct rte_cfgfile_entry *ent = &entries[i];
2292 if (strcmp(ent->name, "pcap_file_wr")) {
2293 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2294 section_name, ent->name);
2296 param->file_name = strdup(ent->value);
2298 PARSE_ERROR_MALLOC((param->file_name != NULL));
2303 if (strcmp(ent->name, "pcap_n_pkt_wr")) {
2306 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2307 section_name, ent->name);
2309 status = parser_read_uint32(
2310 ¶m->n_pkts_to_dump, ent->value);
2312 PARSE_ERROR((status == 0), section_name,
2319 PARSE_ERROR_INVALID(0, section_name, ent->name);
2328 parse_msgq_req_pipeline(struct app_params *app,
2329 const char *section_name,
2330 struct rte_cfgfile *cfg)
2332 struct app_msgq_params *param;
2333 struct rte_cfgfile_entry *entries;
2337 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2338 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2340 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2341 PARSE_ERROR_MALLOC(entries != NULL);
2343 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2345 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2346 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2348 param = &app->msgq_params[param_idx];
2350 for (i = 0; i < n_entries; i++) {
2351 struct rte_cfgfile_entry *ent = &entries[i];
2353 if (strcmp(ent->name, "size") == 0) {
2354 int status = parser_read_uint32(¶m->size,
2357 PARSE_ERROR((status == 0), section_name,
2363 PARSE_ERROR_INVALID(0, section_name, ent->name);
2371 parse_msgq_rsp_pipeline(struct app_params *app,
2372 const char *section_name,
2373 struct rte_cfgfile *cfg)
2375 struct app_msgq_params *param;
2376 struct rte_cfgfile_entry *entries;
2380 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2381 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2383 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2384 PARSE_ERROR_MALLOC(entries != NULL);
2386 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2388 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2389 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2391 param = &app->msgq_params[param_idx];
2393 for (i = 0; i < n_entries; i++) {
2394 struct rte_cfgfile_entry *ent = &entries[i];
2396 if (strcmp(ent->name, "size") == 0) {
2397 int status = parser_read_uint32(¶m->size,
2400 PARSE_ERROR((status == 0), section_name,
2406 PARSE_ERROR_INVALID(0, section_name, ent->name);
2415 parse_msgq(struct app_params *app,
2416 const char *section_name,
2417 struct rte_cfgfile *cfg)
2419 struct app_msgq_params *param;
2420 struct rte_cfgfile_entry *entries;
2424 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2425 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2427 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2428 PARSE_ERROR_MALLOC(entries != NULL);
2430 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2432 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2433 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2435 param = &app->msgq_params[param_idx];
2437 for (i = 0; i < n_entries; i++) {
2438 struct rte_cfgfile_entry *ent = &entries[i];
2440 if (strcmp(ent->name, "size") == 0) {
2441 int status = parser_read_uint32(¶m->size,
2444 PARSE_ERROR((status == 0), section_name,
2449 if (strcmp(ent->name, "cpu") == 0) {
2450 int status = parser_read_uint32(
2451 ¶m->cpu_socket_id, ent->value);
2453 PARSE_ERROR((status == 0), section_name,
2459 PARSE_ERROR_INVALID(0, section_name, ent->name);
2467 typedef void (*config_section_load)(struct app_params *p,
2468 const char *section_name,
2469 struct rte_cfgfile *cfg);
2471 struct config_section {
2472 const char prefix[CFG_NAME_LEN];
2474 config_section_load load;
2477 static const struct config_section cfg_file_scheme[] = {
2478 {"EAL", 0, parse_eal},
2479 {"PIPELINE", 1, parse_pipeline},
2480 {"MEMPOOL", 1, parse_mempool},
2481 {"LINK", 1, parse_link},
2482 {"RXQ", 2, parse_rxq},
2483 {"TXQ", 2, parse_txq},
2484 {"SWQ", 1, parse_swq},
2485 {"TM", 1, parse_tm},
2486 {"SOURCE", 1, parse_source},
2487 {"SINK", 1, parse_sink},
2488 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2489 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2490 {"MSGQ", 1, parse_msgq},
2494 create_implicit_mempools(struct app_params *app)
2498 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2499 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2503 create_implicit_links_from_port_mask(struct app_params *app,
2506 uint32_t pmd_id, link_id;
2509 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2510 char name[APP_PARAM_NAME_SIZE];
2513 if ((port_mask & (1LLU << pmd_id)) == 0)
2516 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2517 idx = APP_PARAM_ADD(app->link_params, name);
2518 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2520 app->link_params[idx].pmd_id = pmd_id;
2526 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2530 for (i = 0; i < app->n_links; i++) {
2531 struct app_link_params *link = &app->link_params[i];
2538 app_config_parse(struct app_params *app, const char *file_name)
2540 struct rte_cfgfile *cfg;
2541 char **section_names;
2542 int i, j, sect_count;
2544 /* Implicit mempools */
2545 create_implicit_mempools(app);
2549 create_implicit_links_from_port_mask(app, app->port_mask);
2551 /* Load application configuration file */
2552 cfg = rte_cfgfile_load(file_name, 0);
2553 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2554 "file %s", file_name);
2556 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2557 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2558 "in file \"%s\" return %d", file_name,
2561 section_names = malloc(sect_count * sizeof(char *));
2562 PARSE_ERROR_MALLOC(section_names != NULL);
2564 for (i = 0; i < sect_count; i++)
2565 section_names[i] = malloc(CFG_NAME_LEN);
2567 rte_cfgfile_sections(cfg, section_names, sect_count);
2569 for (i = 0; i < sect_count; i++) {
2570 const struct config_section *sch_s;
2571 int len, cfg_name_len;
2573 cfg_name_len = strlen(section_names[i]);
2575 /* Find section type */
2576 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2577 sch_s = &cfg_file_scheme[j];
2578 len = strlen(sch_s->prefix);
2580 if (cfg_name_len < len)
2583 /* After section name we expect only '\0' or digit or
2584 * digit dot digit, so protect against false matching,
2585 * for example: "ABC" should match section name
2586 * "ABC0.0", but it should not match section_name
2589 if ((section_names[i][len] != '\0') &&
2590 !isdigit(section_names[i][len]))
2593 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2597 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2598 "Parse error: unknown section %s",
2601 APP_CHECK(validate_name(section_names[i],
2603 sch_s->numbers) == 0,
2604 "Parse error: invalid section name \"%s\"",
2607 sch_s->load(app, section_names[i], cfg);
2610 for (i = 0; i < sect_count; i++)
2611 free(section_names[i]);
2613 free(section_names);
2615 rte_cfgfile_close(cfg);
2617 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2618 APP_PARAM_COUNT(app->link_params, app->n_links);
2619 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2620 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2621 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2622 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2623 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2624 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2625 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2626 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2628 #ifdef RTE_PORT_PCAP
2629 for (i = 0; i < (int)app->n_pktq_source; i++) {
2630 struct app_pktq_source_params *p = &app->source_params[i];
2632 APP_CHECK((p->file_name), "Parse error: missing "
2633 "mandatory field \"pcap_file_rd\" for \"%s\"",
2637 for (i = 0; i < (int)app->n_pktq_source; i++) {
2638 struct app_pktq_source_params *p = &app->source_params[i];
2640 APP_CHECK((!p->file_name), "Parse error: invalid field "
2641 "\"pcap_file_rd\" for \"%s\"", p->name);
2645 if (app->port_mask == 0)
2646 assign_link_pmd_id_from_pci_bdf(app);
2648 /* Save configuration to output file */
2649 app_config_save(app, app->output_file);
2651 /* Load TM configuration files */
2652 app_config_parse_tm(app);
2658 save_eal_params(struct app_params *app, FILE *f)
2660 struct app_eal_params *p = &app->eal_params;
2663 fprintf(f, "[EAL]\n");
2666 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2668 if (p->master_lcore_present)
2669 fprintf(f, "%s = %" PRIu32 "\n",
2670 "master_lcore", p->master_lcore);
2672 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2674 if (p->memory_present)
2675 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2677 if (p->ranks_present)
2678 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2680 for (i = 0; i < APP_MAX_LINKS; i++) {
2681 if (p->pci_blacklist[i] == NULL)
2684 fprintf(f, "%s = %s\n", "pci_blacklist",
2685 p->pci_blacklist[i]);
2688 for (i = 0; i < APP_MAX_LINKS; i++) {
2689 if (p->pci_whitelist[i] == NULL)
2692 fprintf(f, "%s = %s\n", "pci_whitelist",
2693 p->pci_whitelist[i]);
2696 for (i = 0; i < APP_MAX_LINKS; i++) {
2697 if (p->vdev[i] == NULL)
2700 fprintf(f, "%s = %s\n", "vdev",
2704 if (p->vmware_tsc_map_present)
2705 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2706 (p->vmware_tsc_map) ? "yes" : "no");
2709 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2712 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2714 if (p->log_level_present)
2715 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2717 if (p->version_present)
2718 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2720 if (p->help_present)
2721 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2723 if (p->no_huge_present)
2724 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2726 if (p->no_pci_present)
2727 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2729 if (p->no_hpet_present)
2730 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2732 if (p->no_shconf_present)
2733 fprintf(f, "%s = %s\n", "no_shconf",
2734 (p->no_shconf) ? "yes" : "no");
2737 fprintf(f, "%s = %s\n", "d", p->add_driver);
2740 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2743 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2746 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2748 if (p->base_virtaddr)
2749 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2751 if (p->create_uio_dev_present)
2752 fprintf(f, "%s = %s\n", "create_uio_dev",
2753 (p->create_uio_dev) ? "yes" : "no");
2756 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2758 if (p->xen_dom0_present)
2759 fprintf(f, "%s = %s\n", "xen_dom0",
2760 (p->xen_dom0) ? "yes" : "no");
2766 save_mempool_params(struct app_params *app, FILE *f)
2768 struct app_mempool_params *p;
2771 count = RTE_DIM(app->mempool_params);
2772 for (i = 0; i < count; i++) {
2773 p = &app->mempool_params[i];
2774 if (!APP_PARAM_VALID(p))
2777 fprintf(f, "[%s]\n", p->name);
2778 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2779 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2780 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2781 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2788 save_links_params(struct app_params *app, FILE *f)
2790 struct app_link_params *p;
2793 count = RTE_DIM(app->link_params);
2794 for (i = 0; i < count; i++) {
2795 p = &app->link_params[i];
2796 if (!APP_PARAM_VALID(p))
2799 fprintf(f, "[%s]\n", p->name);
2800 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2801 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2802 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2803 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2805 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2806 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2807 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2808 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2811 if (strlen(p->pci_bdf))
2812 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2819 save_rxq_params(struct app_params *app, FILE *f)
2821 struct app_pktq_hwq_in_params *p;
2824 count = RTE_DIM(app->hwq_in_params);
2825 for (i = 0; i < count; i++) {
2826 p = &app->hwq_in_params[i];
2827 if (!APP_PARAM_VALID(p))
2830 fprintf(f, "[%s]\n", p->name);
2831 fprintf(f, "%s = %s\n",
2833 app->mempool_params[p->mempool_id].name);
2834 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2835 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2842 save_txq_params(struct app_params *app, FILE *f)
2844 struct app_pktq_hwq_out_params *p;
2847 count = RTE_DIM(app->hwq_out_params);
2848 for (i = 0; i < count; i++) {
2849 p = &app->hwq_out_params[i];
2850 if (!APP_PARAM_VALID(p))
2853 fprintf(f, "[%s]\n", p->name);
2854 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2855 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2856 fprintf(f, "%s = %s\n",
2858 p->dropless ? "yes" : "no");
2865 save_swq_params(struct app_params *app, FILE *f)
2867 struct app_pktq_swq_params *p;
2870 count = RTE_DIM(app->swq_params);
2871 for (i = 0; i < count; i++) {
2872 p = &app->swq_params[i];
2873 if (!APP_PARAM_VALID(p))
2876 fprintf(f, "[%s]\n", p->name);
2877 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2878 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2879 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2880 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2881 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2882 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2883 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2884 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2885 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2886 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2887 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2888 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2889 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2890 fprintf(f, "%s = %s\n",
2892 app->mempool_params[p->mempool_direct_id].name);
2893 fprintf(f, "%s = %s\n",
2895 app->mempool_params[p->mempool_indirect_id].name);
2903 save_tm_params(struct app_params *app, FILE *f)
2905 struct app_pktq_tm_params *p;
2908 count = RTE_DIM(app->tm_params);
2909 for (i = 0; i < count; i++) {
2910 p = &app->tm_params[i];
2911 if (!APP_PARAM_VALID(p))
2914 fprintf(f, "[%s]\n", p->name);
2915 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2916 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2917 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2924 save_source_params(struct app_params *app, FILE *f)
2926 struct app_pktq_source_params *p;
2929 count = RTE_DIM(app->source_params);
2930 for (i = 0; i < count; i++) {
2931 p = &app->source_params[i];
2932 if (!APP_PARAM_VALID(p))
2935 fprintf(f, "[%s]\n", p->name);
2936 fprintf(f, "%s = %s\n",
2938 app->mempool_params[p->mempool_id].name);
2939 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2940 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2941 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2942 p->n_bytes_per_pkt);
2948 save_sink_params(struct app_params *app, FILE *f)
2950 struct app_pktq_sink_params *p;
2953 count = RTE_DIM(app->sink_params);
2954 for (i = 0; i < count; i++) {
2955 p = &app->sink_params[i];
2956 if (!APP_PARAM_VALID(p))
2959 fprintf(f, "[%s]\n", p->name);
2960 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2961 fprintf(f, "%s = %" PRIu32 "\n",
2962 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2968 save_msgq_params(struct app_params *app, FILE *f)
2970 struct app_msgq_params *p;
2973 count = RTE_DIM(app->msgq_params);
2974 for (i = 0; i < count; i++) {
2975 p = &app->msgq_params[i];
2976 if (!APP_PARAM_VALID(p))
2979 fprintf(f, "[%s]\n", p->name);
2980 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2981 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2988 save_pipeline_params(struct app_params *app, FILE *f)
2992 count = RTE_DIM(app->pipeline_params);
2993 for (i = 0; i < count; i++) {
2994 struct app_pipeline_params *p = &app->pipeline_params[i];
2996 if (!APP_PARAM_VALID(p))
3000 fprintf(f, "[%s]\n", p->name);
3003 fprintf(f, "type = %s\n", p->type);
3006 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
3009 (p->hyper_th_id) ? "h" : "");
3015 fprintf(f, "pktq_in =");
3016 for (j = 0; j < p->n_pktq_in; j++) {
3017 struct app_pktq_in_params *pp = &p->pktq_in[j];
3021 case APP_PKTQ_IN_HWQ:
3022 name = app->hwq_in_params[pp->id].name;
3024 case APP_PKTQ_IN_SWQ:
3025 name = app->swq_params[pp->id].name;
3027 case APP_PKTQ_IN_TM:
3028 name = app->tm_params[pp->id].name;
3030 case APP_PKTQ_IN_SOURCE:
3031 name = app->source_params[pp->id].name;
3034 APP_CHECK(0, "System error "
3035 "occurred while saving "
3036 "parameter to file");
3039 fprintf(f, " %s", name);
3045 if (p->n_pktq_out) {
3048 fprintf(f, "pktq_out =");
3049 for (j = 0; j < p->n_pktq_out; j++) {
3050 struct app_pktq_out_params *pp =
3055 case APP_PKTQ_OUT_HWQ:
3056 name = app->hwq_out_params[pp->id].name;
3058 case APP_PKTQ_OUT_SWQ:
3059 name = app->swq_params[pp->id].name;
3061 case APP_PKTQ_OUT_TM:
3062 name = app->tm_params[pp->id].name;
3064 case APP_PKTQ_OUT_SINK:
3065 name = app->sink_params[pp->id].name;
3068 APP_CHECK(0, "System error "
3069 "occurred while saving "
3070 "parameter to file");
3073 fprintf(f, " %s", name);
3082 fprintf(f, "msgq_in =");
3083 for (j = 0; j < p->n_msgq_in; j++) {
3084 uint32_t id = p->msgq_in[j];
3085 char *name = app->msgq_params[id].name;
3087 fprintf(f, " %s", name);
3093 if (p->n_msgq_out) {
3096 fprintf(f, "msgq_out =");
3097 for (j = 0; j < p->n_msgq_out; j++) {
3098 uint32_t id = p->msgq_out[j];
3099 char *name = app->msgq_params[id].name;
3101 fprintf(f, " %s", name);
3107 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3113 for (j = 0; j < p->n_args; j++)
3114 fprintf(f, "%s = %s\n", p->args_name[j],
3123 app_config_save(struct app_params *app, const char *file_name)
3126 char *name, *dir_name;
3129 name = strdup(file_name);
3130 dir_name = dirname(name);
3131 status = access(dir_name, W_OK);
3132 APP_CHECK((status == 0),
3133 "Error: need write access privilege to directory "
3134 "\"%s\" to save configuration\n", dir_name);
3136 file = fopen(file_name, "w");
3137 APP_CHECK((file != NULL),
3138 "Error: failed to save configuration to file \"%s\"",
3141 save_eal_params(app, file);
3142 save_pipeline_params(app, file);
3143 save_mempool_params(app, file);
3144 save_links_params(app, file);
3145 save_rxq_params(app, file);
3146 save_txq_params(app, file);
3147 save_swq_params(app, file);
3148 save_tm_params(app, file);
3149 save_source_params(app, file);
3150 save_sink_params(app, file);
3151 save_msgq_params(app, file);
3158 app_config_init(struct app_params *app)
3162 memcpy(app, &app_params_default, sizeof(struct app_params));
3164 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3165 memcpy(&app->mempool_params[i],
3166 &mempool_params_default,
3167 sizeof(struct app_mempool_params));
3169 for (i = 0; i < RTE_DIM(app->link_params); i++)
3170 memcpy(&app->link_params[i],
3171 &link_params_default,
3172 sizeof(struct app_link_params));
3174 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3175 memcpy(&app->hwq_in_params[i],
3176 &default_hwq_in_params,
3177 sizeof(default_hwq_in_params));
3179 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3180 memcpy(&app->hwq_out_params[i],
3181 &default_hwq_out_params,
3182 sizeof(default_hwq_out_params));
3184 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3185 memcpy(&app->swq_params[i],
3186 &default_swq_params,
3187 sizeof(default_swq_params));
3189 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3190 memcpy(&app->tm_params[i],
3192 sizeof(default_tm_params));
3194 for (i = 0; i < RTE_DIM(app->source_params); i++)
3195 memcpy(&app->source_params[i],
3196 &default_source_params,
3197 sizeof(default_source_params));
3199 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3200 memcpy(&app->sink_params[i],
3201 &default_sink_params,
3202 sizeof(default_sink_params));
3204 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3205 memcpy(&app->msgq_params[i],
3206 &default_msgq_params,
3207 sizeof(default_msgq_params));
3209 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3210 memcpy(&app->pipeline_params[i],
3211 &default_pipeline_params,
3212 sizeof(default_pipeline_params));
3218 filenamedup(const char *filename, const char *suffix)
3220 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3225 sprintf(s, "%s%s", filename, suffix);
3230 app_config_args(struct app_params *app, int argc, char **argv)
3232 const char *optname;
3233 int opt, option_index;
3234 int f_present, s_present, p_present, l_present;
3235 int preproc_present, preproc_params_present, disable_csum_present;
3237 int flow_dir_present;
3240 static struct option lgopts[] = {
3241 { "disable-hw-csum", 0, 0, 0 },
3242 { "preproc", 1, 0, 0 },
3243 { "preproc-args", 1, 0, 0 },
3244 { "hwlb", 1, 0, 0 },
3245 { "flow_dir", 0, 0, 0 },
3249 /* Copy application name */
3250 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3256 disable_csum_present = 0;
3257 preproc_present = 0;
3258 preproc_params_present = 0;
3259 app->header_csum_req =1; //Default enable haeader checksum
3261 flow_dir_present = 0;
3264 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3265 &option_index)) != EOF)
3269 rte_panic("Error: Config file is provided "
3270 "more than once\n");
3273 /* REST API not needed as user has supplied the config file */
3276 if (!strlen(optarg))
3277 rte_panic("Error: Config file name is null\n");
3279 app->config_file = strdup(optarg);
3280 if (app->config_file == NULL)
3281 rte_panic("Error: Memory allocation failure\n");
3288 rte_panic("Error: Script file is provided "
3289 "more than once\n");
3292 if (!strlen(optarg))
3293 rte_panic("Error: Script file name is null\n");
3295 app->script_file = strdup(optarg);
3296 if (app->script_file == NULL)
3297 rte_panic("Error: Memory allocation failure\n");
3303 rte_panic("Error: PORT_MASK is provided "
3304 "more than once\n");
3307 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3309 ((size_t) scaned != strlen(optarg)))
3310 rte_panic("Error: PORT_MASK is not "
3311 "a hexadecimal integer\n");
3313 if (app->port_mask == 0)
3314 rte_panic("Error: PORT_MASK is null\n");
3320 rte_panic("Error: LOG_LEVEL is provided "
3321 "more than once\n");
3324 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3326 ((size_t) scaned != strlen(optarg)) ||
3327 (app->log_level >= APP_LOG_LEVELS))
3328 rte_panic("Error: LOG_LEVEL invalid value\n");
3333 optname = lgopts[option_index].name;
3335 if (strcmp(optname, "hwlb") == 0) {
3337 rte_panic("Error: hwlb argument "
3338 "is provided more than once\n");
3340 printf(" HWLB is configured\n");
3342 app->n_hwlb_q = atoi(optarg);
3345 rte_panic("HWQs for HWLB must be atleast 1\n");
3347 printf("No of HWQs for HWLB are %d\n",app->n_hwlb_q);
3352 if (strcmp(optname, "flow_dir") == 0) {
3353 if (flow_dir_present)
3354 rte_panic("Error: flow_dir argument "
3355 "is provided more than once\n");
3356 flow_dir_present = 1;
3357 printf(" FLOW DIR is configured\n");
3359 enable_flow_dir = 1;
3364 if (strcmp(optname, "disable-hw-csum") == 0) {
3365 if (disable_csum_present)
3366 rte_panic("Error: disable-hw-csum argument "
3367 "is provided more than once\n");
3369 printf("Disable TCP/UDP HW checksumi\n");
3370 app->header_csum_req = 0;
3371 disable_csum_present = 1;
3375 if (strcmp(optname, "preproc") == 0) {
3376 if (preproc_present)
3377 rte_panic("Error: Preprocessor argument "
3378 "is provided more than once\n");
3379 preproc_present = 1;
3381 app->preproc = strdup(optarg);
3385 if (strcmp(optname, "preproc-args") == 0) {
3386 if (preproc_params_present)
3387 rte_panic("Error: Preprocessor args "
3388 "are provided more than once\n");
3389 preproc_params_present = 1;
3391 app->preproc_args = strdup(optarg);
3395 app_print_usage(argv[0]);
3399 app_print_usage(argv[0]);
3402 optind = 0; /* reset getopt lib */
3404 /* Check dependencies between args */
3405 if (preproc_params_present && (preproc_present == 0))
3406 rte_panic("Error: Preprocessor args specified while "
3407 "preprocessor is not defined\n");
3409 app->parser_file = preproc_present ?
3410 filenamedup(app->config_file, ".preproc") :
3411 strdup(app->config_file);
3412 app->output_file = filenamedup(app->config_file, ".out");
3418 app_config_preproc(struct app_params *app)
3423 if (app->preproc == NULL)
3426 status = access(app->config_file, F_OK | R_OK);
3427 APP_CHECK((status == 0), "Error: Unable to open file %s",
3430 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3432 app->preproc_args ? app->preproc_args : "",
3436 status = system(buffer);
3437 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3438 "Error occurred while pre-processing file \"%s\"\n",