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 8206CA046B for ; Mon, 24 Jun 2019 06:36:51 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7AC1B1BF2C; Mon, 24 Jun 2019 06:36:51 +0200 (CEST) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 9429E1BF2C for ; Mon, 24 Jun 2019 06:36:50 +0200 (CEST) Received: by mail-pf1-f194.google.com with SMTP id r7so6769314pfl.3 for ; Sun, 23 Jun 2019 21:36:50 -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=yWBqtZEz26jOSiFKfgxHoLMT73kVR7F5OGG12TzcBwI=; b=VVHM2MjsJjCrdvMtExYYrufKFS7KUAo/Id8+0ffT0fgHpRZIqo2LzGLOIlrmaJw60W RA07tX0SYuJ8o0kJ1367VLXtLJn8xG/0gnKdzMGaGI5WfUHa+EVN8B0tG/KkIRlXgG3X ZiUwQNf+NyQ9veMsdgqg2aBe7cKSy7jT1RqzgIv/aHQX/prsumuvKAUMjKSyb7DCCiZa O5nH9WTYdR9Nfl3GAQ5Pa27C8IQpihXAb510ClWpSP/UylSGuqUnpINSvLD1jYpIpJOF S/gEiKb3kfubNZyE8T1/2AaGFSRTFMf0t5MQAxRF29Ng+tekD2zb5qRZ4EkGIUeboEAE b3HA== 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=yWBqtZEz26jOSiFKfgxHoLMT73kVR7F5OGG12TzcBwI=; b=RUsqBqXazQfcXkOZnZySyPfmK++9G/CSc7IiexDBvSbjrhc+oWbAV6W73IqJDDiWiv rI4gQn20ODvWjMMd+E4WK1GpH8n0JdzXuMODTMgJPVgLm8bHbWlHsXnqKd9SRF55Cgaw P0pzEGd80J7FdwPPfTlawpgl4TMtB/tQGGBkDlg0s+wilI8hNOemeD4388L7DAsV1Uvv 9KLzrD3zkHHvkQqXVcI8nzj5oixqcutBhw/lJesC4NArUcu9MqgauG7QEmesHMvrh/7m orHFo5+XjMX51gKi+WUlD3Yp8mEHTb+LdgnlHE3UCUuQKIUHujQ5EkyPTErFotw02Ox4 LJzw== X-Gm-Message-State: APjAAAXXL2gw6qvBAo3pdunOvSlBH1URbr7zMV6K0uCYsCB301AIZdHa N/x5iBhHtNFJW6M4N+5fHIPZTkkg X-Google-Smtp-Source: APXvYqyEjWsxMzWcdeQQKsH4wum8r+NK2/UMbDLBUpHjAA6J2B0cYny5SEGn6U3+kQ+YPp3mdtYS0Q== X-Received: by 2002:a17:90a:23ce:: with SMTP id g72mr22495092pje.77.1561351009405; Sun, 23 Jun 2019 21:36:49 -0700 (PDT) Received: from localhost.localdomain ([192.47.164.146]) by smtp.gmail.com with ESMTPSA id c10sm9005178pjq.14.2019.06.23.21.36.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 23 Jun 2019 21:36:49 -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:08 +0900 Message-Id: <20190624043613.19271-9-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 08/13] shared/sec: move rest of JSON formatters 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 This update is to move the rest of JSON formatters defined in `cmd_runner.c`. Signed-off-by: Yasufumi Ogawa --- .../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(¶ms, 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