26 #include <rte_errno.h>
28 #include <rte_jhash.h>
29 #include <rte_malloc.h>
36 #define FNV_OFFSET 0xcbf29ce484222325
37 #define FNV_PRIME 0x100000001b3
38 #define DEFAULT_ENTRIES_NUM 128
51 const unsigned char *
byte = (
const unsigned char *)ptr;
53 uint8_t bytes_num =
sizeof(ptr);
55 id_ptr = (uint64_t *)rte_malloc(
NULL,
sizeof(uint64_t), 0);
58 id = (uint64_t)((*
byte++) ^ id) *
FNV_PRIME;
74 struct rte_hash_parameters table_params = {.name =
"Entries Table",
76 .key_len =
sizeof(uint64_t),
77 .hash_func = rte_jhash,
78 .hash_func_init_val = 0};
82 DOCA_LOG_ERR(
"Failed to allocate memory for Flow Pipes Manager pipe_info structure");
91 DOCA_LOG_ERR(
"Failed to allocate memory for Flow Pipes Manager entries");
111 struct rte_hash_parameters table_params = {.name =
"Pipe id to Pipe info Entries",
113 .key_len =
sizeof(uint64_t),
114 .hash_func = rte_jhash,
115 .hash_func_init_val = 0};
119 DOCA_LOG_ERR(
"Failed to allocate memory for Flow Pipes Manager - %s", rte_strerror(rte_errno));
123 (*pipes_manager)->pipe_id_to_pipe_info_table = rte_hash_create(&table_params);
124 if ((*pipes_manager)->pipe_id_to_pipe_info_table ==
NULL) {
126 DOCA_LOG_ERR(
"Failed to allocate memory for Flow Pipes Manager table - %s", rte_strerror(rte_errno));
130 table_params.name =
"Entry id to Pipe id Table";
132 (*pipes_manager)->entry_id_to_pipe_id_table = rte_hash_create(&table_params);
133 if ((*pipes_manager)->entry_id_to_pipe_id_table ==
NULL) {
134 rte_hash_free((*pipes_manager)->pipe_id_to_pipe_info_table);
136 DOCA_LOG_ERR(
"Failed to allocate memory for Flow Pipes Manager table - %s", rte_strerror(rte_errno));
140 table_params.name =
"Port id to Pipe Entries Table";
146 table_params.key_len =
sizeof(uint32_t);
148 (*pipes_manager)->port_id_to_pipes_id_table = rte_hash_create(&table_params);
149 if ((*pipes_manager)->port_id_to_pipes_id_table ==
NULL) {
150 rte_hash_free((*pipes_manager)->pipe_id_to_pipe_info_table);
151 rte_hash_free((*pipes_manager)->entry_id_to_pipe_id_table);
153 DOCA_LOG_ERR(
"Failed to allocate memory for Flow Pipes Manager table - %s", rte_strerror(rte_errno));
162 struct rte_hash *pipes_table;
163 struct doca_flow_pipe_entry *
entry;
165 uint64_t *pipe_id, *generated_entry_id;
166 uint32_t pipe_itr = 0, entry_itr;
170 (
const void **)&pipe_id,
175 (
const void **)&generated_entry_id,
178 rte_free(generated_entry_id);
186 (
const void **)&port_id,
187 (
void **)&pipes_table,
189 rte_hash_free(pipes_table);
198 struct doca_flow_pipe *
pipe,
203 struct rte_hash *pipes_table;
204 struct rte_hash_parameters table_params = {.name =
"Pipe id's only",
206 .key_len =
sizeof(uint64_t),
207 .hash_func = rte_jhash,
208 .hash_func_init_val = 0};
209 uint64_t *generated_pipe_id;
214 uint32_t temp_port_id = (uint32_t)port_id;
215 uint32_t *port_id_key;
217 bool is_new_table =
false;
221 DOCA_LOG_ERR(
"Could not add new pipe with id=%" PRIu64
", id already exists", *generated_pipe_id);
226 (
const void *)&temp_port_id,
227 (
void **)&pipes_table);
232 port_id_key = (uint32_t *)rte_malloc(
NULL,
sizeof(uint32_t), 0);
233 *port_id_key = temp_port_id;
235 pipes_table = rte_hash_create(&table_params);
236 if (pipes_table ==
NULL) {
237 DOCA_LOG_ERR(
"Could not create new pipes table for pipe with id=%" PRIu64
"",
239 rte_free(port_id_key);
240 rte_free(generated_pipe_id);
244 result = rte_hash_add_key(pipes_table, (
const void *)generated_pipe_id);
246 DOCA_LOG_ERR(
"Could not add new pipe with id=%" PRIu64
", to relevant pipes table",
248 rte_hash_free(pipes_table);
249 rte_free(port_id_key);
250 rte_free(generated_pipe_id);
255 (
const void *)port_id_key,
256 (
void *)pipes_table);
258 DOCA_LOG_ERR(
"Could not add new pipes table to port to pipes table");
259 rte_hash_del_key(pipes_table, (
const void *)generated_pipe_id);
260 rte_hash_free(pipes_table);
261 rte_free(port_id_key);
266 result = rte_hash_add_key(pipes_table, (
const void *)generated_pipe_id);
268 DOCA_LOG_ERR(
"Could not add new pipe id=%" PRIu64
" to relevant pipes table",
270 rte_free(generated_pipe_id);
277 DOCA_LOG_ERR(
"Could not add new pipe id=%" PRIu64
" to relevant pipe_info", *generated_pipe_id);
278 rte_hash_del_key(pipes_table, (
const void *)generated_pipe_id);
281 rte_hash_free(pipes_table);
287 (
const void *)generated_pipe_id,
290 DOCA_LOG_ERR(
"Could not add new pipe_info with pipe id=%" PRIu64
" to relevant pipe info table",
292 rte_hash_del_key(pipes_table, (
const void *)generated_pipe_id);
296 rte_hash_free(pipes_table);
301 *pipe_id = *generated_pipe_id;
307 struct doca_flow_pipe_entry *
entry,
311 uint64_t *generated_entry_id, *pipe_id_ptr;
313 struct rte_hash *entries_table;
320 DOCA_LOG_ERR(
"Could not find relevant pipe id, entry was not entered");
325 DOCA_LOG_ERR(
"Could not find relevant pipe id, entry was not entered");
331 if (rte_hash_lookup(entries_table, (
const void *)&generated_entry_id) >= 0) {
332 DOCA_LOG_ERR(
"Could not add new entry with id=%" PRIu64
", id already exists", *generated_entry_id);
336 result = rte_hash_add_key_data(entries_table, (
const void *)generated_entry_id, (
void *)
entry);
338 DOCA_LOG_ERR(
"Could not add new entry with id=%" PRIu64
", to relevant entries table",
339 *generated_entry_id);
340 rte_free(generated_entry_id);
345 (
const void *)generated_entry_id,
346 (
void *)pipe_id_ptr);
348 DOCA_LOG_ERR(
"Could not add new entry with id=%" PRIu64
", to entry-to-pipe table",
349 *generated_entry_id);
350 rte_hash_del_key(entries_table, (
const void *)generated_entry_id);
354 *entry_id = *generated_entry_id;
373 struct doca_flow_pipe_entry **
entry)
376 struct doca_flow_pipe_entry *pipe_entry;
396 struct doca_flow_pipe_entry *
entry, *pipe_id_key;
397 uint64_t *generated_entry_id;
403 if (key_offset < 0) {
404 DOCA_LOG_ERR(
"Could not remove pipe with id=%" PRIu64
", id was not found", pipe_id);
410 DOCA_LOG_ERR(
"Could not remove pipe with id=%" PRIu64
", id was not found", pipe_id);
416 DOCA_LOG_ERR(
"Could not remove pipe with id=%" PRIu64
"", pipe_id);
427 DOCA_LOG_INFO(
"Pipe with id %" PRIu64
" removed successfully", pipe_id);
435 uint64_t *pipe_id, *entry_id_key;
440 if (key_offset < 0) {
441 DOCA_LOG_ERR(
"Could not remove entry with id=%" PRIu64
", id was not found", entry_id);
447 DOCA_LOG_ERR(
"Could not remove entry with id=%" PRIu64
", id was not found", entry_id);
452 DOCA_LOG_ERR(
"Could not remove entry with id=%" PRIu64
", relevant pipe id was not found", entry_id);
457 DOCA_LOG_ERR(
"Could not remove entry with id=%" PRIu64
", id was not found", entry_id);
462 DOCA_LOG_ERR(
"Could not remove entry with id=%" PRIu64
", id was not found", entry_id);
466 DOCA_LOG_INFO(
"Entry with id=%" PRIu64
" removed successfully", entry_id);
473 struct rte_hash *pipes_table;
475 uint64_t *pipe_id, *generated_entry_id, *data;
476 uint32_t pipe_itr = 0;
482 uint32_t temp_port_id = (uint32_t)port_id;
483 uint32_t *port_id_key;
488 (
const void *)&temp_port_id,
489 (
void **)&pipes_table);
491 if (key_offset < 0) {
492 DOCA_LOG_ERR(
"Could not find port with id=%" PRIu16
", aborting flush", port_id);
498 DOCA_LOG_ERR(
"Could not find port with id=%" PRIu16
", aborting flush", port_id);
502 while (rte_hash_iterate(pipes_table, (
const void **)&pipe_id, (
void **)&data, &pipe_itr) >= 0) {
504 (
const void *)pipe_id,
507 DOCA_LOG_ERR(
"Could not find pipe id pipe_info with id=%" PRIu64
", aborting flush", *pipe_id);
513 (
const void **)&generated_entry_id,
522 rte_hash_free(pipes_table);
static struct doca_flow_pipe_entry * entry[MAX_ENTRIES]
doca_error_t pipes_manager_pipe_add_entry(struct flow_pipes_manager *manager, struct doca_flow_pipe_entry *entry, uint64_t pipe_id, uint64_t *entry_id)
doca_error_t pipes_manager_pipe_destroy(struct flow_pipes_manager *manager, uint64_t pipe_id)
doca_error_t pipes_manager_get_pipe(struct flow_pipes_manager *manager, uint64_t pipe_id, struct doca_flow_pipe **pipe)
doca_error_t create_pipes_manager(struct flow_pipes_manager **pipes_manager)
static uint64_t * generateID(void *ptr)
static struct pipe_info * create_pipe_info(struct doca_flow_pipe *pipe, struct rte_hash *pipes_table)
void destroy_pipes_manager(struct flow_pipes_manager *manager)
doca_error_t pipes_manager_pipe_create(struct flow_pipes_manager *manager, struct doca_flow_pipe *pipe, uint16_t port_id, uint64_t *pipe_id)
static void destroy_pipe_info(struct pipe_info *pipe_info)
#define DEFAULT_ENTRIES_NUM
DOCA_LOG_REGISTER(FLOW_PIPES_MANAGER)
doca_error_t pipes_manager_get_entry(struct flow_pipes_manager *manager, uint64_t entry_id, struct doca_flow_pipe_entry **entry)
doca_error_t pipes_manager_pipe_rm_entry(struct flow_pipes_manager *manager, uint64_t entry_id)
doca_error_t pipes_manager_pipes_flush(struct flow_pipes_manager *manager, uint16_t port_id)
enum doca_error doca_error_t
DOCA API return codes.
@ DOCA_ERROR_INVALID_VALUE
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
struct rte_hash * pipe_id_to_pipe_info_table
struct rte_hash * port_id_to_pipes_id_table
struct rte_hash * entry_id_to_pipe_id_table
struct rte_hash * port_id_to_pipes_table
struct rte_hash * entries_table
struct doca_flow_pipe * pipe
static struct flow_pipes_manager * pipes_manager