Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 08/13] shared/sec: move rest of JSON formatters
Date: Mon, 24 Jun 2019 13:36:08 +0900	[thread overview]
Message-ID: <20190624043613.19271-9-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190624043613.19271-1-yasufum.o@gmail.com>

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

This update is to move the rest of JSON formatters defined in
`cmd_runner.c`.

Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
 .../spp_worker_th/cmd_res_formatter.c         | 396 ++++++++++++++++-
 .../spp_worker_th/cmd_res_formatter.h         |  45 +-
 .../secondary/spp_worker_th/cmd_runner.c      | 399 ------------------
 3 files changed, 433 insertions(+), 407 deletions(-)

diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
index f66f97f..b94cb29 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -31,6 +31,25 @@ const char *PORT_ABILITY_STAT_LIST[] = {
 	"",  /* termination */
 };
 
+/**
+ * List of classifier type. The order of items should be same as the order of
+ * enum `spp_classifier_type` defined in cmd_utils.h.
+ */
+/* TODO(yasufum) fix similar var in cmd_parser.c */
+const char *CLS_TYPE_A_LIST[] = {
+	"none",
+	"mac",
+	"vlan",
+	"",  /* termination */
+};
+
+/* command response result string list */
+struct cmd_response response_result_list[] = {
+	{ "result", append_result_value },
+	{ "error_details", append_error_details_value },
+	{ "", NULL }
+};
+
 /* append a command result for JSON format */
 int
 append_result_value(const char *name, char **output, void *tmp)
@@ -71,7 +90,7 @@ append_error_details_value(const char *name, char **output, void *tmp)
 }
 
 /* Check if port is already flushed. */
-int
+static int
 is_port_flushed(enum port_type iface_type, int iface_no)
 {
 	struct sppwk_port_info *port = get_sppwk_port(iface_type, iface_no);
@@ -107,8 +126,8 @@ append_interface_array(char **output, const enum port_type type)
 
 /* TODO(yasufum) move to another file for util funcs. */
 /* Get proc type from global command params. */
-int
-sppwk_get_proc_type(void)
+static int
+get_wk_type(void)
 {
 	struct startup_param *params;
 	sppwk_get_mng_data(&params, NULL, NULL, NULL, NULL, NULL, NULL);
@@ -121,7 +140,7 @@ append_process_type_value(const char *name, char **output,
 		void *tmp __attribute__ ((unused)))
 {
 	return append_json_str_value(output, name,
-			SPPWK_PROC_TYPE_LIST[sppwk_get_proc_type()]);
+			SPPWK_PROC_TYPE_LIST[get_wk_type()]);
 }
 
 /* append a value of vlan for JSON format */
@@ -145,3 +164,372 @@ append_vlan_value(char **output, const int ope, const int vid, const int pcp)
 	return SPP_RET_OK;
 }
 
+/* append a block of vlan for JSON format */
+int
+append_vlan_block(const char *name, char **output,
+		const int port_id, const enum spp_port_rxtx rxtx)
+{
+	int ret = SPP_RET_NG;
+	int i = 0;
+	struct spp_port_ability *info = NULL;
+	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = %s)\n",
+				name);
+		return SPP_RET_NG;
+	}
+
+	spp_port_ability_get_info(port_id, rxtx, &info);
+	for (i = 0; i < SPP_PORT_ABILITY_MAX; i++) {
+		switch (info[i].ops) {
+		case SPPWK_PORT_ABL_OPS_ADD_VLANTAG:
+		case SPPWK_PORT_ABL_OPS_DEL_VLANTAG:
+			ret = append_vlan_value(&tmp_buff, info[i].ops,
+					info[i].data.vlantag.vid,
+					info[i].data.vlantag.pcp);
+			if (unlikely(ret < SPP_RET_OK))
+				return SPP_RET_NG;
+
+			/*
+			 * Change counter to "maximum+1" for exit the loop.
+			 * An if statement after loop termination is false
+			 * by "maximum+1 ".
+			 */
+			i = SPP_PORT_ABILITY_MAX + 1;
+			break;
+		default:
+			/* not used */
+			break;
+		}
+	}
+	if (i == SPP_PORT_ABILITY_MAX) {
+		ret = append_vlan_value(&tmp_buff, SPPWK_PORT_ABL_OPS_NONE,
+				0, 0);
+		if (unlikely(ret < SPP_RET_OK))
+			return SPP_RET_NG;
+	}
+
+	ret = append_json_block_brackets(output, name, tmp_buff);
+	spp_strbuf_free(tmp_buff);
+	return ret;
+}
+
+/**
+ * Get consistent port ID of rte ethdev from resource UID such as `phy:0`.
+ * It returns a port ID, or error code if it's failed to.
+ */
+static int
+get_ethdev_port_id(enum port_type iface_type, int iface_no)
+{
+	struct iface_info *iface_info = NULL;
+
+	sppwk_get_mng_data(NULL, &iface_info,
+				NULL, NULL, NULL, NULL, NULL);
+	switch (iface_type) {
+	case PHY:
+		return iface_info->nic[iface_no].ethdev_port_id;
+	case RING:
+		return iface_info->ring[iface_no].ethdev_port_id;
+	case VHOST:
+		return iface_info->vhost[iface_no].ethdev_port_id;
+	default:
+		return SPP_RET_NG;
+	}
+}
+
+/* append a block of port numbers for JSON format */
+int
+append_port_block(char **output, const struct sppwk_port_idx *port,
+		const enum spp_port_rxtx rxtx)
+{
+	int ret = SPP_RET_NG;
+	char port_str[CMD_TAG_APPEND_SIZE];
+	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = port_block)\n");
+		return SPP_RET_NG;
+	}
+
+	spp_format_port_string(port_str, port->iface_type, port->iface_no);
+	ret = append_json_str_value(&tmp_buff, "port", port_str);
+	if (unlikely(ret < SPP_RET_OK))
+		return SPP_RET_NG;
+
+	ret = append_vlan_block("vlan", &tmp_buff,
+			get_ethdev_port_id(
+				port->iface_type, port->iface_no),
+			rxtx);
+	if (unlikely(ret < SPP_RET_OK))
+		return SPP_RET_NG;
+
+	ret = append_json_block_brackets(output, "", tmp_buff);
+	spp_strbuf_free(tmp_buff);
+	return ret;
+}
+
+/* append a list of port numbers for JSON format */
+int
+append_port_array(const char *name, char **output, const int num,
+		const struct sppwk_port_idx *ports,
+		const enum spp_port_rxtx rxtx)
+{
+	int ret = SPP_RET_NG;
+	int i = 0;
+	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = %s)\n",
+				name);
+		return SPP_RET_NG;
+	}
+
+	for (i = 0; i < num; i++) {
+		ret = append_port_block(&tmp_buff, &ports[i], rxtx);
+		if (unlikely(ret < SPP_RET_OK))
+			return SPP_RET_NG;
+	}
+
+	ret = append_json_array_brackets(output, name, tmp_buff);
+	spp_strbuf_free(tmp_buff);
+	return ret;
+}
+
+/**
+ * TODO(yasufum) add usages called from `add_core` or refactor
+ * confusing function names.
+ */
+/* append one element of core information for JSON format */
+int
+append_core_element_value(
+		struct spp_iterate_core_params *params,
+		const unsigned int lcore_id,
+		const char *name, const char *type,
+		const int num_rx, const struct sppwk_port_idx *rx_ports,
+		const int num_tx, const struct sppwk_port_idx *tx_ports)
+{
+	int ret = SPP_RET_NG;
+	int unuse_flg = 0;
+	char *buff, *tmp_buff;
+	buff = params->output;
+	tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		/* TODO(yasufum) refactor no meaning err msg */
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				"allocate error. (name = %s)\n",
+				name);
+		return ret;
+	}
+
+	/* there is unnecessary data when "unuse" by type */
+	unuse_flg = strcmp(type, SPPWK_TYPE_NONE_STR);
+
+	/**
+	 * TODO(yasufum) change ambiguous "core" to more specific one such as
+	 * "worker-lcores" or "slave-lcores".
+	 */
+	ret = append_json_uint_value(&tmp_buff, "core", lcore_id);
+	if (unlikely(ret < SPP_RET_OK))
+		return ret;
+
+	if (unuse_flg) {
+		ret = append_json_str_value(&tmp_buff, "name", name);
+		if (unlikely(ret < 0))
+			return ret;
+	}
+
+	ret = append_json_str_value(&tmp_buff, "type", type);
+	if (unlikely(ret < SPP_RET_OK))
+		return ret;
+
+	if (unuse_flg) {
+		ret = append_port_array("rx_port", &tmp_buff,
+				num_rx, rx_ports, SPP_PORT_RXTX_RX);
+		if (unlikely(ret < 0))
+			return ret;
+
+		ret = append_port_array("tx_port", &tmp_buff,
+				num_tx, tx_ports, SPP_PORT_RXTX_TX);
+		if (unlikely(ret < SPP_RET_OK))
+			return ret;
+	}
+
+	ret = append_json_block_brackets(&buff, "", tmp_buff);
+	spp_strbuf_free(tmp_buff);
+	params->output = buff;
+	return ret;
+}
+
+#ifdef SPP_VF_MODULE
+/**
+ * Operator function called in iterator for getting each of entries of
+ * classifier table named as iterate_adding_mac_entry().
+ */
+int
+append_classifier_element_value(
+		struct spp_iterate_classifier_table_params *params,
+		enum spp_classifier_type type,
+		int vid, const char *mac,
+		const struct sppwk_port_idx *port)
+{
+	int ret = SPP_RET_NG;
+	char *buff, *tmp_buff;
+	char port_str[CMD_TAG_APPEND_SIZE];
+	char value_str[STR_LEN_SHORT];
+	buff = params->output;
+	tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = classifier_table)\n");
+		return ret;
+	}
+
+	spp_format_port_string(port_str, port->iface_type, port->iface_no);
+
+	ret = append_json_str_value(&tmp_buff, "type", CLS_TYPE_A_LIST[type]);
+	if (unlikely(ret < SPP_RET_OK))
+		return ret;
+
+	memset(value_str, 0x00, STR_LEN_SHORT);
+	switch (type) {
+	case SPP_CLASSIFIER_TYPE_MAC:
+		sprintf(value_str, "%s", mac);
+		break;
+	case SPP_CLASSIFIER_TYPE_VLAN:
+		sprintf(value_str, "%d/%s", vid, mac);
+		break;
+	default:
+		/* not used */
+		break;
+	}
+
+	ret = append_json_str_value(&tmp_buff, "value", value_str);
+	if (unlikely(ret < 0))
+		return ret;
+
+	ret = append_json_str_value(&tmp_buff, "port", port_str);
+	if (unlikely(ret < SPP_RET_OK))
+		return ret;
+
+	ret = append_json_block_brackets(&buff, "", tmp_buff);
+	spp_strbuf_free(tmp_buff);
+	params->output = buff;
+	return ret;
+}
+#endif /* SPP_VF_MODULE */
+
+/* append string of command response list for JSON format */
+int
+append_response_list_value(char **output, struct cmd_response *responses,
+		void *tmp)
+{
+	int ret = SPP_RET_NG;
+	int i;
+	char *tmp_buff;
+	tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff == NULL)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = response_list)\n");
+		return SPP_RET_NG;
+	}
+
+	for (i = 0; responses[i].tag_name[0] != '\0'; i++) {
+		tmp_buff[0] = '\0';
+		ret = responses[i].func(responses[i].tag_name, &tmp_buff, tmp);
+		if (unlikely(ret < SPP_RET_OK)) {
+			spp_strbuf_free(tmp_buff);
+			RTE_LOG(ERR, WK_CMD_RES_FMT,
+					"Failed to get reply string. "
+					"(tag = %s)\n", responses[i].tag_name);
+			return SPP_RET_NG;
+		}
+
+		if (tmp_buff[0] == '\0')
+			continue;
+
+		if ((*output)[0] != '\0') {
+			ret = append_json_comma(output);
+			if (unlikely(ret < SPP_RET_OK)) {
+				spp_strbuf_free(tmp_buff);
+				RTE_LOG(ERR, WK_CMD_RES_FMT,
+						"Failed to add commas. "
+						"(tag = %s)\n",
+						responses[i].tag_name);
+				return SPP_RET_NG;
+			}
+		}
+
+		*output = spp_strbuf_append(*output, tmp_buff,
+				strlen(tmp_buff));
+		if (unlikely(*output == NULL)) {
+			spp_strbuf_free(tmp_buff);
+			RTE_LOG(ERR, WK_CMD_RES_FMT,
+					"Failed to add reply string. "
+					"(tag = %s)\n",
+					responses[i].tag_name);
+			return SPP_RET_NG;
+		}
+	}
+
+	spp_strbuf_free(tmp_buff);
+	return SPP_RET_OK;
+}
+
+/* append a list of command results for JSON format. */
+int
+append_command_results_value(const char *name, char **output,
+		int num, struct cmd_result *results)
+{
+	int ret = SPP_RET_NG;
+	int i;
+	char *tmp_buff1, *tmp_buff2;
+	tmp_buff1 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff1 == NULL)) {
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = %s, buff=1)\n",
+				name);
+		return SPP_RET_NG;
+	}
+
+	tmp_buff2 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
+	if (unlikely(tmp_buff2 == NULL)) {
+		spp_strbuf_free(tmp_buff1);
+		RTE_LOG(ERR, WK_CMD_RES_FMT,
+				/* TODO(yasufum) refactor no meaning err msg */
+				"allocate error. (name = %s, buff=2)\n",
+				name);
+		return SPP_RET_NG;
+	}
+
+	for (i = 0; i < num; i++) {
+		tmp_buff1[0] = '\0';
+		ret = append_response_list_value(&tmp_buff1,
+				response_result_list, &results[i]);
+		if (unlikely(ret < 0)) {
+			spp_strbuf_free(tmp_buff1);
+			spp_strbuf_free(tmp_buff2);
+			return SPP_RET_NG;
+		}
+
+		ret = append_json_block_brackets(&tmp_buff2, "", tmp_buff1);
+		if (unlikely(ret < 0)) {
+			spp_strbuf_free(tmp_buff1);
+			spp_strbuf_free(tmp_buff2);
+			return SPP_RET_NG;
+		}
+
+	}
+
+	ret = append_json_array_brackets(output, name, tmp_buff2);
+	spp_strbuf_free(tmp_buff1);
+	spp_strbuf_free(tmp_buff2);
+	return ret;
+}
+
diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.h b/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
index c2da2ee..f3e9879 100644
--- a/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
@@ -5,9 +5,12 @@
 #ifndef _SPPWK_CMD_RES_FORMATTER_H_
 #define _SPPWK_CMD_RES_FORMATTER_H_
 
+#include "cmd_utils.h"
+#include "spp_port.h"
 #include "shared/common.h"
 
 #define CMD_RES_LEN  32  /* Size of message including null char. */
+#define CMD_RES_TAG_LEN  32
 #define CMD_ERR_MSG_LEN 128
 
 #define CMD_RES_BUF_INIT_SIZE 2048
@@ -19,20 +22,54 @@ struct cmd_result {
 	char err_msg[CMD_ERR_MSG_LEN];  /* Used only if cmd is failed. */
 };
 
+/**
+ * Contains command response and operator func for. It is used as an array of
+ * this struct.
+ */
+/* TODO(yasufum) add comment describes the purpose of this struct is used. */
+struct cmd_response {
+	char tag_name[CMD_RES_TAG_LEN];
+	int (*func)(const char *name, char **output, void *tmp);
+};
+
 int append_result_value(const char *name, char **output, void *tmp);
 
 int append_error_details_value(const char *name, char **output, void *tmp);
 
-int is_port_flushed(enum port_type iface_type, int iface_no);
-
 int append_interface_array(char **output, const enum port_type type);
 
 int append_process_type_value(const char *name, char **output,
 		void *tmp __attribute__ ((unused)));
 
-int sppwk_get_proc_type(void);
-
 int append_vlan_value(char **output, const int ope, const int vid,
 		const int pcp);
 
+int append_vlan_block(const char *name, char **output,
+		const int port_id, const enum spp_port_rxtx rxtx);
+
+int append_port_block(char **output, const struct sppwk_port_idx *port,
+		const enum spp_port_rxtx rxtx);
+
+int append_port_array(const char *name, char **output, const int num,
+		const struct sppwk_port_idx *ports,
+		const enum spp_port_rxtx rxtx);
+
+int append_core_element_value(struct spp_iterate_core_params *params,
+		const unsigned int lcore_id,
+		const char *name, const char *type,
+		const int num_rx, const struct sppwk_port_idx *rx_ports,
+		const int num_tx, const struct sppwk_port_idx *tx_ports);
+
+int append_classifier_element_value(
+		struct spp_iterate_classifier_table_params *params,
+		enum spp_classifier_type type,
+		int vid, const char *mac,
+		const struct sppwk_port_idx *port);
+
+int append_response_list_value(char **output, struct cmd_response *responses,
+		void *tmp);
+
+int append_command_results_value(const char *name, char **output,
+		int num, struct cmd_result *results);
+
 #endif
diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c
index 7145045..5644aec 100644
--- a/src/shared/secondary/spp_worker_th/cmd_runner.c
+++ b/src/shared/secondary/spp_worker_th/cmd_runner.c
@@ -29,28 +29,6 @@ enum cmd_res_code {
 	CMD_INVALID,
 };
 
-/**
- * Contains command response nad operator func for. It is used as an array of
- * this struct.
- */
-/* TODO(yasufum) add comment describes the purpose of this struct is used. */
-struct cmd_response {
-	char tag_name[SPPWK_NAME_BUFSZ];
-	int (*func)(const char *name, char **output, void *tmp);
-};
-
-/**
- * List of classifier type. The order of items should be same as the order of
- * enum `spp_classifier_type` defined in cmd_utils.h.
- */
-/* TODO(yasufum) fix similar var in cmd_parser.c */
-const char *CLS_TYPE_A_LIST[] = {
-	"none",
-	"mac",
-	"vlan",
-	"",  /* termination */
-};
-
 /* TODO(yasufum) move to another file for util funcs. */
 /* Get client ID from global command params. */
 static int
@@ -518,29 +496,6 @@ _add_classifier_table(
 }
 #endif /* SPP_VF_MODULE */
 
-/**
- * Get consistent port ID of rte ethdev from resource UID such as `phy:0`.
- * It returns a port ID, or error code if it's failed to.
- */
-static int
-sppwk_get_ethdev_port_id(enum port_type iface_type, int iface_no)
-{
-	struct iface_info *iface_info = NULL;
-
-	sppwk_get_mng_data(NULL, &iface_info,
-				NULL, NULL, NULL, NULL, NULL);
-	switch (iface_type) {
-	case PHY:
-		return iface_info->nic[iface_no].ethdev_port_id;
-	case RING:
-		return iface_info->ring[iface_no].ethdev_port_id;
-	case VHOST:
-		return iface_info->vhost[iface_no].ethdev_port_id;
-	default:
-		return SPP_RET_NG;
-	}
-}
-
 /* Execute one command. */
 static int
 exec_one_cmd(const struct sppwk_cmd_attrs *cmd)
@@ -729,183 +684,6 @@ add_interface(const char *name, char **output,
 	return ret;
 }
 
-/* append a block of vlan for JSON format */
-static int
-append_vlan_block(const char *name, char **output,
-		const int port_id, const enum spp_port_rxtx rxtx)
-{
-	int ret = SPP_RET_NG;
-	int i = 0;
-	struct spp_port_ability *info = NULL;
-	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s)\n",
-				name);
-		return SPP_RET_NG;
-	}
-
-	spp_port_ability_get_info(port_id, rxtx, &info);
-	for (i = 0; i < SPP_PORT_ABILITY_MAX; i++) {
-		switch (info[i].ops) {
-		case SPPWK_PORT_ABL_OPS_ADD_VLANTAG:
-		case SPPWK_PORT_ABL_OPS_DEL_VLANTAG:
-			ret = append_vlan_value(&tmp_buff, info[i].ops,
-					info[i].data.vlantag.vid,
-					info[i].data.vlantag.pcp);
-			if (unlikely(ret < SPP_RET_OK))
-				return SPP_RET_NG;
-
-			/*
-			 * Change counter to "maximum+1" for exit the loop.
-			 * An if statement after loop termination is false
-			 * by "maximum+1 ".
-			 */
-			i = SPP_PORT_ABILITY_MAX + 1;
-			break;
-		default:
-			/* not used */
-			break;
-		}
-	}
-	if (i == SPP_PORT_ABILITY_MAX) {
-		ret = append_vlan_value(&tmp_buff, SPPWK_PORT_ABL_OPS_NONE,
-				0, 0);
-		if (unlikely(ret < SPP_RET_OK))
-			return SPP_RET_NG;
-	}
-
-	ret = append_json_block_brackets(output, name, tmp_buff);
-	spp_strbuf_free(tmp_buff);
-	return ret;
-}
-
-/* append a block of port numbers for JSON format */
-static int
-append_port_block(char **output, const struct sppwk_port_idx *port,
-		const enum spp_port_rxtx rxtx)
-{
-	int ret = SPP_RET_NG;
-	char port_str[CMD_TAG_APPEND_SIZE];
-	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = port_block)\n");
-		return SPP_RET_NG;
-	}
-
-	spp_format_port_string(port_str, port->iface_type, port->iface_no);
-	ret = append_json_str_value(&tmp_buff, "port", port_str);
-	if (unlikely(ret < SPP_RET_OK))
-		return SPP_RET_NG;
-
-	ret = append_vlan_block("vlan", &tmp_buff,
-			sppwk_get_ethdev_port_id(
-				port->iface_type, port->iface_no),
-			rxtx);
-	if (unlikely(ret < SPP_RET_OK))
-		return SPP_RET_NG;
-
-	ret = append_json_block_brackets(output, "", tmp_buff);
-	spp_strbuf_free(tmp_buff);
-	return ret;
-}
-
-/* append a list of port numbers for JSON format */
-static int
-append_port_array(const char *name, char **output, const int num,
-		const struct sppwk_port_idx *ports,
-		const enum spp_port_rxtx rxtx)
-{
-	int ret = SPP_RET_NG;
-	int i = 0;
-	char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s)\n",
-				name);
-		return SPP_RET_NG;
-	}
-
-	for (i = 0; i < num; i++) {
-		ret = append_port_block(&tmp_buff, &ports[i], rxtx);
-		if (unlikely(ret < SPP_RET_OK))
-			return SPP_RET_NG;
-	}
-
-	ret = append_json_array_brackets(output, name, tmp_buff);
-	spp_strbuf_free(tmp_buff);
-	return ret;
-}
-
-/**
- * TODO(yasufum) add usages called from `add_core` or refactor
- * confusing function names.
- */
-/* append one element of core information for JSON format */
-static int
-append_core_element_value(
-		struct spp_iterate_core_params *params,
-		const unsigned int lcore_id,
-		const char *name, const char *type,
-		const int num_rx, const struct sppwk_port_idx *rx_ports,
-		const int num_tx, const struct sppwk_port_idx *tx_ports)
-{
-	int ret = SPP_RET_NG;
-	int unuse_flg = 0;
-	char *buff, *tmp_buff;
-	buff = params->output;
-	tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		/* TODO(yasufum) refactor no meaning err msg */
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				"allocate error. (name = %s)\n",
-				name);
-		return ret;
-	}
-
-	/* there is unnecessary data when "unuse" by type */
-	unuse_flg = strcmp(type, SPPWK_TYPE_NONE_STR);
-
-	/**
-	 * TODO(yasufum) change ambiguous "core" to more specific one such as
-	 * "worker-lcores" or "slave-lcores".
-	 */
-	ret = append_json_uint_value(&tmp_buff, "core", lcore_id);
-	if (unlikely(ret < SPP_RET_OK))
-		return ret;
-
-	if (unuse_flg) {
-		ret = append_json_str_value(&tmp_buff, "name", name);
-		if (unlikely(ret < 0))
-			return ret;
-	}
-
-	ret = append_json_str_value(&tmp_buff, "type", type);
-	if (unlikely(ret < SPP_RET_OK))
-		return ret;
-
-	if (unuse_flg) {
-		ret = append_port_array("rx_port", &tmp_buff,
-				num_rx, rx_ports, SPP_PORT_RXTX_RX);
-		if (unlikely(ret < 0))
-			return ret;
-
-		ret = append_port_array("tx_port", &tmp_buff,
-				num_tx, tx_ports, SPP_PORT_RXTX_TX);
-		if (unlikely(ret < SPP_RET_OK))
-			return ret;
-	}
-
-	ret = append_json_block_brackets(&buff, "", tmp_buff);
-	spp_strbuf_free(tmp_buff);
-	params->output = buff;
-	return ret;
-}
-
 /* Add entry of master lcore to a response in JSON. */
 static int
 add_master_lcore(const char *name, char **output,
@@ -946,65 +724,7 @@ add_core(const char *name, char **output,
 	return ret;
 }
 
-/**
- * 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(
-		struct spp_iterate_classifier_table_params *params,
-		enum spp_classifier_type type,
-		int vid, const char *mac,
-		const struct sppwk_port_idx *port)
-{
-	int ret = SPP_RET_NG;
-	char *buff, *tmp_buff;
-	char port_str[CMD_TAG_APPEND_SIZE];
-	char value_str[STR_LEN_SHORT];
-	buff = params->output;
-	tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = classifier_table)\n");
-		return ret;
-	}
-
-	spp_format_port_string(port_str, port->iface_type, port->iface_no);
-
-	ret = append_json_str_value(&tmp_buff, "type", CLS_TYPE_A_LIST[type]);
-	if (unlikely(ret < SPP_RET_OK))
-		return ret;
-
-	memset(value_str, 0x00, STR_LEN_SHORT);
-	switch (type) {
-	case SPP_CLASSIFIER_TYPE_MAC:
-		sprintf(value_str, "%s", mac);
-		break;
-	case SPP_CLASSIFIER_TYPE_VLAN:
-		sprintf(value_str, "%d/%s", vid, mac);
-		break;
-	default:
-		/* not used */
-		break;
-	}
-
-	ret = append_json_str_value(&tmp_buff, "value", value_str);
-	if (unlikely(ret < 0))
-		return ret;
-
-	ret = append_json_str_value(&tmp_buff, "port", port_str);
-	if (unlikely(ret < SPP_RET_OK))
-		return ret;
-
-	ret = append_json_block_brackets(&buff, "", tmp_buff);
-	spp_strbuf_free(tmp_buff);
-	params->output = buff;
-	return ret;
-}
-#endif /* SPP_VF_MODULE */
-
 /**
  * Add entries of classifier table in JSON. Before iterating the entries,
  * this function calls several nested functions.
@@ -1013,7 +733,6 @@ append_classifier_element_value(
  *       -> add_classifier_table_val()  // Setup data and call iterator.
  *         -> iterate_adding_mac_entry()
  */
-#ifdef SPP_VF_MODULE
 static int
 add_classifier_table(const char *name, char **output,
 		void *tmp __attribute__ ((unused)))
@@ -1044,72 +763,6 @@ add_classifier_table(const char *name, char **output,
 }
 #endif /* SPP_VF_MODULE */
 
-/* append string of command response list for JSON format */
-static int
-append_response_list_value(char **output,
-		struct cmd_response *responses,
-		void *tmp)
-{
-	int ret = SPP_RET_NG;
-	int i;
-	char *tmp_buff;
-	tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = response_list)\n");
-		return SPP_RET_NG;
-	}
-
-	for (i = 0; responses[i].tag_name[0] != '\0'; i++) {
-		tmp_buff[0] = '\0';
-		ret = responses[i].func(responses[i].tag_name, &tmp_buff, tmp);
-		if (unlikely(ret < SPP_RET_OK)) {
-			spp_strbuf_free(tmp_buff);
-			RTE_LOG(ERR, WK_CMD_RUNNER,
-					"Failed to get reply string. "
-					"(tag = %s)\n", responses[i].tag_name);
-			return SPP_RET_NG;
-		}
-
-		if (tmp_buff[0] == '\0')
-			continue;
-
-		if ((*output)[0] != '\0') {
-			ret = append_json_comma(output);
-			if (unlikely(ret < SPP_RET_OK)) {
-				spp_strbuf_free(tmp_buff);
-				RTE_LOG(ERR, WK_CMD_RUNNER,
-						"Failed to add commas. "
-						"(tag = %s)\n",
-						responses[i].tag_name);
-				return SPP_RET_NG;
-			}
-		}
-
-		*output = spp_strbuf_append(*output, tmp_buff,
-				strlen(tmp_buff));
-		if (unlikely(*output == NULL)) {
-			spp_strbuf_free(tmp_buff);
-			RTE_LOG(ERR, WK_CMD_RUNNER,
-					"Failed to add reply string. "
-					"(tag = %s)\n",
-					responses[i].tag_name);
-			return SPP_RET_NG;
-		}
-	}
-
-	spp_strbuf_free(tmp_buff);
-	return SPP_RET_OK;
-}
-
-/* command response result string list */
-struct cmd_response response_result_list[] = {
-	{ "result", append_result_value },
-	{ "error_details", append_error_details_value },
-	{ "", NULL }
-};
-
 /**
  * List of combination of tag and operator function. It is used to assemble
  * a result of command in JSON like as following.
@@ -1135,58 +788,6 @@ struct cmd_response response_info_list[] = {
 	{ "", NULL }
 };
 
-/* append a list of command results for JSON format. */
-static int
-append_command_results_value(const char *name, char **output,
-		int num, struct cmd_result *results)
-{
-	int ret = SPP_RET_NG;
-	int i;
-	char *tmp_buff1, *tmp_buff2;
-	tmp_buff1 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff1 == NULL)) {
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s, buff=1)\n",
-				name);
-		return SPP_RET_NG;
-	}
-
-	tmp_buff2 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE);
-	if (unlikely(tmp_buff2 == NULL)) {
-		spp_strbuf_free(tmp_buff1);
-		RTE_LOG(ERR, WK_CMD_RUNNER,
-				/* TODO(yasufum) refactor no meaning err msg */
-				"allocate error. (name = %s, buff=2)\n",
-				name);
-		return SPP_RET_NG;
-	}
-
-	for (i = 0; i < num; i++) {
-		tmp_buff1[0] = '\0';
-		ret = append_response_list_value(&tmp_buff1,
-				response_result_list, &results[i]);
-		if (unlikely(ret < 0)) {
-			spp_strbuf_free(tmp_buff1);
-			spp_strbuf_free(tmp_buff2);
-			return SPP_RET_NG;
-		}
-
-		ret = append_json_block_brackets(&tmp_buff2, "", tmp_buff1);
-		if (unlikely(ret < 0)) {
-			spp_strbuf_free(tmp_buff1);
-			spp_strbuf_free(tmp_buff2);
-			return SPP_RET_NG;
-		}
-
-	}
-
-	ret = append_json_array_brackets(output, name, tmp_buff2);
-	spp_strbuf_free(tmp_buff1);
-	spp_strbuf_free(tmp_buff2);
-	return ret;
-}
-
 /* append a list of status information for JSON format. */
 static int
 append_info_value(const char *name, char **output)
-- 
2.17.1


  parent reply	other threads:[~2019-06-24  4:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-24  4:36 [spp] [PATCH 00/13] Move JSON utils from libs for running cmds yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 01/13] shared/sec: rename ops for setup cmd response yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 02/13] shared/sec: rename functions for spp_mirror yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 03/13] shared/sec: move principle JSON formatter funcs yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 04/13] shared/sec: change order of args of JSON fmtters yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 05/13] shared/sec: move JSON formatter to shard/secondary yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 06/13] shared/sec: revise including headers yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 07/13] shared/sec: move JSON formatters from cmd_runner yasufum.o
2019-06-24  4:36 ` yasufum.o [this message]
2019-06-24  4:36 ` [spp] [PATCH 09/13] shared/sec: move lcore funcs in response_info_list yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 10/13] shared/sec: move ope cli-id " yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 11/13] shared/sec: move rest of ops " yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 12/13] shared/sec: remove local funcs from header yasufum.o
2019-06-24  4:36 ` [spp] [PATCH 13/13] shared/sec: refactor comments for JSON formatter 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=20190624043613.19271-9-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).