1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_compat.h>
10 #ifndef _RTE_TELEMETRY_H_
11 #define _RTE_TELEMETRY_H_
13 /** Maximum length for string used in object. */
14 #define RTE_TEL_MAX_STRING_LEN 64
15 /** Maximum length of string. */
16 #define RTE_TEL_MAX_SINGLE_STRING_LEN 8192
17 /** Maximum number of dictionary entries. */
18 #define RTE_TEL_MAX_DICT_ENTRIES 256
19 /** Maximum number of array entries. */
20 #define RTE_TEL_MAX_ARRAY_ENTRIES 512
29 * All functions in this file may be changed or removed without prior notice.
31 * The telemetry library provides a method to retrieve statistics from
32 * DPDK by sending a request message over a socket. DPDK will send
33 * a JSON encoded response containing telemetry data.
36 /** opaque structure used internally for managing data from callbacks */
40 * The types of data that can be managed in arrays or dicts.
41 * For arrays, this must be specified at creation time, while for
42 * dicts this is specified implicitly each time an element is added
43 * via calling a type-specific function.
45 enum rte_tel_value_type {
46 RTE_TEL_STRING_VAL, /** a string value */
47 RTE_TEL_INT_VAL, /** a signed 32-bit int value */
48 RTE_TEL_U64_VAL, /** an unsigned 64-bit int value */
49 RTE_TEL_CONTAINER, /** a container struct */
53 * Start an array of the specified type for returning from a callback
56 * The data structure passed to the callback
58 * The type of the array of data
60 * 0 on success, negative errno on error
64 rte_tel_data_start_array(struct rte_tel_data *d, enum rte_tel_value_type type);
67 * Start a dictionary of values for returning from a callback
70 * The data structure passed to the callback
72 * 0 on success, negative errno on error
76 rte_tel_data_start_dict(struct rte_tel_data *d);
79 * Set a string for returning from a callback
82 * The data structure passed to the callback
84 * The string to be returned in the data structure
86 * 0 on success, negative errno on error, E2BIG on string truncation
90 rte_tel_data_string(struct rte_tel_data *d, const char *str);
93 * Add a string to an array.
94 * The array must have been started by rte_tel_data_start_array() with
95 * RTE_TEL_STRING_VAL as the type parameter.
98 * The data structure passed to the callback
100 * The string to be returned in the array
102 * 0 on success, negative errno on error, E2BIG on string truncation
106 rte_tel_data_add_array_string(struct rte_tel_data *d, const char *str);
109 * Add an int to an array.
110 * The array must have been started by rte_tel_data_start_array() with
111 * RTE_TEL_INT_VAL as the type parameter.
114 * The data structure passed to the callback
116 * The number to be returned in the array
118 * 0 on success, negative errno on error
122 rte_tel_data_add_array_int(struct rte_tel_data *d, int x);
125 * Add a uint64_t to an array.
126 * The array must have been started by rte_tel_data_start_array() with
127 * RTE_TEL_U64_VAL as the type parameter.
130 * The data structure passed to the callback
132 * The number to be returned in the array
134 * 0 on success, negative errno on error
138 rte_tel_data_add_array_u64(struct rte_tel_data *d, uint64_t x);
141 * Add a container to an array. A container is an existing telemetry data
142 * array. The array the container is to be added to must have been started by
143 * rte_tel_data_start_array() with RTE_TEL_CONTAINER as the type parameter.
144 * The container type must be an array of type uint64_t/int/string.
147 * The data structure passed to the callback
149 * The pointer to the container to be stored in the array.
151 * Flag to indicate that the container memory should not be automatically
152 * freed by the telemetry library once it has finished with the data.
153 * 1 = keep, 0 = free.
155 * 0 on success, negative errno on error
159 rte_tel_data_add_array_container(struct rte_tel_data *d,
160 struct rte_tel_data *val, int keep);
163 * Add a string value to a dictionary.
164 * The dict must have been started by rte_tel_data_start_dict().
167 * The data structure passed to the callback
169 * The name the value is to be stored under in the dict
171 * The string to be stored in the dict
173 * 0 on success, negative errno on error, E2BIG on string truncation of
174 * either name or value.
178 rte_tel_data_add_dict_string(struct rte_tel_data *d, const char *name,
182 * Add an int value to a dictionary.
183 * The dict must have been started by rte_tel_data_start_dict().
186 * The data structure passed to the callback
188 * The name the value is to be stored under in the dict
190 * The number to be stored in the dict
192 * 0 on success, negative errno on error, E2BIG on string truncation of name.
196 rte_tel_data_add_dict_int(struct rte_tel_data *d, const char *name, int val);
199 * Add a uint64_t value to a dictionary.
200 * The dict must have been started by rte_tel_data_start_dict().
203 * The data structure passed to the callback
205 * The name the value is to be stored under in the dict
207 * The number to be stored in the dict
209 * 0 on success, negative errno on error, E2BIG on string truncation of name.
213 rte_tel_data_add_dict_u64(struct rte_tel_data *d,
214 const char *name, uint64_t val);
217 * Add a container to a dictionary. A container is an existing telemetry data
218 * array. The dict the container is to be added to must have been started by
219 * rte_tel_data_start_dict(). The container must be an array of type
220 * uint64_t/int/string.
223 * The data structure passed to the callback
225 * The name the value is to be stored under in the dict.
227 * The pointer to the container to be stored in the dict.
229 * Flag to indicate that the container memory should not be automatically
230 * freed by the telemetry library once it has finished with the data.
231 * 1 = keep, 0 = free.
233 * 0 on success, negative errno on error
237 rte_tel_data_add_dict_container(struct rte_tel_data *d, const char *name,
238 struct rte_tel_data *val, int keep);
241 * This telemetry callback is used when registering a telemetry command.
242 * It handles getting and formatting information to be returned to telemetry
246 * The cmd that was requested by the client.
248 * Contains data required by the callback function.
250 * The information to be returned to the caller.
253 * Length of buffer used on success.
255 * Negative integer on error.
257 typedef int (*telemetry_cb)(const char *cmd, const char *params,
258 struct rte_tel_data *info);
261 * Used for handling data received over a telemetry socket.
264 * ID for the socket to be used by the handler.
269 typedef void * (*handler)(void *sock_id);
272 * Used when registering a command and callback function with telemetry.
275 * The command to register with telemetry.
277 * Callback function to be called when the command is requested.
279 * Help text for the command.
284 * -EINVAL for invalid parameters failure.
286 * -ENOMEM for mem allocation failure.
290 rte_telemetry_register_cmd(const char *cmd, telemetry_cb fn, const char *help);
294 * Get a pointer to a container with memory allocated. The container is to be
295 * used embedded within an existing telemetry dict/array.
298 * Pointer to a container.
301 struct rte_tel_data *
302 rte_tel_data_alloc(void);
306 * Free a container that has memory allocated.
309 * Pointer to container.
314 rte_tel_data_free(struct rte_tel_data *data);