From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 7398DA046B for ; Mon, 24 Jun 2019 06:36:49 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C3151BF40; Mon, 24 Jun 2019 06:36:49 +0200 (CEST) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by dpdk.org (Postfix) with ESMTP id D89181BF2C for ; Mon, 24 Jun 2019 06:36:47 +0200 (CEST) Received: by mail-pg1-f174.google.com with SMTP id f25so6394146pgv.10 for ; Sun, 23 Jun 2019 21:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=LJYCJj+PqnYXXj6nfwLr1MqXmyYaSodZVHES1fPf6pM=; b=tTy+APi+xt0nyGNASlzoLNap9CnTkRgN4sKug6MjqkNjELx5r4P+st0/3D+KLPGMNw OQpBaSno+jiPMxzA4+J/msfw9MF0PQMH4lMDwyUAfBxrfLlMpsp0zmGNUzmLYc7BiBmH kuPrOLbzpSDQxSQG+nfN85nHbc3Shzka4Sft5XzCGbFQS/suB18nxi08JvxHtdQ90KJ2 JW5awm6/RkJnwebhp53YDXRDbFnhFl/mrqJ6SjpnpVvQ0ck2RE2kothM5pGevXWfBZEf 7VOYlLiuIIe6SqDHkrWFCn7jsNO4g8wg9irO8mbgRo7fXe5A8XdbTvhFbZHD0RdEP8jT qMfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=LJYCJj+PqnYXXj6nfwLr1MqXmyYaSodZVHES1fPf6pM=; b=VHCs2cAlDkWgyqMqt8DfCWmVEzWOKbj3ght4RuJrGpcRKoSZ212X/dhj/plZxsTpJA VIVbSM4s3tGIO2s2uF3mwFyAT6ec6Qg9H6lJDxnuY4wb0qyS5FwXTFWtG/FYHWNY84uL JoPfGG9ysWloQxPnD+XH5UjFZL/krYfxrZ6Aj4gv0QMviy2xYIj78p4e/QIiUUn73kJR W6R1PS6rZJ9fjQuTLEw0bmJ4dgGCDmD5pZRW9hDhASozQvVM3dX47eImHjNzA+kU3OUO AsG5M/EKsLq6CIFmHRWeBVJkUBhchgI1ee75DJeB+zG4rXeKQ/kkRCrtdBaFwsOFY/n1 bu5Q== X-Gm-Message-State: APjAAAXJAXzOOIvIZLqOBnylw6XjjFYrkPi5qfyFhqexNwI6FeQgqdhE Mtz6Tok6RYvsiwj3FzUwkwKHUJQ9 X-Google-Smtp-Source: APXvYqw8LCF88uZdKO8TatnHzDz9s9ZnHn2F3ZtQfGxPD7uJYc7/C83DTwpNysJisRBWh/WwCMGLTQ== X-Received: by 2002:a65:5347:: with SMTP id w7mr30713629pgr.375.1561351006816; Sun, 23 Jun 2019 21:36:46 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id c10sm9005178pjq.14.2019.06.23.21.36.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Jun 2019 21:36:46 -0700 (PDT) From: yasufum.o@gmail.com To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com Date: Mon, 24 Jun 2019 13:36:07 +0900 Message-Id: <20190624043613.19271-8-yasufum.o@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190624043613.19271-1-yasufum.o@gmail.com> References: <20190624043613.19271-1-yasufum.o@gmail.com> Subject: [spp] [PATCH 07/13] shared/sec: move JSON formatters from cmd_runner X-BeenThere: spp@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Soft Patch Panel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: spp-bounces@dpdk.org Sender: "spp" From: Yasufumi Ogawa 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 --- 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 #include +#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