1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021 Intel Corporation
4 #ifndef __INCLUDE_RTE_SWX_TABLE_LEARNER_H__
5 #define __INCLUDE_RTE_SWX_TABLE_LEARNER_H__
13 * RTE SWX Learner Table
15 * The learner table API.
17 * This table type is typically used for learning or connection tracking, where it allows for the
18 * implementation of the "add on miss" scenario: whenever the lookup key is not found in the table
19 * (lookup miss), the data plane can decide to add this key to the table with a given action with no
20 * control plane intervention. Likewise, the table keys expire based on a configurable timeout and
21 * are thus automatically removed from the table with no control plane intervention.
23 * The keys are not automatically rearmed on lookup hit. To delay the key expiration, the key timer
24 * has to be explicitly reinitialized on lookup hit. The key will be kept in the table as long as it
25 * is frequently hit and explicitly rearmed on every hit.
29 * a) add: Add the current input key (the key that missed the lookup) to the table with given
30 * action, action parameters and expiration timeout. This is the way to populate the
31 * table (which is empty initially). Data plane operation.
32 * b) Do nothing: Keep the current input key out of the table.
34 * a) add: Update the action, action parameters and/or the expiration timeout for the current
35 * input key, which is already in the table. The expiration timer of the key is
36 * automatically rearmed. Data plane operation.
37 * b) rearm: Rearm the expiration timer for the current input key, which is already in the
38 * table. The timeout value used for the expiration timer is either the same as the one
39 * currently associated with the key or a new one can be provided as input. Data plane
41 * c) delete: Delete the current input key from the table. The purpose of this operation is to
42 * force the deletion of the key from the table before the key expires on timeout due
43 * to inactivity. Data plane operation.
44 * d) Do nothing: Keep the expiration timer of the current input key running down. This key
45 * will thus expire naturally, unless it is hit again as part of a subsequent lookup
46 * operation, when the key timer can be rearmed or re-added to prolong its life.
51 #include <rte_compat.h>
53 /** Maximum number of key timeout values per learner table. */
54 #ifndef RTE_SWX_TABLE_LEARNER_N_KEY_TIMEOUTS_MAX
55 #define RTE_SWX_TABLE_LEARNER_N_KEY_TIMEOUTS_MAX 16
58 /** Learner table creation parameters. */
59 struct rte_swx_table_learner_params {
60 /** Key size in bytes. Must be non-zero. */
63 /** Offset of the first byte of the key within the key buffer. */
66 /** Mask of *key_size* bytes logically laid over the bytes at positions
67 * *key_offset* .. (*key_offset* + *key_size* - 1) of the key buffer in order to specify
68 * which bits from the key buffer are part of the key and which ones are not. A bit value of
69 * 1 in the *key_mask0* means the respective bit in the key buffer is part of the key, while
70 * a bit value of 0 means the opposite. A NULL value means that all the bits are part of the
71 * key, i.e. the *key_mask0* is an all-ones mask.
75 /** Maximum size (in bytes) of the action data. The data stored in the table for each entry
76 * is equal to *action_data_size* plus 8 bytes, which are used to store the action ID.
78 uint32_t action_data_size;
80 /** Maximum number of keys to be stored in the table together with their associated data. */
83 /** The set of all possible key timeout values measured in seconds. Each value must be
84 * non-zero. Each table key expires and is automatically deleted from the table after
87 uint32_t *key_timeout;
89 /** Number of possible key timeout values present in the *key_timeout* set. It must be less
90 * than or equal to *RTE_SWX_TABLE_LEARNER_N_KEY_TIMEOUTS_MAX*.
92 uint32_t n_key_timeouts;
96 * Learner table memory footprint get
99 * Table create parameters.
101 * Table memory footprint in bytes.
105 rte_swx_table_learner_footprint_get(struct rte_swx_table_learner_params *params);
108 * Learner table mailbox size get
110 * The mailbox is used to store the context of a lookup operation that is in
111 * progress and it is passed as a parameter to the lookup operation. This allows
112 * for multiple concurrent lookup operations into the same table.
115 * Table mailbox footprint in bytes.
119 rte_swx_table_learner_mailbox_size_get(void);
122 * Learner table create
125 * Table creation parameters.
126 * @param[in] numa_node
127 * Non-Uniform Memory Access (NUMA) node.
129 * Table handle, on success, or NULL, on error.
133 rte_swx_table_learner_create(struct rte_swx_table_learner_params *params, int numa_node);
136 * Learner table key timeout update
140 * @param[in] key_timeout_id
141 * Key timeout ID. Must be less than the configured *n_key_timeouts* value.
142 * @param[in] key_timeout
143 * Key timeout value measured in seconds.
145 * 0 on success or the following error codes otherwise:
146 * -EINVAL: Invalid argument(s).
150 rte_swx_table_learner_timeout_update(void *table,
151 uint32_t key_timeout_id,
152 uint32_t key_timeout);
155 * Learner table key lookup
157 * The table lookup operation searches a given key in the table and upon its completion it returns
158 * an indication of whether the key is found in the table (lookup hit) or not (lookup miss). In case
159 * of lookup hit, the action_id and the action_data associated with the key are also returned.
161 * Multiple invocations of this function may be required in order to complete a single table lookup
162 * operation for a given table and a given lookup key. The completion of the table lookup operation
163 * is flagged by a return value of 1; in case of a return value of 0, the function must be invoked
164 * again with exactly the same arguments.
166 * The mailbox argument is used to store the context of an on-going table key lookup operation, and
167 * possibly an associated key add operation. The mailbox mechanism allows for multiple concurrent
168 * table key lookup and add operations into the same table.
173 * Mailbox for the current table lookup operation.
175 * Current time measured in CPU clock cycles.
177 * Lookup key. Its size must be equal to the table *key_size*.
178 * @param[out] action_id
179 * ID of the action associated with the *key*. Must point to a valid 64-bit variable. Only valid
180 * when the function returns 1 and *hit* is set to true.
181 * @param[out] action_data
182 * Action data for the *action_id* action. Must point to a valid array of table *action_data_size*
183 * bytes. Only valid when the function returns 1 and *hit* is set to true.
185 * Only valid when the function returns 1. Set to non-zero (true) on table lookup hit and to zero
186 * (false) on table lookup miss.
188 * 0 when the table lookup operation is not yet completed, and 1 when the table lookup operation
189 * is completed. No other return values are allowed.
193 rte_swx_table_learner_lookup(void *table,
198 uint8_t **action_data,
202 * Learner table key add
204 * This operation takes the latest key that was looked up in the table and adds it to the table with
205 * the given action ID and action data. Typically, this operation is only invoked when the latest
206 * lookup operation in the current table resulted in lookup miss.
211 * Mailbox for the current operation.
213 * Current time measured in CPU clock cycles.
214 * @param[out] action_id
215 * ID of the action associated with the key.
216 * @param[out] action_data
217 * Action data for the *action_id* action.
218 * @param[in] key_timeout_id
221 * 0 on success, 1 or error (table full).
225 rte_swx_table_learner_add(void *table,
229 uint8_t *action_data,
230 uint32_t key_timeout_id);
233 * Learner table key rearm with same timeout value
235 * This operation takes the latest key that was looked up in the table and, in case of lookup hit,
236 * it rearms its expiration timer using the same timeout value currently associated with the key.
241 * Mailbox for the current operation.
243 * Current time measured in CPU clock cycles.
247 rte_swx_table_learner_rearm(void *table,
252 * Learner table key rearm with given timeout value
254 * This operation takes the latest key that was looked up in the table and, in case of lookup hit,
255 * it rearms its expiration timer using the given timeout value.
260 * Mailbox for the current operation.
262 * Current time measured in CPU clock cycles.
263 * @param[in] key_timeout_id
268 rte_swx_table_learner_rearm_new(void *table,
271 uint32_t key_timeout_id);
274 * Learner table key delete
276 * This operation takes the latest key that was looked up in the table and deletes it from the
277 * table. Typically, this operation is only invoked to force the deletion of the key before the key
278 * expires on timeout due to inactivity.
283 * Mailbox for the current operation.
287 rte_swx_table_learner_delete(void *table,
298 rte_swx_table_learner_free(void *table);