telemetry: remove redundant code

This patch removes the existing telemetry files, which are now redundant
as the new version of telemetry has backward compatibility for their
functionality.

Signed-off-by: Ciara Power <ciara.power@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
This commit is contained in:
Ciara Power 2020-04-30 17:01:33 +01:00 committed by Thomas Monjalon
parent b80fe1805e
commit 63e7cb1bf1
12 changed files with 23 additions and 2601 deletions

View File

@ -7,7 +7,6 @@
#include <rte_ethdev.h>
#include <rte_string_fns.h>
#ifdef RTE_LIBRTE_TELEMETRY
#include <rte_telemetry_internal.h>
#include <rte_telemetry_legacy.h>
#endif
@ -529,14 +528,6 @@ handle_ports_stats_values_by_name(const char *cmd __rte_unused,
RTE_INIT(metrics_ctor)
{
#ifdef RTE_LIBRTE_TELEMETRY
static const struct metrics_functions fns = {
.reg_all_ethdev = rte_metrics_tel_reg_all_ethdev,
.encode_json_format = rte_metrics_tel_encode_json_format,
.get_port_stats_ids = rte_metrics_tel_get_port_stats_ids,
.get_ports_stats_json = rte_metrics_tel_get_ports_stats_json,
.extract_data = rte_metrics_tel_extract_data
};
rte_telemetry_set_metrics_fns(&fns); /* assign them to telemetry lib */
rte_telemetry_legacy_register("ports_all_stat_values", DATA_NOT_REQ,
handle_ports_all_stats_values);
rte_telemetry_legacy_register("global_stat_values", DATA_NOT_REQ,

View File

@ -15,14 +15,10 @@ CFLAGS += -pthread
LDLIBS += -lrte_eal
LDLIBS += -lpthread
LDLIBS += -ljansson
EXPORT_MAP := rte_telemetry_version.map
# library source files
SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) := rte_telemetry.c
SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser.c
SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += rte_telemetry_parser_test.c
SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += telemetry.c
SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += telemetry_data.c
SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += telemetry_legacy.c

View File

@ -3,16 +3,7 @@
includes = [global_inc]
sources = files('rte_telemetry.c', 'rte_telemetry_parser.c', 'rte_telemetry_parser_test.c',
'telemetry.c', 'telemetry_data.c', 'telemetry_legacy.c')
headers = files('rte_telemetry.h', 'rte_telemetry_internal.h', 'rte_telemetry_parser.h')
sources = files('telemetry.c', 'telemetry_data.c', 'telemetry_legacy.c')
headers = files('rte_telemetry.h')
includes += include_directories('../librte_metrics')
jansson = dependency('jansson', required: false)
if jansson.found()
ext_deps += jansson
dpdk_app_link_libraries += ['telemetry']
else
build = false
reason = 'missing dependency "jansson"'
endif
dpdk_app_link_libraries += ['telemetry']

File diff suppressed because it is too large Load Diff

View File

@ -219,56 +219,6 @@ typedef int (*telemetry_cb)(const char *cmd, const char *params,
*/
typedef void * (*handler)(void *sock_id);
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice
*
* Initialize Telemetry
*
* @return
* 0 on successful initialisation.
* @return
* -ENOMEM on memory allocation error
* @return
* -EPERM on unknown error failure
* @return
* -EALREADY if Telemetry is already initialised.
*/
__rte_experimental
int32_t
rte_telemetry_init(void);
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice
*
* Clean up and free memory.
*
* @return
* 0 on success
* @return
* -EPERM on failure
*/
__rte_experimental
int32_t
rte_telemetry_cleanup(void);
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice
*
* Runs various tests to ensure telemetry initialisation and register/unregister
* functions are working correctly.
*
* @return
* 0 on success when all tests have passed
* @return
* -1 on failure when the test has failed
*/
__rte_experimental
int32_t
rte_telemetry_selftest(void);
/**
* Used when registering a command and callback function with telemetry.
*
@ -291,7 +241,7 @@ int
rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help);
/**
* Initialize new version of Telemetry.
* Initialize Telemetry.
*
* @return
* 0 on success.
@ -300,5 +250,5 @@ rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help);
*/
__rte_experimental
int
rte_telemetry_new_init(void);
rte_telemetry_init(void);
#endif

View File

@ -1,114 +0,0 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Intel Corporation
*/
#include <rte_log.h>
#include <rte_tailq.h>
#include <rte_metrics.h>
#include <rte_metrics_telemetry.h>
#ifndef _RTE_TELEMETRY_INTERNAL_H_
#define _RTE_TELEMETRY_INTERNAL_H_
/* function types for the functions coming from metrics library */
typedef int32_t (*metrics_tel_reg_all_ethdev_t)(int *metrics_register_done,
int *reg_index_list);
typedef int32_t (*metrics_tel_encode_json_format_t)(
struct telemetry_encode_param *ep, char **json_buffer);
typedef int32_t (*metrics_tel_get_port_stats_ids_t)(
struct telemetry_encode_param *ep);
typedef int32_t (*metrics_tel_get_ports_stats_json_t)(
struct telemetry_encode_param *ep,
int *reg_index, char **json_buffer);
typedef int32_t (*metrics_tel_extract_data_t)(struct telemetry_encode_param *ep,
json_t *data);
struct metrics_functions {
metrics_tel_reg_all_ethdev_t reg_all_ethdev;
metrics_tel_encode_json_format_t encode_json_format;
metrics_tel_get_port_stats_ids_t get_port_stats_ids;
metrics_tel_get_ports_stats_json_t get_ports_stats_json;
metrics_tel_extract_data_t extract_data;
};
extern const struct metrics_functions *metrics_fns;
/* API for use by metrics libraries to provide the functions to use */
__rte_experimental
void rte_telemetry_set_metrics_fns(const struct metrics_functions *fns);
/* Logging Macros */
extern int telemetry_log_level;
#define TELEMETRY_LOG(level, fmt, args...) \
rte_log(RTE_LOG_ ##level, telemetry_log_level, "%s(): "fmt "\n", \
__func__, ##args)
#define TELEMETRY_LOG_ERR(fmt, args...) \
TELEMETRY_LOG(ERR, fmt, ## args)
#define TELEMETRY_LOG_WARN(fmt, args...) \
TELEMETRY_LOG(WARNING, fmt, ## args)
#define TELEMETRY_LOG_INFO(fmt, args...) \
TELEMETRY_LOG(INFO, fmt, ## args)
#define MAX_METRICS 256
typedef struct telemetry_client {
char *file_path;
int fd;
TAILQ_ENTRY(telemetry_client) client_list;
} telemetry_client;
typedef struct telemetry_impl {
int accept_fd;
int server_fd;
pthread_t thread_id;
int thread_status;
uint32_t socket_id;
int reg_index[RTE_MAX_ETHPORTS];
int metrics_register_done;
TAILQ_HEAD(, telemetry_client) client_list_head;
struct telemetry_client *request_client;
int register_fail_count;
} telemetry_impl;
enum rte_telemetry_parser_actions {
ACTION_GET = 0,
ACTION_DELETE = 2
};
int32_t
rte_telemetry_parse_client_message(struct telemetry_impl *telemetry, char *buf);
int32_t
rte_telemetry_send_error_response(struct telemetry_impl *telemetry,
int error_type);
int32_t
rte_telemetry_register_client(struct telemetry_impl *telemetry,
const char *client_path);
int32_t
rte_telemetry_unregister_client(struct telemetry_impl *telemetry,
const char *client_path);
int32_t
rte_telemetry_send_ports_stats_values(struct telemetry_encode_param *ep,
struct telemetry_impl *telemetry);
int32_t
rte_telemetry_socket_messaging_testing(int index, int socket);
int32_t
rte_telemetry_send_global_stats_values(struct telemetry_encode_param *ep,
struct telemetry_impl *telemetry);
int32_t
rte_telemetry_parser_test(struct telemetry_impl *telemetry);
#endif

View File

@ -1,435 +0,0 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Intel Corporation
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <jansson.h>
#include <rte_metrics.h>
#include <rte_common.h>
#include <rte_metrics_telemetry.h>
#include "rte_telemetry_internal.h"
#include "rte_telemetry_parser.h"
typedef int (*command_func)(struct telemetry_impl *, int, json_t *);
struct rte_telemetry_command {
const char *text;
command_func fn;
} command;
static int32_t
rte_telemetry_command_clients(struct telemetry_impl *telemetry, int action,
json_t *data)
{
int ret;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
if (action != ACTION_DELETE) {
TELEMETRY_LOG_WARN("Invalid action for this command");
goto einval_fail;
}
if (!json_is_object(data)) {
TELEMETRY_LOG_WARN("Invalid data provided for this command");
goto einval_fail;
}
json_t *client_path = json_object_get(data, "client_path");
if (!json_is_string(client_path)) {
TELEMETRY_LOG_WARN("Command value is not a string");
goto einval_fail;
}
ret = rte_telemetry_unregister_client(telemetry,
json_string_value(client_path));
if (ret < 0) {
TELEMETRY_LOG_ERR("Could not unregister client");
goto einval_fail;
}
return 0;
einval_fail:
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
static int32_t
rte_telemetry_command_ports(struct telemetry_impl *telemetry, int action,
json_t *data)
{
int ret;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
if (!json_is_null(data)) {
TELEMETRY_LOG_WARN("Data should be NULL JSON object for 'ports' command");
goto einval_fail;
}
if (action != ACTION_GET) {
TELEMETRY_LOG_WARN("Invalid action for this command");
goto einval_fail;
}
return 0;
einval_fail:
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
static int32_t
rte_telemetry_command_ports_details(struct telemetry_impl *telemetry,
int action, json_t *data)
{
json_t *value, *port_ids_json = json_object_get(data, "ports");
uint64_t num_port_ids = json_array_size(port_ids_json);
int ret, port_ids[num_port_ids];
RTE_SET_USED(port_ids);
size_t index;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
if (action != ACTION_GET) {
TELEMETRY_LOG_WARN("Invalid action for this command");
goto einval_fail;
}
if (!json_is_object(data)) {
TELEMETRY_LOG_WARN("Invalid data provided for this command");
goto einval_fail;
}
if (!json_is_array(port_ids_json)) {
TELEMETRY_LOG_WARN("Invalid Port ID array");
goto einval_fail;
}
json_array_foreach(port_ids_json, index, value) {
if (!json_is_integer(value)) {
TELEMETRY_LOG_WARN("Port ID given is invalid");
goto einval_fail;
}
port_ids[index] = json_integer_value(value);
}
return 0;
einval_fail:
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
static int32_t
rte_telemetry_command_port_stats(struct telemetry_impl *telemetry, int action,
json_t *data)
{
int ret;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
if (!json_is_null(data)) {
TELEMETRY_LOG_WARN("Data should be NULL JSON object for 'port_stats' command");
goto einval_fail;
}
if (action != ACTION_GET) {
TELEMETRY_LOG_WARN("Invalid action for this command");
goto einval_fail;
}
return 0;
einval_fail:
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
static int32_t
rte_telemetry_command_ports_all_stat_values(struct telemetry_impl *telemetry,
int action, json_t *data)
{
int ret;
struct telemetry_encode_param ep;
memset(&ep, 0, sizeof(ep));
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
if (action != ACTION_GET) {
TELEMETRY_LOG_WARN("Invalid action for this command");
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
if (json_is_object(data)) {
TELEMETRY_LOG_WARN("Invalid data provided for this command");
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
ret = metrics_fns->get_port_stats_ids(&ep);
if (ret < 0) {
TELEMETRY_LOG_ERR("Could not get ports stat values");
ret = rte_telemetry_send_error_response(telemetry, ret);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
ret = rte_telemetry_send_ports_stats_values(&ep, telemetry);
if (ret < 0) {
TELEMETRY_LOG_ERR("Sending ports stats values failed");
return -1;
}
return 0;
}
static int32_t
rte_telemetry_command_global_stat_values(struct telemetry_impl *telemetry,
int action, json_t *data)
{
int ret;
struct telemetry_encode_param ep = { .type = GLOBAL_STATS };
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
if (action != ACTION_GET) {
TELEMETRY_LOG_WARN("Invalid action for this command");
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
if (json_is_object(data)) {
TELEMETRY_LOG_WARN("Invalid data provided for this command");
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
ret = rte_telemetry_send_global_stats_values(&ep, telemetry);
if (ret < 0) {
TELEMETRY_LOG_ERR("Sending global stats values failed");
return -1;
}
return 0;
}
static int32_t
rte_telemetry_command_ports_stats_values_by_name(struct telemetry_impl
*telemetry, int action, json_t *data)
{
int ret;
struct telemetry_encode_param ep;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
if (action != ACTION_GET) {
TELEMETRY_LOG_WARN("Invalid action for this command");
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
ret = metrics_fns->extract_data(&ep, data);
if (ret < 0) {
TELEMETRY_LOG_ERR("Extracting JSON data failed");
ret = rte_telemetry_send_error_response(telemetry, ret);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
ret = rte_telemetry_send_ports_stats_values(&ep, telemetry);
if (ret < 0) {
TELEMETRY_LOG_ERR("Sending ports stats values failed");
return -1;
}
return 0;
}
static int32_t
rte_telemetry_parse_command(struct telemetry_impl *telemetry, int action,
const char *command, json_t *data)
{
int ret;
uint32_t i;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
struct rte_telemetry_command commands[] = {
{
.text = "clients",
.fn = &rte_telemetry_command_clients
},
{
.text = "ports",
.fn = &rte_telemetry_command_ports
},
{
.text = "ports_details",
.fn = &rte_telemetry_command_ports_details
},
{
.text = "port_stats",
.fn = &rte_telemetry_command_port_stats
},
{
.text = "ports_stats_values_by_name",
.fn = &rte_telemetry_command_ports_stats_values_by_name
},
{
.text = "ports_all_stat_values",
.fn = &rte_telemetry_command_ports_all_stat_values
},
{
.text = "global_stat_values",
.fn = &rte_telemetry_command_global_stat_values
}
};
const uint32_t num_commands = RTE_DIM(commands);
for (i = 0; i < num_commands; i++) {
if (strcmp(command, commands[i].text) == 0) {
ret = commands[i].fn(telemetry, action, data);
if (ret < 0) {
TELEMETRY_LOG_ERR("Command Function for %s failed",
commands[i].text);
return -1;
}
return 0;
}
}
TELEMETRY_LOG_WARN("\"%s\" command not found", command);
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -1;
}
int32_t
rte_telemetry_parse(struct telemetry_impl *telemetry, char *socket_rx_data)
{
int ret, action_int;
json_error_t error;
json_t *root, *action, *command, *data;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Invalid telemetry argument");
return -1;
}
root = json_loads(socket_rx_data, 0, &error);
if (root == NULL) {
TELEMETRY_LOG_WARN("Could not load JSON object from data passed in : %s",
error.text);
ret = rte_telemetry_send_error_response(telemetry, -EPERM);
if (ret < 0)
TELEMETRY_LOG_ERR("Could not send error");
return -EPERM;
} else if (!json_is_object(root)) {
TELEMETRY_LOG_WARN("JSON Request is not a JSON object");
json_decref(root);
goto einval_fail;
}
action = json_object_get(root, "action");
if (action == NULL) {
TELEMETRY_LOG_WARN("Request does not have action field");
goto einval_fail;
} else if (!json_is_integer(action)) {
TELEMETRY_LOG_WARN("Action value is not an integer");
goto einval_fail;
}
command = json_object_get(root, "command");
if (command == NULL) {
TELEMETRY_LOG_WARN("Request does not have command field");
goto einval_fail;
} else if (!json_is_string(command)) {
TELEMETRY_LOG_WARN("Command value is not a string");
goto einval_fail;
}
action_int = json_integer_value(action);
if (action_int != ACTION_GET && action_int != ACTION_DELETE) {
TELEMETRY_LOG_WARN("Invalid action code");
goto einval_fail;
}
const char *command_string = json_string_value(command);
data = json_object_get(root, "data");
if (data == NULL) {
TELEMETRY_LOG_WARN("Request does not have data field");
goto einval_fail;
}
ret = rte_telemetry_parse_command(telemetry, action_int, command_string,
data);
if (ret < 0) {
TELEMETRY_LOG_WARN("Could not parse command");
return -EINVAL;
}
return 0;
einval_fail:
ret = rte_telemetry_send_error_response(telemetry, -EINVAL);
if (ret < 0) {
TELEMETRY_LOG_ERR("Could not send error");
return -EPERM;
}
return -EINVAL;
}

View File

@ -1,15 +0,0 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Intel Corporation
*/
#include "rte_telemetry_internal.h"
#include "rte_compat.h"
#ifndef _RTE_TELEMETRY_PARSER_H_
#define _RTE_TELEMETRY_PARSER_H_
__rte_experimental
int32_t
rte_telemetry_parse(struct telemetry_impl *telemetry, char *socket_rx_data);
#endif

View File

@ -1,533 +0,0 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Intel Corporation
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <jansson.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <rte_common.h>
#include <rte_tailq.h>
#include <rte_string_fns.h>
#include "rte_telemetry_parser.h"
#include "rte_telemetry_internal.h"
enum choices {
INV_ACTION_VAL,
INV_COMMAND_VAL,
INV_DATA_VAL,
INV_ACTION_FIELD,
INV_COMMAND_FIELD,
INV_DATA_FIELD,
INV_JSON_FORMAT,
VALID_REQ
};
#define TEST_CLIENT "/var/run/dpdk/test_client"
static int32_t
rte_telemetry_create_test_socket(struct telemetry_impl *telemetry,
const char *test_client_path)
{
int ret, sockfd;
struct sockaddr_un addr = {0};
struct telemetry_client *client;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Telemetry argument has not been initialised");
return -EINVAL;
}
sockfd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
if (sockfd < 0) {
TELEMETRY_LOG_ERR("Test socket creation failure");
return -1;
}
addr.sun_family = AF_UNIX;
strlcpy(addr.sun_path, test_client_path, sizeof(addr.sun_path));
unlink(test_client_path);
if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
TELEMETRY_LOG_ERR("Test socket binding failure");
return -1;
}
if (listen(sockfd, 1) < 0) {
TELEMETRY_LOG_ERR("Listen failure");
return -1;
}
ret = rte_telemetry_register_client(telemetry, test_client_path);
if (ret < 0) {
TELEMETRY_LOG_ERR("Register dummy client failed: %i", ret);
return -1;
}
ret = accept(sockfd, NULL, NULL);
if (ret < 0) {
TELEMETRY_LOG_ERR("Socket accept failed");
return -1;
}
TAILQ_FOREACH(client, &telemetry->client_list_head, client_list)
telemetry->request_client = client;
return 0;
}
static int32_t
rte_telemetry_format_port_stat_ids(int *port_ids, int num_port_ids,
const char * const *stat_names, int num_stat_names, json_t **data)
{
int ret;
json_t *stat_names_json_array = NULL;
json_t *port_ids_json_array = NULL;
uint32_t i;
if (num_port_ids < 0) {
TELEMETRY_LOG_ERR("Port Ids Count invalid");
goto fail;
}
*data = json_object();
if (*data == NULL) {
TELEMETRY_LOG_ERR("Data json object creation failed");
goto fail;
}
port_ids_json_array = json_array();
if (port_ids_json_array == NULL) {
TELEMETRY_LOG_ERR("port_ids_json_array creation failed");
goto fail;
}
for (i = 0; i < (uint32_t)num_port_ids; i++) {
ret = json_array_append(port_ids_json_array,
json_integer(port_ids[i]));
if (ret < 0) {
TELEMETRY_LOG_ERR("JSON array creation failed");
goto fail;
}
}
ret = json_object_set_new(*data, "ports", port_ids_json_array);
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting 'ports' value in data object failed");
goto fail;
}
if (stat_names) {
if (num_stat_names < 0) {
TELEMETRY_LOG_ERR("Stat Names Count invalid");
goto fail;
}
stat_names_json_array = json_array();
if (stat_names_json_array == NULL) {
TELEMETRY_LOG_ERR("stat_names_json_array creation failed");
goto fail;
}
uint32_t i;
for (i = 0; i < (uint32_t)num_stat_names; i++) {
ret = json_array_append(stat_names_json_array,
json_string(stat_names[i]));
if (ret < 0) {
TELEMETRY_LOG_ERR("JSON array creation failed");
goto fail;
}
}
ret = json_object_set_new(*data, "stats", stat_names_json_array);
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting 'stats' value in data object failed");
goto fail;
}
}
return 0;
fail:
if (*data)
json_decref(*data);
if (stat_names_json_array)
json_decref(stat_names_json_array);
if (port_ids_json_array)
json_decref(port_ids_json_array);
return -1;
}
static int32_t
rte_telemetry_create_json_request(int action, const char *command,
const char *client_path, int *port_ids, int num_port_ids,
const char * const *stat_names, int num_stat_names, char **request,
int inv_choice)
{
int ret;
json_t *root = json_object();
json_t *data;
if (root == NULL) {
TELEMETRY_LOG_ERR("Could not create root json object");
goto fail;
}
if (inv_choice == INV_ACTION_FIELD) {
ret = json_object_set_new(root, "ac--on", json_integer(action));
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting invalid action field in root object failed");
goto fail;
}
} else {
ret = json_object_set_new(root, "action", json_integer(action));
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting valid action field in root object failed");
goto fail;
}
}
if (inv_choice == INV_COMMAND_FIELD) {
ret = json_object_set_new(root, "co---nd", json_string(command));
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting invalid command field in root object failed");
goto fail;
}
} else {
ret = json_object_set_new(root, "command", json_string(command));
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting valid command field in root object failed");
goto fail;
}
}
data = json_null();
if (client_path) {
data = json_object();
if (data == NULL) {
TELEMETRY_LOG_ERR("Data json object creation failed");
goto fail;
}
ret = json_object_set_new(data, "client_path",
json_string(client_path));
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting valid client_path field in data object failed");
goto fail;
}
} else if (port_ids) {
ret = rte_telemetry_format_port_stat_ids(port_ids, num_port_ids,
stat_names, num_stat_names, &data);
if (ret < 0) {
TELEMETRY_LOG_ERR("Formatting Port/Stat arrays failed");
goto fail;
}
}
if (inv_choice == INV_DATA_FIELD) {
ret = json_object_set_new(root, "d--a", data);
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting invalid data field in data object failed");
goto fail;
}
} else {
ret = json_object_set_new(root, "data", data);
if (ret < 0) {
TELEMETRY_LOG_ERR("Setting valid data field in data object failed");
goto fail;
}
}
*request = json_dumps(root, 0);
if (*request == NULL) {
TELEMETRY_LOG_ERR("Converting JSON root object to char* failed");
goto fail;
}
json_decref(root);
return 0;
fail:
if (root)
json_decref(root);
return -1;
}
static int32_t
rte_telemetry_send_get_ports_and_stats_request(struct telemetry_impl *telemetry,
int action_choice, const char *command_choice, int inv_choice)
{
int ret;
char *request;
const char *client_path_data = NULL;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Telemetry argument has not been initialised");
return -EINVAL;
}
if (inv_choice == INV_ACTION_VAL)
action_choice = -1;
else if (inv_choice == INV_COMMAND_VAL)
command_choice = "INVALID_COMMAND";
else if (inv_choice == INV_DATA_VAL)
client_path_data = "INVALID_DATA";
ret = rte_telemetry_create_json_request(action_choice, command_choice,
client_path_data, NULL, -1, NULL, -1, &request, inv_choice);
if (ret < 0) {
TELEMETRY_LOG_ERR("Could not create JSON Request");
return -1;
}
if (inv_choice == INV_JSON_FORMAT)
request++;
ret = rte_telemetry_parse(telemetry, request);
if (ret < 0) {
TELEMETRY_LOG_WARN("Could not parse JSON Request");
return -1;
}
return 0;
}
static int32_t
rte_telemetry_send_get_ports_details_request(struct telemetry_impl *telemetry,
int action_choice, int *port_ids, int num_port_ids, int inv_choice)
{
int ret;
char *request;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Telemetry argument has not been initialised");
return -EINVAL;
}
const char *command = "ports_details";
if (inv_choice == INV_ACTION_VAL)
action_choice = -1;
else if (inv_choice == INV_COMMAND_VAL)
command = "INVALID_COMMAND";
else if (inv_choice == INV_DATA_VAL)
port_ids = NULL;
ret = rte_telemetry_create_json_request(action_choice, command, NULL,
port_ids, num_port_ids, NULL, -1, &request, inv_choice);
if (ret < 0) {
TELEMETRY_LOG_ERR("Could not create JSON Request");
return -1;
}
if (inv_choice == INV_JSON_FORMAT)
request++;
ret = rte_telemetry_parse(telemetry, request);
if (ret < 0) {
TELEMETRY_LOG_WARN("Could not parse JSON Request");
return -1;
}
return 0;
}
static int32_t
rte_telemetry_send_stats_values_by_name_request(struct telemetry_impl
*telemetry, int action_choice, int *port_ids, int num_port_ids,
const char * const *stat_names, int num_stat_names,
int inv_choice)
{
int ret;
char *request;
const char *command = "ports_stats_values_by_name";
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Telemetry argument has not been initialised");
return -EINVAL;
}
if (inv_choice == INV_ACTION_VAL)
action_choice = -1;
else if (inv_choice == INV_COMMAND_VAL)
command = "INVALID_COMMAND";
else if (inv_choice == INV_DATA_VAL) {
port_ids = NULL;
stat_names = NULL;
}
ret = rte_telemetry_create_json_request(action_choice, command, NULL,
port_ids, num_port_ids, stat_names, num_stat_names, &request,
inv_choice);
if (ret < 0) {
TELEMETRY_LOG_ERR("Could not create JSON Request");
return -1;
}
if (inv_choice == INV_JSON_FORMAT)
request++;
ret = rte_telemetry_parse(telemetry, request);
if (ret < 0) {
TELEMETRY_LOG_WARN("Could not parse JSON Request");
return -1;
}
return 0;
}
static int32_t
rte_telemetry_send_unreg_request(struct telemetry_impl *telemetry,
int action_choice, const char *client_path, int inv_choice)
{
int ret;
char *request;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Telemetry argument has not been initialised");
return -EINVAL;
}
const char *command = "clients";
if (inv_choice == INV_ACTION_VAL)
action_choice = -1;
else if (inv_choice == INV_COMMAND_VAL)
command = "INVALID_COMMAND";
else if (inv_choice == INV_DATA_VAL)
client_path = NULL;
ret = rte_telemetry_create_json_request(action_choice, command,
client_path, NULL, -1, NULL, -1, &request, inv_choice);
if (ret < 0) {
TELEMETRY_LOG_ERR("Could not create JSON Request");
return -1;
}
if (inv_choice == INV_JSON_FORMAT)
request++;
ret = rte_telemetry_parse(telemetry, request);
if (ret < 0) {
TELEMETRY_LOG_WARN("Could not parse JSON Request");
return -1;
}
return 0;
}
int32_t
rte_telemetry_parser_test(struct telemetry_impl *telemetry)
{
int ret;
const char *client_path = TEST_CLIENT;
if (telemetry == NULL) {
TELEMETRY_LOG_ERR("Telemetry argument has not been initialised");
return -EINVAL;
}
ret = rte_telemetry_create_test_socket(telemetry, client_path);
if (ret < 0) {
TELEMETRY_LOG_ERR("Could not create test request client socket");
return -1;
}
int port_ids[] = {0, 1};
int num_port_ids = RTE_DIM(port_ids);
static const char * const stat_names[] = {"tx_good_packets",
"rx_good_packets"};
int num_stat_names = RTE_DIM(stat_names);
static const char * const test_types[] = {
"INVALID ACTION VALUE TESTS",
"INVALID COMMAND VALUE TESTS",
"INVALID DATA VALUE TESTS",
"INVALID ACTION FIELD TESTS",
"INVALID COMMAND FIELD TESTS",
"INVALID DATA FIELD TESTS",
"INVALID JSON FORMAT TESTS",
"VALID TESTS"
};
uint32_t i;
for (i = 0; i < RTE_DIM(test_types); i++) {
TELEMETRY_LOG_INFO("%s", test_types[i]);
ret = rte_telemetry_send_get_ports_and_stats_request(telemetry,
ACTION_GET, "ports", i);
if (ret != 0 && i == VALID_REQ) {
TELEMETRY_LOG_ERR("Get ports valid test failed");
return -EPERM;
} else if (ret != -1 && i != VALID_REQ) {
TELEMETRY_LOG_ERR("Get ports invalid test failed");
return -EPERM;
}
TELEMETRY_LOG_INFO("Success - Get ports test passed");
ret = rte_telemetry_send_get_ports_details_request(telemetry,
ACTION_GET, port_ids, num_port_ids, i);
if (ret != 0 && i == VALID_REQ) {
TELEMETRY_LOG_ERR("Get ports details valid");
return -EPERM;
} else if (ret != -1 && i != VALID_REQ) {
TELEMETRY_LOG_ERR("Get ports details invalid");
return -EPERM;
}
TELEMETRY_LOG_INFO("Success - Get ports details test passed");
ret = rte_telemetry_send_get_ports_and_stats_request(telemetry,
ACTION_GET, "port_stats", i);
if (ret != 0 && i == VALID_REQ) {
TELEMETRY_LOG_ERR("Get port stats valid test");
return -EPERM;
} else if (ret != -1 && i != VALID_REQ) {
TELEMETRY_LOG_ERR("Get ports stats invalid test failed");
return -EPERM;
}
TELEMETRY_LOG_INFO("Success - Get ports stats test passed");
ret = rte_telemetry_send_stats_values_by_name_request(telemetry,
ACTION_GET, port_ids, num_port_ids, stat_names,
num_stat_names, i);
if (ret != 0 && i == VALID_REQ) {
TELEMETRY_LOG_ERR("Get ports stats values by name valid test failed");
return -EPERM;
} else if (ret != -1 && i != VALID_REQ) {
TELEMETRY_LOG_ERR("Get ports stats values by name invalid test failed");
return -EPERM;
}
TELEMETRY_LOG_INFO("Success - Get ports stats values by name test passed");
ret = rte_telemetry_send_unreg_request(telemetry, ACTION_DELETE,
client_path, i);
if (ret != 0 && i == VALID_REQ) {
TELEMETRY_LOG_ERR("Deregister valid test failed");
return -EPERM;
} else if (ret != -1 && i != VALID_REQ) {
TELEMETRY_LOG_ERR("Deregister invalid test failed");
return -EPERM;
}
TELEMETRY_LOG_INFO("Success - Deregister test passed");
}
return 0;
}

View File

@ -1,36 +0,0 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Intel Corporation
*/
#include <stdbool.h>
#include "rte_telemetry_internal.h"
#ifndef _RTE_TELEMETRY_SOCKET_TESTING_H_
#define _RTE_TELEMETRY_SOCKET_TESTING_H_
int32_t
rte_telemetry_json_socket_message_test(struct telemetry_impl *telemetry,
int fd);
int32_t
rte_telemetry_invalid_json_test(struct telemetry_impl *telemetry, int fd);
int32_t
rte_telemetry_valid_json_test(struct telemetry_impl *telemetry, int fd);
int32_t
rte_telemetry_json_contents_test(struct telemetry_impl *telemetry, int fd);
int32_t
rte_telemetry_json_empty_test(struct telemetry_impl *telemetry, int fd);
int32_t
rte_telemetry_socket_register_test(struct telemetry_impl *telemetry, int *fd,
int send_fd, int recv_fd);
int32_t
rte_telemetry_socket_test_setup(struct telemetry_impl *telemetry, int *send_fd,
int *recv_fd);
#endif

View File

@ -10,14 +10,9 @@ EXPERIMENTAL {
rte_tel_data_start_array;
rte_tel_data_start_dict;
rte_tel_data_string;
rte_telemetry_cleanup;
rte_telemetry_init;
rte_telemetry_legacy_register;
rte_telemetry_new_init;
rte_telemetry_parse;
rte_telemetry_register_cmd;
rte_telemetry_selftest;
rte_telemetry_set_metrics_fns;
local: *;
};

View File

@ -14,6 +14,7 @@
#include <rte_common.h>
#include <rte_spinlock.h>
#include <rte_version.h>
#include <rte_option.h>
#include "rte_telemetry.h"
#include "telemetry_json.h"
@ -340,7 +341,7 @@ error:
return -1;
}
static int __rte_unused /* will be used in future commit */
static int
telemetry_legacy_init(const char *runtime_dir)
{
pthread_t t_old;
@ -396,7 +397,7 @@ telemetry_v2_init(const char *runtime_dir)
}
int32_t
rte_telemetry_new_init(void)
rte_telemetry_init(void)
{
const char *error_str;
if (telemetry_v2_init(rte_eal_get_runtime_dir()) != 0) {
@ -404,5 +405,20 @@ rte_telemetry_new_init(void)
printf("Error initialising telemetry - %s", error_str);
return -1;
}
if (telemetry_legacy_init(rte_eal_get_runtime_dir()) != 0) {
error_str = telemetry_log_error;
printf("No telemetry legacy support- %s", error_str);
}
return 0;
}
static struct rte_option option = {
.name = "telemetry",
.usage = "Enable telemetry backend",
.cb = &rte_telemetry_init,
.enabled = 0
};
RTE_INIT(telemetry_register_op) {
rte_option_register(&option);
}