From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Hi, The name of group of spp_vf siblings is changed to SPP worker for removing ambiguity by which prefix of libs of SPP worker `spp_` is renamed to `sppwk_`. For this update, each of common functions and vars should also be renamed. This series of patches is the first step of the update. * Rename `command_dec.h` to `cmd_parser.h`. * Update all of functions and vars in `cmd_parser.h` to apply with the above changes. Regards, Yasufumi Yasufumi Ogawa (17): shared/sec: change prefix of common functions shared/sec: refactor parse error code shared/sec: revice cmd parser of SPP worker shared/sec: refactor branching for cmd action shared/sec: rename define starts from SPP_CMD_MAX shared/sec: rename define of buffer size for cmds shared/sec: remove unused define of cmd parser shared/sec: refactor commad type of SPP worker shared/sec: change struct of classier table attrs shared/sec: refactor function parsing cls port shared/sec: rename func of flush command shared/sec: change struct of comp command shared/sec: revise port info of SPP worker shared/sec: rename func for getting port ID shared/sec: rename dpdk_port attr shared/sec: rename struct for command request shared/sec: rename func for parsing request src/mirror/spp_mirror.c | 30 +-- .../secondary/spp_worker_th/cmd_parser.h | 157 ++++++++++++ .../secondary/spp_worker_th/command_dec.c | 233 +++++++++--------- .../secondary/spp_worker_th/command_dec.h | 201 --------------- .../secondary/spp_worker_th/command_proc.c | 168 ++++++------- src/shared/secondary/spp_worker_th/spp_port.c | 6 +- src/shared/secondary/spp_worker_th/spp_proc.c | 80 +++--- src/shared/secondary/spp_worker_th/spp_proc.h | 72 +++--- src/vf/classifier_mac.c | 42 ++-- src/vf/spp_forward.c | 26 +- src/vf/spp_vf.c | 2 +- 11 files changed, 487 insertions(+), 530 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 -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Some of common functions are prefixed with `spp_`, but not common especially for spp_vf siblings. From this patch, change the prefix to `sppwk_` to be more specific. The meaning of `sppwk` is “SPP worker (thread)”. This patch is to refactor struct `spp_command_decode_error` to `sppwk_parse_err_msg`. It also include refactor of func names, such as from `set_decode_error()` to `set_parse_error()` for formatting error message object because it does not decode actually. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/command_dec.c | 36 +++++++++---------- .../secondary/spp_worker_th/command_dec.h | 6 ++-- .../secondary/spp_worker_th/command_proc.c | 28 +++++++-------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 9523ab9..236cabf 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -201,26 +201,26 @@ spp_convert_component_type(const char *type_str) return SPP_COMPONENT_UNUSE; } -/* set decode error */ +/* Format error message object and return error code for an error case */ static inline int -set_decode_error(struct spp_command_decode_error *error, - const int error_code, const char *error_name) +set_parse_error(struct sppwk_parse_err_msg *err_msg, + const int err_code, const char *err_name) { - error->code = error_code; + err_msg->code = err_code; - if (likely(error_name != NULL)) - strcpy(error->value_name, error_name); + if (likely(err_name != NULL)) + strcpy(err_msg->value_name, err_name); - return error->code; + return err_msg->code; } /* set decode error */ static inline int -set_string_value_decode_error(struct spp_command_decode_error *error, +set_string_value_decode_error(struct sppwk_parse_err_msg *error, const char *value, const char *error_name) { strcpy(error->value, value); - return set_decode_error(error, SPP_CMD_DERR_BAD_VALUE, error_name); + return set_parse_error(error, SPP_CMD_DERR_BAD_VALUE, error_name); } /* Split command line parameter with spaces */ @@ -898,7 +898,7 @@ parameter_list[][SPP_CMD_MAX_PARAMETERS] = { static int decode_command_parameter_component(struct spp_command_request *request, int argc, char *argv[], - struct spp_command_decode_error *error, + struct sppwk_parse_err_msg *error, int maxargc __attribute__ ((unused))) { int ret = SPP_RET_OK; @@ -926,7 +926,7 @@ decode_command_parameter_component(struct spp_command_request *request, static int decode_command_parameter_cls_table(struct spp_command_request *request, int argc, char *argv[], - struct spp_command_decode_error *error, + struct sppwk_parse_err_msg *error, int maxargc) { return decode_command_parameter_component(request, @@ -939,7 +939,7 @@ decode_command_parameter_cls_table(struct spp_command_request *request, static int decode_command_parameter_cls_table_vlan(struct spp_command_request *request, int argc, char *argv[], - struct spp_command_decode_error *error, + struct sppwk_parse_err_msg *error, int maxargc __attribute__ ((unused))) { int ret = SPP_RET_OK; @@ -966,7 +966,7 @@ decode_command_parameter_cls_table_vlan(struct spp_command_request *request, static int decode_command_parameter_port(struct spp_command_request *request, int argc, char *argv[], - struct spp_command_decode_error *error, + struct sppwk_parse_err_msg *error, int maxargc) { int ret = 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 spp_command_decode_error *error, + char *argv[], struct sppwk_parse_err_msg *error, int maxargc); /* Pointer to command handling function */ }; @@ -1028,7 +1028,7 @@ static struct decode_command_list command_list[] = { static int decode_command_in_list(struct spp_command_request *request, const char *request_str, - struct spp_command_decode_error *error) + struct sppwk_parse_err_msg *error) { int ret = SPP_RET_OK; int command_name_check = 0; @@ -1046,7 +1046,7 @@ 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_decode_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL); + return set_parse_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL); } RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array. num=%d\n", argc); @@ -1072,7 +1072,7 @@ 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_decode_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL); + return set_parse_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL); } RTE_LOG(ERR, SPP_COMMAND_PROC, @@ -1086,7 +1086,7 @@ int spp_command_decode_request( struct spp_command_request *request, const char *request_str, size_t request_str_len, - struct spp_command_decode_error *error) + struct sppwk_parse_err_msg *error) { int ret = SPP_RET_NG; int i; diff --git a/src/shared/secondary/spp_worker_th/command_dec.h b/src/shared/secondary/spp_worker_th/command_dec.h index 93b4ebe..da94cf3 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.h +++ b/src/shared/secondary/spp_worker_th/command_dec.h @@ -171,7 +171,7 @@ struct spp_command_request { }; /** decode error information */ -struct spp_command_decode_error { +struct sppwk_parse_err_msg { int code; /**< Error code */ char value_name[SPP_CMD_NAME_BUFSZ]; /**< Error value name */ char value[SPP_CMD_VALUE_BUFSZ]; /**< Error value */ @@ -188,7 +188,7 @@ struct spp_command_decode_error { * @param request_str_len * The length of requested command message. * @param error - * The pointer to struct spp_command_decode_error.@n + * The pointer to struct sppwk_parse_err_msg.@n * Detailed error information will be stored. * * @retval SPP_RET_OK succeeded. @@ -196,6 +196,6 @@ struct spp_command_decode_error { */ int spp_command_decode_request(struct spp_command_request *request, const char *request_str, size_t request_str_len, - struct spp_command_decode_error *error); + struct sppwk_parse_err_msg *err_msg); #endif /* _COMMAND_DEC_H_ */ diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 1e16bd0..40b3121 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -805,30 +805,30 @@ execute_command(const struct spp_command *command) /* make decode error message for response */ static const char * make_decode_error_message( - const struct spp_command_decode_error *decode_error, + const struct sppwk_parse_err_msg *err_msg, char *message) { - switch (decode_error->code) { + switch (err_msg->code) { case SPP_CMD_DERR_BAD_FORMAT: sprintf(message, "bad message format"); break; case SPP_CMD_DERR_UNKNOWN_COMMAND: - sprintf(message, "unknown command(%s)", decode_error->value); + sprintf(message, "unknown command(%s)", err_msg->value); break; case SPP_CMD_DERR_NO_PARAM: sprintf(message, "not enough parameter(%s)", - decode_error->value_name); + err_msg->value_name); break; case SPP_CMD_DERR_BAD_TYPE: sprintf(message, "bad value type(%s)", - decode_error->value_name); + err_msg->value_name); break; case SPP_CMD_DERR_BAD_VALUE: - sprintf(message, "bad value(%s)", decode_error->value_name); + sprintf(message, "bad value(%s)", err_msg->value_name); break; default: @@ -866,21 +866,21 @@ set_command_results(struct command_result *result, static void set_decode_error_to_results(struct command_result *results, const struct spp_command_request *request, - const struct spp_command_decode_error *decode_error) + const struct sppwk_parse_err_msg *err_msg) { int i; const char *tmp_buff; char error_messege[CMD_RES_ERR_MSG_SIZE]; for (i = 0; i < request->num_command; i++) { - if (decode_error->code == 0) + if (err_msg->code == 0) set_command_results(&results[i], CRES_SUCCESS, ""); else set_command_results(&results[i], CRES_INVALID, ""); } - if (decode_error->code != 0) { - tmp_buff = make_decode_error_message(decode_error, + if (err_msg->code != 0) { + tmp_buff = make_decode_error_message(err_msg, error_messege); set_command_results(&results[request->num_valid_command], CRES_FAILURE, tmp_buff); @@ -1646,11 +1646,11 @@ process_request(int *sock, const char *request_str, size_t request_str_len) int i; struct spp_command_request request; - struct spp_command_decode_error decode_error; + struct sppwk_parse_err_msg wk_err_msg; struct command_result command_results[SPP_CMD_MAX_COMMANDS]; memset(&request, 0, sizeof(struct spp_command_request)); - memset(&decode_error, 0, sizeof(struct spp_command_decode_error)); + memset(&wk_err_msg, 0, sizeof(struct sppwk_parse_err_msg)); memset(command_results, 0, sizeof(command_results)); RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Start command request processing. " @@ -1659,11 +1659,11 @@ process_request(int *sock, const char *request_str, size_t request_str_len) /* decode request message */ ret = spp_command_decode_request( - &request, request_str, request_str_len, &decode_error); + &request, request_str, request_str_len, &wk_err_msg); if (unlikely(ret != SPP_RET_OK)) { /* send error response */ set_decode_error_to_results(command_results, &request, - &decode_error); + &wk_err_msg); send_decode_error_response(sock, &request, command_results); RTE_LOG(DEBUG, SPP_COMMAND_PROC, "End command request processing.\n"); -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Revise the name of enum `spp_comamnd_decode_error_code` to `sppwk_parse_error_code`, and its members started from `SPP_CMD_DERR_` to `SPPWK_PARSE_` to be more reasonable. The prefix of the members does not need to include the word `ERR` because following word, such as `INVALID_VALUE`, can be understood as error. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/command_dec.c | 6 ++--- .../secondary/spp_worker_th/command_dec.h | 18 ++++++++------- .../secondary/spp_worker_th/command_proc.c | 23 ++++++++++--------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 236cabf..db69dfe 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -220,7 +220,7 @@ set_string_value_decode_error(struct sppwk_parse_err_msg *error, const char *value, const char *error_name) { strcpy(error->value, value); - return set_parse_error(error, SPP_CMD_DERR_BAD_VALUE, error_name); + return set_parse_error(error, SPPWK_PARSE_INVALID_VALUE, error_name); } /* Split command line parameter with spaces */ @@ -1046,7 +1046,7 @@ 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, SPP_CMD_DERR_BAD_FORMAT, NULL); + return set_parse_error(error, SPPWK_PARSE_WRONG_FORMAT, NULL); } RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array. num=%d\n", argc); @@ -1072,7 +1072,7 @@ 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, SPP_CMD_DERR_BAD_FORMAT, NULL); + return set_parse_error(error, SPPWK_PARSE_WRONG_FORMAT, NULL); } RTE_LOG(ERR, SPP_COMMAND_PROC, diff --git a/src/shared/secondary/spp_worker_th/command_dec.h b/src/shared/secondary/spp_worker_th/command_dec.h index da94cf3..7da562a 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.h +++ b/src/shared/secondary/spp_worker_th/command_dec.h @@ -29,14 +29,16 @@ /** string that specify unused */ #define SPP_CMD_UNUSE "unuse" -/** decode error code */ -enum spp_command_decode_error_code { - /* not use 0, in general 0 is OK */ - SPP_CMD_DERR_BAD_FORMAT = 1, /**< Wrong format */ - SPP_CMD_DERR_UNKNOWN_COMMAND, /**< Unknown command */ - SPP_CMD_DERR_NO_PARAM, /**< No parameters */ - SPP_CMD_DERR_BAD_TYPE, /**< Wrong data type */ - SPP_CMD_DERR_BAD_VALUE, /**< Wrong value */ +/** + * 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 */ }; /** diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 40b3121..2911266 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -809,30 +809,31 @@ make_decode_error_message( char *message) { switch (err_msg->code) { - case SPP_CMD_DERR_BAD_FORMAT: - sprintf(message, "bad message format"); + case SPPWK_PARSE_WRONG_FORMAT: + sprintf(message, "Wrong message format"); break; - case SPP_CMD_DERR_UNKNOWN_COMMAND: - sprintf(message, "unknown command(%s)", err_msg->value); + case SPPWK_PARSE_UNKNOWN_CMD: + /* TODO(yasufum) Fix compile err if space exists before "(" */ + sprintf(message, "Unknown command(%s)", err_msg->value); break; - case SPP_CMD_DERR_NO_PARAM: - sprintf(message, "not enough parameter(%s)", + case SPPWK_PARSE_NO_PARAM: + sprintf(message, "No or insufficient number of params (%s)", err_msg->value_name); break; - case SPP_CMD_DERR_BAD_TYPE: - sprintf(message, "bad value type(%s)", + case SPPWK_PARSE_INVALID_TYPE: + sprintf(message, "Invalid value type (%s)", err_msg->value_name); break; - case SPP_CMD_DERR_BAD_VALUE: - sprintf(message, "bad value(%s)", err_msg->value_name); + case SPPWK_PARSE_INVALID_VALUE: + sprintf(message, "Invalid value (%s)", err_msg->value_name); break; default: - sprintf(message, "error occur"); + sprintf(message, "Failed to parse with unexpected reason"); break; } -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> 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 <ogawa.yasufumi@lab.ntt.co.jp> --- 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 <rte_log.h> #include <rte_branch_prediction.h> -#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]; - /**<Information of executed commands */ - - int is_requested_client_id; /**< Id for get_client_id command */ - int is_requested_status; /**< Id for status command */ - int is_requested_exit; /**< Id for exit command */ -}; - -/** decode error information */ -struct sppwk_parse_err_msg { - int code; /**< Error code */ - char value_name[SPP_CMD_NAME_BUFSZ]; /**< Error value name */ - char value[SPP_CMD_VALUE_BUFSZ]; /**< Error value */ -}; - -/** - * decode request from no-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 error - * 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 *err_msg); - -#endif /* _COMMAND_DEC_H_ */ diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 2911266..38cc45f 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -14,7 +14,7 @@ #include "string_buffer.h" #include "command_conn.h" -#include "command_dec.h" +#include "cmd_parser.h" #include "command_proc.h" #define RTE_LOGTYPE_SPP_COMMAND_PROC RTE_LOGTYPE_USER1 @@ -802,7 +802,7 @@ execute_command(const struct spp_command *command) return ret; } -/* make decode error message for response */ +/* Fill err_msg obj with given error message. */ static const char * make_decode_error_message( const struct sppwk_parse_err_msg *err_msg, @@ -815,21 +815,21 @@ make_decode_error_message( case SPPWK_PARSE_UNKNOWN_CMD: /* TODO(yasufum) Fix compile err if space exists before "(" */ - sprintf(message, "Unknown command(%s)", err_msg->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
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> For refactor branching of command action which is too redundant to understand, change the name of enum `spp_command_action` to `sppwk_action` because it is for just SPP worker thread and not for all of SPP processes. Prefix of members of the enum is also changed from `SPP_CMD_ACTION_` to `SPPWK_ACT_` to be more specific and simple to use. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/cmd_parser.h | 19 ++++---- .../secondary/spp_worker_th/command_dec.c | 43 +++++++++---------- .../secondary/spp_worker_th/command_proc.c | 37 ++++++++-------- 3 files changed, 47 insertions(+), 52 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index 6792b08..ccdf6bb 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -46,13 +46,12 @@ enum sppwk_parse_error_code { * - 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 */ +enum sppwk_action { + SPPWK_ACT_NONE, /**< none */ + SPPWK_ACT_START, /**< start */ + SPPWK_ACT_STOP, /**< stop */ + SPPWK_ACT_ADD, /**< add */ + SPPWK_ACT_DEL, /**< delete */ }; /** @@ -74,7 +73,7 @@ enum spp_command_type { /* `classifier_table` command specific parameters. */ struct spp_command_classifier_table { - enum spp_command_action action; /**< add or del */ + enum sppwk_action wk_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 */ @@ -88,7 +87,7 @@ struct spp_command_flush { /* `component` command parameters. */ struct spp_command_component { - enum spp_command_action action; /**< start or stop */ + enum sppwk_action wk_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 */ @@ -96,7 +95,7 @@ struct spp_command_component { /* `port` command parameters. */ struct spp_command_port { - enum spp_command_action action; /**< add or del */ + enum sppwk_action wk_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 */ diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 77f15c5..f9849bb 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -56,9 +56,9 @@ const char *CLASSIFILER_TYPE_STRINGS[] = { /* termination */ "", }; -/* - * command action type string list - * do it same as the order of enum spp_command_action (cmd_parser.h) +/** + * List of command action. The order of items should be same as the order of + * enum `sppwk_action` in cmd_parser.h. */ const char *COMMAND_ACTION_STRINGS[] = { SPP_ACTION_NONE_STR, @@ -66,8 +66,7 @@ const char *COMMAND_ACTION_STRINGS[] = { SPP_ACTION_STOP_STR, SPP_ACTION_ADD_STR, SPP_ACTION_DEL_STR, - - /* termination */ "", + "", /* termination */ }; /* @@ -355,8 +354,8 @@ decode_component_action_value(void *output, const char *arg_val, return SPP_RET_NG; } - if (unlikely(ret != SPP_CMD_ACTION_START) && - unlikely(ret != SPP_CMD_ACTION_STOP)) { + if (unlikely(ret != SPPWK_ACT_START) && + unlikely(ret != SPPWK_ACT_STOP)) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown component action. val=%s\n", arg_val); @@ -376,7 +375,7 @@ decode_component_name_value(void *output, const char *arg_val, struct spp_command_component *component = output; /* "stop" has no core ID parameter. */ - if (component->action == SPP_CMD_ACTION_START) { + if (component->wk_action == SPPWK_ACT_START) { ret = spp_get_component_id(arg_val); if (unlikely(ret >= 0)) { RTE_LOG(ERR, SPP_COMMAND_PROC, @@ -397,7 +396,7 @@ decode_component_core_value(void *output, const char *arg_val, struct spp_command_component *component = output; /* "stop" has no core ID parameter. */ - if (component->action != SPP_CMD_ACTION_START) + if (component->wk_action != SPPWK_ACT_START) return SPP_RET_OK; return decode_core_value(&component->core, arg_val); @@ -412,7 +411,7 @@ decode_component_type_value(void *output, const char *arg_val, struct spp_command_component *component = output; /* "stop" has no type parameter. */ - if (component->action != SPP_CMD_ACTION_START) + if (component->wk_action != SPPWK_ACT_START) return SPP_RET_OK; comp_type = spp_convert_component_type(arg_val); @@ -441,8 +440,8 @@ decode_port_action_value(void *output, const char *arg_val, return SPP_RET_NG; } - if (unlikely(ret != SPP_CMD_ACTION_ADD) && - unlikely(ret != SPP_CMD_ACTION_DEL)) { + if (unlikely(ret != SPPWK_ACT_ADD) && + unlikely(ret != SPPWK_ACT_DEL)) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown port action. val=%s\n", arg_val); @@ -467,7 +466,7 @@ decode_port_port_value(void *output, const char *arg_val, int allow_override) /* add vlantag command check */ if (allow_override == 0) { - if ((port->action == SPP_CMD_ACTION_ADD) && + if ((port->wk_action == SPPWK_ACT_ADD) && (spp_check_used_port(tmp_port.iface_type, tmp_port.iface_no, SPP_PORT_RXTX_RX) >= 0) && @@ -502,7 +501,7 @@ decode_port_rxtx_value(void *output, const char *arg_val, int allow_override) /* add vlantag command check */ if (allow_override == 0) { - if ((port->action == SPP_CMD_ACTION_ADD) && + if ((port->wk_action == SPPWK_ACT_ADD) && (spp_check_used_port(port->port.iface_type, port->port.iface_no, ret) >= 0)) { RTE_LOG(ERR, SPP_COMMAND_PROC, @@ -656,8 +655,8 @@ decode_classifier_action_value(void *output, const char *arg_val, return SPP_RET_NG; } - if (unlikely(ret != SPP_CMD_ACTION_ADD) && - unlikely(ret != SPP_CMD_ACTION_DEL)) { + if (unlikely(ret != SPPWK_ACT_ADD) && + unlikely(ret != SPPWK_ACT_DEL)) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown port action. val=%s\n", arg_val); return SPP_RET_NG; @@ -724,7 +723,7 @@ decode_classifier_port_value(void *output, const char *arg_val, if (classifier_table->type == SPP_CLASSIFIER_TYPE_MAC) classifier_table->vid = ETH_VLAN_ID_MAX; - if (unlikely(classifier_table->action == SPP_CMD_ACTION_ADD)) { + if (unlikely(classifier_table->wk_action == SPPWK_ACT_ADD)) { if (!spp_check_classid_used_port(ETH_VLAN_ID_MAX, 0, tmp_port.iface_type, tmp_port.iface_no)) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Port in used. " @@ -732,7 +731,7 @@ decode_classifier_port_value(void *output, const char *arg_val, arg_val); return SPP_RET_NG; } - } else if (unlikely(classifier_table->action == SPP_CMD_ACTION_DEL)) { + } else if (unlikely(classifier_table->wk_action == SPPWK_ACT_DEL)) { mac_addr = spp_change_mac_str_to_int64(classifier_table->mac); if (mac_addr < 0) return SPP_RET_NG; @@ -769,7 +768,7 @@ parameter_list[][SPP_CMD_MAX_PARAMETERS] = { { .name = "action", .offset = offsetof(struct spp_command, - spec.classifier_table.action), + spec.classifier_table.wk_action), .func = decode_classifier_action_value }, { @@ -796,7 +795,7 @@ parameter_list[][SPP_CMD_MAX_PARAMETERS] = { { .name = "action", .offset = offsetof(struct spp_command, - spec.classifier_table.action), + spec.classifier_table.wk_action), .func = decode_classifier_action_value }, { @@ -832,7 +831,7 @@ parameter_list[][SPP_CMD_MAX_PARAMETERS] = { { .name = "action", .offset = offsetof(struct spp_command, - spec.component.action), + spec.component.wk_action), .func = decode_component_action_value }, { @@ -856,7 +855,7 @@ parameter_list[][SPP_CMD_MAX_PARAMETERS] = { { .name = "action", .offset = offsetof(struct spp_command, - spec.port.action), + spec.port.wk_action), .func = decode_port_action_value }, { diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 38cc45f..b6d5b4b 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -129,10 +129,10 @@ spp_check_flush_port(enum port_type iface_type, int iface_no) return port->dpdk_port >= 0; } -/* update classifier table according to the specified action(add or del). */ +/* Update classifier table with given action, add or del. */ static int spp_update_classifier_table( - enum spp_command_action action, + enum sppwk_action wk_action, enum spp_classifier_type type __attribute__ ((unused)), int vid, const char *mac_addr_str, @@ -166,7 +166,7 @@ spp_update_classifier_table( return SPP_RET_NG; } - if (action == SPP_CMD_ACTION_DEL) { + if (wk_action == SPPWK_ACT_DEL) { /* Delete */ if ((port_info->class_id.vlantag.vid != 0) && unlikely(port_info->class_id.vlantag.vid != @@ -188,7 +188,7 @@ spp_update_classifier_table( memset(port_info->class_id.mac_addr_str, 0x00, SPP_MIN_STR_LEN); - } else if (action == SPP_CMD_ACTION_ADD) { + } else if (wk_action == SPPWK_ACT_ADD) { /* Setting */ if (unlikely(port_info->class_id.vlantag.vid != ETH_VLAN_ID_MAX)) { @@ -216,13 +216,10 @@ spp_update_classifier_table( return SPP_RET_OK; } -/** - * Assign or remove component to/from specified lcore depending - * on component action - */ +/* Assign worker thread or remove on specified lcore. */ static int spp_update_component( - enum spp_command_action action, + enum sppwk_action wk_action, const char *name, unsigned int lcore_id, enum spp_component_type type) @@ -242,8 +239,8 @@ spp_update_component( spp_get_mng_data_addr(NULL, NULL, &comp_info_base, &core_info, &change_core, &change_component, NULL); - switch (action) { - case SPP_CMD_ACTION_START: + switch (wk_action) { + case SPPWK_ACT_START: info = (core_info + lcore_id); if (info->status == SPP_CORE_UNUSE) { RTE_LOG(ERR, APP, "Core %d is not available because " @@ -281,7 +278,7 @@ spp_update_component( *(change_component + component_id) = 1; break; - case SPP_CMD_ACTION_STOP: + case SPPWK_ACT_STOP: component_id = spp_get_component_id(name); if (component_id < 0) return SPP_RET_OK; @@ -367,7 +364,7 @@ check_port_count(int component_type, enum spp_port_rxtx rxtx, int num_rx, * appropriate one. */ static int -spp_update_port(enum spp_command_action action, +spp_update_port(enum sppwk_action wk_action, const struct spp_port_index *port, enum spp_port_rxtx rxtx, const char *name, @@ -403,8 +400,8 @@ spp_update_port(enum spp_command_action action, ports = comp_info->tx_ports; } - switch (action) { - case SPP_CMD_ACTION_ADD: + switch (wk_action) { + case SPPWK_ACT_ADD: /* Check if over the maximum num of ports of component. */ if (check_port_count(comp_info->type, rxtx, comp_info->num_rx_port, @@ -462,7 +459,7 @@ spp_update_port(enum spp_command_action action, ret = SPP_RET_OK; break; - case SPP_CMD_ACTION_DEL: + case SPPWK_ACT_DEL: for (cnt = 0; cnt < SPP_PORT_ABILITY_MAX; cnt++) { if (port_info->ability[cnt].ope == SPP_PORT_ABILITY_OPE_NONE) @@ -747,7 +744,7 @@ execute_command(const struct spp_command *command) RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute classifier_table command.\n"); ret = spp_update_classifier_table( - command->spec.classifier_table.action, + command->spec.classifier_table.wk_action, command->spec.classifier_table.type, command->spec.classifier_table.vid, command->spec.classifier_table.mac, @@ -763,7 +760,7 @@ execute_command(const struct spp_command *command) RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute component command.\n"); ret = spp_update_component( - command->spec.component.action, + command->spec.component.wk_action, command->spec.component.name, command->spec.component.core, command->spec.component.type); @@ -777,9 +774,9 @@ execute_command(const struct spp_command *command) case SPP_CMDTYPE_PORT: RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute port command. (act = %d)\n", - command->spec.port.action); + command->spec.port.wk_action); ret = spp_update_port( - command->spec.port.action, + command->spec.port.wk_action, &command->spec.port.port, command->spec.port.rxtx, command->spec.port.name, -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> For refactoring, rename SPP_CMD_MAX_COMMANDS and SPP_CMD_MAX_PARAMETERS to SPPWK_MAX_CMDS and SPPWK_MAX_PARAMS to be more simple and specific. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/shared/secondary/spp_worker_th/cmd_parser.h | 6 +++--- src/shared/secondary/spp_worker_th/command_dec.c | 8 ++++---- src/shared/secondary/spp_worker_th/command_proc.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index ccdf6bb..2a0e580 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -13,10 +13,10 @@ #include "spp_proc.h" /* Maximum number of commands per request. */ -#define SPP_CMD_MAX_COMMANDS 32 +#define SPPWK_MAX_CMDS 32 /* Maximum number of parameters per command. */ -#define SPP_CMD_MAX_PARAMETERS 8 +#define SPPWK_MAX_PARAMS 8 /* Size of string buffer of message including null char. */ #define SPP_CMD_NAME_BUFSZ 32 @@ -117,7 +117,7 @@ struct spp_command { 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 */ + struct spp_command commands[SPPWK_MAX_CMDS]; /**< list of cmds */ int is_requested_client_id; int is_requested_status; diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index f9849bb..1dbd510 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -763,7 +763,7 @@ struct decode_parameter_list { /* parameter list for each command */ static struct decode_parameter_list -parameter_list[][SPP_CMD_MAX_PARAMETERS] = { +parameter_list[][SPPWK_MAX_PARAMS] = { { /* classifier_table(mac) */ { .name = "action", @@ -1034,13 +1034,13 @@ decode_command_in_list(struct spp_command_request *request, struct decode_command_list *list = NULL; int i = 0; int argc = 0; - char *argv[SPP_CMD_MAX_PARAMETERS]; - char tmp_str[SPP_CMD_MAX_PARAMETERS*SPP_CMD_VALUE_BUFSZ]; + char *argv[SPPWK_MAX_PARAMS]; + char tmp_str[SPPWK_MAX_PARAMS*SPP_CMD_VALUE_BUFSZ]; memset(argv, 0x00, sizeof(argv)); memset(tmp_str, 0x00, sizeof(tmp_str)); strcpy(tmp_str, request_str); - ret = decode_parameter_value(tmp_str, SPP_CMD_MAX_PARAMETERS, + ret = decode_parameter_value(tmp_str, SPPWK_MAX_PARAMS, &argc, argv); if (ret < SPP_RET_OK) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Parameter number over limit." diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index b6d5b4b..1ab8111 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -1645,7 +1645,7 @@ process_request(int *sock, const char *request_str, size_t request_str_len) struct spp_command_request request; struct sppwk_parse_err_msg wk_err_msg; - struct command_result command_results[SPP_CMD_MAX_COMMANDS]; + struct command_result command_results[SPPWK_MAX_CMDS]; memset(&request, 0, sizeof(struct spp_command_request)); memset(&wk_err_msg, 0, sizeof(struct sppwk_parse_err_msg)); -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> For refactoring, rename SPP_CMD_NAME_BUFSZ and SPP_CMD_NAME_VALUE_BUFSZ to SPPWK_NAME_BUFSZ and SPPWK_VAL_BUFSZ to be more simple and specific. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/shared/secondary/spp_worker_th/cmd_parser.h | 14 +++++++------- src/shared/secondary/spp_worker_th/command_dec.c | 4 ++-- src/shared/secondary/spp_worker_th/command_proc.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index 2a0e580..99346cb 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -19,10 +19,10 @@ #define SPPWK_MAX_PARAMS 8 /* Size of string buffer of message including null char. */ -#define SPP_CMD_NAME_BUFSZ 32 +#define SPPWK_NAME_BUFSZ 32 /* Size of string buffer of detailed message including null char. */ -#define SPP_CMD_VALUE_BUFSZ 111 +#define SPPWK_VAL_BUFSZ 111 /* Fix value for 'unused' status. */ #define SPP_CMD_UNUSE "unuse" @@ -76,7 +76,7 @@ struct spp_command_classifier_table { enum sppwk_action wk_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 */ + char mac[SPPWK_VAL_BUFSZ]; /**< MAC address */ struct spp_port_index port;/**< Destination port type and number */ }; @@ -88,7 +88,7 @@ struct spp_command_flush { /* `component` command parameters. */ struct spp_command_component { enum sppwk_action wk_action; /**< start or stop */ - char name[SPP_CMD_NAME_BUFSZ]; /**< component name */ + char name[SPPWK_NAME_BUFSZ]; /**< component name */ unsigned int core; /**< logical core number */ enum spp_component_type type; /**< component type */ }; @@ -98,7 +98,7 @@ struct spp_command_port { enum sppwk_action wk_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 */ + char name[SPPWK_NAME_BUFSZ]; /**< component name */ struct spp_port_ability ability; /**< port ability */ }; @@ -127,8 +127,8 @@ struct spp_command_request { /* 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 */ + char msg[SPPWK_NAME_BUFSZ]; /**< Message in short */ + char details[SPPWK_VAL_BUFSZ]; /**< Detailed message */ }; /** diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 1dbd510..519ce3a 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -302,7 +302,7 @@ get_uint_value( static int decode_str_value(char *output, const char *arg_val) { - if (strlen(arg_val) >= SPP_CMD_VALUE_BUFSZ) + if (strlen(arg_val) >= SPPWK_VAL_BUFSZ) return SPP_RET_NG; strcpy(output, arg_val); @@ -1035,7 +1035,7 @@ decode_command_in_list(struct spp_command_request *request, int i = 0; int argc = 0; char *argv[SPPWK_MAX_PARAMS]; - char tmp_str[SPPWK_MAX_PARAMS*SPP_CMD_VALUE_BUFSZ]; + char tmp_str[SPPWK_MAX_PARAMS*SPPWK_VAL_BUFSZ]; memset(argv, 0x00, sizeof(argv)); memset(tmp_str, 0x00, sizeof(tmp_str)); diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 1ab8111..7fd5fcd 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -48,7 +48,7 @@ struct command_result { int code; /* Response message */ - char result[SPP_CMD_NAME_BUFSZ]; + char result[SPPWK_NAME_BUFSZ]; /* Detailed response message */ char error_message[CMD_RES_ERR_MSG_SIZE]; @@ -57,7 +57,7 @@ struct command_result { /* command response list control structure */ struct command_response_list { /* Tag name */ - char tag_name[SPP_CMD_NAME_BUFSZ]; + char tag_name[SPPWK_NAME_BUFSZ]; /* Pointer to handling function */ int (*func)(const char *name, char **output, void *tmp); -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Remove define SPP_CMD_UNUSE because it is not referred from anywhere. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/shared/secondary/spp_worker_th/cmd_parser.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index 99346cb..965c99b 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -24,9 +24,6 @@ /* Size of string buffer of detailed message including null char. */ #define SPPWK_VAL_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. -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Refactor enum `spp_command_type`. Rename the name of enum to `sppwk_cmd_type` and also each of members. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/cmd_parser.h | 24 +++++++++++-------- .../secondary/spp_worker_th/command_dec.c | 6 ++--- .../secondary/spp_worker_th/command_proc.c | 8 +++---- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index 965c99b..5922654 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -57,15 +57,19 @@ enum sppwk_action { * @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 */ +/* + * TODO(yasufum) consider to divide because each of target of scope is + * different and not so understandable for usage. For example, worker is + * including classifier or it status. + */ +enum sppwk_cmd_type { + SPPWK_CMDTYPE_CLS_MAC, + SPPWK_CMDTYPE_CLS_VLAN, + SPPWK_CMDTYPE_CLIENT_ID, /**< get_client_id */ + SPPWK_CMDTYPE_STATUS, /**< status */ + SPPWK_CMDTYPE_EXIT, /**< exit */ + SPPWK_CMDTYPE_WORKER, /**< worker thread */ + SPPWK_CMDTYPE_PORT, /**< port */ }; /* `classifier_table` command specific parameters. */ @@ -100,7 +104,7 @@ struct spp_command_port { }; struct spp_command { - enum spp_command_type type; /**< command type */ + enum sppwk_cmd_type type; /**< command type */ union { /**< command descriptors */ struct spp_command_classifier_table classifier_table; diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 519ce3a..7a65269 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -1107,13 +1107,13 @@ spp_command_decode_request( /* check getter command */ for (i = 0; i < request->num_valid_command; ++i) { switch (request->commands[i].type) { - case SPP_CMDTYPE_CLIENT_ID: + case SPPWK_CMDTYPE_CLIENT_ID: request->is_requested_client_id = 1; break; - case SPP_CMDTYPE_STATUS: + case SPPWK_CMDTYPE_STATUS: request->is_requested_status = 1; break; - case SPP_CMDTYPE_EXIT: + case SPPWK_CMDTYPE_EXIT: request->is_requested_exit = 1; break; default: diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 7fd5fcd..5ae34d0 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -739,8 +739,8 @@ execute_command(const struct spp_command *command) int ret = SPP_RET_OK; switch (command->type) { - case SPP_CMDTYPE_CLASSIFIER_TABLE_MAC: - case SPP_CMDTYPE_CLASSIFIER_TABLE_VLAN: + case SPPWK_CMDTYPE_CLS_MAC: + case SPPWK_CMDTYPE_CLS_VLAN: RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute classifier_table command.\n"); ret = spp_update_classifier_table( @@ -756,7 +756,7 @@ execute_command(const struct spp_command *command) } break; - case SPP_CMDTYPE_COMPONENT: + case SPPWK_CMDTYPE_WORKER: RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute component command.\n"); ret = spp_update_component( @@ -771,7 +771,7 @@ execute_command(const struct spp_command *command) } break; - case SPP_CMDTYPE_PORT: + case SPPWK_CMDTYPE_PORT: RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute port command. (act = %d)\n", command->spec.port.wk_action); -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> For refactoring, change `spp_command_classifier_table` to `sppwk_cls_cmd_attr`. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/cmd_parser.h | 4 ++-- .../secondary/spp_worker_th/command_dec.c | 20 +++++++++---------- .../secondary/spp_worker_th/command_proc.c | 10 +++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index 5922654..db60499 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -73,7 +73,7 @@ enum sppwk_cmd_type { }; /* `classifier_table` command specific parameters. */ -struct spp_command_classifier_table { +struct sppwk_cls_cmd_attr { enum sppwk_action wk_action; /**< add or del */ enum spp_classifier_type type; /**< currently only for mac */ int vid; /**< VLAN ID */ @@ -107,7 +107,7 @@ struct spp_command { enum sppwk_cmd_type type; /**< command type */ union { /**< command descriptors */ - struct spp_command_classifier_table classifier_table; + struct sppwk_cls_cmd_attr cls_table; struct spp_command_flush flush; struct spp_command_component component; struct spp_command_port port; diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 7a65269..4316b10 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -705,7 +705,7 @@ decode_classifier_port_value(void *output, const char *arg_val, int allow_override __attribute__ ((unused))) { int ret = SPP_RET_OK; - struct spp_command_classifier_table *classifier_table = output; + struct sppwk_cls_cmd_attr *classifier_table = output; struct spp_port_index tmp_port; int64_t mac_addr = 0; @@ -768,25 +768,25 @@ parameter_list[][SPPWK_MAX_PARAMS] = { { .name = "action", .offset = offsetof(struct spp_command, - spec.classifier_table.wk_action), + spec.cls_table.wk_action), .func = decode_classifier_action_value }, { .name = "type", .offset = offsetof(struct spp_command, - spec.classifier_table.type), + spec.cls_table.type), .func = decode_classifier_type_value }, { .name = "mac address", .offset = offsetof(struct spp_command, - spec.classifier_table.mac), + spec.cls_table.mac), .func = decode_mac_addr_str_value }, { .name = "port", .offset = offsetof(struct spp_command, - spec.classifier_table), + spec.cls_table), .func = decode_classifier_port_value }, DECODE_PARAMETER_LIST_EMPTY, @@ -795,31 +795,31 @@ parameter_list[][SPPWK_MAX_PARAMS] = { { .name = "action", .offset = offsetof(struct spp_command, - spec.classifier_table.wk_action), + spec.cls_table.wk_action), .func = decode_classifier_action_value }, { .name = "type", .offset = offsetof(struct spp_command, - spec.classifier_table.type), + spec.cls_table.type), .func = decode_classifier_type_value }, { .name = "vlan id", .offset = offsetof(struct spp_command, - spec.classifier_table.vid), + spec.cls_table.vid), .func = decode_classifier_vid_value }, { .name = "mac address", .offset = offsetof(struct spp_command, - spec.classifier_table.mac), + spec.cls_table.mac), .func = decode_mac_addr_str_value }, { .name = "port", .offset = offsetof(struct spp_command, - spec.classifier_table), + spec.cls_table), .func = decode_classifier_port_value }, DECODE_PARAMETER_LIST_EMPTY, diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 5ae34d0..c5b1273 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -744,11 +744,11 @@ execute_command(const struct spp_command *command) RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute classifier_table command.\n"); ret = spp_update_classifier_table( - command->spec.classifier_table.wk_action, - command->spec.classifier_table.type, - command->spec.classifier_table.vid, - command->spec.classifier_table.mac, - &command->spec.classifier_table.port); + command->spec.cls_table.wk_action, + command->spec.cls_table.type, + command->spec.cls_table.vid, + command->spec.cls_table.mac, + &command->spec.cls_table.port); if (ret == 0) { RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute flush.\n"); -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Change function name `decode_classifier_port_value` to `parse_cls_port` to be more simple and specific. The names of argument are also refactored for the reason. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/command_dec.c | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 4316b10..9904ad8 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -701,11 +701,11 @@ decode_classifier_vid_value(void *output, const char *arg_val, /* decoding procedure of port for classifier_table command */ static int -decode_classifier_port_value(void *output, const char *arg_val, - int allow_override __attribute__ ((unused))) +parse_cls_port(void *cls_cmd_attr, const char *arg_val, + int allow_override __attribute__ ((unused))) { int ret = SPP_RET_OK; - struct sppwk_cls_cmd_attr *classifier_table = output; + struct sppwk_cls_cmd_attr *cls_attr = cls_cmd_attr; struct spp_port_index tmp_port; int64_t mac_addr = 0; @@ -720,10 +720,10 @@ decode_classifier_port_value(void *output, const char *arg_val, return SPP_RET_NG; } - if (classifier_table->type == SPP_CLASSIFIER_TYPE_MAC) - classifier_table->vid = ETH_VLAN_ID_MAX; + if (cls_attr->type == SPP_CLASSIFIER_TYPE_MAC) + cls_attr->vid = ETH_VLAN_ID_MAX; - if (unlikely(classifier_table->wk_action == SPPWK_ACT_ADD)) { + if (unlikely(cls_attr->wk_action == SPPWK_ACT_ADD)) { if (!spp_check_classid_used_port(ETH_VLAN_ID_MAX, 0, tmp_port.iface_type, tmp_port.iface_no)) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Port in used. " @@ -731,12 +731,12 @@ decode_classifier_port_value(void *output, const char *arg_val, arg_val); return SPP_RET_NG; } - } else if (unlikely(classifier_table->wk_action == SPPWK_ACT_DEL)) { - mac_addr = spp_change_mac_str_to_int64(classifier_table->mac); + } else if (unlikely(cls_attr->wk_action == SPPWK_ACT_DEL)) { + mac_addr = spp_change_mac_str_to_int64(cls_attr->mac); if (mac_addr < 0) return SPP_RET_NG; - if (!spp_check_classid_used_port(classifier_table->vid, + if (!spp_check_classid_used_port(cls_attr->vid, (uint64_t)mac_addr, tmp_port.iface_type, tmp_port.iface_no)) { RTE_LOG(ERR, SPP_COMMAND_PROC, "Port in used. " @@ -746,8 +746,8 @@ decode_classifier_port_value(void *output, const char *arg_val, } } - classifier_table->port.iface_type = tmp_port.iface_type; - classifier_table->port.iface_no = tmp_port.iface_no; + cls_attr->port.iface_type = tmp_port.iface_type; + cls_attr->port.iface_no = tmp_port.iface_no; return SPP_RET_OK; } @@ -787,7 +787,7 @@ parameter_list[][SPPWK_MAX_PARAMS] = { .name = "port", .offset = offsetof(struct spp_command, spec.cls_table), - .func = decode_classifier_port_value + .func = parse_cls_port }, DECODE_PARAMETER_LIST_EMPTY, }, @@ -820,7 +820,7 @@ parameter_list[][SPPWK_MAX_PARAMS] = { .name = "port", .offset = offsetof(struct spp_command, spec.cls_table), - .func = decode_classifier_port_value + .func = parse_cls_port }, DECODE_PARAMETER_LIST_EMPTY, }, -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> For refactoring, rename function `spp_command_flush` to `sppwk_cmd_flush`. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/shared/secondary/spp_worker_th/cmd_parser.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index db60499..04f9f75 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -82,7 +82,7 @@ struct sppwk_cls_cmd_attr { }; /* `flush` command specific parameters. */ -struct spp_command_flush { +struct sppwk_cmd_flush { /* nothing specific */ }; @@ -108,7 +108,7 @@ struct spp_command { union { /**< command descriptors */ struct sppwk_cls_cmd_attr cls_table; - struct spp_command_flush flush; + struct sppwk_cmd_flush flush; struct spp_command_component component; struct spp_command_port port; } spec; -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> For refactoring, change the name of struct `spp_command_component` to `sppwk_cmd_comp`. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/shared/secondary/spp_worker_th/cmd_parser.h | 4 ++-- src/shared/secondary/spp_worker_th/command_dec.c | 14 +++++++------- src/shared/secondary/spp_worker_th/command_proc.c | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index 04f9f75..669f199 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -87,7 +87,7 @@ struct sppwk_cmd_flush { }; /* `component` command parameters. */ -struct spp_command_component { +struct sppwk_cmd_comp { enum sppwk_action wk_action; /**< start or stop */ char name[SPPWK_NAME_BUFSZ]; /**< component name */ unsigned int core; /**< logical core number */ @@ -109,7 +109,7 @@ struct spp_command { union { /**< command descriptors */ struct sppwk_cls_cmd_attr cls_table; struct sppwk_cmd_flush flush; - struct spp_command_component component; + struct sppwk_cmd_comp comp; struct spp_command_port port; } spec; }; diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 9904ad8..493d9cb 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -372,7 +372,7 @@ decode_component_name_value(void *output, const char *arg_val, int allow_override __attribute__ ((unused))) { int ret = SPP_RET_OK; - struct spp_command_component *component = output; + struct sppwk_cmd_comp *component = output; /* "stop" has no core ID parameter. */ if (component->wk_action == SPPWK_ACT_START) { @@ -393,7 +393,7 @@ static int decode_component_core_value(void *output, const char *arg_val, int allow_override __attribute__ ((unused))) { - struct spp_command_component *component = output; + struct sppwk_cmd_comp *component = output; /* "stop" has no core ID parameter. */ if (component->wk_action != SPPWK_ACT_START) @@ -408,7 +408,7 @@ decode_component_type_value(void *output, const char *arg_val, int allow_override __attribute__ ((unused))) { enum spp_component_type comp_type; - struct spp_command_component *component = output; + struct sppwk_cmd_comp *component = output; /* "stop" has no type parameter. */ if (component->wk_action != SPPWK_ACT_START) @@ -831,22 +831,22 @@ parameter_list[][SPPWK_MAX_PARAMS] = { { .name = "action", .offset = offsetof(struct spp_command, - spec.component.wk_action), + spec.comp.wk_action), .func = decode_component_action_value }, { .name = "component name", - .offset = offsetof(struct spp_command, spec.component), + .offset = offsetof(struct spp_command, spec.comp), .func = decode_component_name_value }, { .name = "core", - .offset = offsetof(struct spp_command, spec.component), + .offset = offsetof(struct spp_command, spec.comp), .func = decode_component_core_value }, { .name = "component type", - .offset = offsetof(struct spp_command, spec.component), + .offset = offsetof(struct spp_command, spec.comp), .func = decode_component_type_value }, DECODE_PARAMETER_LIST_EMPTY, diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index c5b1273..3e8c52a 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -760,10 +760,10 @@ execute_command(const struct spp_command *command) RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute component command.\n"); ret = spp_update_component( - command->spec.component.wk_action, - command->spec.component.name, - command->spec.component.core, - command->spec.component.type); + command->spec.comp.wk_action, + command->spec.comp.name, + command->spec.comp.core, + command->spec.comp.type); if (ret == 0) { RTE_LOG(INFO, SPP_COMMAND_PROC, "Execute flush.\n"); -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> SPP worker has two kind of struct `spp_port_index` and `spp_port_info`, but it is confusing and not clear for considering usages. `spp_port_index` is used for the case just refering port type and index, and `spp_port_info` is for more detailed info actually. This update is to refactor for rename prefix `spp_` to `sppwk_`, and adding comment for usages. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/mirror/spp_mirror.c | 16 ++-- .../secondary/spp_worker_th/cmd_parser.h | 11 +-- .../secondary/spp_worker_th/command_dec.c | 26 +++---- .../secondary/spp_worker_th/command_proc.c | 22 +++--- src/shared/secondary/spp_worker_th/spp_port.c | 4 +- src/shared/secondary/spp_worker_th/spp_proc.c | 46 ++++++------ src/shared/secondary/spp_worker_th/spp_proc.h | 73 ++++++++++--------- src/vf/classifier_mac.c | 8 +- src/vf/spp_forward.c | 16 ++-- 9 files changed, 111 insertions(+), 111 deletions(-) diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c index 6d01501..5c4f68a 100644 --- a/src/mirror/spp_mirror.c +++ b/src/mirror/spp_mirror.c @@ -29,8 +29,8 @@ /* A set of port info of rx and tx */ struct mirror_rxtx { - struct spp_port_info rx; /* rx port */ - struct spp_port_info tx; /* tx port */ + struct sppwk_port_info rx; /* rx port */ + struct sppwk_port_info tx; /* tx port */ }; /* Information on the path used for mirror. */ @@ -319,12 +319,12 @@ spp_mirror_update(struct spp_component_info *component) path->num_tx = component->num_tx_port; for (cnt = 0; cnt < num_rx; cnt++) memcpy(&path->ports[cnt].rx, component->rx_ports[cnt], - sizeof(struct spp_port_info)); + sizeof(struct sppwk_port_info)); /* Transmit port is set according with larger num_rx / num_tx. */ for (cnt = 0; cnt < num_tx; cnt++) memcpy(&path->ports[cnt].tx, component->tx_ports[cnt], - sizeof(struct spp_port_info)); + sizeof(struct sppwk_port_info)); info->upd_index = info->ref_index; while (likely(info->ref_index == info->upd_index)) @@ -368,8 +368,8 @@ mirror_proc(int id) int nb_tx2 = 0; struct mirror_info *info = &g_mirror_info[id]; struct mirror_path *path = NULL; - struct spp_port_info *rx = NULL; - struct spp_port_info *tx = NULL; + struct sppwk_port_info *rx = NULL; + struct sppwk_port_info *tx = NULL; struct rte_mbuf *bufs[MAX_PKT_BURST]; struct rte_mbuf *copybufs[MAX_PKT_BURST]; struct rte_mbuf *org_mbuf = NULL; @@ -478,8 +478,8 @@ spp_mirror_get_component_status( const char *component_type = NULL; struct mirror_info *info = &g_mirror_info[id]; struct mirror_path *path = &info->path[info->ref_index]; - struct spp_port_index rx_ports[RTE_MAX_ETHPORTS]; - struct spp_port_index tx_ports[RTE_MAX_ETHPORTS]; + struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; + struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; if (unlikely(path->type == SPP_COMPONENT_UNUSE)) { RTE_LOG(ERR, MIRROR, diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index 669f199..3d31833 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -78,12 +78,12 @@ struct sppwk_cls_cmd_attr { enum spp_classifier_type type; /**< currently only for mac */ int vid; /**< VLAN ID */ char mac[SPPWK_VAL_BUFSZ]; /**< MAC address */ - struct spp_port_index port;/**< Destination port type and number */ + struct sppwk_port_idx port;/**< Destination port type and number */ }; /* `flush` command specific parameters. */ struct sppwk_cmd_flush { - /* nothing specific */ + /* Take no params. */ }; /* `component` command parameters. */ @@ -95,14 +95,15 @@ struct sppwk_cmd_comp { }; /* `port` command parameters. */ -struct spp_command_port { +struct sppwk_cmd_port { enum sppwk_action wk_action; /**< add or del */ - struct spp_port_index port; /**< port type and number */ + struct sppwk_port_idx port; /**< port type and number */ enum spp_port_rxtx rxtx; /**< rx or tx identifier */ char name[SPPWK_NAME_BUFSZ]; /**< component name */ struct spp_port_ability ability; /**< port ability */ }; +/* TODO(yasufum) Add usage and desc for members. What's command descriptors? */ struct spp_command { enum sppwk_cmd_type type; /**< command type */ @@ -110,7 +111,7 @@ struct spp_command { struct sppwk_cls_cmd_attr cls_table; struct sppwk_cmd_flush flush; struct sppwk_cmd_comp comp; - struct spp_command_port port; + struct sppwk_cmd_port port; } spec; }; diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 493d9cb..918c2a2 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -99,12 +99,10 @@ spp_check_classid_used_port( int vid, uint64_t mac_addr, enum port_type iface_type, int iface_no) { - struct spp_port_info *port_info = get_iface_info(iface_type, iface_no); + struct sppwk_port_info *port_info = get_iface_info( + iface_type, iface_no); - /** - * return true if given mac_addr/vid matches - * with that of port_info/vid - */ + /* Return true if given mac_addr matches with port_info, and vid. */ return ((mac_addr == port_info->class_id.mac_addr) && (vid == port_info->class_id.vlantag.vid)); } @@ -113,7 +111,7 @@ spp_check_classid_used_port( static int spp_check_added_port(enum port_type iface_type, int iface_no) { - struct spp_port_info *port = get_iface_info(iface_type, iface_no); + struct sppwk_port_info *port = get_iface_info(iface_type, iface_no); return port->iface_type != UNDEF; } @@ -314,7 +312,7 @@ static int decode_port_value(void *output, const char *arg_val) { int ret = SPP_RET_OK; - struct spp_port_index *port = output; + struct sppwk_port_idx *port = output; ret = spp_convert_port_to_iface(arg_val, &port->iface_type, &port->iface_no); if (unlikely(ret != 0)) { @@ -457,8 +455,8 @@ static int decode_port_port_value(void *output, const char *arg_val, int allow_override) { int ret = SPP_RET_NG; - struct spp_port_index tmp_port; - struct spp_command_port *port = output; + struct sppwk_port_idx tmp_port; + struct sppwk_cmd_port *port = output; ret = decode_port_value(&tmp_port, arg_val); if (ret < SPP_RET_OK) @@ -490,7 +488,7 @@ static int decode_port_rxtx_value(void *output, const char *arg_val, int allow_override) { int ret = SPP_RET_OK; - struct spp_command_port *port = output; + struct sppwk_cmd_port *port = output; ret = get_arrary_index(arg_val, PORT_RXTX_STRINGS); if (unlikely(ret <= 0)) { @@ -538,7 +536,7 @@ decode_port_vlan_operation(void *output, const char *arg_val, int allow_override __attribute__ ((unused))) { int ret = SPP_RET_OK; - struct spp_command_port *port = output; + struct sppwk_cmd_port *port = output; struct spp_port_ability *ability = &port->ability; switch (ability->ope) { @@ -570,7 +568,7 @@ decode_port_vid(void *output, const char *arg_val, int allow_override __attribute__ ((unused))) { int ret = SPP_RET_OK; - struct spp_command_port *port = output; + struct sppwk_cmd_port *port = output; struct spp_port_ability *ability = &port->ability; switch (ability->ope) { @@ -598,7 +596,7 @@ decode_port_pcp(void *output, const char *arg_val, int allow_override __attribute__ ((unused))) { int ret = SPP_RET_OK; - struct spp_command_port *port = output; + struct sppwk_cmd_port *port = output; struct spp_port_ability *ability = &port->ability; switch (ability->ope) { @@ -706,7 +704,7 @@ parse_cls_port(void *cls_cmd_attr, const char *arg_val, { int ret = SPP_RET_OK; struct sppwk_cls_cmd_attr *cls_attr = cls_cmd_attr; - struct spp_port_index tmp_port; + struct sppwk_port_idx tmp_port; int64_t mac_addr = 0; ret = decode_port_value(&tmp_port, arg_val); diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 3e8c52a..34bfe82 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -125,7 +125,7 @@ spp_get_process_type(void) static int spp_check_flush_port(enum port_type iface_type, int iface_no) { - struct spp_port_info *port = get_iface_info(iface_type, iface_no); + struct sppwk_port_info *port = get_iface_info(iface_type, iface_no); return port->dpdk_port >= 0; } @@ -136,9 +136,9 @@ spp_update_classifier_table( enum spp_classifier_type type __attribute__ ((unused)), int vid, const char *mac_addr_str, - const struct spp_port_index *port) + const struct sppwk_port_idx *port) { - struct spp_port_info *port_info = NULL; + struct sppwk_port_info *port_info = NULL; int64_t ret_mac = 0; uint64_t mac_addr = 0; @@ -365,7 +365,7 @@ check_port_count(int component_type, enum spp_port_rxtx rxtx, int num_rx, */ static int spp_update_port(enum sppwk_action wk_action, - const struct spp_port_index *port, + const struct sppwk_port_idx *port, enum spp_port_rxtx rxtx, const char *name, const struct spp_port_ability *ability) @@ -376,9 +376,9 @@ spp_update_port(enum sppwk_action wk_action, int component_id = 0; int cnt = 0; struct spp_component_info *comp_info = NULL; - struct spp_port_info *port_info = NULL; + struct sppwk_port_info *port_info = NULL; int *num = NULL; - struct spp_port_info **ports = NULL; + struct sppwk_port_info **ports = NULL; struct spp_component_info *comp_info_base = NULL; int *change_component = NULL; @@ -1078,7 +1078,7 @@ append_vlan_block(const char *name, char **output, /* append a block of port numbers for JSON format */ static int -append_port_block(char **output, const struct spp_port_index *port, +append_port_block(char **output, const struct sppwk_port_idx *port, const enum spp_port_rxtx rxtx) { int ret = SPP_RET_NG; @@ -1110,7 +1110,7 @@ append_port_block(char **output, const struct spp_port_index *port, /* append a list of port numbers for JSON format */ static int append_port_array(const char *name, char **output, const int num, - const struct spp_port_index *ports, + const struct sppwk_port_idx *ports, const enum spp_port_rxtx rxtx) { int ret = SPP_RET_NG; @@ -1145,8 +1145,8 @@ 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 spp_port_index *rx_ports, - const int num_tx, const struct spp_port_index *tx_ports) + 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; @@ -1247,7 +1247,7 @@ append_classifier_element_value( struct spp_iterate_classifier_table_params *params, enum spp_classifier_type type, int vid, const char *mac, - const struct spp_port_index *port) + const struct sppwk_port_idx *port) { int ret = SPP_RET_NG; char *buff, *tmp_buff; diff --git a/src/shared/secondary/spp_worker_th/spp_port.c b/src/shared/secondary/spp_worker_th/spp_port.c index 06422c3..c4070ce 100644 --- a/src/shared/secondary/spp_worker_th/spp_port.c +++ b/src/shared/secondary/spp_worker_th/spp_port.c @@ -247,7 +247,7 @@ spp_port_ability_change_index( /* Set ability data of port ability. */ static void port_ability_set_ability( - struct spp_port_info *port, + struct sppwk_port_info *port, enum spp_port_rxtx rxtx) { int in_cnt, out_cnt = 0; @@ -308,7 +308,7 @@ void spp_port_ability_update(const struct spp_component_info *component) { int cnt; - struct spp_port_info *port = NULL; + struct sppwk_port_info *port = NULL; for (cnt = 0; cnt < component->num_rx_port; cnt++) { port = component->rx_ports[cnt]; port_ability_set_ability(port, SPP_PORT_RXTX_RX); diff --git a/src/shared/secondary/spp_worker_th/spp_proc.c b/src/shared/secondary/spp_worker_th/spp_proc.c index 1d39e89..689fb00 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.c +++ b/src/shared/secondary/spp_worker_th/spp_proc.c @@ -269,7 +269,7 @@ stop_process(int signal) * * It returns NULL value if given type is invalid. */ -struct spp_port_info * +struct sppwk_port_info * get_iface_info(enum port_type iface_type, int iface_no) { struct iface_info *iface_info = g_mng_data_addr.p_iface_info; @@ -309,30 +309,30 @@ dump_core_info(const struct core_mng_info *core_info) /* Dump of component information */ void -dump_component_info(const struct spp_component_info *component_info) +dump_component_info(const struct spp_component_info *comp_info) { char str[SPP_NAME_STR_LEN]; - const struct spp_component_info *component = NULL; + const struct spp_component_info *tmp_ci = NULL; int cnt = 0; for (cnt = 0; cnt < RTE_MAX_LCORE; cnt++) { - component = &component_info[cnt]; - if (component->type == SPP_COMPONENT_UNUSE) + tmp_ci = &comp_info[cnt]; + if (tmp_ci->type == SPP_COMPONENT_UNUSE) continue; RTE_LOG(DEBUG, APP, "component[%d] name=%s, type=%d, " "core=%u, index=%d\n", - cnt, component->name, component->type, - component->lcore_id, component->component_id); + cnt, tmp_ci->name, tmp_ci->type, + tmp_ci->lcore_id, tmp_ci->component_id); sprintf(str, "component[%d] rx=%d", cnt, - component->num_rx_port); - dump_buff(str, component->rx_ports, - sizeof(struct spp_port_info *)*component->num_rx_port); + tmp_ci->num_rx_port); + dump_buff(str, tmp_ci->rx_ports, + sizeof(struct sppwk_port_info *)*tmp_ci->num_rx_port); sprintf(str, "component[%d] tx=%d", cnt, - component->num_tx_port); - dump_buff(str, component->tx_ports, - sizeof(struct spp_port_info *)*component->num_tx_port); + tmp_ci->num_tx_port); + dump_buff(str, tmp_ci->tx_ports, + sizeof(struct sppwk_port_info *)*tmp_ci->num_tx_port); } } @@ -340,7 +340,7 @@ dump_component_info(const struct spp_component_info *component_info) void dump_interface_info(const struct iface_info *iface_info) { - const struct spp_port_info *port = NULL; + const struct sppwk_port_info *port = NULL; int cnt = 0; RTE_LOG(DEBUG, APP, "interface phy=%d, vhost=%d, ring=%d\n", iface_info->num_nic, @@ -598,7 +598,7 @@ print_ring_latency_stats(void) /* Remove sock file if spp is not running */ void -del_vhost_sockfile(struct spp_port_info *vhost) +del_vhost_sockfile(struct sppwk_port_info *vhost) { int cnt; @@ -662,8 +662,8 @@ spp_check_used_port( { int cnt, port_cnt, max = 0; struct spp_component_info *component = NULL; - struct spp_port_info **port_array = NULL; - struct spp_port_info *port = get_iface_info(iface_type, iface_no); + struct sppwk_port_info **port_array = NULL; + struct sppwk_port_info *port = get_iface_info(iface_type, iface_no); struct spp_component_info *component_info = g_mng_data_addr.p_component_info; @@ -693,7 +693,7 @@ spp_check_used_port( /* Set component update flag for given port */ void -set_component_change_port(struct spp_port_info *port, enum spp_port_rxtx rxtx) +set_component_change_port(struct sppwk_port_info *port, enum spp_port_rxtx rxtx) { int ret = 0; if ((rxtx == SPP_PORT_RXTX_RX) || (rxtx == SPP_PORT_RXTX_ALL)) { @@ -774,9 +774,9 @@ del_component_info(int component_id, int component_num, int *componet_array) /* get port element which matches the condition */ int check_port_element( - struct spp_port_info *info, + struct sppwk_port_info *info, int num, - struct spp_port_info *array[]) + struct sppwk_port_info *array[]) { int cnt = 0; int match = SPP_RET_NG; @@ -790,9 +790,9 @@ check_port_element( /* search matched port_info from array and delete it */ int get_del_port_element( - struct spp_port_info *info, + struct sppwk_port_info *info, int num, - struct spp_port_info *array[]) + struct sppwk_port_info *array[]) { int cnt = 0; int match = SPP_RET_NG; @@ -819,7 +819,7 @@ flush_port(void) { int ret = 0; int cnt = 0; - struct spp_port_info *port = NULL; + struct sppwk_port_info *port = NULL; struct iface_info *p_iface_info = g_mng_data_addr.p_iface_info; /* Initialize added vhost. */ diff --git a/src/shared/secondary/spp_worker_th/spp_proc.h b/src/shared/secondary/spp_worker_th/spp_proc.h index 734c604..a11be2b 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.h +++ b/src/shared/secondary/spp_worker_th/spp_proc.h @@ -155,14 +155,6 @@ enum secondary_type { SECONDARY_TYPE_MIRROR, }; -/** - * Interface information structure - */ -struct spp_port_index { - enum port_type iface_type; /**< Interface type (phy/vhost/ring) */ - int iface_no; /**< Interface number */ -}; - /** VLAN tag information */ struct spp_vlantag_info { int vid; /**< VLAN ID */ @@ -193,15 +185,23 @@ struct spp_port_class_identifier { struct spp_vlantag_info vlantag; /**< VLAN tag information */ }; -/* Port info */ -struct spp_port_info { - enum port_type iface_type; /**< Interface type (phy/vhost/ring) */ - int iface_no; /**< Interface number */ - int dpdk_port; /**< DPDK port number */ +/** + * Simply define type and index of resource UID such as phy:0. For detailed + * attributions, use `sppwk_port_info` which has additional port params. + */ +struct sppwk_port_idx { + enum port_type iface_type; /**< phy, vhost or ring */ + int iface_no; +}; + +/* Define detailed port params in addition to `sppwk_port_idx`. */ +/* TODO(yasufum) revise name and usage of `dpdk_port`. */ +struct sppwk_port_info { + enum port_type iface_type; /**< phy, vhost or ring */ + int iface_no; + int dpdk_port; /**< DPDK port number */ struct spp_port_class_identifier class_id; - /**< Port class identifier */ struct spp_port_ability ability[SPP_PORT_ABILITY_MAX]; - /**< Port ability */ }; /* Component info */ @@ -212,9 +212,9 @@ struct spp_component_info { int component_id; /**< Component ID */ int num_rx_port; /**< The number of rx ports */ int num_tx_port; /**< The number of tx ports */ - struct spp_port_info *rx_ports[RTE_MAX_ETHPORTS]; + struct sppwk_port_info *rx_ports[RTE_MAX_ETHPORTS]; /**< Array of pointers to rx ports */ - struct spp_port_info *tx_ports[RTE_MAX_ETHPORTS]; + struct sppwk_port_info *tx_ports[RTE_MAX_ETHPORTS]; /**< Array of pointers to tx ports */ }; @@ -234,11 +234,11 @@ struct iface_info { int num_nic; /* The number of phy */ int num_vhost; /* The number of vhost */ int num_ring; /* The number of ring */ - struct spp_port_info nic[RTE_MAX_ETHPORTS]; + struct sppwk_port_info nic[RTE_MAX_ETHPORTS]; /* Port information of phy */ - struct spp_port_info vhost[RTE_MAX_ETHPORTS]; + struct sppwk_port_info vhost[RTE_MAX_ETHPORTS]; /* Port information of vhost */ - struct spp_port_info ring[RTE_MAX_ETHPORTS]; + struct sppwk_port_info ring[RTE_MAX_ETHPORTS]; /* Port information of ring */ }; @@ -288,9 +288,9 @@ typedef int (*spp_iterate_core_element_proc)( const char *name, const char *type, const int num_rx, - const struct spp_port_index *rx_ports, + const struct sppwk_port_idx *rx_ports, const int num_tx, - const struct spp_port_index *tx_ports); + const struct sppwk_port_idx *tx_ports); /** * iterate core table parameters which is @@ -316,7 +316,7 @@ typedef int (*spp_iterate_classifier_element_proc)( struct spp_iterate_classifier_table_params *params, enum spp_classifier_type type, int vid, const char *mac, - const struct spp_port_index *port); + const struct sppwk_port_idx *port); /** * iterate classifier table parameters which is @@ -440,10 +440,10 @@ void stop_process(int signal); * @param iface_no * Interface number to be validated. * - * @retval !NULL spp_port_info. + * @retval !NULL sppwk_port_info. * @retval NULL failed. */ -struct spp_port_info * +struct sppwk_port_info * get_iface_info(enum port_type iface_type, int iface_no); /* Dump of core information */ @@ -487,7 +487,7 @@ void print_ring_latency_stats(void); #endif /* SPP_RINGLATENCYSTATS_ENABLE */ /* Remove sock file if spp is not running */ -void del_vhost_sockfile(struct spp_port_info *vhost); +void del_vhost_sockfile(struct sppwk_port_info *vhost); /** * Get core ID of target component @@ -537,13 +537,14 @@ int spp_check_used_port( * Set component update flag for given port. * * @param port - * spp_port_info address + * sppwk_port_info address * @param rxtx * enum spp_port_rxtx * */ void -set_component_change_port(struct spp_port_info *port, enum spp_port_rxtx rxtx); +set_component_change_port( + struct sppwk_port_info *port, enum spp_port_rxtx rxtx); /** * Get unused component id @@ -584,37 +585,37 @@ del_component_info(int component_id, int component_num, int *componet_array); * get port element which matches the condition. * * @param info - * spp_port_info address + * sppwk_port_info address * @param num * port count * @param array[] - * spp_port_info array address + * sppwk_port_info array address * * @retval 0~ match index. * @retval -1 failed. */ int check_port_element( - struct spp_port_info *info, + struct sppwk_port_info *info, int num, - struct spp_port_info *array[]); + struct sppwk_port_info *array[]); /** * search matched port_info from array and delete it. * * @param info - * spp_port_info address + * sppwk_port_info address * @param num * port count * @param array[] - * spp_port_info array address + * sppwk_port_info array address * * @retval 0 succeeded. * @retval -1 failed. */ int get_del_port_element( - struct spp_port_info *info, + struct sppwk_port_info *info, int num, - struct spp_port_info *array[]); + struct sppwk_port_info *array[]); /** * Flush initial setting of each interface. diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index b49cf14..30b6353 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -330,7 +330,7 @@ init_component_info(struct component_info *cmp_info, char mac_addr_str[ETHER_ADDR_STR_BUF_SZ]; struct classified_data *clsd_data_rx = &cmp_info->classified_data_rx; struct classified_data *clsd_data_tx = cmp_info->classified_data_tx; - struct spp_port_info *tx_port = NULL; + struct sppwk_port_info *tx_port = NULL; uint16_t vid; /* set rx */ @@ -816,8 +816,8 @@ spp_classifier_get_component_status( struct management_info *mng_info; struct component_info *cmp_info; struct classified_data *clsd_data; - struct spp_port_index rx_ports[RTE_MAX_ETHPORTS]; - struct spp_port_index tx_ports[RTE_MAX_ETHPORTS]; + struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; + struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; mng_info = g_mng_infos + id; if (!is_used_mng_info(mng_info)) { @@ -870,7 +870,7 @@ mac_classification_iterate_table( const void *key; void *data; uint32_t next; - struct spp_port_index port; + struct sppwk_port_idx port; char mac_addr_str[ETHER_ADDR_STR_BUF_SZ]; enum spp_classifier_type type; diff --git a/src/vf/spp_forward.c b/src/vf/spp_forward.c index 053d7c9..b9c0ad6 100644 --- a/src/vf/spp_forward.c +++ b/src/vf/spp_forward.c @@ -13,8 +13,8 @@ /* A set of port info of rx and tx */ struct forward_rxtx { - struct spp_port_info rx; /* rx port */ - struct spp_port_info tx; /* tx port */ + struct sppwk_port_info rx; /* rx port */ + struct sppwk_port_info tx; /* tx port */ }; /* Information on the path used for forward. */ @@ -93,12 +93,12 @@ spp_forward_update(struct spp_component_info *component) path->num_tx = component->num_tx_port; for (cnt = 0; cnt < num_rx; cnt++) memcpy(&path->ports[cnt].rx, component->rx_ports[cnt], - sizeof(struct spp_port_info)); + sizeof(struct sppwk_port_info)); /* Transmit port is set according with larger num_rx / num_tx. */ for (cnt = 0; cnt < max; cnt++) memcpy(&path->ports[cnt].tx, component->tx_ports[0], - sizeof(struct spp_port_info)); + sizeof(struct sppwk_port_info)); info->upd_index = info->ref_index; while (likely(info->ref_index == info->upd_index)) @@ -141,8 +141,8 @@ spp_forward(int id) int nb_tx = 0; struct forward_info *info = &g_forward_info[id]; struct forward_path *path = NULL; - struct spp_port_info *rx; - struct spp_port_info *tx; + struct sppwk_port_info *rx; + struct sppwk_port_info *tx; struct rte_mbuf *bufs[MAX_PKT_BURST]; change_forward_index(id); @@ -194,8 +194,8 @@ spp_forward_get_component_status( const char *component_type = NULL; struct forward_info *info = &g_forward_info[id]; struct forward_path *path = &info->path[info->ref_index]; - struct spp_port_index rx_ports[RTE_MAX_ETHPORTS]; - struct spp_port_index tx_ports[RTE_MAX_ETHPORTS]; + struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; + struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; if (unlikely(path->type == SPP_COMPONENT_UNUSE)) { RTE_LOG(ERR, FORWARD, -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Function `spp_get_dpdk_port()` is for getting consistent port ID provided by rte ethdev library, and intended to be used to convert SPP's resource UID such as `phy:0` to consistent ID. The name of function is not describing the purpose exactly. This update is to rename it to `sppwk_get_ethdev_port_id()` for refactoring. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/shared/secondary/spp_worker_th/command_proc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 34bfe82..9c8672b 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -594,9 +594,12 @@ spp_iterate_classifier_table( } #endif /* SPP_VF_MODULE */ -/* Get port number assigned by DPDK lib */ +/** + * 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 -spp_get_dpdk_port(enum port_type iface_type, int iface_no) +sppwk_get_ethdev_port_id(enum port_type iface_type, int iface_no) { struct iface_info *iface_info = NULL; @@ -1097,7 +1100,8 @@ append_port_block(char **output, const struct sppwk_port_idx *port, return SPP_RET_NG; ret = append_vlan_block("vlan", &tmp_buff, - spp_get_dpdk_port(port->iface_type, port->iface_no), + sppwk_get_ethdev_port_id( + port->iface_type, port->iface_no), rxtx); if (unlikely(ret < SPP_RET_OK)) return SPP_RET_NG; -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> `dpdk_port` defined in struct `sppwk_port_info` is a port ID provided by RTE ethdev library and the name is not appropriate. This update is to rename the attribute to `ethdev_port_id` instead. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/mirror/spp_mirror.c | 12 +++---- .../secondary/spp_worker_th/command_proc.c | 8 ++--- src/shared/secondary/spp_worker_th/spp_port.c | 2 +- src/shared/secondary/spp_worker_th/spp_proc.c | 34 +++++++++---------- src/shared/secondary/spp_worker_th/spp_proc.h | 3 +- src/vf/classifier_mac.c | 34 +++++++++---------- src/vf/spp_forward.c | 10 +++--- 7 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c index 5c4f68a..29eac4e 100644 --- a/src/mirror/spp_mirror.c +++ b/src/mirror/spp_mirror.c @@ -383,13 +383,13 @@ mirror_proc(int id) rx = &path->ports[0].rx; /* Receive packets */ - nb_rx = spp_eth_rx_burst(rx->dpdk_port, 0, bufs, MAX_PKT_BURST); + nb_rx = spp_eth_rx_burst(rx->ethdev_port_id, 0, bufs, MAX_PKT_BURST); if (unlikely(nb_rx == 0)) return SPP_RET_OK; /* mirror */ tx = &path->ports[1].tx; - if (tx->dpdk_port >= 0) { + if (tx->ethdev_port_id >= 0) { nb_tx2 = 0; for (cnt = 0; cnt < nb_rx; cnt++) { org_mbuf = bufs[cnt]; @@ -438,14 +438,14 @@ mirror_proc(int id) #endif /* SPP_MIRROR_SHALLOWCOPY */ } if (cnt != 0) - nb_tx2 = spp_eth_tx_burst(tx->dpdk_port, 0, - copybufs, cnt); + nb_tx2 = spp_eth_tx_burst( + tx->ethdev_port_id, 0, copybufs, cnt); } /* orginal */ tx = &path->ports[0].tx; - if (tx->dpdk_port >= 0) - nb_tx1 = spp_eth_tx_burst(tx->dpdk_port, 0, bufs, nb_rx); + if (tx->ethdev_port_id >= 0) + nb_tx1 = spp_eth_tx_burst(tx->ethdev_port_id, 0, bufs, nb_rx); nb_tx = nb_tx1; if (nb_tx1 != nb_tx2) diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 9c8672b..6ce407e 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -126,7 +126,7 @@ static int spp_check_flush_port(enum port_type iface_type, int iface_no) { struct sppwk_port_info *port = get_iface_info(iface_type, iface_no); - return port->dpdk_port >= 0; + return port->ethdev_port_id >= 0; } /* Update classifier table with given action, add or del. */ @@ -607,11 +607,11 @@ sppwk_get_ethdev_port_id(enum port_type iface_type, int iface_no) NULL, NULL, NULL, NULL, NULL); switch (iface_type) { case PHY: - return iface_info->nic[iface_no].dpdk_port; + return iface_info->nic[iface_no].ethdev_port_id; case RING: - return iface_info->ring[iface_no].dpdk_port; + return iface_info->ring[iface_no].ethdev_port_id; case VHOST: - return iface_info->vhost[iface_no].dpdk_port; + return iface_info->vhost[iface_no].ethdev_port_id; default: return SPP_RET_NG; } diff --git a/src/shared/secondary/spp_worker_th/spp_port.c b/src/shared/secondary/spp_worker_th/spp_port.c index c4070ce..9c0e109 100644 --- a/src/shared/secondary/spp_worker_th/spp_port.c +++ b/src/shared/secondary/spp_worker_th/spp_port.c @@ -251,7 +251,7 @@ port_ability_set_ability( enum spp_port_rxtx rxtx) { int in_cnt, out_cnt = 0; - int port_id = port->dpdk_port; + int port_id = port->ethdev_port_id; struct port_ability_port_mng_info *port_mng = &g_port_mng_info[port_id]; struct port_ability_mng_info *mng = NULL; diff --git a/src/shared/secondary/spp_worker_th/spp_proc.c b/src/shared/secondary/spp_worker_th/spp_proc.c index 689fb00..18acd64 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.c +++ b/src/shared/secondary/spp_worker_th/spp_proc.c @@ -354,7 +354,7 @@ dump_interface_info(const struct iface_info *iface_info) RTE_LOG(DEBUG, APP, "phy [%d] type=%d, no=%d, port=%d, " "vid = %u, mac=%08lx(%s)\n", cnt, port->iface_type, port->iface_no, - port->dpdk_port, + port->ethdev_port_id, port->class_id.vlantag.vid, port->class_id.mac_addr, port->class_id.mac_addr_str); @@ -367,7 +367,7 @@ dump_interface_info(const struct iface_info *iface_info) RTE_LOG(DEBUG, APP, "vhost[%d] type=%d, no=%d, port=%d, " "vid = %u, mac=%08lx(%s)\n", cnt, port->iface_type, port->iface_no, - port->dpdk_port, + port->ethdev_port_id, port->class_id.vlantag.vid, port->class_id.mac_addr, port->class_id.mac_addr_str); @@ -380,7 +380,7 @@ dump_interface_info(const struct iface_info *iface_info) RTE_LOG(DEBUG, APP, "ring [%d] type=%d, no=%d, port=%d, " "vid = %u, mac=%08lx(%s)\n", cnt, port->iface_type, port->iface_no, - port->dpdk_port, + port->ethdev_port_id, port->class_id.vlantag.vid, port->class_id.mac_addr, port->class_id.mac_addr_str); @@ -474,20 +474,20 @@ init_iface_info(void) memset(p_iface_info, 0x00, sizeof(struct iface_info)); for (port_cnt = 0; port_cnt < RTE_MAX_ETHPORTS; port_cnt++) { p_iface_info->nic[port_cnt].iface_type = UNDEF; - p_iface_info->nic[port_cnt].iface_no = port_cnt; - p_iface_info->nic[port_cnt].dpdk_port = -1; + p_iface_info->nic[port_cnt].iface_no = port_cnt; + p_iface_info->nic[port_cnt].ethdev_port_id = -1; p_iface_info->nic[port_cnt].class_id.vlantag.vid = - ETH_VLAN_ID_MAX; + ETH_VLAN_ID_MAX; p_iface_info->vhost[port_cnt].iface_type = UNDEF; - p_iface_info->vhost[port_cnt].iface_no = port_cnt; - p_iface_info->vhost[port_cnt].dpdk_port = -1; + p_iface_info->vhost[port_cnt].iface_no = port_cnt; + p_iface_info->vhost[port_cnt].ethdev_port_id = -1; p_iface_info->vhost[port_cnt].class_id.vlantag.vid = - ETH_VLAN_ID_MAX; + ETH_VLAN_ID_MAX; p_iface_info->ring[port_cnt].iface_type = UNDEF; - p_iface_info->ring[port_cnt].iface_no = port_cnt; - p_iface_info->ring[port_cnt].dpdk_port = -1; + p_iface_info->ring[port_cnt].iface_no = port_cnt; + p_iface_info->ring[port_cnt].ethdev_port_id = -1; p_iface_info->ring[port_cnt].class_id.vlantag.vid = - ETH_VLAN_ID_MAX; + ETH_VLAN_ID_MAX; } } @@ -534,7 +534,7 @@ set_nic_interface(void) for (nic_cnt = 0; nic_cnt < p_iface_info->num_nic; nic_cnt++) { p_iface_info->nic[nic_cnt].iface_type = PHY; - p_iface_info->nic[nic_cnt].dpdk_port = nic_cnt; + p_iface_info->nic[nic_cnt].ethdev_port_id = nic_cnt; } return SPP_RET_OK; @@ -825,23 +825,23 @@ flush_port(void) /* Initialize added vhost. */ for (cnt = 0; cnt < RTE_MAX_ETHPORTS; cnt++) { port = &p_iface_info->vhost[cnt]; - if ((port->iface_type != UNDEF) && (port->dpdk_port < 0)) { + if ((port->iface_type != UNDEF) && (port->ethdev_port_id < 0)) { ret = spp_vf_add_vhost_pmd(port->iface_no, g_mng_data_addr.p_startup_param->vhost_client); if (ret < 0) return SPP_RET_NG; - port->dpdk_port = ret; + port->ethdev_port_id = ret; } } /* Initialize added ring. */ for (cnt = 0; cnt < RTE_MAX_ETHPORTS; cnt++) { port = &p_iface_info->ring[cnt]; - if ((port->iface_type != UNDEF) && (port->dpdk_port < 0)) { + if ((port->iface_type != UNDEF) && (port->ethdev_port_id < 0)) { ret = add_ring_pmd(port->iface_no); if (ret < 0) return SPP_RET_NG; - port->dpdk_port = ret; + port->ethdev_port_id = ret; } } return SPP_RET_OK; diff --git a/src/shared/secondary/spp_worker_th/spp_proc.h b/src/shared/secondary/spp_worker_th/spp_proc.h index a11be2b..d7952fb 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.h +++ b/src/shared/secondary/spp_worker_th/spp_proc.h @@ -195,11 +195,10 @@ struct sppwk_port_idx { }; /* Define detailed port params in addition to `sppwk_port_idx`. */ -/* TODO(yasufum) revise name and usage of `dpdk_port`. */ struct sppwk_port_info { enum port_type iface_type; /**< phy, vhost or ring */ int iface_no; - int dpdk_port; /**< DPDK port number */ + int ethdev_port_id; /**< Consistent ID of ethdev */ struct spp_port_class_identifier class_id; struct spp_port_ability ability[SPP_PORT_ABILITY_MAX]; }; diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index 30b6353..1e98636 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -335,20 +335,20 @@ init_component_info(struct component_info *cmp_info, /* set rx */ if (component_info->num_rx_port == 0) { - clsd_data_rx->iface_type = UNDEF; - clsd_data_rx->iface_no = 0; + clsd_data_rx->iface_type = UNDEF; + clsd_data_rx->iface_no = 0; clsd_data_rx->iface_no_global = 0; - clsd_data_rx->port = 0; - clsd_data_rx->num_pkt = 0; + clsd_data_rx->port = 0; + clsd_data_rx->num_pkt = 0; } else { - clsd_data_rx->iface_type = - component_info->rx_ports[0]->iface_type; - clsd_data_rx->iface_no = 0; + clsd_data_rx->iface_type = + component_info->rx_ports[0]->iface_type; + clsd_data_rx->iface_no = 0; clsd_data_rx->iface_no_global = - component_info->rx_ports[0]->iface_no; - clsd_data_rx->port = - component_info->rx_ports[0]->dpdk_port; - clsd_data_rx->num_pkt = 0; + component_info->rx_ports[0]->iface_no; + clsd_data_rx->port = + component_info->rx_ports[0]->ethdev_port_id; + clsd_data_rx->num_pkt = 0; } /* set tx */ @@ -362,7 +362,7 @@ init_component_info(struct component_info *cmp_info, clsd_data_tx[i].iface_type = tx_port->iface_type; clsd_data_tx[i].iface_no = i; clsd_data_tx[i].iface_no_global = tx_port->iface_no; - clsd_data_tx[i].port = tx_port->dpdk_port; + clsd_data_tx[i].port = tx_port->ethdev_port_id; clsd_data_tx[i].num_pkt = 0; if (tx_port->class_id.mac_addr == 0) @@ -395,11 +395,11 @@ init_component_info(struct component_info *cmp_info, RTE_LOG(INFO, SPP_CLASSIFIER_MAC, "default classified. vid=%hu, " "iface_type=%d, iface_no=%d, " - "dpdk_port=%d\n", + "ethdev_port_id=%d\n", vid, tx_port->iface_type, tx_port->iface_no, - tx_port->dpdk_port); + tx_port->ethdev_port_id); continue; } @@ -423,12 +423,12 @@ init_component_info(struct component_info *cmp_info, RTE_LOG(INFO, SPP_CLASSIFIER_MAC, "Add entry to classifier mac table. " "vid=%hu, mac_addr=%s, iface_type=%d, " - "iface_no=%d, dpdk_port=%d\n", + "iface_no=%d, ethdev_port_id=%d\n", vid, mac_addr_str, tx_port->iface_type, tx_port->iface_no, - tx_port->dpdk_port); + tx_port->ethdev_port_id); } return SPP_RET_OK; @@ -462,7 +462,7 @@ transmit_packet(struct classified_data *clsd_data) for (i = n_tx; i < clsd_data->num_pkt; i++) rte_pktmbuf_free(clsd_data->pkts[i]); RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, - "drop packets(tx). num=%hu, dpdk_port=%hu\n", + "drop packets(tx). num=%hu, ethdev_port_id=%hu\n", (uint16_t)(clsd_data->num_pkt - n_tx), clsd_data->port); } diff --git a/src/vf/spp_forward.c b/src/vf/spp_forward.c index b9c0ad6..67fcd19 100644 --- a/src/vf/spp_forward.c +++ b/src/vf/spp_forward.c @@ -164,15 +164,15 @@ spp_forward(int id) tx = &path->ports[cnt].tx; /* Receive packets */ - nb_rx = spp_eth_rx_burst(rx->dpdk_port, 0, - bufs, MAX_PKT_BURST); + nb_rx = spp_eth_rx_burst(rx->ethdev_port_id, 0, + bufs, MAX_PKT_BURST); if (unlikely(nb_rx == 0)) continue; /* Send packets */ - if (tx->dpdk_port >= 0) - nb_tx = spp_eth_tx_burst(tx->dpdk_port, - 0, bufs, nb_rx); + if (tx->ethdev_port_id >= 0) + nb_tx = spp_eth_tx_burst(tx->ethdev_port_id, + 0, bufs, nb_rx); /* Discard remained packets to release mbuf */ if (unlikely(nb_tx < nb_rx)) { -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This update is to rename struct `spp_command_request` to `sppwk_cmd_req` to be more simple and specific. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/shared/secondary/spp_worker_th/cmd_parser.h | 6 +++--- src/shared/secondary/spp_worker_th/command_dec.c | 14 +++++++------- src/shared/secondary/spp_worker_th/command_proc.c | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index 3d31833..e42bc14 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -116,7 +116,7 @@ struct spp_command { }; /* Request parameters. */ -struct spp_command_request { +struct sppwk_cmd_req { int num_command; /**< Number of accepted commands */ int num_valid_command; /**< Number of executed commands */ struct spp_command commands[SPPWK_MAX_CMDS]; /**< list of cmds */ @@ -137,7 +137,7 @@ struct sppwk_parse_err_msg { * Parse request of non null terminated string. * * @param request - * The pointer to struct spp_command_request.@n + * The pointer to struct sppwk_cmd_req.@n * The result value of decoding the command message. * @param request_str * The pointer to requested command message. @@ -150,7 +150,7 @@ struct sppwk_parse_err_msg { * @retval SPP_RET_OK succeeded. * @retval !0 failed. */ -int spp_command_decode_request(struct spp_command_request *request, +int spp_command_decode_request(struct sppwk_cmd_req *request, const char *request_str, size_t request_str_len, struct sppwk_parse_err_msg *wk_err_msg); diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 918c2a2..80fd6d2 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -893,7 +893,7 @@ parameter_list[][SPPWK_MAX_PARAMS] = { /* Validate given command. */ static int -decode_command_parameter_component(struct spp_command_request *request, +decode_command_parameter_component(struct sppwk_cmd_req *request, int argc, char *argv[], struct sppwk_parse_err_msg *wk_err_msg, int maxargc __attribute__ ((unused))) @@ -921,7 +921,7 @@ decode_command_parameter_component(struct spp_command_request *request, /* Validate given command for clssfier_table. */ static int -decode_command_parameter_cls_table(struct spp_command_request *request, +decode_command_parameter_cls_table(struct sppwk_cmd_req *request, int argc, char *argv[], struct sppwk_parse_err_msg *wk_err_msg, int maxargc) @@ -934,7 +934,7 @@ decode_command_parameter_cls_table(struct spp_command_request *request, } /* Validate given command for clssfier_table of vlan. */ static int -decode_command_parameter_cls_table_vlan(struct spp_command_request *request, +decode_command_parameter_cls_table_vlan(struct sppwk_cmd_req *request, int argc, char *argv[], struct sppwk_parse_err_msg *wk_err_msg, int maxargc __attribute__ ((unused))) @@ -961,7 +961,7 @@ decode_command_parameter_cls_table_vlan(struct spp_command_request *request, /* Validate given command for port. */ static int -decode_command_parameter_port(struct spp_command_request *request, +decode_command_parameter_port(struct sppwk_cmd_req *request, int argc, char *argv[], struct sppwk_parse_err_msg *wk_err_msg, int maxargc) @@ -997,7 +997,7 @@ struct decode_command_list { const char *name; /* Command name */ int param_min; /* Min number of parameters */ int param_max; /* Max number of parameters */ - int (*func)(struct spp_command_request *request, int argc, + int (*func)(struct sppwk_cmd_req *request, int argc, char *argv[], struct sppwk_parse_err_msg *wk_err_msg, int maxargc); /* Pointer to command handling function */ @@ -1023,7 +1023,7 @@ static struct decode_command_list command_list[] = { /* Parse command line parameters. */ static int -decode_command_in_list(struct spp_command_request *request, +decode_command_in_list(struct sppwk_cmd_req *request, const char *request_str, struct sppwk_parse_err_msg *wk_err_msg) { @@ -1083,7 +1083,7 @@ decode_command_in_list(struct spp_command_request *request, /* decode request from no-null-terminated string */ int spp_command_decode_request( - struct spp_command_request *request, + struct sppwk_cmd_req *request, const char *request_str, size_t request_str_len, struct sppwk_parse_err_msg *wk_err_msg) { diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 6ce407e..1cb43e7 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -866,7 +866,7 @@ set_command_results(struct command_result *result, /* set decode error to command result */ static void set_decode_error_to_results(struct command_result *results, - const struct spp_command_request *request, + const struct sppwk_cmd_req *request, const struct sppwk_parse_err_msg *err_msg) { int i; @@ -1501,7 +1501,7 @@ append_info_value(const char *name, char **output) /* send response for decode error */ static void send_decode_error_response(int *sock, - const struct spp_command_request *request, + const struct sppwk_cmd_req *request, struct command_result *command_results) { int ret = SPP_RET_NG; @@ -1560,7 +1560,7 @@ send_decode_error_response(int *sock, /* send response for command execution result */ static void send_command_result_response(int *sock, - const struct spp_command_request *request, + const struct sppwk_cmd_req *request, struct command_result *command_results) { int ret = SPP_RET_NG; @@ -1647,11 +1647,11 @@ process_request(int *sock, const char *request_str, size_t request_str_len) int ret = SPP_RET_NG; int i; - struct spp_command_request request; + struct sppwk_cmd_req request; struct sppwk_parse_err_msg wk_err_msg; struct command_result command_results[SPPWK_MAX_CMDS]; - memset(&request, 0, sizeof(struct spp_command_request)); + memset(&request, 0, sizeof(struct sppwk_cmd_req)); memset(&wk_err_msg, 0, sizeof(struct sppwk_parse_err_msg)); memset(command_results, 0, sizeof(command_results)); -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> For refactoring, This update is to rename `spp_command_decode_request()` to `sppwk_parse_req()` because it is too long and not for decoding. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/shared/secondary/spp_worker_th/cmd_parser.h | 2 +- src/shared/secondary/spp_worker_th/command_dec.c | 4 ++-- src/shared/secondary/spp_worker_th/command_proc.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index e42bc14..785fffe 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -150,7 +150,7 @@ struct sppwk_parse_err_msg { * @retval SPP_RET_OK succeeded. * @retval !0 failed. */ -int spp_command_decode_request(struct sppwk_cmd_req *request, +int sppwk_parse_req(struct sppwk_cmd_req *request, const char *request_str, size_t request_str_len, struct sppwk_parse_err_msg *wk_err_msg); diff --git a/src/shared/secondary/spp_worker_th/command_dec.c b/src/shared/secondary/spp_worker_th/command_dec.c index 80fd6d2..723d8c4 100644 --- a/src/shared/secondary/spp_worker_th/command_dec.c +++ b/src/shared/secondary/spp_worker_th/command_dec.c @@ -1080,9 +1080,9 @@ decode_command_in_list(struct sppwk_cmd_req *request, return set_string_value_decode_error(wk_err_msg, argv[0], "command"); } -/* decode request from no-null-terminated string */ +/* Parse request of non null terminated string. */ int -spp_command_decode_request( +sppwk_parse_req( struct sppwk_cmd_req *request, const char *request_str, size_t request_str_len, struct sppwk_parse_err_msg *wk_err_msg) diff --git a/src/shared/secondary/spp_worker_th/command_proc.c b/src/shared/secondary/spp_worker_th/command_proc.c index 1cb43e7..f345759 100644 --- a/src/shared/secondary/spp_worker_th/command_proc.c +++ b/src/shared/secondary/spp_worker_th/command_proc.c @@ -1660,7 +1660,7 @@ process_request(int *sock, const char *request_str, size_t request_str_len) (int)request_str_len, request_str); /* decode request message */ - ret = spp_command_decode_request( + ret = sppwk_parse_req( &request, request_str, request_str_len, &wk_err_msg); if (unlikely(ret != SPP_RET_OK)) { /* send error response */ -- 2.17.1