NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
simple_fwd_ft.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef SIMPLE_FWD_FT_H_
27 #define SIMPLE_FWD_FT_H_
28 
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include <sys/types.h>
32 
33 #include <rte_mbuf.h>
34 
35 #include "simple_fwd_pkt.h"
36 
37 struct simple_fwd_ft; /* Flow table */
38 struct simple_fwd_ft_key; /* Keys flow table */
39 
40 /* Flow table user context */
42  uint32_t fid; /* Forwarding id, used for flow table */
43  uint8_t data[0]; /* A pointer to the flow entry in the flow table as represented in the application */
44 };
45 
46 /* Simple FWD flow entry representation in flow table */
48  LIST_ENTRY(simple_fwd_ft_entry) next; /* Entry pointers in the list */
49  struct simple_fwd_ft_key key; /* Generated key of the entry */
50  uint64_t expiration; /* Expiration time */
51  uint32_t age_sec; /* Age time in seconds */
52  uint64_t last_counter; /* Last HW counter of matched packets */
53  uint64_t sw_ctr; /* SW counter of matched packets */
54  uint8_t hw_off; /* Whether or not the entry was HW offloaded */
55  uint16_t buckets_index; /* The index of the entry in the buckets */
56  struct simple_fwd_ft_user_ctx user_ctx; /* A context that can be stored and used */
57 };
58 LIST_HEAD(simple_fwd_ft_entry_head, simple_fwd_ft_entry); /* Head of the list of the flows as represented in the
59  application */
60 
61 /* Extracting the source IPv4 address for key generating */
62 #define simple_fwd_ft_key_get_ipv4_src(inner, pinfo) \
63  (inner ? simple_fwd_pinfo_inner_ipv4_src(pinfo) : simple_fwd_pinfo_outer_ipv4_src(pinfo))
64 
65 /* Extracting the destination IPv4 address for key generating */
66 #define simple_fwd_ft_key_get_ipv4_dst(inner, pinfo) \
67  (inner ? simple_fwd_pinfo_inner_ipv4_dst(pinfo) : simple_fwd_pinfo_outer_ipv4_dst(pinfo))
68 
69 /* Extracting the source port for key generating */
70 #define simple_fwd_ft_key_get_src_port(inner, pinfo) \
71  (inner ? simple_fwd_pinfo_inner_src_port(pinfo) : simple_fwd_pinfo_outer_src_port(pinfo))
72 
73 /* Extracting the destination port for key generating */
74 #define simple_fwd_ft_key_get_dst_port(inner, pinfo) \
75  (inner ? simple_fwd_pinfo_inner_dst_port(pinfo) : simple_fwd_pinfo_outer_dst_port(pinfo))
76 
77 /*
78  * Create new flow table
79  *
80  * @nb_flows [in]: number of flows
81  * @user_data_size [in]: private data for user
82  * @simple_fwd_aging_cb [in]: function pointer
83  * @simple_fwd_aging_hw_cb [in]: function pointer
84  * @age_thread [in/out]: has dedicated age thread or not
85  * @return: pointer to new allocated flow table and NULL otherwise
86  */
87 struct simple_fwd_ft *simple_fwd_ft_create(int nb_flows,
88  uint32_t user_data_size,
90  void (*simple_fwd_aging_hw_cb)(void),
91  bool age_thread);
92 
93 /*
94  * Destroy flow table
95  *
96  * @ft [in]: flow table to destroy
97  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
98  */
100 
101 /*
102  * Add entry to flow table
103  *
104  * @ft [in]: flow table to add the entry to
105  * @pinfo [in]: the packet info for generating the key for the new entry to add
106  * @ctx [in]: simple fwd user context
107  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
108  */
110  struct simple_fwd_pkt_info *pinfo,
111  struct simple_fwd_ft_user_ctx **ctx);
112 
113 /*
114  * Find if there is an existing entry matching the given packet's info
115  *
116  * @ft [in]: flow table to search in
117  * @pinfo [in]: the packet info for generating the key for the search
118  * @ctx [in]: simple fwd user context
119  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
120  */
122  struct simple_fwd_pkt_info *pinfo,
123  struct simple_fwd_ft_user_ctx **ctx);
124 
125 /*
126  * Remove entry from flow table if found
127  *
128  * @ft [in]: flow table to remove the entry from
129  * @ft_entry [in]: the pointer to the entry to remove
130  */
131 void simple_fwd_ft_destroy_entry(struct simple_fwd_ft *ft, struct simple_fwd_ft_entry *ft_entry);
132 
133 /*
134  * Update aging time of entry in the flow table
135  *
136  * @e [in]: pointer to the entry to update the age time for
137  * @age_sec [in]: time of aging to set for the entry
138  */
139 void simple_fwd_ft_update_age_sec(struct simple_fwd_ft_entry *e, uint32_t age_sec);
140 
141 /*
142  * Updates the expiration time of a given entry in the flow table
143  *
144  * @e [in]: a pointer to the entry to update the eexpiration time for
145  */
147 
148 #endif /* SIMPLE_FWD_FT_H_ */
enum doca_error doca_error_t
DOCA API return codes.
void simple_fwd_ft_update_expiration(struct simple_fwd_ft_entry *e)
Definition: simple_fwd_ft.c:78
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)
LIST_HEAD(simple_fwd_ft_entry_head, simple_fwd_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)
Definition: simple_fwd_ft.c:73
Definition: simple_fwd_ft.h:47
struct simple_fwd_ft_key key
Definition: simple_fwd_ft.h:49
uint16_t buckets_index
Definition: simple_fwd_ft.h:55
LIST_ENTRY(simple_fwd_ft_entry) next
uint32_t age_sec
Definition: simple_fwd_ft.h:51
uint8_t hw_off
Definition: simple_fwd_ft.h:54
uint64_t expiration
Definition: simple_fwd_ft.h:50
uint64_t sw_ctr
Definition: simple_fwd_ft.h:53
struct simple_fwd_ft_user_ctx user_ctx
Definition: simple_fwd_ft.h:56
uint64_t last_counter
Definition: simple_fwd_ft.h:52
pthread_t age_thread
Definition: simple_fwd_ft.c:64
void(* simple_fwd_aging_cb)(struct simple_fwd_ft_user_ctx *ctx)
Definition: simple_fwd_ft.c:67
void(* simple_fwd_aging_hw_cb)(void)
Definition: simple_fwd_ft.c:69
struct upf_accel_ctx * ctx