4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 #include <rte_errno.h>
46 #include <rte_cfgfile.h>
47 #include <rte_string_fns.h>
53 * Default config values
56 static struct app_params app_params_default = {
57 .config_file = "./config/ip_pipeline.cfg",
58 .log_level = APP_LOG_LEVEL_HIGH,
66 static const struct app_mempool_params mempool_params_default = {
68 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
69 .pool_size = 32 * 1024,
74 static const struct app_link_params link_params_default = {
93 .mq_mode = ETH_MQ_RX_NONE,
95 .header_split = 0, /* Header split */
96 .hw_ip_checksum = 0, /* IP checksum offload */
97 .hw_vlan_filter = 0, /* VLAN filtering */
98 .hw_vlan_strip = 0, /* VLAN strip */
99 .hw_vlan_extend = 0, /* Extended VLAN */
100 .jumbo_frame = 0, /* Jumbo frame support */
101 .hw_strip_crc = 0, /* CRC strip by HW */
102 .enable_scatter = 0, /* Scattered packets RX handler */
104 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
105 .split_hdr_size = 0, /* Header split buffer size */
108 .mq_mode = ETH_MQ_TX_NONE,
116 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
128 .rx_free_thresh = 64,
130 .rx_deferred_start = 0,
134 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
149 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
150 ETH_TXQ_FLAGS_NOOFFLOADS,
151 .tx_deferred_start = 0,
155 static const struct app_pktq_swq_params default_swq_params = {
169 .mempool_direct_id = 0,
170 .mempool_indirect_id = 0,
173 struct app_pktq_tm_params default_tm_params = {
175 .file_name = "./config/tm_profile.cfg",
180 struct app_pktq_source_params default_source_params = {
185 .n_bytes_per_pkt = 0,
188 struct app_pktq_sink_params default_sink_params = {
192 struct app_msgq_params default_msgq_params = {
198 struct app_pipeline_params default_pipeline_params = {
211 static const char app_usage[] =
212 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
213 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
216 "\t-f CONFIG_FILE: Default config file is %s\n"
217 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
218 "config file when not provided)\n"
219 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
220 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
221 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
222 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
226 app_print_usage(char *prgname)
228 rte_exit(0, app_usage, prgname, app_params_default.config_file);
231 #define skip_white_spaces(pos) \
233 __typeof__(pos) _p = (pos); \
234 for ( ; isspace(*_p); _p++); \
238 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
240 APP_CHECK((result != -EINVAL), \
241 "Parse error: no free memory"); \
242 APP_CHECK((result != -ENOMEM), \
243 "Parse error: too many \"%s\" sections", section_name); \
244 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
245 "Parse error: duplicate \"%s\" section", section_name); \
246 APP_CHECK((result >= 0), \
247 "Parse error in section \"%s\"", section_name); \
251 parser_read_arg_bool(const char *p)
253 p = skip_white_spaces(p);
254 int result = -EINVAL;
256 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
257 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
262 if (((p[0] == 'o') && (p[1] == 'n')) ||
263 ((p[0] == 'O') && (p[1] == 'N'))) {
268 if (((p[0] == 'n') && (p[1] == 'o')) ||
269 ((p[0] == 'N') && (p[1] == 'O'))) {
274 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
275 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
280 p = skip_white_spaces(p);
288 #define PARSE_ERROR(exp, section, entry) \
289 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
291 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
292 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n", \
293 section, entry, message)
296 #define PARSE_ERROR_MALLOC(exp) \
297 APP_CHECK(exp, "Parse error: no free memory\n")
299 #define PARSE_ERROR_SECTION(exp, section) \
300 APP_CHECK(exp, "Parse error in section \"%s\"", section)
302 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
303 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
305 #define PARSE_WARNING_IGNORED(exp, section, entry) \
308 fprintf(stderr, "Parse warning in section \"%s\": " \
309 "entry \"%s\" is ignored\n", section, entry); \
312 #define PARSE_ERROR_INVALID(exp, section, entry) \
313 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
316 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
317 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
321 parser_read_uint64(uint64_t *value, const char *p)
326 p = skip_white_spaces(p);
330 val = strtoul(p, &next, 10);
352 p = skip_white_spaces(p);
361 parser_read_uint32(uint32_t *value, const char *p)
364 int ret = parser_read_uint64(&val, p);
369 if (val > UINT32_MAX)
377 parse_pipeline_core(uint32_t *socket,
385 uint32_t s = 0, c = 0, h = 0, val;
386 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
387 const char *next = skip_white_spaces(entry);
390 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
391 while (*next != '\0') {
392 /* If everything parsed nothing should left */
393 if (s_parsed && c_parsed && h_parsed)
400 if (s_parsed || c_parsed || h_parsed)
407 if (c_parsed || h_parsed)
420 /* If it start from digit it must be only core id. */
421 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
427 for (num_len = 0; *next != '\0'; next++, num_len++) {
428 if (num_len == RTE_DIM(num))
434 num[num_len] = *next;
437 if (num_len == 0 && type != 'h' && type != 'H')
440 if (num_len != 0 && (type == 'h' || type == 'H'))
444 val = strtol(num, NULL, 10);
473 case '0': case '1': case '2': case '3': case '4': case '5':
474 case '6': case '7': case '8': case '9':
476 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
478 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
486 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
491 /* Check input parameters */
499 if (((len & 3) != 0) ||
504 for (c = src; *c != 0; c++) {
505 if ((((*c) >= '0') && ((*c) <= '9')) ||
506 (((*c) >= 'A') && ((*c) <= 'F')) ||
507 (((*c) >= 'a') && ((*c) <= 'f')))
513 /* Convert chars to bytes */
514 for (i = 0; i < *size; i++)
515 dst[i] = get_hex_val(src[2 * i]) * 16 +
516 get_hex_val(src[2 * i + 1]);
522 skip_digits(const char *src)
526 for (i = 0; isdigit(src[i]); i++);
532 validate_name(const char *name, const char *prefix, int num)
536 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
537 if (name[i] != prefix[i])
541 if (prefix[i] != '\0')
552 j = skip_digits(&name[i]);
554 if ((j == 0) || (name[i] != '.'))
560 j = skip_digits(&name[i]);
562 if ((j == 0) || (name[i] != '\0'))
570 parse_eal(struct app_params *app,
571 const char *section_name,
572 struct rte_cfgfile *cfg)
574 struct app_eal_params *p = &app->eal_params;
575 struct rte_cfgfile_entry *entries;
578 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
579 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
581 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
582 PARSE_ERROR_MALLOC(entries != NULL);
584 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
586 for (i = 0; i < n_entries; i++) {
587 struct rte_cfgfile_entry *entry = &entries[i];
590 if (strcmp(entry->name, "c") == 0) {
591 PARSE_WARNING_IGNORED(0, section_name, entry->name);
596 if (strcmp(entry->name, "l") == 0) {
597 PARSE_WARNING_IGNORED(0, section_name, entry->name);
602 if (strcmp(entry->name, "lcores") == 0) {
603 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
606 p->coremap = strdup(entry->value);
611 if (strcmp(entry->name, "master_lcore") == 0) {
614 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
617 p->master_lcore_present = 1;
619 status = parser_read_uint32(&p->master_lcore,
621 PARSE_ERROR((status == 0), section_name, entry->name);
626 if (strcmp(entry->name, "n") == 0) {
629 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
632 p->channels_present = 1;
634 status = parser_read_uint32(&p->channels, entry->value);
635 PARSE_ERROR((status == 0), section_name, entry->name);
640 if (strcmp(entry->name, "m") == 0) {
643 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
646 p->memory_present = 1;
648 status = parser_read_uint32(&p->memory, entry->value);
649 PARSE_ERROR((status == 0), section_name, entry->name);
654 if (strcmp(entry->name, "r") == 0) {
657 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
660 p->ranks_present = 1;
662 status = parser_read_uint32(&p->ranks, entry->value);
663 PARSE_ERROR((status == 0), section_name, entry->name);
668 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
669 (strcmp(entry->name, "b") == 0)) {
672 for (i = 0; i < APP_MAX_LINKS; i++) {
673 if (p->pci_blacklist[i])
676 p->pci_blacklist[i] =
677 strdup(entry->value);
678 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
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]);
705 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
706 section_name, entry->name,
707 "too many elements");
712 if (strcmp(entry->name, "vdev") == 0) {
715 for (i = 0; i < APP_MAX_LINKS; i++) {
719 p->vdev[i] = strdup(entry->value);
720 PARSE_ERROR_MALLOC(p->vdev[i]);
723 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
724 section_name, entry->name,
725 "too many elements");
730 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
733 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
736 p->vmware_tsc_map_present = 1;
738 val = parser_read_arg_bool(entry->value);
739 PARSE_ERROR((val >= 0), section_name, entry->name);
740 p->vmware_tsc_map = val;
745 if (strcmp(entry->name, "proc_type") == 0) {
746 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
749 p->proc_type = strdup(entry->value);
754 if (strcmp(entry->name, "syslog") == 0) {
755 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
758 p->syslog = strdup(entry->value);
763 if (strcmp(entry->name, "log_level") == 0) {
766 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
769 p->log_level_present = 1;
771 status = parser_read_uint32(&p->log_level,
773 PARSE_ERROR((status == 0), section_name, entry->name);
778 if (strcmp(entry->name, "v") == 0) {
781 PARSE_ERROR_DUPLICATE((p->version_present == 0),
784 p->version_present = 1;
786 val = parser_read_arg_bool(entry->value);
787 PARSE_ERROR((val >= 0), section_name, entry->name);
793 if ((strcmp(entry->name, "help") == 0) ||
794 (strcmp(entry->name, "h") == 0)) {
797 PARSE_ERROR_DUPLICATE((p->help_present == 0),
802 val = parser_read_arg_bool(entry->value);
803 PARSE_ERROR((val >= 0), section_name, entry->name);
809 if (strcmp(entry->name, "no_huge") == 0) {
812 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
815 p->no_huge_present = 1;
817 val = parser_read_arg_bool(entry->value);
818 PARSE_ERROR((val >= 0), section_name, entry->name);
824 if (strcmp(entry->name, "no_pci") == 0) {
827 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
830 p->no_pci_present = 1;
832 val = parser_read_arg_bool(entry->value);
833 PARSE_ERROR((val >= 0), section_name, entry->name);
839 if (strcmp(entry->name, "no_hpet") == 0) {
842 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
845 p->no_hpet_present = 1;
847 val = parser_read_arg_bool(entry->value);
848 PARSE_ERROR((val >= 0), section_name, entry->name);
854 if (strcmp(entry->name, "no_shconf") == 0) {
857 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
860 p->no_shconf_present = 1;
862 val = parser_read_arg_bool(entry->value);
863 PARSE_ERROR((val >= 0), section_name, entry->name);
869 if (strcmp(entry->name, "d") == 0) {
870 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
873 p->add_driver = strdup(entry->value);
878 if (strcmp(entry->name, "socket_mem") == 0) {
879 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
882 p->socket_mem = strdup(entry->value);
887 if (strcmp(entry->name, "huge_dir") == 0) {
888 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
891 p->huge_dir = strdup(entry->value);
896 if (strcmp(entry->name, "file_prefix") == 0) {
897 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
900 p->file_prefix = strdup(entry->value);
905 if (strcmp(entry->name, "base_virtaddr") == 0) {
906 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
909 p->base_virtaddr = strdup(entry->value);
914 if (strcmp(entry->name, "create_uio_dev") == 0) {
917 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
920 p->create_uio_dev_present = 1;
922 val = parser_read_arg_bool(entry->value);
923 PARSE_ERROR((val >= 0), section_name, entry->name);
924 p->create_uio_dev = val;
929 if (strcmp(entry->name, "vfio_intr") == 0) {
930 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
933 p->vfio_intr = strdup(entry->value);
938 if (strcmp(entry->name, "xen_dom0") == 0) {
941 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
944 p->xen_dom0_present = 1;
946 val = parser_read_arg_bool(entry->value);
947 PARSE_ERROR((val >= 0), section_name, entry->name);
953 PARSE_ERROR_INVALID(0, section_name, entry->name);
960 parse_pipeline_pcap_source(struct app_params *app,
961 struct app_pipeline_params *p,
962 const char *file_name, const char *cp_size)
964 const char *next = NULL;
969 if (file_name && !cp_size) {
971 parse_file = 1; /* parse file path */
972 } else if (cp_size && !file_name) {
974 parse_file = 0; /* parse copy size */
978 char name[APP_PARAM_NAME_SIZE];
981 if (p->n_pktq_in == 0)
984 for (i = 0; i < p->n_pktq_in; i++) {
985 if (p->pktq_in[i].type != APP_PKTQ_IN_SOURCE)
990 while (*next != '\0') {
993 if (i >= p->n_pktq_in)
996 id = p->pktq_in[i].id;
998 end = strchr(next, ' ');
1000 name_len = strlen(next);
1002 name_len = end - next;
1004 if (name_len == 0 || name_len == sizeof(name))
1007 strncpy(name, next, name_len);
1008 name[name_len] = '\0';
1014 app->source_params[id].file_name = strdup(name);
1015 if (app->source_params[id].file_name == NULL)
1018 if (parser_read_uint32(
1019 &app->source_params[id].n_bytes_per_pkt,
1021 if (app->source_params[id].
1023 free(app->source_params[id].
1031 if (i == p->n_pktq_in)
1039 parse_pipeline_pktq_in(struct app_params *app,
1040 struct app_pipeline_params *p,
1043 const char *next = value;
1045 char name[APP_PARAM_NAME_SIZE];
1048 while (*next != '\0') {
1049 enum app_pktq_in_type type;
1054 next = skip_white_spaces(next);
1058 end_space = strchr(next, ' ');
1059 end_tab = strchr(next, ' ');
1061 if (end_space && (!end_tab))
1063 else if ((!end_space) && end_tab)
1065 else if (end_space && end_tab)
1066 end = RTE_MIN(end_space, end_tab);
1071 name_len = strlen(next);
1073 name_len = end - next;
1075 if (name_len == 0 || name_len == sizeof(name))
1078 strncpy(name, next, name_len);
1079 name[name_len] = '\0';
1084 if (validate_name(name, "RXQ", 2) == 0) {
1085 type = APP_PKTQ_IN_HWQ;
1086 id = APP_PARAM_ADD(app->hwq_in_params, name);
1087 } else if (validate_name(name, "SWQ", 1) == 0) {
1088 type = APP_PKTQ_IN_SWQ;
1089 id = APP_PARAM_ADD(app->swq_params, name);
1090 } else if (validate_name(name, "TM", 1) == 0) {
1091 type = APP_PKTQ_IN_TM;
1092 id = APP_PARAM_ADD(app->tm_params, name);
1093 } else if (validate_name(name, "SOURCE", 1) == 0) {
1094 type = APP_PKTQ_IN_SOURCE;
1095 id = APP_PARAM_ADD(app->source_params, name);
1102 p->pktq_in[p->n_pktq_in].type = type;
1103 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1111 parse_pipeline_pktq_out(struct app_params *app,
1112 struct app_pipeline_params *p,
1115 const char *next = value;
1117 char name[APP_PARAM_NAME_SIZE];
1120 while (*next != '\0') {
1121 enum app_pktq_out_type type;
1126 next = skip_white_spaces(next);
1130 end_space = strchr(next, ' ');
1131 end_tab = strchr(next, ' ');
1133 if (end_space && (!end_tab))
1135 else if ((!end_space) && end_tab)
1137 else if (end_space && end_tab)
1138 end = RTE_MIN(end_space, end_tab);
1143 name_len = strlen(next);
1145 name_len = end - next;
1147 if (name_len == 0 || name_len == sizeof(name))
1150 strncpy(name, next, name_len);
1151 name[name_len] = '\0';
1155 if (validate_name(name, "TXQ", 2) == 0) {
1156 type = APP_PKTQ_OUT_HWQ;
1157 id = APP_PARAM_ADD(app->hwq_out_params, name);
1158 } else if (validate_name(name, "SWQ", 1) == 0) {
1159 type = APP_PKTQ_OUT_SWQ;
1160 id = APP_PARAM_ADD(app->swq_params, name);
1161 } else if (validate_name(name, "TM", 1) == 0) {
1162 type = APP_PKTQ_OUT_TM;
1163 id = APP_PARAM_ADD(app->tm_params, name);
1164 } else if (validate_name(name, "SINK", 1) == 0) {
1165 type = APP_PKTQ_OUT_SINK;
1166 id = APP_PARAM_ADD(app->sink_params, name);
1173 p->pktq_out[p->n_pktq_out].type = type;
1174 p->pktq_out[p->n_pktq_out].id = id;
1182 parse_pipeline_msgq_in(struct app_params *app,
1183 struct app_pipeline_params *p,
1186 const char *next = value;
1188 char name[APP_PARAM_NAME_SIZE];
1192 while (*next != '\0') {
1196 next = skip_white_spaces(next);
1200 end_space = strchr(next, ' ');
1201 end_tab = strchr(next, ' ');
1203 if (end_space && (!end_tab))
1205 else if ((!end_space) && end_tab)
1207 else if (end_space && end_tab)
1208 end = RTE_MIN(end_space, end_tab);
1213 name_len = strlen(next);
1215 name_len = end - next;
1217 if (name_len == 0 || name_len == sizeof(name))
1220 strncpy(name, next, name_len);
1221 name[name_len] = '\0';
1226 if (validate_name(name, "MSGQ", 1) != 0)
1229 idx = APP_PARAM_ADD(app->msgq_params, name);
1233 p->msgq_in[p->n_msgq_in] = idx;
1241 parse_pipeline_msgq_out(struct app_params *app,
1242 struct app_pipeline_params *p,
1245 const char *next = value;
1247 char name[APP_PARAM_NAME_SIZE];
1251 while (*next != '\0') {
1255 next = skip_white_spaces(next);
1259 end_space = strchr(next, ' ');
1260 end_tab = strchr(next, ' ');
1262 if (end_space && (!end_tab))
1264 else if ((!end_space) && end_tab)
1266 else if (end_space && end_tab)
1267 end = RTE_MIN(end_space, end_tab);
1272 name_len = strlen(next);
1274 name_len = end - next;
1276 if (name_len == 0 || name_len == sizeof(name))
1279 strncpy(name, next, name_len);
1280 name[name_len] = '\0';
1285 if (validate_name(name, "MSGQ", 1) != 0)
1288 idx = APP_PARAM_ADD(app->msgq_params, name);
1292 p->msgq_out[p->n_msgq_out] = idx;
1300 parse_pipeline(struct app_params *app,
1301 const char *section_name,
1302 struct rte_cfgfile *cfg)
1304 char name[CFG_NAME_LEN];
1305 struct app_pipeline_params *param;
1306 struct rte_cfgfile_entry *entries;
1310 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1311 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1313 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1314 PARSE_ERROR_MALLOC(entries != NULL);
1316 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1318 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1319 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1321 param = &app->pipeline_params[param_idx];
1323 for (i = 0; i < n_entries; i++) {
1324 struct rte_cfgfile_entry *ent = &entries[i];
1326 if (strcmp(ent->name, "type") == 0) {
1327 int w_size = snprintf(param->type, RTE_DIM(param->type),
1330 PARSE_ERROR(((w_size > 0) &&
1331 (w_size < (int)RTE_DIM(param->type))),
1337 if (strcmp(ent->name, "core") == 0) {
1338 int status = parse_pipeline_core(
1339 ¶m->socket_id, ¶m->core_id,
1340 ¶m->hyper_th_id, ent->value);
1342 PARSE_ERROR((status == 0), section_name,
1347 if (strcmp(ent->name, "pktq_in") == 0) {
1348 int status = parse_pipeline_pktq_in(app, param,
1351 PARSE_ERROR((status == 0), section_name,
1356 if (strcmp(ent->name, "pktq_out") == 0) {
1357 int status = parse_pipeline_pktq_out(app, param,
1360 PARSE_ERROR((status == 0), section_name,
1365 if (strcmp(ent->name, "msgq_in") == 0) {
1366 int status = parse_pipeline_msgq_in(app, param,
1369 PARSE_ERROR((status == 0), section_name,
1374 if (strcmp(ent->name, "msgq_out") == 0) {
1375 int status = parse_pipeline_msgq_out(app, param,
1378 PARSE_ERROR((status == 0), section_name,
1383 if (strcmp(ent->name, "timer_period") == 0) {
1384 int status = parser_read_uint32(
1385 ¶m->timer_period,
1388 PARSE_ERROR((status == 0), section_name,
1393 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1394 int status = parse_pipeline_pcap_source(app,
1395 param, ent->value, NULL);
1397 PARSE_ERROR((status == 0), section_name,
1402 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1403 int status = parse_pipeline_pcap_source(app,
1404 param, NULL, ent->value);
1406 PARSE_ERROR((status == 0), section_name,
1411 /* pipeline type specific items */
1412 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1413 "Parse error in section \"%s\": too many "
1414 "pipeline specified parameters", section_name);
1416 param->args_name[param->n_args] = strdup(ent->name);
1417 param->args_value[param->n_args] = strdup(ent->value);
1419 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1420 (param->args_value[param->n_args] != NULL),
1421 "Parse error: no free memory");
1428 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1429 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1430 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1431 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1432 param->msgq_in[param->n_msgq_in++] = param_idx;
1434 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1435 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1436 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1437 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1438 param->msgq_out[param->n_msgq_out++] = param_idx;
1440 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1443 (param->hyper_th_id) ? "h" : "");
1444 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1445 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1446 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1448 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1451 (param->hyper_th_id) ? "h" : "");
1452 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1453 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1454 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1460 parse_mempool(struct app_params *app,
1461 const char *section_name,
1462 struct rte_cfgfile *cfg)
1464 struct app_mempool_params *param;
1465 struct rte_cfgfile_entry *entries;
1469 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1470 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1472 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1473 PARSE_ERROR_MALLOC(entries != NULL);
1475 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1477 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1478 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1480 param = &app->mempool_params[param_idx];
1482 for (i = 0; i < n_entries; i++) {
1483 struct rte_cfgfile_entry *ent = &entries[i];
1485 if (strcmp(ent->name, "buffer_size") == 0) {
1486 int status = parser_read_uint32(
1487 ¶m->buffer_size, ent->value);
1489 PARSE_ERROR((status == 0), section_name,
1494 if (strcmp(ent->name, "pool_size") == 0) {
1495 int status = parser_read_uint32(
1496 ¶m->pool_size, ent->value);
1498 PARSE_ERROR((status == 0), section_name,
1503 if (strcmp(ent->name, "cache_size") == 0) {
1504 int status = parser_read_uint32(
1505 ¶m->cache_size, ent->value);
1507 PARSE_ERROR((status == 0), section_name,
1512 if (strcmp(ent->name, "cpu") == 0) {
1513 int status = parser_read_uint32(
1514 ¶m->cpu_socket_id, ent->value);
1516 PARSE_ERROR((status == 0), section_name,
1522 PARSE_ERROR_INVALID(0, section_name, ent->name);
1531 parse_link(struct app_params *app,
1532 const char *section_name,
1533 struct rte_cfgfile *cfg)
1535 struct app_link_params *param;
1536 struct rte_cfgfile_entry *entries;
1538 int pci_bdf_present = 0;
1541 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1542 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1544 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1545 PARSE_ERROR_MALLOC(entries != NULL);
1547 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1549 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1550 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1552 param = &app->link_params[param_idx];
1554 for (i = 0; i < n_entries; i++) {
1555 struct rte_cfgfile_entry *ent = &entries[i];
1557 if (strcmp(ent->name, "promisc") == 0) {
1558 int status = parser_read_arg_bool(ent->value);
1560 PARSE_ERROR((status != -EINVAL), section_name,
1562 param->promisc = status;
1566 if (strcmp(ent->name, "arp_q") == 0) {
1567 int status = parser_read_uint32(¶m->arp_q,
1570 PARSE_ERROR((status == 0), section_name,
1575 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1576 int status = parser_read_uint32(
1577 ¶m->tcp_syn_q, ent->value);
1579 PARSE_ERROR((status == 0), section_name, ent->name);
1583 if (strcmp(ent->name, "ip_local_q") == 0) {
1584 int status = parser_read_uint32(
1585 ¶m->ip_local_q, ent->value);
1587 PARSE_ERROR((status == 0), section_name,
1593 if (strcmp(ent->name, "tcp_local_q") == 0) {
1594 int status = parser_read_uint32(
1595 ¶m->tcp_local_q, ent->value);
1597 PARSE_ERROR((status == 0), section_name,
1602 if (strcmp(ent->name, "udp_local_q") == 0) {
1603 int status = parser_read_uint32(
1604 ¶m->udp_local_q, ent->value);
1606 PARSE_ERROR((status == 0), section_name,
1611 if (strcmp(ent->name, "sctp_local_q") == 0) {
1612 int status = parser_read_uint32(
1613 ¶m->sctp_local_q, ent->value);
1615 PARSE_ERROR((status == 0), section_name,
1620 if (strcmp(ent->name, "pci_bdf") == 0) {
1621 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1622 section_name, ent->name);
1624 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1626 pci_bdf_present = 1;
1631 PARSE_ERROR_INVALID(0, section_name, ent->name);
1634 /* Check for mandatory fields */
1636 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1637 section_name, "pci_bdf",
1638 "entry not allowed (port_mask is provided)");
1640 PARSE_ERROR_MESSAGE((pci_bdf_present),
1641 section_name, "pci_bdf",
1642 "this entry is mandatory (port_mask is not "
1651 parse_rxq(struct app_params *app,
1652 const char *section_name,
1653 struct rte_cfgfile *cfg)
1655 struct app_pktq_hwq_in_params *param;
1656 struct rte_cfgfile_entry *entries;
1660 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1661 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1663 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1664 PARSE_ERROR_MALLOC(entries != NULL);
1666 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1668 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1669 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1671 param = &app->hwq_in_params[param_idx];
1673 for (i = 0; i < n_entries; i++) {
1674 struct rte_cfgfile_entry *ent = &entries[i];
1676 if (strcmp(ent->name, "mempool") == 0) {
1677 int status = validate_name(ent->value,
1681 PARSE_ERROR((status == 0), section_name,
1683 idx = APP_PARAM_ADD(app->mempool_params,
1685 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1687 param->mempool_id = idx;
1691 if (strcmp(ent->name, "size") == 0) {
1692 int status = parser_read_uint32(¶m->size,
1695 PARSE_ERROR((status == 0), section_name,
1700 if (strcmp(ent->name, "burst") == 0) {
1701 int status = parser_read_uint32(¶m->burst,
1704 PARSE_ERROR((status == 0), section_name,
1710 PARSE_ERROR_INVALID(0, section_name, ent->name);
1719 parse_txq(struct app_params *app,
1720 const char *section_name,
1721 struct rte_cfgfile *cfg)
1723 struct app_pktq_hwq_out_params *param;
1724 struct rte_cfgfile_entry *entries;
1728 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1729 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1731 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1732 PARSE_ERROR_MALLOC(entries != NULL);
1734 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1736 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1737 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1739 param = &app->hwq_out_params[param_idx];
1741 for (i = 0; i < n_entries; i++) {
1742 struct rte_cfgfile_entry *ent = &entries[i];
1744 if (strcmp(ent->name, "size") == 0) {
1745 int status = parser_read_uint32(¶m->size,
1748 PARSE_ERROR((status == 0), section_name,
1753 if (strcmp(ent->name, "burst") == 0) {
1754 int status = parser_read_uint32(¶m->burst,
1757 PARSE_ERROR((status == 0), section_name,
1762 if (strcmp(ent->name, "dropless") == 0) {
1763 int status = parser_read_arg_bool(ent->value);
1766 PARSE_ERROR((status != -EINVAL), section_name,
1768 param->dropless = status;
1773 PARSE_ERROR_INVALID(0, section_name, ent->name);
1782 parse_swq(struct app_params *app,
1783 const char *section_name,
1784 struct rte_cfgfile *cfg)
1786 struct app_pktq_swq_params *param;
1787 struct rte_cfgfile_entry *entries;
1789 uint32_t mtu_present = 0;
1790 uint32_t metadata_size_present = 0;
1791 uint32_t mempool_direct_present = 0;
1792 uint32_t mempool_indirect_present = 0;
1796 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1797 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1799 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1800 PARSE_ERROR_MALLOC(entries != NULL);
1802 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1804 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1805 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1807 param = &app->swq_params[param_idx];
1809 for (i = 0; i < n_entries; i++) {
1810 struct rte_cfgfile_entry *ent = &entries[i];
1812 if (strcmp(ent->name, "size") == 0) {
1813 int status = parser_read_uint32(¶m->size,
1816 PARSE_ERROR((status == 0), section_name,
1821 if (strcmp(ent->name, "burst_read") == 0) {
1822 int status = parser_read_uint32(&
1823 param->burst_read, ent->value);
1825 PARSE_ERROR((status == 0), section_name,
1830 if (strcmp(ent->name, "burst_write") == 0) {
1831 int status = parser_read_uint32(
1832 ¶m->burst_write, ent->value);
1834 PARSE_ERROR((status == 0), section_name,
1839 if (strcmp(ent->name, "dropless") == 0) {
1840 int status = parser_read_arg_bool(ent->value);
1842 PARSE_ERROR((status != -EINVAL), section_name,
1844 param->dropless = status;
1848 if (strcmp(ent->name, "n_retries") == 0) {
1849 int status = parser_read_uint64(¶m->n_retries,
1852 PARSE_ERROR((status == 0), section_name,
1857 if (strcmp(ent->name, "cpu") == 0) {
1858 int status = parser_read_uint32(
1859 ¶m->cpu_socket_id, ent->value);
1861 PARSE_ERROR((status == 0), section_name, ent->name);
1865 if (strcmp(ent->name, "ipv4_frag") == 0) {
1866 int status = parser_read_arg_bool(ent->value);
1868 PARSE_ERROR((status != -EINVAL), section_name,
1871 param->ipv4_frag = status;
1872 if (param->mtu == 0)
1878 if (strcmp(ent->name, "ipv6_frag") == 0) {
1879 int status = parser_read_arg_bool(ent->value);
1881 PARSE_ERROR((status != -EINVAL), section_name,
1883 param->ipv6_frag = status;
1884 if (param->mtu == 0)
1889 if (strcmp(ent->name, "ipv4_ras") == 0) {
1890 int status = parser_read_arg_bool(ent->value);
1892 PARSE_ERROR((status != -EINVAL), section_name,
1894 param->ipv4_ras = status;
1898 if (strcmp(ent->name, "ipv6_ras") == 0) {
1899 int status = parser_read_arg_bool(ent->value);
1901 PARSE_ERROR((status != -EINVAL), section_name,
1903 param->ipv6_ras = status;
1907 if (strcmp(ent->name, "mtu") == 0) {
1908 int status = parser_read_uint32(¶m->mtu,
1911 PARSE_ERROR((status == 0), section_name,
1917 if (strcmp(ent->name, "metadata_size") == 0) {
1918 int status = parser_read_uint32(
1919 ¶m->metadata_size, ent->value);
1921 PARSE_ERROR((status == 0), section_name,
1923 metadata_size_present = 1;
1927 if (strcmp(ent->name, "mempool_direct") == 0) {
1928 int status = validate_name(ent->value,
1932 PARSE_ERROR((status == 0), section_name,
1935 idx = APP_PARAM_ADD(app->mempool_params,
1937 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1939 param->mempool_direct_id = idx;
1940 mempool_direct_present = 1;
1944 if (strcmp(ent->name, "mempool_indirect") == 0) {
1945 int status = validate_name(ent->value,
1949 PARSE_ERROR((status == 0), section_name,
1951 idx = APP_PARAM_ADD(app->mempool_params,
1953 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1955 param->mempool_indirect_id = idx;
1956 mempool_indirect_present = 1;
1961 PARSE_ERROR_INVALID(0, section_name, ent->name);
1964 APP_CHECK(((mtu_present) &&
1965 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1966 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1967 "is off, therefore entry \"mtu\" is not allowed",
1970 APP_CHECK(((metadata_size_present) &&
1971 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1972 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1973 "is off, therefore entry \"metadata_size\" is "
1974 "not allowed", section_name);
1976 APP_CHECK(((mempool_direct_present) &&
1977 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1978 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1979 "is off, therefore entry \"mempool_direct\" is "
1980 "not allowed", section_name);
1982 APP_CHECK(((mempool_indirect_present) &&
1983 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1984 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1985 "is off, therefore entry \"mempool_indirect\" is "
1986 "not allowed", section_name);
1994 parse_tm(struct app_params *app,
1995 const char *section_name,
1996 struct rte_cfgfile *cfg)
1998 struct app_pktq_tm_params *param;
1999 struct rte_cfgfile_entry *entries;
2003 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2004 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2006 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2007 PARSE_ERROR_MALLOC(entries != NULL);
2009 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2011 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2012 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2014 param = &app->tm_params[param_idx];
2016 for (i = 0; i < n_entries; i++) {
2017 struct rte_cfgfile_entry *ent = &entries[i];
2019 if (strcmp(ent->name, "cfg") == 0) {
2020 param->file_name = strdup(ent->value);
2021 PARSE_ERROR_MALLOC(param->file_name != NULL);
2025 if (strcmp(ent->name, "burst_read") == 0) {
2026 int status = parser_read_uint32(
2027 ¶m->burst_read, ent->value);
2029 PARSE_ERROR((status == 0), section_name,
2034 if (strcmp(ent->name, "burst_write") == 0) {
2035 int status = parser_read_uint32(
2036 ¶m->burst_write, ent->value);
2038 PARSE_ERROR((status == 0), section_name,
2044 PARSE_ERROR_INVALID(0, section_name, ent->name);
2053 parse_source(struct app_params *app,
2054 const char *section_name,
2055 struct rte_cfgfile *cfg)
2057 struct app_pktq_source_params *param;
2058 struct rte_cfgfile_entry *entries;
2062 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2063 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2065 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2066 PARSE_ERROR_MALLOC(entries != NULL);
2068 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2070 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2071 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2073 param = &app->source_params[param_idx];
2075 for (i = 0; i < n_entries; i++) {
2076 struct rte_cfgfile_entry *ent = &entries[i];
2078 if (strcmp(ent->name, "mempool") == 0) {
2079 int status = validate_name(ent->value,
2083 PARSE_ERROR((status == 0), section_name,
2085 idx = APP_PARAM_ADD(app->mempool_params,
2087 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2089 param->mempool_id = idx;
2093 if (strcmp(ent->name, "burst") == 0) {
2094 int status = parser_read_uint32(¶m->burst,
2097 PARSE_ERROR((status == 0), section_name,
2102 if (strcmp(ent->name, "pcap_file_rd")) {
2103 param->file_name = strdup(ent->value);
2105 PARSE_ERROR_MALLOC(param->file_name != NULL);
2109 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2110 int status = parser_read_uint32(
2111 ¶m->n_bytes_per_pkt, ent->value);
2113 PARSE_ERROR((status == 0), section_name,
2118 PARSE_ERROR_INVALID(0, section_name, ent->name);
2127 parse_msgq_req_pipeline(struct app_params *app,
2128 const char *section_name,
2129 struct rte_cfgfile *cfg)
2131 struct app_msgq_params *param;
2132 struct rte_cfgfile_entry *entries;
2136 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2137 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2139 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2140 PARSE_ERROR_MALLOC(entries != NULL);
2142 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2144 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2145 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2147 param = &app->msgq_params[param_idx];
2149 for (i = 0; i < n_entries; i++) {
2150 struct rte_cfgfile_entry *ent = &entries[i];
2152 if (strcmp(ent->name, "size") == 0) {
2153 int status = parser_read_uint32(¶m->size,
2156 PARSE_ERROR((status == 0), section_name,
2162 PARSE_ERROR_INVALID(0, section_name, ent->name);
2170 parse_msgq_rsp_pipeline(struct app_params *app,
2171 const char *section_name,
2172 struct rte_cfgfile *cfg)
2174 struct app_msgq_params *param;
2175 struct rte_cfgfile_entry *entries;
2179 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2180 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2182 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2183 PARSE_ERROR_MALLOC(entries != NULL);
2185 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2187 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2188 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2190 param = &app->msgq_params[param_idx];
2192 for (i = 0; i < n_entries; i++) {
2193 struct rte_cfgfile_entry *ent = &entries[i];
2195 if (strcmp(ent->name, "size") == 0) {
2196 int status = parser_read_uint32(¶m->size,
2199 PARSE_ERROR((status == 0), section_name,
2205 PARSE_ERROR_INVALID(0, section_name, ent->name);
2214 parse_msgq(struct app_params *app,
2215 const char *section_name,
2216 struct rte_cfgfile *cfg)
2218 struct app_msgq_params *param;
2219 struct rte_cfgfile_entry *entries;
2223 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2224 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2226 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2227 PARSE_ERROR_MALLOC(entries != NULL);
2229 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2231 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2232 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2234 param = &app->msgq_params[param_idx];
2236 for (i = 0; i < n_entries; i++) {
2237 struct rte_cfgfile_entry *ent = &entries[i];
2239 if (strcmp(ent->name, "size") == 0) {
2240 int status = parser_read_uint32(¶m->size,
2243 PARSE_ERROR((status == 0), section_name,
2248 if (strcmp(ent->name, "cpu") == 0) {
2249 int status = parser_read_uint32(
2250 ¶m->cpu_socket_id, ent->value);
2252 PARSE_ERROR((status == 0), section_name,
2258 PARSE_ERROR_INVALID(0, section_name, ent->name);
2266 typedef void (*config_section_load)(struct app_params *p,
2267 const char *section_name,
2268 struct rte_cfgfile *cfg);
2270 struct config_section {
2271 const char prefix[CFG_NAME_LEN];
2273 config_section_load load;
2276 static const struct config_section cfg_file_scheme[] = {
2277 {"EAL", 0, parse_eal},
2278 {"PIPELINE", 1, parse_pipeline},
2279 {"MEMPOOL", 1, parse_mempool},
2280 {"LINK", 1, parse_link},
2281 {"RXQ", 2, parse_rxq},
2282 {"TXQ", 2, parse_txq},
2283 {"SWQ", 1, parse_swq},
2284 {"TM", 1, parse_tm},
2285 {"SOURCE", 1, parse_source},
2286 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2287 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2288 {"MSGQ", 1, parse_msgq},
2292 create_implicit_mempools(struct app_params *app)
2296 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2297 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2301 create_implicit_links_from_port_mask(struct app_params *app,
2304 uint32_t pmd_id, link_id;
2307 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2308 char name[APP_PARAM_NAME_SIZE];
2311 if ((port_mask & (1LLU << pmd_id)) == 0)
2314 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2315 idx = APP_PARAM_ADD(app->link_params, name);
2316 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2318 app->link_params[idx].pmd_id = pmd_id;
2324 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2328 for (i = 0; i < app->n_links; i++) {
2329 struct app_link_params *link = &app->link_params[i];
2336 app_config_parse(struct app_params *app, const char *file_name)
2338 struct rte_cfgfile *cfg;
2339 char **section_names;
2340 int i, j, sect_count;
2342 /* Implicit mempools */
2343 create_implicit_mempools(app);
2347 create_implicit_links_from_port_mask(app, app->port_mask);
2349 /* Load application configuration file */
2350 cfg = rte_cfgfile_load(file_name, 0);
2351 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2352 "file %s", file_name);
2354 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2355 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2356 "in file \"%s\" return %d", file_name,
2359 section_names = malloc(sect_count * sizeof(char *));
2360 PARSE_ERROR_MALLOC(section_names != NULL);
2362 for (i = 0; i < sect_count; i++)
2363 section_names[i] = malloc(CFG_NAME_LEN);
2365 rte_cfgfile_sections(cfg, section_names, sect_count);
2367 for (i = 0; i < sect_count; i++) {
2368 const struct config_section *sch_s;
2369 int len, cfg_name_len;
2371 cfg_name_len = strlen(section_names[i]);
2373 /* Find section type */
2374 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2375 sch_s = &cfg_file_scheme[j];
2376 len = strlen(sch_s->prefix);
2378 if (cfg_name_len < len)
2381 /* After section name we expect only '\0' or digit or
2382 * digit dot digit, so protect against false matching,
2383 * for example: "ABC" should match section name
2384 * "ABC0.0", but it should not match section_name
2387 if ((section_names[i][len] != '\0') &&
2388 !isdigit(section_names[i][len]))
2391 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2395 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2396 "Parse error: unknown section %s",
2399 APP_CHECK(validate_name(section_names[i],
2401 sch_s->numbers) == 0,
2402 "Parse error: invalid section name \"%s\"",
2405 sch_s->load(app, section_names[i], cfg);
2408 for (i = 0; i < sect_count; i++)
2409 free(section_names[i]);
2411 free(section_names);
2413 rte_cfgfile_close(cfg);
2415 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2416 APP_PARAM_COUNT(app->link_params, app->n_links);
2417 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2418 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2419 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2420 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2421 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2422 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2423 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2424 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2426 if (app->port_mask == 0)
2427 assign_link_pmd_id_from_pci_bdf(app);
2429 /* Save configuration to output file */
2430 app_config_save(app, app->output_file);
2432 /* Load TM configuration files */
2433 app_config_parse_tm(app);
2439 save_eal_params(struct app_params *app, FILE *f)
2441 struct app_eal_params *p = &app->eal_params;
2444 fprintf(f, "[EAL]\n");
2447 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2449 if (p->master_lcore_present)
2450 fprintf(f, "%s = %" PRIu32 "\n",
2451 "master_lcore", p->master_lcore);
2453 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2455 if (p->memory_present)
2456 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2458 if (p->ranks_present)
2459 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2461 for (i = 0; i < APP_MAX_LINKS; i++) {
2462 if (p->pci_blacklist[i] == NULL)
2465 fprintf(f, "%s = %s\n", "pci_blacklist",
2466 p->pci_blacklist[i]);
2469 for (i = 0; i < APP_MAX_LINKS; i++) {
2470 if (p->pci_whitelist[i] == NULL)
2473 fprintf(f, "%s = %s\n", "pci_whitelist",
2474 p->pci_whitelist[i]);
2477 for (i = 0; i < APP_MAX_LINKS; i++) {
2478 if (p->vdev[i] == NULL)
2481 fprintf(f, "%s = %s\n", "vdev",
2485 if (p->vmware_tsc_map_present)
2486 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2487 (p->vmware_tsc_map) ? "yes" : "no");
2490 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2493 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2495 if (p->log_level_present)
2496 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2498 if (p->version_present)
2499 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2501 if (p->help_present)
2502 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2504 if (p->no_huge_present)
2505 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2507 if (p->no_pci_present)
2508 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2510 if (p->no_hpet_present)
2511 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2513 if (p->no_shconf_present)
2514 fprintf(f, "%s = %s\n", "no_shconf",
2515 (p->no_shconf) ? "yes" : "no");
2518 fprintf(f, "%s = %s\n", "d", p->add_driver);
2521 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2524 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2527 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2529 if (p->base_virtaddr)
2530 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2532 if (p->create_uio_dev_present)
2533 fprintf(f, "%s = %s\n", "create_uio_dev",
2534 (p->create_uio_dev) ? "yes" : "no");
2537 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2539 if (p->xen_dom0_present)
2540 fprintf(f, "%s = %s\n", "xen_dom0",
2541 (p->xen_dom0) ? "yes" : "no");
2547 save_mempool_params(struct app_params *app, FILE *f)
2549 struct app_mempool_params *p;
2552 count = RTE_DIM(app->mempool_params);
2553 for (i = 0; i < count; i++) {
2554 p = &app->mempool_params[i];
2555 if (!APP_PARAM_VALID(p))
2558 fprintf(f, "[%s]\n", p->name);
2559 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2560 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2561 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2562 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2569 save_links_params(struct app_params *app, FILE *f)
2571 struct app_link_params *p;
2574 count = RTE_DIM(app->link_params);
2575 for (i = 0; i < count; i++) {
2576 p = &app->link_params[i];
2577 if (!APP_PARAM_VALID(p))
2580 fprintf(f, "[%s]\n", p->name);
2581 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2582 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2583 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2584 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2586 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2587 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2588 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2589 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2592 if (strlen(p->pci_bdf))
2593 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2600 save_rxq_params(struct app_params *app, FILE *f)
2602 struct app_pktq_hwq_in_params *p;
2605 count = RTE_DIM(app->hwq_in_params);
2606 for (i = 0; i < count; i++) {
2607 p = &app->hwq_in_params[i];
2608 if (!APP_PARAM_VALID(p))
2611 fprintf(f, "[%s]\n", p->name);
2612 fprintf(f, "%s = %s\n",
2614 app->mempool_params[p->mempool_id].name);
2615 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2616 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2623 save_txq_params(struct app_params *app, FILE *f)
2625 struct app_pktq_hwq_out_params *p;
2628 count = RTE_DIM(app->hwq_out_params);
2629 for (i = 0; i < count; i++) {
2630 p = &app->hwq_out_params[i];
2631 if (!APP_PARAM_VALID(p))
2634 fprintf(f, "[%s]\n", p->name);
2635 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2636 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2637 fprintf(f, "%s = %s\n",
2639 p->dropless ? "yes" : "no");
2646 save_swq_params(struct app_params *app, FILE *f)
2648 struct app_pktq_swq_params *p;
2651 count = RTE_DIM(app->swq_params);
2652 for (i = 0; i < count; i++) {
2653 p = &app->swq_params[i];
2654 if (!APP_PARAM_VALID(p))
2657 fprintf(f, "[%s]\n", p->name);
2658 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2659 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2660 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2661 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2662 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2663 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2664 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2665 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2666 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2667 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2668 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2669 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2670 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2671 fprintf(f, "%s = %s\n",
2673 app->mempool_params[p->mempool_direct_id].name);
2674 fprintf(f, "%s = %s\n",
2676 app->mempool_params[p->mempool_indirect_id].name);
2684 save_tm_params(struct app_params *app, FILE *f)
2686 struct app_pktq_tm_params *p;
2689 count = RTE_DIM(app->tm_params);
2690 for (i = 0; i < count; i++) {
2691 p = &app->tm_params[i];
2692 if (!APP_PARAM_VALID(p))
2695 fprintf(f, "[%s]\n", p->name);
2696 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2697 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2698 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2705 save_source_params(struct app_params *app, FILE *f)
2707 struct app_pktq_source_params *p;
2710 count = RTE_DIM(app->source_params);
2711 for (i = 0; i < count; i++) {
2712 p = &app->source_params[i];
2713 if (!APP_PARAM_VALID(p))
2716 fprintf(f, "[%s]\n", p->name);
2717 fprintf(f, "%s = %s\n",
2719 app->mempool_params[p->mempool_id].name);
2720 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2721 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2722 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2723 p->n_bytes_per_pkt);
2729 save_msgq_params(struct app_params *app, FILE *f)
2731 struct app_msgq_params *p;
2734 count = RTE_DIM(app->msgq_params);
2735 for (i = 0; i < count; i++) {
2736 p = &app->msgq_params[i];
2737 if (!APP_PARAM_VALID(p))
2740 fprintf(f, "[%s]\n", p->name);
2741 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2742 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2749 save_pipeline_params(struct app_params *app, FILE *f)
2753 count = RTE_DIM(app->pipeline_params);
2754 for (i = 0; i < count; i++) {
2755 struct app_pipeline_params *p = &app->pipeline_params[i];
2757 if (!APP_PARAM_VALID(p))
2761 fprintf(f, "[%s]\n", p->name);
2764 fprintf(f, "type = %s\n", p->type);
2767 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2770 (p->hyper_th_id) ? "h" : "");
2776 fprintf(f, "pktq_in =");
2777 for (j = 0; j < p->n_pktq_in; j++) {
2778 struct app_pktq_in_params *pp = &p->pktq_in[j];
2782 case APP_PKTQ_IN_HWQ:
2783 name = app->hwq_in_params[pp->id].name;
2785 case APP_PKTQ_IN_SWQ:
2786 name = app->swq_params[pp->id].name;
2788 case APP_PKTQ_IN_TM:
2789 name = app->tm_params[pp->id].name;
2791 case APP_PKTQ_IN_SOURCE:
2792 name = app->source_params[pp->id].name;
2795 APP_CHECK(0, "System error "
2796 "occurred while saving "
2797 "parameter to file");
2800 fprintf(f, " %s", name);
2806 if (p->n_pktq_out) {
2809 fprintf(f, "pktq_out =");
2810 for (j = 0; j < p->n_pktq_out; j++) {
2811 struct app_pktq_out_params *pp =
2816 case APP_PKTQ_OUT_HWQ:
2817 name = app->hwq_out_params[pp->id].name;
2819 case APP_PKTQ_OUT_SWQ:
2820 name = app->swq_params[pp->id].name;
2822 case APP_PKTQ_OUT_TM:
2823 name = app->tm_params[pp->id].name;
2825 case APP_PKTQ_OUT_SINK:
2826 name = app->sink_params[pp->id].name;
2829 APP_CHECK(0, "System error "
2830 "occurred while saving "
2831 "parameter to file");
2834 fprintf(f, " %s", name);
2843 fprintf(f, "msgq_in =");
2844 for (j = 0; j < p->n_msgq_in; j++) {
2845 uint32_t id = p->msgq_in[j];
2846 char *name = app->msgq_params[id].name;
2848 fprintf(f, " %s", name);
2854 if (p->n_msgq_out) {
2857 fprintf(f, "msgq_out =");
2858 for (j = 0; j < p->n_msgq_out; j++) {
2859 uint32_t id = p->msgq_out[j];
2860 char *name = app->msgq_params[id].name;
2862 fprintf(f, " %s", name);
2868 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2874 for (j = 0; j < p->n_args; j++)
2875 fprintf(f, "%s = %s\n", p->args_name[j],
2884 app_config_save(struct app_params *app, const char *file_name)
2887 char *name, *dir_name;
2890 name = strdup(file_name);
2891 dir_name = dirname(name);
2892 status = access(dir_name, W_OK);
2893 APP_CHECK((status == 0),
2894 "Error: need write access privilege to directory "
2895 "\"%s\" to save configuration\n", dir_name);
2897 file = fopen(file_name, "w");
2898 APP_CHECK((file != NULL),
2899 "Error: failed to save configuration to file \"%s\"",
2902 save_eal_params(app, file);
2903 save_pipeline_params(app, file);
2904 save_mempool_params(app, file);
2905 save_links_params(app, file);
2906 save_rxq_params(app, file);
2907 save_txq_params(app, file);
2908 save_swq_params(app, file);
2909 save_tm_params(app, file);
2910 save_source_params(app, file);
2911 save_msgq_params(app, file);
2918 app_config_init(struct app_params *app)
2922 memcpy(app, &app_params_default, sizeof(struct app_params));
2924 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2925 memcpy(&app->mempool_params[i],
2926 &mempool_params_default,
2927 sizeof(struct app_mempool_params));
2929 for (i = 0; i < RTE_DIM(app->link_params); i++)
2930 memcpy(&app->link_params[i],
2931 &link_params_default,
2932 sizeof(struct app_link_params));
2934 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2935 memcpy(&app->hwq_in_params[i],
2936 &default_hwq_in_params,
2937 sizeof(default_hwq_in_params));
2939 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2940 memcpy(&app->hwq_out_params[i],
2941 &default_hwq_out_params,
2942 sizeof(default_hwq_out_params));
2944 for (i = 0; i < RTE_DIM(app->swq_params); i++)
2945 memcpy(&app->swq_params[i],
2946 &default_swq_params,
2947 sizeof(default_swq_params));
2949 for (i = 0; i < RTE_DIM(app->tm_params); i++)
2950 memcpy(&app->tm_params[i],
2952 sizeof(default_tm_params));
2954 for (i = 0; i < RTE_DIM(app->source_params); i++)
2955 memcpy(&app->source_params[i],
2956 &default_source_params,
2957 sizeof(default_source_params));
2959 for (i = 0; i < RTE_DIM(app->sink_params); i++)
2960 memcpy(&app->sink_params[i],
2961 &default_sink_params,
2962 sizeof(default_sink_params));
2964 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2965 memcpy(&app->msgq_params[i],
2966 &default_msgq_params,
2967 sizeof(default_msgq_params));
2969 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2970 memcpy(&app->pipeline_params[i],
2971 &default_pipeline_params,
2972 sizeof(default_pipeline_params));
2978 filenamedup(const char *filename, const char *suffix)
2980 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2985 sprintf(s, "%s%s", filename, suffix);
2990 app_config_args(struct app_params *app, int argc, char **argv)
2992 const char *optname;
2993 int opt, option_index;
2994 int f_present, s_present, p_present, l_present;
2995 int preproc_present, preproc_params_present;
2998 static struct option lgopts[] = {
2999 { "preproc", 1, 0, 0 },
3000 { "preproc-args", 1, 0, 0 },
3004 /* Copy application name */
3005 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3011 preproc_present = 0;
3012 preproc_params_present = 0;
3014 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3015 &option_index)) != EOF)
3019 rte_panic("Error: Config file is provided "
3020 "more than once\n");
3023 if (!strlen(optarg))
3024 rte_panic("Error: Config file name is null\n");
3026 app->config_file = strdup(optarg);
3027 if (app->config_file == NULL)
3028 rte_panic("Error: Memory allocation failure\n");
3034 rte_panic("Error: Script file is provided "
3035 "more than once\n");
3038 if (!strlen(optarg))
3039 rte_panic("Error: Script file name is null\n");
3041 app->script_file = strdup(optarg);
3042 if (app->script_file == NULL)
3043 rte_panic("Error: Memory allocation failure\n");
3049 rte_panic("Error: PORT_MASK is provided "
3050 "more than once\n");
3053 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3055 ((size_t) scaned != strlen(optarg)))
3056 rte_panic("Error: PORT_MASK is not "
3057 "a hexadecimal integer\n");
3059 if (app->port_mask == 0)
3060 rte_panic("Error: PORT_MASK is null\n");
3066 rte_panic("Error: LOG_LEVEL is provided "
3067 "more than once\n");
3070 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3072 ((size_t) scaned != strlen(optarg)) ||
3073 (app->log_level >= APP_LOG_LEVELS))
3074 rte_panic("Error: LOG_LEVEL invalid value\n");
3079 optname = lgopts[option_index].name;
3081 if (strcmp(optname, "preproc") == 0) {
3082 if (preproc_present)
3083 rte_panic("Error: Preprocessor argument "
3084 "is provided more than once\n");
3085 preproc_present = 1;
3087 app->preproc = strdup(optarg);
3091 if (strcmp(optname, "preproc-args") == 0) {
3092 if (preproc_params_present)
3093 rte_panic("Error: Preprocessor args "
3094 "are provided more than once\n");
3095 preproc_params_present = 1;
3097 app->preproc_args = strdup(optarg);
3101 app_print_usage(argv[0]);
3105 app_print_usage(argv[0]);
3108 optind = 0; /* reset getopt lib */
3110 /* Check dependencies between args */
3111 if (preproc_params_present && (preproc_present == 0))
3112 rte_panic("Error: Preprocessor args specified while "
3113 "preprocessor is not defined\n");
3115 app->parser_file = preproc_present ?
3116 filenamedup(app->config_file, ".preproc") :
3117 strdup(app->config_file);
3118 app->output_file = filenamedup(app->config_file, ".out");
3124 app_config_preproc(struct app_params *app)
3129 if (app->preproc == NULL)
3132 status = access(app->config_file, F_OK | R_OK);
3133 APP_CHECK((status == 0), "Error: Unable to open file %s",
3136 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3138 app->preproc_args ? app->preproc_args : "",
3142 status = system(buffer);
3143 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3144 "Error occurred while pre-processing file \"%s\"\n",