[v3,5/8] fib6: make lookup function type configurable
Checks
Commit Message
Add type argument to trie_get_lookup_fn()
Now it only supports RTE_FIB6_TRIE_SCALAR
Add new rte_fib6_set_lookup_fn() - user can change lookup
function type runtime.
Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
lib/librte_fib/rte_fib6.c | 19 ++++++++++++++++++-
lib/librte_fib/rte_fib6.h | 20 ++++++++++++++++++++
lib/librte_fib/rte_fib_version.map | 1 +
lib/librte_fib/trie.c | 25 ++++++++++++++-----------
lib/librte_fib/trie.h | 2 +-
5 files changed, 54 insertions(+), 13 deletions(-)
@@ -107,7 +107,7 @@ init_dataplane(struct rte_fib6 *fib, __rte_unused int socket_id,
fib->dp = trie_create(dp_name, socket_id, conf);
if (fib->dp == NULL)
return -rte_errno;
- fib->lookup = rte_trie_get_lookup_fn(conf);
+ fib->lookup = trie_get_lookup_fn(fib->dp, RTE_FIB6_TRIE_SCALAR);
fib->modify = trie_modify;
return 0;
default:
@@ -319,3 +319,20 @@ rte_fib6_get_rib(struct rte_fib6 *fib)
{
return (fib == NULL) ? NULL : fib->rib;
}
+
+int
+rte_fib6_set_lookup_fn(struct rte_fib6 *fib, int type)
+{
+ rte_fib6_lookup_fn_t fn;
+
+ switch (fib->type) {
+ case RTE_FIB6_TRIE:
+ fn = trie_get_lookup_fn(fib->dp, type);
+ if (fn == NULL)
+ return -EINVAL;
+ fib->lookup = fn;
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
@@ -52,6 +52,10 @@ enum rte_fib_trie_nh_sz {
RTE_FIB6_TRIE_8B
};
+enum rte_fib_trie_lookup_type {
+ RTE_FIB6_TRIE_SCALAR
+};
+
/** FIB configuration structure */
struct rte_fib6_conf {
enum rte_fib6_type type; /**< Type of FIB struct */
@@ -194,6 +198,22 @@ __rte_experimental
struct rte_rib6 *
rte_fib6_get_rib(struct rte_fib6 *fib);
+/**
+ * Set lookup function based on type
+ *
+ * @param fib
+ * FIB object handle
+ * @param type
+ * type of lookup function
+ *
+ * @return
+ * -EINVAL on failure
+ * 0 on success
+ */
+__rte_experimental
+int
+rte_fib6_set_lookup_fn(struct rte_fib6 *fib, int type);
+
#ifdef __cplusplus
}
#endif
@@ -19,6 +19,7 @@ EXPERIMENTAL {
rte_fib6_lookup_bulk;
rte_fib6_get_dp;
rte_fib6_get_rib;
+ rte_fib6_set_lookup_fn;
local: *;
};
@@ -59,13 +59,6 @@ enum edge {
REDGE
};
-enum lookup_type {
- MACRO,
- INLINE,
- UNI
-};
-static enum lookup_type test_lookup = MACRO;
-
static inline uint32_t
get_tbl24_idx(const uint8_t *ip)
{
@@ -154,11 +147,18 @@ LOOKUP_FUNC(4b, uint32_t, 2)
LOOKUP_FUNC(8b, uint64_t, 3)
rte_fib6_lookup_fn_t
-rte_trie_get_lookup_fn(struct rte_fib6_conf *conf)
+trie_get_lookup_fn(void *p, enum rte_fib_trie_lookup_type type)
{
- enum rte_fib_trie_nh_sz nh_sz = conf->trie.nh_sz;
+ enum rte_fib_trie_nh_sz nh_sz;
+ struct rte_trie_tbl *dp = p;
- if (test_lookup == MACRO) {
+ if (dp == NULL)
+ return NULL;
+
+ nh_sz = dp->nh_sz;
+
+ switch (type) {
+ case RTE_FIB6_TRIE_SCALAR:
switch (nh_sz) {
case RTE_FIB6_TRIE_2B:
return rte_trie_lookup_bulk_2b;
@@ -166,9 +166,12 @@ rte_trie_get_lookup_fn(struct rte_fib6_conf *conf)
return rte_trie_lookup_bulk_4b;
case RTE_FIB6_TRIE_8B:
return rte_trie_lookup_bulk_8b;
+ default:
+ return NULL;
}
+ default:
+ return NULL;
}
-
return NULL;
}
@@ -22,7 +22,7 @@ void
trie_free(void *p);
rte_fib6_lookup_fn_t
-rte_trie_get_lookup_fn(struct rte_fib6_conf *fib_conf);
+trie_get_lookup_fn(void *p, enum rte_fib_trie_lookup_type type);
int
trie_modify(struct rte_fib6 *fib, const uint8_t ip[RTE_FIB6_IPV6_ADDR_SIZE],