From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 07/13] shared/sec: move JSON formatters from cmd_runner
Date: Mon, 24 Jun 2019 13:36:07 +0900 [thread overview]
Message-ID: <20190624043613.19271-8-yasufum.o@gmail.com> (raw)
In-Reply-To: <20190624043613.19271-1-yasufum.o@gmail.com>
From: Yasufumi Ogawa <yasufum.o@gmail.com>
JSON formatter functions for making a command result are defined in
`cmd_runner.c`, but better to move another file because this file is too
large and functions are not for running command.
This update is to move following functions to `cmd_res_formatter.c` and
its header. The rest of functions are moved in the next patch.
* append_result_value()
* append_error_details_value()
* is_port_flushed()
* append_interface_array()
* append_process_type_value()
* sppwk_get_proc_type()
* append_vlan_value()
Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com>
---
src/mirror/Makefile | 1 +
.../spp_worker_th/cmd_res_formatter.c | 147 +++++++++++++++++
.../spp_worker_th/cmd_res_formatter.h | 38 +++++
.../secondary/spp_worker_th/cmd_runner.c | 150 +-----------------
src/vf/Makefile | 1 +
5 files changed, 189 insertions(+), 148 deletions(-)
create mode 100644 src/shared/secondary/spp_worker_th/cmd_res_formatter.c
create mode 100644 src/shared/secondary/spp_worker_th/cmd_res_formatter.h
diff --git a/src/mirror/Makefile b/src/mirror/Makefile
index fc18d1e..7e666f5 100644
--- a/src/mirror/Makefile
+++ b/src/mirror/Makefile
@@ -26,6 +26,7 @@ SRCS-y += $(SPP_WKT_DIR)/conn_spp_ctl.c
SRCS-y += $(SPP_WKT_DIR)/cmd_parser.c
SRCS-y += $(SPP_WKT_DIR)/cmd_runner.c
SRCS-y += $(SPP_WKT_DIR)/ringlatencystats.c
+SRCS-y += $(SPP_WKT_DIR)/cmd_res_formatter.c
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += $(WERROR_FLAGS) -O3 -MMD
diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.c b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
new file mode 100644
index 0000000..f66f97f
--- /dev/null
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.c
@@ -0,0 +1,147 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#include "cmd_res_formatter.h"
+#include "cmd_utils.h"
+#include "shared/secondary/json_helper.h"
+
+#define RTE_LOGTYPE_WK_CMD_RES_FMT RTE_LOGTYPE_USER1
+
+/**
+ * List of worker process type. The order of items should be same as the order
+ * of enum `secondary_type` in cmd_utils.h.
+ */
+/* TODO(yasufum) rename `secondary_type` to `sppwk_proc_type`. */
+const char *SPPWK_PROC_TYPE_LIST[] = {
+ "none",
+ "vf",
+ "mirror",
+ "", /* termination */
+};
+
+/**
+ * List of port abilities. The order of items should be same as the order of
+ * enum `spp_port_ability_type` in spp_vf.h.
+ */
+const char *PORT_ABILITY_STAT_LIST[] = {
+ "none",
+ "add",
+ "del",
+ "", /* termination */
+};
+
+/* append a command result for JSON format */
+int
+append_result_value(const char *name, char **output, void *tmp)
+{
+ const struct cmd_result *result = tmp;
+ return append_json_str_value(output, name, result->result);
+}
+
+/* append error details for JSON format */
+int
+append_error_details_value(const char *name, char **output, void *tmp)
+{
+ int ret = SPP_RET_NG;
+ const struct cmd_result *result = tmp;
+ char *tmp_buff;
+ /* string is empty, except for errors */
+ if (result->err_msg[0] == '\0')
+ return SPP_RET_OK;
+
+ 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;
+ }
+
+ ret = append_json_str_value(&tmp_buff, "message", result->err_msg);
+ if (unlikely(ret < 0)) {
+ spp_strbuf_free(tmp_buff);
+ return SPP_RET_NG;
+ }
+
+ ret = append_json_block_brackets(output, name, tmp_buff);
+ spp_strbuf_free(tmp_buff);
+ return ret;
+}
+
+/* Check if port is already flushed. */
+int
+is_port_flushed(enum port_type iface_type, int iface_no)
+{
+ struct sppwk_port_info *port = get_sppwk_port(iface_type, iface_no);
+ return port->ethdev_port_id >= 0;
+}
+
+/* append a list of interface numbers */
+int
+append_interface_array(char **output, const enum port_type type)
+{
+ int i, port_cnt = 0;
+ char tmp_str[CMD_TAG_APPEND_SIZE];
+
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
+ if (!is_port_flushed(type, i))
+ continue;
+
+ sprintf(tmp_str, "%s%d", JSON_APPEND_COMMA(port_cnt), i);
+
+ *output = spp_strbuf_append(*output, tmp_str, strlen(tmp_str));
+ if (unlikely(*output == NULL)) {
+ RTE_LOG(ERR, WK_CMD_RES_FMT,
+ "Interface number failed to add. "
+ "(type = %d)\n", type);
+ return SPP_RET_NG;
+ }
+
+ port_cnt++;
+ }
+
+ return SPP_RET_OK;
+}
+
+/* TODO(yasufum) move to another file for util funcs. */
+/* Get proc type from global command params. */
+int
+sppwk_get_proc_type(void)
+{
+ struct startup_param *params;
+ sppwk_get_mng_data(¶ms, NULL, NULL, NULL, NULL, NULL, NULL);
+ return params->secondary_type;
+}
+
+/* append a secondary process type for JSON format */
+int
+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()]);
+}
+
+/* append a value of vlan for JSON format */
+int
+append_vlan_value(char **output, const int ope, const int vid, const int pcp)
+{
+ int ret = SPP_RET_OK;
+ ret = append_json_str_value(output, "operation",
+ PORT_ABILITY_STAT_LIST[ope]);
+ if (unlikely(ret < SPP_RET_OK))
+ return SPP_RET_NG;
+
+ ret = append_json_int_value(output, "id", vid);
+ if (unlikely(ret < 0))
+ return SPP_RET_NG;
+
+ ret = append_json_int_value(output, "pcp", pcp);
+ if (unlikely(ret < 0))
+ return SPP_RET_NG;
+
+ return SPP_RET_OK;
+}
+
diff --git a/src/shared/secondary/spp_worker_th/cmd_res_formatter.h b/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
new file mode 100644
index 0000000..c2da2ee
--- /dev/null
+++ b/src/shared/secondary/spp_worker_th/cmd_res_formatter.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation
+ */
+
+#ifndef _SPPWK_CMD_RES_FORMATTER_H_
+#define _SPPWK_CMD_RES_FORMATTER_H_
+
+#include "shared/common.h"
+
+#define CMD_RES_LEN 32 /* Size of message including null char. */
+#define CMD_ERR_MSG_LEN 128
+
+#define CMD_RES_BUF_INIT_SIZE 2048
+#define CMD_TAG_APPEND_SIZE 16
+
+struct cmd_result {
+ int code; /* Response code. */
+ char result[CMD_RES_LEN]; /* Response msg in short. */
+ char err_msg[CMD_ERR_MSG_LEN]; /* Used only if cmd is failed. */
+};
+
+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);
+
+#endif
diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c
index b1718fa..7145045 100644
--- a/src/shared/secondary/spp_worker_th/cmd_runner.c
+++ b/src/shared/secondary/spp_worker_th/cmd_runner.c
@@ -8,23 +8,20 @@
#include <rte_log.h>
#include <rte_branch_prediction.h>
+#include "cmd_runner.h"
#include "vf_deps.h"
#include "mirror_deps.h"
#include "spp_port.h"
#include "shared/secondary/string_buffer.h"
-
#include "shared/secondary/json_helper.h"
+#include "cmd_res_formatter.h"
#include "conn_spp_ctl.h"
#include "cmd_parser.h"
-#include "cmd_runner.h"
#define RTE_LOGTYPE_WK_CMD_RUNNER RTE_LOGTYPE_USER1
/* request message initial size */
-#define CMD_TAG_APPEND_SIZE 16
-#define CMD_ERR_MSG_LEN 128
#define CMD_REQ_BUF_INIT_SIZE 2048
-#define CMD_RES_BUF_INIT_SIZE 2048
enum cmd_res_code {
CMD_SUCCESS = 0,
@@ -32,12 +29,6 @@ enum cmd_res_code {
CMD_INVALID,
};
-struct cmd_result {
- int code; /* Response code. */
- char result[SPPWK_NAME_BUFSZ]; /* Response msg in short. */
- char err_msg[CMD_ERR_MSG_LEN]; /* Used only if cmd is failed. */
-};
-
/**
* Contains command response nad operator func for. It is used as an array of
* this struct.
@@ -48,29 +39,6 @@ struct cmd_response {
int (*func)(const char *name, char **output, void *tmp);
};
-/**
- * List of worker process type. The order of items should be same as the order
- * of enum `secondary_type` in cmd_utils.h.
- */
-/* TODO(yasufum) rename `secondary_type` to `sppwk_proc_type`. */
-const char *SPPWK_PROC_TYPE_LIST[] = {
- "none",
- "vf",
- "mirror",
- "", /* termination */
-};
-
-/**
- * List of port abilities. The order of items should be same as the order of
- * enum `spp_port_ability_type` in spp_vf.h.
- */
-const char *PORT_ABILITY_STAT_LIST[] = {
- "none",
- "add",
- "del",
- "", /* 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.
@@ -93,24 +61,6 @@ sppwk_get_client_id(void)
return params->client_id;
}
-/* TODO(yasufum) move to another file for util funcs. */
-/* Get proc type from global command params. */
-static int
-sppwk_get_proc_type(void)
-{
- struct startup_param *params;
- sppwk_get_mng_data(¶ms, NULL, NULL, NULL, NULL, NULL, NULL);
- return params->secondary_type;
-}
-
-/* Check if port is already flushed. */
-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);
- return port->ethdev_port_id >= 0;
-}
-
/* Update classifier table with given action, add or del. */
static int
update_cls_table(enum sppwk_action wk_action,
@@ -737,45 +687,6 @@ prepare_parse_err_msg(struct cmd_result *results,
}
}
-/* append a command result for JSON format */
-static int
-append_result_value(const char *name, char **output, void *tmp)
-{
- const struct cmd_result *result = tmp;
- return append_json_str_value(output, name, result->result);
-}
-
-/* append error details for JSON format */
-static int
-append_error_details_value(const char *name, char **output, void *tmp)
-{
- int ret = SPP_RET_NG;
- const struct cmd_result *result = tmp;
- char *tmp_buff;
- /* string is empty, except for errors */
- if (result->err_msg[0] == '\0')
- return SPP_RET_OK;
-
- 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;
- }
-
- ret = append_json_str_value(&tmp_buff, "message", result->err_msg);
- if (unlikely(ret < 0)) {
- spp_strbuf_free(tmp_buff);
- return SPP_RET_NG;
- }
-
- ret = append_json_block_brackets(output, name, tmp_buff);
- spp_strbuf_free(tmp_buff);
- return ret;
-}
-
/* Add entry of client ID to a response in JSON. */
static int
add_client_id(const char *name, char **output,
@@ -784,42 +695,6 @@ add_client_id(const char *name, char **output,
return append_json_int_value(output, name, sppwk_get_client_id());
}
-/* append a list of interface numbers */
-static int
-append_interface_array(char **output, const enum port_type type)
-{
- int i, port_cnt = 0;
- char tmp_str[CMD_TAG_APPEND_SIZE];
-
- for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
- if (!is_port_flushed(type, i))
- continue;
-
- sprintf(tmp_str, "%s%d", JSON_APPEND_COMMA(port_cnt), i);
-
- *output = spp_strbuf_append(*output, tmp_str, strlen(tmp_str));
- if (unlikely(*output == NULL)) {
- RTE_LOG(ERR, WK_CMD_RUNNER,
- "Interface number failed to add. "
- "(type = %d)\n", type);
- return SPP_RET_NG;
- }
-
- port_cnt++;
- }
-
- return SPP_RET_OK;
-}
-
-/* append a secondary process type for JSON format */
-static int
-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()]);
-}
-
/* Add entry of port to a response in JSON such as "phy:0". */
static int
add_interface(const char *name, char **output,
@@ -854,27 +729,6 @@ add_interface(const char *name, char **output,
return ret;
}
-/* append a value of vlan for JSON format */
-static int
-append_vlan_value(char **output, const int ope, const int vid, const int pcp)
-{
- int ret = SPP_RET_OK;
- ret = append_json_str_value(output, "operation",
- PORT_ABILITY_STAT_LIST[ope]);
- if (unlikely(ret < SPP_RET_OK))
- return SPP_RET_NG;
-
- ret = append_json_int_value(output, "id", vid);
- if (unlikely(ret < 0))
- return SPP_RET_NG;
-
- ret = append_json_int_value(output, "pcp", pcp);
- if (unlikely(ret < 0))
- return SPP_RET_NG;
-
- return SPP_RET_OK;
-}
-
/* append a block of vlan for JSON format */
static int
append_vlan_block(const char *name, char **output,
diff --git a/src/vf/Makefile b/src/vf/Makefile
index 3cbdb01..dd5a100 100644
--- a/src/vf/Makefile
+++ b/src/vf/Makefile
@@ -25,6 +25,7 @@ SRCS-y += $(SPP_WKT_DIR)/conn_spp_ctl.c
SRCS-y += $(SPP_WKT_DIR)/cmd_parser.c
SRCS-y += $(SPP_WKT_DIR)/cmd_runner.c
SRCS-y += $(SPP_WKT_DIR)/cmd_utils.c
+SRCS-y += $(SPP_WKT_DIR)/cmd_res_formatter.c
SRCS-y += ../shared/common.c
CFLAGS += -DALLOW_EXPERIMENTAL_API
--
2.17.1
next prev 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 ` yasufum.o [this message]
2019-06-24 4:36 ` [spp] [PATCH 08/13] shared/sec: move rest of JSON formatters yasufum.o
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-8-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).