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 = {
92 .mq_mode = ETH_MQ_RX_NONE,
94 .header_split = 0, /* Header split */
95 .hw_ip_checksum = 0, /* IP checksum offload */
96 .hw_vlan_filter = 0, /* VLAN filtering */
97 .hw_vlan_strip = 0, /* VLAN strip */
98 .hw_vlan_extend = 0, /* Extended VLAN */
99 .jumbo_frame = 0, /* Jumbo frame support */
100 .hw_strip_crc = 0, /* CRC strip by HW */
101 .enable_scatter = 0, /* Scattered packets RX handler */
103 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
104 .split_hdr_size = 0, /* Header split buffer size */
107 .mq_mode = ETH_MQ_TX_NONE,
115 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
127 .rx_free_thresh = 64,
129 .rx_deferred_start = 0,
133 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
148 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
149 ETH_TXQ_FLAGS_NOOFFLOADS,
150 .tx_deferred_start = 0,
154 static const struct app_pktq_swq_params default_swq_params = {
168 .mempool_direct_id = 0,
169 .mempool_indirect_id = 0,
172 struct app_pktq_tm_params default_tm_params = {
174 .file_name = "./config/tm_profile.cfg",
179 struct app_pktq_source_params default_source_params = {
184 .n_bytes_per_pkt = 0,
187 struct app_pktq_sink_params default_sink_params = {
193 struct app_msgq_params default_msgq_params = {
199 struct app_pipeline_params default_pipeline_params = {
212 static const char app_usage[] =
213 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
214 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
217 "\t-f CONFIG_FILE: Default config file is %s\n"
218 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
219 "config file when not provided)\n"
220 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
221 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
222 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
223 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
227 app_print_usage(char *prgname)
229 rte_exit(0, app_usage, prgname, app_params_default.config_file);
232 #define skip_white_spaces(pos) \
234 __typeof__(pos) _p = (pos); \
235 for ( ; isspace(*_p); _p++); \
239 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
241 APP_CHECK((result != -EINVAL), \
242 "Parse error: no free memory"); \
243 APP_CHECK((result != -ENOMEM), \
244 "Parse error: too many \"%s\" sections", section_name); \
245 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
246 "Parse error: duplicate \"%s\" section", section_name); \
247 APP_CHECK((result >= 0), \
248 "Parse error in section \"%s\"", section_name); \
252 parser_read_arg_bool(const char *p)
254 p = skip_white_spaces(p);
255 int result = -EINVAL;
257 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
258 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
263 if (((p[0] == 'o') && (p[1] == 'n')) ||
264 ((p[0] == 'O') && (p[1] == 'N'))) {
269 if (((p[0] == 'n') && (p[1] == 'o')) ||
270 ((p[0] == 'N') && (p[1] == 'O'))) {
275 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
276 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
281 p = skip_white_spaces(p);
289 #define PARSE_ERROR(exp, section, entry) \
290 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
292 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
293 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n", \
294 section, entry, message)
297 #define PARSE_ERROR_MALLOC(exp) \
298 APP_CHECK(exp, "Parse error: no free memory\n")
300 #define PARSE_ERROR_SECTION(exp, section) \
301 APP_CHECK(exp, "Parse error in section \"%s\"", section)
303 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
304 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
306 #define PARSE_WARNING_IGNORED(exp, section, entry) \
309 fprintf(stderr, "Parse warning in section \"%s\": " \
310 "entry \"%s\" is ignored\n", section, entry); \
313 #define PARSE_ERROR_INVALID(exp, section, entry) \
314 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
317 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
318 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
322 parser_read_uint64(uint64_t *value, const char *p)
327 p = skip_white_spaces(p);
331 val = strtoul(p, &next, 10);
353 p = skip_white_spaces(p);
362 parser_read_uint32(uint32_t *value, const char *p)
365 int ret = parser_read_uint64(&val, p);
370 if (val > UINT32_MAX)
378 parse_pipeline_core(uint32_t *socket,
386 uint32_t s = 0, c = 0, h = 0, val;
387 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
388 const char *next = skip_white_spaces(entry);
391 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
392 while (*next != '\0') {
393 /* If everything parsed nothing should left */
394 if (s_parsed && c_parsed && h_parsed)
401 if (s_parsed || c_parsed || h_parsed)
408 if (c_parsed || h_parsed)
421 /* If it start from digit it must be only core id. */
422 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
428 for (num_len = 0; *next != '\0'; next++, num_len++) {
429 if (num_len == RTE_DIM(num))
435 num[num_len] = *next;
438 if (num_len == 0 && type != 'h' && type != 'H')
441 if (num_len != 0 && (type == 'h' || type == 'H'))
445 val = strtol(num, NULL, 10);
474 case '0': case '1': case '2': case '3': case '4': case '5':
475 case '6': case '7': case '8': case '9':
477 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
479 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
487 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
492 /* Check input parameters */
500 if (((len & 3) != 0) ||
505 for (c = src; *c != 0; c++) {
506 if ((((*c) >= '0') && ((*c) <= '9')) ||
507 (((*c) >= 'A') && ((*c) <= 'F')) ||
508 (((*c) >= 'a') && ((*c) <= 'f')))
514 /* Convert chars to bytes */
515 for (i = 0; i < *size; i++)
516 dst[i] = get_hex_val(src[2 * i]) * 16 +
517 get_hex_val(src[2 * i + 1]);
523 skip_digits(const char *src)
527 for (i = 0; isdigit(src[i]); i++);
533 validate_name(const char *name, const char *prefix, int num)
537 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
538 if (name[i] != prefix[i])
542 if (prefix[i] != '\0')
553 j = skip_digits(&name[i]);
555 if ((j == 0) || (name[i] != '.'))
561 j = skip_digits(&name[i]);
563 if ((j == 0) || (name[i] != '\0'))
571 parse_eal(struct app_params *app,
572 const char *section_name,
573 struct rte_cfgfile *cfg)
575 struct app_eal_params *p = &app->eal_params;
576 struct rte_cfgfile_entry *entries;
579 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
580 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
582 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
583 PARSE_ERROR_MALLOC(entries != NULL);
585 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
587 for (i = 0; i < n_entries; i++) {
588 struct rte_cfgfile_entry *entry = &entries[i];
591 if (strcmp(entry->name, "c") == 0) {
592 PARSE_WARNING_IGNORED(0, section_name, entry->name);
597 if (strcmp(entry->name, "l") == 0) {
598 PARSE_WARNING_IGNORED(0, section_name, entry->name);
603 if (strcmp(entry->name, "lcores") == 0) {
604 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
607 p->coremap = strdup(entry->value);
612 if (strcmp(entry->name, "master_lcore") == 0) {
615 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
618 p->master_lcore_present = 1;
620 status = parser_read_uint32(&p->master_lcore,
622 PARSE_ERROR((status == 0), section_name, entry->name);
627 if (strcmp(entry->name, "n") == 0) {
630 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
633 p->channels_present = 1;
635 status = parser_read_uint32(&p->channels, entry->value);
636 PARSE_ERROR((status == 0), section_name, entry->name);
641 if (strcmp(entry->name, "m") == 0) {
644 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
647 p->memory_present = 1;
649 status = parser_read_uint32(&p->memory, entry->value);
650 PARSE_ERROR((status == 0), section_name, entry->name);
655 if (strcmp(entry->name, "r") == 0) {
658 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
661 p->ranks_present = 1;
663 status = parser_read_uint32(&p->ranks, entry->value);
664 PARSE_ERROR((status == 0), section_name, entry->name);
669 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
670 (strcmp(entry->name, "b") == 0)) {
673 for (i = 0; i < APP_MAX_LINKS; i++) {
674 if (p->pci_blacklist[i])
677 p->pci_blacklist[i] =
678 strdup(entry->value);
679 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
684 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
685 section_name, entry->name,
686 "too many elements");
691 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
692 (strcmp(entry->name, "w") == 0)) {
695 PARSE_ERROR_MESSAGE((app->port_mask != 0),
696 section_name, entry->name, "entry to be "
697 "generated by the application (port_mask "
700 for (i = 0; i < APP_MAX_LINKS; i++) {
701 if (p->pci_whitelist[i])
704 p->pci_whitelist[i] = strdup(entry->value);
705 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
710 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
711 section_name, entry->name,
712 "too many elements");
717 if (strcmp(entry->name, "vdev") == 0) {
720 for (i = 0; i < APP_MAX_LINKS; i++) {
724 p->vdev[i] = strdup(entry->value);
725 PARSE_ERROR_MALLOC(p->vdev[i]);
730 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
731 section_name, entry->name,
732 "too many elements");
737 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
740 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
743 p->vmware_tsc_map_present = 1;
745 val = parser_read_arg_bool(entry->value);
746 PARSE_ERROR((val >= 0), section_name, entry->name);
747 p->vmware_tsc_map = val;
752 if (strcmp(entry->name, "proc_type") == 0) {
753 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
756 p->proc_type = strdup(entry->value);
761 if (strcmp(entry->name, "syslog") == 0) {
762 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
765 p->syslog = strdup(entry->value);
770 if (strcmp(entry->name, "log_level") == 0) {
773 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
776 p->log_level_present = 1;
778 status = parser_read_uint32(&p->log_level,
780 PARSE_ERROR((status == 0), section_name, entry->name);
785 if (strcmp(entry->name, "v") == 0) {
788 PARSE_ERROR_DUPLICATE((p->version_present == 0),
791 p->version_present = 1;
793 val = parser_read_arg_bool(entry->value);
794 PARSE_ERROR((val >= 0), section_name, entry->name);
800 if ((strcmp(entry->name, "help") == 0) ||
801 (strcmp(entry->name, "h") == 0)) {
804 PARSE_ERROR_DUPLICATE((p->help_present == 0),
809 val = parser_read_arg_bool(entry->value);
810 PARSE_ERROR((val >= 0), section_name, entry->name);
816 if (strcmp(entry->name, "no_huge") == 0) {
819 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
822 p->no_huge_present = 1;
824 val = parser_read_arg_bool(entry->value);
825 PARSE_ERROR((val >= 0), section_name, entry->name);
831 if (strcmp(entry->name, "no_pci") == 0) {
834 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
837 p->no_pci_present = 1;
839 val = parser_read_arg_bool(entry->value);
840 PARSE_ERROR((val >= 0), section_name, entry->name);
846 if (strcmp(entry->name, "no_hpet") == 0) {
849 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
852 p->no_hpet_present = 1;
854 val = parser_read_arg_bool(entry->value);
855 PARSE_ERROR((val >= 0), section_name, entry->name);
861 if (strcmp(entry->name, "no_shconf") == 0) {
864 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
867 p->no_shconf_present = 1;
869 val = parser_read_arg_bool(entry->value);
870 PARSE_ERROR((val >= 0), section_name, entry->name);
876 if (strcmp(entry->name, "d") == 0) {
877 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
880 p->add_driver = strdup(entry->value);
885 if (strcmp(entry->name, "socket_mem") == 0) {
886 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
889 p->socket_mem = strdup(entry->value);
894 if (strcmp(entry->name, "huge_dir") == 0) {
895 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
898 p->huge_dir = strdup(entry->value);
903 if (strcmp(entry->name, "file_prefix") == 0) {
904 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
907 p->file_prefix = strdup(entry->value);
912 if (strcmp(entry->name, "base_virtaddr") == 0) {
913 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
916 p->base_virtaddr = strdup(entry->value);
921 if (strcmp(entry->name, "create_uio_dev") == 0) {
924 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
927 p->create_uio_dev_present = 1;
929 val = parser_read_arg_bool(entry->value);
930 PARSE_ERROR((val >= 0), section_name, entry->name);
931 p->create_uio_dev = val;
936 if (strcmp(entry->name, "vfio_intr") == 0) {
937 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
940 p->vfio_intr = strdup(entry->value);
945 if (strcmp(entry->name, "xen_dom0") == 0) {
948 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
951 p->xen_dom0_present = 1;
953 val = parser_read_arg_bool(entry->value);
954 PARSE_ERROR((val >= 0), section_name, entry->name);
960 PARSE_ERROR_INVALID(0, section_name, entry->name);
967 parse_pipeline_pktq_in(struct app_params *app,
968 struct app_pipeline_params *p,
971 const char *next = value;
973 char name[APP_PARAM_NAME_SIZE];
976 while (*next != '\0') {
977 enum app_pktq_in_type type;
982 next = skip_white_spaces(next);
986 end_space = strchr(next, ' ');
987 end_tab = strchr(next, ' ');
989 if (end_space && (!end_tab))
991 else if ((!end_space) && end_tab)
993 else if (end_space && end_tab)
994 end = RTE_MIN(end_space, end_tab);
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';
1012 if (validate_name(name, "RXQ", 2) == 0) {
1013 type = APP_PKTQ_IN_HWQ;
1014 id = APP_PARAM_ADD(app->hwq_in_params, name);
1015 } else if (validate_name(name, "SWQ", 1) == 0) {
1016 type = APP_PKTQ_IN_SWQ;
1017 id = APP_PARAM_ADD(app->swq_params, name);
1018 } else if (validate_name(name, "TM", 1) == 0) {
1019 type = APP_PKTQ_IN_TM;
1020 id = APP_PARAM_ADD(app->tm_params, name);
1021 } else if (validate_name(name, "SOURCE", 1) == 0) {
1022 type = APP_PKTQ_IN_SOURCE;
1023 id = APP_PARAM_ADD(app->source_params, name);
1030 p->pktq_in[p->n_pktq_in].type = type;
1031 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1039 parse_pipeline_pktq_out(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_out_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';
1083 if (validate_name(name, "TXQ", 2) == 0) {
1084 type = APP_PKTQ_OUT_HWQ;
1085 id = APP_PARAM_ADD(app->hwq_out_params, name);
1086 } else if (validate_name(name, "SWQ", 1) == 0) {
1087 type = APP_PKTQ_OUT_SWQ;
1088 id = APP_PARAM_ADD(app->swq_params, name);
1089 } else if (validate_name(name, "TM", 1) == 0) {
1090 type = APP_PKTQ_OUT_TM;
1091 id = APP_PARAM_ADD(app->tm_params, name);
1092 } else if (validate_name(name, "SINK", 1) == 0) {
1093 type = APP_PKTQ_OUT_SINK;
1094 id = APP_PARAM_ADD(app->sink_params, name);
1101 p->pktq_out[p->n_pktq_out].type = type;
1102 p->pktq_out[p->n_pktq_out].id = id;
1110 parse_pipeline_msgq_in(struct app_params *app,
1111 struct app_pipeline_params *p,
1114 const char *next = value;
1116 char name[APP_PARAM_NAME_SIZE];
1120 while (*next != '\0') {
1124 next = skip_white_spaces(next);
1128 end_space = strchr(next, ' ');
1129 end_tab = strchr(next, ' ');
1131 if (end_space && (!end_tab))
1133 else if ((!end_space) && end_tab)
1135 else if (end_space && end_tab)
1136 end = RTE_MIN(end_space, end_tab);
1141 name_len = strlen(next);
1143 name_len = end - next;
1145 if (name_len == 0 || name_len == sizeof(name))
1148 strncpy(name, next, name_len);
1149 name[name_len] = '\0';
1154 if (validate_name(name, "MSGQ", 1) != 0)
1157 idx = APP_PARAM_ADD(app->msgq_params, name);
1161 p->msgq_in[p->n_msgq_in] = idx;
1169 parse_pipeline_msgq_out(struct app_params *app,
1170 struct app_pipeline_params *p,
1173 const char *next = value;
1175 char name[APP_PARAM_NAME_SIZE];
1179 while (*next != '\0') {
1183 next = skip_white_spaces(next);
1187 end_space = strchr(next, ' ');
1188 end_tab = strchr(next, ' ');
1190 if (end_space && (!end_tab))
1192 else if ((!end_space) && end_tab)
1194 else if (end_space && end_tab)
1195 end = RTE_MIN(end_space, end_tab);
1200 name_len = strlen(next);
1202 name_len = end - next;
1204 if (name_len == 0 || name_len == sizeof(name))
1207 strncpy(name, next, name_len);
1208 name[name_len] = '\0';
1213 if (validate_name(name, "MSGQ", 1) != 0)
1216 idx = APP_PARAM_ADD(app->msgq_params, name);
1220 p->msgq_out[p->n_msgq_out] = idx;
1228 parse_pipeline(struct app_params *app,
1229 const char *section_name,
1230 struct rte_cfgfile *cfg)
1232 char name[CFG_NAME_LEN];
1233 struct app_pipeline_params *param;
1234 struct rte_cfgfile_entry *entries;
1238 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1239 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1241 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1242 PARSE_ERROR_MALLOC(entries != NULL);
1244 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1246 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1247 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1249 param = &app->pipeline_params[param_idx];
1251 for (i = 0; i < n_entries; i++) {
1252 struct rte_cfgfile_entry *ent = &entries[i];
1254 if (strcmp(ent->name, "type") == 0) {
1255 int w_size = snprintf(param->type, RTE_DIM(param->type),
1258 PARSE_ERROR(((w_size > 0) &&
1259 (w_size < (int)RTE_DIM(param->type))),
1265 if (strcmp(ent->name, "core") == 0) {
1266 int status = parse_pipeline_core(
1267 ¶m->socket_id, ¶m->core_id,
1268 ¶m->hyper_th_id, ent->value);
1270 PARSE_ERROR((status == 0), section_name,
1275 if (strcmp(ent->name, "pktq_in") == 0) {
1276 int status = parse_pipeline_pktq_in(app, param,
1279 PARSE_ERROR((status == 0), section_name,
1284 if (strcmp(ent->name, "pktq_out") == 0) {
1285 int status = parse_pipeline_pktq_out(app, param,
1288 PARSE_ERROR((status == 0), section_name,
1293 if (strcmp(ent->name, "msgq_in") == 0) {
1294 int status = parse_pipeline_msgq_in(app, param,
1297 PARSE_ERROR((status == 0), section_name,
1302 if (strcmp(ent->name, "msgq_out") == 0) {
1303 int status = parse_pipeline_msgq_out(app, param,
1306 PARSE_ERROR((status == 0), section_name,
1311 if (strcmp(ent->name, "timer_period") == 0) {
1312 int status = parser_read_uint32(
1313 ¶m->timer_period,
1316 PARSE_ERROR((status == 0), section_name,
1321 /* pipeline type specific items */
1322 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1323 "Parse error in section \"%s\": too many "
1324 "pipeline specified parameters", section_name);
1326 param->args_name[param->n_args] = strdup(ent->name);
1327 param->args_value[param->n_args] = strdup(ent->value);
1329 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1330 (param->args_value[param->n_args] != NULL),
1331 "Parse error: no free memory");
1338 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1339 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1340 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1341 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1342 param->msgq_in[param->n_msgq_in++] = param_idx;
1344 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1345 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1346 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1347 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1348 param->msgq_out[param->n_msgq_out++] = param_idx;
1350 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1353 (param->hyper_th_id) ? "h" : "");
1354 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1355 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1356 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1358 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1361 (param->hyper_th_id) ? "h" : "");
1362 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1363 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1364 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1370 parse_mempool(struct app_params *app,
1371 const char *section_name,
1372 struct rte_cfgfile *cfg)
1374 struct app_mempool_params *param;
1375 struct rte_cfgfile_entry *entries;
1379 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1380 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1382 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1383 PARSE_ERROR_MALLOC(entries != NULL);
1385 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1387 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1388 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1390 param = &app->mempool_params[param_idx];
1392 for (i = 0; i < n_entries; i++) {
1393 struct rte_cfgfile_entry *ent = &entries[i];
1395 if (strcmp(ent->name, "buffer_size") == 0) {
1396 int status = parser_read_uint32(
1397 ¶m->buffer_size, ent->value);
1399 PARSE_ERROR((status == 0), section_name,
1404 if (strcmp(ent->name, "pool_size") == 0) {
1405 int status = parser_read_uint32(
1406 ¶m->pool_size, ent->value);
1408 PARSE_ERROR((status == 0), section_name,
1413 if (strcmp(ent->name, "cache_size") == 0) {
1414 int status = parser_read_uint32(
1415 ¶m->cache_size, ent->value);
1417 PARSE_ERROR((status == 0), section_name,
1422 if (strcmp(ent->name, "cpu") == 0) {
1423 int status = parser_read_uint32(
1424 ¶m->cpu_socket_id, ent->value);
1426 PARSE_ERROR((status == 0), section_name,
1432 PARSE_ERROR_INVALID(0, section_name, ent->name);
1441 parse_link(struct app_params *app,
1442 const char *section_name,
1443 struct rte_cfgfile *cfg)
1445 struct app_link_params *param;
1446 struct rte_cfgfile_entry *entries;
1448 int pci_bdf_present = 0;
1451 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1452 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1454 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1455 PARSE_ERROR_MALLOC(entries != NULL);
1457 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1459 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1460 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1462 param = &app->link_params[param_idx];
1464 for (i = 0; i < n_entries; i++) {
1465 struct rte_cfgfile_entry *ent = &entries[i];
1467 if (strcmp(ent->name, "promisc") == 0) {
1468 int status = parser_read_arg_bool(ent->value);
1470 PARSE_ERROR((status != -EINVAL), section_name,
1472 param->promisc = status;
1476 if (strcmp(ent->name, "arp_q") == 0) {
1477 int status = parser_read_uint32(¶m->arp_q,
1480 PARSE_ERROR((status == 0), section_name,
1485 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1486 int status = parser_read_uint32(
1487 ¶m->tcp_syn_q, ent->value);
1489 PARSE_ERROR((status == 0), section_name, ent->name);
1493 if (strcmp(ent->name, "ip_local_q") == 0) {
1494 int status = parser_read_uint32(
1495 ¶m->ip_local_q, ent->value);
1497 PARSE_ERROR((status == 0), section_name,
1503 if (strcmp(ent->name, "tcp_local_q") == 0) {
1504 int status = parser_read_uint32(
1505 ¶m->tcp_local_q, ent->value);
1507 PARSE_ERROR((status == 0), section_name,
1512 if (strcmp(ent->name, "udp_local_q") == 0) {
1513 int status = parser_read_uint32(
1514 ¶m->udp_local_q, ent->value);
1516 PARSE_ERROR((status == 0), section_name,
1521 if (strcmp(ent->name, "sctp_local_q") == 0) {
1522 int status = parser_read_uint32(
1523 ¶m->sctp_local_q, ent->value);
1525 PARSE_ERROR((status == 0), section_name,
1530 if (strcmp(ent->name, "pci_bdf") == 0) {
1531 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1532 section_name, ent->name);
1534 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1536 pci_bdf_present = 1;
1541 PARSE_ERROR_INVALID(0, section_name, ent->name);
1544 /* Check for mandatory fields */
1546 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1547 section_name, "pci_bdf",
1548 "entry not allowed (port_mask is provided)");
1550 PARSE_ERROR_MESSAGE((pci_bdf_present),
1551 section_name, "pci_bdf",
1552 "this entry is mandatory (port_mask is not "
1561 parse_rxq(struct app_params *app,
1562 const char *section_name,
1563 struct rte_cfgfile *cfg)
1565 struct app_pktq_hwq_in_params *param;
1566 struct rte_cfgfile_entry *entries;
1570 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1571 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1573 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1574 PARSE_ERROR_MALLOC(entries != NULL);
1576 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1578 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1579 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1581 param = &app->hwq_in_params[param_idx];
1583 for (i = 0; i < n_entries; i++) {
1584 struct rte_cfgfile_entry *ent = &entries[i];
1586 if (strcmp(ent->name, "mempool") == 0) {
1587 int status = validate_name(ent->value,
1591 PARSE_ERROR((status == 0), section_name,
1593 idx = APP_PARAM_ADD(app->mempool_params,
1595 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1597 param->mempool_id = idx;
1601 if (strcmp(ent->name, "size") == 0) {
1602 int status = parser_read_uint32(¶m->size,
1605 PARSE_ERROR((status == 0), section_name,
1610 if (strcmp(ent->name, "burst") == 0) {
1611 int status = parser_read_uint32(¶m->burst,
1614 PARSE_ERROR((status == 0), section_name,
1620 PARSE_ERROR_INVALID(0, section_name, ent->name);
1629 parse_txq(struct app_params *app,
1630 const char *section_name,
1631 struct rte_cfgfile *cfg)
1633 struct app_pktq_hwq_out_params *param;
1634 struct rte_cfgfile_entry *entries;
1638 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1639 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1641 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1642 PARSE_ERROR_MALLOC(entries != NULL);
1644 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1646 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1647 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1649 param = &app->hwq_out_params[param_idx];
1651 for (i = 0; i < n_entries; i++) {
1652 struct rte_cfgfile_entry *ent = &entries[i];
1654 if (strcmp(ent->name, "size") == 0) {
1655 int status = parser_read_uint32(¶m->size,
1658 PARSE_ERROR((status == 0), section_name,
1663 if (strcmp(ent->name, "burst") == 0) {
1664 int status = parser_read_uint32(¶m->burst,
1667 PARSE_ERROR((status == 0), section_name,
1672 if (strcmp(ent->name, "dropless") == 0) {
1673 int status = parser_read_arg_bool(ent->value);
1676 PARSE_ERROR((status != -EINVAL), section_name,
1678 param->dropless = status;
1683 PARSE_ERROR_INVALID(0, section_name, ent->name);
1692 parse_swq(struct app_params *app,
1693 const char *section_name,
1694 struct rte_cfgfile *cfg)
1696 struct app_pktq_swq_params *param;
1697 struct rte_cfgfile_entry *entries;
1699 uint32_t mtu_present = 0;
1700 uint32_t metadata_size_present = 0;
1701 uint32_t mempool_direct_present = 0;
1702 uint32_t mempool_indirect_present = 0;
1706 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1707 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1709 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1710 PARSE_ERROR_MALLOC(entries != NULL);
1712 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1714 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1715 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1717 param = &app->swq_params[param_idx];
1719 for (i = 0; i < n_entries; i++) {
1720 struct rte_cfgfile_entry *ent = &entries[i];
1722 if (strcmp(ent->name, "size") == 0) {
1723 int status = parser_read_uint32(¶m->size,
1726 PARSE_ERROR((status == 0), section_name,
1731 if (strcmp(ent->name, "burst_read") == 0) {
1732 int status = parser_read_uint32(&
1733 param->burst_read, ent->value);
1735 PARSE_ERROR((status == 0), section_name,
1740 if (strcmp(ent->name, "burst_write") == 0) {
1741 int status = parser_read_uint32(
1742 ¶m->burst_write, ent->value);
1744 PARSE_ERROR((status == 0), section_name,
1749 if (strcmp(ent->name, "dropless") == 0) {
1750 int status = parser_read_arg_bool(ent->value);
1752 PARSE_ERROR((status != -EINVAL), section_name,
1754 param->dropless = status;
1758 if (strcmp(ent->name, "n_retries") == 0) {
1759 int status = parser_read_uint64(¶m->n_retries,
1762 PARSE_ERROR((status == 0), section_name,
1767 if (strcmp(ent->name, "cpu") == 0) {
1768 int status = parser_read_uint32(
1769 ¶m->cpu_socket_id, ent->value);
1771 PARSE_ERROR((status == 0), section_name, ent->name);
1775 if (strcmp(ent->name, "ipv4_frag") == 0) {
1776 int status = parser_read_arg_bool(ent->value);
1778 PARSE_ERROR((status != -EINVAL), section_name,
1781 param->ipv4_frag = status;
1782 if (param->mtu == 0)
1788 if (strcmp(ent->name, "ipv6_frag") == 0) {
1789 int status = parser_read_arg_bool(ent->value);
1791 PARSE_ERROR((status != -EINVAL), section_name,
1793 param->ipv6_frag = status;
1794 if (param->mtu == 0)
1799 if (strcmp(ent->name, "ipv4_ras") == 0) {
1800 int status = parser_read_arg_bool(ent->value);
1802 PARSE_ERROR((status != -EINVAL), section_name,
1804 param->ipv4_ras = status;
1808 if (strcmp(ent->name, "ipv6_ras") == 0) {
1809 int status = parser_read_arg_bool(ent->value);
1811 PARSE_ERROR((status != -EINVAL), section_name,
1813 param->ipv6_ras = status;
1817 if (strcmp(ent->name, "mtu") == 0) {
1818 int status = parser_read_uint32(¶m->mtu,
1821 PARSE_ERROR((status == 0), section_name,
1827 if (strcmp(ent->name, "metadata_size") == 0) {
1828 int status = parser_read_uint32(
1829 ¶m->metadata_size, ent->value);
1831 PARSE_ERROR((status == 0), section_name,
1833 metadata_size_present = 1;
1837 if (strcmp(ent->name, "mempool_direct") == 0) {
1838 int status = validate_name(ent->value,
1842 PARSE_ERROR((status == 0), section_name,
1845 idx = APP_PARAM_ADD(app->mempool_params,
1847 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1849 param->mempool_direct_id = idx;
1850 mempool_direct_present = 1;
1854 if (strcmp(ent->name, "mempool_indirect") == 0) {
1855 int status = validate_name(ent->value,
1859 PARSE_ERROR((status == 0), section_name,
1861 idx = APP_PARAM_ADD(app->mempool_params,
1863 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1865 param->mempool_indirect_id = idx;
1866 mempool_indirect_present = 1;
1871 PARSE_ERROR_INVALID(0, section_name, ent->name);
1874 APP_CHECK(((mtu_present) &&
1875 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1876 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1877 "is off, therefore entry \"mtu\" is not allowed",
1880 APP_CHECK(((metadata_size_present) &&
1881 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1882 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1883 "is off, therefore entry \"metadata_size\" is "
1884 "not allowed", section_name);
1886 APP_CHECK(((mempool_direct_present) &&
1887 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1888 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1889 "is off, therefore entry \"mempool_direct\" is "
1890 "not allowed", section_name);
1892 APP_CHECK(((mempool_indirect_present) &&
1893 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
1894 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
1895 "is off, therefore entry \"mempool_indirect\" is "
1896 "not allowed", section_name);
1904 parse_tm(struct app_params *app,
1905 const char *section_name,
1906 struct rte_cfgfile *cfg)
1908 struct app_pktq_tm_params *param;
1909 struct rte_cfgfile_entry *entries;
1913 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1914 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1916 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1917 PARSE_ERROR_MALLOC(entries != NULL);
1919 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1921 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1922 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
1924 param = &app->tm_params[param_idx];
1926 for (i = 0; i < n_entries; i++) {
1927 struct rte_cfgfile_entry *ent = &entries[i];
1929 if (strcmp(ent->name, "cfg") == 0) {
1930 param->file_name = strdup(ent->value);
1931 PARSE_ERROR_MALLOC(param->file_name != NULL);
1935 if (strcmp(ent->name, "burst_read") == 0) {
1936 int status = parser_read_uint32(
1937 ¶m->burst_read, ent->value);
1939 PARSE_ERROR((status == 0), section_name,
1944 if (strcmp(ent->name, "burst_write") == 0) {
1945 int status = parser_read_uint32(
1946 ¶m->burst_write, ent->value);
1948 PARSE_ERROR((status == 0), section_name,
1954 PARSE_ERROR_INVALID(0, section_name, ent->name);
1963 parse_source(struct app_params *app,
1964 const char *section_name,
1965 struct rte_cfgfile *cfg)
1967 struct app_pktq_source_params *param;
1968 struct rte_cfgfile_entry *entries;
1971 uint32_t pcap_file_present = 0;
1972 uint32_t pcap_size_present = 0;
1974 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1975 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1977 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1978 PARSE_ERROR_MALLOC(entries != NULL);
1980 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1982 param_idx = APP_PARAM_ADD(app->source_params, section_name);
1983 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
1985 param = &app->source_params[param_idx];
1987 for (i = 0; i < n_entries; i++) {
1988 struct rte_cfgfile_entry *ent = &entries[i];
1990 if (strcmp(ent->name, "mempool") == 0) {
1991 int status = validate_name(ent->value,
1995 PARSE_ERROR((status == 0), section_name,
1997 idx = APP_PARAM_ADD(app->mempool_params,
1999 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2001 param->mempool_id = idx;
2005 if (strcmp(ent->name, "burst") == 0) {
2006 int status = parser_read_uint32(¶m->burst,
2009 PARSE_ERROR((status == 0), section_name,
2014 if (strcmp(ent->name, "pcap_file_rd") == 0) {
2015 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2016 section_name, ent->name);
2018 param->file_name = strdup(ent->value);
2020 PARSE_ERROR_MALLOC(param->file_name != NULL);
2021 pcap_file_present = 1;
2026 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2029 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2030 section_name, ent->name);
2032 status = parser_read_uint32(
2033 ¶m->n_bytes_per_pkt, ent->value);
2035 PARSE_ERROR((status == 0), section_name,
2037 pcap_size_present = 1;
2043 PARSE_ERROR_INVALID(0, section_name, ent->name);
2052 parse_sink(struct app_params *app,
2053 const char *section_name,
2054 struct rte_cfgfile *cfg)
2056 struct app_pktq_sink_params *param;
2057 struct rte_cfgfile_entry *entries;
2060 uint32_t pcap_file_present = 0;
2061 uint32_t pcap_n_pkt_present = 0;
2063 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2064 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2066 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2067 PARSE_ERROR_MALLOC(entries != NULL);
2069 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2071 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2072 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2074 param = &app->sink_params[param_idx];
2076 for (i = 0; i < n_entries; i++) {
2077 struct rte_cfgfile_entry *ent = &entries[i];
2079 if (strcmp(ent->name, "pcap_file_wr") == 0) {
2080 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2081 section_name, ent->name);
2083 param->file_name = strdup(ent->value);
2085 PARSE_ERROR_MALLOC((param->file_name != NULL));
2090 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
2093 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2094 section_name, ent->name);
2096 status = parser_read_uint32(
2097 ¶m->n_pkts_to_dump, ent->value);
2099 PARSE_ERROR((status == 0), section_name,
2106 PARSE_ERROR_INVALID(0, section_name, ent->name);
2115 parse_msgq_req_pipeline(struct app_params *app,
2116 const char *section_name,
2117 struct rte_cfgfile *cfg)
2119 struct app_msgq_params *param;
2120 struct rte_cfgfile_entry *entries;
2124 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2125 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2127 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2128 PARSE_ERROR_MALLOC(entries != NULL);
2130 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2132 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2133 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2135 param = &app->msgq_params[param_idx];
2137 for (i = 0; i < n_entries; i++) {
2138 struct rte_cfgfile_entry *ent = &entries[i];
2140 if (strcmp(ent->name, "size") == 0) {
2141 int status = parser_read_uint32(¶m->size,
2144 PARSE_ERROR((status == 0), section_name,
2150 PARSE_ERROR_INVALID(0, section_name, ent->name);
2158 parse_msgq_rsp_pipeline(struct app_params *app,
2159 const char *section_name,
2160 struct rte_cfgfile *cfg)
2162 struct app_msgq_params *param;
2163 struct rte_cfgfile_entry *entries;
2167 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2168 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2170 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2171 PARSE_ERROR_MALLOC(entries != NULL);
2173 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2175 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2176 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2178 param = &app->msgq_params[param_idx];
2180 for (i = 0; i < n_entries; i++) {
2181 struct rte_cfgfile_entry *ent = &entries[i];
2183 if (strcmp(ent->name, "size") == 0) {
2184 int status = parser_read_uint32(¶m->size,
2187 PARSE_ERROR((status == 0), section_name,
2193 PARSE_ERROR_INVALID(0, section_name, ent->name);
2202 parse_msgq(struct app_params *app,
2203 const char *section_name,
2204 struct rte_cfgfile *cfg)
2206 struct app_msgq_params *param;
2207 struct rte_cfgfile_entry *entries;
2211 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2212 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2214 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2215 PARSE_ERROR_MALLOC(entries != NULL);
2217 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2219 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2220 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2222 param = &app->msgq_params[param_idx];
2224 for (i = 0; i < n_entries; i++) {
2225 struct rte_cfgfile_entry *ent = &entries[i];
2227 if (strcmp(ent->name, "size") == 0) {
2228 int status = parser_read_uint32(¶m->size,
2231 PARSE_ERROR((status == 0), section_name,
2236 if (strcmp(ent->name, "cpu") == 0) {
2237 int status = parser_read_uint32(
2238 ¶m->cpu_socket_id, ent->value);
2240 PARSE_ERROR((status == 0), section_name,
2246 PARSE_ERROR_INVALID(0, section_name, ent->name);
2254 typedef void (*config_section_load)(struct app_params *p,
2255 const char *section_name,
2256 struct rte_cfgfile *cfg);
2258 struct config_section {
2259 const char prefix[CFG_NAME_LEN];
2261 config_section_load load;
2264 static const struct config_section cfg_file_scheme[] = {
2265 {"EAL", 0, parse_eal},
2266 {"PIPELINE", 1, parse_pipeline},
2267 {"MEMPOOL", 1, parse_mempool},
2268 {"LINK", 1, parse_link},
2269 {"RXQ", 2, parse_rxq},
2270 {"TXQ", 2, parse_txq},
2271 {"SWQ", 1, parse_swq},
2272 {"TM", 1, parse_tm},
2273 {"SOURCE", 1, parse_source},
2274 {"SINK", 1, parse_sink},
2275 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2276 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2277 {"MSGQ", 1, parse_msgq},
2281 create_implicit_mempools(struct app_params *app)
2285 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2286 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2290 create_implicit_links_from_port_mask(struct app_params *app,
2293 uint32_t pmd_id, link_id;
2296 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2297 char name[APP_PARAM_NAME_SIZE];
2300 if ((port_mask & (1LLU << pmd_id)) == 0)
2303 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2304 idx = APP_PARAM_ADD(app->link_params, name);
2305 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2307 app->link_params[idx].pmd_id = pmd_id;
2313 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2317 for (i = 0; i < app->n_links; i++) {
2318 struct app_link_params *link = &app->link_params[i];
2325 app_config_parse(struct app_params *app, const char *file_name)
2327 struct rte_cfgfile *cfg;
2328 char **section_names;
2329 int i, j, sect_count;
2331 /* Implicit mempools */
2332 create_implicit_mempools(app);
2336 create_implicit_links_from_port_mask(app, app->port_mask);
2338 /* Load application configuration file */
2339 cfg = rte_cfgfile_load(file_name, 0);
2340 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2341 "file %s", file_name);
2343 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2344 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2345 "in file \"%s\" return %d", file_name,
2348 section_names = malloc(sect_count * sizeof(char *));
2349 PARSE_ERROR_MALLOC(section_names != NULL);
2351 for (i = 0; i < sect_count; i++)
2352 section_names[i] = malloc(CFG_NAME_LEN);
2354 rte_cfgfile_sections(cfg, section_names, sect_count);
2356 for (i = 0; i < sect_count; i++) {
2357 const struct config_section *sch_s;
2358 int len, cfg_name_len;
2360 cfg_name_len = strlen(section_names[i]);
2362 /* Find section type */
2363 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2364 sch_s = &cfg_file_scheme[j];
2365 len = strlen(sch_s->prefix);
2367 if (cfg_name_len < len)
2370 /* After section name we expect only '\0' or digit or
2371 * digit dot digit, so protect against false matching,
2372 * for example: "ABC" should match section name
2373 * "ABC0.0", but it should not match section_name
2376 if ((section_names[i][len] != '\0') &&
2377 !isdigit(section_names[i][len]))
2380 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2384 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2385 "Parse error: unknown section %s",
2388 APP_CHECK(validate_name(section_names[i],
2390 sch_s->numbers) == 0,
2391 "Parse error: invalid section name \"%s\"",
2394 sch_s->load(app, section_names[i], cfg);
2397 for (i = 0; i < sect_count; i++)
2398 free(section_names[i]);
2400 free(section_names);
2402 rte_cfgfile_close(cfg);
2404 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2405 APP_PARAM_COUNT(app->link_params, app->n_links);
2406 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2407 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2408 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2409 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2410 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2411 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2412 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2413 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2415 if (app->port_mask == 0)
2416 assign_link_pmd_id_from_pci_bdf(app);
2418 /* Save configuration to output file */
2419 app_config_save(app, app->output_file);
2421 /* Load TM configuration files */
2422 app_config_parse_tm(app);
2428 save_eal_params(struct app_params *app, FILE *f)
2430 struct app_eal_params *p = &app->eal_params;
2433 fprintf(f, "[EAL]\n");
2436 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2438 if (p->master_lcore_present)
2439 fprintf(f, "%s = %" PRIu32 "\n",
2440 "master_lcore", p->master_lcore);
2442 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2444 if (p->memory_present)
2445 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2447 if (p->ranks_present)
2448 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2450 for (i = 0; i < APP_MAX_LINKS; i++) {
2451 if (p->pci_blacklist[i] == NULL)
2454 fprintf(f, "%s = %s\n", "pci_blacklist",
2455 p->pci_blacklist[i]);
2458 for (i = 0; i < APP_MAX_LINKS; i++) {
2459 if (p->pci_whitelist[i] == NULL)
2462 fprintf(f, "%s = %s\n", "pci_whitelist",
2463 p->pci_whitelist[i]);
2466 for (i = 0; i < APP_MAX_LINKS; i++) {
2467 if (p->vdev[i] == NULL)
2470 fprintf(f, "%s = %s\n", "vdev",
2474 if (p->vmware_tsc_map_present)
2475 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2476 (p->vmware_tsc_map) ? "yes" : "no");
2479 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2482 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2484 if (p->log_level_present)
2485 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2487 if (p->version_present)
2488 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2490 if (p->help_present)
2491 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2493 if (p->no_huge_present)
2494 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2496 if (p->no_pci_present)
2497 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2499 if (p->no_hpet_present)
2500 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2502 if (p->no_shconf_present)
2503 fprintf(f, "%s = %s\n", "no_shconf",
2504 (p->no_shconf) ? "yes" : "no");
2507 fprintf(f, "%s = %s\n", "d", p->add_driver);
2510 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2513 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2516 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2518 if (p->base_virtaddr)
2519 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2521 if (p->create_uio_dev_present)
2522 fprintf(f, "%s = %s\n", "create_uio_dev",
2523 (p->create_uio_dev) ? "yes" : "no");
2526 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2528 if (p->xen_dom0_present)
2529 fprintf(f, "%s = %s\n", "xen_dom0",
2530 (p->xen_dom0) ? "yes" : "no");
2536 save_mempool_params(struct app_params *app, FILE *f)
2538 struct app_mempool_params *p;
2541 count = RTE_DIM(app->mempool_params);
2542 for (i = 0; i < count; i++) {
2543 p = &app->mempool_params[i];
2544 if (!APP_PARAM_VALID(p))
2547 fprintf(f, "[%s]\n", p->name);
2548 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2549 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2550 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2551 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2558 save_links_params(struct app_params *app, FILE *f)
2560 struct app_link_params *p;
2563 count = RTE_DIM(app->link_params);
2564 for (i = 0; i < count; i++) {
2565 p = &app->link_params[i];
2566 if (!APP_PARAM_VALID(p))
2569 fprintf(f, "[%s]\n", p->name);
2570 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2571 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2572 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2573 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2575 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2576 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2577 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2578 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2581 if (strlen(p->pci_bdf))
2582 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2589 save_rxq_params(struct app_params *app, FILE *f)
2591 struct app_pktq_hwq_in_params *p;
2594 count = RTE_DIM(app->hwq_in_params);
2595 for (i = 0; i < count; i++) {
2596 p = &app->hwq_in_params[i];
2597 if (!APP_PARAM_VALID(p))
2600 fprintf(f, "[%s]\n", p->name);
2601 fprintf(f, "%s = %s\n",
2603 app->mempool_params[p->mempool_id].name);
2604 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2605 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2612 save_txq_params(struct app_params *app, FILE *f)
2614 struct app_pktq_hwq_out_params *p;
2617 count = RTE_DIM(app->hwq_out_params);
2618 for (i = 0; i < count; i++) {
2619 p = &app->hwq_out_params[i];
2620 if (!APP_PARAM_VALID(p))
2623 fprintf(f, "[%s]\n", p->name);
2624 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2625 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2626 fprintf(f, "%s = %s\n",
2628 p->dropless ? "yes" : "no");
2635 save_swq_params(struct app_params *app, FILE *f)
2637 struct app_pktq_swq_params *p;
2640 count = RTE_DIM(app->swq_params);
2641 for (i = 0; i < count; i++) {
2642 p = &app->swq_params[i];
2643 if (!APP_PARAM_VALID(p))
2646 fprintf(f, "[%s]\n", p->name);
2647 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2648 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2649 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2650 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2651 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2652 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2653 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2654 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2655 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2656 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2657 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2658 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2659 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2660 fprintf(f, "%s = %s\n",
2662 app->mempool_params[p->mempool_direct_id].name);
2663 fprintf(f, "%s = %s\n",
2665 app->mempool_params[p->mempool_indirect_id].name);
2673 save_tm_params(struct app_params *app, FILE *f)
2675 struct app_pktq_tm_params *p;
2678 count = RTE_DIM(app->tm_params);
2679 for (i = 0; i < count; i++) {
2680 p = &app->tm_params[i];
2681 if (!APP_PARAM_VALID(p))
2684 fprintf(f, "[%s]\n", p->name);
2685 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2686 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2687 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2694 save_source_params(struct app_params *app, FILE *f)
2696 struct app_pktq_source_params *p;
2699 count = RTE_DIM(app->source_params);
2700 for (i = 0; i < count; i++) {
2701 p = &app->source_params[i];
2702 if (!APP_PARAM_VALID(p))
2705 fprintf(f, "[%s]\n", p->name);
2706 fprintf(f, "%s = %s\n",
2708 app->mempool_params[p->mempool_id].name);
2709 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2710 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2711 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2712 p->n_bytes_per_pkt);
2718 save_sink_params(struct app_params *app, FILE *f)
2720 struct app_pktq_sink_params *p;
2723 count = RTE_DIM(app->sink_params);
2724 for (i = 0; i < count; i++) {
2725 p = &app->sink_params[i];
2726 if (!APP_PARAM_VALID(p))
2729 fprintf(f, "[%s]\n", p->name);
2730 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2731 fprintf(f, "%s = %" PRIu32 "\n",
2732 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2738 save_msgq_params(struct app_params *app, FILE *f)
2740 struct app_msgq_params *p;
2743 count = RTE_DIM(app->msgq_params);
2744 for (i = 0; i < count; i++) {
2745 p = &app->msgq_params[i];
2746 if (!APP_PARAM_VALID(p))
2749 fprintf(f, "[%s]\n", p->name);
2750 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2751 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2758 save_pipeline_params(struct app_params *app, FILE *f)
2762 count = RTE_DIM(app->pipeline_params);
2763 for (i = 0; i < count; i++) {
2764 struct app_pipeline_params *p = &app->pipeline_params[i];
2766 if (!APP_PARAM_VALID(p))
2770 fprintf(f, "[%s]\n", p->name);
2773 fprintf(f, "type = %s\n", p->type);
2776 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2779 (p->hyper_th_id) ? "h" : "");
2785 fprintf(f, "pktq_in =");
2786 for (j = 0; j < p->n_pktq_in; j++) {
2787 struct app_pktq_in_params *pp = &p->pktq_in[j];
2791 case APP_PKTQ_IN_HWQ:
2792 name = app->hwq_in_params[pp->id].name;
2794 case APP_PKTQ_IN_SWQ:
2795 name = app->swq_params[pp->id].name;
2797 case APP_PKTQ_IN_TM:
2798 name = app->tm_params[pp->id].name;
2800 case APP_PKTQ_IN_SOURCE:
2801 name = app->source_params[pp->id].name;
2804 APP_CHECK(0, "System error "
2805 "occurred while saving "
2806 "parameter to file");
2809 fprintf(f, " %s", name);
2815 if (p->n_pktq_out) {
2818 fprintf(f, "pktq_out =");
2819 for (j = 0; j < p->n_pktq_out; j++) {
2820 struct app_pktq_out_params *pp =
2825 case APP_PKTQ_OUT_HWQ:
2826 name = app->hwq_out_params[pp->id].name;
2828 case APP_PKTQ_OUT_SWQ:
2829 name = app->swq_params[pp->id].name;
2831 case APP_PKTQ_OUT_TM:
2832 name = app->tm_params[pp->id].name;
2834 case APP_PKTQ_OUT_SINK:
2835 name = app->sink_params[pp->id].name;
2838 APP_CHECK(0, "System error "
2839 "occurred while saving "
2840 "parameter to file");
2843 fprintf(f, " %s", name);
2852 fprintf(f, "msgq_in =");
2853 for (j = 0; j < p->n_msgq_in; j++) {
2854 uint32_t id = p->msgq_in[j];
2855 char *name = app->msgq_params[id].name;
2857 fprintf(f, " %s", name);
2863 if (p->n_msgq_out) {
2866 fprintf(f, "msgq_out =");
2867 for (j = 0; j < p->n_msgq_out; j++) {
2868 uint32_t id = p->msgq_out[j];
2869 char *name = app->msgq_params[id].name;
2871 fprintf(f, " %s", name);
2877 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2883 for (j = 0; j < p->n_args; j++)
2884 fprintf(f, "%s = %s\n", p->args_name[j],
2893 app_config_save(struct app_params *app, const char *file_name)
2896 char *name, *dir_name;
2899 name = strdup(file_name);
2900 dir_name = dirname(name);
2901 status = access(dir_name, W_OK);
2902 APP_CHECK((status == 0),
2903 "Error: need write access privilege to directory "
2904 "\"%s\" to save configuration\n", dir_name);
2906 file = fopen(file_name, "w");
2907 APP_CHECK((file != NULL),
2908 "Error: failed to save configuration to file \"%s\"",
2911 save_eal_params(app, file);
2912 save_pipeline_params(app, file);
2913 save_mempool_params(app, file);
2914 save_links_params(app, file);
2915 save_rxq_params(app, file);
2916 save_txq_params(app, file);
2917 save_swq_params(app, file);
2918 save_tm_params(app, file);
2919 save_source_params(app, file);
2920 save_sink_params(app, file);
2921 save_msgq_params(app, file);
2928 app_config_init(struct app_params *app)
2932 memcpy(app, &app_params_default, sizeof(struct app_params));
2934 /* configure default_source_params */
2935 default_source_params.file_name = strdup("./config/packets.pcap");
2936 PARSE_ERROR_MALLOC(default_source_params.file_name != NULL);
2938 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2939 memcpy(&app->mempool_params[i],
2940 &mempool_params_default,
2941 sizeof(struct app_mempool_params));
2943 for (i = 0; i < RTE_DIM(app->link_params); i++)
2944 memcpy(&app->link_params[i],
2945 &link_params_default,
2946 sizeof(struct app_link_params));
2948 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2949 memcpy(&app->hwq_in_params[i],
2950 &default_hwq_in_params,
2951 sizeof(default_hwq_in_params));
2953 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2954 memcpy(&app->hwq_out_params[i],
2955 &default_hwq_out_params,
2956 sizeof(default_hwq_out_params));
2958 for (i = 0; i < RTE_DIM(app->swq_params); i++)
2959 memcpy(&app->swq_params[i],
2960 &default_swq_params,
2961 sizeof(default_swq_params));
2963 for (i = 0; i < RTE_DIM(app->tm_params); i++)
2964 memcpy(&app->tm_params[i],
2966 sizeof(default_tm_params));
2968 for (i = 0; i < RTE_DIM(app->source_params); i++)
2969 memcpy(&app->source_params[i],
2970 &default_source_params,
2971 sizeof(default_source_params));
2973 for (i = 0; i < RTE_DIM(app->sink_params); i++)
2974 memcpy(&app->sink_params[i],
2975 &default_sink_params,
2976 sizeof(default_sink_params));
2978 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2979 memcpy(&app->msgq_params[i],
2980 &default_msgq_params,
2981 sizeof(default_msgq_params));
2983 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2984 memcpy(&app->pipeline_params[i],
2985 &default_pipeline_params,
2986 sizeof(default_pipeline_params));
2992 filenamedup(const char *filename, const char *suffix)
2994 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2999 sprintf(s, "%s%s", filename, suffix);
3004 app_config_args(struct app_params *app, int argc, char **argv)
3006 const char *optname;
3007 int opt, option_index;
3008 int f_present, s_present, p_present, l_present;
3009 int preproc_present, preproc_params_present;
3012 static struct option lgopts[] = {
3013 { "preproc", 1, 0, 0 },
3014 { "preproc-args", 1, 0, 0 },
3018 /* Copy application name */
3019 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3025 preproc_present = 0;
3026 preproc_params_present = 0;
3028 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3029 &option_index)) != EOF)
3033 rte_panic("Error: Config file is provided "
3034 "more than once\n");
3037 if (!strlen(optarg))
3038 rte_panic("Error: Config file name is null\n");
3040 app->config_file = strdup(optarg);
3041 if (app->config_file == NULL)
3042 rte_panic("Error: Memory allocation failure\n");
3048 rte_panic("Error: Script file is provided "
3049 "more than once\n");
3052 if (!strlen(optarg))
3053 rte_panic("Error: Script file name is null\n");
3055 app->script_file = strdup(optarg);
3056 if (app->script_file == NULL)
3057 rte_panic("Error: Memory allocation failure\n");
3063 rte_panic("Error: PORT_MASK is provided "
3064 "more than once\n");
3067 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3069 ((size_t) scaned != strlen(optarg)))
3070 rte_panic("Error: PORT_MASK is not "
3071 "a hexadecimal integer\n");
3073 if (app->port_mask == 0)
3074 rte_panic("Error: PORT_MASK is null\n");
3080 rte_panic("Error: LOG_LEVEL is provided "
3081 "more than once\n");
3084 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3086 ((size_t) scaned != strlen(optarg)) ||
3087 (app->log_level >= APP_LOG_LEVELS))
3088 rte_panic("Error: LOG_LEVEL invalid value\n");
3093 optname = lgopts[option_index].name;
3095 if (strcmp(optname, "preproc") == 0) {
3096 if (preproc_present)
3097 rte_panic("Error: Preprocessor argument "
3098 "is provided more than once\n");
3099 preproc_present = 1;
3101 app->preproc = strdup(optarg);
3105 if (strcmp(optname, "preproc-args") == 0) {
3106 if (preproc_params_present)
3107 rte_panic("Error: Preprocessor args "
3108 "are provided more than once\n");
3109 preproc_params_present = 1;
3111 app->preproc_args = strdup(optarg);
3115 app_print_usage(argv[0]);
3119 app_print_usage(argv[0]);
3122 optind = 0; /* reset getopt lib */
3124 /* Check dependencies between args */
3125 if (preproc_params_present && (preproc_present == 0))
3126 rte_panic("Error: Preprocessor args specified while "
3127 "preprocessor is not defined\n");
3129 app->parser_file = preproc_present ?
3130 filenamedup(app->config_file, ".preproc") :
3131 strdup(app->config_file);
3132 app->output_file = filenamedup(app->config_file, ".out");
3138 app_config_preproc(struct app_params *app)
3143 if (app->preproc == NULL)
3146 status = access(app->config_file, F_OK | R_OK);
3147 APP_CHECK((status == 0), "Error: Unable to open file %s",
3150 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3152 app->preproc_args ? app->preproc_args : "",
3156 status = system(buffer);
3157 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3158 "Error occurred while pre-processing file \"%s\"\n",