Skip to contentSkip to conversation

ip_pipeline: configuration file parser cleanup

PATCH Superseded Jasvinder Singh 3 participants 9 messages May 2, 2016 – Jun 8, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip_pipeline: configuration file parser cleanup

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.

---
 examples/ip_pipeline/config_parse.c | 221 ++++++++----------------------------
 1 file changed, 45 insertions(+), 176 deletions(-)
examples/ip_pipeline/config_parse.c +45 -176
index ab79cd5..72e3d61 100644
@@ -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++;
 	}
 
Signature · 1 line
2.5.5
#1 lore raw
Quoted 6 lines · Jasvinder Singh

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.

Hi Jasvinder,

can you provide more detail in the patch commit message, please? Why was this cleanup wanted/needed, and how was it done? The code diff is pretty large so a clear description of how the code works before and after this patch is needed to help someone scanning the patch understand what is happening there.

Thanks,
/Bruce

#2 lore raw

PATCH v2 1/1 ip_pipeline: configuration file parser cleanup

In reply to Jasvinder Singh

This patch updates the parsing routines related to 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.

In the updated routines, function "strtok_r()" is used for parsing the string instead of manually checking the string termination, white spaces, tabs etc., between the string tokens. Each call to strtok_r() returns a pointer to a null-terminated string containing the next token. If no more tokens are found, strtok_r() returns NULL. As a result of using strtok_r(), the code size of the parsing routines is reduced significantly.

---
v2
- update the commit message
- change the local variable name from "token" to "name"

 examples/ip_pipeline/config_parse.c | 169 ++++--------------------------------
 1 file changed, 19 insertions(+), 150 deletions(-)
examples/ip_pipeline/config_parse.c +19 -150
index e166891..208f39a 100644
@@ -1128,49 +1128,17 @@ 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 *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == 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) {
 			type = APP_PKTQ_IN_HWQ;
 			id = APP_PARAM_ADD(app->hwq_in_params, name);
@@ -1200,48 +1168,16 @@ 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 *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == 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) {
 			type = APP_PKTQ_OUT_HWQ;
 			id = APP_PARAM_ADD(app->hwq_out_params, name);
@@ -1271,48 +1207,15 @@ 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 idx;
+		char *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == 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)
 			return -EINVAL;
 
@@ -1330,48 +1233,14 @@ 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 idx;
+		char *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == 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)
 			return -EINVAL;
 
Signature · 1 line
2.5.5
#3 lore raw

PATCH v3 1/1 ip_pipeline: configuration file parser cleanup

This patch updates the parsing routines related to 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.

In the updated routines, function "strtok_r()" is used for parsing the string instead of manually checking the string termination, white spaces, tabs etc., between the string tokens. Each call to strtok_r() returns a pointer to a null-terminated string containing the next token. If no more tokens are found, strtok_r() returns NULL. As a result of using strtok_r(), the code size of the parsing routines is reduced significantly.

---
v3
- add check on the number of pktq_in/out entries
- add check on the number of msgq_in/out entries

v2
- update the commit message
- change the local variable name from "token" to "name"

 examples/ip_pipeline/config_parse.c | 190 +++++++++---------------------------
 1 file changed, 44 insertions(+), 146 deletions(-)
examples/ip_pipeline/config_parse.c +44 -146
index ab2f637..f09e04f 100644
@@ -1,4 +1,4 @@
-/*-
+/*-
  *   BSD LICENSE
  *
  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
@@ -307,6 +307,10 @@ APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
 APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": %s\n",	\
 	section, entry, message)
 
+#define PARSE_ERROR_TOO_MANY_ELEMENTS(exp, section, entry, max)		\
+APP_CHECK(exp, "Parse error in section \"%s\", entry \"%s\": "	\
+	"maximum number of elements allowed is %lu\n",	\
+	section, entry, max)
 
 #define PARSE_ERROR_MALLOC(exp)						\
 APP_CHECK(exp, "Parse error: no free memory\n")
@@ -1128,48 +1132,19 @@ 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 *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == 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 (p->n_pktq_in == RTE_DIM(p->pktq_in))
+			return -ENOMEM;
 
 		if (validate_name(name, "RXQ", 2) == 0) {
 			type = APP_PKTQ_IN_HWQ;
@@ -1200,48 +1175,19 @@ 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 *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == 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;
+		if (p->n_pktq_out == RTE_DIM(p->pktq_out))
+			return -ENOMEM;
 
-		strncpy(name, next, name_len);
-		name[name_len] = '\0';
-		next += name_len;
-		if (*next != '\0')
-			next++;
 		if (validate_name(name, "TXQ", 2) == 0) {
 			type = APP_PKTQ_OUT_HWQ;
 			id = APP_PARAM_ADD(app->hwq_out_params, name);
@@ -1271,47 +1217,17 @@ 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 idx;
+		char *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == 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 (p->n_msgq_in == RTE_DIM(p->msgq_in))
+			return -ENOMEM;
 
 		if (validate_name(name, "MSGQ", 1) != 0)
 			return -EINVAL;
@@ -1330,47 +1246,17 @@ 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 idx;
+		char *name = strtok_r(value, PARSE_DELIMITER, &value);
 
-		next = skip_white_spaces(next);
-		if (!next)
+		if (name == 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 (p->n_msgq_out == RTE_DIM(p->msgq_out))
+			return -ENOMEM;
 
 		if (validate_name(name, "MSGQ", 1) != 0)
 			return -EINVAL;
@@ -1438,6 +1324,9 @@ parse_pipeline(struct app_params *app,
 			int status = parse_pipeline_pktq_in(app, param,
 				ent->value);
 
+			PARSE_ERROR_TOO_MANY_ELEMENTS((status != -ENOMEM),
+				section_name, ent->name,
+				RTE_DIM(param->pktq_in));
 			PARSE_ERROR((status == 0), section_name,
 				ent->name);
 			continue;
@@ -1447,6 +1336,9 @@ parse_pipeline(struct app_params *app,
 			int status = parse_pipeline_pktq_out(app, param,
 				ent->value);
 
+			PARSE_ERROR_TOO_MANY_ELEMENTS((status != -ENOMEM),
+				section_name, ent->name,
+				RTE_DIM(param->pktq_out));
 			PARSE_ERROR((status == 0), section_name,
 				ent->name);
 			continue;
@@ -1456,6 +1348,9 @@ parse_pipeline(struct app_params *app,
 			int status = parse_pipeline_msgq_in(app, param,
 				ent->value);
 
+			PARSE_ERROR_TOO_MANY_ELEMENTS((status != -ENOMEM),
+				section_name, ent->name,
+				RTE_DIM(param->msgq_in));
 			PARSE_ERROR((status == 0), section_name,
 				ent->name);
 			continue;
@@ -1465,6 +1360,9 @@ parse_pipeline(struct app_params *app,
 			int status = parse_pipeline_msgq_out(app, param,
 				ent->value);
 
+			PARSE_ERROR_TOO_MANY_ELEMENTS((status != -ENOMEM),
+				section_name, ent->name,
+				RTE_DIM(param->msgq_out));
 			PARSE_ERROR((status == 0), section_name,
 				ent->name);
 			continue;
Signature · 1 line
2.5.5
#4 lore raw

PATCH v4 1/1 ip_pipeline: configuration file parser cleanup

This commit adds following changes to configuration file parsing of the ip pipeline application;

1. Parsing routines related to packet queues (pktq_in/out fields in the PIPELINE section) and message queues (msgq_in/out fields of in the MSGQ Section) are updated.

In the parsing routines, function "strtok_r()" is used for parsing the string instead of manually checking the string termination, white spaces, tabs etc., between the string tokens. Each call to strtok_r() returns a pointer to a null-terminated string containing the next token. If no more tokens are found, strtok_r() returns NULL. As a result of using strtok_r(), the code size of the parsing routines is reduced significantly.

2. Replace PARSER_PARAM_ADD_CHECK macro by more specific macros such as PARSE_CHECK_DUPLICATE_SECTION, PARSE_CHECK_DUPLICATE_SECTION_EAL to detect duplicate entries in the various sections of the configuration file

3. Add new macros PARSER_ERROR_NO_ELEMENTS and PARSE_ERROR_TOO_MANY_ELEMENTS for detecting no element and more elements than allowed situations respectively, in the section entry.

4. Add new macros APP_PARAM_ADD_LINK_FOR_RXQ, APP_PARAM_ADD_LINK_FOR_TXQ and APP_PARAM_ADD_LINK_FOR_TM which add corresponding nic ports entry to the application param structure while parsing rx/tx queues, TM (Traffic Manager) port sections and pktq_in/out entries of pipeline sections

---
v4
- update the commit message
- move APP_PARAM_ADD macro from app.h to config_parse.c as it is only used by the routines defined in this file
- remove extra newline character from error message display
- rebased on top of ip_pipeline CLI patchset
(http://dpdk.org/dev/patchwork/patch/12911/) and NULL packet processing fix patch (http://dpdk.org/dev/patchwork/patch/12807/)

v3
- add check on the number of pktq_in/out entries
- add check on the number of msgq_in/out entries

v2
- update the commit message
- change the local variable name from "token" to "name"

 examples/ip_pipeline/app.h          |  25 +-
 examples/ip_pipeline/config_parse.c | 472 +++++++++++++++---------------------
 2 files changed, 196 insertions(+), 301 deletions(-)
examples/ip_pipeline/app.h +3 -22
index e775024..05d608b 100644
@@ -50,6 +50,7 @@
 
 #define APP_PARAM_NAME_SIZE                      PIPELINE_NAME_SIZE
 #define APP_LINK_PCI_BDF_SIZE                    16
+
 struct app_mempool_params {
 	char *name;
 	uint32_t parsed;
@@ -370,6 +371,8 @@ struct app_eal_params {
 	/* Support running on Xen dom0 without hugetlbfs */
 	uint32_t xen_dom0_present;
 	int xen_dom0;
+
+	uint32_t parsed;
 };
 
 #ifndef APP_APPNAME_SIZE
@@ -529,28 +532,6 @@ do									\
 	sscanf(obj->name, prefix "%" SCNu32, &id);				\
 while (0)								\
 
-#define APP_PARAM_ADD(obj_array, obj_name)				\
-({									\
-	ssize_t obj_idx;						\
-	const ssize_t obj_count = RTE_DIM(obj_array);			\
-									\
-	obj_idx = APP_PARAM_FIND(obj_array, obj_name);			\
-	if (obj_idx < 0) {						\
-		for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {	\
-			if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))	\
-				break;					\
-		}							\
-									\
-		if (obj_idx < obj_count) {				\
-			(obj_array)[obj_idx].name = strdup(obj_name);   \
-			if ((obj_array)[obj_idx].name == NULL)          \
-				obj_idx = -EINVAL;			\
-		} else							\
-			obj_idx = -ENOMEM;				\
-	}								\
-	obj_idx;							\
-})
-
 #define	APP_CHECK(exp, fmt, ...)					\
 do {									\
 	if (!(exp)) {							\
examples/ip_pipeline/config_parse.c +193 -279

869 lines not on this page · raw message

Signature · 1 line
2.5.5
#5 lore raw

clang compilation fails:
examples/ip_pipeline/config_parse.c:852:11: error:
implicit conversion from enumeration type 'enum app_pktq_out_type' to different enumeration type 'enum app_pktq_in_type'

#6 lore raw
Quoted 10 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, June 8, 2016 3:48 PM
To: Singh, Jasvinder <[email protected]>
Cc: [email protected]; Dumitrescu, Cristian <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v4] ip_pipeline: configuration file parser cleanup

Quoted 5 lines

clang compilation fails:

	examples/ip_pipeline/config_parse.c:852:11: error:
	implicit conversion from enumeration type 'enum

app_pktq_out_type'
to different enumeration type 'enum app_pktq_in_type'

Thanks, Thomas. V5 has been sent fixing this error.

#7 lore raw

PATCH v5 1/1 ip_pipeline: configuration file parser cleanup

In reply to Jasvinder Singh

This commit adds following changes to configuration file parsing of the ip pipeline application;

1. Parsing routines related to packet queues (pktq_in/out fields in the PIPELINE section) and message queues (msgq_in/out fields of in the MSGQ Section) are updated.

In the parsing routines, function "strtok_r()" is used for parsing the string instead of manually checking the string termination, white spaces, tabs etc., between the string tokens. Each call to strtok_r() returns a pointer to a null-terminated string containing the next token. If no more tokens are found, strtok_r() returns NULL. As a result of using strtok_r(), the code size of the parsing routines is reduced significantly.

2. Replace PARSER_PARAM_ADD_CHECK macro by more specific macros such as PARSE_CHECK_DUPLICATE_SECTION, PARSE_CHECK_DUPLICATE_SECTION_EAL to detect duplicate entries in the various sections of the configuration file

3. Add new macros PARSER_ERROR_NO_ELEMENTS and PARSE_ERROR_TOO_MANY_ELEMENTS for detecting no element and more elements than allowed situations respectively, in the section entry.

4. Add new macros APP_PARAM_ADD_LINK_FOR_RXQ, APP_PARAM_ADD_LINK_FOR_TXQ and APP_PARAM_ADD_LINK_FOR_TM which add corresponding nic ports entry to the application param structure while parsing rx/tx queues, TM (Traffic Manager) port sections and pktq_in/out entries of pipeline sections

---
v5
- fix clang compilation error on enum type 'enum app_pktq_out_type'

v4
- update the commit message
- move APP_PARAM_ADD macro from app.h to config_parse.c as it is only used by the routines defined in this file
- remove extra newline character from error message display
- rebased on top of ip_pipeline CLI patchset
(http://dpdk.org/dev/patchwork/patch/12911/) and NULL packet processing fix patch (http://dpdk.org/dev/patchwork/patch/12807/)

v3
- add check on the number of pktq_in/out entries
- add check on the number of msgq_in/out entries

v2
- update the commit message
- change the local variable name from "token" to "name"

 examples/ip_pipeline/app.h          |  25 +-
 examples/ip_pipeline/config_parse.c | 470 +++++++++++++++---------------------
 2 files changed, 195 insertions(+), 300 deletions(-)
examples/ip_pipeline/app.h +3 -22
index e775024..05d608b 100644
@@ -50,6 +50,7 @@
 
 #define APP_PARAM_NAME_SIZE                      PIPELINE_NAME_SIZE
 #define APP_LINK_PCI_BDF_SIZE                    16
+
 struct app_mempool_params {
 	char *name;
 	uint32_t parsed;
@@ -370,6 +371,8 @@ struct app_eal_params {
 	/* Support running on Xen dom0 without hugetlbfs */
 	uint32_t xen_dom0_present;
 	int xen_dom0;
+
+	uint32_t parsed;
 };
 
 #ifndef APP_APPNAME_SIZE
@@ -529,28 +532,6 @@ do									\
 	sscanf(obj->name, prefix "%" SCNu32, &id);				\
 while (0)								\
 
-#define APP_PARAM_ADD(obj_array, obj_name)				\
-({									\
-	ssize_t obj_idx;						\
-	const ssize_t obj_count = RTE_DIM(obj_array);			\
-									\
-	obj_idx = APP_PARAM_FIND(obj_array, obj_name);			\
-	if (obj_idx < 0) {						\
-		for (obj_idx = 0; obj_idx < obj_count; obj_idx++) {	\
-			if (!APP_PARAM_VALID(&((obj_array)[obj_idx])))	\
-				break;					\
-		}							\
-									\
-		if (obj_idx < obj_count) {				\
-			(obj_array)[obj_idx].name = strdup(obj_name);   \
-			if ((obj_array)[obj_idx].name == NULL)          \
-				obj_idx = -EINVAL;			\
-		} else							\
-			obj_idx = -ENOMEM;				\
-	}								\
-	obj_idx;							\
-})
-
 #define	APP_CHECK(exp, fmt, ...)					\
 do {									\
 	if (!(exp)) {							\
examples/ip_pipeline/config_parse.c +192 -278

868 lines not on this page · raw message

Signature · 1 line
2.5.5
#8 lore raw

2016-06-08 17:30, Jasvinder Singh:

Quoted 23 lines

This commit adds following changes to configuration file parsing of the ip pipeline application;

1. Parsing routines related to packet queues (pktq_in/out fields in the PIPELINE section) and message queues (msgq_in/out fields of in the MSGQ Section) are updated.

In the parsing routines, function "strtok_r()" is used for parsing the string instead of manually checking the string termination, white spaces, tabs etc., between the string tokens. Each call to strtok_r() returns a pointer to a null-terminated string containing the next token. If no more tokens are found, strtok_r() returns NULL. As a result of using strtok_r(), the code size of the parsing routines is reduced significantly.

2. Replace PARSER_PARAM_ADD_CHECK macro by more specific macros such as PARSE_CHECK_DUPLICATE_SECTION, PARSE_CHECK_DUPLICATE_SECTION_EAL to detect duplicate entries in the various sections of the configuration file

3. Add new macros PARSER_ERROR_NO_ELEMENTS and PARSE_ERROR_TOO_MANY_ELEMENTS for detecting no element and more elements than allowed situations respectively, in the section entry.

Quoted 7 lines

4. Add new macros APP_PARAM_ADD_LINK_FOR_RXQ, APP_PARAM_ADD_LINK_FOR_TXQ and APP_PARAM_ADD_LINK_FOR_TM which add corresponding nic ports entry to the application param structure while parsing rx/tx queues, TM (Traffic Manager) port sections and pktq_in/out entries of pipeline sections

Applied, thanks