Soft Patch Panel
 help / color / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 11/11] shared/sec: refactor setup cls table stat in JSON
Date: Mon, 24 Jun 2019 11:25:04 +0900
Message-ID: <20190624022504.18752-12-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190624022504.18752-1-yasufum.o@gmail.com>

From: Yasufumi Ogawa <yasufum.o@gmail.com>

This update is to refactor setting up a list of entries in classifier
table for `status` command. Names of function for setting up JSON are
revised, but still hard to understand the features.
append_classifier_table() for setting up the entries calls several
nested functions as in the following order.

  append_classifier_table()  // This function.
    -> add_classifier_table()  // Wrapper and doesn't almost nothing.
      -> add_classifier_table_val()  // Setup data and call iterator.
        -> iterate_adding_mac_entry()

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 .../secondary/spp_worker_th/cmd_parser.c      |  2 +-
 .../secondary/spp_worker_th/cmd_runner.c      | 25 ++++++--
 .../secondary/spp_worker_th/cmd_utils.h       |  2 +-
 src/shared/secondary/spp_worker_th/vf_deps.h  |  8 ++-
 src/vf/classifier_mac.c                       | 64 +++++++++++--------
 src/vf/classifier_mac.h                       |  2 +-
 6 files changed, 67 insertions(+), 36 deletions(-)

diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.c b/src/shared/secondary/spp_worker_th/cmd_parser.c
index 55fc1d2..13e7013 100644
--- a/src/shared/secondary/spp_worker_th/cmd_parser.c
+++ b/src/shared/secondary/spp_worker_th/cmd_parser.c
@@ -651,7 +651,7 @@ parse_mac_addr(void *output, const char *arg_val,
 	const char *str_val = arg_val;
 
 	/* If given value is the default, use dummy address instead. */
-	if (unlikely(strcmp(str_val, SPP_DEFAULT_CLASSIFIED_SPEC_STR) == 0))
+	if (unlikely(strcmp(str_val, SPPWK_TERM_DEFAULT) == 0))
 		str_val = SPP_DEFAULT_CLASSIFIED_DMY_ADDR_STR;
 
 	/* Check if the given value is valid. */
diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c
index 856e79e..bc3ae06 100644
--- a/src/shared/secondary/spp_worker_th/cmd_runner.c
+++ b/src/shared/secondary/spp_worker_th/cmd_runner.c
@@ -561,12 +561,12 @@ spp_iterate_core_info(struct spp_iterate_core_params *params)
 /* Iterate classifier_table to create response to status command */
 #ifdef SPP_VF_MODULE
 static int
-spp_iterate_classifier_table(
+add_classifier_table(
 		struct spp_iterate_classifier_table_params *params)
 {
 	int ret;
 
-	ret = spp_classifier_mac_iterate_table(params);
+	ret = add_classifier_table_val(params);
 	if (unlikely(ret != 0)) {
 		RTE_LOG(ERR, WK_CMD_RUNNER, "Cannot iterate classifier_mac_table.\n");
 		return SPP_RET_NG;
@@ -1219,7 +1219,10 @@ append_core_value(const char *name, char **output,
 	return ret;
 }
 
-/* append one element of classifier table for JSON format */
+/**
+ * Operator function called in iterator for getting each of entries of
+ * classifier table named as iterate_adding_mac_entry().
+ */
 #ifdef SPP_VF_MODULE
 static int
 append_classifier_element_value(
@@ -1276,10 +1279,18 @@ append_classifier_element_value(
 }
 #endif /* SPP_VF_MODULE */
 
-/* append a list of classifier table for JSON format */
+/**
+ * Append entries of classifier table in JSON. Before iterating the entries,
+ * this function calls several nested functions.
+ *   append_classifier_table()  // This function.
+ *     -> add_classifier_table()  // Wrapper and doesn't almost nothing.
+ *       -> add_classifier_table_val()  // Setup data and call iterator.
+ *         -> iterate_adding_mac_entry()
+ *
+ */
 #ifdef SPP_VF_MODULE
 static int
-append_classifier_table_value(const char *name, char **output,
+append_classifier_table(const char *name, char **output,
 		void *tmp __attribute__ ((unused)))
 {
 	int ret = SPP_RET_NG;
@@ -1296,7 +1307,7 @@ append_classifier_table_value(const char *name, char **output,
 	itr_params.output = tmp_buff;
 	itr_params.element_proc = append_classifier_element_value;
 
-	ret = spp_iterate_classifier_table(&itr_params);
+	ret = add_classifier_table(&itr_params);
 	if (unlikely(ret != SPP_RET_OK)) {
 		spp_strbuf_free(itr_params.output);
 		return SPP_RET_NG;
@@ -1388,7 +1399,7 @@ struct cmd_response response_info_list[] = {
 	{ "master-lcore", append_master_lcore_value },
 	{ "core", append_core_value },
 #ifdef SPP_VF_MODULE
-	{ "classifier_table", append_classifier_table_value },
+	{ "classifier_table", append_classifier_table},
 #endif /* SPP_VF_MODULE */
 	{ "", NULL }
 };
diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.h b/src/shared/secondary/spp_worker_th/cmd_utils.h
index 1d6c332..b8ab10c 100644
--- a/src/shared/secondary/spp_worker_th/cmd_utils.h
+++ b/src/shared/secondary/spp_worker_th/cmd_utils.h
@@ -47,7 +47,7 @@
 #define SPP_CORE_STATUS_CHECK_MAX 5
 
 /** Character sting for default port of classifier */
-#define SPP_DEFAULT_CLASSIFIED_SPEC_STR     "default"
+#define SPPWK_TERM_DEFAULT "default"
 
 /** Value for default MAC address of classifier */
 #define SPP_DEFAULT_CLASSIFIED_DMY_ADDR     0x010000000000
diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h
index fb34215..beafc64 100644
--- a/src/shared/secondary/spp_worker_th/vf_deps.h
+++ b/src/shared/secondary/spp_worker_th/vf_deps.h
@@ -75,7 +75,13 @@ void init_classifier_info(int component_id);
 
 void uninit_component_info(struct cls_comp_info *cmp_info);
 
-int spp_classifier_mac_iterate_table(
+/**
+ * Setup data of classifier table and call iterator function for getting
+ * each of entries.
+ *
+ * @params[in] params Object which has pointer of operator func and attrs.
+ */
+int add_classifier_table_val(
 		struct spp_iterate_classifier_table_params *params);
 
 /**
diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c
index 9023a69..8d677a9 100644
--- a/src/vf/classifier_mac.c
+++ b/src/vf/classifier_mac.c
@@ -224,6 +224,7 @@ log_classification(
 		log_classification(clsd_idx, pkt, cmp_info, clsd_data, \
 				__func__, __LINE__)
 
+/* Log DEBUG message for classified MAC and VLAN info. */
 static void
 log_entry(
 		long clsd_idx,
@@ -852,13 +853,17 @@ get_classifier_status(unsigned int lcore_id, int id,
 	return SPP_RET_OK;
 }
 
+/**
+ * For setting up a response for `status` command, iterate adding each of
+ * entries in MAC address table to the result message.
+ */
 static void
-mac_classification_iterate_table(
+iterate_adding_mac_entry(
 		struct spp_iterate_classifier_table_params *params,
 		uint16_t vid,
 		struct mac_classifier *mac_cls,
 		__rte_unused struct cls_comp_info *cmp_info,
-		struct cls_port_info *clsd_data)
+		struct cls_port_info *port_info)
 {
 	int ret;
 	const void *key;
@@ -873,18 +878,20 @@ mac_classification_iterate_table(
 		type = SPP_CLASSIFIER_TYPE_MAC;
 
 	if (mac_cls->default_cls_idx >= 0) {
-		port.iface_type = (clsd_data +
+		port.iface_type = (port_info +
 				mac_cls->default_cls_idx)->iface_type;
-		port.iface_no   = (clsd_data +
+		port.iface_no = (port_info +
 				mac_cls->default_cls_idx)->iface_no_global;
 
-		LOG_ENT((long)mac_cls->default_cls_idx,
-				vid,
-				SPP_DEFAULT_CLASSIFIED_SPEC_STR,
-				cmp_info, clsd_data);
-
-		(*params->element_proc)(params, type, vid,
-				SPP_DEFAULT_CLASSIFIED_SPEC_STR, &port);
+		/* Logging DEBUG message. */
+		LOG_ENT((long)mac_cls->default_cls_idx, vid,
+				SPPWK_TERM_DEFAULT, cmp_info, port_info);
+		/**
+		 * Append "default" entry. `element_proc` is a funciton
+		 * pointer to append_classifier_element_value().
+		 */
+		(*params->element_proc)(params, type, vid, SPPWK_TERM_DEFAULT,
+				&port);
 	}
 
 	next = 0;
@@ -897,25 +904,32 @@ mac_classification_iterate_table(
 		ether_format_addr(mac_addr_str, sizeof(mac_addr_str),
 				(const struct ether_addr *)key);
 
-		port.iface_type = (clsd_data + (long)data)->iface_type;
-		port.iface_no   = (clsd_data + (long)data)->iface_no_global;
+		port.iface_type = (port_info + (long)data)->iface_type;
+		port.iface_no = (port_info + (long)data)->iface_no_global;
 
-		LOG_ENT((long)data, vid, mac_addr_str, cmp_info, clsd_data);
+		LOG_ENT((long)data, vid, mac_addr_str, cmp_info, port_info);
 
+		/**
+		 * Append each entry of MAC address. `element_proc` is a
+		 * funciton pointer to append_classifier_element_value().
+		 */
 		(*params->element_proc)(params, type, vid, mac_addr_str,
 				&port);
 	}
 }
 
-/* classifier(mac address) iterate classifier table. */
+/**
+ * Setup data of classifier table and call iterator function for getting
+ * each of entries.
+ */
 int
-spp_classifier_mac_iterate_table(
+add_classifier_table_val(
 		struct spp_iterate_classifier_table_params *params)
 {
-	int i, n;
+	int i, vlan_id;
 	struct management_info *mng_info;
 	struct cls_comp_info *cmp_info;
-	struct cls_port_info *clsd_data;
+	struct cls_port_info *port_info;
 
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
 		mng_info = g_mng_infos + i;
@@ -923,18 +937,18 @@ spp_classifier_mac_iterate_table(
 			continue;
 
 		cmp_info = mng_info->cmp_infos + mng_info->ref_index;
-		clsd_data = cmp_info->tx_ports_i;
+		port_info = cmp_info->tx_ports_i;
 
 		RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC,
-			"Core[%u] Start iterate classifier table.\n", i);
+			"Start iterate classifier table on lcore %u.\n", i);
 
-		for (n = 0; n < NOF_VLAN; ++n) {
-			if (cmp_info->mac_clfs[n] == NULL)
+		for (vlan_id = 0; vlan_id < NOF_VLAN; ++vlan_id) {
+			if (cmp_info->mac_clfs[vlan_id] == NULL)
 				continue;
 
-			mac_classification_iterate_table(params, (uint16_t) n,
-					cmp_info->mac_clfs[n], cmp_info,
-					clsd_data);
+			iterate_adding_mac_entry(params, (uint16_t) vlan_id,
+					cmp_info->mac_clfs[vlan_id], cmp_info,
+					port_info);
 		}
 	}
 
diff --git a/src/vf/classifier_mac.h b/src/vf/classifier_mac.h
index d3c5ab6..21433e6 100644
--- a/src/vf/classifier_mac.h
+++ b/src/vf/classifier_mac.h
@@ -56,7 +56,7 @@ int spp_classifier_mac_do(int id);
  * @retval SPP_RET_OK succeeded.
  * @retval SPP_RET_NG failed.
  */
-int spp_classifier_mac_iterate_table(
+int add_classifier_table_val(
 		struct spp_iterate_classifier_table_params *params);
 
 #endif /* _CLASSIFIER_MAC_H_ */
-- 
2.17.1


      parent reply index

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24  2:24 [spp] [PATCH 00/11] Refactor libs for classifier in spp_vf yasufum.o
2019-06-24  2:24 ` [spp] [PATCH 01/11] shared/sec: refactor defines of VLAN " yasufum.o
2019-06-24  2:24 ` [spp] [PATCH 02/11] shared/sec: rename struct mac_classification yasufum.o
2019-06-24  2:24 ` [spp] [PATCH 03/11] shared/sec: refactor comments in vf_deps.h yasufum.o
2019-06-24  2:24 ` [spp] [PATCH 04/11] shared/sec: rename struct classified_data yasufum.o
2019-06-24  2:24 ` [spp] [PATCH 05/11] shared/sec: revise usage of term component_info yasufum.o
2019-06-24  2:24 ` [spp] [PATCH 06/11] shared/sec: revise members of struct cls_port_info yasufum.o
2019-06-24  2:25 ` [spp] [PATCH 07/11] shared/sec: rename func free_mac_classification yasufum.o
2019-06-24  2:25 ` [spp] [PATCH 08/11] shared/sec: refactor updating classifier info yasufum.o
2019-06-24  2:25 ` [spp] [PATCH 09/11] shared/sec: refactor updating forwarder yasufum.o
2019-06-24  2:25 ` [spp] [PATCH 10/11] shared/sec: refactor getting classifier status yasufum.o
2019-06-24  2:25 ` yasufum.o [this message]

Reply instructions:

You may reply publically 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=20190624022504.18752-12-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

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