1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #ifndef __INCLUDE_RTE_TABLE_H__ 6 #define __INCLUDE_RTE_TABLE_H__ 7 8 #ifdef __cplusplus 9 extern "C" { 10 #endif 11 12 /** 13 * @file 14 * RTE Table 15 * 16 * This tool is part of the DPDK Packet Framework tool suite and provides 17 * a standard interface to implement different types of lookup tables for data 18 * plane processing. 19 * 20 * Virtually any search algorithm that can uniquely associate data to a lookup 21 * key can be fitted under this lookup table abstraction. For the flow table 22 * use-case, the lookup key is an n-tuple of packet fields that uniquely 23 * identifies a traffic flow, while data represents actions and action 24 * meta-data associated with the same traffic flow. 25 */ 26 27 #include <stdint.h> 28 #include <rte_port.h> 29 30 struct rte_mbuf; 31 32 /** Lookup table statistics */ 33 struct rte_table_stats { 34 uint64_t n_pkts_in; 35 uint64_t n_pkts_lookup_miss; 36 }; 37 38 /** 39 * Lookup table create 40 * 41 * @param params 42 * Parameters for lookup table creation. The underlying data structure is 43 * different for each lookup table type. 44 * @param socket_id 45 * CPU socket ID (e.g. for memory allocation purpose) 46 * @param entry_size 47 * Data size of each lookup table entry (measured in bytes) 48 * @return 49 * Handle to lookup table instance 50 */ 51 typedef void* (*rte_table_op_create)(void *params, int socket_id, 52 uint32_t entry_size); 53 54 /** 55 * Lookup table free 56 * 57 * @param table 58 * Handle to lookup table instance 59 * @return 60 * 0 on success, error code otherwise 61 */ 62 typedef int (*rte_table_op_free)(void *table); 63 64 /** 65 * Lookup table entry add 66 * 67 * @param table 68 * Handle to lookup table instance 69 * @param key 70 * Lookup key 71 * @param entry 72 * Data to be associated with the current key. This parameter has to point to 73 * a valid memory buffer where the first entry_size bytes (table create 74 * parameter) are populated with the data. 75 * @param key_found 76 * After successful invocation, *key_found is set to a value different than 0 77 * if the current key is already present in the table and to 0 if not. This 78 * pointer has to be set to a valid memory location before the table entry add 79 * function is called. 80 * @param entry_ptr 81 * After successful invocation, *entry_ptr stores the handle to the table 82 * entry containing the data associated with the current key. This handle can 83 * be used to perform further read-write accesses to this entry. This handle 84 * is valid until the key is deleted from the table or the same key is 85 * re-added to the table, typically to associate it with different data. This 86 * pointer has to be set to a valid memory location before the function is 87 * called. 88 * @return 89 * 0 on success, error code otherwise 90 */ 91 typedef int (*rte_table_op_entry_add)( 92 void *table, 93 void *key, 94 void *entry, 95 int *key_found, 96 void **entry_ptr); 97 98 /** 99 * Lookup table entry delete 100 * 101 * @param table 102 * Handle to lookup table instance 103 * @param key 104 * Lookup key 105 * @param key_found 106 * After successful invocation, *key_found is set to a value different than 0 107 * if the current key was present in the table before the delete operation 108 * was performed and to 0 if not. This pointer has to be set to a valid 109 * memory location before the table entry delete function is called. 110 * @param entry 111 * After successful invocation, if the key is found in the table (*key found 112 * is different than 0 after function call is completed) and entry points to 113 * a valid buffer (entry is set to a value different than NULL before the 114 * function is called), then the first entry_size bytes (table create 115 * parameter) in *entry store a copy of table entry that contained the data 116 * associated with the current key before the key was deleted. 117 * @return 118 * 0 on success, error code otherwise 119 */ 120 typedef int (*rte_table_op_entry_delete)( 121 void *table, 122 void *key, 123 int *key_found, 124 void *entry); 125 126 /** 127 * Lookup table entry add bulk 128 * 129 * @param table 130 * Handle to lookup table instance 131 * @param keys 132 * Array containing lookup keys 133 * @param entries 134 * Array containing data to be associated with each key. Every item in the 135 * array has to point to a valid memory buffer where the first entry_size 136 * bytes (table create parameter) are populated with the data. 137 * @param n_keys 138 * Number of keys to add 139 * @param key_found 140 * After successful invocation, key_found for every item in the array is set 141 * to a value different than 0 if the current key is already present in the 142 * table and to 0 if not. This pointer has to be set to a valid memory 143 * location before the table entry add function is called. 144 * @param entries_ptr 145 * After successful invocation, array *entries_ptr stores the handle to the 146 * table entry containing the data associated with every key. This handle can 147 * be used to perform further read-write accesses to this entry. This handle 148 * is valid until the key is deleted from the table or the same key is 149 * re-added to the table, typically to associate it with different data. This 150 * pointer has to be set to a valid memory location before the function is 151 * called. 152 * @return 153 * 0 on success, error code otherwise 154 */ 155 typedef int (*rte_table_op_entry_add_bulk)( 156 void *table, 157 void **keys, 158 void **entries, 159 uint32_t n_keys, 160 int *key_found, 161 void **entries_ptr); 162 163 /** 164 * Lookup table entry delete bulk 165 * 166 * @param table 167 * Handle to lookup table instance 168 * @param keys 169 * Array containing lookup keys 170 * @param n_keys 171 * Number of keys to delete 172 * @param key_found 173 * After successful invocation, key_found for every item in the array is set 174 * to a value different than 0if the current key was present in the table 175 * before the delete operation was performed and to 0 if not. This pointer 176 * has to be set to a valid memory location before the table entry delete 177 * function is called. 178 * @param entries 179 * If entries pointer is NULL, this pointer is ignored for every entry found. 180 * Else, after successful invocation, if specific key is found in the table 181 * (key_found is different than 0 for this item after function call is 182 * completed) and item of entry array points to a valid buffer (entry is set 183 * to a value different than NULL before the function is called), then the 184 * first entry_size bytes (table create parameter) in *entry store a copy of 185 * table entry that contained the data associated with the current key before 186 * the key was deleted. 187 * @return 188 * 0 on success, error code otherwise 189 */ 190 typedef int (*rte_table_op_entry_delete_bulk)( 191 void *table, 192 void **keys, 193 uint32_t n_keys, 194 int *key_found, 195 void **entries); 196 197 /** 198 * Lookup table lookup 199 * 200 * @param table 201 * Handle to lookup table instance 202 * @param pkts 203 * Burst of input packets specified as array of up to 64 pointers to struct 204 * rte_mbuf 205 * @param pkts_mask 206 * 64-bit bitmask specifying which packets in the input burst are valid. When 207 * pkts_mask bit n is set, then element n of pkts array is pointing to a 208 * valid packet. Otherwise, element n of pkts array does not point to a valid 209 * packet, therefore it will not be accessed. 210 * @param lookup_hit_mask 211 * Once the table lookup operation is completed, this 64-bit bitmask 212 * specifies which of the valid packets in the input burst resulted in lookup 213 * hit. For each valid input packet (pkts_mask bit n is set), the following 214 * are true on lookup hit: lookup_hit_mask bit n is set, element n of entries 215 * array is valid and it points to the lookup table entry that was hit. For 216 * each valid input packet (pkts_mask bit n is set), the following are true 217 * on lookup miss: lookup_hit_mask bit n is not set and element n of entries 218 * array is not valid. 219 * @param entries 220 * Once the table lookup operation is completed, this array provides the 221 * lookup table entries that were hit, as described above. It is required 222 * that this array is always pre-allocated by the caller of this function 223 * with exactly 64 elements. The implementation is allowed to speculatively 224 * modify the elements of this array, so elements marked as invalid in 225 * lookup_hit_mask once the table lookup operation is completed might have 226 * been modified by this function. 227 * @return 228 * 0 on success, error code otherwise 229 */ 230 typedef int (*rte_table_op_lookup)( 231 void *table, 232 struct rte_mbuf **pkts, 233 uint64_t pkts_mask, 234 uint64_t *lookup_hit_mask, 235 void **entries); 236 237 /** 238 * Lookup table stats read 239 * 240 * @param table 241 * Handle to lookup table instance 242 * @param stats 243 * Handle to table stats struct to copy data 244 * @param clear 245 * Flag indicating that stats should be cleared after read 246 * 247 * @return 248 * Error code or 0 on success. 249 */ 250 typedef int (*rte_table_op_stats_read)( 251 void *table, 252 struct rte_table_stats *stats, 253 int clear); 254 255 /** Lookup table interface defining the lookup table operation */ 256 struct rte_table_ops { 257 rte_table_op_create f_create; /**< Create */ 258 rte_table_op_free f_free; /**< Free */ 259 rte_table_op_entry_add f_add; /**< Entry add */ 260 rte_table_op_entry_delete f_delete; /**< Entry delete */ 261 rte_table_op_entry_add_bulk f_add_bulk; /**< Add entry bulk */ 262 rte_table_op_entry_delete_bulk f_delete_bulk; /**< Delete entry bulk */ 263 rte_table_op_lookup f_lookup; /**< Lookup */ 264 rte_table_op_stats_read f_stats; /**< Stats */ 265 }; 266 267 #ifdef __cplusplus 268 } 269 #endif 270 271 #endif 272