From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 1/2] spp_primary: add commands to add and del port
Date: Tue, 16 Jul 2019 16:30:56 +0900 [thread overview]
Message-ID: <20190716073057.18821-2-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190716073057.18821-1-yasufum.o@gmail.com>
From: Yasufumi Ogawa <yasufum.o@gmail.com>
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 <yasufum.o@gmail.com>
---
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
next prev parent reply other threads:[~2019-07-16 7:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-16 7:30 [spp] [PATCH 0/2] Add REST APIs for add or del port to spp_primary yasufum.o
2019-07-16 7:30 ` yasufum.o [this message]
2019-07-16 7:30 ` [spp] [PATCH 2/2] spp-ctl: add port add and del APIs for spp_primary yasufum.o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190716073057.18821-2-yasufum.o@gmail.com \
--to=yasufum.o@gmail.com \
--cc=ferruh.yigit@intel.com \
--cc=spp@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).