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 14E09A046B for ; Thu, 25 Jul 2019 13:26:10 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0D65B1C309; Thu, 25 Jul 2019 13:26:10 +0200 (CEST) Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by dpdk.org (Postfix) with ESMTP id 88B411BF6B for ; Thu, 25 Jul 2019 13:26:06 +0200 (CEST) Received: by mail-pl1-f196.google.com with SMTP id 4so16319585pld.10 for ; Thu, 25 Jul 2019 04:26:06 -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=c/ctA3ZwUlcC+U6FcRD2DTIce8aERXWSIUFB/Ginj0s=; b=gtvk1fwI6uJiBRw06r0EmKneGitfnM6yjgjl1Y2ORU+36ruUQF2qNHFeglvzReQXCH Qw9h0yyR20Blqyt+zM7NBY4CCcZYyBoUPK2A9wqYeERHCDo6YxT/a8OchlNDX0thdRA8 3qb5XPkKSnxfLRwcL5pjhnqtrQl3yXkwTpWvoY2wSgB8CzI0Ou7BAU6wyR7O/NbUFU2v LOkJKQCW6of+UFztp7mwsFwFxMTipVTPXihHYV2+mGO6uT+YdSsaU+jGCWYYU2QvYbxJ lkcXvPe+wyO/wPK7cUmA7I5iwnENPWtwrmQ2+Aq32s4+xeJpXQlGYXed0SeA0AQe1/LG E4IA== 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=c/ctA3ZwUlcC+U6FcRD2DTIce8aERXWSIUFB/Ginj0s=; b=Dl/h4LFQ+8T08LW3NoMiWpvLwfsyiU/VG8xtRdA3qkCAVaDwe0bIWbN26s5hEe/iQ/ stTOLNdrr/QktTjC91jCOuf3lK1RWG5DJtVvaxfJseUyRiBdhPE5oWISgw2CQIJl2FFb /8NBoN1t3pFkriTtUrDxxlkxKURjJKl3NWsuf+mbCbG34rhK3CziK34EPAXPZ+y9GpuB 0nBV1kMpYpcOhOev6q2His7Z/lutcpl7zr4BGqzLFIgd+iHBl7jR7/S4AwBerUsNzBa2 tvM1PMFAy0zaF2LqUzrhpUx9X5+WsE2BfD4i4aUpV+L5iDLb7H6gvTqwIXFxFazgrFsk TFLA== X-Gm-Message-State: APjAAAWMxAKPqSfBvPnUKtw3LpZGmzgeNDVL42hnhxV7dDPO5qyi8rWp DSDD9/JQx5uVlo+7/jBHf7ny+9Tt X-Google-Smtp-Source: APXvYqwj9CP/6CGGmuObGtOY5fv2SyJ0gLpUu/rCkcFNQ3oY+xUsaviIUemHlpxTgDzDz1hjxkJCiQ== X-Received: by 2002:a17:902:7202:: with SMTP id ba2mr91922272plb.266.1564053965719; Thu, 25 Jul 2019 04:26:05 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id m20sm50882361pff.79.2019.07.25.04.26.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Jul 2019 04:26:05 -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:26:01 +0900 Message-Id: <20190725112601.27436-1-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [spp] [PATCH] spp_primary: 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_primary does not return to JSON message without to `status` 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/primary/main.c | 91 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 24 deletions(-) diff --git a/src/primary/main.c b/src/primary/main.c index 635cd71..55bb532 100644 --- a/src/primary/main.c +++ b/src/primary/main.c @@ -192,7 +192,7 @@ do_send(int *connected, int *sock, char *str) return 0; } -/* +/** * Launch secondary process of given name and ID. * * This function finds the path of secondary by using the path of spp_primary @@ -230,6 +230,10 @@ launch_sec_proc(char *sec_name, int sec_id, char **sec_args) RTE_LOG(INFO, PRIMARY, "Failed to find exec file of spp_primary.\n"); else { + /** + * TODO(yasufum) confirm that log dir and helper tool are + * existing. + */ /* Tokenize path of spp_primary */ token_list[i] = strtok(path_spp_pri, "/"); while (token_list[i] != NULL) { @@ -452,18 +456,12 @@ get_status_json(char *str) * combination of port type and ID like as 'ring:0'. */ static int -add_port(char *res_uid) +add_port(char *p_type, int p_id) { uint16_t dev_id; - char *p_type; - int p_id; - int res; + int res = 0; uint16_t cnt = 0; - res = parse_resource_uid(res_uid, &p_type, &p_id); - if (res < 0) - return -1; - for (dev_id = 0; dev_id < RTE_MAX_ETHPORTS; dev_id++) { if (port_id_list[dev_id].port_id == PORT_RESET) break; @@ -523,19 +521,9 @@ find_ethdev_id(int p_id, enum port_type ptype) /* Delete port. */ static int -del_port(char *res_uid) +del_port(char *p_type, int p_id) { uint16_t dev_id = 0; - char *p_type; - int p_id; - int res; - - res = parse_resource_uid(res_uid, &p_type, &p_id); - if (res < 0) { - RTE_LOG(ERR, PRIMARY, - "Failed to parse resource UID\n"); - return -1; - } if (!strcmp(p_type, "vhost")) { dev_id = find_ethdev_id(p_id, VHOST); @@ -579,6 +567,10 @@ parse_command(char *str) int i = 0; uint16_t dev_id; char dev_name[RTE_DEV_NAME_MAX_LEN] = { 0 }; + char result[16] = { 0 }; /* succeeded or failed. */ + char port_set[32] = { 0 }; + char *p_type; + int p_id; memset(sec_name, '\0', 16); @@ -603,6 +595,7 @@ parse_command(char *str) memset(str, '\0', MSG_SIZE); ret = get_status_json(str); + /* Output all of ports under management for debugging. */ RTE_ETH_FOREACH_DEV(dev_id) { rte_eth_dev_get_name_by_port(dev_id, dev_name); if (strlen(dev_name) > 0) @@ -617,27 +610,77 @@ parse_command(char *str) ret = launch_sec_proc(sec_name, strtod(token_list[1], NULL), sec_args); + if (ret < 0) { + RTE_LOG(ERR, PRIMARY, "Failed to launch secondary.\n"); + sprintf(result, "%s", "\"failed\""); + } else + sprintf(result, "%s", "\"succeeded\""); + + memset(str, '\0', MSG_SIZE); + sprintf(str, "{%s:%s,%s:%s}", + "\"result\"", result, + "\"command\"", "\"launch\""); + } else if (!strcmp(token_list[0], "add")) { RTE_LOG(DEBUG, PRIMARY, "'%s' command received.\n", token_list[0]); - if (add_port(token_list[1]) < 0) + ret = parse_resource_uid(token_list[1], &p_type, &p_id); + if (ret < 0) { + RTE_LOG(ERR, PRIMARY, "Failed to parse RES UID.\n"); + return ret; + } + + if (add_port(p_type, p_id) < 0) { RTE_LOG(ERR, PRIMARY, "Failed to add_port()\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], "del")) { RTE_LOG(DEBUG, PRIMARY, "Received del command\n"); - cmd = STOP; - if (del_port(token_list[1]) < 0) + + ret = parse_resource_uid(token_list[1], &p_type, &p_id); + if (ret < 0) { + RTE_LOG(ERR, PRIMARY, "Failed to parse RES UID.\n"); + return ret; + } + + if (del_port(p_type, p_id) < 0) { RTE_LOG(ERR, PRIMARY, "Failed to del_port()\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); } else if (!strcmp(token_list[0], "exit")) { RTE_LOG(DEBUG, PRIMARY, "'exit' command received.\n"); cmd = STOP; ret = -1; + memset(str, '\0', MSG_SIZE); + sprintf(str, "{%s:%s,%s:%s}", + "\"result\"", "\"succeeded\"", + "\"command\"", "\"exit\""); } else if (!strcmp(token_list[0], "clear")) { - sprintf(str, "{\"status\": \"cleared\"}"); clear_stats(); + memset(str, '\0', MSG_SIZE); + sprintf(str, "{%s:%s,%s:%s}", + "\"result\"", "\"succeeded\"", + "\"command\"", "\"clear\""); } return ret; -- 2.17.1