Soft Patch Panel
 help / color / mirror / Atom feed
From: x-fn-spp@sl.ntt-tx.co.jp
To: ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp
Cc: spp@dpdk.org
Subject: [spp] [PATCH 07/23] spp_vf: move functions for decode to common dir
Date: Wed, 21 Nov 2018 10:35:42 +0900	[thread overview]
Message-ID: <201811210136.wAL1a0O3009620@imss03.silk.ntt-tx.co.jp> (raw)
In-Reply-To: <20181121013558.8869-1-x-fn-spp@sl.ntt-tx.co.jp>

From: Hideyuki Yamashita <yamashita.hideyuki@po.ntt-tx.co.jp>

Move functions for decode to common directory.

This patch also refactors code on following point.
  change of a function name.
   - from spp_get_iface_index() to spp_convert_port_to_iface()
   - from spp_change_component_type() to spp_convert_component_type()

Signed-off-by: Hideyuki Yamashita <yamashita.hideyuki@po.ntt-tx.co.jp>
Signed-off-by: Naoki Takada <takada.naoki@lab.ntt.co.jp>
---
 src/vf/common/command_dec.c | 113 +++++++++++++++++++++++++++++++++++-
 src/vf/spp_vf.c             | 108 ----------------------------------
 src/vf/spp_vf.h             |  74 -----------------------
 3 files changed, 110 insertions(+), 185 deletions(-)

diff --git a/src/vf/common/command_dec.c b/src/vf/common/command_dec.c
index 5275f4f..35066c2 100644
--- a/src/vf/common/command_dec.c
+++ b/src/vf/common/command_dec.c
@@ -64,6 +64,112 @@ const char *PORT_ABILITY_STRINGS[] = {
 	/* termination */ "",
 };
 
+/* Get component type being updated on target core */
+static enum spp_component_type
+spp_get_component_type_update(unsigned int lcore_id)
+{
+	struct core_mng_info *info = &g_core_info[lcore_id];
+	return info->core[info->upd_index].type;
+}
+
+/* Check mac address used on the port for registering or removing */
+static int
+spp_check_classid_used_port(
+		int vid, uint64_t mac_addr,
+		enum port_type iface_type, int iface_no)
+{
+	struct spp_port_info *port_info = get_iface_info(iface_type, iface_no);
+
+	/**
+	 * return true if given mac_addr/vid matches
+	 *  with that of port_info/vid
+	 */
+	return ((mac_addr == port_info->class_id.mac_addr) &&
+		(vid == port_info->class_id.vlantag.vid));
+}
+
+/* Check if port has been added. */
+static int
+spp_check_added_port(enum port_type iface_type, int iface_no)
+{
+	struct spp_port_info *port = get_iface_info(iface_type, iface_no);
+	return port->iface_type != UNDEF;
+}
+
+/**
+ * Separate port id of combination of iface type and number and
+ * assign to given argument, iface_type and iface_no.
+ *
+ * For instance, 'ring:0' is separated to 'ring' and '0'.
+ */
+static int
+spp_convert_port_to_iface(const char *port,
+		    enum port_type *iface_type,
+		    int *iface_no)
+{
+	enum port_type type = UNDEF;
+	const char *no_str = NULL;
+	char *endptr = NULL;
+
+	/* Find out which type of interface from port */
+	if (strncmp(port, SPP_IFTYPE_NIC_STR ":",
+			strlen(SPP_IFTYPE_NIC_STR)+1) == 0) {
+		/* NIC */
+		type = PHY;
+		no_str = &port[strlen(SPP_IFTYPE_NIC_STR)+1];
+	} else if (strncmp(port, SPP_IFTYPE_VHOST_STR ":",
+			strlen(SPP_IFTYPE_VHOST_STR)+1) == 0) {
+		/* VHOST */
+		type = VHOST;
+		no_str = &port[strlen(SPP_IFTYPE_VHOST_STR)+1];
+	} else if (strncmp(port, SPP_IFTYPE_RING_STR ":",
+			strlen(SPP_IFTYPE_RING_STR)+1) == 0) {
+		/* RING */
+		type = RING;
+		no_str = &port[strlen(SPP_IFTYPE_RING_STR)+1];
+	} else {
+		/* OTHER */
+		RTE_LOG(ERR, APP, "Unknown interface type. (port = %s)\n",
+				port);
+		return -1;
+	}
+
+	/* Change type of number of interface */
+	int ret_no = strtol(no_str, &endptr, 0);
+	if (unlikely(no_str == endptr) || unlikely(*endptr != '\0')) {
+		/* No IF number */
+		RTE_LOG(ERR, APP, "No interface number. (port = %s)\n", port);
+		return -1;
+	}
+
+	*iface_type = type;
+	*iface_no = ret_no;
+
+	RTE_LOG(DEBUG, APP, "Port = %s => Type = %d No = %d\n",
+			port, *iface_type, *iface_no);
+	return 0;
+}
+
+/* Convert component name to component type */
+static enum spp_component_type
+spp_convert_component_type(const char *type_str)
+{
+	if (strncmp(type_str, CORE_TYPE_CLASSIFIER_MAC_STR,
+			strlen(CORE_TYPE_CLASSIFIER_MAC_STR)+1) == 0) {
+		/* Classifier */
+		return SPP_COMPONENT_CLASSIFIER_MAC;
+	} else if (strncmp(type_str, CORE_TYPE_MERGE_STR,
+			strlen(CORE_TYPE_MERGE_STR)+1) == 0) {
+		/* Merger */
+		return SPP_COMPONENT_MERGE;
+	} else if (strncmp(type_str, CORE_TYPE_FORWARD_STR,
+			strlen(CORE_TYPE_FORWARD_STR)+1) == 0) {
+		/* Forwarder */
+		return SPP_COMPONENT_FORWARD;
+	}
+	return SPP_COMPONENT_UNUSE;
+}
+
 /* set decode error */
 inline int
 set_decode_error(struct spp_command_decode_error *error,
@@ -179,7 +285,8 @@ decode_port_value(void *output, const char *arg_val)
 {
 	int ret = 0;
 	struct spp_port_index *port = output;
-	ret = spp_get_iface_index(arg_val, &port->iface_type, &port->iface_no);
+	ret = spp_convert_port_to_iface(arg_val, &port->iface_type,
+							&port->iface_no);
 	if (unlikely(ret != 0)) {
 		RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad port. val=%s\n", arg_val);
 		return -1;
@@ -273,7 +380,7 @@ decode_component_type_value(void *output, const char *arg_val)
 	if (component->action != SPP_CMD_ACTION_START)
 		return 0;
 
-	set_type = spp_get_component_type(arg_val);
+	set_type = spp_convert_component_type(arg_val);
 	if (unlikely(set_type <= 0)) {
 		RTE_LOG(ERR, SPP_COMMAND_PROC,
 				"Unknown component type. val=%s\n",
@@ -392,7 +499,7 @@ decode_port_name_value(void *output, const char *arg_val)
 	return decode_str_value(output, arg_val);
 }
 
-#/* decoding procedure of port ability for port command */
+/* decoding procedure of port ability for port command */
 static int
 decode_port_ability_value(void *output, const char *arg_val)
 {
diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c
index 62ceb20..f086eaf 100644
--- a/src/vf/spp_vf.c
+++ b/src/vf/spp_vf.c
@@ -183,15 +183,6 @@ parse_app_args(int argc, char *argv[])
 	return 0;
 }
 
-/* Get component type being updated on target core */
-enum spp_component_type
-spp_get_component_type_update(unsigned int lcore_id)
-{
-	struct core_mng_info *info = &g_core_info[lcore_id];
-	return info->core[info->upd_index].type;
-}
-
-
 /* Main process of slave core */
 static int
 slave_main(void *arg __attribute__ ((unused)))
@@ -389,29 +380,6 @@ spp_get_client_id(void)
 	return g_startup_param.client_id;
 }
 
-/**
- * Check mac address used on the port for registering or removing
- */
-int
-spp_check_classid_used_port(
-		int vid, uint64_t mac_addr,
-		enum port_type iface_type, int iface_no)
-{
-	struct spp_port_info *port_info = get_iface_info(iface_type, iface_no);
-	return ((mac_addr == port_info->class_id.mac_addr) &&
-			(vid == port_info->class_id.vlantag.vid));
-}
-
-/*
- * Check if port has been added.
- */
-int
-spp_check_added_port(enum port_type iface_type, int iface_no)
-{
-	struct spp_port_info *port = get_iface_info(iface_type, iface_no);
-	return port->iface_type != UNDEF;
-}
-
 /*
  * Check if port has been flushed.
  */
@@ -795,79 +763,3 @@ spp_get_dpdk_port(enum port_type iface_type, int iface_no)
 		return -1;
 	}
 }
-
-/**
- * Separate port id of combination of iface type and number and
- * assign to given argument, iface_type and iface_no.
- *
- * For instance, 'ring:0' is separated to 'ring' and '0'.
- */
-int
-spp_get_iface_index(const char *port,
-		    enum port_type *iface_type,
-		    int *iface_no)
-{
-	enum port_type type = UNDEF;
-	const char *no_str = NULL;
-	char *endptr = NULL;
-
-	/* Find out which type of interface from port */
-	if (strncmp(port, SPP_IFTYPE_NIC_STR ":",
-			strlen(SPP_IFTYPE_NIC_STR)+1) == 0) {
-		/* NIC */
-		type = PHY;
-		no_str = &port[strlen(SPP_IFTYPE_NIC_STR)+1];
-	} else if (strncmp(port, SPP_IFTYPE_VHOST_STR ":",
-			strlen(SPP_IFTYPE_VHOST_STR)+1) == 0) {
-		/* VHOST */
-		type = VHOST;
-		no_str = &port[strlen(SPP_IFTYPE_VHOST_STR)+1];
-	} else if (strncmp(port, SPP_IFTYPE_RING_STR ":",
-			strlen(SPP_IFTYPE_RING_STR)+1) == 0) {
-		/* RING */
-		type = RING;
-		no_str = &port[strlen(SPP_IFTYPE_RING_STR)+1];
-	} else {
-		/* OTHER */
-		RTE_LOG(ERR, APP, "Unknown interface type. (port = %s)\n",
-				port);
-		return -1;
-	}
-
-	/* Change type of number of interface */
-	int ret_no = strtol(no_str, &endptr, 0);
-	if (unlikely(no_str == endptr) || unlikely(*endptr != '\0')) {
-		/* No IF number */
-		RTE_LOG(ERR, APP, "No interface number. (port = %s)\n", port);
-		return -1;
-	}
-
-	*iface_type = type;
-	*iface_no = ret_no;
-
-	RTE_LOG(DEBUG, APP, "Port = %s => Type = %d No = %d\n",
-			port, *iface_type, *iface_no);
-	return 0;
-}
-
-/**
- * Return the type of forwarder as a member of enum of spp_component_type
- */
-enum spp_component_type
-spp_change_component_type(const char *type_str)
-{
-	if (strncmp(type_str, CORE_TYPE_CLASSIFIER_MAC_STR,
-			 strlen(CORE_TYPE_CLASSIFIER_MAC_STR)+1) == 0) {
-		/* Classifier */
-		return SPP_COMPONENT_CLASSIFIER_MAC;
-	} else if (strncmp(type_str, CORE_TYPE_MERGE_STR,
-			 strlen(CORE_TYPE_MERGE_STR)+1) == 0) {
-		/* Merger */
-		return SPP_COMPONENT_MERGE;
-	} else if (strncmp(type_str, CORE_TYPE_FORWARD_STR,
-			 strlen(CORE_TYPE_FORWARD_STR)+1) == 0) {
-		/* Forwarder */
-		return SPP_COMPONENT_FORWARD;
-	}
-	return SPP_COMPONENT_UNUSE;
-}
diff --git a/src/vf/spp_vf.h b/src/vf/spp_vf.h
index 1d05e66..1a49847 100644
--- a/src/vf/spp_vf.h
+++ b/src/vf/spp_vf.h
@@ -131,51 +131,6 @@ int spp_iterate_core_info(struct spp_iterate_core_params *params);
 int spp_iterate_classifier_table(
 		struct spp_iterate_classifier_table_params *params);
 
-/**
- * Get component type being updated on target core
- *
- * @param lcore_id
- *  Logical core ID.
- *
- * @return
- *  Type of component that will be executed on
- *  specified logical core after update.
- */
-enum spp_component_type spp_get_component_type_update(unsigned int lcore_id);
-
-/**
- * Check mac address used on the port for registering or removing
- *
- * @param vid
- *  VLAN ID to be validated.
- * @param mac_addr
- *  Mac address to be validated.
- * @param iface_type
- *  Interface to be validated.
- * @param iface_no
- *  Interface number to be validated.
- *
- * @return
- *  True if target identifier(VLAN ID, MAC address)
- *  matches identifier(VLAN ID, MAC address) of port.
- */
-int spp_check_classid_used_port(
-		int vid, uint64_t mac_addr,
-		enum port_type iface_type, int iface_no);
-
-/**
- * Check if port has been added.
- *
- * @param iface_type
- *  Interface to be validated.
- * @param iface_no
- *  Interface number to be validated.
- *
- * @return
- *  True if port has been added.
- */
-int spp_check_added_port(enum port_type iface_type, int iface_no);
-
 /**
  * Check if port has been flushed.
  *
@@ -202,33 +157,4 @@ int spp_check_flush_port(enum port_type iface_type, int iface_no);
  */
 int spp_get_dpdk_port(enum port_type iface_type, int iface_no);
 
-/**
- * Extract if-type/if-number from port string
- *
- * @param port
- *  Character string expressing the port, e.g. "phy:0","ring:1"
- * @param iface_type
- *  Interface type obtained from port.
- * @param iface_no
- *  Interface number obtained from port.
- *
- * @retval 0  succeeded.
- * @retval -1 failed.
- */
-int spp_get_iface_index(
-		const char *port,
-		enum port_type *iface_type,
-		int *iface_no);
-
-/**
- * Change component type from string to type value.
- *
- * @param type_str
- *  Name string for each component
- *
- * @return
- *  Component type corresponding to type_str.
- */
-enum spp_component_type spp_change_component_type(const char *type_str);
-
 #endif /* __SPP_VF_H__ */
-- 
2.18.0

  parent reply	other threads:[~2018-11-21  1:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20181121013558.8869-1-x-fn-spp@sl.ntt-tx.co.jp>
2018-11-21  1:35 ` [spp] [PATCH 01/23] spp_vf: fix invalid code for max chars x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 02/23] spp_vf: move common source and header files x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 03/23] spp_vf: change include path x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 04/23] spp_vf: update Makefile for common files x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 05/23] spp_vf: move functions to common directory x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 06/23] spp_vf: move defines to common dir x-fn-spp
2018-11-21  1:35 ` x-fn-spp [this message]
2018-11-21  1:35 ` [spp] [PATCH 08/23] spp_vf: move defines for decode " x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 09/23] spp_vf: move functions to command_proc.c x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 10/23] spp_vf: add management data registration x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 11/23] spp_vf: change reference of management data x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 12/23] spp_vf: change return values to explain result x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 13/23] spp_vf: define terms of commands as consts x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 14/23] spp_vf: remove unnecessary includes x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 15/23] spp_vf: add include header files x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 16/23] spp_vf: update comments for header file x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 17/23] spp_vf: update makefile of spp_vf x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 18/23] spp_vf: add check num of ports before forwarding x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 19/23] spp_vf: add flag for classifier table x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 20/23] spp_vf: add checking the number of ports x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 21/23] spp_vf: add vlantag command check flag x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 22/23] spp_vf: simplify changing VLAN tag x-fn-spp
2018-11-21  1:35 ` [spp] [PATCH 23/23] spp_vf: add SPP_VF_MODULE preprocessor directive x-fn-spp

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=201811210136.wAL1a0O3009620@imss03.silk.ntt-tx.co.jp \
    --to=x-fn-spp@sl.ntt-tx.co.jp \
    --cc=ferruh.yigit@intel.com \
    --cc=ogawa.yasufumi@lab.ntt.co.jp \
    --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).