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 BE4C2A0471 for ; Tue, 16 Jul 2019 09:31:05 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B6E2D3423; Tue, 16 Jul 2019 09:31:05 +0200 (CEST) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 1165C3423 for ; Tue, 16 Jul 2019 09:31:05 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id u17so8989814pgi.6 for ; Tue, 16 Jul 2019 00:31:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=lC8gn7PySk2LE9KaXmX9OP/wvVChXEeJQFnFVbJCDtY=; b=mR//YMOSXPMjy+lntSmVz6iP6tpFH0vNw+lJRYectX1X4PQbJP8C6Ub9xevOr4gpIZ +bNHFybCtXrB1jNI+i6XW8DmNYw2xUBHNAoMZsU2QRT5j7OzKmXPaduIv4FPxOjB2GzZ ttuesfSHTlMpY6k4idDcfxvSaIOn5/1j+rk8s8UJX97i7L1HsHu86Jt5cL3myk3qLh0M PcY1m+qN9d4gW3uT5MdOa3ehv5KsxZnAIQAl/enY20d39e8oIPcKO0Nsab1pJhtXMDBn fMtS+ohy8W+J1Fhm6vhGmKceSkby/0YKrHIyhsA/ctuEcj6H7iAKvTFEmXvFBRLSqgDA k3kw== 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:in-reply-to :references; bh=lC8gn7PySk2LE9KaXmX9OP/wvVChXEeJQFnFVbJCDtY=; b=i+9btUCy2OorlRc7xP9ClRWGJ9s2ZVKcMFVO2w255APfJQzNDKrJU4HLvm+vc7szyL hG2FO1VaEbpgKVKFK22DwpEIpevqdHF9n1uHGTKOKUOm3d+O7GLRbqbqUCsC6Od+czgg XQY7paS7oNWrFHaLDju0oDkGRyGimxnktCJO/sv3QnduXEnrLLTPdf6iQAShSo1dl2Ra X4gK+Ilx32WqD2/3rfD0AKR1aPgcUzBnvoalrGH6eBf4frn1ZMqIItNJruv0U3/GQMHV e0+aJHQDfHsyqa/MdvTktOwTAWutXYNzYtOtFKmrUhi1BLH91YUk7p2uMvLFo1H7pSpk B6IQ== X-Gm-Message-State: APjAAAWiQ+chXYM3f5LfUspYWpleqYE5gj/fLSw9alhl/KU9f2CI/gNA WTwwBnybhNSRJJkZxPG5VRBqU2ph X-Google-Smtp-Source: APXvYqx53nkbQXXrSyHwS2Hhkz2fjPq1jrQweIaaEy0dSyNS2n9l3dE6e5xGj0L+mYVKSoPuFc0+Fw== X-Received: by 2002:a65:50c8:: with SMTP id s8mr25134041pgp.339.1563262263999; Tue, 16 Jul 2019 00:31:03 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id 185sm20086849pfd.125.2019.07.16.00.31.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 00:31:03 -0700 (PDT) From: yasufum.o@gmail.com To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Tue, 16 Jul 2019 16:30:56 +0900 Message-Id: <20190716073057.18821-2-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190716073057.18821-1-yasufum.o@gmail.com> References: <20190716073057.18821-1-yasufum.o@gmail.com> Subject: [spp] [PATCH 1/2] spp_primary: add commands to add and del port 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 This patch is to add commands for adding or deleting a port to spp_primary. REST APIs for the commands are added in the next patch. Signed-off-by: Yasufumi Ogawa --- src/nfv/commands.h | 2 +- src/primary/Makefile | 6 ++ src/primary/main.c | 179 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 181 insertions(+), 6 deletions(-) diff --git a/src/nfv/commands.h b/src/nfv/commands.h index 8f19f4e..7bdbdff 100644 --- a/src/nfv/commands.h +++ b/src/nfv/commands.h @@ -188,7 +188,7 @@ parse_command(char *str) RTE_ETH_FOREACH_DEV(dev_id) { rte_eth_dev_get_name_by_port(dev_id, dev_name); if (strlen(dev_name) > 0) - RTE_LOG(DEBUG, SPP_NFV, "Eth devs: %d\t%s\n", + RTE_LOG(DEBUG, SPP_NFV, "ethdevs:%2d %s\n", dev_id, dev_name); } diff --git a/src/primary/Makefile b/src/primary/Makefile index f348146..e524ef1 100644 --- a/src/primary/Makefile +++ b/src/primary/Makefile @@ -18,8 +18,14 @@ endif # binary name APP = spp_primary +# TODO: move add_port.c and parse_resource uid() in utils.c to shared +# dir and remove it. +SPP_SEC_DIR = ../shared/secondary + # all source are stored in SRCS-y SRCS-y := main.c init.c args.c ../shared/common.c +SRCS-y += $(SPP_SEC_DIR)/add_port.c +SRCS-y += $(SPP_SEC_DIR)/utils.c INC := $(wildcard *.h) diff --git a/src/primary/main.c b/src/primary/main.c index fc9ca9b..635cd71 100644 --- a/src/primary/main.c +++ b/src/primary/main.c @@ -17,6 +17,9 @@ #include "init.h" #include "primary.h" +#include "shared/secondary/add_port.h" +#include "shared/secondary/utils.h" + /* * Buffer sizes of status message of primary. Total number of size * must be equal to MSG_SIZE 2048 defined in `shared/common.h`. @@ -38,10 +41,19 @@ #define POLL_TIMEOUT_MS 100 -static sig_atomic_t on = 1; +/** + * Set of port id and type of resource UID, such as `vhost:1`. It is intended + * to be used for mapping to ethdev ID. as port_id_list. + */ +struct port_id_map { + int port_id; + enum port_type type; +}; -static enum cmd_type cmd = STOP; +struct port_id_map port_id_list[RTE_MAX_ETHPORTS]; +static sig_atomic_t on = 1; +static enum cmd_type cmd = STOP; static struct pollfd pfd; /* global var - extern in header */ @@ -170,7 +182,7 @@ do_send(int *connected, int *sock, char *str) ret = send(*sock, str, MSG_SIZE, 0); if (ret == -1) { - RTE_LOG(ERR, PRIMARY, "send failed"); + RTE_LOG(ERR, PRIMARY, "Failed to send\n"); *connected = 0; return -1; } @@ -221,8 +233,6 @@ launch_sec_proc(char *sec_name, int sec_id, char **sec_args) /* Tokenize path of spp_primary */ token_list[i] = strtok(path_spp_pri, "/"); while (token_list[i] != NULL) { - // RTE_LOG(DEBUG, PRIMARY, "token: %s\n", - // token_list[i]); i++; num_token++; token_list[i] = strtok(NULL, "/"); @@ -437,6 +447,128 @@ get_status_json(char *str) return 0; } +/** + * Add a port to spp_primary. Port is given as a resource UID which is a + * combination of port type and ID like as 'ring:0'. + */ +static int +add_port(char *res_uid) +{ + uint16_t dev_id; + char *p_type; + int p_id; + int res; + 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; + cnt += 1; + } + + if (!strcmp(p_type, "vhost")) { + res = add_vhost_pmd(p_id); + port_id_list[cnt].port_id = p_id; + port_id_list[cnt].type = VHOST; + + } else if (!strcmp(p_type, "ring")) { + res = add_ring_pmd(p_id); + port_id_list[cnt].port_id = p_id; + port_id_list[cnt].type = RING; + + } else if (!strcmp(p_type, "pcap")) { + res = add_pcap_pmd(p_id); + port_id_list[cnt].port_id = p_id; + port_id_list[cnt].type = PCAP; + + } else if (!strcmp(p_type, "nullpmd")) { + res = add_null_pmd(p_id); + port_id_list[cnt].port_id = p_id; + port_id_list[cnt].type = NULLPMD; + } + + if (res < 0) + return -1; + + return 0; +} + +/* Find ethdev ID from resource UID to delete. */ +static uint16_t +find_ethdev_id(int p_id, enum port_type ptype) +{ + int cnt; + struct port_id_map *p_map; + + RTE_LOG(DEBUG, PRIMARY, "Finding ethdev_id, p_id: %d, ptype: %d\n", + p_id, ptype); + + for (cnt = 0; cnt < RTE_MAX_ETHPORTS; cnt++) { + p_map = &port_id_list[cnt]; + if (p_map == NULL) + RTE_LOG(ERR, PRIMARY, "Failed to find port_id.\n"); + else { + if (p_map->port_id == p_id && + p_map->type == ptype) + return cnt; + } + } + + return PORT_RESET; +} + +/* Delete port. */ +static int +del_port(char *res_uid) +{ + 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); + if (dev_id == PORT_RESET) + return -1; + dev_detach_by_port_id(dev_id); + + } else if (!strcmp(p_type, "ring")) { + dev_id = find_ethdev_id(p_id, RING); + if (dev_id == PORT_RESET) + return -1; + rte_eth_dev_stop(dev_id); + rte_eth_dev_close(dev_id); + + } else if (!strcmp(p_type, "pcap")) { + dev_id = find_ethdev_id(p_id, PCAP); + if (dev_id == PORT_RESET) + return -1; + dev_detach_by_port_id(dev_id); + + } else if (!strcmp(p_type, "nullpmd")) { + dev_id = find_ethdev_id(p_id, NULLPMD); + if (dev_id == PORT_RESET) + return -1; + dev_detach_by_port_id(dev_id); + } + + port_id_list[dev_id].port_id = PORT_RESET; + port_id_list[dev_id].type = UNDEF; + + return 0; +} + static int parse_command(char *str) { @@ -445,6 +577,8 @@ parse_command(char *str) char *sec_args[NOF_TOKENS] = {NULL}; int ret = 0; int i = 0; + uint16_t dev_id; + char dev_name[RTE_DEV_NAME_MAX_LEN] = { 0 }; memset(sec_name, '\0', 16); @@ -469,6 +603,13 @@ parse_command(char *str) memset(str, '\0', MSG_SIZE); ret = get_status_json(str); + RTE_ETH_FOREACH_DEV(dev_id) { + rte_eth_dev_get_name_by_port(dev_id, dev_name); + if (strlen(dev_name) > 0) + RTE_LOG(DEBUG, PRIMARY, "Port list: %d\t%s\n", + dev_id, dev_name); + } + } else if (!strcmp(token_list[0], "launch")) { RTE_LOG(DEBUG, PRIMARY, "'%s' command received.\n", token_list[0]); @@ -476,6 +617,19 @@ parse_command(char *str) ret = launch_sec_proc(sec_name, strtod(token_list[1], NULL), sec_args); + } 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) + RTE_LOG(ERR, PRIMARY, "Failed to add_port()\n"); + + } else if (!strcmp(token_list[0], "del")) { + RTE_LOG(DEBUG, PRIMARY, "Received del command\n"); + cmd = STOP; + if (del_port(token_list[1]) < 0) + RTE_LOG(ERR, PRIMARY, "Failed to del_port()\n"); + } else if (!strcmp(token_list[0], "exit")) { RTE_LOG(DEBUG, PRIMARY, "'exit' command received.\n"); cmd = STOP; @@ -568,6 +722,8 @@ int main(int argc, char *argv[]) { int sock = SOCK_RESET; + uint16_t dev_id; + char dev_name[RTE_DEV_NAME_MAX_LEN] = { 0 }; int connected = 0; char str[MSG_SIZE]; int flg_exit; // used as res of parse_command() to exit if -1 @@ -587,6 +743,19 @@ main(int argc, char *argv[]) /* clear statistics */ clear_stats(); + memset(port_id_list, 0x00, + sizeof(struct port_id_map) * RTE_MAX_ETHPORTS); + for (dev_id = 0; dev_id < RTE_MAX_ETHPORTS; dev_id++) { + ret = rte_eth_dev_get_name_by_port(dev_id, dev_name); + if (ret > -1) { + port_id_list[dev_id].port_id = dev_id; + port_id_list[dev_id].type = PHY; + } else { + port_id_list[dev_id].port_id = PORT_RESET; + port_id_list[dev_id].type = UNDEF; + } + } + /* put all other cores to sleep bar master */ rte_eal_mp_remote_launch(sleep_lcore, NULL, SKIP_MASTER); -- 2.17.1