43 #include <sys/queue.h>
48 #include <rte_config.h>
52 #include <rte_compat.h>
59 #define RTE_LPM_NAMESIZE 32
62 #define RTE_LPM_MAX_DEPTH 32
65 #define RTE_LPM_TBL24_NUM_ENTRIES (1 << 24)
68 #define RTE_LPM_TBL8_GROUP_NUM_ENTRIES 256
71 #define RTE_LPM_MAX_TBL8_NUM_GROUPS (1 << 24)
74 #define RTE_LPM_TBL8_NUM_GROUPS 256
77 #define RTE_LPM_TBL8_NUM_ENTRIES (RTE_LPM_TBL8_NUM_GROUPS * \
78 RTE_LPM_TBL8_GROUP_NUM_ENTRIES)
81 #if defined(RTE_LIBRTE_LPM_DEBUG)
82 #define RTE_LPM_RETURN_IF_TRUE(cond, retval) do { \
83 if (cond) return (retval); \
86 #define RTE_LPM_RETURN_IF_TRUE(cond, retval)
90 #define RTE_LPM_VALID_EXT_ENTRY_BITMASK 0x03000000
93 #define RTE_LPM_LOOKUP_SUCCESS 0x01000000
95 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
98 struct rte_lpm_tbl_entry_v20 {
118 uint8_t valid_group :1;
123 struct rte_lpm_tbl_entry {
129 uint32_t next_hop :24;
139 uint32_t valid_group :1;
145 struct rte_lpm_tbl_entry_v20 {
147 uint8_t valid_group :1;
156 struct rte_lpm_tbl_entry {
158 uint32_t valid_group :1;
160 uint32_t next_hop :24;
174 struct rte_lpm_rule_v20 {
179 struct rte_lpm_rule {
185 struct rte_lpm_rule_info {
198 struct rte_lpm_tbl_entry_v20 tbl24[RTE_LPM_TBL24_NUM_ENTRIES]
200 struct rte_lpm_tbl_entry_v20 tbl8[RTE_LPM_TBL8_NUM_ENTRIES]
202 struct rte_lpm_rule_v20 rules_tbl[]
210 uint32_t number_tbl8s;
214 struct rte_lpm_tbl_entry tbl24[RTE_LPM_TBL24_NUM_ENTRIES]
216 struct rte_lpm_tbl_entry *tbl8;
217 struct rte_lpm_rule *rules_tbl;
243 rte_lpm_create_v20(
const char *name,
int socket_id,
int max_rules,
int flags);
245 rte_lpm_create_v1604(
const char *name,
int socket_id,
261 rte_lpm_find_existing_v20(
const char *name);
263 rte_lpm_find_existing_v1604(
const char *name);
276 rte_lpm_free_v20(
struct rte_lpm_v20 *lpm);
278 rte_lpm_free_v1604(
struct rte_lpm *lpm);
295 rte_lpm_add(
struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t next_hop);
297 rte_lpm_add_v20(
struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
300 rte_lpm_add_v1604(
struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
322 rte_lpm_is_rule_present_v20(
struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth,
325 rte_lpm_is_rule_present_v1604(
struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
343 rte_lpm_delete_v20(
struct rte_lpm_v20 *lpm, uint32_t ip, uint8_t depth);
345 rte_lpm_delete_v1604(
struct rte_lpm *lpm, uint32_t ip, uint8_t depth);
356 rte_lpm_delete_all_v20(
struct rte_lpm_v20 *lpm);
358 rte_lpm_delete_all_v1604(
struct rte_lpm *lpm);
375 unsigned tbl24_index = (ip >> 8);
377 const uint32_t *ptbl;
380 RTE_LPM_RETURN_IF_TRUE(((lpm == NULL) || (next_hop == NULL)), -EINVAL);
383 ptbl = (
const uint32_t *)(&lpm->tbl24[tbl24_index]);
387 if (
unlikely((tbl_entry & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
388 RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
390 unsigned tbl8_index = (uint8_t)ip +
391 (((uint32_t)tbl_entry & 0x00FFFFFF) *
392 RTE_LPM_TBL8_GROUP_NUM_ENTRIES);
394 ptbl = (
const uint32_t *)&lpm->tbl8[tbl8_index];
398 *next_hop = ((uint32_t)tbl_entry & 0x00FFFFFF);
422 #define rte_lpm_lookup_bulk(lpm, ips, next_hops, n) \
423 rte_lpm_lookup_bulk_func(lpm, ips, next_hops, n)
426 rte_lpm_lookup_bulk_func(
const struct rte_lpm *lpm,
const uint32_t *ips,
427 uint32_t *next_hops,
const unsigned n)
430 unsigned tbl24_indexes[n];
431 const uint32_t *ptbl;
434 RTE_LPM_RETURN_IF_TRUE(((lpm == NULL) || (ips == NULL) ||
435 (next_hops == NULL)), -EINVAL);
437 for (i = 0; i < n; i++) {
438 tbl24_indexes[i] = ips[i] >> 8;
441 for (i = 0; i < n; i++) {
443 ptbl = (
const uint32_t *)&lpm->tbl24[tbl24_indexes[i]];
444 next_hops[i] = *ptbl;
447 if (
unlikely((next_hops[i] & RTE_LPM_VALID_EXT_ENTRY_BITMASK) ==
448 RTE_LPM_VALID_EXT_ENTRY_BITMASK)) {
450 unsigned tbl8_index = (uint8_t)ips[i] +
451 (((uint32_t)next_hops[i] & 0x00FFFFFF) *
452 RTE_LPM_TBL8_GROUP_NUM_ENTRIES);
454 ptbl = (
const uint32_t *)&lpm->tbl8[tbl8_index];
455 next_hops[i] = *ptbl;
462 #define RTE_LPM_MASKX4_RES UINT64_C(0x00ffffff00ffffff)
487 #if defined(RTE_ARCH_ARM) || defined(RTE_ARCH_ARM64)
488 #include "rte_lpm_neon.h"
489 #elif defined(RTE_ARCH_PPC_64)
490 #include "rte_lpm_altivec.h"
492 #include "rte_lpm_sse.h"
void rte_lpm_free(struct rte_lpm *lpm)
struct rte_lpm * rte_lpm_create(const char *name, int socket_id, const struct rte_lpm_config *config)
void rte_lpm_delete_all(struct rte_lpm *lpm)
struct rte_mbuf __rte_cache_aligned
#define RTE_LPM_MAX_DEPTH
static int rte_lpm_lookup(struct rte_lpm *lpm, uint32_t ip, uint32_t *next_hop)
static void rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], uint32_t defv)
int rte_lpm_delete(struct rte_lpm *lpm, uint32_t ip, uint8_t depth)
#define RTE_LPM_LOOKUP_SUCCESS
int rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t next_hop)
int rte_lpm_is_rule_present(struct rte_lpm *lpm, uint32_t ip, uint8_t depth, uint32_t *next_hop)
struct rte_lpm * rte_lpm_find_existing(const char *name)