29 #include <arpa/inet.h>
31 #include <rte_random.h>
45 #define BE_IPV4_ADDR(a, b, c, d) (RTE_BE32(((uint32_t)a << 24) + (b << 16) + (c << 8) + d))
48 #define SET_MAC_ADDR(addr, a, b, c, d, e, f) \
59 #define SET_L4_PORT(layer, port, value) \
61 if (match->layer.l4_type_ext == DOCA_FLOW_L4_TYPE_EXT_TCP) \
62 match->layer.tcp.l4_port.port = (value); \
63 else if (match->layer.l4_type_ext == DOCA_FLOW_L4_TYPE_EXT_UDP) \
64 match->layer.udp.l4_port.port = (value); \
71 #define GET_FT_ENTRY(ctx) container_of(ctx, struct simple_fwd_ft_entry, user_ctx)
73 #define PULL_TIME_OUT 10000
74 #define NB_ACTION_ARRAY (1)
75 #define NB_ACTION_DESC (1)
108 if (entry_status ==
NULL)
135 struct doca_flow_cfg *flow_cfg;
206 struct doca_flow_port_cfg *port_cfg;
208 struct doca_flow_port *port;
219 goto destroy_port_cfg;
225 goto destroy_port_cfg;
233 goto destroy_port_cfg;
239 goto destroy_port_cfg;
262 for (portid = 0; portid <
nb_ports; portid++) {
280 for (portid = 0; portid <
nb_ports; portid++) {
289 if (!is_hairpin || !portid || !(portid % 2))
397 struct doca_flow_pipe_cfg *pipe_cfg;
398 struct doca_flow_pipe_entry *
entry;
403 int num_of_entries = 1;
407 memset(&match, 0,
sizeof(match));
409 memset(&
fwd, 0,
sizeof(
fwd));
440 for (i = 0; i < port_cfg->
nb_queues; i++)
497 struct doca_flow_pipe_cfg *pipe_cfg;
498 struct doca_flow_pipe_entry *
entry;
502 int num_of_entries = 1;
505 memset(&match, 0,
sizeof(match));
507 memset(&
fwd, 0,
sizeof(
fwd));
641 struct doca_flow_pipe_cfg *pipe_cfg;
642 struct doca_flow_pipe **pipe;
643 const char *pipe_name;
646 memset(&match, 0,
sizeof(match));
648 memset(&descs, 0,
sizeof(descs));
650 memset(&
fwd, 0,
sizeof(
fwd));
660 pipe_name =
"VXLAN_PIPE";
671 pipe_name =
"GTP_FWD";
685 pipe_name =
"GRE_PIPE";
767 struct doca_flow_pipe_cfg *pipe_cfg;
816 struct doca_flow_pipe_entry *
entry;
819 uint8_t priority = 0;
826 memset(&match, 0,
sizeof(match));
827 memset(&
fwd, 0,
sizeof(
fwd));
855 memset(&match, 0,
sizeof(match));
856 memset(&
fwd, 0,
sizeof(
fwd));
883 memset(&match, 0,
sizeof(match));
884 memset(&
fwd, 0,
sizeof(
fwd));
912 memset(&match, 0,
sizeof(match));
913 memset(&
fwd, 0,
sizeof(
fwd));
959 struct doca_flow_pipe_cfg *pipe_cfg;
962 memset(&match, 0,
sizeof(match));
965 memset(&
fwd, 0,
sizeof(
fwd));
1044 struct doca_flow_pipe_entry *
entry;
1047 int num_of_entries = 1;
1051 uint8_t encap_ttl = 17;
1053 uint8_t src_mac[] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
1054 uint8_t dst_mac[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
1058 memset(&match, 0,
sizeof(match));
1060 memset(status, 0,
sizeof(*status));
1182 DOCA_LOG_ERR(
"Failed adding entries to the control pipe");
1256 switch (pkt_l4_type) {
1265 DOCA_LOG_WARN(
"The L4 type %u is not supported", pkt_l4_type);
1290 memset(match, 0x0,
sizeof(*match));
1358 struct doca_flow_pipe *pipe;
1359 struct doca_flow_pipe_entry *
entry;
1361 int num_of_entries = 1;
1366 memset(&match, 0,
sizeof(match));
1450 entry->is_hw =
true;
1493 entry->total_pkts++;
1506 #define MAX_HANDLING_TIME_MS 10
if(bitoffset % 64+bitlength > 64) result|
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_actions actions
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]
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
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
doca flow layer 4 packet extend type
#define DOCA_FLOW_VXLAN_DEFAULT_PORT
#define DOCA_FLOW_PROTO_GRE
#define DOCA_FLOW_PROTO_UDP
#define DOCA_FLOW_PROTO_TCP
#define DOCA_FLOW_GTPU_DEFAULT_PORT
doca_flow_tun_type
doca flow tunnel type
#define DOCA_FLOW_ETHER_TYPE_IPV4
#define DOCA_FLOW_ETHER_ADDR_LEN
@ DOCA_FLOW_L4_TYPE_EXT_TCP
@ DOCA_FLOW_L4_TYPE_EXT_NONE
@ DOCA_FLOW_L4_TYPE_EXT_UDP
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_cfg_set_mode_args(struct doca_flow_cfg *cfg, const char *mode_args)
Set DOCA mode args.
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_STABLE doca_error_t doca_flow_pipe_cfg_set_name(struct doca_flow_pipe_cfg *cfg, const char *name)
Set pipe's name.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_pair(struct doca_flow_port *port, struct doca_flow_port *pair_port)
pair two doca flow ports.
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_STABLE doca_error_t doca_flow_cfg_set_nr_meters(struct doca_flow_cfg *cfg, uint32_t nr_meters)
Set number of traffic meters to configure.
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_port_start(const struct doca_flow_port_cfg *cfg, struct doca_flow_port **port)
Start a doca port.
doca_flow_entry_op
doca flow entry operation
DOCA_STABLE doca_error_t doca_flow_cfg_set_cb_entry_process(struct doca_flow_cfg *cfg, doca_flow_entry_process_cb cb)
Set callback for entry create/destroy.
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_set_is_root(struct doca_flow_pipe_cfg *cfg, bool is_root)
Set if pipe is root or not.
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_STABLE doca_error_t doca_flow_cfg_create(struct doca_flow_cfg **cfg)
Create DOCA Flow configuration struct.
DOCA_STABLE uint8_t * doca_flow_port_priv_data(struct doca_flow_port *port)
Get pointer of user private data.
#define DOCA_FLOW_MAX_ENTRY_ACTIONS_MEM_SIZE
meter mark color
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_set_type(struct doca_flow_pipe_cfg *cfg, enum doca_flow_pipe_type type)
Set pipe's type.
DOCA_STABLE doca_error_t doca_flow_port_cfg_set_priv_data_size(struct doca_flow_port_cfg *cfg, uint16_t priv_data_size)
Set user private data size.
DOCA_EXPERIMENTAL doca_error_t doca_flow_init(struct doca_flow_cfg *cfg)
Initialize the doca flow.
DOCA_STABLE doca_error_t doca_flow_cfg_set_nr_counters(struct doca_flow_cfg *cfg, uint32_t nr_counters)
Set number of counters to configure.
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_port_cfg_set_actions_mem_size(struct doca_flow_port_cfg *cfg, uint32_t size)
Set max memory size used by actions.
DOCA_STABLE int doca_flow_aging_handle(struct doca_flow_port *port, uint16_t queue, uint64_t quota, uint64_t max_entries)
Handle aging of entries.
DOCA_STABLE doca_error_t doca_flow_port_stop(struct doca_flow_port *port)
Stop a doca port.
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 doca_error_t doca_flow_pipe_remove_entry(uint16_t pipe_queue, uint32_t flags, struct doca_flow_pipe_entry *entry)
Free one pipe entry.
doca_flow_entry_status
doca flow entry status
DOCA_STABLE void doca_flow_destroy(void)
Destroy the doca flow.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_cfg_set_port_id(struct doca_flow_port_cfg *cfg, uint16_t port_id)
Set the logical port ID.
DOCA_EXPERIMENTAL doca_error_t doca_flow_cfg_set_default_rss(struct doca_flow_cfg *cfg, const struct doca_flow_resource_rss_cfg *rss)
Set RSS global configuration.
DOCA_STABLE doca_error_t doca_flow_port_cfg_create(struct doca_flow_port_cfg **cfg)
Create DOCA Flow port configuration struct.
DOCA_STABLE doca_error_t doca_flow_port_cfg_destroy(struct doca_flow_port_cfg *cfg)
Destroy DOCA Flow port configuration struct.
DOCA_STABLE doca_error_t doca_flow_cfg_set_pipe_queues(struct doca_flow_cfg *cfg, uint16_t pipe_queues)
Set pipe queues.
DOCA_STABLE doca_error_t doca_flow_pipe_cfg_set_domain(struct doca_flow_pipe_cfg *cfg, enum doca_flow_pipe_domain domain)
Set pipe's domain.
DOCA_STABLE doca_error_t doca_flow_cfg_destroy(struct doca_flow_cfg *cfg)
Destroy DOCA Flow configuration struct.
@ DOCA_FLOW_ENTRY_OP_AGED
@ DOCA_FLOW_RESOURCE_TYPE_NON_SHARED
@ DOCA_FLOW_ENTRY_STATUS_SUCCESS
@ DOCA_FLOW_PIPE_DOMAIN_EGRESS
#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_DBG(format,...)
Generates a DEBUG application log message.
struct app_vnf * simple_fwd_get_vnf(void)
static struct doca_flow_pipe * simple_fwd_select_pipe(struct simple_fwd_pkt_info *pinfo)
static struct doca_flow_pipe_entry * simple_fwd_pipe_add_entry(struct simple_fwd_pkt_info *pinfo, void *user_ctx, uint32_t *age_sec)
static int simple_fwd_destroy(void)
DOCA_LOG_REGISTER(SIMPLE_FWD)
static int simple_fwd_build_rss_flow(uint16_t port_id)
static int simple_fwd_destroy_ins(void)
static int simple_fwd_init_doca_flow(int nb_queues, const char *mode, uint32_t nr_counters, uint32_t nr_meters)
static int simple_fwd_dump_stats(uint32_t port_id)
static void simple_fwd_build_entry_match(struct simple_fwd_pkt_info *pinfo, struct doca_flow_match *match)
static bool simple_fwd_need_new_ft(struct simple_fwd_pkt_info *pinfo)
static int simple_fwd_add_control_pipe_entries(struct simple_fwd_port_cfg *port_cfg)
#define SET_L4_PORT(layer, port, value)
static void simple_fwd_match_set_tun(struct simple_fwd_pkt_info *pinfo, struct doca_flow_match *match)
static void simple_fwd_build_entry_actions(struct doca_flow_actions *actions)
static struct doca_flow_port * simple_fwd_create_doca_flow_port(int port_id)
static int simple_fwd_create_control_pipe(struct simple_fwd_port_cfg *port_cfg)
static doca_error_t simple_fwd_create_vxlan_encap_pipe(struct simple_fwd_port_cfg *port_cfg)
static void simple_fwd_aged_flow_cb(struct simple_fwd_ft_user_ctx *ctx)
static int simple_fwd_init(void *p)
#define BE_IPV4_ADDR(a, b, c, d)
static int simple_fwd_create_ins(struct simple_fwd_port_cfg *port_cfg)
static int simple_fwd_handle_new_flow(struct simple_fwd_pkt_info *pinfo, struct simple_fwd_ft_user_ctx **ctx)
static struct simple_fwd_app * simple_fwd_ins
#define SET_MAC_ADDR(addr, a, b, c, d, e, f)
static int simple_fwd_init_doca_flow_ports(int nb_ports, struct doca_flow_port *ports[], bool is_hairpin)
static void simple_fwd_stop_doca_flow_ports(int nb_ports, struct doca_flow_port *ports[])
static int simple_fwd_build_hairpin_flow(uint16_t port_id)
static void simple_fwd_build_entry_monitor(struct simple_fwd_pkt_info *pinfo, struct doca_flow_monitor *monitor)
static int simple_fwd_handle_packet(struct simple_fwd_pkt_info *pinfo)
static void simple_fwd_build_fwd(struct simple_fwd_port_cfg *port_cfg, struct doca_flow_fwd *fwd)
static int simple_fwd_init_ports_and_pipes(struct simple_fwd_port_cfg *port_cfg)
#define GET_FT_ENTRY(ctx)
static void simple_fwd_handle_aging(uint32_t port_id, uint16_t queue)
static void simple_fwd_check_for_valid_entry(struct doca_flow_pipe_entry *entry, uint16_t pipe_queue, enum doca_flow_entry_status status, enum doca_flow_entry_op op, void *user_ctx)
static struct app_vnf simple_fwd_vnf
static enum doca_flow_l4_type_ext simple_fwd_l3_type_transfer(uint8_t pkt_l4_type)
static int simple_fwd_create_match_pipe(struct simple_fwd_port_cfg *port_cfg, enum doca_flow_tun_type type)
#define MAX_HANDLING_TIME_MS
static doca_error_t simple_fwd_add_vxlan_encap_pipe_entry(struct simple_fwd_port_cfg *port_cfg)
static void simple_fwd_build_pipe_common_match_fields(struct doca_flow_match *match)
#define SIMPLE_FWD_MAX_FLOWS
void simple_fwd_ft_update_expiration(struct simple_fwd_ft_entry *e)
struct simple_fwd_ft * simple_fwd_ft_create(int nb_flows, uint32_t user_data_size, void(*simple_fwd_aging_cb)(struct simple_fwd_ft_user_ctx *ctx), void(*simple_fwd_aging_hw_cb)(void), bool age_thread)
doca_error_t simple_fwd_ft_find(struct simple_fwd_ft *ft, struct simple_fwd_pkt_info *pinfo, struct simple_fwd_ft_user_ctx **ctx)
doca_error_t simple_fwd_ft_destroy(struct simple_fwd_ft *ft)
void simple_fwd_ft_destroy_entry(struct simple_fwd_ft *ft, struct simple_fwd_ft_entry *ft_entry)
doca_error_t simple_fwd_ft_add_new(struct simple_fwd_ft *ft, struct simple_fwd_pkt_info *pinfo, struct simple_fwd_ft_user_ctx **ctx)
void simple_fwd_ft_update_age_sec(struct simple_fwd_ft_entry *e, uint32_t age_sec)
doca_be16_t simple_fwd_pinfo_inner_dst_port(struct simple_fwd_pkt_info *pinfo)
doca_be16_t simple_fwd_pinfo_outer_dst_port(struct simple_fwd_pkt_info *pinfo)
doca_be32_t simple_fwd_pinfo_outer_ipv4_src(struct simple_fwd_pkt_info *pinfo)
doca_be16_t simple_fwd_pinfo_inner_src_port(struct simple_fwd_pkt_info *pinfo)
doca_be16_t simple_fwd_pinfo_outer_src_port(struct simple_fwd_pkt_info *pinfo)
doca_be32_t simple_fwd_pinfo_inner_ipv4_src(struct simple_fwd_pkt_info *pinfo)
doca_be32_t simple_fwd_pinfo_inner_ipv4_dst(struct simple_fwd_pkt_info *pinfo)
uint8_t * simple_fwd_pinfo_outer_mac_src(struct simple_fwd_pkt_info *pinfo)
doca_be32_t simple_fwd_pinfo_outer_ipv4_dst(struct simple_fwd_pkt_info *pinfo)
uint8_t * simple_fwd_pinfo_outer_mac_dst(struct simple_fwd_pkt_info *pinfo)
int simple_fwd_dump_port_stats(uint16_t port_id, struct doca_flow_port *port)
doca flow actions information
struct doca_flow_resource_encap_cfg encap_cfg
struct doca_flow_header_format outer
enum doca_flow_resource_type encap_type
struct doca_flow_meta meta
enum doca_flow_resource_type decap_type
struct doca_flow_resource_decap_cfg decap_cfg
struct doca_flow_header_format outer
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 inner
struct doca_flow_parser_meta parser_meta
struct doca_flow_header_format outer
struct doca_flow_meta meta
doca monitor action configuration
enum doca_flow_resource_type counter_type
struct doca_flow_encap_action encap
enum doca_flow_tun_type type
user context struct that will be used in entries process callback
struct doca_flow_pipe * pipe_rss[SIMPLE_FWD_PORTS]
struct doca_flow_pipe * pipe_vxlan[SIMPLE_FWD_PORTS]
struct simple_fwd_ft * ft
struct doca_flow_pipe * pipe_hairpin[SIMPLE_FWD_PORTS]
struct doca_flow_port * ports[SIMPLE_FWD_PORTS]
struct doca_flow_pipe * pipe_gre[SIMPLE_FWD_PORTS]
struct doca_flow_pipe * vxlan_encap_pipe[SIMPLE_FWD_PORTS]
struct doca_flow_pipe * pipe_control[SIMPLE_FWD_PORTS]
struct doca_flow_pipe * pipe_gtp[SIMPLE_FWD_PORTS]
uint16_t hairpin_peer[SIMPLE_FWD_PORTS]
struct simple_fwd_pkt_format outer
enum doca_flow_tun_type tun_type
struct simple_fwd_pkt_format inner
struct simple_fwd_pkt_tun_format tun
static struct doca_flow_port * ports[FLOW_SWITCH_PORTS_MAX]
struct upf_accel_ctx * ctx
void linear_array_init_u16(uint16_t *array, uint16_t n)