From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 6113D37A8 for ; Mon, 2 May 2016 13:47:38 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 02 May 2016 04:47:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,567,1455004800"; d="scan'208";a="957064364" Received: from sie-lab-212-251.ir.intel.com (HELO silpixa00381635.ir.intel.com) ([10.237.212.251]) by fmsmga001.fm.intel.com with ESMTP; 02 May 2016 04:47:35 -0700 From: Jasvinder Singh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com Date: Mon, 2 May 2016 12:53:55 +0100 Message-Id: <1462190035-63125-1-git-send-email-jasvinder.singh@intel.com> X-Mailer: git-send-email 2.5.5 Subject: [dpdk-dev] [PATCH] ip_pipeline: configuration file parser cleanup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 May 2016 11:47:39 -0000 This patch updates the parsing routines of packet queues (pktq_in/out fields in the PIPELINE section) and message queues (msgq_in/out fields of in the MSGQ Section) specified in ip_pipeline configuration file. Signed-off-by: Jasvinder Singh Acked-by: Cristian Dumitrescu --- examples/ip_pipeline/config_parse.c | 221 ++++++++---------------------------- 1 file changed, 45 insertions(+), 176 deletions(-) diff --git a/examples/ip_pipeline/config_parse.c b/examples/ip_pipeline/config_parse.c index ab79cd5..72e3d61 100644 --- a/examples/ip_pipeline/config_parse.c +++ b/examples/ip_pipeline/config_parse.c @@ -1128,61 +1128,29 @@ parse_pipeline_pcap_sink(struct app_params *app, static int parse_pipeline_pktq_in(struct app_params *app, struct app_pipeline_params *p, - const char *value) + char *value) { - const char *next = value; - char *end; - char name[APP_PARAM_NAME_SIZE]; - size_t name_len; - while (*next != '\0') { + while (1) { enum app_pktq_in_type type; int id; - char *end_space; - char *end_tab; + char *token = strtok_r(value, PARSE_DELIMITER, &value); - next = skip_white_spaces(next); - if (!next) + if (token == NULL) break; - end_space = strchr(next, ' '); - end_tab = strchr(next, ' '); - - if (end_space && (!end_tab)) - end = end_space; - else if ((!end_space) && end_tab) - end = end_tab; - else if (end_space && end_tab) - end = RTE_MIN(end_space, end_tab); - else - end = NULL; - - if (!end) - name_len = strlen(next); - else - name_len = end - next; - - if (name_len == 0 || name_len == sizeof(name)) - return -EINVAL; - - strncpy(name, next, name_len); - name[name_len] = '\0'; - next += name_len; - if (*next != '\0') - next++; - - if (validate_name(name, "RXQ", 2) == 0) { + if (validate_name(token, "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) { + id = APP_PARAM_ADD(app->hwq_in_params, token); + } else if (validate_name(token, "SWQ", 1) == 0) { type = APP_PKTQ_IN_SWQ; - id = APP_PARAM_ADD(app->swq_params, name); - } else if (validate_name(name, "TM", 1) == 0) { + id = APP_PARAM_ADD(app->swq_params, token); + } else if (validate_name(token, "TM", 1) == 0) { type = APP_PKTQ_IN_TM; - id = APP_PARAM_ADD(app->tm_params, name); - } else if (validate_name(name, "SOURCE", 1) == 0) { + id = APP_PARAM_ADD(app->tm_params, token); + } else if (validate_name(token, "SOURCE", 1) == 0) { type = APP_PKTQ_IN_SOURCE; - id = APP_PARAM_ADD(app->source_params, name); + id = APP_PARAM_ADD(app->source_params, token); } else return -EINVAL; @@ -1200,60 +1168,28 @@ parse_pipeline_pktq_in(struct app_params *app, static int parse_pipeline_pktq_out(struct app_params *app, struct app_pipeline_params *p, - const char *value) + char *value) { - const char *next = value; - char *end; - char name[APP_PARAM_NAME_SIZE]; - size_t name_len; - - while (*next != '\0') { - enum app_pktq_out_type type; + while (1) { + enum app_pktq_in_type type; int id; - char *end_space; - char *end_tab; + char *token = strtok_r(value, PARSE_DELIMITER, &value); - next = skip_white_spaces(next); - if (!next) + if (token == NULL) break; - end_space = strchr(next, ' '); - end_tab = strchr(next, ' '); - - if (end_space && (!end_tab)) - end = end_space; - else if ((!end_space) && end_tab) - end = end_tab; - else if (end_space && end_tab) - end = RTE_MIN(end_space, end_tab); - else - end = NULL; - - if (!end) - name_len = strlen(next); - else - name_len = end - next; - - if (name_len == 0 || name_len == sizeof(name)) - return -EINVAL; - - strncpy(name, next, name_len); - name[name_len] = '\0'; - next += name_len; - if (*next != '\0') - next++; - if (validate_name(name, "TXQ", 2) == 0) { + if (validate_name(token, "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) { + id = APP_PARAM_ADD(app->hwq_out_params, token); + } else if (validate_name(token, "SWQ", 1) == 0) { type = APP_PKTQ_OUT_SWQ; - id = APP_PARAM_ADD(app->swq_params, name); - } else if (validate_name(name, "TM", 1) == 0) { + id = APP_PARAM_ADD(app->swq_params, token); + } else if (validate_name(token, "TM", 1) == 0) { type = APP_PKTQ_OUT_TM; - id = APP_PARAM_ADD(app->tm_params, name); - } else if (validate_name(name, "SINK", 1) == 0) { + id = APP_PARAM_ADD(app->tm_params, token); + } else if (validate_name(token, "SINK", 1) == 0) { type = APP_PKTQ_OUT_SINK; - id = APP_PARAM_ADD(app->sink_params, name); + id = APP_PARAM_ADD(app->sink_params, token); } else return -EINVAL; @@ -1271,56 +1207,23 @@ parse_pipeline_pktq_out(struct app_params *app, static int parse_pipeline_msgq_in(struct app_params *app, struct app_pipeline_params *p, - const char *value) + char *value) { - const char *next = value; - char *end; - char name[APP_PARAM_NAME_SIZE]; - size_t name_len; - ssize_t idx; - - while (*next != '\0') { - char *end_space; - char *end_tab; + while (1) { + int id; + char *token = strtok_r(value, PARSE_DELIMITER, &value); - next = skip_white_spaces(next); - if (!next) + if (token == NULL) break; - end_space = strchr(next, ' '); - end_tab = strchr(next, ' '); - - if (end_space && (!end_tab)) - end = end_space; - else if ((!end_space) && end_tab) - end = end_tab; - else if (end_space && end_tab) - end = RTE_MIN(end_space, end_tab); - else - end = NULL; - - if (!end) - name_len = strlen(next); - else - name_len = end - next; - - if (name_len == 0 || name_len == sizeof(name)) - return -EINVAL; - - strncpy(name, next, name_len); - name[name_len] = '\0'; - next += name_len; - if (*next != '\0') - next++; - - if (validate_name(name, "MSGQ", 1) != 0) + if (validate_name(token, "MSGQ", 1) != 0) return -EINVAL; - idx = APP_PARAM_ADD(app->msgq_params, name); - if (idx < 0) - return idx; + id = APP_PARAM_ADD(app->msgq_params, token); + if (id < 0) + return id; - p->msgq_in[p->n_msgq_in] = idx; + p->msgq_in[p->n_msgq_in] = id; p->n_msgq_in++; } @@ -1330,56 +1233,22 @@ parse_pipeline_msgq_in(struct app_params *app, static int parse_pipeline_msgq_out(struct app_params *app, struct app_pipeline_params *p, - const char *value) + char *value) { - const char *next = value; - char *end; - char name[APP_PARAM_NAME_SIZE]; - size_t name_len; - ssize_t idx; - - while (*next != '\0') { - char *end_space; - char *end_tab; + while (1) { + int id; + char *token = strtok_r(value, PARSE_DELIMITER, &value); - next = skip_white_spaces(next); - if (!next) + if (token == NULL) break; - - end_space = strchr(next, ' '); - end_tab = strchr(next, ' '); - - if (end_space && (!end_tab)) - end = end_space; - else if ((!end_space) && end_tab) - end = end_tab; - else if (end_space && end_tab) - end = RTE_MIN(end_space, end_tab); - else - end = NULL; - - if (!end) - name_len = strlen(next); - else - name_len = end - next; - - if (name_len == 0 || name_len == sizeof(name)) - return -EINVAL; - - strncpy(name, next, name_len); - name[name_len] = '\0'; - next += name_len; - if (*next != '\0') - next++; - - if (validate_name(name, "MSGQ", 1) != 0) + if (validate_name(token, "MSGQ", 1) != 0) return -EINVAL; - idx = APP_PARAM_ADD(app->msgq_params, name); - if (idx < 0) - return idx; + id = APP_PARAM_ADD(app->msgq_params, token); + if (id < 0) + return id; - p->msgq_out[p->n_msgq_out] = idx; + p->msgq_out[p->n_msgq_out] = id; p->n_msgq_out++; } -- 2.5.5