Soft Patch Panel
 help / color / Atom feed
* [spp] [PATCH] spp_nfv: move funcs for managing ports to shared
@ 2019-10-14 18:45 Yasufumi Ogawa
  0 siblings, 0 replies; only message in thread
From: Yasufumi Ogawa @ 2019-10-14 18:45 UTC (permalink / raw)
  To: spp, ferruh.yigit, yasufum.o

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 18:45 [spp] [PATCH] spp_nfv: move funcs for managing ports to shared Yasufumi Ogawa

Soft Patch Panel

Archives are clonable:
	git clone --mirror http://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ http://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp


Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/ public-inbox