From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This series of patches is to refactor functions, structs and vars for manipulating resources of spp_pcap. Yasufumi Ogawa (9): spp_pcap: rename enum spp_core_status spp_pcap: rename file of util libs spp_pcap: refactor parse error code spp_pcap: rename define starts from SPP_CMD_MAX spp_pcap: rename define of buffer size for cmds spp_pcap: revise name of error message object spp_pcap: revise return codes spp_pcap: rename struct spp_port_info spp_pcap: rename struct spp_port_index src/pcap/Makefile | 2 +- src/pcap/{command_dec.c => cmd_parser.c} | 72 +++-- src/pcap/{command_dec.h => cmd_parser.h} | 44 +-- src/pcap/{command_proc.c => cmd_runner.c} | 304 +++++++++--------- src/pcap/{command_proc.h => cmd_runner.h} | 14 +- src/pcap/cmd_utils.c | 62 ++-- src/pcap/cmd_utils.h | 90 +++--- src/pcap/spp_pcap.c | 193 +++++------ src/pcap/spp_pcap.h | 4 +- .../secondary/spp_worker_th/cmd_utils.h | 2 +- 10 files changed, 398 insertions(+), 389 deletions(-) rename src/pcap/{command_dec.c => cmd_parser.c} (68%) rename src/pcap/{command_dec.h => cmd_parser.h} (69%) rename src/pcap/{command_proc.c => cmd_runner.c} (81%) rename src/pcap/{command_proc.h => cmd_runner.h} (71%) -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This update is to rename enum `spp_core_status` to `sppwk_lcore_status` to be more specific. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/pcap/cmd_utils.c | 10 +++++----- src/pcap/cmd_utils.h | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/pcap/cmd_utils.c b/src/pcap/cmd_utils.c index be12058..f8f5e46 100644 --- a/src/pcap/cmd_utils.c +++ b/src/pcap/cmd_utils.c @@ -64,7 +64,7 @@ add_ring_pmd(int ring_id) } /* Get core status */ -enum spp_core_status +enum sppwk_lcore_status spp_get_core_status(unsigned int lcore_id) { return (g_mng_data_addr.p_core_info + lcore_id)->status; @@ -77,7 +77,7 @@ spp_get_core_status(unsigned int lcore_id) * If core is in use, status will be checked. */ static int -check_core_status(enum spp_core_status status) +check_core_status(enum sppwk_lcore_status status) { unsigned int lcore_id = 0; RTE_LCORE_FOREACH_SLAVE(lcore_id) { @@ -91,7 +91,7 @@ check_core_status(enum spp_core_status status) } int -check_core_status_wait(enum spp_core_status status) +check_core_status_wait(enum sppwk_lcore_status status) { int cnt = 0; for (cnt = 0; cnt < SPP_CORE_STATUS_CHECK_MAX; cnt++) { @@ -109,14 +109,14 @@ check_core_status_wait(enum spp_core_status status) /* Set core status */ void set_core_status(unsigned int lcore_id, - enum spp_core_status status) + enum sppwk_lcore_status status) { (g_mng_data_addr.p_core_info + lcore_id)->status = status; } /* Set all core to given status */ void -set_all_core_status(enum spp_core_status status) +set_all_core_status(enum sppwk_lcore_status status) { unsigned int lcore_id = 0; RTE_LCORE_FOREACH_SLAVE(lcore_id) { diff --git a/src/pcap/cmd_utils.h b/src/pcap/cmd_utils.h index 1b028fa..c7684c9 100644 --- a/src/pcap/cmd_utils.h +++ b/src/pcap/cmd_utils.h @@ -31,8 +31,9 @@ #define SPP_IFTYPE_NIC_STR "phy" #define SPP_IFTYPE_RING_STR "ring" +/* TODO(yasufum) merge it to the same definition in shared/.../cmd_utils.h */ /* State on core */ -enum spp_core_status { +enum sppwk_lcore_status { SPP_CORE_UNUSE, /**< Not used */ SPP_CORE_STOP, /**< Stopped */ SPP_CORE_IDLE, /**< Idling */ @@ -177,7 +178,7 @@ struct iface_info { /* Manage core status and component information as global variable */ struct core_mng_info { /* Status of cpu core */ - volatile enum spp_core_status status; + volatile enum sppwk_lcore_status status; }; struct spp_iterate_core_params; @@ -230,7 +231,7 @@ int add_ring_pmd(int ring_id); * @return * Status of specified logical core. */ -enum spp_core_status spp_get_core_status(unsigned int lcore_id); +enum sppwk_lcore_status spp_get_core_status(unsigned int lcore_id); /** * Run check_core_status() for SPP_CORE_STATUS_CHECK_MAX times with @@ -242,7 +243,7 @@ enum spp_core_status spp_get_core_status(unsigned int lcore_id); * @retval 0 succeeded. * @retval -1 failed. */ -int check_core_status_wait(enum spp_core_status status); +int check_core_status_wait(enum sppwk_lcore_status status); /** * Set core status @@ -253,7 +254,7 @@ int check_core_status_wait(enum spp_core_status status); * set status. * */ -void set_core_status(unsigned int lcore_id, enum spp_core_status status); +void set_core_status(unsigned int lcore_id, enum sppwk_lcore_status status); /** * Set all core status to given @@ -262,7 +263,7 @@ void set_core_status(unsigned int lcore_id, enum spp_core_status status); * set status. * */ -void set_all_core_status(enum spp_core_status status); +void set_all_core_status(enum sppwk_lcore_status status); /** * Set all of component status to SPP_CORE_STOP_REQUEST if received signal -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> As renamed in shared dir, this update is to rename `command_dec.*` and `command_proc.*` to `cmd_parser.*` and `cmd_runner.*`. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/pcap/Makefile | 2 +- src/pcap/{command_dec.c => cmd_parser.c} | 2 +- src/pcap/{command_dec.h => cmd_parser.h} | 0 src/pcap/{command_proc.c => cmd_runner.c} | 4 ++-- src/pcap/{command_proc.h => cmd_runner.h} | 0 src/pcap/spp_pcap.c | 4 ++-- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/pcap/{command_dec.c => cmd_parser.c} (99%) rename src/pcap/{command_dec.h => cmd_parser.h} (100%) rename src/pcap/{command_proc.c => cmd_runner.c} (99%) rename src/pcap/{command_proc.h => cmd_runner.h} (100%) diff --git a/src/pcap/Makefile b/src/pcap/Makefile index e5e0b00..61f6f81 100644 --- a/src/pcap/Makefile +++ b/src/pcap/Makefile @@ -16,7 +16,7 @@ SPP_WKT_DIR = ../shared/secondary/spp_worker_th # all source are stored in SRCS-y SRCS-y := spp_pcap.c SRCS-y += cmd_utils.c -SRCS-y += command_proc.c command_dec.c +SRCS-y += cmd_runner.c cmd_parser.c SRCS-y += ../shared/common.c SRCS-y += $(SPP_WKT_DIR)/command_conn.c SRCS-y += $(SPP_WKT_DIR)/spp_port.c diff --git a/src/pcap/command_dec.c b/src/pcap/cmd_parser.c similarity index 99% rename from src/pcap/command_dec.c rename to src/pcap/cmd_parser.c index 943ab0f..6734c1e 100644 --- a/src/pcap/command_dec.c +++ b/src/pcap/cmd_parser.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_DEC RTE_LOGTYPE_USER2 diff --git a/src/pcap/command_dec.h b/src/pcap/cmd_parser.h similarity index 100% rename from src/pcap/command_dec.h rename to src/pcap/cmd_parser.h diff --git a/src/pcap/command_proc.c b/src/pcap/cmd_runner.c similarity index 99% rename from src/pcap/command_proc.c rename to src/pcap/cmd_runner.c index 2987cad..f51b819 100644 --- a/src/pcap/command_proc.c +++ b/src/pcap/cmd_runner.c @@ -10,8 +10,8 @@ #include "shared/secondary/spp_worker_th/string_buffer.h" #include "spp_pcap.h" #include "shared/secondary/spp_worker_th/command_conn.h" -#include "command_dec.h" -#include "command_proc.h" +#include "cmd_parser.h" +#include "cmd_runner.h" #define RTE_LOGTYPE_SPP_COMMAND_PROC RTE_LOGTYPE_USER2 diff --git a/src/pcap/command_proc.h b/src/pcap/cmd_runner.h similarity index 100% rename from src/pcap/command_proc.h rename to src/pcap/cmd_runner.h diff --git a/src/pcap/spp_pcap.c b/src/pcap/spp_pcap.c index b048237..b48caf4 100644 --- a/src/pcap/spp_pcap.c +++ b/src/pcap/spp_pcap.c @@ -15,8 +15,8 @@ #include "shared/common.h" #include "cmd_utils.h" #include "spp_pcap.h" -#include "command_proc.h" -#include "command_dec.h" +#include "cmd_runner.h" +#include "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> Revise the name of enum `spp_comamnd_decode_error_code` to `sppwk_parse_error_code`, and its members to be more reasonable. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/pcap/cmd_parser.c | 6 +++--- src/pcap/cmd_parser.h | 12 ++++++------ src/pcap/cmd_runner.c | 21 +++++++++++---------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/pcap/cmd_parser.c b/src/pcap/cmd_parser.c index 6734c1e..e7ad50e 100644 --- a/src/pcap/cmd_parser.c +++ b/src/pcap/cmd_parser.c @@ -32,7 +32,7 @@ set_string_value_parse_error(struct spp_command_parse_error *error, const char *value, const char *error_name) { strcpy(error->value, value); - return set_parse_error(error, BAD_VALUE, error_name); + return set_parse_error(error, SPPWK_PARSE_INVALID_VALUE, error_name); } /* Split command line parameter with spaces */ @@ -102,7 +102,7 @@ parse_command_in_list(struct spp_command_request *request, if (ret < SPP_RET_OK) { RTE_LOG(ERR, SPP_COMMAND_DEC, "Parameter number over limit." "request_str=%s\n", request_str); - return set_parse_error(error, BAD_FORMAT, NULL); + return set_parse_error(error, SPPWK_PARSE_WRONG_FORMAT, NULL); } RTE_LOG(DEBUG, SPP_COMMAND_DEC, "Decode array. num=%d\n", argc); @@ -128,7 +128,7 @@ parse_command_in_list(struct spp_command_request *request, if (command_name_check != 0) { RTE_LOG(ERR, SPP_COMMAND_DEC, "Parameter number out of range." "request_str=%s\n", request_str); - return set_parse_error(error, BAD_FORMAT, NULL); + return set_parse_error(error, SPPWK_PARSE_WRONG_FORMAT, NULL); } RTE_LOG(ERR, SPP_COMMAND_DEC, diff --git a/src/pcap/cmd_parser.h b/src/pcap/cmd_parser.h index 84f7ae6..3893214 100644 --- a/src/pcap/cmd_parser.h +++ b/src/pcap/cmd_parser.h @@ -27,13 +27,13 @@ #define SPP_CMD_VALUE_BUFSZ 111 /** parse error code */ -enum spp_command_parse_error_code { +enum sppwk_parse_error_code { /* not use 0, in general 0 is OK */ - BAD_FORMAT = 1, /**< Wrong format */ - UNKNOWN_COMMAND, /**< Unknown command */ - NO_PARAM, /**< No parameters */ - BAD_TYPE, /**< Wrong data type */ - BAD_VALUE, /**< Wrong value */ + SPPWK_PARSE_WRONG_FORMAT = 1, /**< Wrong format */ + SPPWK_PARSE_UNKNOWN_CMD, /**< Unknown command */ + SPPWK_PARSE_NO_PARAM, /**< No parameters */ + SPPWK_PARSE_INVALID_TYPE, /**< Wrong data type */ + SPPWK_PARSE_INVALID_VALUE, /**< Wrong value */ }; /** diff --git a/src/pcap/cmd_runner.c b/src/pcap/cmd_runner.c index f51b819..44d00ae 100644 --- a/src/pcap/cmd_runner.c +++ b/src/pcap/cmd_runner.c @@ -276,26 +276,27 @@ parse_error_message( char *message) { switch (parse_error->code) { - case BAD_FORMAT: - sprintf(message, "bad message format"); + case SPPWK_PARSE_WRONG_FORMAT: + sprintf(message, "Wrong message format"); break; - case UNKNOWN_COMMAND: - sprintf(message, "unknown command(%s)", parse_error->value); + case SPPWK_PARSE_UNKNOWN_CMD: + /* TODO(yasufum) Fix compile err if space exists before "(" */ + sprintf(message, "Unknown command(%s)", parse_error->value); break; - case NO_PARAM: - sprintf(message, "not enough parameter(%s)", + case SPPWK_PARSE_NO_PARAM: + sprintf(message, "No or insufficient number of params (%s)", parse_error->value_name); break; - case BAD_TYPE: - sprintf(message, "bad value type(%s)", + case SPPWK_PARSE_INVALID_TYPE: + sprintf(message, "Invalid value type (%s)", parse_error->value_name); break; - case BAD_VALUE: - sprintf(message, "bad value(%s)", parse_error->value_name); + case SPPWK_PARSE_INVALID_VALUE: + sprintf(message, "Invalid value (%s)", parse_error->value_name); break; default: -- 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. This update is also revise log labels. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/pcap/cmd_parser.c | 18 ++++----- src/pcap/cmd_parser.h | 12 +++--- src/pcap/cmd_runner.c | 92 +++++++++++++++++++++---------------------- src/pcap/cmd_runner.h | 6 +-- src/pcap/cmd_utils.c | 10 ++--- src/pcap/cmd_utils.h | 8 +++- 6 files changed, 76 insertions(+), 70 deletions(-) diff --git a/src/pcap/cmd_parser.c b/src/pcap/cmd_parser.c index e7ad50e..b91b39c 100644 --- a/src/pcap/cmd_parser.c +++ b/src/pcap/cmd_parser.c @@ -11,7 +11,7 @@ #include "cmd_parser.h" -#define RTE_LOGTYPE_SPP_COMMAND_DEC RTE_LOGTYPE_USER2 +#define RTE_LOGTYPE_PCAP_PARSER RTE_LOGTYPE_USER2 /* set parse error */ static inline int @@ -91,20 +91,20 @@ parse_command_in_list(struct spp_command_request *request, struct parse_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 = parse_parameter_value(tmp_str, SPP_CMD_MAX_PARAMETERS, + ret = parse_parameter_value(tmp_str, SPPWK_MAX_PARAMS, &argc, argv); if (ret < SPP_RET_OK) { - RTE_LOG(ERR, SPP_COMMAND_DEC, "Parameter number over limit." + RTE_LOG(ERR, PCAP_PARSER, "Parameter number over limit." "request_str=%s\n", request_str); return set_parse_error(error, SPPWK_PARSE_WRONG_FORMAT, NULL); } - RTE_LOG(DEBUG, SPP_COMMAND_DEC, "Decode array. num=%d\n", argc); + RTE_LOG(DEBUG, PCAP_PARSER, "Decode array. num=%d\n", argc); for (i = 0; command_list_pcap[i].name[0] != '\0'; i++) { list = &command_list_pcap[i]; @@ -126,12 +126,12 @@ parse_command_in_list(struct spp_command_request *request, } if (command_name_check != 0) { - RTE_LOG(ERR, SPP_COMMAND_DEC, "Parameter number out of range." + RTE_LOG(ERR, PCAP_PARSER, "Parameter number out of range." "request_str=%s\n", request_str); return set_parse_error(error, SPPWK_PARSE_WRONG_FORMAT, NULL); } - RTE_LOG(ERR, SPP_COMMAND_DEC, + RTE_LOG(ERR, PCAP_PARSER, "Unknown command. command=%s, request_str=%s\n", argv[0], request_str); return set_string_value_parse_error(error, argv[0], "command"); @@ -151,7 +151,7 @@ spp_command_parse_request( request->num_command = 1; ret = parse_command_in_list(request, request_str, error); if (unlikely(ret != SPP_RET_OK)) { - RTE_LOG(ERR, SPP_COMMAND_DEC, + RTE_LOG(ERR, PCAP_PARSER, "Cannot parse command request. " "ret=%d, request_str=%.*s\n", ret, (int)request_str_len, request_str); diff --git a/src/pcap/cmd_parser.h b/src/pcap/cmd_parser.h index 3893214..109b649 100644 --- a/src/pcap/cmd_parser.h +++ b/src/pcap/cmd_parser.h @@ -2,8 +2,8 @@ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation */ -#ifndef _SPP_PCAP_COMMAND_DEC_H_ -#define _SPP_PCAP_COMMAND_DEC_H_ +#ifndef _SPP_PCAP_CMD_PARSER_H_ +#define _SPP_PCAP_CMD_PARSER_H_ /** * @file @@ -15,10 +15,10 @@ #include "cmd_utils.h" /** max number of command 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 /** command name string buffer size (include null char) */ #define SPP_CMD_NAME_BUFSZ 32 @@ -69,7 +69,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]; + struct spp_command commands[SPPWK_MAX_CMDS]; /**<Information of executed commands */ int is_requested_client_id; /**< Id for get_client_id command */ @@ -107,4 +107,4 @@ int spp_command_parse_request(struct spp_command_request *request, const char *request_str, size_t request_str_len, struct spp_command_parse_error *error); -#endif /* _COMMAND_DEC_H_ */ +#endif /* _SPP_PCAP_CMD_PARSER_H_ */ diff --git a/src/pcap/cmd_runner.c b/src/pcap/cmd_runner.c index 44d00ae..0ce5d49 100644 --- a/src/pcap/cmd_runner.c +++ b/src/pcap/cmd_runner.c @@ -13,7 +13,7 @@ #include "cmd_parser.h" #include "cmd_runner.h" -#define RTE_LOGTYPE_SPP_COMMAND_PROC RTE_LOGTYPE_USER2 +#define RTE_LOGTYPE_PCAP_RUNNER RTE_LOGTYPE_USER2 /* request message initial size */ #define CMD_RES_ERR_MSG_SIZE 128 @@ -90,7 +90,7 @@ spp_iterate_core_info(struct spp_iterate_core_params *params) ret = spp_pcap_get_core_status(lcore_id, params); if (unlikely(ret != 0)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Cannot iterate core information. " "(core = %d)\n", lcore_id); return SPP_RET_NG; @@ -106,7 +106,7 @@ append_json_comma(char **output) { *output = spp_strbuf_append(*output, ", ", strlen(", ")); if (unlikely(*output == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "JSON's comma failed to add.\n"); return SPP_RET_NG; } @@ -126,7 +126,7 @@ append_json_uint_value(const char *name, char **output, unsigned int value) *output = spp_strbuf_append(*output, "", strlen(name) + CMD_TAG_APPEND_SIZE*2); if (unlikely(*output == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "JSON's numeric format failed to add. " "(name = %s, uint = %u)\n", name, value); return SPP_RET_NG; @@ -150,7 +150,7 @@ append_json_int_value(const char *name, char **output, int value) *output = spp_strbuf_append(*output, "", strlen(name) + CMD_TAG_APPEND_SIZE*2); if (unlikely(*output == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "JSON's numeric format failed to add. " "(name = %s, int = %d)\n", name, value); return SPP_RET_NG; @@ -174,7 +174,7 @@ append_json_str_value(const char *name, char **output, const char *str) *output = spp_strbuf_append(*output, "", strlen(name) + strlen(str) + CMD_TAG_APPEND_SIZE); if (unlikely(*output == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "JSON's string format failed to add. " "(name = %s, str = %s)\n", name, str); return SPP_RET_NG; @@ -198,7 +198,7 @@ append_json_array_brackets(const char *name, char **output, const char *str) *output = spp_strbuf_append(*output, "", strlen(name) + strlen(str) + CMD_TAG_APPEND_SIZE); if (unlikely(*output == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "JSON's square bracket failed to add. " "(name = %s, str = %s)\n", name, str); return SPP_RET_NG; @@ -218,7 +218,7 @@ append_json_block_brackets(const char *name, char **output, const char *str) *output = spp_strbuf_append(*output, "", strlen(name) + strlen(str) + CMD_TAG_APPEND_SIZE); if (unlikely(*output == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "JSON's curly bracket failed to add. " "(name = %s, str = %s)\n", name, str); return SPP_RET_NG; @@ -241,27 +241,27 @@ execute_command(const struct spp_command *command) switch (command->type) { case CMD_CLIENT_ID: - RTE_LOG(INFO, SPP_COMMAND_PROC, + RTE_LOG(INFO, PCAP_RUNNER, "Execute get_client_id command.\n"); break; case CMD_STATUS: - RTE_LOG(INFO, SPP_COMMAND_PROC, + RTE_LOG(INFO, PCAP_RUNNER, "Execute status command.\n"); break; case CMD_EXIT: - RTE_LOG(INFO, SPP_COMMAND_PROC, + RTE_LOG(INFO, PCAP_RUNNER, "Execute exit command.\n"); break; case CMD_START: - RTE_LOG(INFO, SPP_COMMAND_PROC, + RTE_LOG(INFO, PCAP_RUNNER, "Execute start command.\n"); break; case CMD_STOP: - RTE_LOG(INFO, SPP_COMMAND_PROC, + RTE_LOG(INFO, PCAP_RUNNER, "Execute stop command.\n"); break; } @@ -376,7 +376,7 @@ append_error_details_value(const char *name, char **output, void *tmp) tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s)\n", name); return SPP_RET_NG; @@ -424,7 +424,7 @@ append_port_entry(char **output, const struct spp_port_index *port, char port_str[CMD_TAG_APPEND_SIZE]; char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = port_block)\n"); return SPP_RET_NG; } @@ -449,7 +449,7 @@ append_port_array(const char *name, char **output, const int num, int i = 0; char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s)\n", name); return SPP_RET_NG; @@ -496,7 +496,7 @@ append_pcap_core_element_value( tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (lcore_id = %d, type = %s)\n", lcore_id, type); return ret; @@ -544,7 +544,7 @@ append_core_value(const char *name, char **output, char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s)\n", name); return SPP_RET_NG; @@ -575,7 +575,7 @@ append_response_list_value(char **output, char *tmp_buff; tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = response_list)\n"); return SPP_RET_NG; } @@ -585,7 +585,7 @@ append_response_list_value(char **output, ret = list[i].func(list[i].tag_name, &tmp_buff, tmp); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Failed to get reply string. " "(tag = %s)\n", list[i].tag_name); return SPP_RET_NG; @@ -598,7 +598,7 @@ append_response_list_value(char **output, ret = append_json_comma(output); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Failed to add commas. " "(tag = %s)\n", list[i].tag_name); @@ -610,7 +610,7 @@ append_response_list_value(char **output, strlen(tmp_buff)); if (unlikely(*output == NULL)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Failed to add reply string. " "(tag = %s)\n", list[i].tag_name); @@ -651,7 +651,7 @@ append_command_results_value(const char *name, char **output, char *tmp_buff1, *tmp_buff2; tmp_buff1 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff1 == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s, buff=1)\n", name); return SPP_RET_NG; @@ -660,7 +660,7 @@ append_command_results_value(const char *name, char **output, tmp_buff2 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff2 == NULL)) { spp_strbuf_free(tmp_buff1); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s, buff=2)\n", name); return SPP_RET_NG; @@ -698,7 +698,7 @@ append_info_value(const char *name, char **output) int ret = SPP_RET_NG; char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s)\n", name); return SPP_RET_NG; @@ -726,7 +726,7 @@ send_parse_error_response(int *sock, char *msg, *tmp_buff; tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, "allocate error. " + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. " "(name = parse_error_response)\n"); return; } @@ -736,7 +736,7 @@ send_parse_error_response(int *sock, request->num_command, command_results); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Failed to make command result response.\n"); return; } @@ -744,7 +744,7 @@ send_parse_error_response(int *sock, msg = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(msg == NULL)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, "allocate error. " + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. " "(name = parse_error_response)\n"); return; } @@ -752,19 +752,19 @@ send_parse_error_response(int *sock, spp_strbuf_free(tmp_buff); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(msg); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = result_response)\n"); return; } - RTE_LOG(DEBUG, SPP_COMMAND_PROC, + RTE_LOG(DEBUG, PCAP_RUNNER, "Make command response (parse error). " "response_str=\n%s\n", msg); /* send response to requester */ ret = spp_send_message(sock, msg, strlen(msg)); if (unlikely(ret != SPP_RET_OK)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Failed to send parse error response.\n"); /* not return */ } @@ -784,7 +784,7 @@ send_command_result_response(int *sock, tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = result_response)\n"); return; } @@ -794,7 +794,7 @@ send_command_result_response(int *sock, request->num_command, command_results); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Failed to make command result response.\n"); return; } @@ -804,7 +804,7 @@ send_command_result_response(int *sock, ret = append_client_id_value("client_id", &tmp_buff, NULL); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, "Failed to make " + RTE_LOG(ERR, PCAP_RUNNER, "Failed to make " "client id response.\n"); return; } @@ -817,7 +817,7 @@ send_command_result_response(int *sock, ret = append_info_value("info", &tmp_buff); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Failed to make status response.\n"); return; } @@ -840,7 +840,7 @@ send_command_result_response(int *sock, msg = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(msg == NULL)) { spp_strbuf_free(tmp_buff); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = result_response)\n"); return; } @@ -848,19 +848,19 @@ send_command_result_response(int *sock, spp_strbuf_free(tmp_buff); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(msg); - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = result_response)\n"); return; } - RTE_LOG(DEBUG, SPP_COMMAND_PROC, + RTE_LOG(DEBUG, PCAP_RUNNER, "Make command response (command result). " "response_str=\n%s\n", msg); /* send response to requester */ ret = spp_send_message(sock, msg, strlen(msg)); if (unlikely(ret != SPP_RET_OK)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Failed to send command result response.\n"); /* not return */ } @@ -877,13 +877,13 @@ process_request(int *sock, const char *request_str, size_t request_str_len) struct spp_command_request request; struct spp_command_parse_error parse_error; - 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(&parse_error, 0, sizeof(struct spp_command_parse_error)); memset(command_results, 0, sizeof(command_results)); - RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Start command request processing. " + RTE_LOG(DEBUG, PCAP_RUNNER, "Start command request processing. " "request_str=\n%.*s\n", (int)request_str_len, request_str); @@ -895,12 +895,12 @@ process_request(int *sock, const char *request_str, size_t request_str_len) set_parse_error_to_results(command_results, &request, &parse_error); send_parse_error_response(sock, &request, command_results); - RTE_LOG(DEBUG, SPP_COMMAND_PROC, + RTE_LOG(DEBUG, PCAP_RUNNER, "End command request processing.\n"); return SPP_RET_OK; } - RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Command request is valid. " + RTE_LOG(DEBUG, PCAP_RUNNER, "Command request is valid. " "num_command=%d, num_valid_command=%d\n", request.num_command, request.num_valid_command); @@ -927,7 +927,7 @@ process_request(int *sock, const char *request_str, size_t request_str_len) /* Other route is normal end because it responds to command. */ set_command_results(&command_results[0], CMD_SUCCESS, ""); send_command_result_response(sock, &request, command_results); - RTE_LOG(INFO, SPP_COMMAND_PROC, + RTE_LOG(INFO, PCAP_RUNNER, "Terminate process for exit.\n"); return SPP_RET_NG; } @@ -935,7 +935,7 @@ process_request(int *sock, const char *request_str, size_t request_str_len) /* send response */ send_command_result_response(sock, &request, command_results); - RTE_LOG(DEBUG, SPP_COMMAND_PROC, "End command request processing.\n"); + RTE_LOG(DEBUG, PCAP_RUNNER, "End command request processing.\n"); return SPP_RET_OK; } @@ -960,7 +960,7 @@ spp_command_proc_do(void) if (unlikely(msgbuf == NULL)) { msgbuf = spp_strbuf_allocate(CMD_REQ_BUF_INIT_SIZE); if (unlikely(msgbuf == NULL)) { - RTE_LOG(ERR, SPP_COMMAND_PROC, + RTE_LOG(ERR, PCAP_RUNNER, "Cannot allocate memory " "for receive data(init).\n"); return SPP_RET_NG; diff --git a/src/pcap/cmd_runner.h b/src/pcap/cmd_runner.h index cbaf6a2..ccae164 100644 --- a/src/pcap/cmd_runner.h +++ b/src/pcap/cmd_runner.h @@ -2,8 +2,8 @@ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation */ -#ifndef _SPP_PCAP_COMMAND_PROC_H_ -#define _SPP_PCAP_COMMAND_PROC_H_ +#ifndef _SPP_PCAP_CMD_RUNNER_H_ +#define _SPP_PCAP_CMD_RUNNER_H_ /** * @file @@ -39,4 +39,4 @@ spp_command_proc_init(const char *controller_ip, int controller_port); int spp_command_proc_do(void); -#endif /* _SPP_PCAP_COMMAND_PROC_H_ */ +#endif /* _SPP_PCAP_CMD_RUNNER_H_ */ diff --git a/src/pcap/cmd_utils.c b/src/pcap/cmd_utils.c index f8f5e46..f425ed0 100644 --- a/src/pcap/cmd_utils.c +++ b/src/pcap/cmd_utils.c @@ -10,7 +10,7 @@ #include "cmd_utils.h" -#define RTE_LOGTYPE_SPP_PROC RTE_LOGTYPE_USER2 +#define RTE_LOGTYPE_PCAP_UTILS RTE_LOGTYPE_USER2 /* Manage data to addoress */ struct manage_data_addr_info { @@ -38,7 +38,7 @@ add_ring_pmd(int ring_id) /* Lookup ring of given id */ ring = rte_ring_lookup(get_rx_queue_name(ring_id)); if (unlikely(ring == NULL)) { - RTE_LOG(ERR, SPP_PROC, + RTE_LOG(ERR, PCAP_UTILS, "Cannot get RX ring - is server process running?\n"); return SPP_RET_NG; } @@ -50,7 +50,7 @@ add_ring_pmd(int ring_id) if (port_id == PORT_RESET) { ring_port_id = rte_eth_from_ring(ring); if (ring_port_id < 0) { - RTE_LOG(ERR, SPP_PROC, "Cannot create eth dev with " + RTE_LOG(ERR, PCAP_UTILS, "Cannot create eth dev with " "rte_eth_from_ring()\n"); return SPP_RET_NG; } @@ -58,7 +58,7 @@ add_ring_pmd(int ring_id) ring_port_id = port_id; rte_eth_dev_start(ring_port_id); } - RTE_LOG(INFO, SPP_PROC, "ring port add. (no = %d / port = %d)\n", + RTE_LOG(INFO, PCAP_UTILS, "ring port add. (no = %d / port = %d)\n", ring_id, ring_port_id); return ring_port_id; } @@ -101,7 +101,7 @@ check_core_status_wait(enum sppwk_lcore_status status) return SPP_RET_OK; } - RTE_LOG(ERR, SPP_PROC, + RTE_LOG(ERR, PCAP_UTILS, "Status check time out. (status = %d)\n", status); return SPP_RET_NG; } diff --git a/src/pcap/cmd_utils.h b/src/pcap/cmd_utils.h index c7684c9..8cebf2d 100644 --- a/src/pcap/cmd_utils.h +++ b/src/pcap/cmd_utils.h @@ -2,6 +2,12 @@ * Copyright(c) 2018 Nippon Telegraph and Telephone Corporation */ +/** + * TODO(yasufum) change this define tag because it is the same as + * shared/.../cmd_utils.h. However, it should be the same to avoid both of + * this and shared headers are included which are incompabtible and causes + * an compile error. After fixing the incompatibility, change the tag name. + */ #ifndef _SPPWK_CMD_UTILS_H_ #define _SPPWK_CMD_UTILS_H_ @@ -387,4 +393,4 @@ void spp_get_mng_data_addr(struct startup_param **startup_param_addr, int **capture_request_addr, int **capture_status_addr); -#endif /* _SPPWK_CMD_UTILS_H_ */ +#endif -- 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/pcap/cmd_parser.c | 2 +- src/pcap/cmd_parser.h | 8 ++++---- src/pcap/cmd_runner.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pcap/cmd_parser.c b/src/pcap/cmd_parser.c index b91b39c..a5f3a4a 100644 --- a/src/pcap/cmd_parser.c +++ b/src/pcap/cmd_parser.c @@ -92,7 +92,7 @@ parse_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/pcap/cmd_parser.h b/src/pcap/cmd_parser.h index 109b649..5945e62 100644 --- a/src/pcap/cmd_parser.h +++ b/src/pcap/cmd_parser.h @@ -21,10 +21,10 @@ #define SPPWK_MAX_PARAMS 8 /** command name string buffer size (include null char) */ -#define SPP_CMD_NAME_BUFSZ 32 +#define SPPWK_NAME_BUFSZ 32 /** command value string buffer size (include null char) */ -#define SPP_CMD_VALUE_BUFSZ 111 +#define SPPWK_VAL_BUFSZ 111 /** parse error code */ enum sppwk_parse_error_code { @@ -82,8 +82,8 @@ struct spp_command_request { /** parse error information */ struct spp_command_parse_error { int code; /**< Error code */ - char value_name[SPP_CMD_NAME_BUFSZ]; /**< Error value name */ - char value[SPP_CMD_VALUE_BUFSZ]; /**< Error value */ + char value_name[SPPWK_NAME_BUFSZ]; /**< Error value name */ + char value[SPPWK_VAL_BUFSZ]; /**< Error value */ }; /** diff --git a/src/pcap/cmd_runner.c b/src/pcap/cmd_runner.c index 0ce5d49..d5ae3a5 100644 --- a/src/pcap/cmd_runner.c +++ b/src/pcap/cmd_runner.c @@ -42,7 +42,7 @@ struct command_result { int code; /* Response message */ - char msg[SPP_CMD_NAME_BUFSZ]; + char msg[SPPWK_NAME_BUFSZ]; /* Detailed response message */ char error_message[CMD_RES_ERR_MSG_SIZE]; @@ -51,7 +51,7 @@ struct command_result { /* command response list control structure */ struct command_response_list { /* JSON 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> This update is to the name of struct for containing error message objects to `sppwk_parse_err_msg` and its members. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/pcap/cmd_parser.c | 38 ++++++++++++++++++++------------------ src/pcap/cmd_parser.h | 14 +++++++------- src/pcap/cmd_runner.c | 27 +++++++++++++-------------- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/pcap/cmd_parser.c b/src/pcap/cmd_parser.c index a5f3a4a..48a8bd6 100644 --- a/src/pcap/cmd_parser.c +++ b/src/pcap/cmd_parser.c @@ -15,24 +15,24 @@ /* set parse error */ static inline int -set_parse_error(struct spp_command_parse_error *error, - const int error_code, const char *error_name) +set_parse_error(struct sppwk_parse_err_msg *wk_err_msg, + const int err_code, const char *err_msg) { - error->code = error_code; + wk_err_msg->code = err_code; - if (likely(error_name != NULL)) - strcpy(error->value_name, error_name); + if (likely(err_msg != NULL)) + strcpy(wk_err_msg->msg, err_msg); - return error->code; + return wk_err_msg->code; } /* set parse error */ static inline int -set_string_value_parse_error(struct spp_command_parse_error *error, - const char *value, const char *error_name) +set_string_value_parse_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 */ @@ -63,7 +63,7 @@ struct parse_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_parse_error *error, + char *argv[], struct sppwk_parse_err_msg *error, int maxargc); /* Pointer to command handling function */ enum spp_command_type type; @@ -84,7 +84,7 @@ static struct parse_command_list command_list_pcap[] = { static int parse_command_in_list(struct spp_command_request *request, const char *request_str, - struct spp_command_parse_error *error) + struct sppwk_parse_err_msg *wk_err_msg) { int ret = SPP_RET_OK; int command_name_check = 0; @@ -102,7 +102,8 @@ parse_command_in_list(struct spp_command_request *request, if (ret < SPP_RET_OK) { RTE_LOG(ERR, PCAP_PARSER, "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, PCAP_PARSER, "Decode array. num=%d\n", argc); @@ -119,7 +120,7 @@ parse_command_in_list(struct spp_command_request *request, request->commands[0].type = command_list_pcap[i].type; 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; @@ -128,13 +129,14 @@ parse_command_in_list(struct spp_command_request *request, if (command_name_check != 0) { RTE_LOG(ERR, PCAP_PARSER, "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, PCAP_PARSER, "Unknown command. command=%s, request_str=%s\n", argv[0], request_str); - return set_string_value_parse_error(error, argv[0], "command"); + return set_string_value_parse_error(wk_err_msg, argv[0], "command"); } /* parse request from no-null-terminated string */ @@ -142,14 +144,14 @@ int spp_command_parse_request( struct spp_command_request *request, const char *request_str, size_t request_str_len, - struct spp_command_parse_error *error) + struct sppwk_parse_err_msg *wk_err_msg) { int ret = SPP_RET_NG; int i; /* parse request */ request->num_command = 1; - ret = parse_command_in_list(request, request_str, error); + ret = parse_command_in_list(request, request_str, wk_err_msg); if (unlikely(ret != SPP_RET_OK)) { RTE_LOG(ERR, PCAP_PARSER, "Cannot parse command request. " diff --git a/src/pcap/cmd_parser.h b/src/pcap/cmd_parser.h index 5945e62..9fa1b7b 100644 --- a/src/pcap/cmd_parser.h +++ b/src/pcap/cmd_parser.h @@ -79,11 +79,11 @@ struct spp_command_request { int is_requested_stop; /**< Id for stop command */ }; -/** parse error information */ -struct spp_command_parse_error { - int code; /**< Error code */ - char value_name[SPPWK_NAME_BUFSZ]; /**< Error value name */ - char value[SPPWK_VAL_BUFSZ]; /**< Error value */ +/* Error message if parse failed. */ +struct sppwk_parse_err_msg { + int code; /**< Code in enu sppwk_parse_error_code */ + char msg[SPPWK_NAME_BUFSZ]; /**< Message in short */ + char details[SPPWK_VAL_BUFSZ]; /**< Detailed message */ }; /** @@ -97,7 +97,7 @@ struct spp_command_parse_error { * @param request_str_len * The length of requested command message. * @param error - * The pointer to struct spp_command_parse_error.@n + * The pointer to struct sppwk_parse_err_msg.@n * Detailed error information will be stored. * * @retval SPP_RET_OK succeeded. @@ -105,6 +105,6 @@ struct spp_command_parse_error { */ int spp_command_parse_request(struct spp_command_request *request, const char *request_str, size_t request_str_len, - struct spp_command_parse_error *error); + struct sppwk_parse_err_msg *error); #endif /* _SPP_PCAP_CMD_PARSER_H_ */ diff --git a/src/pcap/cmd_runner.c b/src/pcap/cmd_runner.c index d5ae3a5..6ecf99d 100644 --- a/src/pcap/cmd_runner.c +++ b/src/pcap/cmd_runner.c @@ -272,31 +272,31 @@ execute_command(const struct spp_command *command) /* parse error message for response */ static const char * parse_error_message( - const struct spp_command_parse_error *parse_error, + const struct sppwk_parse_err_msg *wk_err_msg, char *message) { - switch (parse_error->code) { + switch (wk_err_msg->code) { case SPPWK_PARSE_WRONG_FORMAT: sprintf(message, "Wrong message format"); break; case SPPWK_PARSE_UNKNOWN_CMD: /* TODO(yasufum) Fix compile err if space exists before "(" */ - sprintf(message, "Unknown command(%s)", parse_error->value); + sprintf(message, "Unknown command(%s)", wk_err_msg->details); break; case SPPWK_PARSE_NO_PARAM: sprintf(message, "No or insufficient number of params (%s)", - parse_error->value_name); + wk_err_msg->msg); break; case SPPWK_PARSE_INVALID_TYPE: sprintf(message, "Invalid value type (%s)", - parse_error->value_name); + wk_err_msg->msg); break; case SPPWK_PARSE_INVALID_VALUE: - sprintf(message, "Invalid value (%s)", parse_error->value_name); + sprintf(message, "Invalid value (%s)", wk_err_msg->msg); break; default: @@ -334,22 +334,21 @@ set_command_results(struct command_result *result, static void set_parse_error_to_results(struct command_result *results, const struct spp_command_request *request, - const struct spp_command_parse_error *parse_error) + const struct sppwk_parse_err_msg *wk_err_msg) { int i; const char *tmp_buff; - char error_messege[CMD_RES_ERR_MSG_SIZE]; + char err_msg[CMD_RES_ERR_MSG_SIZE]; for (i = 0; i < request->num_command; i++) { - if (parse_error->code == 0) + if (wk_err_msg->code == 0) set_command_results(&results[i], CMD_SUCCESS, ""); else set_command_results(&results[i], CMD_INVALID, ""); } - if (parse_error->code != 0) { - tmp_buff = parse_error_message(parse_error, - error_messege); + if (wk_err_msg->code != 0) { + tmp_buff = parse_error_message(wk_err_msg, err_msg); set_command_results(&results[request->num_valid_command], CMD_FAILURE, tmp_buff); } @@ -876,11 +875,11 @@ process_request(int *sock, const char *request_str, size_t request_str_len) int i; struct spp_command_request request; - struct spp_command_parse_error parse_error; + struct sppwk_parse_err_msg parse_error; struct command_result command_results[SPPWK_MAX_CMDS]; memset(&request, 0, sizeof(struct spp_command_request)); - memset(&parse_error, 0, sizeof(struct spp_command_parse_error)); + memset(&parse_error, 0, sizeof(struct sppwk_parse_err_msg)); memset(command_results, 0, sizeof(command_results)); RTE_LOG(DEBUG, PCAP_RUNNER, "Start command request processing. " -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Rename name of enum `spp_return_value` to `sppwk_return_val`, and replace prefix of members `SPP_` with `SPPWK_` to be more specific. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/pcap/cmd_parser.c | 14 +- src/pcap/cmd_parser.h | 2 +- src/pcap/cmd_runner.c | 152 ++++++++-------- src/pcap/cmd_runner.h | 8 +- src/pcap/cmd_utils.c | 30 ++-- src/pcap/cmd_utils.h | 20 +-- src/pcap/spp_pcap.c | 170 +++++++++--------- src/pcap/spp_pcap.h | 4 +- .../secondary/spp_worker_th/cmd_utils.h | 2 +- 9 files changed, 201 insertions(+), 201 deletions(-) diff --git a/src/pcap/cmd_parser.c b/src/pcap/cmd_parser.c index 48a8bd6..4cf8059 100644 --- a/src/pcap/cmd_parser.c +++ b/src/pcap/cmd_parser.c @@ -47,14 +47,14 @@ parse_parameter_value(char *string, int max, int *argc, char *argv[]) argv_tok = strtok_r(string, delim, &saveptr); while (argv_tok != NULL) { if (cnt >= max) - return SPP_RET_NG; + return SPPWK_RET_NG; argv[cnt] = argv_tok; cnt++; argv_tok = strtok_r(NULL, delim, &saveptr); } *argc = cnt; - return SPP_RET_OK; + return SPPWK_RET_OK; } /* command list for parse */ @@ -86,7 +86,7 @@ parse_command_in_list(struct spp_command_request *request, const char *request_str, struct sppwk_parse_err_msg *wk_err_msg) { - int ret = SPP_RET_OK; + int ret = SPPWK_RET_OK; int command_name_check = 0; struct parse_command_list *list = NULL; int i = 0; @@ -99,7 +99,7 @@ parse_command_in_list(struct spp_command_request *request, strcpy(tmp_str, request_str); ret = parse_parameter_value(tmp_str, SPPWK_MAX_PARAMS, &argc, argv); - if (ret < SPP_RET_OK) { + if (ret < SPPWK_RET_OK) { RTE_LOG(ERR, PCAP_PARSER, "Parameter number over limit." "request_str=%s\n", request_str); return set_parse_error(wk_err_msg, @@ -123,7 +123,7 @@ parse_command_in_list(struct spp_command_request *request, return (*list->func)(request, argc, argv, wk_err_msg, list->param_max); - return SPP_RET_OK; + return SPPWK_RET_OK; } if (command_name_check != 0) { @@ -146,13 +146,13 @@ spp_command_parse_request( const char *request_str, size_t request_str_len, struct sppwk_parse_err_msg *wk_err_msg) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; int i; /* parse request */ request->num_command = 1; ret = parse_command_in_list(request, request_str, wk_err_msg); - if (unlikely(ret != SPP_RET_OK)) { + if (unlikely(ret != SPPWK_RET_OK)) { RTE_LOG(ERR, PCAP_PARSER, "Cannot parse command request. " "ret=%d, request_str=%.*s\n", diff --git a/src/pcap/cmd_parser.h b/src/pcap/cmd_parser.h index 9fa1b7b..88ad862 100644 --- a/src/pcap/cmd_parser.h +++ b/src/pcap/cmd_parser.h @@ -100,7 +100,7 @@ struct sppwk_parse_err_msg { * The pointer to struct sppwk_parse_err_msg.@n * Detailed error information will be stored. * - * @retval SPP_RET_OK succeeded. + * @retval SPPWK_RET_OK succeeded. * @retval !0 failed. */ int spp_command_parse_request(struct spp_command_request *request, diff --git a/src/pcap/cmd_runner.c b/src/pcap/cmd_runner.c index 6ecf99d..4d133e3 100644 --- a/src/pcap/cmd_runner.c +++ b/src/pcap/cmd_runner.c @@ -93,11 +93,11 @@ spp_iterate_core_info(struct spp_iterate_core_params *params) RTE_LOG(ERR, PCAP_RUNNER, "Cannot iterate core information. " "(core = %d)\n", lcore_id); - return SPP_RET_NG; + return SPPWK_RET_NG; } } - return SPP_RET_OK; + return SPPWK_RET_OK; } /* append a comma for JSON format */ @@ -108,10 +108,10 @@ append_json_comma(char **output) if (unlikely(*output == NULL)) { RTE_LOG(ERR, PCAP_RUNNER, "JSON's comma failed to add.\n"); - return SPP_RET_NG; + return SPPWK_RET_NG; } - return SPP_RET_OK; + return SPPWK_RET_OK; } /** @@ -129,12 +129,12 @@ append_json_uint_value(const char *name, char **output, unsigned int value) RTE_LOG(ERR, PCAP_RUNNER, "JSON's numeric format failed to add. " "(name = %s, uint = %u)\n", name, value); - return SPP_RET_NG; + return SPPWK_RET_NG; } sprintf(&(*output)[len], JSON_APPEND_VALUE("%u"), JSON_APPEND_COMMA(len), name, value); - return SPP_RET_OK; + return SPPWK_RET_OK; } /** @@ -153,12 +153,12 @@ append_json_int_value(const char *name, char **output, int value) RTE_LOG(ERR, PCAP_RUNNER, "JSON's numeric format failed to add. " "(name = %s, int = %d)\n", name, value); - return SPP_RET_NG; + return SPPWK_RET_NG; } sprintf(&(*output)[len], JSON_APPEND_VALUE("%d"), JSON_APPEND_COMMA(len), name, value); - return SPP_RET_OK; + return SPPWK_RET_OK; } /** @@ -177,12 +177,12 @@ append_json_str_value(const char *name, char **output, const char *str) RTE_LOG(ERR, PCAP_RUNNER, "JSON's string format failed to add. " "(name = %s, str = %s)\n", name, str); - return SPP_RET_NG; + return SPPWK_RET_NG; } sprintf(&(*output)[len], JSON_APPEND_VALUE("\"%s\""), JSON_APPEND_COMMA(len), name, str); - return SPP_RET_OK; + return SPPWK_RET_OK; } /** @@ -201,12 +201,12 @@ append_json_array_brackets(const char *name, char **output, const char *str) RTE_LOG(ERR, PCAP_RUNNER, "JSON's square bracket failed to add. " "(name = %s, str = %s)\n", name, str); - return SPP_RET_NG; + return SPPWK_RET_NG; } sprintf(&(*output)[len], JSON_APPEND_ARRAY, JSON_APPEND_COMMA(len), name, str); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* append brackets of the blocks for JSON format */ @@ -221,7 +221,7 @@ append_json_block_brackets(const char *name, char **output, const char *str) RTE_LOG(ERR, PCAP_RUNNER, "JSON's curly bracket failed to add. " "(name = %s, str = %s)\n", name, str); - return SPP_RET_NG; + return SPPWK_RET_NG; } if (name[0] == '\0') @@ -230,14 +230,14 @@ append_json_block_brackets(const char *name, char **output, const char *str) else sprintf(&(*output)[len], JSON_APPEND_BLOCK, JSON_APPEND_COMMA(len), name, str); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* execute one command */ static int execute_command(const struct spp_command *command) { - int ret = SPP_RET_OK; + int ret = SPPWK_RET_OK; switch (command->type) { case CMD_CLIENT_ID: @@ -366,26 +366,26 @@ append_result_value(const char *name, char **output, void *tmp) static int append_error_details_value(const char *name, char **output, void *tmp) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; const struct command_result *result = tmp; char *tmp_buff; /* string is empty, except for errors */ if (result->error_message[0] == '\0') - return SPP_RET_OK; + return SPPWK_RET_OK; tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s)\n", name); - return SPP_RET_NG; + return SPPWK_RET_NG; } ret = append_json_str_value("message", &tmp_buff, result->error_message); if (unlikely(ret < 0)) { spp_strbuf_free(tmp_buff); - return SPP_RET_NG; + return SPPWK_RET_NG; } ret = append_json_block_brackets(name, output, tmp_buff); @@ -419,19 +419,19 @@ static int append_port_entry(char **output, const struct spp_port_index *port, const enum spp_port_rxtx rxtx __attribute__ ((unused))) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; char port_str[CMD_TAG_APPEND_SIZE]; char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = port_block)\n"); - return SPP_RET_NG; + return SPPWK_RET_NG; } spp_format_port_string(port_str, port->iface_type, port->iface_no); ret = append_json_str_value("port", &tmp_buff, port_str); - if (unlikely(ret < SPP_RET_OK)) - return SPP_RET_NG; + if (unlikely(ret < SPPWK_RET_OK)) + return SPPWK_RET_NG; ret = append_json_block_brackets("", output, tmp_buff); spp_strbuf_free(tmp_buff); @@ -444,20 +444,20 @@ append_port_array(const char *name, char **output, const int num, const struct spp_port_index *ports, const enum spp_port_rxtx rxtx) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; int i = 0; char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s)\n", name); - return SPP_RET_NG; + return SPPWK_RET_NG; } for (i = 0; i < num; i++) { ret = append_port_entry(&tmp_buff, &ports[i], rxtx); - if (unlikely(ret < SPP_RET_OK)) - return SPP_RET_NG; + if (unlikely(ret < SPPWK_RET_OK)) + return SPPWK_RET_NG; } ret = append_json_array_brackets(name, output, tmp_buff); @@ -483,7 +483,7 @@ append_pcap_core_element_value( const int num_tx __attribute__ ((unused)), const struct spp_port_index *tx_ports __attribute__ ((unused))) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; int unuse_flg = 0; char *buff, *tmp_buff; buff = params->output; @@ -491,7 +491,7 @@ append_pcap_core_element_value( /* there is not necessary data when "unuse" by type */ unuse_flg = strcmp(type, "unuse"); if (!unuse_flg) - return SPP_RET_OK; + return SPPWK_RET_OK; tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { @@ -502,11 +502,11 @@ append_pcap_core_element_value( } ret = append_json_uint_value("core", &tmp_buff, lcore_id); - if (unlikely(ret < SPP_RET_OK)) + if (unlikely(ret < SPPWK_RET_OK)) return ret; ret = append_json_str_value("role", &tmp_buff, type); - if (unlikely(ret < SPP_RET_OK)) + if (unlikely(ret < SPPWK_RET_OK)) return ret; if (num_rx != 0) @@ -528,7 +528,7 @@ static int append_master_lcore_value(const char *name, char **output, void *tmp __attribute__ ((unused))) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; ret = append_json_int_value(name, output, rte_get_master_lcore()); return ret; } @@ -538,7 +538,7 @@ static int append_core_value(const char *name, char **output, void *tmp __attribute__ ((unused))) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; struct spp_iterate_core_params itr_params; char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); @@ -546,16 +546,16 @@ append_core_value(const char *name, char **output, RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s)\n", name); - return SPP_RET_NG; + return SPPWK_RET_NG; } itr_params.output = tmp_buff; itr_params.element_proc = append_pcap_core_element_value; ret = spp_iterate_core_info(&itr_params); - if (unlikely(ret != SPP_RET_OK)) { + if (unlikely(ret != SPPWK_RET_OK)) { spp_strbuf_free(itr_params.output); - return SPP_RET_NG; + return SPPWK_RET_NG; } ret = append_json_array_brackets(name, output, itr_params.output); @@ -569,25 +569,25 @@ append_response_list_value(char **output, struct command_response_list *list, void *tmp) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; int i; char *tmp_buff; tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = response_list)\n"); - return SPP_RET_NG; + return SPPWK_RET_NG; } for (i = 0; list[i].tag_name[0] != '\0'; i++) { tmp_buff[0] = '\0'; ret = list[i].func(list[i].tag_name, &tmp_buff, tmp); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(tmp_buff); RTE_LOG(ERR, PCAP_RUNNER, "Failed to get reply string. " "(tag = %s)\n", list[i].tag_name); - return SPP_RET_NG; + return SPPWK_RET_NG; } if (tmp_buff[0] == '\0') @@ -595,13 +595,13 @@ append_response_list_value(char **output, if ((*output)[0] != '\0') { ret = append_json_comma(output); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(tmp_buff); RTE_LOG(ERR, PCAP_RUNNER, "Failed to add commas. " "(tag = %s)\n", list[i].tag_name); - return SPP_RET_NG; + return SPPWK_RET_NG; } } @@ -613,12 +613,12 @@ append_response_list_value(char **output, "Failed to add reply string. " "(tag = %s)\n", list[i].tag_name); - return SPP_RET_NG; + return SPPWK_RET_NG; } } spp_strbuf_free(tmp_buff); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* termination constant of command response list */ @@ -645,7 +645,7 @@ static int append_command_results_value(const char *name, char **output, int num, struct command_result *results) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; int i; char *tmp_buff1, *tmp_buff2; tmp_buff1 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); @@ -653,7 +653,7 @@ append_command_results_value(const char *name, char **output, RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s, buff=1)\n", name); - return SPP_RET_NG; + return SPPWK_RET_NG; } tmp_buff2 = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); @@ -662,7 +662,7 @@ append_command_results_value(const char *name, char **output, RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s, buff=2)\n", name); - return SPP_RET_NG; + return SPPWK_RET_NG; } for (i = 0; i < num; i++) { @@ -672,14 +672,14 @@ append_command_results_value(const char *name, char **output, if (unlikely(ret < 0)) { spp_strbuf_free(tmp_buff1); spp_strbuf_free(tmp_buff2); - return SPP_RET_NG; + return SPPWK_RET_NG; } ret = append_json_block_brackets("", &tmp_buff2, tmp_buff1); if (unlikely(ret < 0)) { spp_strbuf_free(tmp_buff1); spp_strbuf_free(tmp_buff2); - return SPP_RET_NG; + return SPPWK_RET_NG; } } @@ -694,20 +694,20 @@ append_command_results_value(const char *name, char **output, static int append_info_value(const char *name, char **output) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; char *tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = %s)\n", name); - return SPP_RET_NG; + return SPPWK_RET_NG; } ret = append_response_list_value(&tmp_buff, response_info_list, NULL); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(tmp_buff); - return SPP_RET_NG; + return SPPWK_RET_NG; } ret = append_json_block_brackets(name, output, tmp_buff); @@ -721,7 +721,7 @@ send_parse_error_response(int *sock, const struct spp_command_request *request, struct command_result *command_results) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; char *msg, *tmp_buff; tmp_buff = spp_strbuf_allocate(CMD_RES_BUF_INIT_SIZE); if (unlikely(tmp_buff == NULL)) { @@ -733,7 +733,7 @@ send_parse_error_response(int *sock, /* create & append result array */ ret = append_command_results_value("results", &tmp_buff, request->num_command, command_results); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(tmp_buff); RTE_LOG(ERR, PCAP_RUNNER, "Failed to make command result response.\n"); @@ -749,7 +749,7 @@ send_parse_error_response(int *sock, } ret = append_json_block_brackets("", &msg, tmp_buff); spp_strbuf_free(tmp_buff); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(msg); RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = result_response)\n"); @@ -762,7 +762,7 @@ send_parse_error_response(int *sock, /* send response to requester */ ret = spp_send_message(sock, msg, strlen(msg)); - if (unlikely(ret != SPP_RET_OK)) { + if (unlikely(ret != SPPWK_RET_OK)) { RTE_LOG(ERR, PCAP_RUNNER, "Failed to send parse error response.\n"); /* not return */ @@ -777,7 +777,7 @@ send_command_result_response(int *sock, const struct spp_command_request *request, struct command_result *command_results) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; char *msg, *tmp_buff; int *capture_request = NULL; @@ -791,7 +791,7 @@ send_command_result_response(int *sock, /* create & append result array */ ret = append_command_results_value("results", &tmp_buff, request->num_command, command_results); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(tmp_buff); RTE_LOG(ERR, PCAP_RUNNER, "Failed to make command result response.\n"); @@ -801,7 +801,7 @@ send_command_result_response(int *sock, /* append client id information value */ if (request->is_requested_client_id) { ret = append_client_id_value("client_id", &tmp_buff, NULL); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(tmp_buff); RTE_LOG(ERR, PCAP_RUNNER, "Failed to make " "client id response.\n"); @@ -814,7 +814,7 @@ send_command_result_response(int *sock, /* append info value */ if (request->is_requested_status) { ret = append_info_value("info", &tmp_buff); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(tmp_buff); RTE_LOG(ERR, PCAP_RUNNER, "Failed to make status response.\n"); @@ -845,7 +845,7 @@ send_command_result_response(int *sock, } ret = append_json_block_brackets("", &msg, tmp_buff); spp_strbuf_free(tmp_buff); - if (unlikely(ret < SPP_RET_OK)) { + if (unlikely(ret < SPPWK_RET_OK)) { spp_strbuf_free(msg); RTE_LOG(ERR, PCAP_RUNNER, "allocate error. (name = result_response)\n"); @@ -858,7 +858,7 @@ send_command_result_response(int *sock, /* send response to requester */ ret = spp_send_message(sock, msg, strlen(msg)); - if (unlikely(ret != SPP_RET_OK)) { + if (unlikely(ret != SPPWK_RET_OK)) { RTE_LOG(ERR, PCAP_RUNNER, "Failed to send command result response.\n"); /* not return */ @@ -871,7 +871,7 @@ send_command_result_response(int *sock, static int process_request(int *sock, const char *request_str, size_t request_str_len) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; int i; struct spp_command_request request; @@ -889,14 +889,14 @@ process_request(int *sock, const char *request_str, size_t request_str_len) /* parse request message */ ret = spp_command_parse_request( &request, request_str, request_str_len, &parse_error); - if (unlikely(ret != SPP_RET_OK)) { + if (unlikely(ret != SPPWK_RET_OK)) { /* send error response */ set_parse_error_to_results(command_results, &request, &parse_error); send_parse_error_response(sock, &request, command_results); RTE_LOG(DEBUG, PCAP_RUNNER, "End command request processing.\n"); - return SPP_RET_OK; + return SPPWK_RET_OK; } RTE_LOG(DEBUG, PCAP_RUNNER, "Command request is valid. " @@ -906,7 +906,7 @@ process_request(int *sock, const char *request_str, size_t request_str_len) /* execute commands */ for (i = 0; i < request.num_command ; ++i) { ret = execute_command(request.commands + i); - if (unlikely(ret != SPP_RET_OK)) { + if (unlikely(ret != SPPWK_RET_OK)) { set_command_results(&command_results[i], CMD_FAILURE, "error occur"); @@ -928,7 +928,7 @@ process_request(int *sock, const char *request_str, size_t request_str_len) send_command_result_response(sock, &request, command_results); RTE_LOG(INFO, PCAP_RUNNER, "Terminate process for exit.\n"); - return SPP_RET_NG; + return SPPWK_RET_NG; } /* send response */ @@ -936,7 +936,7 @@ process_request(int *sock, const char *request_str, size_t request_str_len) RTE_LOG(DEBUG, PCAP_RUNNER, "End command request processing.\n"); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* initialize command processor. */ @@ -950,7 +950,7 @@ spp_command_proc_init(const char *controller_ip, int controller_port) int spp_command_proc_do(void) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; int msg_ret = -1; static int sock = -1; @@ -962,22 +962,22 @@ spp_command_proc_do(void) RTE_LOG(ERR, PCAP_RUNNER, "Cannot allocate memory " "for receive data(init).\n"); - return SPP_RET_NG; + return SPPWK_RET_NG; } } ret = spp_connect_to_controller(&sock); - if (unlikely(ret != SPP_RET_OK)) - return SPP_RET_OK; + if (unlikely(ret != SPPWK_RET_OK)) + return SPPWK_RET_OK; msg_ret = spp_receive_message(&sock, &msgbuf); if (unlikely(msg_ret <= 0)) { if (likely(msg_ret == 0)) - return SPP_RET_OK; + return SPPWK_RET_OK; else if (unlikely(msg_ret == SPP_CONNERR_TEMPORARY)) - return SPP_RET_OK; + return SPPWK_RET_OK; else - return SPP_RET_NG; + return SPPWK_RET_NG; } ret = process_request(&sock, msgbuf, msg_ret); diff --git a/src/pcap/cmd_runner.h b/src/pcap/cmd_runner.h index ccae164..0e53081 100644 --- a/src/pcap/cmd_runner.h +++ b/src/pcap/cmd_runner.h @@ -23,8 +23,8 @@ * @param controller_port * The controller's port number. * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @retval SPPWK_RET_OK succeeded. + * @retval SPPWK_RET_NG failed. */ int spp_command_proc_init(const char *controller_ip, int controller_port); @@ -32,8 +32,8 @@ spp_command_proc_init(const char *controller_ip, int controller_port); /** * process command from controller. * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG process termination is required. + * @retval SPPWK_RET_OK succeeded. + * @retval SPPWK_RET_NG process termination is required. * (occurred connection failure, or received exit command) */ int diff --git a/src/pcap/cmd_utils.c b/src/pcap/cmd_utils.c index f425ed0..05f9da1 100644 --- a/src/pcap/cmd_utils.c +++ b/src/pcap/cmd_utils.c @@ -40,7 +40,7 @@ add_ring_pmd(int ring_id) if (unlikely(ring == NULL)) { RTE_LOG(ERR, PCAP_UTILS, "Cannot get RX ring - is server process running?\n"); - return SPP_RET_NG; + return SPPWK_RET_NG; } /* Create ring pmd */ @@ -52,7 +52,7 @@ add_ring_pmd(int ring_id) if (ring_port_id < 0) { RTE_LOG(ERR, PCAP_UTILS, "Cannot create eth dev with " "rte_eth_from_ring()\n"); - return SPP_RET_NG; + return SPPWK_RET_NG; } } else { ring_port_id = port_id; @@ -73,7 +73,7 @@ spp_get_core_status(unsigned int lcore_id) /** * Check status of all of cores is same as given * - * It returns SPP_RET_NG as status mismatch if status is not same. + * It returns SPPWK_RET_NG as status mismatch if status is not same. * If core is in use, status will be checked. */ static int @@ -84,10 +84,10 @@ check_core_status(enum sppwk_lcore_status status) if ((g_mng_data_addr.p_core_info + lcore_id)->status != status) { /* Status is mismatched */ - return SPP_RET_NG; + return SPPWK_RET_NG; } } - return SPP_RET_OK; + return SPPWK_RET_OK; } int @@ -98,12 +98,12 @@ check_core_status_wait(enum sppwk_lcore_status status) sleep(1); int ret = check_core_status(status); if (ret == 0) - return SPP_RET_OK; + return SPPWK_RET_OK; } RTE_LOG(ERR, PCAP_UTILS, "Status check time out. (status = %d)\n", status); - return SPP_RET_NG; + return SPPWK_RET_NG; } /* Set core status */ @@ -215,7 +215,7 @@ set_nic_interface(void) p_iface_info->nic[nic_cnt].dpdk_port = nic_cnt; } - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Setup management info for spp_pcap */ @@ -227,10 +227,10 @@ init_mng_data(void) init_core_info(); int ret_nic = set_nic_interface(); - if (unlikely(ret_nic != SPP_RET_OK)) - return SPP_RET_NG; + if (unlikely(ret_nic != SPPWK_RET_OK)) + return SPPWK_RET_NG; - return SPP_RET_OK; + return SPPWK_RET_OK; } /** @@ -249,12 +249,12 @@ int spp_format_port_string(char *port, enum port_type iface_type, int iface_no) iface_type_str = SPP_IFTYPE_RING_STR; break; default: - return SPP_RET_NG; + return SPPWK_RET_NG; } sprintf(port, "%s:%d", iface_type_str, iface_no); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Set mange data address */ @@ -270,7 +270,7 @@ int spp_set_mng_data_addr(struct startup_param *startup_param_addr, capture_request_addr == NULL || capture_status_addr == NULL || main_lcore_id == 0xffffffff) - return SPP_RET_NG; + return SPPWK_RET_NG; g_mng_data_addr.p_startup_param = startup_param_addr; g_mng_data_addr.p_iface_info = iface_addr; @@ -279,7 +279,7 @@ int spp_set_mng_data_addr(struct startup_param *startup_param_addr, g_mng_data_addr.p_capture_status = capture_status_addr; g_mng_data_addr.main_lcore_id = main_lcore_id; - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Get manage data address */ diff --git a/src/pcap/cmd_utils.h b/src/pcap/cmd_utils.h index 8cebf2d..2bd1100 100644 --- a/src/pcap/cmd_utils.h +++ b/src/pcap/cmd_utils.h @@ -49,14 +49,14 @@ enum sppwk_lcore_status { }; /* State on capture */ -enum spp_capture_status { +enum sppwk_capture_status { SPP_CAPTURE_IDLE, /* Idling */ SPP_CAPTURE_RUNNING /* Running */ }; -enum spp_return_value { - SPP_RET_OK = 0, /**< succeeded */ - SPP_RET_NG = -1, /**< failed */ +enum sppwk_return_val { + SPPWK_RET_OK = 0, /**< succeeded */ + SPPWK_RET_NG = -1, /**< failed */ }; /** @@ -325,8 +325,8 @@ struct core_info *get_core_info(unsigned int lcore_id); * @param iface_no * interface no * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @retval SPPWK_RET_OK succeeded. + * @retval SPPWK_RET_NG failed. */ int spp_format_port_string(char *port, enum port_type iface_type, int iface_no); @@ -341,8 +341,8 @@ spp_format_port_string(char *port, enum port_type iface_type, int iface_no); * @param iface_no * interface no * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @retval SPPWK_RET_OK succeeded. + * @retval SPPWK_RET_NG failed. */ int spp_format_port_string(char *port, enum port_type iface_type, int iface_no); @@ -363,8 +363,8 @@ spp_format_port_string(char *port, enum port_type iface_type, int iface_no); * @param main_lcore_id * main_lcore_id mask * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @retval SPPWK_RET_OK succeeded. + * @retval SPPWK_RET_NG failed. */ int spp_set_mng_data_addr(struct startup_param *startup_param_addr, struct iface_info *iface_addr, diff --git a/src/pcap/spp_pcap.c b/src/pcap/spp_pcap.c index b48caf4..2aad0ad 100644 --- a/src/pcap/spp_pcap.c +++ b/src/pcap/spp_pcap.c @@ -124,16 +124,16 @@ struct pcap_option { * (e.g. worker thread type, file number, pointer to writing file etc) per core */ struct pcap_mng_info { - volatile enum worker_thread_type type; /* thread type */ - enum spp_capture_status status; /* thread status */ - int thread_no; /* thread no */ - int file_no; /* file no */ - char compress_file_name[PCAP_FNAME_STRLEN]; /* lz4 file name */ - LZ4F_compressionContext_t ctx; /* lz4 file Ccontext */ - FILE *compress_fp; /* lzf file pointer */ - size_t outbuf_capacity; /* compress date buffer size */ - void *outbuff; /* compress date buffer */ - uint64_t file_size; /* file write size */ + volatile enum worker_thread_type type; /* thread type */ + enum sppwk_capture_status status; /* ideling or running */ + int thread_no; /* thread no */ + int file_no; /* file no */ + char compress_file_name[PCAP_FNAME_STRLEN]; /* lz4 file name */ + LZ4F_compressionContext_t ctx; /* lz4 file Ccontext */ + FILE *compress_fp; /* lzf file pointer */ + size_t outbuf_capacity; /* compress date buffer size */ + void *outbuff; /* compress date buffer */ + uint64_t file_size; /* file write size */ }; /* Pcap status info. */ @@ -191,8 +191,8 @@ usage(const char *progname) } /** - * Convert string type of client ID to integer and return SPP_RET_OK, or - * SPP_RET_NG if failed. + * Convert string type of client ID to integer and return SPPWK_RET_OK, or + * SPPWK_RET_NG if failed. */ static int client_id_toi(const char *client_id_str, int *client_id) @@ -202,14 +202,14 @@ client_id_toi(const char *client_id_str, int *client_id) id = strtol(client_id_str, &endptr, 0); if (unlikely(client_id_str == endptr) || unlikely(*endptr != '\0')) - return SPP_RET_NG; + return SPPWK_RET_NG; if (id >= RTE_MAX_LCORE) - return SPP_RET_NG; + return SPPWK_RET_NG; *client_id = id; RTE_LOG(DEBUG, SPP_PCAP, "Set client id = %d\n", *client_id); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Parse options for server IP and port */ @@ -223,18 +223,18 @@ parse_server_ip(const char *server_str, char *server_ip, int *server_port) pos = strcspn(server_str, delim); if (pos >= strlen(server_str)) - return SPP_RET_NG; + return SPPWK_RET_NG; port = strtol(&server_str[pos+1], &endptr, 0); if (unlikely(&server_str[pos+1] == endptr) || unlikely(*endptr != '\0')) - return SPP_RET_NG; + return SPPWK_RET_NG; memcpy(server_ip, server_str, pos); server_ip[pos] = '\0'; *server_port = port; RTE_LOG(DEBUG, SPP_PCAP, "Set server IP = %s\n", server_ip); RTE_LOG(DEBUG, SPP_PCAP, "Set server port = %d\n", *server_port); - return SPP_RET_OK; + return SPPWK_RET_OK; } @@ -247,11 +247,11 @@ parse_fsize(const char *fsize_str, uint64_t *fsize) fs = strtoull(fsize_str, &endptr, 10); if (unlikely(fsize_str == endptr) || unlikely(*endptr != '\0')) - return SPP_RET_NG; + return SPPWK_RET_NG; *fsize = fs; RTE_LOG(DEBUG, SPP_PCAP, "Set fzise = %ld\n", *fsize); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Parse `-c` option for captured port and get the port type and ID */ @@ -278,7 +278,7 @@ parse_captured_port(const char *port_str, enum port_type *iface_type, /* OTHER */ RTE_LOG(ERR, SPP_PCAP, "The interface that does not suppor. " "(port = %s)\n", port_str); - return SPP_RET_NG; + return SPPWK_RET_NG; } /* Convert from string to number */ @@ -287,7 +287,7 @@ parse_captured_port(const char *port_str, enum port_type *iface_type, /* No IF number */ RTE_LOG(ERR, SPP_PCAP, "No interface number. (port = %s)\n", port_str); - return SPP_RET_NG; + return SPPWK_RET_NG; } *iface_type = type; @@ -295,7 +295,7 @@ parse_captured_port(const char *port_str, enum port_type *iface_type, RTE_LOG(DEBUG, SPP_PCAP, "Port = %s => Type = %d No = %d\n", port_str, *iface_type, *iface_no); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Parse options for client app */ @@ -344,9 +344,9 @@ parse_args(int argc, char *argv[]) case SPP_LONGOPT_RETVAL_CLIENT_ID: if (client_id_toi(optarg, &g_startup_param.client_id) != - SPP_RET_OK) { + SPPWK_RET_OK) { usage(progname); - return SPP_RET_NG; + return SPPWK_RET_NG; } proc_flg = 1; break; @@ -356,14 +356,14 @@ parse_args(int argc, char *argv[]) if (g_pcap_option.compress_file_path[0] == '\0' || stat(optarg, &statBuf) != 0) { usage(progname); - return SPP_RET_NG; + return SPPWK_RET_NG; } break; case SPP_LONGOPT_RETVAL_FILE_SIZE: if (parse_fsize(optarg, &g_pcap_option.fsize_limit) != - SPP_RET_OK) { + SPPWK_RET_OK) { usage(progname); - return SPP_RET_NG; + return SPPWK_RET_NG; } break; case 'c': /* captured port */ @@ -371,31 +371,31 @@ parse_args(int argc, char *argv[]) if (parse_captured_port(optarg, &g_pcap_option.port_cap.iface_type, &g_pcap_option.port_cap.iface_no) != - SPP_RET_OK) { + SPPWK_RET_OK) { usage(progname); - return SPP_RET_NG; + return SPPWK_RET_NG; } port_flg = 1; break; case 's': /* server addr */ if (parse_server_ip(optarg, g_startup_param.server_ip, &g_startup_param.server_port) != - SPP_RET_OK) { + SPPWK_RET_OK) { usage(progname); - return SPP_RET_NG; + return SPPWK_RET_NG; } server_flg = 1; break; default: usage(progname); - return SPP_RET_NG; + return SPPWK_RET_NG; } } /* Check mandatory parameters */ if ((proc_flg == 0) || (server_flg == 0) || (port_flg == 0)) { usage(progname); - return SPP_RET_NG; + return SPPWK_RET_NG; } RTE_LOG(INFO, SPP_PCAP, @@ -407,7 +407,7 @@ parse_args(int argc, char *argv[]) port_str, g_pcap_option.compress_file_path, g_pcap_option.fsize_limit); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Pcap get core status */ @@ -416,7 +416,7 @@ spp_pcap_get_core_status( unsigned int lcore_id, struct spp_iterate_core_params *params) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; char role_type[8]; struct pcap_mng_info *info = &g_pcap_info[lcore_id]; char name[PCAP_FPATH_STRLEN + PCAP_FDATE_STRLEN]; @@ -447,9 +447,9 @@ spp_pcap_get_core_status( name, role_type, rx_num, rx_ports, 0, NULL); if (unlikely(ret != 0)) - return SPP_RET_NG; + return SPPWK_RET_NG; - return SPP_RET_OK; + return SPPWK_RET_OK; } /* write compressed data into file */ @@ -458,14 +458,14 @@ static int output_pcap_file(FILE *compress_fp, void *srcbuf, size_t write_len) size_t write_size; if (write_len == 0) - return SPP_RET_OK; + return SPPWK_RET_OK; write_size = fwrite(srcbuf, write_len, 1, compress_fp); if (write_size != 1) { RTE_LOG(ERR, SPP_PCAP, "file write error len=%lu\n", write_len); - return SPP_RET_NG; + return SPPWK_RET_NG; } - return SPP_RET_OK; + return SPPWK_RET_OK; } /* compress data & write file */ @@ -480,14 +480,14 @@ static int output_lz4_pcap_file(struct pcap_mng_info *info, if (LZ4F_isError(compress_len)) { RTE_LOG(ERR, SPP_PCAP, "Compression failed: error %zd\n", compress_len); - return SPP_RET_NG; + return SPPWK_RET_NG; } RTE_LOG(DEBUG, SPP_PCAP, "src len=%d\n", src_len); if (output_pcap_file(info->compress_fp, info->outbuff, compress_len) != 0) - return SPP_RET_NG; + return SPPWK_RET_NG; - return SPP_RET_OK; + return SPPWK_RET_OK; } /** @@ -538,14 +538,14 @@ static int file_compression_operation(struct pcap_mng_info *info, fclose(info->compress_fp); info->compress_fp = NULL; free(info->outbuff); - return SPP_RET_NG; + return SPPWK_RET_NG; } if (output_pcap_file(info->compress_fp, info->outbuff, - compress_len) != SPP_RET_OK) { + compress_len) != SPPWK_RET_OK) { fclose(info->compress_fp); info->compress_fp = NULL; free(info->outbuff); - return SPP_RET_NG; + return SPPWK_RET_NG; } /* flush remained data */ @@ -585,7 +585,7 @@ static int file_compression_operation(struct pcap_mng_info *info, } else { /* close mode */ /* Close temporary file and rename to persistent */ if (info->compress_fp == NULL) - return SPP_RET_OK; + return SPPWK_RET_OK; compress_len = LZ4F_compressEnd(info->ctx, info->outbuff, info->outbuf_capacity, NULL); if (LZ4F_isError(compress_len)) { @@ -616,7 +616,7 @@ static int file_compression_operation(struct pcap_mng_info *info, info->compress_fp = NULL; free(info->outbuff); - return SPP_RET_OK; + return SPPWK_RET_OK; } /* file open */ @@ -632,7 +632,7 @@ static int file_compression_operation(struct pcap_mng_info *info, RTE_LOG(ERR, SPP_PCAP, "file open error! filename=%s\n", info->compress_file_name); free(info->outbuff); - return SPP_RET_NG; + return SPPWK_RET_NG; } /* init lz4 stream */ @@ -643,7 +643,7 @@ static int file_compression_operation(struct pcap_mng_info *info, fclose(info->compress_fp); info->compress_fp = NULL; free(info->outbuff); - return SPP_RET_NG; + return SPPWK_RET_NG; } /* write compress frame header */ @@ -655,7 +655,7 @@ static int file_compression_operation(struct pcap_mng_info *info, fclose(info->compress_fp); info->compress_fp = NULL; free(info->outbuff); - return SPP_RET_NG; + return SPPWK_RET_NG; } RTE_LOG(DEBUG, SPP_PCAP, "Buffer size is %zd bytes, header size %zd " "bytes\n", info->outbuf_capacity, headerSize); @@ -664,7 +664,7 @@ static int file_compression_operation(struct pcap_mng_info *info, fclose(info->compress_fp); info->compress_fp = NULL; free(info->outbuff); - return SPP_RET_NG; + return SPPWK_RET_NG; } info->file_size = headerSize; @@ -679,15 +679,15 @@ static int file_compression_operation(struct pcap_mng_info *info, /* pcap header write */ if (output_lz4_pcap_file(info, &pcap_h, sizeof(struct pcap_header)) - != SPP_RET_OK) { + != SPPWK_RET_OK) { RTE_LOG(ERR, SPP_PCAP, "pcap header write error!\n"); fclose(info->compress_fp); info->compress_fp = NULL; free(info->outbuff); - return SPP_RET_NG; + return SPPWK_RET_NG; } - return SPP_RET_OK; + return SPPWK_RET_OK; } /* compress packet data */ @@ -702,13 +702,13 @@ static int compress_file_packet(struct pcap_mng_info *info, int bytes_to_write; if (info->compress_fp == NULL) - return SPP_RET_OK; + return SPPWK_RET_OK; /* capture file rool */ if (info->file_size > g_pcap_option.fsize_limit) { if (file_compression_operation(info, UPDATE_MODE) - != SPP_RET_OK) - return SPP_RET_NG; + != SPPWK_RET_OK) + return SPPWK_RET_NG; } /* cast to packet */ @@ -729,9 +729,9 @@ static int compress_file_packet(struct pcap_mng_info *info, /* output to lz4_pcap_file */ if (output_lz4_pcap_file(info, &pcap_packet_h.ts_sec, - sizeof(struct pcap_packet_header)) != SPP_RET_OK) { + sizeof(struct pcap_packet_header)) != SPPWK_RET_OK) { file_compression_operation(info, CLOSE_MODE); - return SPP_RET_NG; + return SPPWK_RET_NG; } info->file_size += sizeof(struct pcap_packet_header); @@ -748,14 +748,14 @@ static int compress_file_packet(struct pcap_mng_info *info, rte_pktmbuf_mtod(cap_pkt, void*), bytes_to_write) != 0) { file_compression_operation(info, CLOSE_MODE); - return SPP_RET_NG; + return SPPWK_RET_NG; } cap_pkt = cap_pkt->next; remaining_bytes -= bytes_to_write; info->file_size += bytes_to_write; } - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Receive packets from shared ring buffer */ @@ -788,7 +788,7 @@ static int pcap_proc_receive(int lcore_id) if (g_pcap_thread_info.start_up_cnt != 0) g_pcap_thread_info.start_up_cnt -= 1; } - return SPP_RET_OK; + return SPPWK_RET_OK; } if (info->status == SPP_CAPTURE_IDLE) { /* Get time for output file name */ @@ -812,13 +812,13 @@ static int pcap_proc_receive(int lcore_id) /* Write thread start up wait. */ if (g_pcap_thread_info.thread_cnt > g_pcap_thread_info.start_up_cnt) - return SPP_RET_OK; + return SPPWK_RET_OK; /* Receive packets */ rx = &g_pcap_option.port_cap; nb_rx = spp_eth_rx_burst(rx->dpdk_port, 0, bufs, MAX_PCAP_BURST); if (unlikely(nb_rx == 0)) - return SPP_RET_OK; + return SPPWK_RET_OK; /* Forward to ring for writer thread */ nb_tx = rte_ring_enqueue_burst(write_ring, (void *)bufs, nb_rx, NULL); @@ -834,13 +834,13 @@ static int pcap_proc_receive(int lcore_id) total_rx += nb_rx; total_drop += nb_rx - nb_tx; - return SPP_RET_OK; + return SPPWK_RET_OK; } /* Output packets to file on writer thread */ static int pcap_proc_write(int lcore_id) { - int ret = SPP_RET_OK; + int ret = SPPWK_RET_OK; int buf; int nb_rx = 0; struct rte_mbuf *bufs[MAX_PCAP_BURST]; @@ -850,15 +850,15 @@ static int pcap_proc_write(int lcore_id) if (g_capture_status == SPP_CAPTURE_IDLE) { if (info->status == SPP_CAPTURE_IDLE) - return SPP_RET_OK; + return SPPWK_RET_OK; } if (info->status == SPP_CAPTURE_IDLE) { RTE_LOG(DEBUG, SPP_PCAP, "write[%d] idle->run\n", lcore_id); info->status = SPP_CAPTURE_RUNNING; if (file_compression_operation(info, INIT_MODE) - != SPP_RET_OK) { + != SPPWK_RET_OK) { info->status = SPP_CAPTURE_IDLE; - return SPP_RET_NG; + return SPPWK_RET_NG; } g_pcap_thread_info.start_up_cnt += 1; g_total_write[lcore_id] = 0; @@ -880,22 +880,22 @@ static int pcap_proc_write(int lcore_id) if (g_pcap_thread_info.start_up_cnt != 0) g_pcap_thread_info.start_up_cnt -= 1; if (file_compression_operation(info, CLOSE_MODE) - != SPP_RET_OK) - return SPP_RET_NG; + != SPPWK_RET_OK) + return SPPWK_RET_NG; } - return SPP_RET_OK; + return SPPWK_RET_OK; } for (buf = 0; buf < nb_rx; buf++) { mbuf = bufs[buf]; rte_prefetch0(rte_pktmbuf_mtod(mbuf, void *)); if (compress_file_packet(&g_pcap_info[lcore_id], mbuf) - != SPP_RET_OK) { + != SPPWK_RET_OK) { RTE_LOG(ERR, SPP_PCAP, "Failed compress_file_packet(), " "errno=%d (%s)\n", errno, strerror(errno)); - ret = SPP_RET_NG; + ret = SPPWK_RET_NG; info->status = SPP_CAPTURE_IDLE; file_compression_operation(info, CLOSE_MODE); break; @@ -914,7 +914,7 @@ static int pcap_proc_write(int lcore_id) static int slave_main(void *arg __attribute__ ((unused))) { - int ret = SPP_RET_OK; + int ret = SPPWK_RET_OK; unsigned int lcore_id = rte_lcore_id(); struct pcap_mng_info *pcap_info = &g_pcap_info[lcore_id]; @@ -940,7 +940,7 @@ slave_main(void *arg __attribute__ ((unused))) ret = pcap_proc_receive(lcore_id); else ret = pcap_proc_write(lcore_id); - if (unlikely(ret != SPP_RET_OK)) { + if (unlikely(ret != SPPWK_RET_OK)) { RTE_LOG(ERR, SPP_PCAP, "Core[%d] Thread Error.\n", lcore_id); break; @@ -955,12 +955,12 @@ slave_main(void *arg __attribute__ ((unused))) /** * Main function * - * Return SPP_RET_NG explicitly if error is occurred. + * Return SPPWK_RET_NG explicitly if error is occurred. */ int main(int argc, char *argv[]) { - int ret = SPP_RET_NG; + int ret = SPPWK_RET_NG; #ifdef SPP_DEMONIZE /* Daemonize process */ int ret_daemon = daemon(0, 0); @@ -1013,7 +1013,7 @@ main(int argc, char *argv[]) int ret_command_init = spp_command_proc_init( g_startup_param.server_ip, g_startup_param.server_port); - if (unlikely(ret_command_init != SPP_RET_OK)) + if (unlikely(ret_command_init != SPPWK_RET_OK)) break; /* capture port setup */ @@ -1037,7 +1037,7 @@ main(int argc, char *argv[]) } else { if (port_info->iface_type == UNDEF) { ret = add_ring_pmd(port_info->iface_no); - if (ret == SPP_RET_NG) { + if (ret == SPPWK_RET_NG) { RTE_LOG(ERR, SPP_PCAP, "caputre port " "undefined.(ring:%d)\n", port_cap->iface_no); @@ -1100,7 +1100,7 @@ main(int argc, char *argv[]) SPP_CORE_STOP_REQUEST)) { /* Receive command */ ret_do = spp_command_proc_do(); - if (unlikely(ret_do != SPP_RET_OK)) + if (unlikely(ret_do != SPPWK_RET_OK)) break; /* @@ -1109,12 +1109,12 @@ main(int argc, char *argv[]) usleep(100); } - if (unlikely(ret_do != SPP_RET_OK)) { + if (unlikely(ret_do != SPPWK_RET_OK)) { set_all_core_status(SPP_CORE_STOP_REQUEST); break; } - ret = SPP_RET_OK; + ret = SPPWK_RET_OK; break; } diff --git a/src/pcap/spp_pcap.h b/src/pcap/spp_pcap.h index 6a4ded7..bf2eec1 100644 --- a/src/pcap/spp_pcap.h +++ b/src/pcap/spp_pcap.h @@ -25,8 +25,8 @@ * The pointer to struct spp_iterate_core_params.@n * Detailed data of pcap status. * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @retval SPPWK_RET_OK succeeded. + * @retval SPPWK_RET_NG failed. */ int spp_pcap_get_core_status( unsigned int lcore_id, diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.h b/src/shared/secondary/spp_worker_th/cmd_utils.h index b1febe9..7a31da6 100644 --- a/src/shared/secondary/spp_worker_th/cmd_utils.h +++ b/src/shared/secondary/spp_worker_th/cmd_utils.h @@ -102,7 +102,7 @@ enum spp_classifier_type { SPP_CLASSIFIER_TYPE_VLAN /**< VLAN ID */ }; -enum spp_return_value { +enum sppwk_return_val { SPP_RET_OK = 0, /**< succeeded */ SPP_RET_NG = -1, /**< failed */ }; -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This update is to rename struct `spp_port_info` to `sppwk_port_info` to be more specific, and its member `dpdk_port` to `ethdev_port_id` correctly. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/pcap/cmd_utils.c | 8 ++++---- src/pcap/cmd_utils.h | 18 +++++++++--------- src/pcap/spp_pcap.c | 17 +++++++++-------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/pcap/cmd_utils.c b/src/pcap/cmd_utils.c index 05f9da1..08e4c98 100644 --- a/src/pcap/cmd_utils.c +++ b/src/pcap/cmd_utils.c @@ -146,7 +146,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; @@ -175,12 +175,12 @@ init_iface_info(void) 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].ethdev_port_id = -1; p_iface_info->nic[port_cnt].class_id.vlantag.vid = 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].ethdev_port_id = -1; p_iface_info->ring[port_cnt].class_id.vlantag.vid = ETH_VLAN_ID_MAX; } @@ -212,7 +212,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 SPPWK_RET_OK; diff --git a/src/pcap/cmd_utils.h b/src/pcap/cmd_utils.h index 2bd1100..862eb27 100644 --- a/src/pcap/cmd_utils.h +++ b/src/pcap/cmd_utils.h @@ -139,11 +139,11 @@ 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 */ +/* Define detailed port params in addition to `sppwk_port_idx`. */ +struct sppwk_port_info { + enum port_type iface_type; /**< phy, vhost or ring */ + int iface_no; + int ethdev_port_id; /**< Consistent ID of ethdev */ struct spp_port_class_identifier class_id; /**< Port class identifier */ struct spp_port_ability ability[SPP_PORT_ABILITY_MAX]; @@ -175,9 +175,9 @@ struct startup_param { struct iface_info { int num_nic; /* The number of phy */ 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 ring[RTE_MAX_ETHPORTS]; + struct sppwk_port_info ring[RTE_MAX_ETHPORTS]; /* Port information of ring */ }; @@ -289,10 +289,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); /** diff --git a/src/pcap/spp_pcap.c b/src/pcap/spp_pcap.c index 2aad0ad..ee89b0a 100644 --- a/src/pcap/spp_pcap.c +++ b/src/pcap/spp_pcap.c @@ -115,7 +115,7 @@ struct pcap_option { uint64_t fsize_limit; /* file size limit */ char compress_file_path[PCAP_FPATH_STRLEN]; /* file path */ char compress_file_date[PCAP_FDATE_STRLEN]; /* file name date */ - struct spp_port_info port_cap; /* capture port */ + struct sppwk_port_info port_cap; /* capture port */ struct rte_ring *cap_ring; /* RTE ring structure */ }; @@ -766,7 +766,7 @@ static int pcap_proc_receive(int lcore_id) int buf; int nb_rx = 0; int nb_tx = 0; - struct spp_port_info *rx; + struct sppwk_port_info *rx; struct rte_mbuf *bufs[MAX_PCAP_BURST]; struct pcap_mng_info *info = &g_pcap_info[lcore_id]; struct rte_ring *write_ring = g_pcap_option.cap_ring; @@ -816,7 +816,7 @@ static int pcap_proc_receive(int lcore_id) /* Receive packets */ rx = &g_pcap_option.port_cap; - nb_rx = spp_eth_rx_burst(rx->dpdk_port, 0, bufs, MAX_PCAP_BURST); + nb_rx = spp_eth_rx_burst(rx->ethdev_port_id, 0, bufs, MAX_PCAP_BURST); if (unlikely(nb_rx == 0)) return SPPWK_RET_OK; @@ -1017,8 +1017,8 @@ main(int argc, char *argv[]) break; /* capture port setup */ - struct spp_port_info *port_cap = &g_pcap_option.port_cap; - struct spp_port_info *port_info = get_iface_info( + struct sppwk_port_info *port_cap = &g_pcap_option.port_cap; + struct sppwk_port_info *port_info = get_iface_info( port_cap->iface_type, port_cap->iface_no); if (port_info == NULL) { @@ -1027,7 +1027,8 @@ main(int argc, char *argv[]) } if (port_cap->iface_type == PHY) { if (port_info->iface_type != UNDEF) - port_cap->dpdk_port = port_info->dpdk_port; + port_cap->ethdev_port_id = + port_info->ethdev_port_id; else { RTE_LOG(ERR, SPP_PCAP, "caputre port undefined.(phy:%d)\n", @@ -1043,7 +1044,7 @@ main(int argc, char *argv[]) port_cap->iface_no); break; } - port_cap->dpdk_port = ret; + port_cap->ethdev_port_id = ret; } else { RTE_LOG(ERR, SPP_PCAP, "caputre port " "undefined.(ring:%d)\n", @@ -1054,7 +1055,7 @@ main(int argc, char *argv[]) RTE_LOG(DEBUG, SPP_PCAP, "Recv port type=%d, no=%d, port_id=%d\n", port_cap->iface_type, port_cap->iface_no, - port_cap->dpdk_port); + port_cap->ethdev_port_id); /* create ring */ char ring_name[PORT_STR_SIZE]; -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> Rename struct `spp_port_index` to `sppwk_port_idx` to be more specific, and its members. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/pcap/cmd_runner.c | 8 ++++---- src/pcap/cmd_utils.c | 4 ++-- src/pcap/cmd_utils.h | 31 +++++++++++++++---------------- src/pcap/spp_pcap.c | 2 +- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/pcap/cmd_runner.c b/src/pcap/cmd_runner.c index 4d133e3..a931956 100644 --- a/src/pcap/cmd_runner.c +++ b/src/pcap/cmd_runner.c @@ -416,7 +416,7 @@ append_client_id_value(const char *name, char **output, /* append a block of port entry for JSON format */ static int -append_port_entry(char **output, const struct spp_port_index *port, +append_port_entry(char **output, const struct sppwk_port_idx *port, const enum spp_port_rxtx rxtx __attribute__ ((unused))) { int ret = SPPWK_RET_NG; @@ -441,7 +441,7 @@ append_port_entry(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 = SPPWK_RET_NG; @@ -479,9 +479,9 @@ append_pcap_core_element_value( const unsigned int lcore_id, 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 __attribute__ ((unused)), - const struct spp_port_index *tx_ports __attribute__ ((unused))) + const struct sppwk_port_idx *tx_ports __attribute__ ((unused))) { int ret = SPPWK_RET_NG; int unuse_flg = 0; diff --git a/src/pcap/cmd_utils.c b/src/pcap/cmd_utils.c index 08e4c98..084b3ca 100644 --- a/src/pcap/cmd_utils.c +++ b/src/pcap/cmd_utils.c @@ -176,12 +176,12 @@ init_iface_info(void) 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].ethdev_port_id = -1; - p_iface_info->nic[port_cnt].class_id.vlantag.vid = + p_iface_info->nic[port_cnt].cls_attrs.vlantag.vid = 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].ethdev_port_id = -1; - p_iface_info->ring[port_cnt].class_id.vlantag.vid = + p_iface_info->ring[port_cnt].cls_attrs.vlantag.vid = ETH_VLAN_ID_MAX; } } diff --git a/src/pcap/cmd_utils.h b/src/pcap/cmd_utils.h index 862eb27..8487c23 100644 --- a/src/pcap/cmd_utils.h +++ b/src/pcap/cmd_utils.h @@ -103,12 +103,6 @@ enum SPP_LONGOPT_RETVAL { SPP_LONGOPT_RETVAL_FILE_SIZE /* --fsize */ }; -/* Interface information structure */ -struct spp_port_index { - enum port_type iface_type; /**< Interface type (phy/ring) */ - int iface_no; /**< Interface number */ -}; - /** VLAN tag information */ struct spp_vlantag_info { int vid; /**< VLAN ID */ @@ -132,11 +126,18 @@ struct spp_port_ability { union spp_ability_data data; /**< Port ability data */ }; -/** Port class identifier for classifying */ -struct spp_port_class_identifier { - uint64_t mac_addr; /**< Mac address (binary) */ - char mac_addr_str[SPP_MIN_STR_LEN]; /**< Mac address (text) */ - struct spp_vlantag_info vlantag; /**< VLAN tag information */ +/* TODO(yasufum) confirm why vlantag is required for spp_pcap. */ +/* Attributes for classifying . */ +struct sppwk_cls_attrs { + uint64_t mac_addr; /**< Mac address (binary) */ + char mac_addr_str[SPP_MIN_STR_LEN]; /**< Mac address (text) */ + struct spp_vlantag_info vlantag; /**< VLAN tag information */ +}; + +/* Interface information structure */ +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`. */ @@ -144,10 +145,8 @@ struct sppwk_port_info { enum port_type iface_type; /**< phy, vhost or ring */ int iface_no; int ethdev_port_id; /**< Consistent ID of ethdev */ - struct spp_port_class_identifier class_id; - /**< Port class identifier */ + struct sppwk_cls_attrs cls_attrs; struct spp_port_ability ability[SPP_PORT_ABILITY_MAX]; - /**< Port ability */ }; /* TODO(yasufum) merge it to the same definition in shared/.../cmd_utils.h */ @@ -200,9 +199,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 diff --git a/src/pcap/spp_pcap.c b/src/pcap/spp_pcap.c index ee89b0a..bfb0233 100644 --- a/src/pcap/spp_pcap.c +++ b/src/pcap/spp_pcap.c @@ -420,7 +420,7 @@ spp_pcap_get_core_status( char role_type[8]; struct pcap_mng_info *info = &g_pcap_info[lcore_id]; char name[PCAP_FPATH_STRLEN + PCAP_FDATE_STRLEN]; - struct spp_port_index rx_ports[1]; + struct sppwk_port_idx rx_ports[1]; int rx_num = 0; RTE_LOG(DEBUG, SPP_PCAP, "status core[%d]\n", lcore_id); -- 2.17.1