2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
28 #include <rte_errno.h>
29 #include <rte_cfgfile.h>
30 #include <rte_string_fns.h>
36 * Default config values
39 static struct app_params app_params_default = {
40 .config_file = "./config/ip_pipeline.cfg",
41 .log_level = APP_LOG_LEVEL_HIGH,
49 static const struct app_mempool_params mempool_params_default = {
51 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
52 .pool_size = 32 * 1024,
57 static const struct app_link_params link_params_default = {
68 .ipv6 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
77 .mq_mode = ETH_MQ_RX_NONE,
79 .header_split = 0, /* Header split */
80 .hw_ip_checksum = 0, /* IP checksum offload */
81 .hw_vlan_filter = 0, /* VLAN filtering */
82 .hw_vlan_strip = 0, /* VLAN strip */
83 .hw_vlan_extend = 0, /* Extended VLAN */
84 .jumbo_frame = 0, /* Jumbo frame support */
85 .hw_strip_crc = 0, /* CRC strip by HW */
86 .enable_scatter = 0, /* Scattered packets RX handler */
88 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
89 .split_hdr_size = 0, /* Header split buffer size */
92 .mq_mode = ETH_MQ_TX_NONE,
98 .lsc = 1, /**< lsc interrupt feature enabled */
107 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
119 .rx_free_thresh = 64,
121 .rx_deferred_start = 0,
125 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
140 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
141 ETH_TXQ_FLAGS_NOOFFLOADS,
142 .tx_deferred_start = 0,
146 static const struct app_pktq_swq_params default_swq_params = {
160 .mempool_direct_id = 0,
161 .mempool_indirect_id = 0,
164 struct app_pktq_tm_params default_tm_params = {
166 .file_name = "./config/tm_profile.cfg",
171 struct app_pktq_source_params default_source_params = {
176 .n_bytes_per_pkt = 0,
179 struct app_pktq_sink_params default_sink_params = {
185 struct app_msgq_params default_msgq_params = {
191 struct app_pipeline_params default_pipeline_params = {
204 static const char app_usage[] =
205 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] [-p PORT_MASK] "
206 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
209 "\t-f CONFIG_FILE: Default config file is %s\n"
210 "\t-p PORT_MASK: Mask of NIC port IDs in hex format (generated from "
211 "config file when not provided)\n"
212 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
213 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
214 "\t--disable-hw-csum Disable TCP/UDP HW checksum\n"
215 "\t--preproc PREPROCESSOR: Configuration file pre-processor\n"
216 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
220 app_print_usage(char *prgname)
222 rte_exit(0, app_usage, prgname, app_params_default.config_file);
225 #define skip_white_spaces(pos) \
227 __typeof__(pos) _p = (pos); \
228 for ( ; isspace(*_p); _p++); \
232 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
234 APP_CHECK((result != -EINVAL), \
235 "Parse error: no free memory"); \
236 APP_CHECK((result != -ENOMEM), \
237 "Parse error: too many \"%s\" sections", section_name); \
238 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
239 "Parse error: duplicate \"%s\" section", section_name); \
240 APP_CHECK((result >= 0), \
241 "Parse error in section \"%s\"", section_name); \
245 parser_read_arg_bool(const char *p)
247 p = skip_white_spaces(p);
248 int result = -EINVAL;
250 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
251 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
256 if (((p[0] == 'o') && (p[1] == 'n')) ||
257 ((p[0] == 'O') && (p[1] == 'N'))) {
262 if (((p[0] == 'n') && (p[1] == 'o')) ||
263 ((p[0] == 'N') && (p[1] == 'O'))) {
268 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
269 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
274 p = skip_white_spaces(p);
282 #define PARSE_ERROR(exp, section, entry) \
283 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
285 #define PARSE_ERROR_MESSAGE(exp, section, entry, message) \
286 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n", \
287 section, entry, message)
290 #define PARSE_ERROR_MALLOC(exp) \
291 APP_CHECK(exp, "Parse error: no free memory\n")
293 #define PARSE_ERROR_SECTION(exp, section) \
294 APP_CHECK(exp, "Parse error in section \"%s\"", section)
296 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
297 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
299 #define PARSE_WARNING_IGNORED(exp, section, entry) \
302 fprintf(stderr, "Parse warning in section \"%s\": " \
303 "entry \"%s\" is ignored\n", section, entry); \
306 #define PARSE_ERROR_INVALID(exp, section, entry) \
307 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
310 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
311 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
315 parser_read_uint64(uint64_t *value, const char *p)
320 p = skip_white_spaces(p);
324 val = strtoul(p, &next, 10);
346 p = skip_white_spaces(p);
355 parser_read_uint32(uint32_t *value, const char *p)
358 int ret = parser_read_uint64(&val, p);
363 if (val > UINT32_MAX)
371 parse_pipeline_core(uint32_t *socket,
379 uint32_t s = 0, c = 0, h = 0, val;
380 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
381 const char *next = skip_white_spaces(entry);
384 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
385 while (*next != '\0') {
386 /* If everything parsed nothing should left */
387 if (s_parsed && c_parsed && h_parsed)
394 if (s_parsed || c_parsed || h_parsed)
401 if (c_parsed || h_parsed)
414 /* If it start from digit it must be only core id. */
415 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
421 for (num_len = 0; *next != '\0'; next++, num_len++) {
422 if (num_len == RTE_DIM(num))
428 num[num_len] = *next;
431 if (num_len == 0 && type != 'h' && type != 'H')
434 if (num_len != 0 && (type == 'h' || type == 'H'))
436 if(num_len < sizeof(num))
438 val = strtol(num, NULL, 10);
467 case '0': case '1': case '2': case '3': case '4': case '5':
468 case '6': case '7': case '8': case '9':
470 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
472 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
480 parse_hex_string(char *src, uint8_t *dst, uint32_t *size)
485 /* Check input parameters */
493 if (((len & 3) != 0) ||
498 for (c = src; *c != 0; c++) {
499 if ((((*c) >= '0') && ((*c) <= '9')) ||
500 (((*c) >= 'A') && ((*c) <= 'F')) ||
501 (((*c) >= 'a') && ((*c) <= 'f')))
507 /* Convert chars to bytes */
508 for (i = 0; i < *size; i++)
509 dst[i] = get_hex_val(src[2 * i]) * 16 +
510 get_hex_val(src[2 * i + 1]);
516 skip_digits(const char *src)
520 for (i = 0; isdigit(src[i]); i++);
526 validate_name(const char *name, const char *prefix, int num)
530 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
531 if (name[i] != prefix[i])
535 if (prefix[i] != '\0')
546 j = skip_digits(&name[i]);
548 if ((j == 0) || (name[i] != '.'))
554 j = skip_digits(&name[i]);
556 if ((j == 0) || (name[i] != '\0'))
564 parse_eal(struct app_params *app,
565 const char *section_name,
566 struct rte_cfgfile *cfg)
568 struct app_eal_params *p = &app->eal_params;
569 struct rte_cfgfile_entry *entries;
572 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
573 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
575 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
576 PARSE_ERROR_MALLOC(entries != NULL);
578 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
580 for (i = 0; i < n_entries; i++) {
581 struct rte_cfgfile_entry *entry = &entries[i];
584 if (strcmp(entry->name, "c") == 0) {
585 PARSE_WARNING_IGNORED(0, section_name, entry->name);
590 if (strcmp(entry->name, "l") == 0) {
591 PARSE_WARNING_IGNORED(0, section_name, entry->name);
596 if (strcmp(entry->name, "lcores") == 0) {
597 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
600 p->coremap = strdup(entry->value);
605 if (strcmp(entry->name, "master_lcore") == 0) {
608 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
611 p->master_lcore_present = 1;
613 status = parser_read_uint32(&p->master_lcore,
615 PARSE_ERROR((status == 0), section_name, entry->name);
620 if (strcmp(entry->name, "n") == 0) {
623 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
626 p->channels_present = 1;
628 status = parser_read_uint32(&p->channels, entry->value);
629 PARSE_ERROR((status == 0), section_name, entry->name);
634 if (strcmp(entry->name, "m") == 0) {
637 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
640 p->memory_present = 1;
642 status = parser_read_uint32(&p->memory, entry->value);
643 PARSE_ERROR((status == 0), section_name, entry->name);
648 if (strcmp(entry->name, "r") == 0) {
651 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
654 p->ranks_present = 1;
656 status = parser_read_uint32(&p->ranks, entry->value);
657 PARSE_ERROR((status == 0), section_name, entry->name);
662 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
663 (strcmp(entry->name, "b") == 0)) {
666 for (i = 0; i < APP_MAX_LINKS; i++) {
667 if (p->pci_blacklist[i])
670 p->pci_blacklist[i] =
671 strdup(entry->value);
672 PARSE_ERROR_MALLOC(p->pci_blacklist[i]);
677 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
678 section_name, entry->name,
679 "too many elements");
684 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
685 (strcmp(entry->name, "w") == 0)) {
688 PARSE_ERROR_MESSAGE((app->port_mask != 0),
689 section_name, entry->name, "entry to be "
690 "generated by the application (port_mask "
693 for (i = 0; i < APP_MAX_LINKS; i++) {
694 if (p->pci_whitelist[i])
697 p->pci_whitelist[i] = strdup(entry->value);
698 PARSE_ERROR_MALLOC(p->pci_whitelist[i]);
703 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
704 section_name, entry->name,
705 "too many elements");
710 if (strcmp(entry->name, "vdev") == 0) {
713 for (i = 0; i < APP_MAX_LINKS; i++) {
717 p->vdev[i] = strdup(entry->value);
718 PARSE_ERROR_MALLOC(p->vdev[i]);
723 PARSE_ERROR_MESSAGE((i < APP_MAX_LINKS),
724 section_name, entry->name,
725 "too many elements");
730 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
733 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
736 p->vmware_tsc_map_present = 1;
738 val = parser_read_arg_bool(entry->value);
739 PARSE_ERROR((val >= 0), section_name, entry->name);
740 p->vmware_tsc_map = val;
745 if (strcmp(entry->name, "proc_type") == 0) {
746 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
749 p->proc_type = strdup(entry->value);
754 if (strcmp(entry->name, "syslog") == 0) {
755 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
758 p->syslog = strdup(entry->value);
763 if (strcmp(entry->name, "log_level") == 0) {
766 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
769 p->log_level_present = 1;
771 status = parser_read_uint32(&p->log_level,
773 PARSE_ERROR((status == 0), section_name, entry->name);
778 if (strcmp(entry->name, "v") == 0) {
781 PARSE_ERROR_DUPLICATE((p->version_present == 0),
784 p->version_present = 1;
786 val = parser_read_arg_bool(entry->value);
787 PARSE_ERROR((val >= 0), section_name, entry->name);
793 if ((strcmp(entry->name, "help") == 0) ||
794 (strcmp(entry->name, "h") == 0)) {
797 PARSE_ERROR_DUPLICATE((p->help_present == 0),
802 val = parser_read_arg_bool(entry->value);
803 PARSE_ERROR((val >= 0), section_name, entry->name);
809 if (strcmp(entry->name, "no_huge") == 0) {
812 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
815 p->no_huge_present = 1;
817 val = parser_read_arg_bool(entry->value);
818 PARSE_ERROR((val >= 0), section_name, entry->name);
824 if (strcmp(entry->name, "no_pci") == 0) {
827 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
830 p->no_pci_present = 1;
832 val = parser_read_arg_bool(entry->value);
833 PARSE_ERROR((val >= 0), section_name, entry->name);
839 if (strcmp(entry->name, "no_hpet") == 0) {
842 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
845 p->no_hpet_present = 1;
847 val = parser_read_arg_bool(entry->value);
848 PARSE_ERROR((val >= 0), section_name, entry->name);
854 if (strcmp(entry->name, "no_shconf") == 0) {
857 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
860 p->no_shconf_present = 1;
862 val = parser_read_arg_bool(entry->value);
863 PARSE_ERROR((val >= 0), section_name, entry->name);
869 if (strcmp(entry->name, "d") == 0) {
870 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
873 p->add_driver = strdup(entry->value);
878 if (strcmp(entry->name, "socket_mem") == 0) {
879 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
882 p->socket_mem = strdup(entry->value);
887 if (strcmp(entry->name, "huge_dir") == 0) {
888 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
891 p->huge_dir = strdup(entry->value);
896 if (strcmp(entry->name, "file_prefix") == 0) {
897 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
900 p->file_prefix = strdup(entry->value);
905 if (strcmp(entry->name, "base_virtaddr") == 0) {
906 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
909 p->base_virtaddr = strdup(entry->value);
914 if (strcmp(entry->name, "create_uio_dev") == 0) {
917 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
920 p->create_uio_dev_present = 1;
922 val = parser_read_arg_bool(entry->value);
923 PARSE_ERROR((val >= 0), section_name, entry->name);
924 p->create_uio_dev = val;
929 if (strcmp(entry->name, "vfio_intr") == 0) {
930 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
933 p->vfio_intr = strdup(entry->value);
938 if (strcmp(entry->name, "xen_dom0") == 0) {
941 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
944 p->xen_dom0_present = 1;
946 val = parser_read_arg_bool(entry->value);
947 PARSE_ERROR((val >= 0), section_name, entry->name);
953 PARSE_ERROR_INVALID(0, section_name, entry->name);
960 parse_pipeline_pcap_source(struct app_params *app,
961 struct app_pipeline_params *p,
962 const char *file_name, const char *cp_size)
964 const char *next = NULL;
969 if (file_name && !cp_size) {
971 parse_file = 1; /* parse file path */
972 } else if (cp_size && !file_name) {
974 parse_file = 0; /* parse copy size */
978 char name[APP_PARAM_NAME_SIZE];
981 if (p->n_pktq_in == 0)
985 while (*next != '\0') {
988 if (i >= p->n_pktq_in)
991 id = p->pktq_in[i].id;
993 end = strchr(next, ' ');
995 name_len = strlen(next);
997 name_len = end - next;
999 if (name_len == 0 || name_len == sizeof(name))
1002 strncpy(name, next, name_len);
1003 name[name_len] = '\0';
1009 app->source_params[id].file_name = strdup(name);
1010 if (app->source_params[id].file_name == NULL)
1013 if (parser_read_uint32(
1014 &app->source_params[id].n_bytes_per_pkt,
1016 if (app->source_params[id].
1018 free(app->source_params[id].
1026 if (i == p->n_pktq_in)
1034 parse_pipeline_pcap_sink(struct app_params *app,
1035 struct app_pipeline_params *p,
1036 const char *file_name, const char *n_pkts_to_dump)
1038 const char *next = NULL;
1043 if (file_name && !n_pkts_to_dump) {
1045 parse_file = 1; /* parse file path */
1046 } else if (n_pkts_to_dump && !file_name) {
1047 next = n_pkts_to_dump;
1048 parse_file = 0; /* parse copy size */
1052 char name[APP_PARAM_NAME_SIZE];
1055 if (p->n_pktq_out == 0)
1059 while (*next != '\0') {
1062 if (i >= p->n_pktq_out)
1065 id = p->pktq_out[i].id;
1067 end = strchr(next, ' ');
1069 name_len = strlen(next);
1071 name_len = end - next;
1073 if (name_len == 0 || name_len == sizeof(name))
1076 strncpy(name, next, name_len);
1077 name[name_len] = '\0';
1083 app->sink_params[id].file_name = strdup(name);
1084 if (app->sink_params[id].file_name == NULL)
1087 if (parser_read_uint32(
1088 &app->sink_params[id].n_pkts_to_dump,
1090 if (app->sink_params[id].file_name !=
1092 free(app->sink_params[id].
1100 if (i == p->n_pktq_out)
1108 parse_pipeline_pktq_in(struct app_params *app,
1109 struct app_pipeline_params *p,
1112 const char *next = value;
1116 char name[APP_PARAM_NAME_SIZE];
1119 while (*next != '\0') {
1120 enum app_pktq_in_type type;
1125 next = skip_white_spaces(next);
1129 end_space = strchr(next, ' ');
1130 end_tab = strchr(next, ' ');
1132 if (end_space && (!end_tab))
1134 else if ((!end_space) && end_tab)
1136 else if (end_space && end_tab)
1137 end = RTE_MIN(end_space, end_tab);
1142 name_len = strlen(next);
1144 name_len = end - next;
1146 if (name_len == 0 || name_len == sizeof(name))
1149 strncpy(name, next, name_len);
1150 name[name_len] = '\0';
1155 if (validate_name(name, "RXQ", 2) == 0) {
1156 type = APP_PKTQ_IN_HWQ;
1157 id = APP_PARAM_ADD(app->hwq_in_params, name);
1158 } else if (validate_name(name, "SWQ", 1) == 0) {
1159 type = APP_PKTQ_IN_SWQ;
1160 id = APP_PARAM_ADD(app->swq_params, name);
1161 } else if (validate_name(name, "TM", 1) == 0) {
1162 type = APP_PKTQ_IN_TM;
1163 id = APP_PARAM_ADD(app->tm_params, name);
1164 } else if (validate_name(name, "SOURCE", 1) == 0) {
1165 type = APP_PKTQ_IN_SOURCE;
1166 id = APP_PARAM_ADD(app->source_params, name);
1173 p->pktq_in[p->n_pktq_in].type = type;
1174 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
1182 parse_pipeline_pktq_out(struct app_params *app,
1183 struct app_pipeline_params *p,
1186 const char *next = value;
1190 char name[APP_PARAM_NAME_SIZE];
1193 while (*next != '\0') {
1194 enum app_pktq_out_type type;
1199 next = skip_white_spaces(next);
1203 end_space = strchr(next, ' ');
1204 end_tab = strchr(next, ' ');
1206 if (end_space && (!end_tab))
1208 else if ((!end_space) && end_tab)
1210 else if (end_space && end_tab)
1211 end = RTE_MIN(end_space, end_tab);
1216 name_len = strlen(next);
1218 name_len = end - next;
1220 if (name_len == 0 || name_len == sizeof(name))
1223 strncpy(name, next, name_len);
1224 name[name_len] = '\0';
1228 if (validate_name(name, "TXQ", 2) == 0) {
1229 type = APP_PKTQ_OUT_HWQ;
1230 id = APP_PARAM_ADD(app->hwq_out_params, name);
1231 } else if (validate_name(name, "SWQ", 1) == 0) {
1232 type = APP_PKTQ_OUT_SWQ;
1233 id = APP_PARAM_ADD(app->swq_params, name);
1234 } else if (validate_name(name, "TM", 1) == 0) {
1235 type = APP_PKTQ_OUT_TM;
1236 id = APP_PARAM_ADD(app->tm_params, name);
1237 } else if (validate_name(name, "SINK", 1) == 0) {
1238 type = APP_PKTQ_OUT_SINK;
1239 id = APP_PARAM_ADD(app->sink_params, name);
1246 p->pktq_out[p->n_pktq_out].type = type;
1247 p->pktq_out[p->n_pktq_out].id = id;
1255 parse_pipeline_msgq_in(struct app_params *app,
1256 struct app_pipeline_params *p,
1259 const char *next = value;
1263 char name[APP_PARAM_NAME_SIZE];
1267 while (*next != '\0') {
1271 next = skip_white_spaces(next);
1275 end_space = strchr(next, ' ');
1276 end_tab = strchr(next, ' ');
1278 if (end_space && (!end_tab))
1280 else if ((!end_space) && end_tab)
1282 else if (end_space && end_tab)
1283 end = RTE_MIN(end_space, end_tab);
1288 name_len = strlen(next);
1290 name_len = end - next;
1292 if (name_len == 0 || name_len == sizeof(name))
1295 strncpy(name, next, name_len);
1296 name[name_len] = '\0';
1301 if (validate_name(name, "MSGQ", 1) != 0)
1304 idx = APP_PARAM_ADD(app->msgq_params, name);
1308 p->msgq_in[p->n_msgq_in] = idx;
1316 parse_pipeline_msgq_out(struct app_params *app,
1317 struct app_pipeline_params *p,
1320 const char *next = value;
1324 char name[APP_PARAM_NAME_SIZE];
1328 while (*next != '\0') {
1332 next = skip_white_spaces(next);
1336 end_space = strchr(next, ' ');
1337 end_tab = strchr(next, ' ');
1339 if (end_space && (!end_tab))
1341 else if ((!end_space) && end_tab)
1343 else if (end_space && end_tab)
1344 end = RTE_MIN(end_space, end_tab);
1349 name_len = strlen(next);
1351 name_len = end - next;
1353 if (name_len == 0 || name_len == sizeof(name))
1356 strncpy(name, next, name_len);
1357 name[name_len] = '\0';
1362 if (validate_name(name, "MSGQ", 1) != 0)
1365 idx = APP_PARAM_ADD(app->msgq_params, name);
1369 p->msgq_out[p->n_msgq_out] = idx;
1377 parse_pipeline(struct app_params *app,
1378 const char *section_name,
1379 struct rte_cfgfile *cfg)
1381 char name[CFG_NAME_LEN];
1382 struct app_pipeline_params *param;
1383 struct rte_cfgfile_entry *entries;
1387 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1388 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1390 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1391 PARSE_ERROR_MALLOC(entries != NULL);
1393 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1395 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1396 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1398 param = &app->pipeline_params[param_idx];
1400 for (i = 0; i < n_entries; i++) {
1401 struct rte_cfgfile_entry *ent = &entries[i];
1403 if (strcmp(ent->name, "type") == 0) {
1404 int w_size = snprintf(param->type, RTE_DIM(param->type),
1407 PARSE_ERROR(((w_size > 0) &&
1408 (w_size < (int)RTE_DIM(param->type))),
1414 if (strcmp(ent->name, "core") == 0) {
1415 int status = parse_pipeline_core(
1416 ¶m->socket_id, ¶m->core_id,
1417 ¶m->hyper_th_id, ent->value);
1419 PARSE_ERROR((status == 0), section_name,
1424 if (strcmp(ent->name, "pktq_in") == 0) {
1425 int status = parse_pipeline_pktq_in(app, param,
1428 PARSE_ERROR((status == 0), section_name,
1433 if (strcmp(ent->name, "pktq_out") == 0) {
1434 int status = parse_pipeline_pktq_out(app, param,
1437 PARSE_ERROR((status == 0), section_name,
1442 if (strcmp(ent->name, "msgq_in") == 0) {
1443 int status = parse_pipeline_msgq_in(app, param,
1446 PARSE_ERROR((status == 0), section_name,
1451 if (strcmp(ent->name, "msgq_out") == 0) {
1452 int status = parse_pipeline_msgq_out(app, param,
1455 PARSE_ERROR((status == 0), section_name,
1460 if (strcmp(ent->name, "timer_period") == 0) {
1461 int status = parser_read_uint32(
1462 ¶m->timer_period,
1465 PARSE_ERROR((status == 0), section_name,
1470 if (strcmp(ent->name, "pcap_file_rd") == 0) {
1473 #ifndef RTE_PORT_PCAP
1474 PARSE_ERROR_INVALID(0, section_name, ent->name);
1477 status = parse_pipeline_pcap_source(app,
1478 param, ent->value, NULL);
1480 PARSE_ERROR((status == 0), section_name,
1485 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
1488 #ifndef RTE_PORT_PCAP
1489 PARSE_ERROR_INVALID(0, section_name, ent->name);
1492 status = parse_pipeline_pcap_source(app,
1493 param, NULL, ent->value);
1495 PARSE_ERROR((status == 0), section_name,
1500 if (strcmp(ent->name, "pcap_file_wr") == 0) {
1503 #ifndef RTE_PORT_PCAP
1504 PARSE_ERROR_INVALID(0, section_name, ent->name);
1507 status = parse_pipeline_pcap_sink(app, param,
1510 PARSE_ERROR((status == 0), section_name,
1515 if (strcmp(ent->name, "pcap_n_pkt_wr") == 0) {
1518 #ifndef RTE_PORT_PCAP
1519 PARSE_ERROR_INVALID(0, section_name, ent->name);
1522 status = parse_pipeline_pcap_sink(app, param,
1525 PARSE_ERROR((status == 0), section_name,
1530 /* pipeline type specific items */
1531 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1532 "Parse error in section \"%s\": too many "
1533 "pipeline specified parameters", section_name);
1535 param->args_name[param->n_args] = strdup(ent->name);
1536 param->args_value[param->n_args] = strdup(ent->value);
1538 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1539 (param->args_value[param->n_args] != NULL),
1540 "Parse error: no free memory");
1547 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
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;
1551 param->msgq_in[param->n_msgq_in++] = param_idx;
1553 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1554 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1555 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1556 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1557 param->msgq_out[param->n_msgq_out++] = param_idx;
1559 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1562 (param->hyper_th_id) ? "h" : "");
1563 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1564 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1565 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1567 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1570 (param->hyper_th_id) ? "h" : "");
1571 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1572 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, name);
1573 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1579 parse_mempool(struct app_params *app,
1580 const char *section_name,
1581 struct rte_cfgfile *cfg)
1583 struct app_mempool_params *param;
1584 struct rte_cfgfile_entry *entries;
1588 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1589 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1591 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1592 PARSE_ERROR_MALLOC(entries != NULL);
1594 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1596 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1597 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1599 param = &app->mempool_params[param_idx];
1601 for (i = 0; i < n_entries; i++) {
1602 struct rte_cfgfile_entry *ent = &entries[i];
1604 if (strcmp(ent->name, "buffer_size") == 0) {
1605 int status = parser_read_uint32(
1606 ¶m->buffer_size, ent->value);
1608 PARSE_ERROR((status == 0), section_name,
1613 if (strcmp(ent->name, "pool_size") == 0) {
1614 int status = parser_read_uint32(
1615 ¶m->pool_size, ent->value);
1617 PARSE_ERROR((status == 0), section_name,
1622 if (strcmp(ent->name, "cache_size") == 0) {
1623 int status = parser_read_uint32(
1624 ¶m->cache_size, ent->value);
1626 PARSE_ERROR((status == 0), section_name,
1631 if (strcmp(ent->name, "cpu") == 0) {
1632 int status = parser_read_uint32(
1633 ¶m->cpu_socket_id, ent->value);
1635 PARSE_ERROR((status == 0), section_name,
1641 PARSE_ERROR_INVALID(0, section_name, ent->name);
1650 parse_link(struct app_params *app,
1651 const char *section_name,
1652 struct rte_cfgfile *cfg)
1654 struct app_link_params *param;
1655 struct rte_cfgfile_entry *entries;
1657 int pci_bdf_present = 0;
1660 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1661 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1663 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1664 PARSE_ERROR_MALLOC(entries != NULL);
1666 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1668 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1669 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1671 param = &app->link_params[param_idx];
1673 for (i = 0; i < n_entries; i++) {
1674 struct rte_cfgfile_entry *ent = &entries[i];
1676 if (strcmp(ent->name, "promisc") == 0) {
1677 int status = parser_read_arg_bool(ent->value);
1679 PARSE_ERROR((status != -EINVAL), section_name,
1681 param->promisc = status;
1685 if (strcmp(ent->name, "arp_q") == 0) {
1686 int status = parser_read_uint32(¶m->arp_q,
1689 PARSE_ERROR((status == 0), section_name,
1694 if (strcmp(ent->name, "tcp_syn_q") == 0) {
1695 int status = parser_read_uint32(
1696 ¶m->tcp_syn_q, ent->value);
1698 PARSE_ERROR((status == 0), section_name, ent->name);
1702 if (strcmp(ent->name, "ip_local_q") == 0) {
1703 int status = parser_read_uint32(
1704 ¶m->ip_local_q, ent->value);
1706 PARSE_ERROR((status == 0), section_name,
1712 if (strcmp(ent->name, "tcp_local_q") == 0) {
1713 int status = parser_read_uint32(
1714 ¶m->tcp_local_q, ent->value);
1716 PARSE_ERROR((status == 0), section_name,
1721 if (strcmp(ent->name, "udp_local_q") == 0) {
1722 int status = parser_read_uint32(
1723 ¶m->udp_local_q, ent->value);
1725 PARSE_ERROR((status == 0), section_name,
1730 if (strcmp(ent->name, "sctp_local_q") == 0) {
1731 int status = parser_read_uint32(
1732 ¶m->sctp_local_q, ent->value);
1734 PARSE_ERROR((status == 0), section_name,
1739 if (strcmp(ent->name, "pci_bdf") == 0) {
1740 PARSE_ERROR_DUPLICATE((pci_bdf_present == 0),
1741 section_name, ent->name);
1743 snprintf(param->pci_bdf, APP_LINK_PCI_BDF_SIZE,
1745 pci_bdf_present = 1;
1750 PARSE_ERROR_INVALID(0, section_name, ent->name);
1753 /* Check for mandatory fields */
1755 PARSE_ERROR_MESSAGE((pci_bdf_present == 0),
1756 section_name, "pci_bdf",
1757 "entry not allowed (port_mask is provided)");
1759 PARSE_ERROR_MESSAGE((pci_bdf_present),
1760 section_name, "pci_bdf",
1761 "this entry is mandatory (port_mask is not "
1770 parse_rxq(struct app_params *app,
1771 const char *section_name,
1772 struct rte_cfgfile *cfg)
1774 struct app_pktq_hwq_in_params *param;
1775 struct rte_cfgfile_entry *entries;
1779 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1780 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1782 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1783 PARSE_ERROR_MALLOC(entries != NULL);
1785 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1787 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1788 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1790 param = &app->hwq_in_params[param_idx];
1792 for (i = 0; i < n_entries; i++) {
1793 struct rte_cfgfile_entry *ent = &entries[i];
1795 if (strcmp(ent->name, "mempool") == 0) {
1796 int status = validate_name(ent->value,
1800 PARSE_ERROR((status == 0), section_name,
1802 idx = APP_PARAM_ADD(app->mempool_params,
1804 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
1806 param->mempool_id = idx;
1810 if (strcmp(ent->name, "size") == 0) {
1811 int status = parser_read_uint32(¶m->size,
1814 PARSE_ERROR((status == 0), section_name,
1819 if (strcmp(ent->name, "burst") == 0) {
1820 int status = parser_read_uint32(¶m->burst,
1823 PARSE_ERROR((status == 0), section_name,
1829 PARSE_ERROR_INVALID(0, section_name, ent->name);
1838 parse_txq(struct app_params *app,
1839 const char *section_name,
1840 struct rte_cfgfile *cfg)
1842 struct app_pktq_hwq_out_params *param;
1843 struct rte_cfgfile_entry *entries;
1847 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1848 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1850 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1851 PARSE_ERROR_MALLOC(entries != NULL);
1853 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1855 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1856 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1858 param = &app->hwq_out_params[param_idx];
1860 for (i = 0; i < n_entries; i++) {
1861 struct rte_cfgfile_entry *ent = &entries[i];
1863 if (strcmp(ent->name, "size") == 0) {
1864 int status = parser_read_uint32(¶m->size,
1867 PARSE_ERROR((status == 0), section_name,
1872 if (strcmp(ent->name, "burst") == 0) {
1873 int status = parser_read_uint32(¶m->burst,
1876 PARSE_ERROR((status == 0), section_name,
1881 if (strcmp(ent->name, "dropless") == 0) {
1882 int status = parser_read_arg_bool(ent->value);
1885 PARSE_ERROR((status != -EINVAL), section_name,
1887 param->dropless = status;
1892 PARSE_ERROR_INVALID(0, section_name, ent->name);
1901 parse_swq(struct app_params *app,
1902 const char *section_name,
1903 struct rte_cfgfile *cfg)
1905 struct app_pktq_swq_params *param;
1906 struct rte_cfgfile_entry *entries;
1908 uint32_t mtu_present = 0;
1909 uint32_t metadata_size_present = 0;
1910 uint32_t mempool_direct_present = 0;
1911 uint32_t mempool_indirect_present = 0;
1915 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1916 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1918 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1919 PARSE_ERROR_MALLOC(entries != NULL);
1921 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1923 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1924 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1926 param = &app->swq_params[param_idx];
1928 for (i = 0; i < n_entries; i++) {
1929 struct rte_cfgfile_entry *ent = &entries[i];
1931 if (strcmp(ent->name, "size") == 0) {
1932 int status = parser_read_uint32(¶m->size,
1935 PARSE_ERROR((status == 0), section_name,
1940 if (strcmp(ent->name, "burst_read") == 0) {
1941 int status = parser_read_uint32(&
1942 param->burst_read, ent->value);
1944 PARSE_ERROR((status == 0), section_name,
1949 if (strcmp(ent->name, "burst_write") == 0) {
1950 int status = parser_read_uint32(
1951 ¶m->burst_write, ent->value);
1953 PARSE_ERROR((status == 0), section_name,
1958 if (strcmp(ent->name, "dropless") == 0) {
1959 int status = parser_read_arg_bool(ent->value);
1961 PARSE_ERROR((status != -EINVAL), section_name,
1963 param->dropless = status;
1967 if (strcmp(ent->name, "n_retries") == 0) {
1968 int status = parser_read_uint64(¶m->n_retries,
1971 PARSE_ERROR((status == 0), section_name,
1976 if (strcmp(ent->name, "cpu") == 0) {
1977 int status = parser_read_uint32(
1978 ¶m->cpu_socket_id, ent->value);
1980 PARSE_ERROR((status == 0), section_name, ent->name);
1984 if (strcmp(ent->name, "ipv4_frag") == 0) {
1985 int status = parser_read_arg_bool(ent->value);
1987 PARSE_ERROR((status != -EINVAL), section_name,
1990 param->ipv4_frag = status;
1991 if (param->mtu == 0)
1997 if (strcmp(ent->name, "ipv6_frag") == 0) {
1998 int status = parser_read_arg_bool(ent->value);
2000 PARSE_ERROR((status != -EINVAL), section_name,
2002 param->ipv6_frag = status;
2003 if (param->mtu == 0)
2008 if (strcmp(ent->name, "ipv4_ras") == 0) {
2009 int status = parser_read_arg_bool(ent->value);
2011 PARSE_ERROR((status != -EINVAL), section_name,
2013 param->ipv4_ras = status;
2017 if (strcmp(ent->name, "ipv6_ras") == 0) {
2018 int status = parser_read_arg_bool(ent->value);
2020 PARSE_ERROR((status != -EINVAL), section_name,
2022 param->ipv6_ras = status;
2026 if (strcmp(ent->name, "mtu") == 0) {
2027 int status = parser_read_uint32(¶m->mtu,
2030 PARSE_ERROR((status == 0), section_name,
2036 if (strcmp(ent->name, "metadata_size") == 0) {
2037 int status = parser_read_uint32(
2038 ¶m->metadata_size, ent->value);
2040 PARSE_ERROR((status == 0), section_name,
2042 metadata_size_present = 1;
2046 if (strcmp(ent->name, "mempool_direct") == 0) {
2047 int status = validate_name(ent->value,
2051 PARSE_ERROR((status == 0), section_name,
2054 idx = APP_PARAM_ADD(app->mempool_params,
2056 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2058 param->mempool_direct_id = idx;
2059 mempool_direct_present = 1;
2063 if (strcmp(ent->name, "mempool_indirect") == 0) {
2064 int status = validate_name(ent->value,
2068 PARSE_ERROR((status == 0), section_name,
2070 idx = APP_PARAM_ADD(app->mempool_params,
2072 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2074 param->mempool_indirect_id = idx;
2075 mempool_indirect_present = 1;
2080 PARSE_ERROR_INVALID(0, section_name, ent->name);
2083 APP_CHECK(((mtu_present) &&
2084 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2085 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2086 "is off, therefore entry \"mtu\" is not allowed",
2089 APP_CHECK(((metadata_size_present) &&
2090 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2091 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2092 "is off, therefore entry \"metadata_size\" is "
2093 "not allowed", section_name);
2095 APP_CHECK(((mempool_direct_present) &&
2096 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2097 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2098 "is off, therefore entry \"mempool_direct\" is "
2099 "not allowed", section_name);
2101 APP_CHECK(((mempool_indirect_present) &&
2102 ((param->ipv4_frag == 1) || (param->ipv6_frag == 1))),
2103 "Parse error in section \"%s\": IPv4/IPv6 fragmentation "
2104 "is off, therefore entry \"mempool_indirect\" is "
2105 "not allowed", section_name);
2113 parse_tm(struct app_params *app,
2114 const char *section_name,
2115 struct rte_cfgfile *cfg)
2117 struct app_pktq_tm_params *param;
2118 struct rte_cfgfile_entry *entries;
2122 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2123 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2125 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2126 PARSE_ERROR_MALLOC(entries != NULL);
2128 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2130 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
2131 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
2133 param = &app->tm_params[param_idx];
2135 for (i = 0; i < n_entries; i++) {
2136 struct rte_cfgfile_entry *ent = &entries[i];
2138 if (strcmp(ent->name, "cfg") == 0) {
2139 param->file_name = strdup(ent->value);
2140 PARSE_ERROR_MALLOC(param->file_name != NULL);
2144 if (strcmp(ent->name, "burst_read") == 0) {
2145 int status = parser_read_uint32(
2146 ¶m->burst_read, ent->value);
2148 PARSE_ERROR((status == 0), section_name,
2153 if (strcmp(ent->name, "burst_write") == 0) {
2154 int status = parser_read_uint32(
2155 ¶m->burst_write, ent->value);
2157 PARSE_ERROR((status == 0), section_name,
2163 PARSE_ERROR_INVALID(0, section_name, ent->name);
2172 parse_source(struct app_params *app,
2173 const char *section_name,
2174 struct rte_cfgfile *cfg)
2176 struct app_pktq_source_params *param;
2177 struct rte_cfgfile_entry *entries;
2180 uint32_t pcap_file_present = 0;
2181 uint32_t pcap_size_present = 0;
2183 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2184 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2186 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2187 PARSE_ERROR_MALLOC(entries != NULL);
2189 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2191 param_idx = APP_PARAM_ADD(app->source_params, section_name);
2192 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
2194 param = &app->source_params[param_idx];
2196 for (i = 0; i < n_entries; i++) {
2197 struct rte_cfgfile_entry *ent = &entries[i];
2199 if (strcmp(ent->name, "mempool") == 0) {
2200 int status = validate_name(ent->value,
2204 PARSE_ERROR((status == 0), section_name,
2206 idx = APP_PARAM_ADD(app->mempool_params,
2208 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params,
2210 param->mempool_id = idx;
2214 if (strcmp(ent->name, "burst") == 0) {
2215 int status = parser_read_uint32(¶m->burst,
2218 PARSE_ERROR((status == 0), section_name,
2223 if (strcmp(ent->name, "pcap_file_rd")) {
2224 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2225 section_name, ent->name);
2227 param->file_name = strdup(ent->value);
2229 PARSE_ERROR_MALLOC(param->file_name != NULL);
2230 pcap_file_present = 1;
2235 if (strcmp(ent->name, "pcap_bytes_rd_per_pkt") == 0) {
2238 PARSE_ERROR_DUPLICATE((pcap_size_present == 0),
2239 section_name, ent->name);
2241 status = parser_read_uint32(
2242 ¶m->n_bytes_per_pkt, ent->value);
2244 PARSE_ERROR((status == 0), section_name,
2246 pcap_size_present = 1;
2252 PARSE_ERROR_INVALID(0, section_name, ent->name);
2261 parse_sink(struct app_params *app,
2262 const char *section_name,
2263 struct rte_cfgfile *cfg)
2265 struct app_pktq_sink_params *param;
2266 struct rte_cfgfile_entry *entries;
2269 uint32_t pcap_file_present = 0;
2270 uint32_t pcap_n_pkt_present = 0;
2272 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2273 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2275 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2276 PARSE_ERROR_MALLOC(entries != NULL);
2278 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2280 param_idx = APP_PARAM_ADD(app->sink_params, section_name);
2281 PARSER_PARAM_ADD_CHECK(param_idx, app->sink_params, section_name);
2283 param = &app->sink_params[param_idx];
2285 for (i = 0; i < n_entries; i++) {
2286 struct rte_cfgfile_entry *ent = &entries[i];
2288 if (strcmp(ent->name, "pcap_file_wr")) {
2289 PARSE_ERROR_DUPLICATE((pcap_file_present == 0),
2290 section_name, ent->name);
2292 param->file_name = strdup(ent->value);
2294 PARSE_ERROR_MALLOC((param->file_name != NULL));
2299 if (strcmp(ent->name, "pcap_n_pkt_wr")) {
2302 PARSE_ERROR_DUPLICATE((pcap_n_pkt_present == 0),
2303 section_name, ent->name);
2305 status = parser_read_uint32(
2306 ¶m->n_pkts_to_dump, ent->value);
2308 PARSE_ERROR((status == 0), section_name,
2315 PARSE_ERROR_INVALID(0, section_name, ent->name);
2324 parse_msgq_req_pipeline(struct app_params *app,
2325 const char *section_name,
2326 struct rte_cfgfile *cfg)
2328 struct app_msgq_params *param;
2329 struct rte_cfgfile_entry *entries;
2333 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2334 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2336 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2337 PARSE_ERROR_MALLOC(entries != NULL);
2339 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2341 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2342 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2344 param = &app->msgq_params[param_idx];
2346 for (i = 0; i < n_entries; i++) {
2347 struct rte_cfgfile_entry *ent = &entries[i];
2349 if (strcmp(ent->name, "size") == 0) {
2350 int status = parser_read_uint32(¶m->size,
2353 PARSE_ERROR((status == 0), section_name,
2359 PARSE_ERROR_INVALID(0, section_name, ent->name);
2367 parse_msgq_rsp_pipeline(struct app_params *app,
2368 const char *section_name,
2369 struct rte_cfgfile *cfg)
2371 struct app_msgq_params *param;
2372 struct rte_cfgfile_entry *entries;
2376 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2377 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2379 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2380 PARSE_ERROR_MALLOC(entries != NULL);
2382 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2384 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2385 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2387 param = &app->msgq_params[param_idx];
2389 for (i = 0; i < n_entries; i++) {
2390 struct rte_cfgfile_entry *ent = &entries[i];
2392 if (strcmp(ent->name, "size") == 0) {
2393 int status = parser_read_uint32(¶m->size,
2396 PARSE_ERROR((status == 0), section_name,
2402 PARSE_ERROR_INVALID(0, section_name, ent->name);
2411 parse_msgq(struct app_params *app,
2412 const char *section_name,
2413 struct rte_cfgfile *cfg)
2415 struct app_msgq_params *param;
2416 struct rte_cfgfile_entry *entries;
2420 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
2421 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
2423 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
2424 PARSE_ERROR_MALLOC(entries != NULL);
2426 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
2428 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
2429 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
2431 param = &app->msgq_params[param_idx];
2433 for (i = 0; i < n_entries; i++) {
2434 struct rte_cfgfile_entry *ent = &entries[i];
2436 if (strcmp(ent->name, "size") == 0) {
2437 int status = parser_read_uint32(¶m->size,
2440 PARSE_ERROR((status == 0), section_name,
2445 if (strcmp(ent->name, "cpu") == 0) {
2446 int status = parser_read_uint32(
2447 ¶m->cpu_socket_id, ent->value);
2449 PARSE_ERROR((status == 0), section_name,
2455 PARSE_ERROR_INVALID(0, section_name, ent->name);
2463 typedef void (*config_section_load)(struct app_params *p,
2464 const char *section_name,
2465 struct rte_cfgfile *cfg);
2467 struct config_section {
2468 const char prefix[CFG_NAME_LEN];
2470 config_section_load load;
2473 static const struct config_section cfg_file_scheme[] = {
2474 {"EAL", 0, parse_eal},
2475 {"PIPELINE", 1, parse_pipeline},
2476 {"MEMPOOL", 1, parse_mempool},
2477 {"LINK", 1, parse_link},
2478 {"RXQ", 2, parse_rxq},
2479 {"TXQ", 2, parse_txq},
2480 {"SWQ", 1, parse_swq},
2481 {"TM", 1, parse_tm},
2482 {"SOURCE", 1, parse_source},
2483 {"SINK", 1, parse_sink},
2484 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
2485 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
2486 {"MSGQ", 1, parse_msgq},
2490 create_implicit_mempools(struct app_params *app)
2494 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
2495 PARSER_PARAM_ADD_CHECK(idx, app->mempool_params, "start-up");
2499 create_implicit_links_from_port_mask(struct app_params *app,
2502 uint32_t pmd_id, link_id;
2505 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
2506 char name[APP_PARAM_NAME_SIZE];
2509 if ((port_mask & (1LLU << pmd_id)) == 0)
2512 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
2513 idx = APP_PARAM_ADD(app->link_params, name);
2514 PARSER_PARAM_ADD_CHECK(idx, app->link_params, name);
2516 app->link_params[idx].pmd_id = pmd_id;
2522 assign_link_pmd_id_from_pci_bdf(struct app_params *app)
2526 for (i = 0; i < app->n_links; i++) {
2527 struct app_link_params *link = &app->link_params[i];
2534 app_config_parse(struct app_params *app, const char *file_name)
2536 struct rte_cfgfile *cfg;
2537 char **section_names;
2538 int i, j, sect_count;
2540 /* Implicit mempools */
2541 create_implicit_mempools(app);
2545 create_implicit_links_from_port_mask(app, app->port_mask);
2547 /* Load application configuration file */
2548 cfg = rte_cfgfile_load(file_name, 0);
2549 APP_CHECK((cfg != NULL), "Parse error: Unable to load config "
2550 "file %s", file_name);
2552 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
2553 APP_CHECK((sect_count > 0), "Parse error: number of sections "
2554 "in file \"%s\" return %d", file_name,
2557 section_names = malloc(sect_count * sizeof(char *));
2558 PARSE_ERROR_MALLOC(section_names != NULL);
2560 for (i = 0; i < sect_count; i++)
2561 section_names[i] = malloc(CFG_NAME_LEN);
2563 rte_cfgfile_sections(cfg, section_names, sect_count);
2565 for (i = 0; i < sect_count; i++) {
2566 const struct config_section *sch_s;
2567 int len, cfg_name_len;
2569 cfg_name_len = strlen(section_names[i]);
2571 /* Find section type */
2572 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
2573 sch_s = &cfg_file_scheme[j];
2574 len = strlen(sch_s->prefix);
2576 if (cfg_name_len < len)
2579 /* After section name we expect only '\0' or digit or
2580 * digit dot digit, so protect against false matching,
2581 * for example: "ABC" should match section name
2582 * "ABC0.0", but it should not match section_name
2585 if ((section_names[i][len] != '\0') &&
2586 !isdigit(section_names[i][len]))
2589 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
2593 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
2594 "Parse error: unknown section %s",
2597 APP_CHECK(validate_name(section_names[i],
2599 sch_s->numbers) == 0,
2600 "Parse error: invalid section name \"%s\"",
2603 sch_s->load(app, section_names[i], cfg);
2606 for (i = 0; i < sect_count; i++)
2607 free(section_names[i]);
2609 free(section_names);
2611 rte_cfgfile_close(cfg);
2613 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
2614 APP_PARAM_COUNT(app->link_params, app->n_links);
2615 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
2616 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
2617 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
2618 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
2619 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
2620 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
2621 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
2622 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
2624 #ifdef RTE_PORT_PCAP
2625 for (i = 0; i < (int)app->n_pktq_source; i++) {
2626 struct app_pktq_source_params *p = &app->source_params[i];
2628 APP_CHECK((p->file_name), "Parse error: missing "
2629 "mandatory field \"pcap_file_rd\" for \"%s\"",
2633 for (i = 0; i < (int)app->n_pktq_source; i++) {
2634 struct app_pktq_source_params *p = &app->source_params[i];
2636 APP_CHECK((!p->file_name), "Parse error: invalid field "
2637 "\"pcap_file_rd\" for \"%s\"", p->name);
2641 if (app->port_mask == 0)
2642 assign_link_pmd_id_from_pci_bdf(app);
2644 /* Save configuration to output file */
2645 app_config_save(app, app->output_file);
2647 /* Load TM configuration files */
2648 app_config_parse_tm(app);
2654 save_eal_params(struct app_params *app, FILE *f)
2656 struct app_eal_params *p = &app->eal_params;
2659 fprintf(f, "[EAL]\n");
2662 fprintf(f, "%s = %s\n", "lcores", p->coremap);
2664 if (p->master_lcore_present)
2665 fprintf(f, "%s = %" PRIu32 "\n",
2666 "master_lcore", p->master_lcore);
2668 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
2670 if (p->memory_present)
2671 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
2673 if (p->ranks_present)
2674 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
2676 for (i = 0; i < APP_MAX_LINKS; i++) {
2677 if (p->pci_blacklist[i] == NULL)
2680 fprintf(f, "%s = %s\n", "pci_blacklist",
2681 p->pci_blacklist[i]);
2684 for (i = 0; i < APP_MAX_LINKS; i++) {
2685 if (p->pci_whitelist[i] == NULL)
2688 fprintf(f, "%s = %s\n", "pci_whitelist",
2689 p->pci_whitelist[i]);
2692 for (i = 0; i < APP_MAX_LINKS; i++) {
2693 if (p->vdev[i] == NULL)
2696 fprintf(f, "%s = %s\n", "vdev",
2700 if (p->vmware_tsc_map_present)
2701 fprintf(f, "%s = %s\n", "vmware_tsc_map",
2702 (p->vmware_tsc_map) ? "yes" : "no");
2705 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
2708 fprintf(f, "%s = %s\n", "syslog", p->syslog);
2710 if (p->log_level_present)
2711 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
2713 if (p->version_present)
2714 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
2716 if (p->help_present)
2717 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
2719 if (p->no_huge_present)
2720 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2722 if (p->no_pci_present)
2723 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2725 if (p->no_hpet_present)
2726 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2728 if (p->no_shconf_present)
2729 fprintf(f, "%s = %s\n", "no_shconf",
2730 (p->no_shconf) ? "yes" : "no");
2733 fprintf(f, "%s = %s\n", "d", p->add_driver);
2736 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2739 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2742 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2744 if (p->base_virtaddr)
2745 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2747 if (p->create_uio_dev_present)
2748 fprintf(f, "%s = %s\n", "create_uio_dev",
2749 (p->create_uio_dev) ? "yes" : "no");
2752 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2754 if (p->xen_dom0_present)
2755 fprintf(f, "%s = %s\n", "xen_dom0",
2756 (p->xen_dom0) ? "yes" : "no");
2762 save_mempool_params(struct app_params *app, FILE *f)
2764 struct app_mempool_params *p;
2767 count = RTE_DIM(app->mempool_params);
2768 for (i = 0; i < count; i++) {
2769 p = &app->mempool_params[i];
2770 if (!APP_PARAM_VALID(p))
2773 fprintf(f, "[%s]\n", p->name);
2774 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2775 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2776 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2777 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2784 save_links_params(struct app_params *app, FILE *f)
2786 struct app_link_params *p;
2789 count = RTE_DIM(app->link_params);
2790 for (i = 0; i < count; i++) {
2791 p = &app->link_params[i];
2792 if (!APP_PARAM_VALID(p))
2795 fprintf(f, "[%s]\n", p->name);
2796 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2797 fprintf(f, "%s = %s\n", "promisc", p->promisc ? "yes" : "no");
2798 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2799 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_q",
2801 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2802 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2803 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2804 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2807 if (strlen(p->pci_bdf))
2808 fprintf(f, "%s = %s\n", "pci_bdf", p->pci_bdf);
2815 save_rxq_params(struct app_params *app, FILE *f)
2817 struct app_pktq_hwq_in_params *p;
2820 count = RTE_DIM(app->hwq_in_params);
2821 for (i = 0; i < count; i++) {
2822 p = &app->hwq_in_params[i];
2823 if (!APP_PARAM_VALID(p))
2826 fprintf(f, "[%s]\n", p->name);
2827 fprintf(f, "%s = %s\n",
2829 app->mempool_params[p->mempool_id].name);
2830 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2831 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2838 save_txq_params(struct app_params *app, FILE *f)
2840 struct app_pktq_hwq_out_params *p;
2843 count = RTE_DIM(app->hwq_out_params);
2844 for (i = 0; i < count; i++) {
2845 p = &app->hwq_out_params[i];
2846 if (!APP_PARAM_VALID(p))
2849 fprintf(f, "[%s]\n", p->name);
2850 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2851 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2852 fprintf(f, "%s = %s\n",
2854 p->dropless ? "yes" : "no");
2861 save_swq_params(struct app_params *app, FILE *f)
2863 struct app_pktq_swq_params *p;
2866 count = RTE_DIM(app->swq_params);
2867 for (i = 0; i < count; i++) {
2868 p = &app->swq_params[i];
2869 if (!APP_PARAM_VALID(p))
2872 fprintf(f, "[%s]\n", p->name);
2873 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2874 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2875 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2876 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2877 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2878 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2879 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2880 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2881 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2882 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2883 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2884 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2885 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2886 fprintf(f, "%s = %s\n",
2888 app->mempool_params[p->mempool_direct_id].name);
2889 fprintf(f, "%s = %s\n",
2891 app->mempool_params[p->mempool_indirect_id].name);
2899 save_tm_params(struct app_params *app, FILE *f)
2901 struct app_pktq_tm_params *p;
2904 count = RTE_DIM(app->tm_params);
2905 for (i = 0; i < count; i++) {
2906 p = &app->tm_params[i];
2907 if (!APP_PARAM_VALID(p))
2910 fprintf(f, "[%s]\n", p->name);
2911 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2912 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2913 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2920 save_source_params(struct app_params *app, FILE *f)
2922 struct app_pktq_source_params *p;
2925 count = RTE_DIM(app->source_params);
2926 for (i = 0; i < count; i++) {
2927 p = &app->source_params[i];
2928 if (!APP_PARAM_VALID(p))
2931 fprintf(f, "[%s]\n", p->name);
2932 fprintf(f, "%s = %s\n",
2934 app->mempool_params[p->mempool_id].name);
2935 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2936 fprintf(f, "%s = %s\n", "pcap_file_rd", p->file_name);
2937 fprintf(f, "%s = %" PRIu32 "\n", "pcap_bytes_rd_per_pkt",
2938 p->n_bytes_per_pkt);
2944 save_sink_params(struct app_params *app, FILE *f)
2946 struct app_pktq_sink_params *p;
2949 count = RTE_DIM(app->sink_params);
2950 for (i = 0; i < count; i++) {
2951 p = &app->sink_params[i];
2952 if (!APP_PARAM_VALID(p))
2955 fprintf(f, "[%s]\n", p->name);
2956 fprintf(f, "%s = %s\n", "pcap_file_wr", p->file_name);
2957 fprintf(f, "%s = %" PRIu32 "\n",
2958 "pcap_n_pkt_wr", p->n_pkts_to_dump);
2964 save_msgq_params(struct app_params *app, FILE *f)
2966 struct app_msgq_params *p;
2969 count = RTE_DIM(app->msgq_params);
2970 for (i = 0; i < count; i++) {
2971 p = &app->msgq_params[i];
2972 if (!APP_PARAM_VALID(p))
2975 fprintf(f, "[%s]\n", p->name);
2976 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2977 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2984 save_pipeline_params(struct app_params *app, FILE *f)
2988 count = RTE_DIM(app->pipeline_params);
2989 for (i = 0; i < count; i++) {
2990 struct app_pipeline_params *p = &app->pipeline_params[i];
2992 if (!APP_PARAM_VALID(p))
2996 fprintf(f, "[%s]\n", p->name);
2999 fprintf(f, "type = %s\n", p->type);
3002 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
3005 (p->hyper_th_id) ? "h" : "");
3011 fprintf(f, "pktq_in =");
3012 for (j = 0; j < p->n_pktq_in; j++) {
3013 struct app_pktq_in_params *pp = &p->pktq_in[j];
3017 case APP_PKTQ_IN_HWQ:
3018 name = app->hwq_in_params[pp->id].name;
3020 case APP_PKTQ_IN_SWQ:
3021 name = app->swq_params[pp->id].name;
3023 case APP_PKTQ_IN_TM:
3024 name = app->tm_params[pp->id].name;
3026 case APP_PKTQ_IN_SOURCE:
3027 name = app->source_params[pp->id].name;
3030 APP_CHECK(0, "System error "
3031 "occurred while saving "
3032 "parameter to file");
3035 fprintf(f, " %s", name);
3041 if (p->n_pktq_out) {
3044 fprintf(f, "pktq_out =");
3045 for (j = 0; j < p->n_pktq_out; j++) {
3046 struct app_pktq_out_params *pp =
3051 case APP_PKTQ_OUT_HWQ:
3052 name = app->hwq_out_params[pp->id].name;
3054 case APP_PKTQ_OUT_SWQ:
3055 name = app->swq_params[pp->id].name;
3057 case APP_PKTQ_OUT_TM:
3058 name = app->tm_params[pp->id].name;
3060 case APP_PKTQ_OUT_SINK:
3061 name = app->sink_params[pp->id].name;
3064 APP_CHECK(0, "System error "
3065 "occurred while saving "
3066 "parameter to file");
3069 fprintf(f, " %s", name);
3078 fprintf(f, "msgq_in =");
3079 for (j = 0; j < p->n_msgq_in; j++) {
3080 uint32_t id = p->msgq_in[j];
3081 char *name = app->msgq_params[id].name;
3083 fprintf(f, " %s", name);
3089 if (p->n_msgq_out) {
3092 fprintf(f, "msgq_out =");
3093 for (j = 0; j < p->n_msgq_out; j++) {
3094 uint32_t id = p->msgq_out[j];
3095 char *name = app->msgq_params[id].name;
3097 fprintf(f, " %s", name);
3103 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
3109 for (j = 0; j < p->n_args; j++)
3110 fprintf(f, "%s = %s\n", p->args_name[j],
3119 app_config_save(struct app_params *app, const char *file_name)
3122 char *name, *dir_name;
3125 name = strdup(file_name);
3126 dir_name = dirname(name);
3127 status = access(dir_name, W_OK);
3128 APP_CHECK((status == 0),
3129 "Error: need write access privilege to directory "
3130 "\"%s\" to save configuration\n", dir_name);
3132 file = fopen(file_name, "w");
3133 APP_CHECK((file != NULL),
3134 "Error: failed to save configuration to file \"%s\"",
3137 save_eal_params(app, file);
3138 save_pipeline_params(app, file);
3139 save_mempool_params(app, file);
3140 save_links_params(app, file);
3141 save_rxq_params(app, file);
3142 save_txq_params(app, file);
3143 save_swq_params(app, file);
3144 save_tm_params(app, file);
3145 save_source_params(app, file);
3146 save_sink_params(app, file);
3147 save_msgq_params(app, file);
3154 app_config_init(struct app_params *app)
3158 memcpy(app, &app_params_default, sizeof(struct app_params));
3160 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
3161 memcpy(&app->mempool_params[i],
3162 &mempool_params_default,
3163 sizeof(struct app_mempool_params));
3165 for (i = 0; i < RTE_DIM(app->link_params); i++)
3166 memcpy(&app->link_params[i],
3167 &link_params_default,
3168 sizeof(struct app_link_params));
3170 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
3171 memcpy(&app->hwq_in_params[i],
3172 &default_hwq_in_params,
3173 sizeof(default_hwq_in_params));
3175 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
3176 memcpy(&app->hwq_out_params[i],
3177 &default_hwq_out_params,
3178 sizeof(default_hwq_out_params));
3180 for (i = 0; i < RTE_DIM(app->swq_params); i++)
3181 memcpy(&app->swq_params[i],
3182 &default_swq_params,
3183 sizeof(default_swq_params));
3185 for (i = 0; i < RTE_DIM(app->tm_params); i++)
3186 memcpy(&app->tm_params[i],
3188 sizeof(default_tm_params));
3190 for (i = 0; i < RTE_DIM(app->source_params); i++)
3191 memcpy(&app->source_params[i],
3192 &default_source_params,
3193 sizeof(default_source_params));
3195 for (i = 0; i < RTE_DIM(app->sink_params); i++)
3196 memcpy(&app->sink_params[i],
3197 &default_sink_params,
3198 sizeof(default_sink_params));
3200 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
3201 memcpy(&app->msgq_params[i],
3202 &default_msgq_params,
3203 sizeof(default_msgq_params));
3205 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
3206 memcpy(&app->pipeline_params[i],
3207 &default_pipeline_params,
3208 sizeof(default_pipeline_params));
3214 filenamedup(const char *filename, const char *suffix)
3216 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
3221 sprintf(s, "%s%s", filename, suffix);
3226 app_config_args(struct app_params *app, int argc, char **argv)
3228 const char *optname;
3229 int opt, option_index;
3230 int f_present, s_present, p_present, l_present;
3231 int preproc_present, preproc_params_present, disable_csum_present;
3233 int flow_dir_present;
3236 static struct option lgopts[] = {
3237 { "disable-hw-csum", 0, 0, 0 },
3238 { "preproc", 1, 0, 0 },
3239 { "preproc-args", 1, 0, 0 },
3240 { "hwlb", 1, 0, 0 },
3241 { "flow_dir", 0, 0, 0 },
3245 /* Copy application name */
3246 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
3252 disable_csum_present = 0;
3253 preproc_present = 0;
3254 preproc_params_present = 0;
3255 app->header_csum_req =1; //Default enable haeader checksum
3257 flow_dir_present = 0;
3260 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
3261 &option_index)) != EOF)
3265 rte_panic("Error: Config file is provided "
3266 "more than once\n");
3269 if (!strlen(optarg))
3270 rte_panic("Error: Config file name is null\n");
3272 app->config_file = strdup(optarg);
3273 if (app->config_file == NULL)
3274 rte_panic("Error: Memory allocation failure\n");
3280 rte_panic("Error: Script file is provided "
3281 "more than once\n");
3284 if (!strlen(optarg))
3285 rte_panic("Error: Script file name is null\n");
3287 app->script_file = strdup(optarg);
3288 if (app->script_file == NULL)
3289 rte_panic("Error: Memory allocation failure\n");
3295 rte_panic("Error: PORT_MASK is provided "
3296 "more than once\n");
3299 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
3301 ((size_t) scaned != strlen(optarg)))
3302 rte_panic("Error: PORT_MASK is not "
3303 "a hexadecimal integer\n");
3305 if (app->port_mask == 0)
3306 rte_panic("Error: PORT_MASK is null\n");
3312 rte_panic("Error: LOG_LEVEL is provided "
3313 "more than once\n");
3316 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
3318 ((size_t) scaned != strlen(optarg)) ||
3319 (app->log_level >= APP_LOG_LEVELS))
3320 rte_panic("Error: LOG_LEVEL invalid value\n");
3325 optname = lgopts[option_index].name;
3327 if (strcmp(optname, "hwlb") == 0) {
3329 rte_panic("Error: hwlb argument "
3330 "is provided more than once\n");
3332 printf(" HWLB is configured\n");
3334 app->n_hwlb_q = atoi(optarg);
3337 rte_panic("HWQs for HWLB must be atleast 1\n");
3339 printf("No of HWQs for HWLB are %d\n",app->n_hwlb_q);
3344 if (strcmp(optname, "flow_dir") == 0) {
3345 if (flow_dir_present)
3346 rte_panic("Error: flow_dir argument "
3347 "is provided more than once\n");
3348 flow_dir_present = 1;
3349 printf(" FLOW DIR is configured\n");
3351 enable_flow_dir = 1;
3356 if (strcmp(optname, "disable-hw-csum") == 0) {
3357 if (disable_csum_present)
3358 rte_panic("Error: disable-hw-csum argument "
3359 "is provided more than once\n");
3361 printf("Disable TCP/UDP HW checksumi\n");
3362 app->header_csum_req = 0;
3363 disable_csum_present = 1;
3367 if (strcmp(optname, "preproc") == 0) {
3368 if (preproc_present)
3369 rte_panic("Error: Preprocessor argument "
3370 "is provided more than once\n");
3371 preproc_present = 1;
3373 app->preproc = strdup(optarg);
3377 if (strcmp(optname, "preproc-args") == 0) {
3378 if (preproc_params_present)
3379 rte_panic("Error: Preprocessor args "
3380 "are provided more than once\n");
3381 preproc_params_present = 1;
3383 app->preproc_args = strdup(optarg);
3387 app_print_usage(argv[0]);
3391 app_print_usage(argv[0]);
3394 optind = 0; /* reset getopt lib */
3396 /* Check dependencies between args */
3397 if (preproc_params_present && (preproc_present == 0))
3398 rte_panic("Error: Preprocessor args specified while "
3399 "preprocessor is not defined\n");
3401 app->parser_file = preproc_present ?
3402 filenamedup(app->config_file, ".preproc") :
3403 strdup(app->config_file);
3404 app->output_file = filenamedup(app->config_file, ".out");
3410 app_config_preproc(struct app_params *app)
3415 if (app->preproc == NULL)
3418 status = access(app->config_file, F_OK | R_OK);
3419 APP_CHECK((status == 0), "Error: Unable to open file %s",
3422 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
3424 app->preproc_args ? app->preproc_args : "",
3428 status = system(buffer);
3429 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
3430 "Error occurred while pre-processing file \"%s\"\n",