30 #include <rte_ethdev.h>
37 #include "flow_common.h"
43 #define RANDOM_WIDTH 16
46 #define RANDOM_TOTAL_RANGE (1 << RANDOM_WIDTH)
49 #define GET_PERCENTAGE(part, total) (((double)part / (double)total) * 100)
52 #define WAITING_TIME 15
63 struct doca_flow_pipe *next_pipe,
64 struct doca_flow_pipe **pipe)
69 struct doca_flow_pipe_cfg *pipe_cfg;
72 memset(&match, 0,
sizeof(match));
74 memset(&
fwd, 0,
sizeof(
fwd));
135 struct doca_flow_pipe_entry **
entry)
139 memset(&match, 0,
sizeof(match));
147 "IPv4(src='1.1.1.1',dst='8.8.8.8') and TCP(src_port=1234,dst_port=80)");
161 uint16_t random_value;
165 random_value = (uint16_t)temp;
168 DOCA_LOG_DBG(
"Using random value 0x%04x for sampling %g%% of traffic (%g%% requested)",
185 struct doca_flow_pipe_cfg *pipe_cfg;
218 struct doca_flow_pipe_entry **
entry)
225 memset(&match, 0,
sizeof(match));
226 memset(&condition, 0,
sizeof(condition));
228 memset(&
fwd, 0,
sizeof(
fwd));
232 condition.
field_op.a.field_string =
"parser_meta.random.value";
233 condition.
field_op.a.bit_offset = 0;
236 condition.
field_op.b.bit_offset = 0;
275 struct doca_flow_pipe_entry *random_entry,
276 double requested_percentage)
280 double actuall_percentage;
281 uint32_t total_packets;
282 uint32_t nb_sampled_packets;
291 total_packets = root_query_stats.
counter.total_pkts;
292 if (total_packets == 0)
301 nb_sampled_packets = random_query_stats.
counter.total_pkts;
302 actuall_percentage =
GET_PERCENTAGE(nb_sampled_packets, total_packets);
304 DOCA_LOG_INFO(
"Sampling result information (%g%% is requested):", requested_percentage);
305 DOCA_LOG_INFO(
"This pipeline samples %u packets which is %g%% of the traffic (%u/%u)",
329 struct doca_flow_port *switch_port;
332 struct doca_flow_pipe *root_pipe;
333 struct doca_flow_pipe *sampling_pipe;
334 struct doca_flow_pipe_entry *root_entry;
335 struct doca_flow_pipe_entry *random_entry;
337 double requested_percentage = 35;
338 uint32_t num_of_entries = 2;
341 memset(&status, 0,
sizeof(status));
350 memset(dev_arr, 0,
sizeof(
struct doca_dev *) *
nb_ports);
351 dev_arr[0] =
ctx->doca_dev[0];
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)
#define BE_IPV4_ADDR(a, b, c, d)
static struct doca_flow_monitor monitor
static struct doca_flow_fwd fwd
static struct doca_flow_pipe_entry * entry[MAX_ENTRIES]
#define RANDOM_TOTAL_RANGE
static doca_error_t create_random_sampling_pipe(struct doca_flow_port *port, struct doca_flow_pipe **pipe)
static doca_error_t add_root_pipe_entry(struct doca_flow_pipe *pipe, struct entries_status *status, struct doca_flow_pipe_entry **entry)
static doca_error_t random_sampling_results(struct doca_flow_pipe_entry *root_entry, struct doca_flow_pipe_entry *random_entry, double requested_percentage)
#define GET_PERCENTAGE(part, total)
static doca_error_t add_random_sampling_pipe_entry(struct doca_flow_pipe *pipe, struct entries_status *status, double percentage, struct doca_flow_pipe_entry **entry)
doca_error_t flow_sampling(int nb_queues, struct flow_switch_ctx *ctx)
static doca_error_t create_root_pipe(struct doca_flow_port *port, struct doca_flow_pipe *next_pipe, struct doca_flow_pipe **pipe)
static uint16_t get_random_value(double percentage)
DOCA_LOG_REGISTER(FLOW_SAMPLING)
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_control_add_entry(uint16_t pipe_queue, uint32_t priority, struct doca_flow_pipe *pipe, const struct doca_flow_match *match, const struct doca_flow_match *match_mask, const struct doca_flow_match_condition *condition, const struct doca_flow_actions *actions, const struct doca_flow_actions *actions_mask, const struct doca_flow_action_descs *action_descs, const struct doca_flow_monitor *monitor, const struct doca_flow_fwd *fwd, void *usr_ctx, struct doca_flow_pipe_entry **entry)
Add one new entry to a control pipe.
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_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_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_STABLE struct doca_flow_port * doca_flow_port_switch_get(const struct doca_flow_port *port)
Get doca flow switch port.
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_RESOURCE_TYPE_NON_SHARED
#define DOCA_LOG_ERR(format,...)
Generates an ERROR 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
doca flow match condition information
enum doca_flow_compare_op operation
struct doca_flow_match_condition::@68::@70 field_op
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]
struct upf_accel_ctx * ctx