Soft Patch Panel
 help / color / mirror / Atom feed
From: Yasufumi Ogawa <yasufum.o@gmail.com>
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH] spp_nfv: move funcs for managing ports to shared
Date: Tue, 15 Oct 2019 03:45:33 +0900	[thread overview]
Message-ID: <20191014184533.27001-1-yasufum.o@gmail.com> (raw)

This update is to move structs and functions for managing ports to
shared lib because enable to be used from other processes including
spp_primary.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 src/nfv/Makefile             |   2 +-
 src/nfv/init.h               |  34 --------
 src/nfv/main.c               |  12 +--
 src/nfv/params.h             |  16 ----
 src/shared/basic_forwarder.h |   6 +-
 src/shared/port_manager.c    | 158 +++++++++++++++++++++++++++++++++++
 src/shared/port_manager.h    | 117 ++++----------------------
 7 files changed, 185 insertions(+), 160 deletions(-)
 create mode 100644 src/shared/port_manager.c

diff --git a/src/nfv/Makefile b/src/nfv/Makefile
index a8b5629..c3d2806 100644
--- a/src/nfv/Makefile
+++ b/src/nfv/Makefile
@@ -14,7 +14,7 @@ APP = spp_nfv
 
 # all source are stored in SRCS-y
 SRCS-y := main.c nfv_status.c
-SRCS-y += ../shared/common.c ../shared/basic_forwarder.c
+SRCS-y += ../shared/common.c ../shared/basic_forwarder.c ../shared/port_manager.c
 SRCS-y += ../shared/secondary/common.c
 SRCS-y += ../shared/secondary/utils.c ../shared/secondary/add_port.c
 
diff --git a/src/nfv/init.h b/src/nfv/init.h
index 0702082..7d28755 100644
--- a/src/nfv/init.h
+++ b/src/nfv/init.h
@@ -6,39 +6,5 @@
 #ifndef _NFV_INIT_H_
 #define _NFV_INIT_H_
 
-static void
-forward_array_init_one(unsigned int i)
-{
-	ports_fwd_array[i].in_port_id = PORT_RESET;
-	ports_fwd_array[i].out_port_id = PORT_RESET;
-}
-
-/* initialize forward array with default value*/
-static void
-forward_array_init(void)
-{
-	unsigned int i;
-
-	/* initialize port forward array*/
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
-		forward_array_init_one(i);
-}
-
-static void
-port_map_init_one(unsigned int i)
-{
-	port_map[i].id = PORT_RESET;
-	port_map[i].port_type = UNDEF;
-	port_map[i].stats = &port_map[i].default_stats;
-}
-
-static void
-port_map_init(void)
-{
-	unsigned int i;
-
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
-		port_map_init_one(i);
-}
 
 #endif
diff --git a/src/nfv/main.c b/src/nfv/main.c
index ac82139..047d4c1 100644
--- a/src/nfv/main.c
+++ b/src/nfv/main.c
@@ -30,13 +30,13 @@ static sig_atomic_t on = 1;
 
 uint8_t lcore_id_used[RTE_MAX_LCORE] = {};
 
+/*
+ * Long options mapped to a short option.
+ *
+ * First long only option value must be >= 256, so that we won't
+ * conflict with short options.
+ */
 enum {
-	/*
-	 * Long options mapped to a short option.
-	 *
-	 * First long only option value must be >= 256, so that we won't
-	 * conflict with short options.
-	 */
 	CMD_LINE_OPT_MIN_NUM = 256,
 	CMD_OPT_ENABLE_VHOST_CLI,
 };
diff --git a/src/nfv/params.h b/src/nfv/params.h
index 7197baf..7529452 100644
--- a/src/nfv/params.h
+++ b/src/nfv/params.h
@@ -6,22 +6,6 @@
 #ifndef _NFV_PARAMS_H_
 #define _NFV_PARAMS_H_
 
-/* It is used to convert port name from string type to enum */
-struct porttype_map {
-	const char     *port_name;
-	enum port_type port_type;
-};
-
-struct porttype_map portmap[] = {
-	{ .port_name = "phy",   .port_type = PHY, },
-	{ .port_name = "ring",  .port_type = RING, },
-	{ .port_name = "vhost", .port_type = VHOST, },
-	{ .port_name = "pcap", .port_type = PCAP, },
-	{ .port_name = "nullpmd", .port_type = NULLPMD, },
-	{ .port_name = "tap", .port_type = TAP, },
-	{ .port_name = NULL,    .port_type = UNDEF, },
-};
-
 /* the port details */
 struct port_info *ports;
 
diff --git a/src/shared/basic_forwarder.h b/src/shared/basic_forwarder.h
index 173cab3..2e8225d 100644
--- a/src/shared/basic_forwarder.h
+++ b/src/shared/basic_forwarder.h
@@ -2,8 +2,10 @@
  * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
  */
 
-#ifndef __SHARED_FORWARDER_H__
-#define __SHARED_FORWARDER_H__
+#ifndef __SHARED_BASIC_FORWARDER_H__
+#define __SHARED_BASIC_FORWARDER_H__
+
+#include "shared/common.h"
 
 struct port_map port_map[RTE_MAX_ETHPORTS];
 struct port ports_fwd_array[RTE_MAX_ETHPORTS];
diff --git a/src/shared/port_manager.c b/src/shared/port_manager.c
new file mode 100644
index 0000000..98d89c2
--- /dev/null
+++ b/src/shared/port_manager.c
@@ -0,0 +1,158 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#include "shared/port_manager.h"
+
+struct porttype_map portmap[] = {
+	{ .port_name = "phy",   .port_type = PHY, },
+	{ .port_name = "ring",  .port_type = RING, },
+	{ .port_name = "vhost", .port_type = VHOST, },
+	{ .port_name = "pcap", .port_type = PCAP, },
+	{ .port_name = "nullpmd", .port_type = NULLPMD, },
+	{ .port_name = "tap", .port_type = TAP, },
+	{ .port_name = NULL,    .port_type = UNDEF, },
+};
+
+void
+forward_array_init_one(unsigned int i)
+{
+	ports_fwd_array[i].in_port_id = PORT_RESET;
+	ports_fwd_array[i].out_port_id = PORT_RESET;
+}
+
+/* initialize forward array with default value */
+void
+forward_array_init(void)
+{
+	unsigned int i;
+
+	/* initialize port forward array*/
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		forward_array_init_one(i);
+}
+
+void
+forward_array_reset(void)
+{
+	unsigned int i;
+
+	/* initialize port forward array*/
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+		if (ports_fwd_array[i].in_port_id != PORT_RESET) {
+			ports_fwd_array[i].out_port_id = PORT_RESET;
+			RTE_LOG(INFO, SHARED, "Port ID %d\n", i);
+			RTE_LOG(INFO, SHARED, "out_port_id %d\n",
+				ports_fwd_array[i].out_port_id);
+		}
+	}
+}
+
+void
+port_map_init_one(unsigned int i)
+{
+	port_map[i].id = PORT_RESET;
+	port_map[i].port_type = UNDEF;
+	port_map[i].stats = &port_map[i].default_stats;
+}
+
+void
+port_map_init(void)
+{
+	unsigned int i;
+
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		port_map_init_one(i);
+}
+
+/* Return -1 as an error if given patch is invalid */
+int
+add_patch(uint16_t in_port, uint16_t out_port)
+{
+	if (!is_valid_port(in_port) || !is_valid_port(out_port))
+		return -1;
+
+	/* Populate in port data */
+	ports_fwd_array[in_port].in_port_id = in_port;
+	ports_fwd_array[in_port].rx_func = &rte_eth_rx_burst;
+	ports_fwd_array[in_port].tx_func = &rte_eth_tx_burst;
+	ports_fwd_array[in_port].out_port_id = out_port;
+
+	/* Populate out port data */
+	ports_fwd_array[out_port].in_port_id = out_port;
+	ports_fwd_array[out_port].rx_func = &rte_eth_rx_burst;
+	ports_fwd_array[out_port].tx_func = &rte_eth_tx_burst;
+
+	RTE_LOG(DEBUG, SHARED, "STATUS: in port %d in_port_id %d\n", in_port,
+		ports_fwd_array[in_port].in_port_id);
+	RTE_LOG(DEBUG, SHARED, "STATUS: in port %d patch out port id %d\n",
+		in_port, ports_fwd_array[in_port].out_port_id);
+	RTE_LOG(DEBUG, SHARED, "STATUS: outport %d in_port_id %d\n", out_port,
+		ports_fwd_array[out_port].in_port_id);
+
+	return 0;
+}
+
+/*
+ * Return actual port ID which is assigned by system internally, or PORT_RESET
+ * if port is not found.
+ */
+uint16_t
+find_port_id(int id, enum port_type type)
+{
+	uint16_t port_id = PORT_RESET;
+	uint16_t i;
+
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+		if (port_map[i].port_type != type)
+			continue;
+
+		if (port_map[i].id == id) {
+			port_id = i;
+			break;
+		}
+	}
+
+	return port_id;
+}
+
+/* Return 0 if invalid */
+int
+is_valid_port(uint16_t port_id)
+{
+	if (port_id > RTE_MAX_ETHPORTS)
+		return 0;
+
+	return port_map[port_id].id != PORT_RESET;
+}
+
+void
+forward_array_remove(int port_id)
+{
+	unsigned int i;
+
+	/* Update ports_fwd_array */
+	forward_array_init_one(port_id);
+
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+		if (ports_fwd_array[i].in_port_id == PORT_RESET)
+			continue;
+
+		if (ports_fwd_array[i].out_port_id == port_id) {
+			ports_fwd_array[i].out_port_id = PORT_RESET;
+			break;
+		}
+	}
+}
+
+/* Return a type of port as a enum member of porttype_map structure. */
+enum port_type get_port_type(char *portname)
+{
+	int i;
+	for (i = 0; portmap[i].port_name != NULL; i++) {
+		const char *port_name = portmap[i].port_name;
+		if (strncmp(portname, port_name, strlen(port_name)) == 0)
+			return portmap[i].port_type;
+	}
+	return UNDEF;
+}
diff --git a/src/shared/port_manager.h b/src/shared/port_manager.h
index 9756864..c529998 100644
--- a/src/shared/port_manager.h
+++ b/src/shared/port_manager.h
@@ -10,112 +10,27 @@
 
 #include "shared/basic_forwarder.h"
 
-static void
-forward_array_remove(int port_id)
-{
-	unsigned int i;
+/* It is used to convert port name from string type to enum */
+struct porttype_map {
+	const char     *port_name;
+	enum port_type port_type;
+};
 
-	/* Update ports_fwd_array */
-	forward_array_init_one(port_id);
+/* initialize forward array with default value */
+void forward_array_init_one(unsigned int i);
+void forward_array_init(void);
+void forward_array_reset(void);
+void forward_array_remove(int port_id);
 
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (ports_fwd_array[i].in_port_id == PORT_RESET)
-			continue;
+void port_map_init_one(unsigned int i);
+void port_map_init(void);
 
-		if (ports_fwd_array[i].out_port_id == port_id) {
-			ports_fwd_array[i].out_port_id = PORT_RESET;
-			break;
-		}
-	}
-}
+enum port_type get_port_type(char *portname);
 
-/* Return 0 if invalid */
-static int
-is_valid_port(uint16_t port_id)
-{
-	if (port_id > RTE_MAX_ETHPORTS)
-		return 0;
+int add_patch(uint16_t in_port, uint16_t out_port);
 
-	return port_map[port_id].id != PORT_RESET;
-}
+uint16_t find_port_id(int id, enum port_type type);
 
-/*
- * Return actual port ID which is assigned by system internally, or PORT_RESET
- * if port is not found.
- */
-static uint16_t
-find_port_id(int id, enum port_type type)
-{
-	uint16_t port_id = PORT_RESET;
-	uint16_t i;
-
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (port_map[i].port_type != type)
-			continue;
-
-		if (port_map[i].id == id) {
-			port_id = i;
-			break;
-		}
-	}
-
-	return port_id;
-}
-
-/* Return -1 as an error if given patch is invalid */
-static int
-add_patch(uint16_t in_port, uint16_t out_port)
-{
-	if (!is_valid_port(in_port) || !is_valid_port(out_port))
-		return -1;
-
-	/* Populate in port data */
-	ports_fwd_array[in_port].in_port_id = in_port;
-	ports_fwd_array[in_port].rx_func = &rte_eth_rx_burst;
-	ports_fwd_array[in_port].tx_func = &rte_eth_tx_burst;
-	ports_fwd_array[in_port].out_port_id = out_port;
-
-	/* Populate out port data */
-	ports_fwd_array[out_port].in_port_id = out_port;
-	ports_fwd_array[out_port].rx_func = &rte_eth_rx_burst;
-	ports_fwd_array[out_port].tx_func = &rte_eth_tx_burst;
-
-	RTE_LOG(DEBUG, SHARED, "STATUS: in port %d in_port_id %d\n", in_port,
-		ports_fwd_array[in_port].in_port_id);
-	RTE_LOG(DEBUG, SHARED, "STATUS: in port %d patch out port id %d\n",
-		in_port, ports_fwd_array[in_port].out_port_id);
-	RTE_LOG(DEBUG, SHARED, "STATUS: outport %d in_port_id %d\n", out_port,
-		ports_fwd_array[out_port].in_port_id);
-
-	return 0;
-}
-
-static void
-forward_array_reset(void)
-{
-	unsigned int i;
-
-	/* initialize port forward array*/
-	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-		if (ports_fwd_array[i].in_port_id != PORT_RESET) {
-			ports_fwd_array[i].out_port_id = PORT_RESET;
-			RTE_LOG(INFO, SHARED, "Port ID %d\n", i);
-			RTE_LOG(INFO, SHARED, "out_port_id %d\n",
-				ports_fwd_array[i].out_port_id);
-		}
-	}
-}
-
-/* Return a type of port as a enum member of porttype_map structure. */
-static enum port_type get_port_type(char *portname)
-{
-	int i;
-	for (i = 0; portmap[i].port_name != NULL; i++) {
-		const char *port_name = portmap[i].port_name;
-		if (strncmp(portname, port_name, strlen(port_name)) == 0)
-			return portmap[i].port_type;
-	}
-	return UNDEF;
-}
+int is_valid_port(uint16_t port_id);
 
 #endif  // __SHARED_PORT_MANAGER_H__
-- 
2.17.1


                 reply	other threads:[~2019-10-14 18:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20191014184533.27001-1-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).