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 0EF60A0096 for ; Wed, 8 May 2019 04:04:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7DF74569B; Wed, 8 May 2019 04:03:58 +0200 (CEST) Received: from tama500.ecl.ntt.co.jp (tama500.ecl.ntt.co.jp [129.60.39.148]) by dpdk.org (Postfix) with ESMTP id 9871A374C for ; Wed, 8 May 2019 04:03:53 +0200 (CEST) Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x4823qJM023062; Wed, 8 May 2019 11:03:52 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 11D83EA7093; Wed, 8 May 2019 11:03:52 +0900 (JST) Received: from localhost.localdomain (lobster.nslab.ecl.ntt.co.jp [129.60.13.95]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id F2E08EA407F; Wed, 8 May 2019 11:03:51 +0900 (JST) From: ogawa.yasufumi@lab.ntt.co.jp To: spp@dpdk.org, ferruh.yigit@intel.com, ogawa.yasufumi@lab.ntt.co.jp Date: Wed, 8 May 2019 11:01:21 +0900 Message-Id: <1557280895-7978-4-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1557280895-7978-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> References: <1557280895-7978-1-git-send-email-ogawa.yasufumi@lab.ntt.co.jp> X-TM-AS-MML: disable Subject: [spp] [PATCH 03/17] shared/sec: revice cmd parser of SPP worker 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 The name of header file of command parser for SPP worker threads is `command_dec.h` which means "decode commands", but the features are not for decoding but parsing. This update is to change it to `cmd_parser.h` and refactor name of vars, functions and its comments defined in the header file. This update also includes refactoring name of attributes of sppwk_parse_err_msg object and comments for functions in which this object is used. Signed-off-by: Yasufumi Ogawa --- src/mirror/spp_mirror.c | 2 +- .../secondary/spp_worker_th/cmd_parser.h | 156 ++++++++++++++ .../secondary/spp_worker_th/command_dec.c | 84 ++++---- .../secondary/spp_worker_th/command_dec.h | 203 ------------------ .../secondary/spp_worker_th/command_proc.c | 12 +- src/vf/spp_vf.c | 2 +- 6 files changed, 207 insertions(+), 252 deletions(-) create mode 100644 src/shared/secondary/spp_worker_th/cmd_parser.h delete mode 100644 src/shared/secondary/spp_worker_th/command_dec.h diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c index ba0919a..6d01501 100644 --- a/src/mirror/spp_mirror.c +++ b/src/mirror/spp_mirror.c @@ -13,7 +13,7 @@ #include "shared/common.h" #include "shared/secondary/utils.h" #include "shared/secondary/spp_worker_th/command_proc.h" -#include "shared/secondary/spp_worker_th/command_dec.h" +#include "shared/secondary/spp_worker_th/cmd_parser.h" #include "shared/secondary/spp_worker_th/spp_proc.h" #include "shared/secondary/spp_worker_th/spp_port.h" diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h new file mode 100644 index 0000000..6792b08 --- /dev/null +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -0,0 +1,156 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2017-2018 Nippon Telegraph and Telephone Corporation + */ + +#ifndef _SPPWK_CMD_PARSER_H_ +#define _SPPWK_CMD_PARSER_H_ + +/** + * @file cmd_parser.h + * @brief Define a set of vars and functions for parsing SPP worker commands. + */ + +#include "spp_proc.h" + +/* Maximum number of commands per request. */ +#define SPP_CMD_MAX_COMMANDS 32 + +/* Maximum number of parameters per command. */ +#define SPP_CMD_MAX_PARAMETERS 8 + +/* Size of string buffer of message including null char. */ +#define SPP_CMD_NAME_BUFSZ 32 + +/* Size of string buffer of detailed message including null char. */ +#define SPP_CMD_VALUE_BUFSZ 111 + +/* Fix value for 'unused' status. */ +#define SPP_CMD_UNUSE "unuse" + +/** + * Error code for diagnosis and notifying the reason. It starts from 1 because + * 0 is used for succeeded and not appropriate for error in general. + */ +enum sppwk_parse_error_code { + SPPWK_PARSE_WRONG_FORMAT = 1, /**< Wrong format */ + SPPWK_PARSE_UNKNOWN_CMD, /**< Unknown command */ + SPPWK_PARSE_NO_PARAM, /**< No parameters */ + SPPWK_PARSE_INVALID_TYPE, /**< Invalid data type */ + SPPWK_PARSE_INVALID_VALUE, /**< Invalid value */ +}; + +/** + * Define actions of SPP worker threads. Each of targeting objects and actions + * is defined as following. + * - compomnent : start, stop + * - port : add, del + * - classifier_table: add, del + */ +/* TODO(yasufum) refactor each name prefix `SPP_CMD_ACTION_`. */ +enum spp_command_action { + SPP_CMD_ACTION_NONE, /**< none */ + SPP_CMD_ACTION_START, /**< start */ + SPP_CMD_ACTION_STOP, /**< stop */ + SPP_CMD_ACTION_ADD, /**< add */ + SPP_CMD_ACTION_DEL, /**< delete */ +}; + +/** + * SPP command type. + * + * @attention This enumerated type must have the same order of command_list + * defined in command_dec.c + */ +/* TODO(yasufum) refactor each name prefix `SPP_`. */ +enum spp_command_type { + SPP_CMDTYPE_CLASSIFIER_TABLE_MAC, + SPP_CMDTYPE_CLASSIFIER_TABLE_VLAN, + SPP_CMDTYPE_CLIENT_ID, /**< get_client_id */ + SPP_CMDTYPE_STATUS, /**< status */ + SPP_CMDTYPE_EXIT, /**< exit */ + SPP_CMDTYPE_COMPONENT, /**< component */ + SPP_CMDTYPE_PORT, /**< port */ +}; + +/* `classifier_table` command specific parameters. */ +struct spp_command_classifier_table { + enum spp_command_action action; /**< add or del */ + enum spp_classifier_type type; /**< currently only for mac */ + int vid; /**< VLAN ID */ + char mac[SPP_CMD_VALUE_BUFSZ]; /**< MAC address */ + struct spp_port_index port;/**< Destination port type and number */ +}; + +/* `flush` command specific parameters. */ +struct spp_command_flush { + /* nothing specific */ +}; + +/* `component` command parameters. */ +struct spp_command_component { + enum spp_command_action action; /**< start or stop */ + char name[SPP_CMD_NAME_BUFSZ]; /**< component name */ + unsigned int core; /**< logical core number */ + enum spp_component_type type; /**< component type */ +}; + +/* `port` command parameters. */ +struct spp_command_port { + enum spp_command_action action; /**< add or del */ + struct spp_port_index port; /**< port type and number */ + enum spp_port_rxtx rxtx; /**< rx or tx identifier */ + char name[SPP_CMD_NAME_BUFSZ]; /**< component name */ + struct spp_port_ability ability; /**< port ability */ +}; + +struct spp_command { + enum spp_command_type type; /**< command type */ + + union { /**< command descriptors */ + struct spp_command_classifier_table classifier_table; + struct spp_command_flush flush; + struct spp_command_component component; + struct spp_command_port port; + } spec; +}; + +/* Request parameters. */ +struct spp_command_request { + int num_command; /**< Number of accepted commands */ + int num_valid_command; /**< Number of executed commands */ + struct spp_command commands[SPP_CMD_MAX_COMMANDS]; /**< list of cmds */ + + int is_requested_client_id; + int is_requested_status; + int is_requested_exit; +}; + +/* Error message if parse failed. */ +struct sppwk_parse_err_msg { + int code; /**< Code in enu sppwk_parse_error_code */ + char msg[SPP_CMD_NAME_BUFSZ]; /**< Message in short */ + char details[SPP_CMD_VALUE_BUFSZ]; /**< Detailed message */ +}; + +/** + * Parse request of non null terminated string. + * + * @param request + * The pointer to struct spp_command_request.@n + * The result value of decoding the command message. + * @param request_str + * The pointer to requested command message. + * @param request_str_len + * The length of requested command message. + * @param wk_err_msg + * The pointer to struct sppwk_parse_err_msg.@n + * Detailed error information will be stored. + * + * @retval SPP_RET_OK succeeded. + * @retval !0 failed. + */ +int spp_command_decode_request(struct spp_command_request *request, + const char *request_str, size_t request_str_len, + struct sppwk_parse_err_msg *wk_err_msg); + +#endif /* _SPPWK_CMD_PARSER_H_ */ diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index db69dfe..77f15c5 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -9,7 +9,7 @@ #include #include -#include "command_dec.h" +#include "cmd_parser.h" #define RTE_LOGTYPE_SPP_COMMAND_PROC RTE_LOGTYPE_USER1 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER2 @@ -58,7 +58,7 @@ const char *CLASSIFILER_TYPE_STRINGS[] = { /* * command action type string list - * do it same as the order of enum spp_command_action (command_dec.h) + * do it same as the order of enum spp_command_action (cmd_parser.h) */ const char *COMMAND_ACTION_STRINGS[] = { SPP_ACTION_NONE_STR, @@ -201,29 +201,29 @@ spp_convert_component_type(const char *type_str) return SPP_COMPONENT_UNUSE; } -/* Format error message object and return error code for an error case */ +/* Format error message object and return error code for an error case. */ static inline int -set_parse_error(struct sppwk_parse_err_msg *err_msg, - const int err_code, const char *err_name) +set_parse_error(struct sppwk_parse_err_msg *wk_err_msg, + const int err_code, const char *err_msg) { - err_msg->code = err_code; + wk_err_msg->code = err_code; - if (likely(err_name != NULL)) - strcpy(err_msg->value_name, err_name); + if (likely(err_msg != NULL)) + strcpy(wk_err_msg->msg, err_msg); - return err_msg->code; + return wk_err_msg->code; } -/* set decode error */ +/* Set parse error message. */ static inline int -set_string_value_decode_error(struct sppwk_parse_err_msg *error, - const char *value, const char *error_name) +set_string_value_decode_error(struct sppwk_parse_err_msg *wk_err_msg, + const char *err_details, const char *err_msg) { - strcpy(error->value, value); - return set_parse_error(error, SPPWK_PARSE_INVALID_VALUE, error_name); + strcpy(wk_err_msg->details, err_details); + return set_parse_error(wk_err_msg, SPPWK_PARSE_INVALID_VALUE, err_msg); } -/* Split command line parameter with spaces */ +/* Split command line parameter with spaces. */ static int decode_parameter_value(char *string, int max, int *argc, char *argv[]) { @@ -453,7 +453,7 @@ decode_port_action_value(void *output, const char *arg_val, return SPP_RET_OK; } -/* decoding procedure of port for port command */ +/* decoding procedure of port for port command. */ static int decode_port_port_value(void *output, const char *arg_val, int allow_override) { @@ -894,11 +894,11 @@ parameter_list[][SPP_CMD_MAX_PARAMETERS] = { { DECODE_PARAMETER_LIST_EMPTY }, /* termination */ }; -/* check by list for each command line parameter component */ +/* Validate given command. */ static int decode_command_parameter_component(struct spp_command_request *request, int argc, char *argv[], - struct sppwk_parse_err_msg *error, + struct sppwk_parse_err_msg *wk_err_msg, int maxargc __attribute__ ((unused))) { int ret = SPP_RET_OK; @@ -912,34 +912,34 @@ decode_command_parameter_component(struct spp_command_request *request, argv[pi], 0); if (unlikely(ret < 0)) { RTE_LOG(ERR, SPP_COMMAND_PROC, - "Bad value. command=%s, name=%s, " + "Invalid value. command=%s, name=%s, " "index=%d, value=%s\n", argv[0], list->name, pi, argv[pi]); - return set_string_value_decode_error(error, argv[pi], - list->name); + return set_string_value_decode_error(wk_err_msg, + argv[pi], list->name); } } return SPP_RET_OK; } -/* check by list for each command line parameter clssfier_table */ +/* Validate given command for clssfier_table. */ static int decode_command_parameter_cls_table(struct spp_command_request *request, int argc, char *argv[], - struct sppwk_parse_err_msg *error, + struct sppwk_parse_err_msg *wk_err_msg, int maxargc) { return decode_command_parameter_component(request, argc, argv, - error, + wk_err_msg, maxargc); } -/* check by list for each command line parameter clssfier_table(vlan) */ +/* Validate given command for clssfier_table of vlan. */ static int decode_command_parameter_cls_table_vlan(struct spp_command_request *request, int argc, char *argv[], - struct sppwk_parse_err_msg *error, + struct sppwk_parse_err_msg *wk_err_msg, int maxargc __attribute__ ((unused))) { int ret = SPP_RET_OK; @@ -955,18 +955,18 @@ decode_command_parameter_cls_table_vlan(struct spp_command_request *request, RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad value. " "command=%s, name=%s, index=%d, value=%s\n", argv[0], list->name, pi, argv[pi]); - return set_string_value_decode_error(error, argv[pi], - list->name); + return set_string_value_decode_error(wk_err_msg, + argv[pi], list->name); } } return SPP_RET_OK; } -/* check by list for each command line parameter port */ +/* Validate given command for port. */ static int decode_command_parameter_port(struct spp_command_request *request, int argc, char *argv[], - struct sppwk_parse_err_msg *error, + struct sppwk_parse_err_msg *wk_err_msg, int maxargc) { int ret = SPP_RET_OK; @@ -988,8 +988,8 @@ decode_command_parameter_port(struct spp_command_request *request, RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad value. " "command=%s, name=%s, index=%d, value=%s\n", argv[0], list->name, pi, argv[pi]); - return set_string_value_decode_error(error, argv[pi], - list->name); + return set_string_value_decode_error(wk_err_msg, + argv[pi], list->name); } } return SPP_RET_OK; @@ -1001,7 +1001,7 @@ struct decode_command_list { int param_min; /* Min number of parameters */ int param_max; /* Max number of parameters */ int (*func)(struct spp_command_request *request, int argc, - char *argv[], struct sppwk_parse_err_msg *error, + char *argv[], struct sppwk_parse_err_msg *wk_err_msg, int maxargc); /* Pointer to command handling function */ }; @@ -1024,11 +1024,11 @@ static struct decode_command_list command_list[] = { { "", 0, 0, NULL } /* termination */ }; -/* Decode command line parameters */ +/* Parse command line parameters. */ static int decode_command_in_list(struct spp_command_request *request, const char *request_str, - struct sppwk_parse_err_msg *error) + struct sppwk_parse_err_msg *wk_err_msg) { int ret = SPP_RET_OK; int command_name_check = 0; @@ -1046,7 +1046,8 @@ decode_command_in_list(struct spp_command_request *request, if (ret < SPP_RET_OK) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Parameter number over limit." "request_str=%s\n", request_str); - return set_parse_error(error, SPPWK_PARSE_WRONG_FORMAT, NULL); + return set_parse_error(wk_err_msg, SPPWK_PARSE_WRONG_FORMAT, + NULL); } RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array. num=%d\n", argc); @@ -1063,7 +1064,7 @@ decode_command_in_list(struct spp_command_request *request, request->commands[0].type = i; if (list->func != NULL) - return (*list->func)(request, argc, argv, error, + return (*list->func)(request, argc, argv, wk_err_msg, list->param_max); return SPP_RET_OK; @@ -1072,13 +1073,14 @@ decode_command_in_list(struct spp_command_request *request, if (command_name_check != 0) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Parameter number out of range." "request_str=%s\n", request_str); - return set_parse_error(error, SPPWK_PARSE_WRONG_FORMAT, NULL); + return set_parse_error(wk_err_msg, SPPWK_PARSE_WRONG_FORMAT, + NULL); } RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown command. command=%s, request_str=%s\n", argv[0], request_str); - return set_string_value_decode_error(error, argv[0], "command"); + return set_string_value_decode_error(wk_err_msg, argv[0], "command"); } /* decode request from no-null-terminated string */ @@ -1086,14 +1088,14 @@ int spp_command_decode_request( struct spp_command_request *request, const char *request_str, size_t request_str_len, - struct sppwk_parse_err_msg *error) + struct sppwk_parse_err_msg *wk_err_msg) { int ret = SPP_RET_NG; int i; /* decode request */ request->num_command = 1; - ret = decode_command_in_list(request, request_str, error); + ret = decode_command_in_list(request, request_str, wk_err_msg); if (unlikely(ret != SPP_RET_OK)) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Cannot decode command request. " diff --git a/src/shared/secondary/spp_worker_th/command_dec.h b/src/shared/secondary/spp_worker_th/command_dec.h deleted file mode 100644 index 7da562a..0000000 --- a/src/shared/secondary/spp_worker_th/command_dec.h +++ /dev/null @@ -1,203 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2017-2018 Nippon Telegraph and Telephone Corporation - */ - -#ifndef _COMMAND_DEC_H_ -#define _COMMAND_DEC_H_ - -/** - * @file - * SPP command decode - * - * Decode and validate the command message string. - */ - -#include "spp_proc.h" - -/** max number of command per request */ -#define SPP_CMD_MAX_COMMANDS 32 - -/** maximum number of parameters per command */ -#define SPP_CMD_MAX_PARAMETERS 8 - -/** command name string buffer size (include null char) */ -#define SPP_CMD_NAME_BUFSZ 32 - -/** command value string buffer size (include null char) */ -#define SPP_CMD_VALUE_BUFSZ 111 - -/** string that specify unused */ -#define SPP_CMD_UNUSE "unuse" - -/** - * Error code for diagnosis and notifying the reason. It starts from 1 because - * 0 is used for succeeded and not appropriate for error in general. - */ -enum sppwk_parse_error_code { - SPPWK_PARSE_WRONG_FORMAT = 1, /**< Wrong format */ - SPPWK_PARSE_UNKNOWN_CMD, /**< Unknown command */ - SPPWK_PARSE_NO_PARAM, /**< No parameters */ - SPPWK_PARSE_INVALID_TYPE, /**< Invalid data type */ - SPPWK_PARSE_INVALID_VALUE, /**< Invalid value */ -}; - -/** - * Define actions of each of components - * The Run option of the folllwing commands. - * compomnent : start,stop - * port : add,del - * classifier_table : add,del - */ -enum spp_command_action { - SPP_CMD_ACTION_NONE, /**< none */ - SPP_CMD_ACTION_START, /**< start */ - SPP_CMD_ACTION_STOP, /**< stop */ - SPP_CMD_ACTION_ADD, /**< add */ - SPP_CMD_ACTION_DEL, /**< delete */ -}; - -/** - * spp command type. - * - * @attention This enumerated type must have the same order of command_list - * defined in command_dec.c - */ -enum spp_command_type { - /** classifier_table command(mac) */ - SPP_CMDTYPE_CLASSIFIER_TABLE_MAC, - - /** classifier_table command(VLAN) */ - SPP_CMDTYPE_CLASSIFIER_TABLE_VLAN, - - /** get_client_id command */ - SPP_CMDTYPE_CLIENT_ID, - - /** status command */ - SPP_CMDTYPE_STATUS, - - /** exit command */ - SPP_CMDTYPE_EXIT, - - /** component command */ - SPP_CMDTYPE_COMPONENT, - - /** port command */ - SPP_CMDTYPE_PORT, -}; - -/** "classifier_table" command specific parameters */ -struct spp_command_classifier_table { - /** Action identifier (add or del) */ - enum spp_command_action action; - - /** Classify type (currently only for mac) */ - enum spp_classifier_type type; - - /** VLAN ID to be classified */ - int vid; - - /** MAC address to be classified */ - char mac[SPP_CMD_VALUE_BUFSZ]; - - /** Destination port type and number */ - struct spp_port_index port; -}; - -/* "flush" command specific parameters */ -struct spp_command_flush { - /* nothing specific */ -}; - -/** "component" command parameters */ -struct spp_command_component { - /** Action identifier (start or stop) */ - enum spp_command_action action; - - /** Component name */ - char name[SPP_CMD_NAME_BUFSZ]; - - /** Logical core number */ - unsigned int core; - - /** Component type */ - enum spp_component_type type; -}; - -/** "port" command parameters */ -struct spp_command_port { - /** Action identifier (add or del) */ - enum spp_command_action action; - - /** Port type and number */ - struct spp_port_index port; - - /** rx/tx identifier */ - enum spp_port_rxtx rxtx; - - /** Attached component name */ - char name[SPP_CMD_NAME_BUFSZ]; - - /** Port ability */ - struct spp_port_ability ability; -}; - -/** command parameters */ -struct spp_command { - enum spp_command_type type; /**< Command type */ - - union { - /** Structured data for classifier_table command */ - struct spp_command_classifier_table classifier_table; - - /** Structured data for flush command */ - struct spp_command_flush flush; - - /** Structured data for component command */ - struct spp_command_component component; - - /** Structured data for port command */ - struct spp_command_port port; - } spec; -}; - -/** request parameters */ -struct spp_command_request { - int num_command; /**< Number of accepted commands */ - int num_valid_command; /**< Number of executed commands */ - struct spp_command commands[SPP_CMD_MAX_COMMANDS]; - /**value); + sprintf(message, "Unknown command(%s)", err_msg->details); break; case SPPWK_PARSE_NO_PARAM: sprintf(message, "No or insufficient number of params (%s)", - err_msg->value_name); + err_msg->msg); break; case SPPWK_PARSE_INVALID_TYPE: sprintf(message, "Invalid value type (%s)", - err_msg->value_name); + err_msg->msg); break; case SPPWK_PARSE_INVALID_VALUE: - sprintf(message, "Invalid value (%s)", err_msg->value_name); + sprintf(message, "Invalid value (%s)", err_msg->msg); break; default: diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c index b2acb58..9831058 100644 --- a/src/vf/spp_vf.c +++ b/src/vf/spp_vf.c @@ -11,7 +11,7 @@ #include "classifier_mac.h" #include "spp_forward.h" #include "shared/secondary/spp_worker_th/command_proc.h" -#include "shared/secondary/spp_worker_th/command_dec.h" +#include "shared/secondary/spp_worker_th/cmd_parser.h" #include "shared/secondary/spp_worker_th/spp_port.h" /* Declare global variables */ -- 2.17.1