From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3AFA5A046B for ; Thu, 25 Jul 2019 13:25:36 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 31B5B1BF6B; Thu, 25 Jul 2019 13:25:36 +0200 (CEST) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by dpdk.org (Postfix) with ESMTP id 3566F1BF6B for ; Thu, 25 Jul 2019 13:25:35 +0200 (CEST) Received: by mail-pf1-f173.google.com with SMTP id 19so22607241pfa.4 for ; Thu, 25 Jul 2019 04:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=mNQl6nSt6Wi9sWrqA4yuXmJAP26D24ULD/6SM+wfgv4=; b=Ge41LmeSKJ0YkWKo6Zm09pF8VStH1O+ZcKZYhyGgQBi/OD5ynGeztW3Y7ZIvWcfpTY eC9quJN1Fszebpo+7GqaSfT3ipP+iH/GV/6fklUsni4ccj4msNEjBg3LVVByPmge3VSi 1PR0JKtcJW75RznqMxzvCfNImEankKB3CprsByJtd+Pc78niDOiwb73jQuKGL8yQt5NK 0DLVfd7y7fK57BfXgYxdXfkhJ8jVR33Zu3heSI4bnIHL6h06ebCQR3fFitDKXFi7Ed9t lEKzTbM9MbDg45xoIASAPQ0CBnLhvJgRteTt/8A+5Pu8MY9IZuVvUFNxp/C3TsieQsYi gC5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=mNQl6nSt6Wi9sWrqA4yuXmJAP26D24ULD/6SM+wfgv4=; b=d+tLJh01FsnHJsYDbfzHAtrqXlpXFrqK6OosVyTe8wlGTl9xP3sLTnQG2yuCqs1NHG Ex9EGSR65AoptNAu7dFLPjYue7M4veN8ecsqEzHDOGaYNVEAwJDWhqJ/sV8r0TRpV+A9 iBdkhPFIJqAk4f2knK/b8WmidKIQ/ZjxdAc7fuclpNjsSouLIM1Ik1t4adK4uKXj6T0H VOBhYl8G+daGhfKNGjVWYShjU+ZrfTQM4NkBYvYd7HfZdsyKI54p2Hvivvfv36biAFQJ U0OLAh4Lvz/+DyJZZKR73UVhPUrbzs6S8Cq0Y2XaPRBK1sBd9kQyJf1A8wBJpBKsHIH2 XuQQ== X-Gm-Message-State: APjAAAVoezp9EGwXt6kVIKrCQl0Qi7znAPxtPRHDuf1wPqu/tC9L5PhF HVl/4ABgQtsWLFfjOFBnk24a4gzt X-Google-Smtp-Source: APXvYqy9wScnWix6Ow2T2dP4VBTVfoLlHr0yTP5/YsPgfvF0CBgm1HTRRn4DzEIVWUKq6cnHk6WE6w== X-Received: by 2002:aa7:9f1c:: with SMTP id g28mr15968117pfr.81.1564053934225; Thu, 25 Jul 2019 04:25:34 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id q126sm56282657pfq.123.2019.07.25.04.25.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jul 2019 04:25:33 -0700 (PDT) From: yasufum.o@gmail.com To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Thu, 25 Jul 2019 20:25:30 +0900 Message-Id: <20190725112530.27323-1-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [spp] [PATCH] spp_nfv: change to return JSON msg for spp-ctl 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: , Errors-To: spp-bounces@dpdk.org Sender: "spp" From: Yasufumi Ogawa Spp_nfv does not return to JSON message without to `status` and `_get_client_id` requests. Spp-ctl fails to parse the results because it expects JSON formatted message. This update is to change the result to be JSON format. Signed-off-by: Yasufumi Ogawa --- src/nfv/commands.h | 103 +++++++++++++++++++++++++++++++++------------ src/nfv/main.c | 2 +- 2 files changed, 76 insertions(+), 29 deletions(-) diff --git a/src/nfv/commands.h b/src/nfv/commands.h index 06159ad..4b406ab 100644 --- a/src/nfv/commands.h +++ b/src/nfv/commands.h @@ -13,19 +13,9 @@ #define RTE_LOGTYPE_SPP_NFV RTE_LOGTYPE_USER1 static int -do_del(char *res_uid) +do_del(char *p_type, int p_id) { uint16_t port_id = PORT_RESET; - char *p_type; - int p_id; - int res; - - res = parse_resource_uid(res_uid, &p_type, &p_id); - if (res < 0) { - RTE_LOG(ERR, SPP_NFV, - "Failed to parse resource UID\n"); - return -1; - } if (!strcmp(p_type, "vhost")) { port_id = find_port_id(p_id, VHOST); @@ -65,17 +55,11 @@ do_del(char *res_uid) * combination of port type and ID like as 'ring:0'. */ static int -do_add(char *res_uid) +do_add(char *p_type, int p_id) { enum port_type type = UNDEF; uint16_t port_id = PORT_RESET; - char *p_type; - int p_id; - int res; - - res = parse_resource_uid(res_uid, &p_type, &p_id); - if (res < 0) - return -1; + int res = 0; if (!strcmp(p_type, "vhost")) { type = VHOST; @@ -152,11 +136,14 @@ parse_command(char *str) { uint16_t dev_id; char dev_name[RTE_DEV_NAME_MAX_LEN] = { 0 }; - - char *token_list[MAX_PARAMETER] = {NULL}; + char *token_list[MAX_PARAMETER] = { 0 }; int cli_id; int max_token = 0; int ret = 0; + char result[16] = { 0 }; /* succeeded or failed. */ + char port_set[32] = { 0 }; + char *p_type; + int p_id; if (!str) return 0; @@ -194,33 +181,66 @@ parse_command(char *str) } else if (!strcmp(token_list[0], "_get_client_id")) { memset(str, '\0', MSG_SIZE); + /** + * TODO(yasufum) revise result msg. 1) need both of `results` + * and `result`. 2) change `success` to `succeeded`. + */ sprintf(str, "{%s:%s,%s:%d,%s:%s}", "\"results\"", "[{\"result\":\"success\"}]", "\"client_id\"", get_client_id(), "\"process_type\"", "\"nfv\""); } else if (!strcmp(token_list[0], "_set_client_id")) { - if (spp_atoi(token_list[1], &cli_id) >= 0) + if (spp_atoi(token_list[1], &cli_id) >= 0) { set_client_id(cli_id); + sprintf(result, "%s", "\"succeeded\""); + } else + sprintf(result, "%s", "\"failed\""); + sprintf(str, "{%s:%s,%s:%s}", + "\"result\"", result, + "\"command\"", "\"_set_client_id\""); } else if (!strcmp(token_list[0], "exit")) { RTE_LOG(DEBUG, SPP_NFV, "exit\n"); - RTE_LOG(DEBUG, SPP_NFV, "stop\n"); cmd = STOP; ret = -1; + sprintf(str, "{%s:%s,%s:%s}", + "\"result\"", "\"succeeded\"", + "\"command\"", "\"exit\""); } else if (!strcmp(token_list[0], "stop")) { RTE_LOG(DEBUG, SPP_NFV, "stop\n"); cmd = STOP; + sprintf(str, "{%s:%s,%s:%s}", + "\"result\"", "\"succeeded\"", + "\"command\"", "\"stop\""); } else if (!strcmp(token_list[0], "forward")) { RTE_LOG(DEBUG, SPP_NFV, "forward\n"); cmd = FORWARD; + sprintf(str, "{%s:%s,%s:%s}", + "\"result\"", "\"succeeded\"", + "\"command\"", "\"forward\""); } else if (!strcmp(token_list[0], "add")) { RTE_LOG(DEBUG, SPP_NFV, "Received add command\n"); - if (do_add(token_list[1]) < 0) + + ret = parse_resource_uid(token_list[1], &p_type, &p_id); + if (ret < 0) + return ret; + + if (do_add(p_type, p_id) < 0) { RTE_LOG(ERR, SPP_NFV, "Failed to do_add()\n"); + sprintf(result, "%s", "\"failed\""); + } else + sprintf(result, "%s", "\"succeeded\""); + + sprintf(port_set, "\"%s:%d\"", p_type, p_id); + memset(str, '\0', MSG_SIZE); + sprintf(str, "{%s:%s,%s:%s,%s:%s}", + "\"result\"", result, + "\"command\"", "\"add\"", + "\"port\"", port_set); } else if (!strcmp(token_list[0], "patch")) { RTE_LOG(DEBUG, SPP_NFV, "patch\n"); @@ -276,14 +296,27 @@ parse_command(char *str) RTE_LOG(ERR, SPP_NFV, "%s\n", err_msg); } - if (add_patch(in_port, out_port) == 0) + if (add_patch(in_port, out_port) == 0) { RTE_LOG(INFO, SPP_NFV, "Patched '%s:%d' and '%s:%d'\n", in_p_type, in_p_id, out_p_type, out_p_id); - - else + sprintf(result, "%s", "\"succeeded\""); + } else { RTE_LOG(ERR, SPP_NFV, "Failed to patch\n"); + sprintf(result, "%s", "\"failed\""); + } + + sprintf(port_set, + "{\"src\":\"%s:%d\",\"dst\":\"%s:%d\"}", + in_p_type, in_p_id, out_p_type, out_p_id); + + memset(str, '\0', MSG_SIZE); + sprintf(str, "{%s:%s,%s:%s,%s:%s}", + "\"result\"", result, + "\"command\"", "\"patch\"", + "\"ports\"", port_set); + ret = 0; } @@ -292,8 +325,22 @@ parse_command(char *str) cmd = STOP; - if (do_del(token_list[1]) < 0) + ret = parse_resource_uid(token_list[1], &p_type, &p_id); + if (ret < 0) + return ret; + + if (do_del(p_type, p_id) < 0) { RTE_LOG(ERR, SPP_NFV, "Failed to do_del()\n"); + sprintf(result, "%s", "\"failed\""); + } else + sprintf(result, "%s", "\"succeeded\""); + + sprintf(port_set, "\"%s:%d\"", p_type, p_id); + memset(str, '\0', MSG_SIZE); + sprintf(str, "{%s:%s,%s:%s,%s:%s}", + "\"result\"", result, + "\"command\"", "\"del\"", + "\"port\"", port_set); } return ret; diff --git a/src/nfv/main.c b/src/nfv/main.c index 70a6aab..aa2dbc7 100644 --- a/src/nfv/main.c +++ b/src/nfv/main.c @@ -190,7 +190,7 @@ main(int argc, char *argv[]) unsigned int lcore_id; unsigned int nb_ports; int connected = 0; - char str[MSG_SIZE]; + char str[MSG_SIZE] = { 0 }; unsigned int i; int flg_exit; // used as res of parse_command() to exit if -1 int ret; -- 2.17.1