28 #include <rte_ethdev.h>
36 #include "flow_common.h"
38 #define PACKET_BURST 128
81 struct doca_flow_pipe **pipe)
84 struct doca_flow_pipe_cfg *
cfg;
90 memset(&match, 0,
sizeof(match));
91 memset(&
fwd, 0,
sizeof(
fwd));
163 struct doca_flow_pipe **pipe)
166 struct doca_flow_pipe_cfg *
cfg;
171 memset(&match, 0,
sizeof(match));
172 memset(&
fwd, 0,
sizeof(
fwd));
237 struct doca_flow_pipe *fwd_pipe,
239 struct doca_flow_pipe **pipe)
242 struct doca_flow_pipe_cfg *
cfg;
247 memset(&match, 0,
sizeof(match));
248 memset(&
fwd, 0,
sizeof(
fwd));
315 struct doca_flow_pipe *fwd_pipe,
316 struct doca_flow_pipe *fwd_miss_pipe,
317 struct doca_flow_pipe **pipe)
323 struct doca_flow_pipe_cfg *
cfg;
327 memset(&match, 0,
sizeof(match));
328 memset(&mask, 0,
sizeof(mask));
329 memset(&
fwd, 0,
sizeof(
fwd));
406 struct doca_flow_pipe *fwd_pipe,
407 struct doca_flow_pipe *fwd_miss_pipe,
408 struct doca_flow_pipe **pipe)
411 struct doca_flow_pipe_cfg *
cfg;
419 struct doca_flow_actions *actions_mask_list[] = {&meta_action_mask, &nat_action_mask};
422 memset(&match, 0,
sizeof(match));
423 memset(&
fwd, 0,
sizeof(
fwd));
425 memset(&meta_action, 0,
sizeof(meta_action));
426 memset(&nat_action, 0,
sizeof(nat_action));
427 memset(&meta_action_mask, 0,
sizeof(meta_action_mask));
428 memset(&nat_action_mask, 0,
sizeof(nat_action_mask));
438 meta_action.
meta.
u32[0] = UINT32_MAX;
505 const struct rte_tcp_hdr *
tcp_hdr;
507 ipv4_hdr = rte_pktmbuf_mtod_offset(packet,
struct rte_ipv4_hdr *,
sizeof(
struct rte_ether_hdr));
541 uint32_t shared_handle,
542 struct doca_flow_pipe_entry **
entry)
553 int rc, i, nb_packets, nb_process = 0;
555 memset(&match_o, 0,
sizeof(match_o));
556 memset(&match_r, 0,
sizeof(match_r));
557 memset(&action_r, 0,
sizeof(action_r));
558 memset(&shared_action_o, 0,
sizeof(shared_action_o));
564 action_r.
data.action_idx = 1;
566 rc = rte_flow_dynf_metadata_register();
572 nb_packets = rte_eth_rx_burst(0, 0, packets,
PACKET_BURST);
573 if (nb_packets == 0) {
578 DOCA_LOG_INFO(
"%d packets received on rx_burst()", nb_packets);
580 parse_packet(packets[i], &match_o, &match_r, &tcp_state);
583 DOCA_LOG_INFO(
"Already have one alive session, cannot handle more, skip");
632 DOCA_LOG_ERR(
"Flow CT entries process returned with a failure");
637 "TCP session was created, waiting for 'FIN'/'RST' packet before ending the session");
652 DOCA_LOG_WARN(
"Sample is only able to process 'SYN', 'FIN' and 'RST' packets");
655 rte_flow_dynf_metadata_set(packets[i], 1);
656 packets[i]->ol_flags |= RTE_MBUF_DYNFLAG_TX_METADATA;
657 rte_eth_tx_burst(0, 0, &packets[i], 1);
674 uint64_t last_hit_time;
675 memset(&query_stats, 0,
sizeof(query_stats));
676 memset(&miss_stats, 0,
sizeof(miss_stats));
691 printf(
"CT pipe entry: origin_pkts=%ld reply_pkts=%ld\n",
692 query_stats.
counter.total_pkts,
693 miss_stats.
counter.total_pkts);
701 printf(
"Known packets TCP flags filter pipe pkts: %ld\n", query_stats.
counter.total_pkts);
708 printf(
"Unknown packets miss pipe pkts: %ld\n", query_stats.
counter.total_pkts);
715 printf(
"RSS pipe pkts: %ld\n", query_stats.
counter.total_pkts);
722 printf(
"Egress pipe pkts: %ld\n", query_stats.
counter.total_pkts);
740 struct doca_flow_pipe *egress_pipe, *ct_miss_pipe, *tcp_flags_filter_pipe, *rss_pipe, *root_pipe;
741 struct doca_flow_pipe *ct_pipe =
NULL;
744 struct doca_flow_meta o_zone_mask, o_modify_mask, r_zone_mask, r_modify_mask;
748 uint32_t ct_flags, nb_arm_queues = 1, nb_ctrl_queues = 1, nb_user_actions = 4096, nb_ipv4_sessions = 1024,
749 shared_action_handle, nb_ipv6_sessions = 0;
750 uint16_t ct_queue = nb_queues;
753 memset(&ctrl_status, 0,
sizeof(ctrl_status));
754 memset(&ct_status, 0,
sizeof(ct_status));
755 memset(&resource, 0,
sizeof(resource));
756 memset(&shared_action, 0,
sizeof(shared_action));
767 memset(&o_zone_mask, 0,
sizeof(o_zone_mask));
768 memset(&o_modify_mask, 0,
sizeof(o_modify_mask));
769 memset(&r_zone_mask, 0,
sizeof(r_zone_mask));
770 memset(&r_modify_mask, 0,
sizeof(r_modify_mask));
792 memset(dev_arr, 0,
sizeof(
struct doca_dev *) *
nb_ports);
823 shared_action.
data.action_idx = 0;
833 goto cleanup_shared_res;
838 goto cleanup_shared_res;
844 goto cleanup_shared_res;
847 DOCA_LOG_INFO(
"Wait few seconds for 'SYN' packet to arrive");
struct doca_flow_port * init_doca_flow(uint16_t port_id, uint8_t rxq_num)
static void cleanup(struct cache_invalidate_sample_state *state)
doca_error_t init_doca_flow_ct(uint32_t flags, uint32_t nb_arm_queues, uint32_t nb_ctrl_queues, uint32_t nb_user_actions, doca_flow_ct_entry_finalize_cb entry_finalize_cb, uint32_t nb_ipv4_sessions, uint32_t nb_ipv6_sessions, uint32_t dup_filter_sz, bool o_match_inner, struct doca_flow_meta *o_zone_mask, struct doca_flow_meta *o_modify_mask, bool r_match_inner, struct doca_flow_meta *r_zone_mask, struct doca_flow_meta *r_modify_mask)
doca_error_t create_ct_root_pipe(struct doca_flow_port *port, bool is_ipv4, bool is_ipv6, enum doca_flow_l4_meta l4_type, struct doca_flow_pipe *fwd_pipe, struct entries_status *status, struct doca_flow_pipe **pipe)
void cleanup_procedure(struct doca_flow_pipe *ct_pipe, int nb_ports, struct doca_flow_port *ports[])
static struct doca_flow_pipe_entry * ct_miss_entry
doca_error_t flow_ct_tcp_actions(uint16_t nb_queues, struct doca_dev *ct_dev)
DOCA_LOG_REGISTER(FLOW_CT_TCP)
static struct doca_flow_pipe_entry * ct_entry
static doca_error_t process_packets(struct doca_flow_port *port, uint16_t ct_queue, struct entries_status *ct_status, uint32_t shared_handle, struct doca_flow_pipe_entry **entry)
static doca_error_t create_ct_pipe(struct doca_flow_port *port, struct doca_flow_pipe *fwd_pipe, struct doca_flow_pipe *fwd_miss_pipe, struct doca_flow_pipe **pipe)
static struct doca_flow_pipe_entry * egress_entry
static struct doca_flow_pipe_entry * tcp_flags_filter_entry
static doca_error_t create_rss_pipe(struct doca_flow_port *port, struct entries_status *status, struct doca_flow_pipe **pipe)
static doca_error_t create_egress_pipe(struct doca_flow_port *port, int port_id, struct entries_status *status, struct doca_flow_pipe **pipe)
static doca_error_t create_ct_miss_pipe(struct doca_flow_port *port, struct doca_flow_pipe *fwd_pipe, struct entries_status *status, struct doca_flow_pipe **pipe)
static doca_error_t create_tcp_flags_filter_pipe(struct doca_flow_port *port, struct entries_status *status, struct doca_flow_pipe *fwd_pipe, struct doca_flow_pipe *fwd_miss_pipe, struct doca_flow_pipe **pipe)
static struct doca_flow_pipe_entry * rss_entry
static void parse_packet(struct rte_mbuf *packet, struct doca_flow_ct_match *match_o, struct doca_flow_ct_match *match_r, uint8_t *tcp_state)
static doca_error_t print_pipe_counters(uint16_t ct_queue, struct doca_flow_pipe *ct_pipe)
static doca_error_t destroy_pipe_cfg(struct doca_flow_pipe_cfg *cfg)
static struct doca_flow_fwd fwd_miss
static uint16_t * rss_queues
static struct doca_flow_monitor monitor
static struct doca_flow_fwd fwd
static struct doca_flow_pipe_entry * entry[MAX_ENTRIES]
#define DEFAULT_TIMEOUT_US
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_EXPERIMENTAL doca_error_t doca_flow_ct_entries_process(struct doca_flow_port *port, uint16_t pipe_queue, uint32_t min_room, uint32_t max_processed_entries, uint32_t *queue_room)
Process CT entries in queue.
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_query_entry(uint16_t queue, struct doca_flow_pipe *pipe, uint32_t flags, struct doca_flow_pipe_entry *entry, struct doca_flow_resource_query *stats_origin, struct doca_flow_resource_query *stats_reply, uint64_t *last_hit_s)
Extract information about specific entry.
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_actions_add_shared(uint16_t ctrl_queue, struct doca_flow_pipe *pipe, const struct doca_flow_ct_actions actions[], uint32_t nb_actions, uint32_t actions_handles[])
Add shared modify-action.
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_add_entry(uint16_t queue, struct doca_flow_pipe *pipe, uint32_t flags, struct doca_flow_ct_match *match_origin, struct doca_flow_ct_match *match_reply, const struct doca_flow_ct_actions *actions_origin, const struct doca_flow_ct_actions *actions_reply, uint32_t fwd_handle_origin, uint32_t fwd_handle_reply, uint32_t timeout_s, void *usr_ctx, struct doca_flow_pipe_entry *entry)
Add new entry to doca flow CT pipe.
DOCA_EXPERIMENTAL void doca_flow_ct_destroy(void)
Destroy the doca flow ct.
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_actions_rm_shared(uint16_t ctrl_queue, struct doca_flow_pipe *pipe, uint32_t actions_handles[], uint32_t nb_actions)
Remove shared modify-action.
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_rm_entry(uint16_t queue, struct doca_flow_pipe *pipe, uint32_t flags, struct doca_flow_pipe_entry *entry)
remove CT entry.
DOCA_EXPERIMENTAL doca_error_t doca_flow_ct_entry_prepare(uint16_t queue, struct doca_flow_pipe *pipe, uint32_t flags, struct doca_flow_ct_match *match_origin, uint32_t hash_origin, struct doca_flow_ct_match *match_reply, uint32_t hash_reply, struct doca_flow_pipe_entry **entry, bool *conn_found)
Lookup recent CT entry and create on miss.
@ DOCA_FLOW_CT_ENTRY_FLAGS_COUNTER_REPLY
@ DOCA_FLOW_CT_ENTRY_FLAGS_DIR_ORIGIN
@ DOCA_FLOW_CT_ENTRY_FLAGS_NO_WAIT
@ DOCA_FLOW_CT_ENTRY_FLAGS_DIR_REPLY
@ DOCA_FLOW_CT_ENTRY_FLAGS_ALLOC_ON_MISS
@ DOCA_FLOW_CT_ENTRY_FLAGS_COUNTER_ORIGIN
@ DOCA_FLOW_CT_FLAG_NO_AGING
#define DOCA_FLOW_PROTO_TCP
@ DOCA_FLOW_L4_TYPE_EXT_TCP
@ DOCA_FLOW_L4_TYPE_EXT_TRANSPORT
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_STABLE doca_error_t doca_flow_entries_process(struct doca_flow_port *port, uint16_t pipe_queue, uint64_t timeout, uint32_t max_processed_entries)
Process entries in queue.
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_EXPERIMENTAL doca_error_t doca_flow_pipe_cfg_set_actions(struct doca_flow_pipe_cfg *cfg, struct doca_flow_actions *const *actions, struct doca_flow_actions *const *actions_masks, struct doca_flow_action_descs *const *action_descs, size_t nr_actions)
Set pipe's actions, actions mask and actions descriptor.
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_resource_query_entry(struct doca_flow_pipe_entry *entry, struct doca_flow_resource_query *query_stats)
Extract information about specific entry.
@ DOCA_FLOW_MATCH_TCP_FLAG_FIN
@ DOCA_FLOW_MATCH_TCP_FLAG_RST
@ DOCA_FLOW_MATCH_TCP_FLAG_SYN
@ DOCA_FLOW_RESOURCE_TYPE_SHARED
@ 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.
const struct ip_frag_config * cfg
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)
doca flow actions information
struct doca_flow_header_format outer
struct doca_flow_meta meta
enum doca_flow_resource_type resource_type
struct doca_flow_ct_actions::@121::@123 data
struct doca_flow_header_l4_port l4_port
doca flow CT match pattern
struct doca_flow_ct_match4 ipv4
struct doca_flow_pipe * next_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_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]