30 #include <rte_ethdev.h>
37 #include "flow_common.h"
42 #define PACKET_BURST 256
45 #define RANDOM_WIDTH 16
48 #define GET_PERCENTAGE(part, total) (((double)part / (double)total) * 100)
62 struct doca_flow_pipe_cfg *pipe_cfg;
65 memset(&match, 0,
sizeof(match));
67 memset(&
fwd, 0,
sizeof(
fwd));
129 struct doca_flow_pipe *next_pipe,
132 struct doca_flow_pipe_entry **
entry)
137 memset(&match, 0,
sizeof(match));
138 memset(&
fwd, 0,
sizeof(
fwd));
164 struct doca_flow_pipe *distribution_pipe,
165 struct doca_flow_pipe *sampling_pipe,
166 struct doca_flow_pipe_entry **distribution_entry,
167 struct doca_flow_pipe_entry **sampling_entry)
201 double next_highest_supported_percentage = 50;
206 if (percentage >= next_highest_supported_percentage)
209 next_highest_supported_percentage /= 2;
212 if (percentage > next_highest_supported_percentage)
213 DOCA_LOG_WARN(
"Requested %g%% is not supported, converted to %g%% instead",
215 next_highest_supported_percentage);
218 DOCA_LOG_DBG(
"Get random mask 0x%04x for sampling %g%% of traffic", mask, next_highest_supported_percentage);
235 struct doca_flow_pipe **
pipe)
241 struct doca_flow_pipe_cfg *pipe_cfg;
244 memset(&match, 0,
sizeof(match));
247 memset(&
fwd, 0,
sizeof(
fwd));
305 struct doca_flow_pipe_entry **
entry)
309 memset(&match, 0,
sizeof(match));
329 struct doca_flow_pipe **pipe)
334 struct doca_flow_pipe_cfg *pipe_cfg;
338 memset(&
fwd, 0,
sizeof(
fwd));
389 struct doca_flow_pipe_entry *
entry;
395 memset(&
fwd, 0,
sizeof(
fwd));
428 struct doca_flow_pipe_entry *root_entry,
429 struct doca_flow_pipe_entry *random_entry,
430 double requested_percentage)
434 double actuall_percentage;
435 uint32_t total_packets;
445 total_packets = root_query_stats.
counter.total_pkts;
446 if (total_packets == 0)
455 nb_packets = random_query_stats.
counter.total_pkts;
458 DOCA_LOG_INFO(
"Port %d sampling information (%g%% is requested):", port_id, requested_percentage);
459 DOCA_LOG_INFO(
"This pipeline samples %u packets which is %g%% of the traffic (%u/%u)",
478 struct doca_flow_pipe_entry *root_entry)
482 double actuall_percentage, total_percentage = 0;
483 uint32_t total_packets, total_dist_packets = 0;
484 uint16_t nb_packets, nb_hit_queues = 0;
494 total_packets = root_query_stats.
counter.total_pkts;
495 if (total_packets == 0)
500 for (i = 0; i < nb_queues; i++) {
501 nb_packets = rte_eth_rx_burst(port_id, i, packets,
PACKET_BURST);
503 total_dist_packets += nb_packets;
504 total_percentage += actuall_percentage;
505 nb_hit_queues += nb_packets ? 1 : 0;
507 DOCA_LOG_INFO(
"Queue %u received %u packets which is %g%% of the traffic (%u/%u)",
515 DOCA_LOG_INFO(
"The distribution pipe received %u packets which is %g%% of the traffic (%u/%u)",
521 if (nb_hit_queues > 1) {
547 struct doca_flow_pipe *root_pipe;
548 struct doca_flow_pipe *sampling_pipe;
549 struct doca_flow_pipe *distribution_pipe;
550 struct doca_flow_pipe_entry *root2sampling_entry[
nb_ports];
551 struct doca_flow_pipe_entry *root2distribution_entry[
nb_ports];
552 struct doca_flow_pipe_entry *random_entry[
nb_ports];
554 double requested_percentage = 12.5;
555 uint32_t num_of_entries = 3 + nb_rss_queues;
559 memset(&status, 0,
sizeof(status));
568 memset(dev_arr, 0,
sizeof(
struct doca_dev *) *
nb_ports);
577 for (port_id = 0; port_id <
nb_ports; port_id++) {
578 memset(&status, 0,
sizeof(status));
590 DOCA_LOG_ERR(
"Failed to add random distribution pipe entries: %s",
625 &root2distribution_entry[port_id],
626 &root2sampling_entry[port_id]);
646 for (port_id = 0; port_id <
nb_ports; port_id++) {
649 root2sampling_entry[port_id],
650 random_entry[port_id],
651 requested_percentage);
653 DOCA_LOG_ERR(
"Failed to show sampling results in port %u: %s",
664 DOCA_LOG_ERR(
"Failed to show distribution results in port %u: %s",
struct doca_flow_port * init_doca_flow(uint16_t port_id, uint8_t rxq_num)
static doca_error_t destroy_pipe_cfg(struct doca_flow_pipe_cfg *cfg)
static uint16_t * rss_queues
#define BE_IPV4_ADDR(a, b, c, d)
static struct doca_flow_monitor monitor
static struct doca_flow_fwd fwd
static struct doca_flow_match match_mask
static struct doca_flow_pipe_entry * entry[MAX_ENTRIES]
static doca_error_t add_random_sampling_pipe_entry(struct doca_flow_pipe *pipe, struct entries_status *status, struct doca_flow_pipe_entry **entry)
static doca_error_t create_random_sampling_pipe(struct doca_flow_port *port, int port_id, double percentage, struct doca_flow_pipe **pipe)
#define GET_PERCENTAGE(part, total)
doca_error_t flow_random(int nb_steering_queues, int nb_rss_queues)
static doca_error_t random_distribution_results(uint16_t port_id, uint16_t nb_queues, struct doca_flow_pipe_entry *root_entry)
static doca_error_t add_random_distribution_pipe_entries(struct doca_flow_pipe *pipe, int nb_entries, struct entries_status *status)
static doca_error_t add_root_pipe_entries(struct doca_flow_pipe *pipe, struct entries_status *status, struct doca_flow_pipe *distribution_pipe, struct doca_flow_pipe *sampling_pipe, struct doca_flow_pipe_entry **distribution_entry, struct doca_flow_pipe_entry **sampling_entry)
static uint16_t get_random_mask(double percentage)
static doca_error_t create_random_distribution_pipe(struct doca_flow_port *port, int nb_flows, struct doca_flow_pipe **pipe)
static doca_error_t create_root_pipe(struct doca_flow_port *port, struct doca_flow_pipe **pipe)
static doca_error_t random_sampling_results(uint16_t port_id, struct doca_flow_pipe_entry *root_entry, struct doca_flow_pipe_entry *random_entry, double requested_percentage)
DOCA_LOG_REGISTER(FLOW_RANDOM)
static doca_error_t add_root_pipe_entry(struct doca_flow_pipe *pipe, struct doca_flow_pipe *next_pipe, doca_be32_t src_ip_addr, struct entries_status *status, struct doca_flow_pipe_entry **entry)
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_FLOW_L4_TYPE_EXT_TCP
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_destroy(struct doca_flow_pipe_cfg *cfg)
Destroy DOCA Flow pipe configuration struct.
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_create(struct doca_flow_pipe_cfg **cfg, struct doca_flow_port *port)
Create DOCA Flow pipe configuration struct.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_cfg_set_match(struct doca_flow_pipe_cfg *cfg, const struct doca_flow_match *match, const struct doca_flow_match *match_mask)
Set pipe's match and match mask.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_create(const struct doca_flow_pipe_cfg *cfg, const struct doca_flow_fwd *fwd, const struct doca_flow_fwd *fwd_miss, struct doca_flow_pipe **pipe)
Create one new pipe.
doca_flow_flags_type
doca flow flags type
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_cfg_set_monitor(struct doca_flow_pipe_cfg *cfg, const struct doca_flow_monitor *monitor)
Set pipe's monitor.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_add_entry(uint16_t pipe_queue, struct doca_flow_pipe *pipe, const struct doca_flow_match *match, const struct doca_flow_actions *actions, const struct doca_flow_monitor *monitor, const struct doca_flow_fwd *fwd, uint32_t flags, void *usr_ctx, struct doca_flow_pipe_entry **entry)
Add one new entry to a pipe.
DOCA_STABLE void doca_flow_destroy(void)
Destroy the doca flow.
DOCA_EXPERIMENTAL doca_error_t doca_flow_pipe_hash_add_entry(uint16_t pipe_queue, struct doca_flow_pipe *pipe, uint32_t entry_index, const struct doca_flow_actions *actions, const struct doca_flow_monitor *monitor, const struct doca_flow_fwd *fwd, const enum doca_flow_flags_type flags, void *usr_ctx, struct doca_flow_pipe_entry **entry)
Add one new entry to an hash pipe.
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_set_nr_entries(struct doca_flow_pipe_cfg *cfg, uint32_t nr_entries)
Set pipe's maximum number of flow rules.
DOCA_EXPERIMENTAL doca_error_t doca_flow_resource_query_entry(struct doca_flow_pipe_entry *entry, struct doca_flow_resource_query *query_stats)
Extract information about specific entry.
@ DOCA_FLOW_WAIT_FOR_BATCH
@ DOCA_FLOW_RESOURCE_TYPE_NON_SHARED
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_WARN(format,...)
Generates a WARNING application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
#define DOCA_LOG_DBG(format,...)
Generates a DEBUG application log message.
doca_error_t flow_process_entries(struct doca_flow_port *port, struct entries_status *status, uint32_t nr_entries)
doca_error_t stop_doca_flow_ports(int nb_ports, struct doca_flow_port *ports[])
doca_error_t init_doca_flow_ports(int nb_ports, struct doca_flow_port *ports[], bool is_hairpin, struct doca_dev *dev_arr[], uint32_t actions_mem_size[])
doca_error_t set_flow_pipe_cfg(struct doca_flow_pipe_cfg *cfg, const char *name, enum doca_flow_pipe_type type, bool is_root)
#define SHARED_RESOURCE_NUM_VALUES
#define ACTIONS_MEM_SIZE(nr_queues, entries)
#define ARRAY_INIT(array, val)
struct doca_flow_pipe * next_pipe
struct doca_flow_pipe * pipe
enum doca_flow_fwd_type type
enum doca_flow_resource_type rss_type
struct doca_flow_resource_rss_cfg rss
doca flow matcher information
struct doca_flow_parser_meta parser_meta
struct doca_flow_header_format outer
doca monitor action configuration
enum doca_flow_resource_type counter_type
struct doca_flow_resource_query::@115::@117 counter
user context struct that will be used in entries process callback
static uint32_t actions_mem_size[FLOW_SWITCH_PORTS_MAX]
static struct doca_flow_port * ports[FLOW_SWITCH_PORTS_MAX]