[spp] [PATCH 43/57] spp_vf: update command decode procedure

x-fn-spp at sl.ntt-tx.co.jp x-fn-spp at sl.ntt-tx.co.jp
Thu Dec 28 05:55:50 CET 2017


From: Hiroyuki Nakamura <nakamura.hioryuki at po.ntt-tx.co.jp>

update command decode procedures due to the change of
command request format (fix bugs caused by the change.)

* Fix bugs in comditional statements and loop index.
* Fix index of received character array.
* Add initializeion of received commands counter.

Signed-off-by: Kentaro Watanabe <watanabe.kentaro.z01 at as.ntt-tx.co.jp>
Signed-off-by: Yasufum Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
 src/vf/command_dec.c  | 21 ++++++++++++---------
 src/vf/command_proc.c |  6 ++----
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/vf/command_dec.c b/src/vf/command_dec.c
index 468702f..75619d9 100644
--- a/src/vf/command_dec.c
+++ b/src/vf/command_dec.c
@@ -63,7 +63,7 @@ static int
 get_arrary_index(const char *match, const char *list[])
 {
 	int i;
-	for (i = 0; list[i][0] == '\0'; i++) {
+	for (i = 0; list[i][0] != '\0'; i++) {
 		if (strcmp(list[i], match) == 0)
 			return i;
 	}
@@ -113,7 +113,7 @@ decode_classifier_type_value(void *output, const char *arg_val)
 {
         int ret = 0;
 	ret = get_arrary_index(arg_val, CLASSIFILER_TYPE_STRINGS);
-        if (unlikely(ret < 0)) {
+        if (unlikely(ret <= 0)) {
                 RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown classifier type. val=%s\n", arg_val);
                 return -1;
         }
@@ -196,13 +196,14 @@ check_comand_argment_in_list(struct spp_command_request *request,
 	int ci = request->commands[0].type;
 	int pi = 0;
 	static struct decode_parameter_list *list = NULL;
-	for(pi = 1; pi < argc-1; pi++) {
-		list = &parameter_list[ci][pi];
+	for(pi = 1; pi < argc; pi++) {
+		list = &parameter_list[ci][pi-1];
+RTE_LOG(ERR, SPP_COMMAND_PROC, "TEST: command=%s, name=%s, index=%d, value=%s\n", argv[0], list->name, pi, argv[pi]);
 		ret = (*list->func)((void *)((char*)&request->commands[0]+list->offset), argv[pi]);
 		if (unlikely(ret < 0)) {
 			RTE_LOG(ERR, SPP_COMMAND_PROC,
-					"Bad value. command = %s, name=%s, index=%d\n",
-					argv[0], list->name, pi);
+					"Bad value. command=%s, name=%s, index=%d, value=%s\n",
+					argv[0], list->name, pi, argv[pi]);
 			return set_string_value_decode_error(error, argv[pi], list->name);
 		}
 	}
@@ -241,8 +242,6 @@ decode_command_argment(struct spp_command_request *request,
 	memset(argv, 0x00, sizeof(argv));
 	memset(tmp_str, 0x00, sizeof(tmp_str));
 
-	request->num_command = 1;
-
 	strcpy(tmp_str, request_str);
 	decode_argument_value(tmp_str, &argc, argv);
 	RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array. num=%d\n", argc);
@@ -279,14 +278,18 @@ spp_command_decode_request(struct spp_command_request *request, const char *requ
 	int ret = -1;
 	int i;
 
+RTE_LOG(ERR, SPP_COMMAND_PROC, "ERROR:request_str=%s\n", request_str);
 	/* decode request */
+	request->num_command = 1;
 	ret = decode_command_argment(request, request_str, error);
-	if (unlikely(ret < 0)) {
+	if (unlikely(ret != 0)) {
 		RTE_LOG(ERR, SPP_COMMAND_PROC, "Cannot decode command request. "
 				"ret=%d, request_str=%.*s\n", 
 				ret, (int)request_str_len, request_str);
 		return ret;
 	}
+	request->num_valid_command = 1;
+RTE_LOG(ERR, SPP_COMMAND_PROC, "ERROR:command type=%d\n", request->commands[0].type);
 
 	/* check getter command */
 	for (i = 0; i < request->num_valid_command; ++i) {
diff --git a/src/vf/command_proc.c b/src/vf/command_proc.c
index 0dd1d56..ef1ae81 100644
--- a/src/vf/command_proc.c
+++ b/src/vf/command_proc.c
@@ -462,7 +462,6 @@ spp_command_proc_do(void)
 
 	static int sock = -1;
 	static char *msgbuf = NULL;
-	static size_t msg_len = 0;
 
 	if (unlikely(msgbuf == NULL)) {
 		msgbuf = spp_strbuf_allocate(CMD_REQ_BUF_INIT_SIZE);
@@ -487,9 +486,8 @@ spp_command_proc_do(void)
 			return -1;
 	}
 
-	msg_len += (msg_ret + 1);
-	ret = process_request(&sock, msgbuf, msg_len);
-	spp_strbuf_remove_front(msgbuf, msg_len);
+	ret = process_request(&sock, msgbuf, msg_ret);
+	spp_strbuf_remove_front(msgbuf, msg_ret);
 
 	return 0;
 }
-- 
1.9.1



More information about the spp mailing list