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_pcap_source(struct app_params *app,
968 struct app_pipeline_params *p,
969 const char *file_name, const char *cp_size)
971 const char *next = NULL;
976 if (file_name && !cp_size) {
978 parse_file = 1; /* parse file path */
979 } else if (cp_size && !file_name) {
981 parse_file = 0; /* parse copy size */
985 char name[APP_PARAM_NAME_SIZE];
988 if (p->n_pktq_in == 0)
991 for (i = 0; i < p->n_pktq_in; i++) {
992 if (p->pktq_in[i].type != APP_PKTQ_IN_SOURCE)
997 while (*next != '\0') {
1000 if (i >= p->n_pktq_in)
1003 id = p->pktq_in[i].id;
1005 end = strchr(next, ' ');
1007 name_len = strlen(next);
1009 name_len = end - next;
1011 if (name_len == 0 || name_len == sizeof(name))
1014 strncpy(name, next, name_len);
1015 name[name_len] = '\0';
1021 app->source_params[id].file_name = strdup(name);
1022 if (app->source_params[id].file_name == NULL)
1025 if (parser_read_uint32(
1026 &app->source_params[id].n_bytes_per_pkt,
1028 if (app->source_params[id].
1030 free(app->source_params[id].
1038 if (i == p->n_pktq_in)
1046 parse_pipeline_pcap_sink(struct app_params *app,
1047 struct app_pipeline_params *p,
1048 const char *file_name, const char *n_pkts_to_dump)
1050 const char *next = NULL;
1055 if (file_name && !n_pkts_to_dump) {
1057 parse_file = 1; /* parse file path */
1058 } else if (n_pkts_to_dump && !file_name) {
1059 next = n_pkts_to_dump;
1060 parse_file = 0; /* parse copy size */
1064 char name[APP_PARAM_NAME_SIZE];
1067 if (p->n_pktq_out == 0)
1070 for (i = 0; i < p->n_pktq_out; i++) {
1071 if (p->pktq_out[i].type != APP_PKTQ_OUT_SINK)
1076 while (*next != '\0') {
1079 if (i >= p->n_pktq_out)
1082 id = p->pktq_out[i].id;
1084 end = strchr(next, ' ');
1086 name_len = strlen(next);
1088 name_len = end - next;
1090 if (name_len == 0 || name_len == sizeof(name))
1093 strncpy(name, next, name_len);
1094 name[name_len] = '\0';
1100 app->sink_params[id].file_name = strdup(name);
1101 if (app->sink_params[id].file_name == NULL)
1104 if (parser_read_uint32(
1105 &app->sink_params[id].n_pkts_to_dump,
1107 if (app->sink_params[id].file_name !=
1109 free(app->sink_params[id].
1117 if (i == p->n_pktq_out)
1125 parse_pipeline_pktq_in(struct app_params *app,
1126 struct app_pipeline_params *p,
1129 const char *next = value;
1131 char name[APP_PARAM_NAME_SIZE];
1134 while (*next != '\0') {
1135 enum app_pktq_in_type type;
1140 next = skip_white_spaces(next);
1144 end_space = strchr(next, ' ');
1145 end_tab = strchr(next, ' ');
1147 if (end_space && (!end_tab))
1149 else if ((!end_space) && end_tab)
1151 else if (end_space && end_tab)
1152 end = RTE_MIN(end_space, end_tab);
1157 name_len = strlen(next);
1159 name_len = end - next;
1161 if (name_len == 0 || name_len == sizeof(name))
1164 strncpy(name, next, name_len);
1165 name[name_len] = '\0';
1170 if (validate_name(name, "RXQ", 2) == 0) {
1171 type = APP_PKTQ_IN_HWQ;
1172 id = APP_PARAM_ADD(app->hwq_in_params, name);
1173 } else if (validate_name(name, "SWQ", 1) == 0) {
1174 type = APP_PKTQ_IN_SWQ;
1175 id = APP_PARAM_ADD(app->swq_params, name);
1176 } else if (validate_name(name, "TM", 1) == 0) {
1177 type = APP_PKTQ_IN_TM;
1178 id = APP_PARAM_ADD(app->tm_params, name);
1179 } else if (validate_name(name, "SOURCE", 1) == 0) {
1180 type = APP_PKTQ_IN_SOURCE;
1181 id = APP_PARAM_ADD(app->source_params, name);
1188 p->pktq_in[p->n_pktq_in].type = type;
1189 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1197 parse_pipeline_pktq_out(struct app_params *app,
1198 struct app_pipeline_params *p,
1201 const char *next = value;
1203 char name[APP_PARAM_NAME_SIZE];
1206 while (*next != '\0') {
1207 enum app_pktq_out_type type;
1212 next = skip_white_spaces(next);
1216 end_space = strchr(next, ' ');
1217 end_tab = strchr(next, ' ');
1219 if (end_space && (!end_tab))
1221 else if ((!end_space) && end_tab)
1223 else if (end_space && end_tab)
1224 end = RTE_MIN(end_space, end_tab);
1229 name_len = strlen(next);
1231 name_len = end - next;
1233 if (name_len == 0 || name_len == sizeof(name))
1236 strncpy(name, next, name_len);
1237 name[name_len] = '\0';
1241 if (validate_name(name, "TXQ", 2) == 0) {
1242 type = APP_PKTQ_OUT_HWQ;
1243 id = APP_PARAM_ADD(app->hwq_out_params, name);
1244 } else if (validate_name(name, "SWQ", 1) == 0) {
1245 type = APP_PKTQ_OUT_SWQ;
1246 id = APP_PARAM_ADD(app->swq_params, name);
1247 } else if (validate_name(name, "TM", 1) == 0) {
1248 type = APP_PKTQ_OUT_TM;
1249 id = APP_PARAM_ADD(app->tm_params, name);
1250 } else if (validate_name(name, "SINK", 1) == 0) {
1251 type = APP_PKTQ_OUT_SINK;
1252 id = APP_PARAM_ADD(app->sink_params, name);
1259 p->pktq_out[p->n_pktq_out].type = type;
1260 p->pktq_out[p->n_pktq_out].id = id;
1268 parse_pipeline_msgq_in(struct app_params *app,
1269 struct app_pipeline_params *p,
1272 const char *next = value;
1274 char name[APP_PARAM_NAME_SIZE];
1278 while (*next != '\0') {
1282 next = skip_white_spaces(next);
1286 end_space = strchr(next, ' ');
1287 end_tab = strchr(next, ' ');
1289 if (end_space && (!end_tab))
1291 else if ((!end_space) && end_tab)
1293 else if (end_space && end_tab)
1294 end = RTE_MIN(end_space, end_tab);
1299 name_len = strlen(next);
1301 name_len = end - next;
1303 if (name_len == 0 || name_len == sizeof(name))
1306 strncpy(name, next, name_len);
1307 name[name_len] = '\0';
1312 if (validate_name(name, "MSGQ", 1) != 0)
1315 idx = APP_PARAM_ADD(app->msgq_params, name);
1319 p->msgq_in[p->n_msgq_in] = idx;
1327 parse_pipeline_msgq_out(struct app_params *app,
1328 struct app_pipeline_params *p,
1331 const char *next = value;
1333 char name[APP_PARAM_NAME_SIZE];
1337 while (*next != '\0') {
1341 next = skip_white_spaces(next);
1345 end_space = strchr(next, ' ');
1346 end_tab = strchr(next, ' ');
1348 if (end_space && (!end_tab))
1350 else if ((!end_space) && end_tab)
1352 else if (end_space && end_tab)
1353 end = RTE_MIN(end_space, end_tab);
1358 name_len = strlen(next);
1360 name_len = end - next;
1362 if (name_len == 0 || name_len == sizeof(name))
1365 strncpy(name, next, name_len);
1366 name[name_len] = '\0';
1371 if (validate_name(name, "MSGQ", 1) != 0)
1374 idx = APP_PARAM_ADD(app->msgq_params, name);
1378 p->msgq_out[p->n_msgq_out] = idx;
1386 parse_pipeline(struct app_params *app,
1387 const char *section_name,
1388 struct rte_cfgfile *cfg)
1390 char name[CFG_NAME_LEN];
1391 struct app_pipeline_params *param;
1392 struct rte_cfgfile_entry *entries;
1396 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1397 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1399 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1400 PARSE_ERROR_MALLOC(entries != NULL);
1402 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1404 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1405 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1407 param = &app->pipeline_params[param_idx];
1409 for (i = 0; i < n_entries; i++) {
1410 struct rte_cfgfile_entry *ent = &entries[i];
1412 if (strcmp(ent->name, "type") == 0) {
1413 int w_size = snprintf(param->type, RTE_DIM(param->type),
1416 PARSE_ERROR(((w_size > 0) &&
1417 (w_size < (int)RTE_DIM(param->type))),
1423 if (strcmp(ent->name, "core") == 0) {
1424 int status = parse_pipeline_core(
1425 ¶m->socket_id, ¶m->core_id,
1426 ¶m->hyper_th_id, ent->value);
1428 PARSE_ERROR((status == 0), section_name,
1433 if (strcmp(ent->name, "pktq_in") == 0) {
1434 int status = parse_pipeline_pktq_in(app, param,
1437 PARSE_ERROR((status == 0), section_name,
1442 if (strcmp(ent->name, "pktq_out") == 0) {
1443 int status = parse_pipeline_pktq_out(app, param,
1446 PARSE_ERROR((status == 0), section_name,
1451 if (strcmp(ent->name, "msgq_in") == 0) {
1452 int status = parse_pipeline_msgq_in(app, param,
1455 PARSE_ERROR((status == 0), section_name,
1460 if (strcmp(ent->name, "msgq_out") == 0) {
1461 int status = parse_pipeline_msgq_out(app, param,
1464 PARSE_ERROR((status == 0), section_name,
1469 if (strcmp(ent->name, "timer_period") == 0) {
1470 int status = parser_read_uint32(
1471 ¶m->timer_period,
1474 PARSE_ERROR((status == 0), section_name,
1479 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1480 int status = parse_pipeline_pcap_source(app,
1481 param, ent->value, NULL);
1483 PARSE_ERROR((status == 0), section_name,
1488 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1489 int status = parse_pipeline_pcap_source(app,
1490 param, NULL, ent->value);
1492 PARSE_ERROR((status == 0), section_name,
1497 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1498 int status = parse_pipeline_pcap_sink(app, param,
1501 PARSE_ERROR((status == 0), section_name,
1506 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1507 int status = parse_pipeline_pcap_sink(app, param,
1510 PARSE_ERROR((status == 0), section_name,
1515 /* pipeline type specific items */
1516 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1517 "Parse error in section \"%s\": too many "
1518 "pipeline specified parameters", section_name);
1520 param->args_name[param->n_args] = strdup(ent->name);
1521 param->args_value[param->n_args] = strdup(ent->value);
1523 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1524 (param->args_value[param->n_args] != NULL),
1525 "Parse error: no free memory");
1532 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1533 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1534 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1535 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1536 param->msgq_in[param->n_msgq_in++] = param_idx;
1538 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1539 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1540 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1541 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1542 param->msgq_out[param->n_msgq_out++] = param_idx;
1544 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1547 (param->hyper_th_id) ? "h" : "");
1548 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1549 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1550 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1552 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1555 (param->hyper_th_id) ? "h" : "");
1556 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1557 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1558 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1564 parse_mempool(struct app_params *app,
1565 const char *section_name,
1566 struct rte_cfgfile *cfg)
1568 struct app_mempool_params *param;
1569 struct rte_cfgfile_entry *entries;
1573 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1574 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1576 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1577 PARSE_ERROR_MALLOC(entries != NULL);
1579 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1581 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1582 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1584 param = &app->mempool_params[param_idx];
1586 for (i = 0; i < n_entries; i++) {
1587 struct rte_cfgfile_entry *ent = &entries[i];
1589 if (strcmp(ent->name, "buffer_size") == 0) {
1590 int status = parser_read_uint32(
1591 ¶m->buffer_size, ent->value);
1593 PARSE_ERROR((status == 0), section_name,
1598 if (strcmp(ent->name, "pool_size") == 0) {
1599 int status = parser_read_uint32(
1600 ¶m->pool_size, ent->value);
1602 PARSE_ERROR((status == 0), section_name,
1607 if (strcmp(ent->name, "cache_size") == 0) {
1608 int status = parser_read_uint32(
1609 ¶m->cache_size, ent->value);
1611 PARSE_ERROR((status == 0), section_name,
1616 if (strcmp(ent->name, "cpu") == 0) {
1617 int status = parser_read_uint32(
1618 ¶m->cpu_socket_id, ent->value);
1620 PARSE_ERROR((status == 0), section_name,
1626 PARSE_ERROR_INVALID(0, section_name, ent->name);
1635 parse_link(struct app_params *app,
1636 const char *section_name,
1637 struct rte_cfgfile *cfg)
1639 struct app_link_params *param;
1640 struct rte_cfgfile_entry *entries;
1642 int pci_bdf_present = 0;
1645 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1646 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1648 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1649 PARSE_ERROR_MALLOC(entries != NULL);
1651 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1653 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1654 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1656 param = &app->link_params[param_idx];
1658 for (i = 0; i < n_entries; i++) {
1659 struct rte_cfgfile_entry *ent = &entries[i];
1661 if (strcmp(ent->name, "promisc") == 0) {
1662 int status = parser_read_arg_bool(ent->value);
1664 PARSE_ERROR((status != -EINVAL), section_name,
1666 param->promisc = status;
1670 if (strcmp(ent->name, "arp_q") == 0) {
1671 int status = parser_read_uint32(¶m->arp_q,
1674 PARSE_ERROR((status == 0), section_name,
1679 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1680 int status = parser_read_uint32(
1681 ¶m->tcp_syn_q, ent->value);
1683 PARSE_ERROR((status == 0), section_name, ent->name);
1687 if (strcmp(ent->name, "ip_local_q") == 0) {
1688 int status = parser_read_uint32(
1689 ¶m->ip_local_q, ent->value);
1691 PARSE_ERROR((status == 0), section_name,
1697 if (strcmp(ent->name, "tcp_local_q") == 0) {
1698 int status = parser_read_uint32(
1699 ¶m->tcp_local_q, ent->value);
1701 PARSE_ERROR((status == 0), section_name,
1706 if (strcmp(ent->name, "udp_local_q") == 0) {
1707 int status = parser_read_uint32(
1708 ¶m->udp_local_q, ent->value);
1710 PARSE_ERROR((status == 0), section_name,
1715 if (strcmp(ent->name, "sctp_local_q") == 0) {
1716 int status = parser_read_uint32(
1717 ¶m->sctp_local_q, ent->value);
1719 PARSE_ERROR((status == 0), section_name,
1724 if (strcmp(ent->name, "pci_bdf") == 0) {
1725 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1726 section_name, ent->name);
1728 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1730 pci_bdf_present = 1;
1735 PARSE_ERROR_INVALID(0, section_name, ent->name);
1738 /* Check for mandatory fields */
1740 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1741 section_name, "pci_bdf",
1742 "entry not allowed (port_mask is provided)");
1744 PARSE_ERROR_MESSAGE((pci_bdf_present),
1745 section_name, "pci_bdf",
1746 "this entry is mandatory (port_mask is not "
1755 parse_rxq(struct app_params *app,
1756 const char *section_name,
1757 struct rte_cfgfile *cfg)
1759 struct app_pktq_hwq_in_params *param;
1760 struct rte_cfgfile_entry *entries;
1764 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1765 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1767 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1768 PARSE_ERROR_MALLOC(entries != NULL);
1770 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1772 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1773 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1775 param = &app->hwq_in_params[param_idx];
1777 for (i = 0; i < n_entries; i++) {
1778 struct rte_cfgfile_entry *ent = &entries[i];
1780 if (strcmp(ent->name, "mempool") == 0) {
1781 int status = validate_name(ent->value,
1785 PARSE_ERROR((status == 0), section_name,
1787 idx = APP_PARAM_ADD(app->mempool_params,
1789 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1791 param->mempool_id = idx;
1795 if (strcmp(ent->name, "size") == 0) {
1796 int status = parser_read_uint32(¶m->size,
1799 PARSE_ERROR((status == 0), section_name,
1804 if (strcmp(ent->name, "burst") == 0) {
1805 int status = parser_read_uint32(¶m->burst,
1808 PARSE_ERROR((status == 0), section_name,
1814 PARSE_ERROR_INVALID(0, section_name, ent->name);
1823 parse_txq(struct app_params *app,
1824 const char *section_name,
1825 struct rte_cfgfile *cfg)
1827 struct app_pktq_hwq_out_params *param;
1828 struct rte_cfgfile_entry *entries;
1832 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1833 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1835 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1836 PARSE_ERROR_MALLOC(entries != NULL);
1838 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1840 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1841 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1843 param = &app->hwq_out_params[param_idx];
1845 for (i = 0; i < n_entries; i++) {
1846 struct rte_cfgfile_entry *ent = &entries[i];
1848 if (strcmp(ent->name, "size") == 0) {
1849 int status = parser_read_uint32(¶m->size,
1852 PARSE_ERROR((status == 0), section_name,
1857 if (strcmp(ent->name, "burst") == 0) {
1858 int status = parser_read_uint32(¶m->burst,
1861 PARSE_ERROR((status == 0), section_name,
1866 if (strcmp(ent->name, "dropless") == 0) {
1867 int status = parser_read_arg_bool(ent->value);
1870 PARSE_ERROR((status != -EINVAL), section_name,
1872 param->dropless = status;
1877 PARSE_ERROR_INVALID(0, section_name, ent->name);
1886 parse_swq(struct app_params *app,
1887 const char *section_name,
1888 struct rte_cfgfile *cfg)
1890 struct app_pktq_swq_params *param;
1891 struct rte_cfgfile_entry *entries;
1893 uint32_t mtu_present = 0;
1894 uint32_t metadata_size_present = 0;
1895 uint32_t mempool_direct_present = 0;
1896 uint32_t mempool_indirect_present = 0;
1900 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1901 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1903 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1904 PARSE_ERROR_MALLOC(entries != NULL);
1906 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1908 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1909 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1911 param = &app->swq_params[param_idx];
1913 for (i = 0; i < n_entries; i++) {
1914 struct rte_cfgfile_entry *ent = &entries[i];
1916 if (strcmp(ent->name, "size") == 0) {
1917 int status = parser_read_uint32(¶m->size,
1920 PARSE_ERROR((status == 0), section_name,
1925 if (strcmp(ent->name, "burst_read") == 0) {
1926 int status = parser_read_uint32(&
1927 param->burst_read, ent->value);
1929 PARSE_ERROR((status == 0), section_name,
1934 if (strcmp(ent->name, "burst_write") == 0) {
1935 int status = parser_read_uint32(
1936 ¶m->burst_write, ent->value);
1938 PARSE_ERROR((status == 0), section_name,
1943 if (strcmp(ent->name, "dropless") == 0) {
1944 int status = parser_read_arg_bool(ent->value);
1946 PARSE_ERROR((status != -EINVAL), section_name,
1948 param->dropless = status;
1952 if (strcmp(ent->name, "n_retries") == 0) {
1953 int status = parser_read_uint64(¶m->n_retries,
1956 PARSE_ERROR((status == 0), section_name,
1961 if (strcmp(ent->name, "cpu") == 0) {
1962 int status = parser_read_uint32(
1963 ¶m->cpu_socket_id, ent->value);
1965 PARSE_ERROR((status == 0), section_name, ent->name);
1969 if (strcmp(ent->name, "ipv4_frag") == 0) {
1970 int status = parser_read_arg_bool(ent->value);
1972 PARSE_ERROR((status != -EINVAL), section_name,
1975 param->ipv4_frag = status;
1976 if (param->mtu == 0)
1982 if (strcmp(ent->name, "ipv6_frag") == 0) {
1983 int status = parser_read_arg_bool(ent->value);
1985 PARSE_ERROR((status != -EINVAL), section_name,
1987 param->ipv6_frag = status;
1988 if (param->mtu == 0)
1993 if (strcmp(ent->name, "ipv4_ras") == 0) {
1994 int status = parser_read_arg_bool(ent->value);
1996 PARSE_ERROR((status != -EINVAL), section_name,
1998 param->ipv4_ras = status;
2002 if (strcmp(ent->name, "ipv6_ras") == 0) {
2003 int status = parser_read_arg_bool(ent->value);
2005 PARSE_ERROR((status != -EINVAL), section_name,
2007 param->ipv6_ras = status;
2011 if (strcmp(ent->name, "mtu") == 0) {
2012 int status = parser_read_uint32(¶m->mtu,
2015 PARSE_ERROR((status == 0), section_name,
2021 if (strcmp(ent->name, "metadata_size") == 0) {
2022 int status = parser_read_uint32(
2023 ¶m->metadata_size, ent->value);
2025 PARSE_ERROR((status == 0), section_name,
2027 metadata_size_present = 1;
2031 if (strcmp(ent->name, "mempool_direct") == 0) {
2032 int status = validate_name(ent->value,
2036 PARSE_ERROR((status == 0), section_name,
2039 idx = APP_PARAM_ADD(app->mempool_params,
2041 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2043 param->mempool_direct_id = idx;
2044 mempool_direct_present = 1;
2048 if (strcmp(ent->name, "mempool_indirect") == 0) {
2049 int status = validate_name(ent->value,
2053 PARSE_ERROR((status == 0), section_name,
2055 idx = APP_PARAM_ADD(app->mempool_params,
2057 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2059 param->mempool_indirect_id = idx;
2060 mempool_indirect_present = 1;
2065 PARSE_ERROR_INVALID(0, section_name, ent->name);
2068 APP_CHECK(((mtu_present) &&
2069 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2070 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2071 "is off, therefore entry \"mtu\" is not allowed",
2074 APP_CHECK(((metadata_size_present) &&
2075 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2076 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2077 "is off, therefore entry \"metadata_size\" is "
2078 "not allowed", section_name);
2080 APP_CHECK(((mempool_direct_present) &&
2081 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2082 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2083 "is off, therefore entry \"mempool_direct\" is "
2084 "not allowed", section_name);
2086 APP_CHECK(((mempool_indirect_present) &&
2087 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2088 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2089 "is off, therefore entry \"mempool_indirect\" is "
2090 "not allowed", section_name);
2098 parse_tm(struct app_params *app,
2099 const char *section_name,
2100 struct rte_cfgfile *cfg)
2102 struct app_pktq_tm_params *param;
2103 struct rte_cfgfile_entry *entries;
2107 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2108 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2110 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2111 PARSE_ERROR_MALLOC(entries != NULL);
2113 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2115 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2116 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2118 param = &app->tm_params[param_idx];
2120 for (i = 0; i < n_entries; i++) {
2121 struct rte_cfgfile_entry *ent = &entries[i];
2123 if (strcmp(ent->name, "cfg") == 0) {
2124 param->file_name = strdup(ent->value);
2125 PARSE_ERROR_MALLOC(param->file_name != NULL);
2129 if (strcmp(ent->name, "burst_read") == 0) {
2130 int status = parser_read_uint32(
2131 ¶m->burst_read, ent->value);
2133 PARSE_ERROR((status == 0), section_name,
2138 if (strcmp(ent->name, "burst_write") == 0) {
2139 int status = parser_read_uint32(
2140 ¶m->burst_write, ent->value);
2142 PARSE_ERROR((status == 0), section_name,
2148 PARSE_ERROR_INVALID(0, section_name, ent->name);
2157 parse_source(struct app_params *app,
2158 const char *section_name,
2159 struct rte_cfgfile *cfg)
2161 struct app_pktq_source_params *param;
2162 struct rte_cfgfile_entry *entries;
2166 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2167 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2169 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2170 PARSE_ERROR_MALLOC(entries != NULL);
2172 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2174 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2175 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2177 param = &app->source_params[param_idx];
2179 for (i = 0; i < n_entries; i++) {
2180 struct rte_cfgfile_entry *ent = &entries[i];
2182 if (strcmp(ent->name, "mempool") == 0) {
2183 int status = validate_name(ent->value,
2187 PARSE_ERROR((status == 0), section_name,
2189 idx = APP_PARAM_ADD(app->mempool_params,
2191 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2193 param->mempool_id = idx;
2197 if (strcmp(ent->name, "burst") == 0) {
2198 int status = parser_read_uint32(¶m->burst,
2201 PARSE_ERROR((status == 0), section_name,
2206 if (strcmp(ent->name, "pcap_file_rd")) {
2207 param->file_name = strdup(ent->value);
2209 PARSE_ERROR_MALLOC(param->file_name != NULL);
2213 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2214 int status = parser_read_uint32(
2215 ¶m->n_bytes_per_pkt, ent->value);
2217 PARSE_ERROR((status == 0), section_name,
2222 PARSE_ERROR_INVALID(0, section_name, ent->name);
2231 parse_sink(struct app_params *app,
2232 const char *section_name,
2233 struct rte_cfgfile *cfg)
2235 struct app_pktq_sink_params *param;
2236 struct rte_cfgfile_entry *entries;
2240 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2241 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2243 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2244 PARSE_ERROR_MALLOC(entries != NULL);
2246 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2248 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2249 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2251 param = &app->sink_params[param_idx];
2253 for (i = 0; i < n_entries; i++) {
2254 struct rte_cfgfile_entry *ent = &entries[i];
2256 if (strcmp(ent->name, "pcap_file_wr")) {
2257 param->file_name = strdup(ent->value);
2259 PARSE_ERROR_MALLOC((param->file_name != NULL));
2263 if (strcmp(ent->name, "pcap_n_pkt_wr")) {
2264 int status = parser_read_uint32(
2265 ¶m->n_pkts_to_dump, ent->value);
2267 PARSE_ERROR((status == 0), section_name,
2273 PARSE_ERROR_INVALID(0, section_name, ent->name);
2282 parse_msgq_req_pipeline(struct app_params *app,
2283 const char *section_name,
2284 struct rte_cfgfile *cfg)
2286 struct app_msgq_params *param;
2287 struct rte_cfgfile_entry *entries;
2291 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2292 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2294 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2295 PARSE_ERROR_MALLOC(entries != NULL);
2297 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2299 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2300 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2302 param = &app->msgq_params[param_idx];
2304 for (i = 0; i < n_entries; i++) {
2305 struct rte_cfgfile_entry *ent = &entries[i];
2307 if (strcmp(ent->name, "size") == 0) {
2308 int status = parser_read_uint32(¶m->size,
2311 PARSE_ERROR((status == 0), section_name,
2317 PARSE_ERROR_INVALID(0, section_name, ent->name);
2325 parse_msgq_rsp_pipeline(struct app_params *app,
2326 const char *section_name,
2327 struct rte_cfgfile *cfg)
2329 struct app_msgq_params *param;
2330 struct rte_cfgfile_entry *entries;
2334 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2335 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2337 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2338 PARSE_ERROR_MALLOC(entries != NULL);
2340 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2342 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2343 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2345 param = &app->msgq_params[param_idx];
2347 for (i = 0; i < n_entries; i++) {
2348 struct rte_cfgfile_entry *ent = &entries[i];
2350 if (strcmp(ent->name, "size") == 0) {
2351 int status = parser_read_uint32(¶m->size,
2354 PARSE_ERROR((status == 0), section_name,
2360 PARSE_ERROR_INVALID(0, section_name, ent->name);
2369 parse_msgq(struct app_params *app,
2370 const char *section_name,
2371 struct rte_cfgfile *cfg)
2373 struct app_msgq_params *param;
2374 struct rte_cfgfile_entry *entries;
2378 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2379 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2381 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2382 PARSE_ERROR_MALLOC(entries != NULL);
2384 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2386 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2387 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2389 param = &app->msgq_params[param_idx];
2391 for (i = 0; i < n_entries; i++) {
2392 struct rte_cfgfile_entry *ent = &entries[i];
2394 if (strcmp(ent->name, "size") == 0) {
2395 int status = parser_read_uint32(¶m->size,
2398 PARSE_ERROR((status == 0), section_name,
2403 if (strcmp(ent->name, "cpu") == 0) {
2404 int status = parser_read_uint32(
2405 ¶m->cpu_socket_id, ent->value);
2407 PARSE_ERROR((status == 0), section_name,
2413 PARSE_ERROR_INVALID(0, section_name, ent->name);
2421 typedef void (*config_section_load)(struct app_params *p,
2422 const char *section_name,
2423 struct rte_cfgfile *cfg);
2425 struct config_section {
2426 const char prefix[CFG_NAME_LEN];
2428 config_section_load load;
2431 static const struct config_section cfg_file_scheme[] = {
2432 {"EAL", 0, parse_eal},
2433 {"PIPELINE", 1, parse_pipeline},
2434 {"MEMPOOL", 1, parse_mempool},
2435 {"LINK", 1, parse_link},
2436 {"RXQ", 2, parse_rxq},
2437 {"TXQ", 2, parse_txq},
2438 {"SWQ", 1, parse_swq},
2439 {"TM", 1, parse_tm},
2440 {"SOURCE", 1, parse_source},
2441 {"SINK", 1, parse_sink},
2442 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2443 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2444 {"MSGQ", 1, parse_msgq},
2448 create_implicit_mempools(struct app_params *app)
2452 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2453 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2457 create_implicit_links_from_port_mask(struct app_params *app,
2460 uint32_t pmd_id, link_id;
2463 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2464 char name[APP_PARAM_NAME_SIZE];
2467 if ((port_mask & (1LLU << pmd_id)) == 0)
2470 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2471 idx = APP_PARAM_ADD(app->link_params, name);
2472 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2474 app->link_params[idx].pmd_id = pmd_id;
2480 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2484 for (i = 0; i < app->n_links; i++) {
2485 struct app_link_params *link = &app->link_params[i];
2492 app_config_parse(struct app_params *app, const char *file_name)
2494 struct rte_cfgfile *cfg;
2495 char **section_names;
2496 int i, j, sect_count;
2498 /* Implicit mempools */
2499 create_implicit_mempools(app);
2503 create_implicit_links_from_port_mask(app, app->port_mask);
2505 /* Load application configuration file */
2506 cfg = rte_cfgfile_load(file_name, 0);
2507 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2508 "file %s", file_name);
2510 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2511 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2512 "in file \"%s\" return %d", file_name,
2515 section_names = malloc(sect_count * sizeof(char *));
2516 PARSE_ERROR_MALLOC(section_names != NULL);
2518 for (i = 0; i < sect_count; i++)
2519 section_names[i] = malloc(CFG_NAME_LEN);
2521 rte_cfgfile_sections(cfg, section_names, sect_count);
2523 for (i = 0; i < sect_count; i++) {
2524 const struct config_section *sch_s;
2525 int len, cfg_name_len;
2527 cfg_name_len = strlen(section_names[i]);
2529 /* Find section type */
2530 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2531 sch_s = &cfg_file_scheme[j];
2532 len = strlen(sch_s->prefix);
2534 if (cfg_name_len < len)
2537 /* After section name we expect only '\0' or digit or
2538 * digit dot digit, so protect against false matching,
2539 * for example: "ABC" should match section name
2540 * "ABC0.0", but it should not match section_name
2543 if ((section_names[i][len] != '\0') &&
2544 !isdigit(section_names[i][len]))
2547 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2551 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2552 "Parse error: unknown section %s",
2555 APP_CHECK(validate_name(section_names[i],
2557 sch_s->numbers) == 0,
2558 "Parse error: invalid section name \"%s\"",
2561 sch_s->load(app, section_names[i], cfg);
2564 for (i = 0; i < sect_count; i++)
2565 free(section_names[i]);
2567 free(section_names);
2569 rte_cfgfile_close(cfg);
2571 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2572 APP_PARAM_COUNT(app->link_params, app->n_links);
2573 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2574 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2575 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2576 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2577 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2578 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2579 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2580 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2582 if (app->port_mask == 0)
2583 assign_link_pmd_id_from_pci_bdf(app);
2585 /* Save configuration to output file */
2586 app_config_save(app, app->output_file);
2588 /* Load TM configuration files */
2589 app_config_parse_tm(app);
2595 save_eal_params(struct app_params *app, FILE *f)
2597 struct app_eal_params *p = &app->eal_params;
2600 fprintf(f, "[EAL]\n");
2603 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2605 if (p->master_lcore_present)
2606 fprintf(f, "%s = %" PRIu32 "\n",
2607 "master_lcore", p->master_lcore);
2609 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2611 if (p->memory_present)
2612 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2614 if (p->ranks_present)
2615 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2617 for (i = 0; i < APP_MAX_LINKS; i++) {
2618 if (p->pci_blacklist[i] == NULL)
2621 fprintf(f, "%s = %s\n", "pci_blacklist",
2622 p->pci_blacklist[i]);
2625 for (i = 0; i < APP_MAX_LINKS; i++) {
2626 if (p->pci_whitelist[i] == NULL)
2629 fprintf(f, "%s = %s\n", "pci_whitelist",
2630 p->pci_whitelist[i]);
2633 for (i = 0; i < APP_MAX_LINKS; i++) {
2634 if (p->vdev[i] == NULL)
2637 fprintf(f, "%s = %s\n", "vdev",
2641 if (p->vmware_tsc_map_present)
2642 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2643 (p->vmware_tsc_map) ? "yes" : "no");
2646 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2649 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2651 if (p->log_level_present)
2652 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2654 if (p->version_present)
2655 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2657 if (p->help_present)
2658 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2660 if (p->no_huge_present)
2661 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2663 if (p->no_pci_present)
2664 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2666 if (p->no_hpet_present)
2667 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2669 if (p->no_shconf_present)
2670 fprintf(f, "%s = %s\n", "no_shconf",
2671 (p->no_shconf) ? "yes" : "no");
2674 fprintf(f, "%s = %s\n", "d", p->add_driver);
2677 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2680 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2683 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2685 if (p->base_virtaddr)
2686 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2688 if (p->create_uio_dev_present)
2689 fprintf(f, "%s = %s\n", "create_uio_dev",
2690 (p->create_uio_dev) ? "yes" : "no");
2693 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2695 if (p->xen_dom0_present)
2696 fprintf(f, "%s = %s\n", "xen_dom0",
2697 (p->xen_dom0) ? "yes" : "no");
2703 save_mempool_params(struct app_params *app, FILE *f)
2705 struct app_mempool_params *p;
2708 count = RTE_DIM(app->mempool_params);
2709 for (i = 0; i < count; i++) {
2710 p = &app->mempool_params[i];
2711 if (!APP_PARAM_VALID(p))
2714 fprintf(f, "[%s]\n", p->name);
2715 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2716 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2717 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2718 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2725 save_links_params(struct app_params *app, FILE *f)
2727 struct app_link_params *p;
2730 count = RTE_DIM(app->link_params);
2731 for (i = 0; i < count; i++) {
2732 p = &app->link_params[i];
2733 if (!APP_PARAM_VALID(p))
2736 fprintf(f, "[%s]\n", p->name);
2737 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2738 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2739 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2740 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2742 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2743 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2744 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2745 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2748 if (strlen(p->pci_bdf))
2749 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2756 save_rxq_params(struct app_params *app, FILE *f)
2758 struct app_pktq_hwq_in_params *p;
2761 count = RTE_DIM(app->hwq_in_params);
2762 for (i = 0; i < count; i++) {
2763 p = &app->hwq_in_params[i];
2764 if (!APP_PARAM_VALID(p))
2767 fprintf(f, "[%s]\n", p->name);
2768 fprintf(f, "%s = %s\n",
2770 app->mempool_params[p->mempool_id].name);
2771 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2772 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2779 save_txq_params(struct app_params *app, FILE *f)
2781 struct app_pktq_hwq_out_params *p;
2784 count = RTE_DIM(app->hwq_out_params);
2785 for (i = 0; i < count; i++) {
2786 p = &app->hwq_out_params[i];
2787 if (!APP_PARAM_VALID(p))
2790 fprintf(f, "[%s]\n", p->name);
2791 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2792 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2793 fprintf(f, "%s = %s\n",
2795 p->dropless ? "yes" : "no");
2802 save_swq_params(struct app_params *app, FILE *f)
2804 struct app_pktq_swq_params *p;
2807 count = RTE_DIM(app->swq_params);
2808 for (i = 0; i < count; i++) {
2809 p = &app->swq_params[i];
2810 if (!APP_PARAM_VALID(p))
2813 fprintf(f, "[%s]\n", p->name);
2814 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2815 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2816 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2817 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2818 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2819 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2820 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2821 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2822 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2823 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2824 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2825 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2826 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2827 fprintf(f, "%s = %s\n",
2829 app->mempool_params[p->mempool_direct_id].name);
2830 fprintf(f, "%s = %s\n",
2832 app->mempool_params[p->mempool_indirect_id].name);
2840 save_tm_params(struct app_params *app, FILE *f)
2842 struct app_pktq_tm_params *p;
2845 count = RTE_DIM(app->tm_params);
2846 for (i = 0; i < count; i++) {
2847 p = &app->tm_params[i];
2848 if (!APP_PARAM_VALID(p))
2851 fprintf(f, "[%s]\n", p->name);
2852 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2853 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2854 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2861 save_source_params(struct app_params *app, FILE *f)
2863 struct app_pktq_source_params *p;
2866 count = RTE_DIM(app->source_params);
2867 for (i = 0; i < count; i++) {
2868 p = &app->source_params[i];
2869 if (!APP_PARAM_VALID(p))
2872 fprintf(f, "[%s]\n", p->name);
2873 fprintf(f, "%s = %s\n",
2875 app->mempool_params[p->mempool_id].name);
2876 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2877 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2878 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2879 p->n_bytes_per_pkt);
2885 save_sink_params(struct app_params *app, FILE *f)
2887 struct app_pktq_sink_params *p;
2890 count = RTE_DIM(app->sink_params);
2891 for (i = 0; i < count; i++) {
2892 p = &app->sink_params[i];
2893 if (!APP_PARAM_VALID(p))
2896 fprintf(f, "[%s]\n", p->name);
2897 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2898 fprintf(f, "%s = %" PRIu32 "\n",
2899 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2905 save_msgq_params(struct app_params *app, FILE *f)
2907 struct app_msgq_params *p;
2910 count = RTE_DIM(app->msgq_params);
2911 for (i = 0; i < count; i++) {
2912 p = &app->msgq_params[i];
2913 if (!APP_PARAM_VALID(p))
2916 fprintf(f, "[%s]\n", p->name);
2917 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2918 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2925 save_pipeline_params(struct app_params *app, FILE *f)
2929 count = RTE_DIM(app->pipeline_params);
2930 for (i = 0; i < count; i++) {
2931 struct app_pipeline_params *p = &app->pipeline_params[i];
2933 if (!APP_PARAM_VALID(p))
2937 fprintf(f, "[%s]\n", p->name);
2940 fprintf(f, "type = %s\n", p->type);
2943 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2946 (p->hyper_th_id) ? "h" : "");
2952 fprintf(f, "pktq_in =");
2953 for (j = 0; j < p->n_pktq_in; j++) {
2954 struct app_pktq_in_params *pp = &p->pktq_in[j];
2958 case APP_PKTQ_IN_HWQ:
2959 name = app->hwq_in_params[pp->id].name;
2961 case APP_PKTQ_IN_SWQ:
2962 name = app->swq_params[pp->id].name;
2964 case APP_PKTQ_IN_TM:
2965 name = app->tm_params[pp->id].name;
2967 case APP_PKTQ_IN_SOURCE:
2968 name = app->source_params[pp->id].name;
2971 APP_CHECK(0, "System error "
2972 "occurred while saving "
2973 "parameter to file");
2976 fprintf(f, " %s", name);
2982 if (p->n_pktq_out) {
2985 fprintf(f, "pktq_out =");
2986 for (j = 0; j < p->n_pktq_out; j++) {
2987 struct app_pktq_out_params *pp =
2992 case APP_PKTQ_OUT_HWQ:
2993 name = app->hwq_out_params[pp->id].name;
2995 case APP_PKTQ_OUT_SWQ:
2996 name = app->swq_params[pp->id].name;
2998 case APP_PKTQ_OUT_TM:
2999 name = app->tm_params[pp->id].name;
3001 case APP_PKTQ_OUT_SINK:
3002 name = app->sink_params[pp->id].name;
3005 APP_CHECK(0, "System error "
3006 "occurred while saving "
3007 "parameter to file");
3010 fprintf(f, " %s", name);
3019 fprintf(f, "msgq_in =");
3020 for (j = 0; j < p->n_msgq_in; j++) {
3021 uint32_t id = p->msgq_in[j];
3022 char *name = app->msgq_params[id].name;
3024 fprintf(f, " %s", name);
3030 if (p->n_msgq_out) {
3033 fprintf(f, "msgq_out =");
3034 for (j = 0; j < p->n_msgq_out; j++) {
3035 uint32_t id = p->msgq_out[j];
3036 char *name = app->msgq_params[id].name;
3038 fprintf(f, " %s", name);
3044 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3050 for (j = 0; j < p->n_args; j++)
3051 fprintf(f, "%s = %s\n", p->args_name[j],
3060 app_config_save(struct app_params *app, const char *file_name)
3063 char *name, *dir_name;
3066 name = strdup(file_name);
3067 dir_name = dirname(name);
3068 status = access(dir_name, W_OK);
3069 APP_CHECK((status == 0),
3070 "Error: need write access privilege to directory "
3071 "\"%s\" to save configuration\n", dir_name);
3073 file = fopen(file_name, "w");
3074 APP_CHECK((file != NULL),
3075 "Error: failed to save configuration to file \"%s\"",
3078 save_eal_params(app, file);
3079 save_pipeline_params(app, file);
3080 save_mempool_params(app, file);
3081 save_links_params(app, file);
3082 save_rxq_params(app, file);
3083 save_txq_params(app, file);
3084 save_swq_params(app, file);
3085 save_tm_params(app, file);
3086 save_source_params(app, file);
3087 save_sink_params(app, file);
3088 save_msgq_params(app, file);
3095 app_config_init(struct app_params *app)
3099 memcpy(app, &app_params_default, sizeof(struct app_params));
3101 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3102 memcpy(&app->mempool_params[i],
3103 &mempool_params_default,
3104 sizeof(struct app_mempool_params));
3106 for (i = 0; i < RTE_DIM(app->link_params); i++)
3107 memcpy(&app->link_params[i],
3108 &link_params_default,
3109 sizeof(struct app_link_params));
3111 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3112 memcpy(&app->hwq_in_params[i],
3113 &default_hwq_in_params,
3114 sizeof(default_hwq_in_params));
3116 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3117 memcpy(&app->hwq_out_params[i],
3118 &default_hwq_out_params,
3119 sizeof(default_hwq_out_params));
3121 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3122 memcpy(&app->swq_params[i],
3123 &default_swq_params,
3124 sizeof(default_swq_params));
3126 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3127 memcpy(&app->tm_params[i],
3129 sizeof(default_tm_params));
3131 for (i = 0; i < RTE_DIM(app->source_params); i++)
3132 memcpy(&app->source_params[i],
3133 &default_source_params,
3134 sizeof(default_source_params));
3136 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3137 memcpy(&app->sink_params[i],
3138 &default_sink_params,
3139 sizeof(default_sink_params));
3141 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3142 memcpy(&app->msgq_params[i],
3143 &default_msgq_params,
3144 sizeof(default_msgq_params));
3146 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3147 memcpy(&app->pipeline_params[i],
3148 &default_pipeline_params,
3149 sizeof(default_pipeline_params));
3155 filenamedup(const char *filename, const char *suffix)
3157 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3162 sprintf(s, "%s%s", filename, suffix);
3167 app_config_args(struct app_params *app, int argc, char **argv)
3169 const char *optname;
3170 int opt, option_index;
3171 int f_present, s_present, p_present, l_present;
3172 int preproc_present, preproc_params_present;
3175 static struct option lgopts[] = {
3176 { "preproc", 1, 0, 0 },
3177 { "preproc-args", 1, 0, 0 },
3181 /* Copy application name */
3182 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3188 preproc_present = 0;
3189 preproc_params_present = 0;
3191 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3192 &option_index)) != EOF)
3196 rte_panic("Error: Config file is provided "
3197 "more than once\n");
3200 if (!strlen(optarg))
3201 rte_panic("Error: Config file name is null\n");
3203 app->config_file = strdup(optarg);
3204 if (app->config_file == NULL)
3205 rte_panic("Error: Memory allocation failure\n");
3211 rte_panic("Error: Script file is provided "
3212 "more than once\n");
3215 if (!strlen(optarg))
3216 rte_panic("Error: Script file name is null\n");
3218 app->script_file = strdup(optarg);
3219 if (app->script_file == NULL)
3220 rte_panic("Error: Memory allocation failure\n");
3226 rte_panic("Error: PORT_MASK is provided "
3227 "more than once\n");
3230 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3232 ((size_t) scaned != strlen(optarg)))
3233 rte_panic("Error: PORT_MASK is not "
3234 "a hexadecimal integer\n");
3236 if (app->port_mask == 0)
3237 rte_panic("Error: PORT_MASK is null\n");
3243 rte_panic("Error: LOG_LEVEL is provided "
3244 "more than once\n");
3247 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3249 ((size_t) scaned != strlen(optarg)) ||
3250 (app->log_level >= APP_LOG_LEVELS))
3251 rte_panic("Error: LOG_LEVEL invalid value\n");
3256 optname = lgopts[option_index].name;
3258 if (strcmp(optname, "preproc") == 0) {
3259 if (preproc_present)
3260 rte_panic("Error: Preprocessor argument "
3261 "is provided more than once\n");
3262 preproc_present = 1;
3264 app->preproc = strdup(optarg);
3268 if (strcmp(optname, "preproc-args") == 0) {
3269 if (preproc_params_present)
3270 rte_panic("Error: Preprocessor args "
3271 "are provided more than once\n");
3272 preproc_params_present = 1;
3274 app->preproc_args = strdup(optarg);
3278 app_print_usage(argv[0]);
3282 app_print_usage(argv[0]);
3285 optind = 0; /* reset getopt lib */
3287 /* Check dependencies between args */
3288 if (preproc_params_present && (preproc_present == 0))
3289 rte_panic("Error: Preprocessor args specified while "
3290 "preprocessor is not defined\n");
3292 app->parser_file = preproc_present ?
3293 filenamedup(app->config_file, ".preproc") :
3294 strdup(app->config_file);
3295 app->output_file = filenamedup(app->config_file, ".out");
3301 app_config_preproc(struct app_params *app)
3306 if (app->preproc == NULL)
3309 status = access(app->config_file, F_OK | R_OK);
3310 APP_CHECK((status == 0), "Error: Unable to open file %s",
3313 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3315 app->preproc_args ? app->preproc_args : "",
3319 status = system(buffer);
3320 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3321 "Error occurred while pre-processing file \"%s\"\n",