This patch updates the pipelne configuration file parser, cleans up nesting
if/else conditions, and add clearer error message display.

Signed-off-by: Fan Zhang <roy.fan.zhang at intel.com>
---
 examples/ip_pipeline/config_parse.c | 798 ++++++++++++++++++++----------------
 examples/ip_pipeline/pipeline_be.h  |  48 +++
 2 files changed, 494 insertions(+), 352 deletions(-)

diff --git a/examples/ip_pipeline/config_parse.c 
b/examples/ip_pipeline/config_parse.c
index 1bedbe4..6575e31 100644
--- a/examples/ip_pipeline/config_parse.c
+++ b/examples/ip_pipeline/config_parse.c
@@ -291,34 +291,7 @@ parser_read_arg_bool(const char *p)
        return result;
 }

-#define PARSE_ERROR(exp, section, entry)                               \
-APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
-
-#define PARSE_ERROR_MALLOC(exp)                                                
\
-APP_CHECK(exp, "Parse error: no free memory\n")
-
-#define PARSE_ERROR_SECTION(exp, section)                              \
-APP_CHECK(exp, "Parse error in section \"%s\"", section)
-
-#define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section)                   \
-APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
-
-#define PARSE_WARNING_IGNORED(exp, section, entry)                     \
-do                                                                     \
-if (!(exp))                                                            \
-       fprintf(stderr, "Parse warning in section \"%s\": "             \
-               "entry \"%s\" is ignored\n", section, entry);           \
-while (0)
-
-#define PARSE_ERROR_INVALID(exp, section, entry)                       \
-APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
-       section, entry)
-
-#define PARSE_ERROR_DUPLICATE(exp, section, entry)                     \
-APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
-       section, entry)
-
-static int
+int
 parser_read_uint64(uint64_t *value, const char *p)
 {
        char *next;
@@ -358,7 +331,7 @@ parser_read_uint64(uint64_t *value, const char *p)
        return 0;
 }

-static int
+int
 parser_read_uint32(uint32_t *value, const char *p)
 {
        uint64_t val = 0;
@@ -935,6 +908,7 @@ parse_pipeline_pktq_in(struct app_params *app,

        while (*next != '\0') {
                enum app_pktq_in_type type;
+               int name_validated = 0;
                int id;

                end = strchr(next, ' ');
@@ -955,24 +929,41 @@ parse_pipeline_pktq_in(struct app_params *app,
                if (validate_name(name, "RXQ", 2) == 0) {
                        type = APP_PKTQ_IN_HWQ;
                        id = APP_PARAM_ADD(app->hwq_in_params, name);
-               } else if (validate_name(name, "SWQ", 1) == 0) {
+                       if (id < 0)
+                               return id;
+                       name_validated = 1;
+               }
+
+               if (validate_name(name, "SWQ", 1) == 0) {
                        type = APP_PKTQ_IN_SWQ;
                        id = APP_PARAM_ADD(app->swq_params, name);
-               } else if (validate_name(name, "TM", 1) == 0) {
+                       if (id < 0)
+                               return id;
+                       name_validated = 1;
+               }
+
+               if (validate_name(name, "TM", 1) == 0) {
                        type = APP_PKTQ_IN_TM;
                        id = APP_PARAM_ADD(app->tm_params, name);
-               } else if (validate_name(name, "SOURCE", 1) == 0) {
+                       if (id < 0)
+                               return id;
+                       name_validated = 1;
+               }
+
+               if (validate_name(name, "SOURCE", 1) == 0) {
                        type = APP_PKTQ_IN_SOURCE;
                        id = APP_PARAM_ADD(app->source_params, name);
+                       if (id < 0)
+                               return id;
+                       name_validated = 1;
+               }
+
+               if (name_validated == 1) {
+                       p->pktq_in[p->n_pktq_in].type = type;
+                       p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
+                       p->n_pktq_in++;
                } else
                        return -EINVAL;
-
-               if (id < 0)
-                       return id;
-
-               p->pktq_in[p->n_pktq_in].type = type;
-               p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
-               p->n_pktq_in++;
        }

        return 0;
@@ -990,6 +981,7 @@ parse_pipeline_pktq_out(struct app_params *app,

        while (*next != '\0') {
                enum app_pktq_out_type type;
+               int name_validated = 0;
                int id;

                end = strchr(next, ' ');
@@ -1010,24 +1002,41 @@ parse_pipeline_pktq_out(struct app_params *app,
                if (validate_name(name, "TXQ", 2) == 0) {
                        type = APP_PKTQ_OUT_HWQ;
                        id = APP_PARAM_ADD(app->hwq_out_params, name);
-               } else if (validate_name(name, "SWQ", 1) == 0) {
+                       if (id < 0)
+                               return id;
+                       name_validated = 1;
+               }
+
+               if (validate_name(name, "SWQ", 1) == 0) {
                        type = APP_PKTQ_OUT_SWQ;
                        id = APP_PARAM_ADD(app->swq_params, name);
-               } else if (validate_name(name, "TM", 1) == 0) {
+                       if (id < 0)
+                               return id;
+                       name_validated = 1;
+               }
+
+               if (validate_name(name, "TM", 1) == 0) {
                        type = APP_PKTQ_OUT_TM;
                        id = APP_PARAM_ADD(app->tm_params, name);
-               } else if (validate_name(name, "SINK", 1) == 0) {
+                       if (id < 0)
+                               return id;
+                       name_validated = 1;
+               }
+
+               if (validate_name(name, "SINK", 1) == 0) {
                        type = APP_PKTQ_OUT_SINK;
                        id = APP_PARAM_ADD(app->sink_params, name);
+                       if (id < 0)
+                               return id;
+                       name_validated = 1;
+               }
+
+               if (name_validated == 1) {
+                       p->pktq_out[p->n_pktq_out].type = type;
+                       p->pktq_out[p->n_pktq_out].id = id;
+                       p->n_pktq_out++;
                } else
                        return -EINVAL;
-
-               if (id < 0)
-                       return id;
-
-               p->pktq_out[p->n_pktq_out].type = type;
-               p->pktq_out[p->n_pktq_out].id = id;
-               p->n_pktq_out++;
        }

        return 0;
@@ -1125,7 +1134,7 @@ parse_pipeline(struct app_params *app,
        struct app_pipeline_params *param;
        struct rte_cfgfile_entry *entries;
        ssize_t param_idx;
-       int n_entries, ret, i;
+       int n_entries, i;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
        PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
@@ -1139,60 +1148,88 @@ parse_pipeline(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);

        param = &app->pipeline_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

                if (strcmp(ent->name, "type") == 0) {
-                       ret = snprintf(param->type,
-                               RTE_DIM(param->type),
-                               "%s",
-                               ent->value);
-                       if ((ret > 0) && (ret < (int)RTE_DIM(param->type)))
-                               ret = 0;
-                       else
-                               ret = -EINVAL;
-               } else if (strcmp(ent->name, "core") == 0)
-                       ret = parse_pipeline_core(&param->socket_id,
-                               &param->core_id,
-                               &param->hyper_th_id,
+                       int w_size = snprintf(param->type, RTE_DIM(param->type),
+                                       "%s", ent->value);
+
+                       PARSE_ERROR(((w_size > 0) &&
+                                       (w_size < (int)RTE_DIM(param->type))),
+                                       section_name,
+                                       ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "core") == 0) {
+                       int status = parse_pipeline_core(&param->socket_id,
+                               &param->core_id, &param->hyper_th_id,
                                ent->value);
-               else if (strcmp(ent->name, "pktq_in") == 0)
-                       ret = parse_pipeline_pktq_in(app, param, ent->value);
-               else if (strcmp(ent->name, "pktq_out") == 0)
-                       ret = parse_pipeline_pktq_out(app, param, ent->value);
-               else if (strcmp(ent->name, "msgq_in") == 0)
-                       ret = parse_pipeline_msgq_in(app, param, ent->value);
-               else if (strcmp(ent->name, "msgq_out") == 0)
-                       ret = parse_pipeline_msgq_out(app, param, ent->value);
-               else if (strcmp(ent->name, "timer_period") == 0)
-                       ret = parser_read_uint32(&param->timer_period,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "pktq_in") == 0) {
+                       int status = parse_pipeline_pktq_in(app,
+                               param, ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "pktq_out") == 0) {
+                       int status = parse_pipeline_pktq_out(app,
+                               param, ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "msgq_in") == 0) {
+                       int status = parse_pipeline_msgq_in(app,
+                               param, ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "msgq_out") == 0) {
+                       int status = parse_pipeline_msgq_out(app,
+                               param, ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "timer_period") == 0) {
+                       int status = parser_read_uint32(&param->timer_period,
                                ent->value);
-               else {
-                       APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               /* pipeline type specific items */
+               APP_CHECK((param->n_args < APP_MAX_PIPELINE_ARGS),
                                "CFG: [%s] out of memory",
                                section_name);

-                       param->args_name[param->n_args] = strdup(ent->name);
-                       param->args_value[param->n_args] = strdup(ent->value);
+               param->args_name[param->n_args] = strdup(ent->name);
+               param->args_value[param->n_args] = strdup(ent->value);

-                       APP_CHECK((param->args_name[param->n_args] != NULL) &&
+               APP_CHECK((param->args_name[param->n_args] != NULL) &&
                                (param->args_value[param->n_args] != NULL),
                                "CFG: [%s] out of memory",
                                section_name);

-                       param->n_args++;
-                       ret = 0;
-               }
-
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+               param->n_args++;
        }

+       param->parsed = 1;
+
        snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
        param_idx = APP_PARAM_ADD(app->msgq_params, name);
        PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
@@ -1232,7 +1269,7 @@ parse_mempool(struct app_params *app,
        struct app_mempool_params *param;
        struct rte_cfgfile_entry *entries;
        ssize_t param_idx;
-       int n_entries, ret, i;
+       int n_entries, i;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
        PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
@@ -1246,36 +1283,44 @@ parse_mempool(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);

        param = &app->mempool_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
-               if (strcmp(ent->name, "buffer_size") == 0)
-                       ret = parser_read_uint32(&param->buffer_size,
-                               ent->value);
-               else if (strcmp(ent->name, "pool_size") == 0)
-                       ret = parser_read_uint32(&param->pool_size,
+               if (strcmp(ent->name, "buffer_size") == 0) {
+                       int status = parser_read_uint32(&param->buffer_size,
+                                       ent->value);
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "pool_size") == 0) {
+                       int status = parser_read_uint32(&param->pool_size,
                                ent->value);
-               else if (strcmp(ent->name, "cache_size") == 0)
-                       ret = parser_read_uint32(&param->cache_size,
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "cache_size") == 0) {
+                       int status = parser_read_uint32(&param->cache_size,
                                ent->value);
-               else if (strcmp(ent->name, "cpu") == 0)
-                       ret = parser_read_uint32(&param->cpu_socket_id,
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "cpu") == 0) {
+                       int status = parser_read_uint32(&param->cpu_socket_id,
                                ent->value);
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }

-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

@@ -1286,7 +1331,7 @@ parse_link(struct app_params *app,
 {
        struct app_link_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        ssize_t param_idx;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
@@ -1301,48 +1346,73 @@ parse_link(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);

        param = &app->link_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
                if (strcmp(ent->name, "promisc") == 0) {
-                       ret = parser_read_arg_bool(ent->value);
-                       if (ret >= 0) {
-                               param->promisc = ret;
-                               ret = 0;
-                       }
-               } else if (strcmp(ent->name, "arp_q") == 0)
-                       ret = parser_read_uint32(&param->arp_q,
+                       int status = parser_read_arg_bool(ent->value);
+
+                       PARSE_ERROR((status >= 0), section_name, ent->name);
+                       param->promisc = status;
+                       continue;
+               }
+
+               if (strcmp(ent->name, "arp_q") == 0) {
+                       int status = parser_read_uint32(&param->arp_q,
                                ent->value);
-               else if (strcmp(ent->name, "tcp_syn_q") == 0)
-                       ret = parser_read_uint32(&param->tcp_syn_local_q,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "tcp_syn_q") == 0) {
+                       int status = parser_read_uint32(&param->tcp_syn_local_q,
                                ent->value);
-               else if (strcmp(ent->name, "ip_local_q") == 0)
-                       ret = parser_read_uint32(&param->ip_local_q,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "ip_local_q") == 0) {
+                       int status = parser_read_uint32(&param->ip_local_q,
                                ent->value);
-               else if (strcmp(ent->name, "tcp_local_q") == 0)
-                       ret = parser_read_uint32(&param->tcp_local_q,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+
+               if (strcmp(ent->name, "tcp_local_q") == 0) {
+                       int status = parser_read_uint32(&param->tcp_local_q,
                                ent->value);
-               else if (strcmp(ent->name, "udp_local_q") == 0)
-                       ret = parser_read_uint32(&param->udp_local_q,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "udp_local_q") == 0) {
+                       int status = parser_read_uint32(&param->udp_local_q,
                                ent->value);
-               else if (strcmp(ent->name, "sctp_local_q") == 0)
-                       ret = parser_read_uint32(&param->sctp_local_q,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "sctp_local_q") == 0) {
+                       int status = parser_read_uint32(&param->sctp_local_q,
                                ent->value);

-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

@@ -1353,7 +1423,7 @@ parse_rxq(struct app_params *app,
 {
        struct app_pktq_hwq_in_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        ssize_t param_idx;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
@@ -1368,43 +1438,40 @@ parse_rxq(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);

        param = &app->hwq_in_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
                if (strcmp(ent->name, "mempool") == 0) {
                        int status = validate_name(ent->value, "MEMPOOL", 1);
                        ssize_t idx;
-
-                       APP_CHECK((status == 0),
-                               "CFG: [%s] entry '%s': invalid mempool\n",
-                               section_name,
-                               ent->name);
-
+                       PARSE_ERROR((status == 0), section_name, ent->name);
                        idx = APP_PARAM_ADD(app->mempool_params, ent->value);
                        PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
                        param->mempool_id = idx;
-                       ret = 0;
-               } else if (strcmp(ent->name, "size") == 0)
-                       ret = parser_read_uint32(&param->size,
+                       continue;
+               }
+
+               if (strcmp(ent->name, "size") == 0) {
+                       int status = parser_read_uint32(&param->size,
                                ent->value);
-               else if (strcmp(ent->name, "burst") == 0)
-                       ret = parser_read_uint32(&param->burst,
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "burst") == 0) {
+                       int status = parser_read_uint32(&param->burst,
                                ent->value);
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }

-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

@@ -1415,7 +1482,7 @@ parse_txq(struct app_params *app,
 {
        struct app_pktq_hwq_out_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        ssize_t param_idx;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
@@ -1430,35 +1497,40 @@ parse_txq(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);

        param = &app->hwq_out_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
-               if (strcmp(ent->name, "size") == 0)
-                       ret = parser_read_uint32(&param->size, ent->value);
-               else if (strcmp(ent->name, "burst") == 0)
-                       ret = parser_read_uint32(&param->burst, ent->value);
-               else if (strcmp(ent->name, "dropless") == 0) {
-                       ret = parser_read_arg_bool(ent->value);
-                       if (ret >= 0) {
-                               param->dropless = ret;
-                               ret = 0;
-                       }
+               if (strcmp(ent->name, "size") == 0) {
+                       int status = parser_read_uint32(&param->size,
+                               ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
                }

-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+               if (strcmp(ent->name, "burst") == 0) {
+                       int status = parser_read_uint32(&param->burst,
+                               ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "dropless") == 0) {
+                       int status = parser_read_arg_bool(ent->value);
+
+                       PARSE_ERROR((status >= 0), section_name, ent->name);
+                       param->dropless = status;
+                       continue;
+               }
+
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

@@ -1469,7 +1541,7 @@ parse_swq(struct app_params *app,
 {
        struct app_pktq_swq_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        unsigned frag_entries = 0;
        ssize_t param_idx;

@@ -1485,108 +1557,138 @@ parse_swq(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);

        param = &app->swq_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
-               if (strcmp(ent->name, "size") == 0)
-                       ret = parser_read_uint32(&param->size,
+               if (strcmp(ent->name, "size") == 0) {
+                       int status = parser_read_uint32(&param->size,
                                ent->value);
-               else if (strcmp(ent->name, "burst_read") == 0)
-                       ret = parser_read_uint32(&param->burst_read,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "burst_read") == 0) {
+                       int status = parser_read_uint32(&param->burst_read,
                                ent->value);
-               else if (strcmp(ent->name, "burst_write") == 0)
-                       ret = parser_read_uint32(&param->burst_write,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "burst_write") == 0) {
+                       int status = parser_read_uint32(&param->burst_write,
                                ent->value);
-               else if (strcmp(ent->name, "dropless") == 0) {
-                       ret = parser_read_arg_bool(ent->value);
-                       if (ret >= 0) {
-                               param->dropless = ret;
-                               ret = 0;
-                       }
-               } else if (strcmp(ent->name, "n_retries") == 0)
-                       ret = parser_read_uint64(&param->n_retries,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "dropless") == 0) {
+                       int status = parser_read_arg_bool(ent->value);
+
+                       PARSE_ERROR((status >= 0), section_name, ent->name);
+                       param->dropless = status;
+                       continue;
+               }
+
+               if (strcmp(ent->name, "n_retries") == 0) {
+                       int status = parser_read_uint64(&param->n_retries,
                                ent->value);
-               else if (strcmp(ent->name, "cpu") == 0)
-                       ret = parser_read_uint32(&param->cpu_socket_id,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "cpu") == 0) {
+                       int status = parser_read_uint32(&param->cpu_socket_id,
                                ent->value);
-               else if (strcmp(ent->name, "ipv4_frag") == 0) {
-                       ret = parser_read_arg_bool(ent->value);
-                       if (ret >= 0) {
-                               param->ipv4_frag = ret;
-                               if (param->mtu == 0)
-                                       param->mtu = 1500;
-                               ret = 0;
-                       }
-               } else if (strcmp(ent->name, "ipv6_frag") == 0) {
-                       ret = parser_read_arg_bool(ent->value);
-                       if (ret >= 0) {
-                               param->ipv6_frag = ret;
-                               if (param->mtu == 0)
-                                       param->mtu = 1320;
-                               ret = 0;
-                       }
-               } else if (strcmp(ent->name, "ipv4_ras") == 0) {
-                       ret = parser_read_arg_bool(ent->value);
-                       if (ret >= 0) {
-                               param->ipv4_ras = ret;
-                               ret = 0;
-                       }
-               } else if (strcmp(ent->name, "ipv6_ras") == 0) {
-                       ret = parser_read_arg_bool(ent->value);
-                       if (ret >= 0) {
-                               param->ipv6_ras = ret;
-                               ret = 0;
-                       }
-               } else if (strcmp(ent->name, "mtu") == 0) {
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "ipv4_frag") == 0) {
+                       int status = parser_read_arg_bool(ent->value);
+
+                       PARSE_ERROR((status >= 0), section_name, ent->name);
+                       param->ipv4_frag = status;
+                       if (param->mtu == 0)
+                               param->mtu = 1500;
+                       continue;
+               }
+
+               if (strcmp(ent->name, "ipv6_frag") == 0) {
+                       int status = parser_read_arg_bool(ent->value);
+
+                       PARSE_ERROR((status >= 0), section_name, ent->name);
+                       param->ipv6_frag = status;
+                       if (param->mtu == 0)
+                               param->mtu = 1320;
+                       continue;
+               }
+
+               if (strcmp(ent->name, "ipv4_ras") == 0) {
+                       int status = parser_read_arg_bool(ent->value);
+
+                       PARSE_ERROR((status >= 0), section_name, ent->name);
+                       param->ipv4_ras = status;
+                       continue;
+               }
+
+               if (strcmp(ent->name, "ipv6_ras") == 0) {
+                       int status = parser_read_arg_bool(ent->value);
+
+                       PARSE_ERROR((status >= 0), section_name, ent->name);
+                       param->ipv6_ras = status;
+                       continue;
+               }
+
+               if (strcmp(ent->name, "mtu") == 0) {
+                       int status = parser_read_uint32(&param->mtu,
+                                       ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
                        frag_entries = 1;
-                       ret = parser_read_uint32(&param->mtu,
-                               ent->value);
-               } else if (strcmp(ent->name, "metadata_size") == 0) {
+                       continue;
+               }
+
+               if (strcmp(ent->name, "metadata_size") == 0) {
                        frag_entries = 1;
-                       ret = parser_read_uint32(&param->metadata_size,
-                               ent->value);
-               } else if (strcmp(ent->name, "mempool_direct") == 0) {
+                       int status = parser_read_uint32(&param->metadata_size,
+                                       ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "mempool_direct") == 0) {
                        int status = validate_name(ent->value, "MEMPOOL", 1);
                        ssize_t idx;

-                       APP_CHECK((status == 0),
-                               "CFG: [%s] entry '%s': invalid mempool\n",
-                               section_name,
-                               ent->name);
-
+                       PARSE_ERROR((status == 0), section_name, ent->name);
                        idx = APP_PARAM_ADD(app->mempool_params, ent->value);
                        PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
                        param->mempool_direct_id = idx;
                        frag_entries = 1;
-                       ret = 0;
-               } else if (strcmp(ent->name, "mempool_indirect") == 0) {
+                       continue;
+               }
+
+               if (strcmp(ent->name, "mempool_indirect") == 0) {
                        int status = validate_name(ent->value, "MEMPOOL", 1);
                        ssize_t idx;

-                       APP_CHECK((status == 0),
-                               "CFG: [%s] entry '%s': invalid mempool\n",
-                               section_name,
-                               ent->name);
-
+                       PARSE_ERROR((status == 0), section_name, ent->name);
                        idx = APP_PARAM_ADD(app->mempool_params, ent->value);
                        PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
                        param->mempool_indirect_id = idx;
                        frag_entries = 1;
-                       ret = 0;
-               }
-
-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+                       continue;
+               }
+
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

        if (frag_entries == 1) {
@@ -1596,6 +1698,8 @@ parse_swq(struct app_params *app,
                        section_name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

@@ -1606,7 +1710,7 @@ parse_tm(struct app_params *app,
 {
        struct app_pktq_tm_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        ssize_t param_idx;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
@@ -1621,41 +1725,38 @@ parse_tm(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);

        param = &app->tm_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
                if (strcmp(ent->name, "cfg") == 0) {
                        param->file_name = strdup(ent->value);
-                       if (param->file_name == NULL)
-                               ret = -EINVAL;
-                       else
-                               ret = 0;
-               } else if (strcmp(ent->name, "burst_read") == 0)
-                       ret = parser_read_uint32(&param->burst_read,
+                       PARSE_ERROR_MALLOC(param->file_name != NULL);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "burst_read") == 0) {
+                       int status = parser_read_uint32(&param->burst_read,
                                ent->value);
-               else if (strcmp(ent->name, "burst_write") == 0)
-                       ret = parser_read_uint32(&param->burst_write,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "burst_write") == 0) {
+                       int status = parser_read_uint32(&param->burst_write,
                                ent->value);

-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret != -EBADF,
-                       "CFG: [%s] entry '%s': TM cfg parse error '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

@@ -1666,7 +1767,7 @@ parse_source(struct app_params *app,
 {
        struct app_pktq_source_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        ssize_t param_idx;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
@@ -1681,39 +1782,35 @@ parse_source(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);

        param = &app->source_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
                if (strcmp(ent->name, "mempool") == 0) {
                        int status = validate_name(ent->value, "MEMPOOL", 1);
                        ssize_t idx;

-                       APP_CHECK((status == 0),
-                               "CFG: [%s] entry '%s': invalid mempool\n",
-                                       section_name,
-                                       ent->name);
-
+                       PARSE_ERROR((status == 0), section_name, ent->name);
                        idx = APP_PARAM_ADD(app->mempool_params, ent->value);
                        PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
                        param->mempool_id = idx;
-                       ret = 0;
-               } else if (strcmp(ent->name, "burst") == 0)
-                       ret = parser_read_uint32(&param->burst, ent->value);
-
-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "burst") == 0) {
+                       int status = parser_read_uint32(&param->burst,
+                               ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

@@ -1724,7 +1821,7 @@ parse_msgq_req_pipeline(struct app_params *app,
 {
        struct app_msgq_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        ssize_t param_idx;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
@@ -1739,26 +1836,23 @@ parse_msgq_req_pipeline(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);

        param = &app->msgq_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
-               if (strcmp(ent->name, "size") == 0)
-                       ret = parser_read_uint32(&param->size, ent->value);
-
-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+               if (strcmp(ent->name, "size") == 0) {
+                       int status = parser_read_uint32(&param->size,
+                               ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
        free(entries);
 }

@@ -1769,7 +1863,7 @@ parse_msgq_rsp_pipeline(struct app_params *app,
 {
        struct app_msgq_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        ssize_t param_idx;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
@@ -1784,26 +1878,24 @@ parse_msgq_rsp_pipeline(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);

        param = &app->msgq_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
-               if (strcmp(ent->name, "size") == 0)
-                       ret = parser_read_uint32(&param->size, ent->value);
-
-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+               if (strcmp(ent->name, "size") == 0) {
+                       int status = parser_read_uint32(&param->size,
+                               ent->value);
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

@@ -1814,7 +1906,7 @@ parse_msgq(struct app_params *app,
 {
        struct app_msgq_params *param;
        struct rte_cfgfile_entry *entries;
-       int n_entries, ret, i;
+       int n_entries, i;
        ssize_t param_idx;

        n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
@@ -1829,30 +1921,32 @@ parse_msgq(struct app_params *app,
        PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);

        param = &app->msgq_params[param_idx];
-       param->parsed = 1;

        for (i = 0; i < n_entries; i++) {
                struct rte_cfgfile_entry *ent = &entries[i];

-               ret = -ESRCH;
-               if (strcmp(ent->name, "size") == 0)
-                       ret = parser_read_uint32(&param->size,
+               if (strcmp(ent->name, "size") == 0) {
+                       int status = parser_read_uint32(&param->size,
                                ent->value);
-               else if (strcmp(ent->name, "cpu") == 0)
-                       ret = parser_read_uint32(&param->cpu_socket_id,
+
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               if (strcmp(ent->name, "cpu") == 0) {
+                       int status = parser_read_uint32(&param->cpu_socket_id,
                                ent->value);

-               APP_CHECK(ret != -ESRCH,
-                       "CFG: [%s] entry '%s': unknown entry\n",
-                       section_name,
-                       ent->name);
-               APP_CHECK(ret == 0,
-                       "CFG: [%s] entry '%s': Invalid value '%s'\n",
-                       section_name,
-                       ent->name,
-                       ent->value);
+                       PARSE_ERROR((status == 0), section_name, ent->name);
+                       continue;
+               }
+
+               /* unrecognized */
+               PARSE_ERROR_INVALID(0, section_name, ent->name);
        }

+       param->parsed = 1;
+
        free(entries);
 }

diff --git a/examples/ip_pipeline/pipeline_be.h 
b/examples/ip_pipeline/pipeline_be.h
index 0ba00f6..619fdc2 100644
--- a/examples/ip_pipeline/pipeline_be.h
+++ b/examples/ip_pipeline/pipeline_be.h
@@ -271,6 +271,54 @@ struct pipeline_be_ops {
        pipeline_be_op_track f_track;
 };

+/* Global parameter parsing check and display */
+#define        PARSER_ERR_CHECK(exp, fmt, ...) \
+do {                                                                   \
+       if (!(exp)) {                                           \
+               fprintf(stderr, fmt "\n", ## __VA_ARGS__);\
+               abort();                                                \
+       }                               \
+} while (0)
+
+#define PARSE_ERROR(exp, section, entry)                               \
+PARSER_ERR_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n",\
+               section, entry)
+
+#define PARSE_ERROR_MALLOC(exp)                                        \
+PARSER_ERR_CHECK(exp, "Parse error: no free memory\n")
+
+#define PARSE_ERROR_SECTION(exp, section)                              \
+PARSER_ERR_CHECK(exp, "Parse error in section \"%s\"", section)
+
+#define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section)   \
+PARSER_ERR_CHECK(exp, "Parse error in section \"%s\": no entries\n",\
+       section)
+
+#define PARSE_WARNING_IGNORED(exp, section, entry)             \
+do {                                                                   \
+       if (!(exp))                                                     \
+               fprintf(stderr, "Parse warning in section \"%s\": "     \
+                       "entry \"%s\" is ignored\n", section, entry);   \
+} while (0)
+
+#define PARSE_ERROR_INVALID(exp, section, entry)               \
+PARSER_ERR_CHECK(exp,                                          \
+       "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
+       section, entry)
+
+#define PARSE_ERROR_DUPLICATE(exp, section, entry)             \
+PARSER_ERR_CHECK(exp,                                          \
+       "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
+       section, entry)
+
+/* Parse 64-bit integer string to value */
+int
+parser_read_uint64(uint64_t *value, const char *p);
+
+/* Parse 32-bit integer string to value */
+int
+parser_read_uint32(uint32_t *value, const char *p);
+
 /* Parse hex string to uint8_t array */
 int
 parse_hex_string(char *src, uint8_t *dst, uint32_t *size);
-- 
2.5.0

Reply via email to