From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bcmv-tmail01.ecl.ntt.co.jp (bcmv-tmail01.ecl.ntt.co.jp [124.146.185.148]) by dpdk.org (Postfix) with ESMTP id 3D6BB1B4D2 for ; Tue, 9 Oct 2018 12:54:10 +0200 (CEST) Received: from bcmv-ns01.ecl.ntt.co.jp (bcmv-ns01.ecl.ntt.co.jp [129.60.83.123]) by bcmv-tmail01.ecl.ntt.co.jp (8.14.4/8.14.4) with ESMTP id w99As94d017859; Tue, 9 Oct 2018 19:54:09 +0900 Received: from bcmv-ns01.ecl.ntt.co.jp (localhost [127.0.0.1]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id 12FDB125; Tue, 9 Oct 2018 19:54:09 +0900 (JST) Received: from localhost.localdomain (unknown [129.60.13.51]) by bcmv-ns01.ecl.ntt.co.jp (Postfix) with ESMTP id F1132119; Tue, 9 Oct 2018 19:54:08 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Tue, 9 Oct 2018 19:53:56 +0900 Message-Id: <20181009105400.42817-3-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20181009105400.42817-1-ogawa.yasufumi@lab.ntt.co.jp> References: <20181009105400.42817-1-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 2/6] spp_nfv: refactor log of patch command X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Oct 2018 10:54:10 -0000 From: Yasufumi Ogawa To describe the result of patch command correctly, refactor log message. Signed-off-by: Yasufumi Ogawa --- src/nfv/nfv.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/nfv/nfv.c b/src/nfv/nfv.c index 049b3cf..05290ed 100644 --- a/src/nfv/nfv.c +++ b/src/nfv/nfv.c @@ -344,17 +344,19 @@ do_del(char *res_uid) return 0; } +/* Return 0 if invalid */ static int -is_valid_port(int port_id) +is_valid_port(uint16_t port_id) { - if (port_id < 0 || port_id > RTE_MAX_ETHPORTS) + if (port_id > RTE_MAX_ETHPORTS) return 0; return port_map[port_id].id != PORT_RESET; } +/* Return -1 as an error if given patch is invalid */ static int -add_patch(int in_port, int out_port) +add_patch(uint16_t in_port, uint16_t out_port) { if (!is_valid_port(in_port) || !is_valid_port(out_port)) return -1; @@ -711,6 +713,7 @@ do_add(char *res_uid) return 0; } +/* Return -1 if exit command is called to terminate the process */ static int parse_command(char *str) { @@ -805,31 +808,36 @@ parse_command(char *str) if (in_port == PORT_RESET && out_port == PORT_RESET) { char err_msg[128]; memset(err_msg, '\0', sizeof(err_msg)); - sprintf(err_msg, "%s '%s:%d' and '%s:%d' %s", - "Failed to patch, both of", + sprintf(err_msg, "%s '%s:%d' and '%s:%d'", + "Patch not found, both of", in_p_type, in_p_id, - out_p_type, out_p_id, - "not found"); + out_p_type, out_p_id); RTE_LOG(ERR, APP, "%s\n", err_msg); - return 0; } else if (in_port == PORT_RESET) { char err_msg[128]; memset(err_msg, '\0', sizeof(err_msg)); - sprintf(err_msg, "%s '%s:%d' not found", - "Failed to patch, in_port", + sprintf(err_msg, "%s '%s:%d'", + "Patch not found, in_port", in_p_type, in_p_id); RTE_LOG(ERR, APP, "%s\n", err_msg); - return 0; } else if (out_port == PORT_RESET) { char err_msg[128]; memset(err_msg, '\0', sizeof(err_msg)); - sprintf(err_msg, "%s '%s:%d' not found", - "Failed to patch, out_port", + sprintf(err_msg, "%s '%s:%d'", + "Patch not found, out_port", out_p_type, out_p_id); RTE_LOG(ERR, APP, "%s\n", err_msg); } - add_patch(in_port, out_port); + if (add_patch(in_port, out_port) == 0) + RTE_LOG(INFO, APP, + "Patched '%s:%d' and '%s:%d'\n", + in_p_type, in_p_id, + out_p_type, out_p_id); + + else + RTE_LOG(ERR, APP, "Failed to patch\n"); + ret = 0; } } else if (!strcmp(token_list[0], "del")) { @@ -993,7 +1001,7 @@ main(int argc, char *argv[]) RTE_LOG(DEBUG, APP, "Received string: %s\n", str); ret = parse_command(str); - if (ret < 0) + if (ret < 0) /* terminate process if exit is called */ break; /*Send the message back to client*/ -- 2.7.4