[spp] [PATCH 42/57] spp_vf: change how to request commands
x-fn-spp at sl.ntt-tx.co.jp
x-fn-spp at sl.ntt-tx.co.jp
Thu Dec 28 05:55:49 CET 2017
From: Hiroyuki Nakamura <nakamura.hioryuki at po.ntt-tx.co.jp>
Change the way how to request commands.
spp_nfv command is used instead of requesting via json file.
Signed-off-by: Kentaro Watanabe <watanabe.kentaro.z01 at as.ntt-tx.co.jp>
Signed-off-by: Yasufum Ogawa <ogawa.yasufumi at lab.ntt.co.jp>
---
src/vf/command_dec.c | 503 +++++++++++++++++++-------------------------------
src/vf/command_dec.h | 15 +-
src/vf/command_proc.c | 44 +----
src/vf/spp_config.c | 14 +-
src/vf/spp_config.h | 2 +-
src/vf/spp_vf.c | 38 ++--
src/vf/spp_vf.h | 8 +-
7 files changed, 233 insertions(+), 391 deletions(-)
diff --git a/src/vf/command_dec.c b/src/vf/command_dec.c
index bc8829f..468702f 100644
--- a/src/vf/command_dec.c
+++ b/src/vf/command_dec.c
@@ -4,33 +4,12 @@
#include <rte_log.h>
#include <rte_branch_prediction.h>
-#include <jansson.h>
-
#include "spp_vf.h"
#include "spp_config.h"
#include "command_dec.h"
#define RTE_LOGTYPE_SPP_COMMAND_PROC RTE_LOGTYPE_USER1
-/* command type string list
- do it same as the order of enum command_type */
-static const char *COMMAND_TYPE_STRINGS[] = {
-#if 0 /* not supported yet */
- "add",
- "component",
-#endif
- "classifier_table",
- "flush",
-#if 0 /* not supported yet */
- "forward",
- "stop",
-#endif
- "process",
- "status",
-
- /* termination */ "",
-};
-
/* classifier type string list
do it same as the order of enum spp_classifier_type (spp_vf.h) */
static const char *CLASSIFILER_TYPE_STRINGS[] = {
@@ -40,44 +19,15 @@ static const char *CLASSIFILER_TYPE_STRINGS[] = {
/* termination */ "",
};
-/* forward declaration */
-struct json_value_decode_rule;
-
-/* definition of decode procedure function */
-typedef int (*json_value_decode_proc)(
- void *,
- const json_t *,
- const struct json_value_decode_rule *,
- struct spp_command_decode_error *);
-
-/* rule definition that decode json object to c-struct */
-struct json_value_decode_rule {
- char name[SPP_CMD_NAME_BUFSZ];
- json_type json_type;
- size_t offset;
- json_value_decode_proc decode_proc;
-
- struct {
- json_type json_type;
- size_t element_sz;
- size_t offset_num;
- size_t offset_num_valid;
- } array;
-};
-
-/* get output address for decoded json value */
-#define DR_GET_OUTPUT(output_base, rule__) ((char *)output_base + rule__->offset)
-
/* set decode error */
inline int
set_decode_error(struct spp_command_decode_error *error,
- int error_code,
- const struct json_value_decode_rule *error_rule)
+ const int error_code, const char *error_name)
{
error->code = error_code;
- if (likely(error_rule != NULL))
- strcpy(error->value_name, error_rule->name);
+ if (likely(error_name != NULL))
+ strcpy(error->value_name, error_name);
return error->code;
}
@@ -85,307 +35,242 @@ set_decode_error(struct spp_command_decode_error *error,
/* set decode error */
inline int
set_string_value_decode_error(struct spp_command_decode_error *error,
- const char* value,
- const struct json_value_decode_rule *error_rule)
+ const char* value, const char *error_name)
{
strcpy(error->value, value);
- return set_decode_error(error, SPP_CMD_DERR_BAD_VALUE, error_rule);
+ return set_decode_error(error, SPP_CMD_DERR_BAD_VALUE, error_name);
}
-/* helper */
-#define END_OF_DECODE_RULE {.name = ""},
-#define IS_END_OF_DECODE_RULE(rule) ((rule)->name[0] == '\0')
-
-/* definition helper that enum value decode procedure */
-#define DECODE_ENUM_VALUE(proc_name, enum_type, string_table) \
-static int \
-decode_##proc_name##_value(void *output, const json_t *value_obj, \
- const struct json_value_decode_rule *rule, \
- struct spp_command_decode_error *error) \
-{ \
- int i; \
- enum_type type; \
- const char *str_val = json_string_value(value_obj); \
- \
- for (i = 0; string_table[i][0] != '\0'; ++i) { \
- if (unlikely(strcmp(str_val, string_table[i]) == 0)) { \
- type = i; \
- memcpy(output, &type, sizeof(enum_type)); \
- return 0; \
- } \
- } \
- \
- return set_string_value_decode_error(error, str_val, rule); \
-} \
-
-/* enum value decode procedure for "command_type" */
-DECODE_ENUM_VALUE(command_type, enum spp_command_type, COMMAND_TYPE_STRINGS)
-
-/* enum value decode procedure for "classifier_type" */
-DECODE_ENUM_VALUE(classifier_type, enum spp_classifier_type, CLASSIFILER_TYPE_STRINGS)
-
-#if 0 /* not supported yet */
-/* decode procedure for integer */
-static int
-decode_int_value(void *output, const json_t *value_obj,
- __rte_unused const struct json_value_decode_rule *rule,
- __rte_unused struct spp_command_decode_error *error)
+/* Split command line arguments with spaces */
+static void
+decode_argument_value(char *string, int *argc, char *argv[])
{
- int val = json_integer_value(value_obj);
- memcpy(output, &val, sizeof(int));
+ int cnt = 0;
+ const char *delim = " ";
+ char *argv_tok = NULL;
+
+ argv_tok = strtok(string, delim);
+ while(argv_tok != NULL) {
+ argv[cnt] = argv_tok;
+ cnt++;
+ argv_tok = strtok(NULL, delim);
+ }
+ *argc = cnt;
+}
- return 0;
+/* Get index of array */
+static int
+get_arrary_index(const char *match, const char *list[])
+{
+ int i;
+ for (i = 0; list[i][0] == '\0'; i++) {
+ if (strcmp(list[i], match) == 0)
+ return i;
+ }
+ return -1;
}
-/* decode procedure for string */
+/* decoding procedure of port */
static int
-decode_string_value(void *output, const json_t *value_obj,
- __rte_unused const struct json_value_decode_rule *rule,
- __rte_unused struct spp_command_decode_error *error)
+decode_port_value(void *output, const char *arg_val)
{
- const char* str_val = json_string_value(value_obj);
- strcpy(output, str_val);
+ int ret = 0;
+ struct spp_config_port_info *port = output;
+ ret = spp_config_get_if_info(arg_val, &port->if_type, &port->if_no);
+ if (unlikely(ret != 0)) {
+ RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad port. val=%s\n", arg_val);
+ return -1;
+ }
return 0;
}
-#endif
-/* decode procedure for mac address string */
+/* decoding procedure of mac address string */
static int
-decode_mac_addr_str_value(void *output, const json_t *value_obj,
- const struct json_value_decode_rule *rule,
- struct spp_command_decode_error *error)
+decode_mac_addr_str_value(void *output, const char *arg_val)
{
- int ret = -1;
- const char* str_val = json_string_value(value_obj);
+ int64_t ret = 0;
+ const char *str_val = arg_val;
/* if default specification, convert to internal dummy address */
if (unlikely(strcmp(str_val, SPP_CONFIG_DEFAULT_CLASSIFIED_SPEC_STR) == 0))
str_val = SPP_CONFIG_DEFAULT_CLASSIFIED_DMY_ADDR_STR;
ret = spp_config_change_mac_str_to_int64(str_val);
- if (unlikely(ret == -1)) {
+ if (unlikely(ret < 0)) {
RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad mac address string. val=%s\n",
str_val);
- return set_string_value_decode_error(error, str_val, rule);
+ return -1;
}
- strcpy(output, str_val);
-
+ strcpy((char *)output, str_val);
return 0;
}
-/* decode procedure for spp_config_port_info */
+/* decoding procedure of classifier type */
static int
-decode_port_value(void *output, const json_t *value_obj,
- const struct json_value_decode_rule *rule,
- struct spp_command_decode_error *error)
+decode_classifier_type_value(void *output, const char *arg_val)
{
- int ret = -1;
- const char* str_val = json_string_value(value_obj);
- struct spp_config_port_info *port = (struct spp_config_port_info *)output;
-
- if (strcmp(str_val, SPP_CMD_UNUSE) == 0) {
- port->if_type = UNDEF;
- port->if_no = 0;
- return 0;
- }
-
- ret = spp_config_get_if_info(str_val, &port->if_type, &port->if_no);
- if (unlikely(ret != 0)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad port. val=%s\n", str_val);
- return set_string_value_decode_error(error, str_val, rule);
- }
-
- return 0;
+ int ret = 0;
+ ret = get_arrary_index(arg_val, CLASSIFILER_TYPE_STRINGS);
+ if (unlikely(ret < 0)) {
+ RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown classifier type. val=%s\n", arg_val);
+ return -1;
+ }
+
+ *(int *)output = ret;
+ return 0;
}
-/* decode json object */
+/* decode procedure for classifier value */
static int
-decode_json_object(void *output, const json_t *parent_obj,
- const struct json_value_decode_rule *rules,
- struct spp_command_decode_error *error)
+decode_classifiert_value_value(void *output, const char *arg_val)
{
- int ret = -1;
- int i, n;
- json_t *obj;
- json_t *value_obj;
- const struct json_value_decode_rule *rule;
-
- void *sub_output;
-
- for (i = 0; unlikely(! IS_END_OF_DECODE_RULE(&rules[i])); ++ i) {
- rule = rules + i;
-
- RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Get one object. name=%s\n",
- rule->name);
-
- value_obj = json_object_get(parent_obj, rule->name);
- if (unlikely(value_obj == NULL)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "No parameter. "
- "name=%s\n", rule->name);
- return set_decode_error(error, SPP_CMD_DERR_NO_PARAM, rule);
- } else if (unlikely(json_typeof(value_obj) != rule->json_type)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad value type. "
- "name=%s\n", rule->name);
- return set_decode_error(error, SPP_CMD_DERR_BAD_TYPE, rule);
- }
-
- switch (rule->json_type) {
- case JSON_ARRAY:
- RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array. num=%lu\n",
- json_array_size(value_obj));
-
- *(int *)((char *)output + rule->array.offset_num) =
- (int)json_array_size(value_obj);
-
- json_array_foreach(value_obj, n, obj) {
- RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array element. "
- "index=%d\n", n);
-
- if (unlikely(json_typeof(obj) != rule->array.json_type)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad value type. "
- "name=%s, index=%d\n", rule->name, n);
- return set_decode_error(error, SPP_CMD_DERR_BAD_TYPE, rule);
- }
-
- sub_output = DR_GET_OUTPUT(output, rule) +
- (rule->array.element_sz * n);
- ret = (*rule->decode_proc)(sub_output, obj, rule, error);
- if (unlikely(ret != 0)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad value. "
- "name=%s, index=%d\n", rule->name, n);
- /* decode error is set in decode function */
- return ret;
- }
-
- *(int *)((char *)output +
- rule->array.offset_num_valid) = n + 1;
- }
+ int ret = -1;
+ struct spp_command_classifier_table *classifier_table = output;
+ switch(classifier_table->type) {
+ case SPP_CLASSIFIER_TYPE_MAC:
+ ret = decode_mac_addr_str_value(classifier_table->value, arg_val);
break;
default:
- sub_output = DR_GET_OUTPUT(output, rule);
- ret = (*rule->decode_proc)(sub_output, value_obj, rule, error);
- if (unlikely(ret != 0)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad value. "
- "name=%s\n", rule->name);
- /* decode error is set in decode function */
- return ret;
- }
break;
- }
}
+ return ret;
+}
- return 0;
+/* decode procedure for classifier port */
+static int
+decode_classifier_port_value(void *output, const char *arg_val)
+{
+ struct spp_config_port_info *port = output;
+
+ if (strcmp(arg_val, SPP_CMD_UNUSE) == 0) {
+ port->if_type = UNDEF;
+ port->if_no = 0;
+ return 0;
+ }
+
+ return decode_port_value(port, arg_val);
}
-/* decode rule for command-base */
-const struct json_value_decode_rule DECODERULE_COMMAND_BASE[] = {
- {
- .name = "command",
- .json_type = JSON_STRING,
- .offset = offsetof(struct spp_command, type),
- .decode_proc = decode_command_type_value,
- },
- END_OF_DECODE_RULE
+/* parameter list for decoding */
+struct decode_parameter_list {
+ const char *name;
+ size_t offset;
+ int (*func)(void *output, const char *arg_val);
};
-#if 0 /* not supported yet */
-/* decode rule for add-command-spec */
-const struct json_value_decode_rule DECODERULE_ADD_COMMAND[] = {
- {
- .name = "ports",
- .json_type = JSON_ARRAY,
- .offset = offsetof(struct spp_command_add, ports),
- .decode_proc = decode_port_value,
-
- .array.element_sz = sizeof(struct spp_config_port_info),
- .array.json_type = JSON_STRING,
- .array.offset_num = offsetof(struct spp_command_add, num_port),
+/* parameter list for each command */
+static struct decode_parameter_list parameter_list[][SPP_CMD_MAX_PARAMETERS] = {
+ { /* classifier_table */
+ {
+ .name = "type",
+ .offset = offsetof(struct spp_command, spec.classifier_table.type),
+ .func = decode_classifier_type_value
+ },
+ {
+ .name = "value",
+ .offset = offsetof(struct spp_command, spec.classifier_table),
+ .func = decode_classifiert_value_value
+ },
+ {
+ .name = "port",
+ .offset = offsetof(struct spp_command, spec.classifier_table.port),
+ .func = decode_classifier_port_value
+ },
+ { NULL, 0, NULL },
},
- END_OF_DECODE_RULE
-};
-#endif
-
-/* decode rule for classifier-table-command-spec */
-const struct json_value_decode_rule DECODERULE_CLASSIFIER_TABLE_COMMAND[] = {
- {
- .name = "type",
- .json_type = JSON_STRING,
- .offset = offsetof(struct spp_command_classifier_table, type),
- .decode_proc = decode_classifier_type_value,
- },{
- .name = "value",
- .json_type = JSON_STRING,
- .offset = offsetof(struct spp_command_classifier_table, value),
- .decode_proc = decode_mac_addr_str_value,
- },{
- .name = "port",
- .json_type = JSON_STRING,
- .offset = offsetof(struct spp_command_classifier_table, port),
- .decode_proc = decode_port_value,
- },
- END_OF_DECODE_RULE
+ { { NULL, 0, NULL } }, /* flush */
+ { { NULL, 0, NULL } }, /* _get_client_id */
+ { { NULL, 0, NULL } }, /* status */
+ { { NULL, 0, NULL } }, /* termination */
};
-/* decode procedure for command */
+/* check by list for each command line argument */
static int
-decode_command_object(void* output, const json_t *parent_obj,
- __rte_unused const struct json_value_decode_rule *rule,
- struct spp_command_decode_error *error)
+check_comand_argment_in_list(struct spp_command_request *request,
+ int argc, char *argv[],
+ struct spp_command_decode_error *error)
{
- int ret = -1;
- struct spp_command *command = (struct spp_command *)output;
- const struct json_value_decode_rule *spec_rules = NULL;
-
- /* decode command-base */
- ret = decode_json_object(command, parent_obj, DECODERULE_COMMAND_BASE, error);
- if (unlikely(ret != 0)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad command. ret=%d\n", ret);
- /* decode error is set in decode_json_object function */
- return ret;
+ int ret = 0;
+ int ci = request->commands[0].type;
+ int pi = 0;
+ static struct decode_parameter_list *list = NULL;
+ for(pi = 1; pi < argc-1; pi++) {
+ list = ¶meter_list[ci][pi];
+ ret = (*list->func)((void *)((char*)&request->commands[0]+list->offset), argv[pi]);
+ if (unlikely(ret < 0)) {
+ RTE_LOG(ERR, SPP_COMMAND_PROC,
+ "Bad value. command = %s, name=%s, index=%d\n",
+ argv[0], list->name, pi);
+ return set_string_value_decode_error(error, argv[pi], list->name);
+ }
}
+ return 0;
+}
- /* decode command-specific */
- switch (command->type) {
- case SPP_CMDTYPE_CLASSIFIER_TABLE:
- spec_rules = DECODERULE_CLASSIFIER_TABLE_COMMAND;
- break;
+/* command list for decoding */
+struct decode_command_list {
+ const char *name;
+ int param_min;
+ int param_max;
+ int (*func)(struct spp_command_request *request, int argc, char *argv[],
+ struct spp_command_decode_error *error);
+};
- default:
- /* nothing specific */
- /* (unknown command is already checked) */
- break;
- }
+/* command list */
+static struct decode_command_list command_list[] = {
+ { "classifier_table", 4, 4, check_comand_argment_in_list }, /* classifier_table */
+ { "flush", 1, 1, NULL }, /* flush */
+ { "_get_client_id", 1, 1, NULL }, /* _get_client_id */
+ { "status", 1, 1, NULL }, /* status */
+ { "", 0, 0, NULL } /* termination */
+};
- if (likely(spec_rules != NULL)) {
- ret = decode_json_object(&command->spec, parent_obj, spec_rules, error);
- if (unlikely(ret != 0)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "Bad command. ret=%d\n", ret);
- /* decode error is set in decode_json_object function */
- return ret;
+/* Decode command line arguments */
+static int
+decode_command_argment(struct spp_command_request *request,
+ const char *request_str,
+ struct spp_command_decode_error *error)
+{
+ struct decode_command_list *list = NULL;
+ int i = 0;
+ int argc = 0;
+ char *argv[SPP_CMD_MAX_PARAMETERS];
+ char tmp_str[SPP_CMD_MAX_PARAMETERS*SPP_CMD_VALUE_BUFSZ];
+ memset(argv, 0x00, sizeof(argv));
+ memset(tmp_str, 0x00, sizeof(tmp_str));
+
+ request->num_command = 1;
+
+ strcpy(tmp_str, request_str);
+ decode_argument_value(tmp_str, &argc, argv);
+ RTE_LOG(DEBUG, SPP_COMMAND_PROC, "Decode array. num=%d\n", argc);
+
+ for (i = 0; command_list[i].name[0] != '\0'; i++) {
+ list = &command_list[i];
+ if (strcmp(argv[0], list->name) != 0) {
+ continue;
}
+
+ if (unlikely(argc < list->param_min) || unlikely(list->param_max < argc)) {
+ RTE_LOG(ERR, SPP_COMMAND_PROC, "Parameter number out of range."
+ "request_str=%s\n", request_str);
+ return set_decode_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL);
+ }
+
+ request->commands[0].type = i;
+ if (list->func != NULL)
+ return (*list->func)(request, argc, argv, error);
+
+ return 0;
}
- return 0;
+ RTE_LOG(ERR, SPP_COMMAND_PROC, "Unknown command. command=%s, request_str=%s\n",
+ argv[0], request_str);
+ return set_string_value_decode_error(error, argv[0], "command");
}
-/* decode rule for command request */
-const struct json_value_decode_rule DECODERULE_REQUEST[] = {
- {
- .name = "commands",
- .json_type = JSON_ARRAY,
- .offset = offsetof(struct spp_command_request, commands),
- .decode_proc = decode_command_object,
-
- .array.element_sz = sizeof(struct spp_command),
- .array.json_type = JSON_OBJECT,
- .array.offset_num = offsetof(struct spp_command_request, num_command),
- .array.offset_num_valid = offsetof(struct spp_command_request, num_valid_command),
- },
- END_OF_DECODE_RULE
-};
-
/* decode request from no-null-terminated string */
int
spp_command_decode_request(struct spp_command_request *request, const char *request_str,
@@ -393,35 +278,21 @@ spp_command_decode_request(struct spp_command_request *request, const char *requ
{
int ret = -1;
int i;
- json_t *top_obj;
- json_error_t json_error;
-
- /* parse json string */
- top_obj = json_loadb(request_str, request_str_len, 0, &json_error);
- if (unlikely(top_obj == NULL)) {
- RTE_LOG(ERR, SPP_COMMAND_PROC, "Cannot parse command request. "
- "error=%s, request_str=%.*s\n",
- json_error.text, (int)request_str_len, request_str);
- return set_decode_error(error, SPP_CMD_DERR_BAD_FORMAT, NULL);
- }
- /* decode request object */
- ret = decode_json_object(request, top_obj, DECODERULE_REQUEST, error);
- if (unlikely(ret != 0)) {
+ /* decode request */
+ ret = decode_command_argment(request, request_str, error);
+ if (unlikely(ret < 0)) {
RTE_LOG(ERR, SPP_COMMAND_PROC, "Cannot decode command request. "
"ret=%d, request_str=%.*s\n",
ret, (int)request_str_len, request_str);
- /* decode error is set in decode_json_object function */
+ return ret;
}
- /* free json object */
- json_decref(top_obj);
-
/* check getter command */
for (i = 0; i < request->num_valid_command; ++i) {
switch (request->commands[i].type) {
- case SPP_CMDTYPE_PROCESS:
- request->is_requested_process = 1;
+ case SPP_CMDTYPE_CLIENT_ID:
+ request->is_requested_client_id = 1;
break;
case SPP_CMDTYPE_STATUS:
request->is_requested_status = 1;
diff --git a/src/vf/command_dec.h b/src/vf/command_dec.h
index 42a0168..8850485 100644
--- a/src/vf/command_dec.h
+++ b/src/vf/command_dec.h
@@ -4,6 +4,9 @@
/* max number of command per request */
#define SPP_CMD_MAX_COMMANDS 32
+/* maximum number of parameters per command */
+#define SPP_CMD_MAX_PARAMETERS 8
+
/* command name string buffer size (include null char) */
#define SPP_CMD_NAME_BUFSZ 32
@@ -29,17 +32,9 @@ enum spp_command_decode_error_code {
/* command type
do it same as the order of COMMAND_TYPE_STRINGS */
enum spp_command_type {
-#if 0 /* not supported yet yet */
- SPP_CMDTYPE_ADD,
- SPP_CMDTYPE_COMPONENT,
-#endif
SPP_CMDTYPE_CLASSIFIER_TABLE,
SPP_CMDTYPE_FLUSH,
-#if 0 /* not supported yet */
- SPP_CMDTYPE_FORWARD,
- SPP_CMDTYPE_STOP,
-#endif
- SPP_CMDTYPE_PROCESS,
+ SPP_CMDTYPE_CLIENT_ID,
SPP_CMDTYPE_STATUS,
};
@@ -93,7 +88,7 @@ struct spp_command_request {
int num_valid_command;
struct spp_command commands[SPP_CMD_MAX_COMMANDS];
- int is_requested_process;
+ int is_requested_client_id;
int is_requested_status;
};
diff --git a/src/vf/command_proc.c b/src/vf/command_proc.c
index fe18e22..0dd1d56 100644
--- a/src/vf/command_proc.c
+++ b/src/vf/command_proc.c
@@ -206,18 +206,18 @@ append_response_command_results_object(json_t *parent_obj,
return 0;
}
-/* append process value to specified json object */
+/* append client id value to specified json object */
static int
-append_response_process_value(json_t *parent_obj)
+append_response_client_id_value(json_t *parent_obj)
{
int ret = -1;
json_t *proc_obj;
- proc_obj = json_integer(spp_get_process_id());
+ proc_obj = json_integer(spp_get_client_id());
if (unlikely(proc_obj == NULL))
return -1;
- ret = json_object_set_new(parent_obj, "process", proc_obj);
+ ret = json_object_set_new(parent_obj, "client_id", proc_obj);
if (unlikely(ret != 0))
return -1;
@@ -354,9 +354,9 @@ send_command_result_response(int *sock, const struct spp_command_request *reques
return;
}
- /* append process information value */
- if (request->is_requested_process) {
- ret = append_response_process_value(top_obj);
+ /* append client id information value */
+ if (request->is_requested_client_id) {
+ ret = append_response_client_id_value(top_obj);
if (unlikely(ret != 0)) {
RTE_LOG(ERR, SPP_COMMAND_PROC, "Failed to make command result response.");
json_decref(top_obj);
@@ -459,15 +459,11 @@ spp_command_proc_do(void)
{
int ret = -1;
int msg_ret = -1;
- int i;
static int sock = -1;
static char *msgbuf = NULL;
static size_t msg_len = 0;
- static size_t rb_cnt = 0;
- static size_t lb_cnt = 0;
-
if (unlikely(msgbuf == NULL)) {
msgbuf = spp_strbuf_allocate(CMD_REQ_BUF_INIT_SIZE);
if (unlikely(msgbuf == NULL)) {
@@ -491,29 +487,9 @@ spp_command_proc_do(void)
return -1;
}
- for (i = 0; i < msg_ret; ++i) {
- switch (*(msgbuf + msg_len + i)) {
- case '{':
- ++lb_cnt;
- break;
- case '}':
- ++rb_cnt;
- break;
- }
-
- if (likely(lb_cnt != 0) && unlikely(rb_cnt == lb_cnt)) {
- msg_len += (i + 1);
- ret = process_request(&sock, msgbuf, msg_len);
-
- spp_strbuf_remove_front(msgbuf, msg_len);
- msg_ret = 0;
- msg_len = 0;
- rb_cnt = 0;
- lb_cnt = 0;
- }
- }
-
- msg_len = msg_len + msg_ret;
+ msg_len += (msg_ret + 1);
+ ret = process_request(&sock, msgbuf, msg_len);
+ spp_strbuf_remove_front(msgbuf, msg_len);
return 0;
}
diff --git a/src/vf/spp_config.c b/src/vf/spp_config.c
index 27bce8f..bca455c 100644
--- a/src/vf/spp_config.c
+++ b/src/vf/spp_config.c
@@ -162,18 +162,18 @@ spp_config_get_if_info(const char *port, enum port_type *if_type, int *if_no)
char *endptr = NULL;
/* IF type check */
- if (strncmp(port, SPP_CONFIG_IFTYPE_NIC, strlen(SPP_CONFIG_IFTYPE_NIC)) == 0) {
+ if (strncmp(port, SPP_CONFIG_IFTYPE_NIC ":", strlen(SPP_CONFIG_IFTYPE_NIC)+1) == 0) {
/* NIC */
type = PHY;
- no_str = &port[strlen(SPP_CONFIG_IFTYPE_NIC)];
- } else if (strncmp(port, SPP_CONFIG_IFTYPE_VHOST, strlen(SPP_CONFIG_IFTYPE_VHOST)) == 0) {
+ no_str = &port[strlen(SPP_CONFIG_IFTYPE_NIC)+1];
+ } else if (strncmp(port, SPP_CONFIG_IFTYPE_VHOST ":", strlen(SPP_CONFIG_IFTYPE_VHOST)+1) == 0) {
/* VHOST */
type = VHOST;
- no_str = &port[strlen(SPP_CONFIG_IFTYPE_VHOST)];
- } else if (strncmp(port, SPP_CONFIG_IFTYPE_RING, strlen(SPP_CONFIG_IFTYPE_RING)) == 0) {
+ no_str = &port[strlen(SPP_CONFIG_IFTYPE_VHOST)+1];
+ } else if (strncmp(port, SPP_CONFIG_IFTYPE_RING ":", strlen(SPP_CONFIG_IFTYPE_RING)+1) == 0) {
/* RING */
type = RING;
- no_str = &port[strlen(SPP_CONFIG_IFTYPE_RING)];
+ no_str = &port[strlen(SPP_CONFIG_IFTYPE_RING)+1];
} else {
/* OTHER */
RTE_LOG(ERR, APP, "Unknown interface type. (port = %s)\n", port);
@@ -218,7 +218,7 @@ int spp_config_format_port_string(char *port, enum port_type if_type, int if_no)
return -1;
}
- sprintf(port, "%s%d", if_type_str, if_no);
+ sprintf(port, "%s:%d", if_type_str, if_no);
return 0;
}
diff --git a/src/vf/spp_config.h b/src/vf/spp_config.h
index 7a8bdf6..5722afd 100644
--- a/src/vf/spp_config.h
+++ b/src/vf/spp_config.h
@@ -6,7 +6,7 @@
#define SPP_CONFIG_FILE_PATH "/usr/local/etc/spp/spp.json"
-#define SPP_CONFIG_IFTYPE_NIC "nic"
+#define SPP_CONFIG_IFTYPE_NIC "phy"
#define SPP_CONFIG_IFTYPE_VHOST "vhost"
#define SPP_CONFIG_IFTYPE_RING "ring"
diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c
index 18533d1..20a3b40 100644
--- a/src/vf/spp_vf.c
+++ b/src/vf/spp_vf.c
@@ -23,13 +23,13 @@ enum SPP_LONGOPT_RETVAL {
/* add below */
SPP_LONGOPT_RETVAL_CONFIG,
- SPP_LONGOPT_RETVAL_PROCESS_ID,
+ SPP_LONGOPT_RETVAL_CLIENT_ID,
SPP_LONGOPT_RETVAL_VHOST_CLIENT
};
/* struct */
struct startup_param {
- int process_id;
+ int client_id;
char server_ip[INET_ADDRSTRLEN];
int server_port;
int vhost_client;
@@ -70,11 +70,11 @@ static void
usage(const char *progname)
{
RTE_LOG(INFO, APP, "Usage: %s [EAL args] --"
- " --process-id PROC_ID"
+ " --client-id CLIENT_ID"
" [--config CONFIG_FILE_PATH]"
" -s SERVER_IP:SERVER_PORT"
" [--vhost-client]\n"
- " --process-id PROCESS_ID : My process ID\n"
+ " --client-id CLIENT_ID : My client ID\n"
" --config CONFIG_FILE_PATH : specific config file path\n"
" -s SERVER_IP:SERVER_PORT : Access information to the server\n"
" --vhost-client : Run vhost on client\n"
@@ -252,23 +252,23 @@ stop_process(int signal) {
}
/*
- * Parses the process ID of the application argument.
+ * Parses the client ID of the application argument.
*/
static int
-parse_app_process_id(const char *process_id_str, int *process_id)
+parse_app_client_id(const char *client_id_str, int *client_id)
{
int id = 0;
char *endptr = NULL;
- id = strtol(process_id_str, &endptr, 0);
- if (unlikely(process_id_str == endptr) || unlikely(*endptr != '\0'))
+ id = strtol(client_id_str, &endptr, 0);
+ if (unlikely(client_id_str == endptr) || unlikely(*endptr != '\0'))
return -1;
- if (id >= SPP_PROCESS_MAX)
+ if (id >= SPP_CLIENT_MAX)
return -1;
- *process_id = id;
- RTE_LOG(DEBUG, APP, "Set process id = %d\n", *process_id);
+ *client_id = id;
+ RTE_LOG(DEBUG, APP, "Set client id = %d\n", *client_id);
return 0;
}
@@ -314,7 +314,7 @@ parse_app_args(int argc, char *argv[])
const char *progname = argv[0];
static struct option lgopts[] = {
{ "config", required_argument, NULL, SPP_LONGOPT_RETVAL_CONFIG },
- { "process-id", required_argument, NULL, SPP_LONGOPT_RETVAL_PROCESS_ID },
+ { "client-id", required_argument, NULL, SPP_LONGOPT_RETVAL_CLIENT_ID },
{ "vhost-client", no_argument, NULL, SPP_LONGOPT_RETVAL_VHOST_CLIENT },
{ 0 },
};
@@ -340,8 +340,8 @@ parse_app_args(int argc, char *argv[])
}
strcpy(config_file_path, optarg);
break;
- case SPP_LONGOPT_RETVAL_PROCESS_ID:
- if (parse_app_process_id(optarg, &g_startup_param.process_id) != 0) {
+ case SPP_LONGOPT_RETVAL_CLIENT_ID:
+ if (parse_app_client_id(optarg, &g_startup_param.client_id) != 0) {
usage(progname);
return -1;
}
@@ -370,8 +370,8 @@ parse_app_args(int argc, char *argv[])
usage(progname);
return -1;
}
- RTE_LOG(INFO, APP, "application arguments value. (process id = %d, config = %s, server = %s:%d, vhost client = %d)\n",
- g_startup_param.process_id,
+ RTE_LOG(INFO, APP, "application arguments value. (client id = %d, config = %s, server = %s:%d, vhost client = %d)\n",
+ g_startup_param.client_id,
config_file_path,
g_startup_param.server_ip,
g_startup_param.server_port,
@@ -978,12 +978,12 @@ ut_main(int argc, char *argv[])
}
/*
- * Get process ID
+ * Get client ID
*/
int
-spp_get_process_id(void)
+spp_get_client_id(void)
{
- return g_startup_param.process_id;
+ return g_startup_param.client_id;
}
/*
diff --git a/src/vf/spp_vf.h b/src/vf/spp_vf.h
index bbdb904..b0da048 100644
--- a/src/vf/spp_vf.h
+++ b/src/vf/spp_vf.h
@@ -4,7 +4,7 @@
#include "common.h"
#include "spp_config.h"
-#define SPP_PROCESS_MAX 128
+#define SPP_CLIENT_MAX 128
/*
* State on core
@@ -60,10 +60,10 @@ struct spp_core_info {
};
/*
- * Get process ID
- * RETURN : PROCESS ID(0~127)
+ * Get client ID
+ * RETURN : CLIENT ID(0~127)
*/
-int spp_get_process_id(void);
+int spp_get_client_id(void);
/*
* Update Classifier_table
--
1.9.1
More information about the spp
mailing list