4 * Copyright(c) 2010-2015 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.
44 #include <rte_errno.h>
45 #include <rte_cfgfile.h>
46 #include <rte_string_fns.h>
51 * Default config values
54 static struct app_params app_params_default = {
55 .config_file = "./config/ip_pipeline.cfg",
56 .log_level = APP_LOG_LEVEL_HIGH,
63 static const struct app_mempool_params mempool_params_default = {
65 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
66 .pool_size = 32 * 1024,
71 static const struct app_link_params link_params_default = {
89 .mq_mode = ETH_MQ_RX_NONE,
91 .header_split = 0, /* Header split */
92 .hw_ip_checksum = 0, /* IP checksum offload */
93 .hw_vlan_filter = 0, /* VLAN filtering */
94 .hw_vlan_strip = 0, /* VLAN strip */
95 .hw_vlan_extend = 0, /* Extended VLAN */
96 .jumbo_frame = 0, /* Jumbo frame support */
97 .hw_strip_crc = 0, /* CRC strip by HW */
98 .enable_scatter = 0, /* Scattered packets RX handler */
100 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
101 .split_hdr_size = 0, /* Header split buffer size */
104 .mq_mode = ETH_MQ_TX_NONE,
112 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
124 .rx_free_thresh = 64,
126 .rx_deferred_start = 0,
130 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
145 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
146 ETH_TXQ_FLAGS_NOOFFLOADS,
147 .tx_deferred_start = 0,
151 static const struct app_pktq_swq_params default_swq_params = {
165 .mempool_direct_id = 0,
166 .mempool_indirect_id = 0,
169 struct app_pktq_tm_params default_tm_params = {
171 .file_name = "./config/tm_profile.cfg",
176 struct app_pktq_source_params default_source_params = {
182 struct app_pktq_sink_params default_sink_params = {
186 struct app_msgq_params default_msgq_params = {
192 struct app_pipeline_params default_pipeline_params = {
205 static const char app_usage[] =
206 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] -p PORT_MASK "
207 "[-l LOG_LEVEL] [--preproc PREPROCESSOR] [--preproc-args ARGS]\n"
210 "\t-f CONFIG_FILE: Default config file is %s\n"
211 "\t-p PORT_MASK: Mask of NIC port IDs in hexadecimal format\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--preproc PREPROCESSOR: Configuration file pre-processor\n"
215 "\t--preproc-args ARGS: Arguments to be passed to pre-processor\n"
219 app_print_usage(char *prgname)
221 rte_exit(0, app_usage, prgname, app_params_default.config_file);
224 #define skip_white_spaces(pos) \
226 __typeof__(pos) _p = (pos); \
227 for ( ; isspace(*_p); _p++); \
231 #define PARSER_IMPLICIT_PARAM_ADD_CHECK(result, section_name) \
233 APP_CHECK((result != -EINVAL), \
234 "CFG: [%s] name too long", section_name); \
235 APP_CHECK(result != -ENOMEM, \
236 "CFG: [%s] too much sections", section_name); \
237 APP_CHECK(result >= 0, \
238 "CFG: [%s] Unknown error while adding '%s'", \
239 section_name, section_name); \
242 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
244 APP_CHECK((result != -EINVAL), \
245 "CFG: [%s] name too long", section_name); \
246 APP_CHECK((result != -ENOMEM), \
247 "CFG: [%s] too much sections", section_name); \
248 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
249 "CFG: [%s] duplicate section", section_name); \
250 APP_CHECK((result >= 0), \
251 "CFG: [%s] Unknown error while adding '%s'", \
252 section_name, section_name); \
256 parser_read_arg_bool(const char *p)
258 p = skip_white_spaces(p);
259 int result = -EINVAL;
261 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
262 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
267 if (((p[0] == 'o') && (p[1] == 'n')) ||
268 ((p[0] == 'O') && (p[1] == 'N'))) {
273 if (((p[0] == 'n') && (p[1] == 'o')) ||
274 ((p[0] == 'N') && (p[1] == 'O'))) {
279 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
280 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
285 p = skip_white_spaces(p);
293 #define PARSE_ERROR(exp, section, entry) \
294 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
296 #define PARSE_ERROR_MALLOC(exp) \
297 APP_CHECK(exp, "Parse error: no free memory\n")
299 #define PARSE_ERROR_SECTION(exp, section) \
300 APP_CHECK(exp, "Parse error in section \"%s\"", section)
302 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
303 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
305 #define PARSE_WARNING_IGNORED(exp, section, entry) \
308 fprintf(stderr, "Parse warning in section \"%s\": " \
309 "entry \"%s\" is ignored\n", section, entry); \
312 #define PARSE_ERROR_INVALID(exp, section, entry) \
313 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
316 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
317 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
321 parser_read_uint64(uint64_t *value, const char *p)
326 p = skip_white_spaces(p);
330 val = strtoul(p, &next, 10);
352 p = skip_white_spaces(p);
361 parser_read_uint32(uint32_t *value, const char *p)
364 int ret = parser_read_uint64(&val, p);
368 else if (val > UINT32_MAX)
376 parse_pipeline_core(uint32_t *socket,
384 uint32_t s = 0, c = 0, h = 0, val;
385 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
386 const char *next = skip_white_spaces(entry);
389 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
390 while (*next != '\0') {
391 /* If everything parsed nothing should left */
392 if (s_parsed && c_parsed && h_parsed)
399 if (s_parsed || c_parsed || h_parsed)
406 if (c_parsed || h_parsed)
419 /* If it start from digit it must be only core id. */
420 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
426 for (num_len = 0; *next != '\0'; next++, num_len++) {
427 if (num_len == RTE_DIM(num))
433 num[num_len] = *next;
436 if (num_len == 0 && type != 'h' && type != 'H')
439 if (num_len != 0 && (type == 'h' || type == 'H'))
443 val = strtol(num, NULL, 10);
469 skip_digits(const char *src)
473 for (i = 0; isdigit(src[i]); i++);
479 validate_name(const char *name, const char *prefix, int num)
483 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
484 if (name[i] != prefix[i])
488 if (prefix[i] != '\0')
499 j = skip_digits(&name[i]);
501 if ((j == 0) || (name[i] != '.'))
507 j = skip_digits(&name[i]);
509 if ((j == 0) || (name[i] != '\0'))
517 parse_eal(struct app_params *app,
518 const char *section_name,
519 struct rte_cfgfile *cfg)
521 struct app_eal_params *p = &app->eal_params;
522 struct rte_cfgfile_entry *entries;
525 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
526 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
528 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
529 PARSE_ERROR_MALLOC(entries != NULL);
531 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
533 for (i = 0; i < n_entries; i++) {
534 struct rte_cfgfile_entry *entry = &entries[i];
537 if (strcmp(entry->name, "c") == 0) {
538 PARSE_WARNING_IGNORED(0, section_name, entry->name);
543 if (strcmp(entry->name, "l") == 0) {
544 PARSE_WARNING_IGNORED(0, section_name, entry->name);
549 if (strcmp(entry->name, "lcores") == 0) {
550 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
553 p->coremap = strdup(entry->value);
558 if (strcmp(entry->name, "master_lcore") == 0) {
561 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
564 p->master_lcore_present = 1;
566 status = parser_read_uint32(&p->master_lcore,
568 PARSE_ERROR((status == 0), section_name, entry->name);
573 if (strcmp(entry->name, "n") == 0) {
576 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
579 p->channels_present = 1;
581 status = parser_read_uint32(&p->channels, entry->value);
582 PARSE_ERROR((status == 0), section_name, entry->name);
587 if (strcmp(entry->name, "m") == 0) {
590 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
593 p->memory_present = 1;
595 status = parser_read_uint32(&p->memory, entry->value);
596 PARSE_ERROR((status == 0), section_name, entry->name);
601 if (strcmp(entry->name, "r") == 0) {
604 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
607 p->ranks_present = 1;
609 status = parser_read_uint32(&p->ranks, entry->value);
610 PARSE_ERROR((status == 0), section_name, entry->name);
615 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
616 (strcmp(entry->name, "b") == 0)) {
617 PARSE_ERROR_DUPLICATE((p->pci_blacklist == NULL),
620 p->pci_blacklist = strdup(entry->value);
625 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
626 (strcmp(entry->name, "w") == 0)) {
627 PARSE_ERROR_DUPLICATE((p->pci_whitelist == NULL),
630 p->pci_whitelist = strdup(entry->value);
635 if (strcmp(entry->name, "vdev") == 0) {
636 PARSE_ERROR_DUPLICATE((p->vdev == NULL),
639 p->vdev = strdup(entry->value);
644 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
647 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
650 p->vmware_tsc_map_present = 1;
652 val = parser_read_arg_bool(entry->value);
653 PARSE_ERROR((val >= 0), section_name, entry->name);
654 p->vmware_tsc_map = val;
659 if (strcmp(entry->name, "proc_type") == 0) {
660 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
663 p->proc_type = strdup(entry->value);
668 if (strcmp(entry->name, "syslog") == 0) {
669 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
672 p->syslog = strdup(entry->value);
677 if (strcmp(entry->name, "log_level") == 0) {
680 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
683 p->log_level_present = 1;
685 status = parser_read_uint32(&p->log_level,
687 PARSE_ERROR((status == 0), section_name, entry->name);
692 if (strcmp(entry->name, "v") == 0) {
695 PARSE_ERROR_DUPLICATE((p->version_present == 0),
698 p->version_present = 1;
700 val = parser_read_arg_bool(entry->value);
701 PARSE_ERROR((val >= 0), section_name, entry->name);
707 if ((strcmp(entry->name, "help") == 0) ||
708 (strcmp(entry->name, "h") == 0)) {
711 PARSE_ERROR_DUPLICATE((p->help_present == 0),
716 val = parser_read_arg_bool(entry->value);
717 PARSE_ERROR((val >= 0), section_name, entry->name);
723 if (strcmp(entry->name, "no_huge") == 0) {
726 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
729 p->no_huge_present = 1;
731 val = parser_read_arg_bool(entry->value);
732 PARSE_ERROR((val >= 0), section_name, entry->name);
738 if (strcmp(entry->name, "no_pci") == 0) {
741 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
744 p->no_pci_present = 1;
746 val = parser_read_arg_bool(entry->value);
747 PARSE_ERROR((val >= 0), section_name, entry->name);
753 if (strcmp(entry->name, "no_hpet") == 0) {
756 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
759 p->no_hpet_present = 1;
761 val = parser_read_arg_bool(entry->value);
762 PARSE_ERROR((val >= 0), section_name, entry->name);
768 if (strcmp(entry->name, "no_shconf") == 0) {
771 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
774 p->no_shconf_present = 1;
776 val = parser_read_arg_bool(entry->value);
777 PARSE_ERROR((val >= 0), section_name, entry->name);
783 if (strcmp(entry->name, "d") == 0) {
784 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
787 p->add_driver = strdup(entry->value);
792 if (strcmp(entry->name, "socket_mem") == 0) {
793 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
796 p->socket_mem = strdup(entry->value);
801 if (strcmp(entry->name, "huge_dir") == 0) {
802 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
805 p->huge_dir = strdup(entry->value);
810 if (strcmp(entry->name, "file_prefix") == 0) {
811 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
814 p->file_prefix = strdup(entry->value);
819 if (strcmp(entry->name, "base_virtaddr") == 0) {
820 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
823 p->base_virtaddr = strdup(entry->value);
828 if (strcmp(entry->name, "create_uio_dev") == 0) {
831 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
834 p->create_uio_dev_present = 1;
836 val = parser_read_arg_bool(entry->value);
837 PARSE_ERROR((val >= 0), section_name, entry->name);
838 p->create_uio_dev = val;
843 if (strcmp(entry->name, "vfio_intr") == 0) {
844 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
847 p->vfio_intr = strdup(entry->value);
852 if (strcmp(entry->name, "xen_dom0") == 0) {
855 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
858 p->xen_dom0_present = 1;
860 val = parser_read_arg_bool(entry->value);
861 PARSE_ERROR((val >= 0), section_name, entry->name);
867 PARSE_ERROR_INVALID(0, section_name, entry->name);
874 parse_pipeline_pktq_in(struct app_params *app,
875 struct app_pipeline_params *p,
878 const char *next = value;
880 char name[APP_PARAM_NAME_SIZE];
883 while (*next != '\0') {
884 enum app_pktq_in_type type;
887 end = strchr(next, ' ');
889 name_len = strlen(next);
891 name_len = end - next;
893 if (name_len == 0 || name_len == sizeof(name))
896 strncpy(name, next, name_len);
897 name[name_len] = '\0';
902 if (validate_name(name, "RXQ", 2) == 0) {
903 type = APP_PKTQ_IN_HWQ;
904 id = APP_PARAM_ADD(app->hwq_in_params, name);
905 } else if (validate_name(name, "SWQ", 1) == 0) {
906 type = APP_PKTQ_IN_SWQ;
907 id = APP_PARAM_ADD(app->swq_params, name);
908 } else if (validate_name(name, "TM", 1) == 0) {
909 type = APP_PKTQ_IN_TM;
910 id = APP_PARAM_ADD(app->tm_params, name);
911 } else if (validate_name(name, "SOURCE", 1) == 0) {
912 type = APP_PKTQ_IN_SOURCE;
913 id = APP_PARAM_ADD(app->source_params, name);
920 p->pktq_in[p->n_pktq_in].type = type;
921 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
929 parse_pipeline_pktq_out(struct app_params *app,
930 struct app_pipeline_params *p,
933 const char *next = value;
935 char name[APP_PARAM_NAME_SIZE];
938 while (*next != '\0') {
939 enum app_pktq_out_type type;
942 end = strchr(next, ' ');
944 name_len = strlen(next);
946 name_len = end - next;
948 if (name_len == 0 || name_len == sizeof(name))
951 strncpy(name, next, name_len);
952 name[name_len] = '\0';
957 if (validate_name(name, "TXQ", 2) == 0) {
958 type = APP_PKTQ_OUT_HWQ;
959 id = APP_PARAM_ADD(app->hwq_out_params, name);
960 } else if (validate_name(name, "SWQ", 1) == 0) {
961 type = APP_PKTQ_OUT_SWQ;
962 id = APP_PARAM_ADD(app->swq_params, name);
963 } else if (validate_name(name, "TM", 1) == 0) {
964 type = APP_PKTQ_OUT_TM;
965 id = APP_PARAM_ADD(app->tm_params, name);
966 } else if (validate_name(name, "SINK", 1) == 0) {
967 type = APP_PKTQ_OUT_SINK;
968 id = APP_PARAM_ADD(app->sink_params, name);
975 p->pktq_out[p->n_pktq_out].type = type;
976 p->pktq_out[p->n_pktq_out].id = id;
984 parse_pipeline_msgq_in(struct app_params *app,
985 struct app_pipeline_params *p,
988 const char *next = value;
990 char name[APP_PARAM_NAME_SIZE];
994 while (*next != '\0') {
995 end = strchr(next, ' ');
997 name_len = strlen(next);
999 name_len = end - next;
1001 if (name_len == 0 || name_len == sizeof(name))
1004 strncpy(name, next, name_len);
1005 name[name_len] = '\0';
1010 if (validate_name(name, "MSGQ", 1) != 0)
1013 idx = APP_PARAM_ADD(app->msgq_params, name);
1017 p->msgq_in[p->n_msgq_in] = idx;
1025 parse_pipeline_msgq_out(struct app_params *app,
1026 struct app_pipeline_params *p,
1029 const char *next = value;
1031 char name[APP_PARAM_NAME_SIZE];
1035 while (*next != '\0') {
1036 end = strchr(next, ' ');
1038 name_len = strlen(next);
1040 name_len = end - next;
1042 if (name_len == 0 || name_len == sizeof(name))
1045 strncpy(name, next, name_len);
1046 name[name_len] = '\0';
1051 if (validate_name(name, "MSGQ", 1) != 0)
1054 idx = APP_PARAM_ADD(app->msgq_params, name);
1058 p->msgq_out[p->n_msgq_out] = idx;
1067 parse_pipeline(struct app_params *app,
1068 const char *section_name,
1069 struct rte_cfgfile *cfg)
1071 char name[CFG_NAME_LEN];
1072 struct app_pipeline_params *param;
1073 struct rte_cfgfile_entry *entries;
1075 int n_entries, ret, i;
1077 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1078 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1080 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1081 PARSE_ERROR_MALLOC(entries != NULL);
1083 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1085 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1086 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1088 param = &app->pipeline_params[param_idx];
1091 for (i = 0; i < n_entries; i++) {
1092 struct rte_cfgfile_entry *ent = &entries[i];
1094 if (strcmp(ent->name, "type") == 0) {
1095 ret = snprintf(param->type,
1096 RTE_DIM(param->type),
1099 if ((ret > 0) && (ret < (int)RTE_DIM(param->type)))
1103 } else if (strcmp(ent->name, "core") == 0)
1104 ret = parse_pipeline_core(¶m->socket_id,
1106 ¶m->hyper_th_id,
1108 else if (strcmp(ent->name, "pktq_in") == 0)
1109 ret = parse_pipeline_pktq_in(app, param, ent->value);
1110 else if (strcmp(ent->name, "pktq_out") == 0)
1111 ret = parse_pipeline_pktq_out(app, param, ent->value);
1112 else if (strcmp(ent->name, "msgq_in") == 0)
1113 ret = parse_pipeline_msgq_in(app, param, ent->value);
1114 else if (strcmp(ent->name, "msgq_out") == 0)
1115 ret = parse_pipeline_msgq_out(app, param, ent->value);
1116 else if (strcmp(ent->name, "timer_period") == 0)
1117 ret = parser_read_uint32(¶m->timer_period,
1120 APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
1121 "CFG: [%s] out of memory",
1124 param->args_name[param->n_args] = strdup(ent->name);
1125 param->args_value[param->n_args] = strdup(ent->value);
1127 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1128 (param->args_value[param->n_args] != NULL),
1129 "CFG: [%s] out of memory",
1137 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1143 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1144 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1145 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1146 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1147 param->msgq_in[param->n_msgq_in++] = param_idx;
1149 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1150 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1151 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1152 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1153 param->msgq_out[param->n_msgq_out++] = param_idx;
1155 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1158 (param->hyper_th_id) ? "h" : "");
1159 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1160 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1161 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1163 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1166 (param->hyper_th_id) ? "h" : "");
1167 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1168 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1169 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1175 parse_mempool(struct app_params *app,
1176 const char *section_name,
1177 struct rte_cfgfile *cfg)
1179 struct app_mempool_params *param;
1180 struct rte_cfgfile_entry *entries;
1182 int n_entries, ret, i;
1184 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1185 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1187 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1188 PARSE_ERROR_MALLOC(entries != NULL);
1190 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1192 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1193 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1195 param = &app->mempool_params[param_idx];
1198 for (i = 0; i < n_entries; i++) {
1199 struct rte_cfgfile_entry *ent = &entries[i];
1202 if (strcmp(ent->name, "buffer_size") == 0)
1203 ret = parser_read_uint32(¶m->buffer_size,
1205 else if (strcmp(ent->name, "pool_size") == 0)
1206 ret = parser_read_uint32(¶m->pool_size,
1208 else if (strcmp(ent->name, "cache_size") == 0)
1209 ret = parser_read_uint32(¶m->cache_size,
1211 else if (strcmp(ent->name, "cpu") == 0)
1212 ret = parser_read_uint32(¶m->cpu_socket_id,
1215 APP_CHECK(ret != -ESRCH,
1216 "CFG: [%s] entry '%s': unknown entry\n",
1220 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1230 parse_link(struct app_params *app,
1231 const char *section_name,
1232 struct rte_cfgfile *cfg)
1234 struct app_link_params *param;
1235 struct rte_cfgfile_entry *entries;
1236 int n_entries, ret, i;
1239 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1240 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1242 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1243 PARSE_ERROR_MALLOC(entries != NULL);
1245 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1247 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1248 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1250 param = &app->link_params[param_idx];
1253 for (i = 0; i < n_entries; i++) {
1254 struct rte_cfgfile_entry *ent = &entries[i];
1257 if (strcmp(ent->name, "arp_q") == 0)
1258 ret = parser_read_uint32(¶m->arp_q,
1260 else if (strcmp(ent->name, "tcp_syn_q") == 0)
1261 ret = parser_read_uint32(¶m->tcp_syn_local_q,
1263 else if (strcmp(ent->name, "ip_local_q") == 0)
1264 ret = parser_read_uint32(¶m->ip_local_q,
1266 else if (strcmp(ent->name, "tcp_local_q") == 0)
1267 ret = parser_read_uint32(¶m->tcp_local_q,
1269 else if (strcmp(ent->name, "udp_local_q") == 0)
1270 ret = parser_read_uint32(¶m->udp_local_q,
1272 else if (strcmp(ent->name, "sctp_local_q") == 0)
1273 ret = parser_read_uint32(¶m->sctp_local_q,
1276 APP_CHECK(ret != -ESRCH,
1277 "CFG: [%s] entry '%s': unknown entry\n",
1281 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1291 parse_rxq(struct app_params *app,
1292 const char *section_name,
1293 struct rte_cfgfile *cfg)
1295 struct app_pktq_hwq_in_params *param;
1296 struct rte_cfgfile_entry *entries;
1297 int n_entries, ret, i;
1300 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1301 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1303 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1304 PARSE_ERROR_MALLOC(entries != NULL);
1306 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1308 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1309 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1311 param = &app->hwq_in_params[param_idx];
1314 for (i = 0; i < n_entries; i++) {
1315 struct rte_cfgfile_entry *ent = &entries[i];
1318 if (strcmp(ent->name, "mempool") == 0) {
1319 int status = validate_name(ent->value, "MEMPOOL", 1);
1322 APP_CHECK((status == 0),
1323 "CFG: [%s] entry '%s': invalid mempool\n",
1327 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1328 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1329 param->mempool_id = idx;
1331 } else if (strcmp(ent->name, "size") == 0)
1332 ret = parser_read_uint32(¶m->size,
1334 else if (strcmp(ent->name, "burst") == 0)
1335 ret = parser_read_uint32(¶m->burst,
1338 APP_CHECK(ret != -ESRCH,
1339 "CFG: [%s] entry '%s': unknown entry\n",
1343 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1353 parse_txq(struct app_params *app,
1354 const char *section_name,
1355 struct rte_cfgfile *cfg)
1357 struct app_pktq_hwq_out_params *param;
1358 struct rte_cfgfile_entry *entries;
1359 int n_entries, ret, i;
1362 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1363 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1365 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1366 PARSE_ERROR_MALLOC(entries != NULL);
1368 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1370 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1371 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1373 param = &app->hwq_out_params[param_idx];
1376 for (i = 0; i < n_entries; i++) {
1377 struct rte_cfgfile_entry *ent = &entries[i];
1380 if (strcmp(ent->name, "size") == 0)
1381 ret = parser_read_uint32(¶m->size, ent->value);
1382 else if (strcmp(ent->name, "burst") == 0)
1383 ret = parser_read_uint32(¶m->burst, ent->value);
1384 else if (strcmp(ent->name, "dropless") == 0) {
1385 ret = parser_read_arg_bool(ent->value);
1387 param->dropless = ret;
1392 APP_CHECK(ret != -ESRCH,
1393 "CFG: [%s] entry '%s': unknown entry\n",
1397 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1407 parse_swq(struct app_params *app,
1408 const char *section_name,
1409 struct rte_cfgfile *cfg)
1411 struct app_pktq_swq_params *param;
1412 struct rte_cfgfile_entry *entries;
1413 int n_entries, ret, i;
1414 unsigned frag_entries = 0;
1417 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1418 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1420 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1421 PARSE_ERROR_MALLOC(entries != NULL);
1423 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1425 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1426 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1428 param = &app->swq_params[param_idx];
1431 for (i = 0; i < n_entries; i++) {
1432 struct rte_cfgfile_entry *ent = &entries[i];
1435 if (strcmp(ent->name, "size") == 0)
1436 ret = parser_read_uint32(¶m->size,
1438 else if (strcmp(ent->name, "burst_read") == 0)
1439 ret = parser_read_uint32(¶m->burst_read,
1441 else if (strcmp(ent->name, "burst_write") == 0)
1442 ret = parser_read_uint32(¶m->burst_write,
1444 else if (strcmp(ent->name, "dropless") == 0) {
1445 ret = parser_read_arg_bool(ent->value);
1447 param->dropless = ret;
1450 } else if (strcmp(ent->name, "n_retries") == 0)
1451 ret = parser_read_uint64(¶m->n_retries,
1453 else if (strcmp(ent->name, "cpu") == 0)
1454 ret = parser_read_uint32(¶m->cpu_socket_id,
1456 else if (strcmp(ent->name, "ipv4_frag") == 0) {
1457 ret = parser_read_arg_bool(ent->value);
1459 param->ipv4_frag = ret;
1460 if (param->mtu == 0)
1464 } else if (strcmp(ent->name, "ipv6_frag") == 0) {
1465 ret = parser_read_arg_bool(ent->value);
1467 param->ipv6_frag = ret;
1468 if (param->mtu == 0)
1472 } else if (strcmp(ent->name, "ipv4_ras") == 0) {
1473 ret = parser_read_arg_bool(ent->value);
1475 param->ipv4_ras = ret;
1478 } else if (strcmp(ent->name, "ipv6_ras") == 0) {
1479 ret = parser_read_arg_bool(ent->value);
1481 param->ipv6_ras = ret;
1484 } else if (strcmp(ent->name, "mtu") == 0) {
1486 ret = parser_read_uint32(¶m->mtu,
1488 } else if (strcmp(ent->name, "metadata_size") == 0) {
1490 ret = parser_read_uint32(¶m->metadata_size,
1492 } else if (strcmp(ent->name, "mempool_direct") == 0) {
1493 int status = validate_name(ent->value, "MEMPOOL", 1);
1496 APP_CHECK((status == 0),
1497 "CFG: [%s] entry '%s': invalid mempool\n",
1501 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1502 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1503 param->mempool_direct_id = idx;
1506 } else if (strcmp(ent->name, "mempool_indirect") == 0) {
1507 int status = validate_name(ent->value, "MEMPOOL", 1);
1510 APP_CHECK((status == 0),
1511 "CFG: [%s] entry '%s': invalid mempool\n",
1515 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1516 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1517 param->mempool_indirect_id = idx;
1522 APP_CHECK(ret != -ESRCH,
1523 "CFG: [%s] entry '%s': unknown entry\n",
1527 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1533 if (frag_entries == 1) {
1534 APP_CHECK(((param->ipv4_frag == 1) || (param->ipv6_frag == 1)),
1535 "CFG: [%s] ipv4/ipv6 frag is off : unsupported entries on this"
1544 parse_tm(struct app_params *app,
1545 const char *section_name,
1546 struct rte_cfgfile *cfg)
1548 struct app_pktq_tm_params *param;
1549 struct rte_cfgfile_entry *entries;
1550 int n_entries, ret, i;
1553 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1554 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1556 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1557 PARSE_ERROR_MALLOC(entries != NULL);
1559 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1561 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1562 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
1564 param = &app->tm_params[param_idx];
1567 for (i = 0; i < n_entries; i++) {
1568 struct rte_cfgfile_entry *ent = &entries[i];
1571 if (strcmp(ent->name, "cfg") == 0) {
1572 param->file_name = strdup(ent->value);
1573 if (param->file_name == NULL)
1577 } else if (strcmp(ent->name, "burst_read") == 0)
1578 ret = parser_read_uint32(¶m->burst_read,
1580 else if (strcmp(ent->name, "burst_write") == 0)
1581 ret = parser_read_uint32(¶m->burst_write,
1584 APP_CHECK(ret != -ESRCH,
1585 "CFG: [%s] entry '%s': unknown entry\n",
1588 APP_CHECK(ret != -EBADF,
1589 "CFG: [%s] entry '%s': TM cfg parse error '%s'\n",
1594 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1604 parse_source(struct app_params *app,
1605 const char *section_name,
1606 struct rte_cfgfile *cfg)
1608 struct app_pktq_source_params *param;
1609 struct rte_cfgfile_entry *entries;
1610 int n_entries, ret, i;
1613 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1614 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1616 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1617 PARSE_ERROR_MALLOC(entries != NULL);
1619 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1621 param_idx = APP_PARAM_ADD(app->source_params, section_name);
1622 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
1624 param = &app->source_params[param_idx];
1627 for (i = 0; i < n_entries; i++) {
1628 struct rte_cfgfile_entry *ent = &entries[i];
1631 if (strcmp(ent->name, "mempool") == 0) {
1632 int status = validate_name(ent->value, "MEMPOOL", 1);
1635 APP_CHECK((status == 0),
1636 "CFG: [%s] entry '%s': invalid mempool\n",
1640 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1641 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1642 param->mempool_id = idx;
1644 } else if (strcmp(ent->name, "burst") == 0)
1645 ret = parser_read_uint32(¶m->burst, ent->value);
1647 APP_CHECK(ret != -ESRCH,
1648 "CFG: [%s] entry '%s': unknown entry\n",
1652 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1662 parse_msgq_req_pipeline(struct app_params *app,
1663 const char *section_name,
1664 struct rte_cfgfile *cfg)
1666 struct app_msgq_params *param;
1667 struct rte_cfgfile_entry *entries;
1668 int n_entries, ret, i;
1671 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1672 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1674 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1675 PARSE_ERROR_MALLOC(entries != NULL);
1677 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1679 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1680 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1682 param = &app->msgq_params[param_idx];
1685 for (i = 0; i < n_entries; i++) {
1686 struct rte_cfgfile_entry *ent = &entries[i];
1689 if (strcmp(ent->name, "size") == 0)
1690 ret = parser_read_uint32(¶m->size, ent->value);
1692 APP_CHECK(ret != -ESRCH,
1693 "CFG: [%s] entry '%s': unknown entry\n",
1697 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1707 parse_msgq_rsp_pipeline(struct app_params *app,
1708 const char *section_name,
1709 struct rte_cfgfile *cfg)
1711 struct app_msgq_params *param;
1712 struct rte_cfgfile_entry *entries;
1713 int n_entries, ret, i;
1716 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1717 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1719 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1720 PARSE_ERROR_MALLOC(entries != NULL);
1722 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1724 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1725 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1727 param = &app->msgq_params[param_idx];
1730 for (i = 0; i < n_entries; i++) {
1731 struct rte_cfgfile_entry *ent = &entries[i];
1734 if (strcmp(ent->name, "size") == 0)
1735 ret = parser_read_uint32(¶m->size, ent->value);
1737 APP_CHECK(ret != -ESRCH,
1738 "CFG: [%s] entry '%s': unknown entry\n",
1742 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1752 parse_msgq(struct app_params *app,
1753 const char *section_name,
1754 struct rte_cfgfile *cfg)
1756 struct app_msgq_params *param;
1757 struct rte_cfgfile_entry *entries;
1758 int n_entries, ret, i;
1761 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1762 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1764 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1765 PARSE_ERROR_MALLOC(entries != NULL);
1767 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1769 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1770 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1772 param = &app->msgq_params[param_idx];
1775 for (i = 0; i < n_entries; i++) {
1776 struct rte_cfgfile_entry *ent = &entries[i];
1779 if (strcmp(ent->name, "size") == 0)
1780 ret = parser_read_uint32(¶m->size,
1782 else if (strcmp(ent->name, "cpu") == 0)
1783 ret = parser_read_uint32(¶m->cpu_socket_id,
1786 APP_CHECK(ret != -ESRCH,
1787 "CFG: [%s] entry '%s': unknown entry\n",
1791 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1800 typedef void (*config_section_load)(struct app_params *p,
1801 const char *section_name,
1802 struct rte_cfgfile *cfg);
1804 struct config_section {
1805 const char prefix[CFG_NAME_LEN];
1807 config_section_load load;
1810 static const struct config_section cfg_file_scheme[] = {
1811 {"EAL", 0, parse_eal},
1812 {"PIPELINE", 1, parse_pipeline},
1813 {"MEMPOOL", 1, parse_mempool},
1814 {"LINK", 1, parse_link},
1815 {"RXQ", 2, parse_rxq},
1816 {"TXQ", 2, parse_txq},
1817 {"SWQ", 1, parse_swq},
1818 {"TM", 1, parse_tm},
1819 {"SOURCE", 1, parse_source},
1820 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
1821 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
1822 {"MSGQ", 1, parse_msgq},
1826 create_implicit_mempools(struct app_params *app)
1830 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
1831 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, "start-up");
1835 parse_port_mask(struct app_params *app, uint64_t port_mask)
1837 uint32_t pmd_id, link_id;
1840 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
1841 char name[APP_PARAM_NAME_SIZE];
1844 if ((port_mask & (1LLU << pmd_id)) == 0)
1847 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
1848 idx = APP_PARAM_ADD(app->link_params, name);
1849 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, name);
1851 app->link_params[idx].pmd_id = pmd_id;
1857 app_config_parse(struct app_params *app, const char *file_name)
1859 struct rte_cfgfile *cfg;
1860 char **section_names;
1861 int i, j, sect_count;
1863 /* Implicit mempools */
1864 create_implicit_mempools(app);
1867 parse_port_mask(app, app->port_mask);
1869 /* Load application configuration file */
1870 cfg = rte_cfgfile_load(file_name, 0);
1871 APP_CHECK(cfg != NULL, "Unable to load config file %s", file_name);
1873 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
1874 section_names = malloc(sect_count * sizeof(char *));
1875 for (i = 0; i < sect_count; i++)
1876 section_names[i] = malloc(CFG_NAME_LEN);
1878 rte_cfgfile_sections(cfg, section_names, sect_count);
1880 for (i = 0; i < sect_count; i++) {
1881 const struct config_section *sch_s;
1882 int len, cfg_name_len;
1884 cfg_name_len = strlen(section_names[i]);
1886 /* Find section type */
1887 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
1888 sch_s = &cfg_file_scheme[j];
1889 len = strlen(sch_s->prefix);
1891 if (cfg_name_len < len)
1894 /* After section name we expect only '\0' or digit or
1895 * digit dot digit, so protect against false matching,
1896 * for example: "ABC" should match section name
1897 * "ABC0.0", but it should not match section_name
1900 if ((section_names[i][len] != '\0') &&
1901 !isdigit(section_names[i][len]))
1904 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
1908 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
1909 "Unknown section %s",
1912 APP_CHECK(validate_name(section_names[i],
1914 sch_s->numbers) == 0,
1915 "Invalid section name '%s'",
1918 sch_s->load(app, section_names[i], cfg);
1921 for (i = 0; i < sect_count; i++)
1922 free(section_names[i]);
1924 free(section_names);
1926 rte_cfgfile_close(cfg);
1928 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
1929 APP_PARAM_COUNT(app->link_params, app->n_links);
1930 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
1931 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
1932 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
1933 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
1934 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
1935 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
1936 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
1937 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
1939 /* Save configuration to output file */
1940 app_config_save(app, app->output_file);
1942 /* Load TM configuration files */
1943 app_config_parse_tm(app);
1949 save_eal_params(struct app_params *app, FILE *f)
1951 struct app_eal_params *p = &app->eal_params;
1953 fprintf(f, "[EAL]\n");
1956 fprintf(f, "%s = %s\n", "lcores", p->coremap);
1958 if (p->master_lcore_present)
1959 fprintf(f, "%s = %" PRIu32 "\n",
1960 "master_lcore", p->master_lcore);
1962 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
1964 if (p->memory_present)
1965 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
1967 if (p->ranks_present)
1968 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
1970 if (p->pci_blacklist)
1971 fprintf(f, "%s = %s\n", "pci_blacklist", p->pci_blacklist);
1973 if (p->pci_whitelist)
1974 fprintf(f, "%s = %s\n", "pci_whitelist", p->pci_whitelist);
1977 fprintf(f, "%s = %s\n", "vdev", p->vdev);
1979 if (p->vmware_tsc_map_present)
1980 fprintf(f, "%s = %s\n", "vmware_tsc_map",
1981 (p->vmware_tsc_map) ? "yes" : "no");
1984 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
1987 fprintf(f, "%s = %s\n", "syslog", p->syslog);
1989 if (p->log_level_present)
1990 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
1992 if (p->version_present)
1993 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
1995 if (p->help_present)
1996 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
1998 if (p->no_huge_present)
1999 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
2001 if (p->no_pci_present)
2002 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
2004 if (p->no_hpet_present)
2005 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
2007 if (p->no_shconf_present)
2008 fprintf(f, "%s = %s\n", "no_shconf",
2009 (p->no_shconf) ? "yes" : "no");
2012 fprintf(f, "%s = %s\n", "d", p->add_driver);
2015 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
2018 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
2021 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
2023 if (p->base_virtaddr)
2024 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
2026 if (p->create_uio_dev_present)
2027 fprintf(f, "%s = %s\n", "create_uio_dev",
2028 (p->create_uio_dev) ? "yes" : "no");
2031 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
2033 if (p->xen_dom0_present)
2034 fprintf(f, "%s = %s\n", "xen_dom0",
2035 (p->xen_dom0) ? "yes" : "no");
2041 save_mempool_params(struct app_params *app, FILE *f)
2043 struct app_mempool_params *p;
2046 count = RTE_DIM(app->mempool_params);
2047 for (i = 0; i < count; i++) {
2048 p = &app->mempool_params[i];
2049 if (!APP_PARAM_VALID(p))
2052 fprintf(f, "[%s]\n", p->name);
2053 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
2054 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
2055 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
2056 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2063 save_links_params(struct app_params *app, FILE *f)
2065 struct app_link_params *p;
2068 count = RTE_DIM(app->link_params);
2069 for (i = 0; i < count; i++) {
2070 p = &app->link_params[i];
2071 if (!APP_PARAM_VALID(p))
2074 fprintf(f, "[%s]\n", p->name);
2075 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
2076 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
2077 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_local_q",
2078 p->tcp_syn_local_q);
2079 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
2080 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
2081 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2082 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2090 save_rxq_params(struct app_params *app, FILE *f)
2092 struct app_pktq_hwq_in_params *p;
2095 count = RTE_DIM(app->hwq_in_params);
2096 for (i = 0; i < count; i++) {
2097 p = &app->hwq_in_params[i];
2098 if (!APP_PARAM_VALID(p))
2101 fprintf(f, "[%s]\n", p->name);
2102 fprintf(f, "%s = %s\n",
2104 app->mempool_params[p->mempool_id].name);
2105 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2106 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2113 save_txq_params(struct app_params *app, FILE *f)
2115 struct app_pktq_hwq_out_params *p;
2118 count = RTE_DIM(app->hwq_out_params);
2119 for (i = 0; i < count; i++) {
2120 p = &app->hwq_out_params[i];
2121 if (!APP_PARAM_VALID(p))
2124 fprintf(f, "[%s]\n", p->name);
2125 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2126 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2127 fprintf(f, "%s = %s\n",
2129 p->dropless ? "yes" : "no");
2136 save_swq_params(struct app_params *app, FILE *f)
2138 struct app_pktq_swq_params *p;
2141 count = RTE_DIM(app->swq_params);
2142 for (i = 0; i < count; i++) {
2143 p = &app->swq_params[i];
2144 if (!APP_PARAM_VALID(p))
2147 fprintf(f, "[%s]\n", p->name);
2148 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2149 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2150 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2151 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2152 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2153 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2154 fprintf(f, "%s = %s\n", "ipv4_frag", p->ipv4_frag ? "yes" : "no");
2155 fprintf(f, "%s = %s\n", "ipv6_frag", p->ipv6_frag ? "yes" : "no");
2156 fprintf(f, "%s = %s\n", "ipv4_ras", p->ipv4_ras ? "yes" : "no");
2157 fprintf(f, "%s = %s\n", "ipv6_ras", p->ipv6_ras ? "yes" : "no");
2158 if ((p->ipv4_frag == 1) || (p->ipv6_frag == 1)) {
2159 fprintf(f, "%s = %" PRIu32 "\n", "mtu", p->mtu);
2160 fprintf(f, "%s = %" PRIu32 "\n", "metadata_size", p->metadata_size);
2161 fprintf(f, "%s = %s\n",
2163 app->mempool_params[p->mempool_direct_id].name);
2164 fprintf(f, "%s = %s\n",
2166 app->mempool_params[p->mempool_indirect_id].name);
2174 save_tm_params(struct app_params *app, FILE *f)
2176 struct app_pktq_tm_params *p;
2179 count = RTE_DIM(app->tm_params);
2180 for (i = 0; i < count; i++) {
2181 p = &app->tm_params[i];
2182 if (!APP_PARAM_VALID(p))
2185 fprintf(f, "[%s]\n", p->name);
2186 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2187 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2188 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2195 save_source_params(struct app_params *app, FILE *f)
2197 struct app_pktq_source_params *p;
2200 count = RTE_DIM(app->source_params);
2201 for (i = 0; i < count; i++) {
2202 p = &app->source_params[i];
2203 if (!APP_PARAM_VALID(p))
2206 fprintf(f, "[%s]\n", p->name);
2207 fprintf(f, "%s = %s\n",
2209 app->mempool_params[p->mempool_id].name);
2210 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2216 save_msgq_params(struct app_params *app, FILE *f)
2218 struct app_msgq_params *p;
2221 count = RTE_DIM(app->msgq_params);
2222 for (i = 0; i < count; i++) {
2223 p = &app->msgq_params[i];
2224 if (!APP_PARAM_VALID(p))
2227 fprintf(f, "[%s]\n", p->name);
2228 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2229 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2236 save_pipeline_params(struct app_params *app, FILE *f)
2240 count = RTE_DIM(app->pipeline_params);
2241 for (i = 0; i < count; i++) {
2242 struct app_pipeline_params *p = &app->pipeline_params[i];
2244 if (!APP_PARAM_VALID(p))
2248 fprintf(f, "[%s]\n", p->name);
2251 fprintf(f, "type = %s\n", p->type);
2254 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2257 (p->hyper_th_id) ? "h" : "");
2263 fprintf(f, "pktq_in =");
2264 for (j = 0; j < p->n_pktq_in; j++) {
2265 struct app_pktq_in_params *pp = &p->pktq_in[j];
2269 case APP_PKTQ_IN_HWQ:
2270 name = app->hwq_in_params[pp->id].name;
2272 case APP_PKTQ_IN_SWQ:
2273 name = app->swq_params[pp->id].name;
2275 case APP_PKTQ_IN_TM:
2276 name = app->tm_params[pp->id].name;
2278 case APP_PKTQ_IN_SOURCE:
2279 name = app->source_params[pp->id].name;
2282 APP_CHECK(0, "Error\n");
2285 fprintf(f, " %s", name);
2291 if (p->n_pktq_out) {
2294 fprintf(f, "pktq_out =");
2295 for (j = 0; j < p->n_pktq_out; j++) {
2296 struct app_pktq_out_params *pp =
2301 case APP_PKTQ_OUT_HWQ:
2302 name = app->hwq_out_params[pp->id].name;
2304 case APP_PKTQ_OUT_SWQ:
2305 name = app->swq_params[pp->id].name;
2307 case APP_PKTQ_OUT_TM:
2308 name = app->tm_params[pp->id].name;
2310 case APP_PKTQ_OUT_SINK:
2311 name = app->sink_params[pp->id].name;
2314 APP_CHECK(0, "Error\n");
2317 fprintf(f, " %s", name);
2326 fprintf(f, "msgq_in =");
2327 for (j = 0; j < p->n_msgq_in; j++) {
2328 uint32_t id = p->msgq_in[j];
2329 char *name = app->msgq_params[id].name;
2331 fprintf(f, " %s", name);
2340 fprintf(f, "msgq_out =");
2341 for (j = 0; j < p->n_msgq_out; j++) {
2342 uint32_t id = p->msgq_out[j];
2343 char *name = app->msgq_params[id].name;
2345 fprintf(f, " %s", name);
2351 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2357 for (j = 0; j < p->n_args; j++)
2358 fprintf(f, "%s = %s\n", p->args_name[j],
2367 app_config_save(struct app_params *app, const char *file_name)
2370 char *name, *dir_name;
2373 name = strdup(file_name);
2374 dir_name = dirname(name);
2375 status = access(dir_name, W_OK);
2376 APP_CHECK((status == 0),
2377 "Need write access to directory \"%s\" to save configuration\n",
2380 file = fopen(file_name, "w");
2381 APP_CHECK((file != NULL),
2382 "Failed to save configuration to file \"%s\"", file_name);
2384 save_eal_params(app, file);
2385 save_pipeline_params(app, file);
2386 save_mempool_params(app, file);
2387 save_links_params(app, file);
2388 save_rxq_params(app, file);
2389 save_txq_params(app, file);
2390 save_swq_params(app, file);
2391 save_tm_params(app, file);
2392 save_source_params(app, file);
2393 save_msgq_params(app, file);
2400 app_config_init(struct app_params *app)
2404 memcpy(app, &app_params_default, sizeof(struct app_params));
2406 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2407 memcpy(&app->mempool_params[i],
2408 &mempool_params_default,
2409 sizeof(struct app_mempool_params));
2411 for (i = 0; i < RTE_DIM(app->link_params); i++)
2412 memcpy(&app->link_params[i],
2413 &link_params_default,
2414 sizeof(struct app_link_params));
2416 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2417 memcpy(&app->hwq_in_params[i],
2418 &default_hwq_in_params,
2419 sizeof(default_hwq_in_params));
2421 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2422 memcpy(&app->hwq_out_params[i],
2423 &default_hwq_out_params,
2424 sizeof(default_hwq_out_params));
2426 for (i = 0; i < RTE_DIM(app->swq_params); i++)
2427 memcpy(&app->swq_params[i],
2428 &default_swq_params,
2429 sizeof(default_swq_params));
2431 for (i = 0; i < RTE_DIM(app->tm_params); i++)
2432 memcpy(&app->tm_params[i],
2434 sizeof(default_tm_params));
2436 for (i = 0; i < RTE_DIM(app->source_params); i++)
2437 memcpy(&app->source_params[i],
2438 &default_source_params,
2439 sizeof(default_source_params));
2441 for (i = 0; i < RTE_DIM(app->sink_params); i++)
2442 memcpy(&app->sink_params[i],
2443 &default_sink_params,
2444 sizeof(default_sink_params));
2446 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2447 memcpy(&app->msgq_params[i],
2448 &default_msgq_params,
2449 sizeof(default_msgq_params));
2451 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2452 memcpy(&app->pipeline_params[i],
2453 &default_pipeline_params,
2454 sizeof(default_pipeline_params));
2460 filenamedup(const char *filename, const char *suffix)
2462 char *s = malloc(strlen(filename) + strlen(suffix) + 1);
2467 sprintf(s, "%s%s", filename, suffix);
2472 app_config_args(struct app_params *app, int argc, char **argv)
2474 const char *optname;
2475 int opt, option_index;
2476 int f_present, s_present, p_present, l_present;
2477 int preproc_present, preproc_params_present;
2480 static struct option lgopts[] = {
2481 { "preproc", 1, 0, 0 },
2482 { "preproc-args", 1, 0, 0 },
2486 /* Copy application name */
2487 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
2493 preproc_present = 0;
2494 preproc_params_present = 0;
2496 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
2497 &option_index)) != EOF)
2501 rte_panic("Error: Config file is provided "
2502 "more than once\n");
2505 if (!strlen(optarg))
2506 rte_panic("Error: Config file name is null\n");
2508 app->config_file = strdup(optarg);
2509 if (app->config_file == NULL)
2510 rte_panic("Error: Memory allocation failure\n");
2516 rte_panic("Error: Script file is provided "
2517 "more than once\n");
2520 if (!strlen(optarg))
2521 rte_panic("Error: Script file name is null\n");
2523 app->script_file = strdup(optarg);
2524 if (app->script_file == NULL)
2525 rte_panic("Error: Memory allocation failure\n");
2531 rte_panic("Error: PORT_MASK is provided "
2532 "more than once\n");
2535 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
2537 ((size_t) scaned != strlen(optarg)))
2538 rte_panic("Error: PORT_MASK is not "
2539 "a hexadecimal integer\n");
2541 if (app->port_mask == 0)
2542 rte_panic("Error: PORT_MASK is null\n");
2548 rte_panic("Error: LOG_LEVEL is provided "
2549 "more than once\n");
2552 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
2554 ((size_t) scaned != strlen(optarg)) ||
2555 (app->log_level >= APP_LOG_LEVELS))
2556 rte_panic("Error: LOG_LEVEL invalid value\n");
2561 optname = lgopts[option_index].name;
2563 if (strcmp(optname, "preproc") == 0) {
2564 if (preproc_present)
2565 rte_panic("Error: Preprocessor argument "
2566 "is provided more than once\n");
2567 preproc_present = 1;
2569 app->preproc = strdup(optarg);
2573 if (strcmp(optname, "preproc-args") == 0) {
2574 if (preproc_params_present)
2575 rte_panic("Error: Preprocessor args "
2576 "are provided more than once\n");
2577 preproc_params_present = 1;
2579 app->preproc_args = strdup(optarg);
2583 app_print_usage(argv[0]);
2587 app_print_usage(argv[0]);
2590 optind = 0; /* reset getopt lib */
2592 /* Check that mandatory args have been provided */
2594 rte_panic("Error: PORT_MASK is not provided\n");
2596 /* Check dependencies between args */
2597 if (preproc_params_present && (preproc_present == 0))
2598 rte_panic("Error: Preprocessor args specified while "
2599 "preprocessor is not defined\n");
2601 app->parser_file = preproc_present ?
2602 filenamedup(app->config_file, ".preproc") :
2603 strdup(app->config_file);
2604 app->output_file = filenamedup(app->config_file, ".out");
2610 app_config_preproc(struct app_params *app)
2615 if (app->preproc == NULL)
2618 status = access(app->config_file, F_OK | R_OK);
2619 APP_CHECK((status == 0), "Unable to open file %s", app->config_file);
2621 snprintf(buffer, sizeof(buffer), "%s %s %s > %s",
2623 app->preproc_args ? app->preproc_args : "",
2627 status = system(buffer);
2628 APP_CHECK((WIFEXITED(status) && (WEXITSTATUS(status) == 0)),
2629 "Error while preprocessing file \"%s\"\n", app->config_file);