lpm: minor changes
Signed-off-by: Intel
This commit is contained in:
parent
af89e7f85b
commit
a76109c628
@ -67,17 +67,17 @@ enum valid_flag {
|
||||
/* Macro to enable/disable run-time checks. */
|
||||
#if defined(RTE_LIBRTE_LPM_DEBUG)
|
||||
#include <rte_debug.h>
|
||||
#define VERIFY_DEPTH(depth) do { \
|
||||
if ((depth == 0) || (depth > RTE_LPM_MAX_DEPTH)) \
|
||||
rte_panic("LPM: Invalid depth (%u) at line %d", depth, __LINE__); \
|
||||
#define VERIFY_DEPTH(depth) do { \
|
||||
if ((depth == 0) || (depth > RTE_LPM_MAX_DEPTH)) \
|
||||
rte_panic("LPM: Invalid depth (%u) at line %d", \
|
||||
(unsigned)(depth), __LINE__); \
|
||||
} while (0)
|
||||
#else
|
||||
#define VERIFY_DEPTH(depth)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Function Name: depth_to_mask
|
||||
* Usage : Converts a given depth value to its corresponding mask value.
|
||||
* Converts a given depth value to its corresponding mask value.
|
||||
*
|
||||
* depth (IN) : range = 1 - 32
|
||||
* mask (OUT) : 32bit mask
|
||||
@ -94,11 +94,7 @@ depth_to_mask(uint8_t depth)
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name: depth_to_range
|
||||
* Usage : Converts given depth value to its corresponding range value.
|
||||
*
|
||||
* (IN) depth
|
||||
* (OUT) mask
|
||||
* Converts given depth value to its corresponding range value.
|
||||
*/
|
||||
static inline uint32_t __attribute__((pure))
|
||||
depth_to_range(uint8_t depth)
|
||||
@ -142,10 +138,7 @@ rte_lpm_find_existing(const char *name)
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name : rte_lpm_create
|
||||
* Usage : Allocates memory for LPM object
|
||||
*
|
||||
* rte_lpm (RETURN)
|
||||
* Allocates memory for LPM object
|
||||
*/
|
||||
struct rte_lpm *
|
||||
rte_lpm_create(const char *name, int socket_id, int max_rules,
|
||||
@ -232,8 +225,7 @@ rte_lpm_create(const char *name, int socket_id, int max_rules,
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name : free
|
||||
* Usage: Deallocates memory for given LPM table.
|
||||
* Deallocates memory for given LPM table.
|
||||
*/
|
||||
void
|
||||
rte_lpm_free(struct rte_lpm *lpm)
|
||||
@ -250,8 +242,7 @@ rte_lpm_free(struct rte_lpm *lpm)
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name: rule_add
|
||||
* Usage : Adds a rule to the rule table.
|
||||
* Adds a rule to the rule table.
|
||||
*
|
||||
* NOTE: The rule table is split into 32 groups. Each group contains rules that
|
||||
* apply to a specific prefix depth (i.e. group 1 contains rules that apply to
|
||||
@ -274,7 +265,7 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
|
||||
rule_index = rule_gindex;
|
||||
/* Last rule = Last used rule in this rule group. */
|
||||
last_rule = rule_gindex + lpm->used_rules_at_depth[depth - 1];
|
||||
|
||||
|
||||
/* Scan through rule group to see if rule already exists. */
|
||||
for (rule_index = rule_gindex; rule_index < last_rule; rule_index++) {
|
||||
|
||||
@ -304,8 +295,7 @@ rule_add(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name: rule_delete
|
||||
* Usage : Delete a rule from the rule table.
|
||||
* Delete a rule from the rule table.
|
||||
* NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
|
||||
*/
|
||||
static inline void
|
||||
@ -328,8 +318,7 @@ rule_delete(struct rte_lpm *lpm, int32_t rule_index, uint8_t depth)
|
||||
|
||||
|
||||
/*
|
||||
* Function Name: rule_find
|
||||
* Usage : Finds a rule in rule table.
|
||||
* Finds a rule in rule table.
|
||||
* NOTE: Valid range for depth parameter is 1 .. 32 inclusive.
|
||||
*/
|
||||
static inline int32_t
|
||||
@ -354,8 +343,7 @@ rule_find(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth)
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name: tbl8_alloc
|
||||
* Usage : Find, clean and allocate a tbl8.
|
||||
* Find, clean and allocate a tbl8.
|
||||
*/
|
||||
static inline int32_t
|
||||
tbl8_alloc(struct rte_lpm_tbl8_entry *tbl8)
|
||||
@ -426,7 +414,7 @@ add_depth_small(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
|
||||
|
||||
/* If tbl24 entry is valid and extended calculate the index
|
||||
* into tbl8. */
|
||||
tbl8_index = lpm->tbl24[tbl24_index].tbl8_gindex *
|
||||
tbl8_index = lpm->tbl24[tbl24_index].tbl8_gindex *
|
||||
RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
|
||||
tbl8_group_end = tbl8_index + RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
|
||||
|
||||
@ -586,25 +574,21 @@ add_depth_big(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name : rte_lpm_add
|
||||
* Usage : Add a route
|
||||
*
|
||||
*(IN) lpm_handle,
|
||||
*(IN) ip
|
||||
*(IN) depth
|
||||
*(IN) next_hop
|
||||
* Add a route
|
||||
*/
|
||||
int
|
||||
rte_lpm_add(struct rte_lpm *lpm, uint32_t ip, uint8_t depth,
|
||||
uint8_t next_hop)
|
||||
{
|
||||
int32_t rule_index, status = 0;
|
||||
uint32_t ip_masked = (ip & depth_to_mask(depth));
|
||||
uint32_t ip_masked;
|
||||
|
||||
/* Check user arguments. */
|
||||
if ((lpm == NULL) || (depth < 1) || (depth > RTE_LPM_MAX_DEPTH))
|
||||
return -EINVAL;
|
||||
|
||||
ip_masked = ip & depth_to_mask(depth);
|
||||
|
||||
/* Add the rule to the rule table. */
|
||||
rule_index = rule_add(lpm, ip_masked, depth, next_hop);
|
||||
|
||||
@ -673,6 +657,7 @@ delete_depth_small(struct rte_lpm *lpm, uint32_t ip_masked,
|
||||
* associated with this rule.
|
||||
*/
|
||||
for (i = tbl24_index; i < (tbl24_index + tbl24_range); i++) {
|
||||
|
||||
if (lpm->tbl24[i].ext_entry == 0 &&
|
||||
lpm->tbl24[i].depth <= depth ) {
|
||||
lpm->tbl24[i].valid = INVALID;
|
||||
@ -683,6 +668,7 @@ delete_depth_small(struct rte_lpm *lpm, uint32_t ip_masked,
|
||||
* to be a rule with depth >= 25 in the
|
||||
* associated TBL8 group.
|
||||
*/
|
||||
|
||||
tbl8_group_index = lpm->tbl24[i].tbl8_gindex;
|
||||
tbl8_index = tbl8_group_index *
|
||||
RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
|
||||
@ -736,7 +722,7 @@ delete_depth_small(struct rte_lpm *lpm, uint32_t ip_masked,
|
||||
tbl8_group_index = lpm->tbl24[i].tbl8_gindex;
|
||||
tbl8_index = tbl8_group_index *
|
||||
RTE_LPM_TBL8_GROUP_NUM_ENTRIES;
|
||||
|
||||
|
||||
for (j = tbl8_index; j < (tbl8_index +
|
||||
RTE_LPM_TBL8_GROUP_NUM_ENTRIES); j++) {
|
||||
|
||||
@ -751,8 +737,7 @@ delete_depth_small(struct rte_lpm *lpm, uint32_t ip_masked,
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name: tbl8_recycle_check
|
||||
* Usage : Checks if table 8 group can be recycled.
|
||||
* Checks if table 8 group can be recycled.
|
||||
*
|
||||
* Return of -EEXIST means tbl8 is in use and thus can not be recycled.
|
||||
* Return of -EINVAL means tbl8 is empty and thus can be recycled
|
||||
@ -888,12 +873,7 @@ delete_depth_big(struct rte_lpm *lpm, uint32_t ip_masked,
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name: rte_lpm_delete
|
||||
* Usage : Deletes a rule
|
||||
*
|
||||
*(IN) lpm_handle,
|
||||
*(IN) ip
|
||||
*(IN) depth
|
||||
* Deletes a rule
|
||||
*/
|
||||
int
|
||||
rte_lpm_delete(struct rte_lpm *lpm, uint32_t ip, uint8_t depth)
|
||||
@ -947,10 +927,7 @@ rte_lpm_delete(struct rte_lpm *lpm, uint32_t ip, uint8_t depth)
|
||||
}
|
||||
|
||||
/*
|
||||
* Function Name: rte_lpm_delete_all
|
||||
* Usage : Delete all rules from the LPM table.
|
||||
*
|
||||
*(IN) lpm_handle
|
||||
* Delete all rules from the LPM table.
|
||||
*/
|
||||
void
|
||||
rte_lpm_delete_all(struct rte_lpm *lpm)
|
||||
|
@ -52,40 +52,50 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/** Max number of characters in LPM name. */
|
||||
#define RTE_LPM_NAMESIZE 32
|
||||
#define RTE_LPM_NAMESIZE 32
|
||||
|
||||
/** Possible location to allocate memory. */
|
||||
#define RTE_LPM_HEAP 0
|
||||
/** @deprecated Possible location to allocate memory. This was for last
|
||||
* parameter of rte_lpm_create(), but is now redundant. The LPM table is always
|
||||
* allocated in memory using librte_malloc which uses a memzone. */
|
||||
#define RTE_LPM_HEAP 0
|
||||
|
||||
/** Possible location to allocate memory. */
|
||||
#define RTE_LPM_MEMZONE 1
|
||||
/** @deprecated Possible location to allocate memory. This was for last
|
||||
* parameter of rte_lpm_create(), but is now redundant. The LPM table is always
|
||||
* allocated in memory using librte_malloc which uses a memzone. */
|
||||
#define RTE_LPM_MEMZONE 1
|
||||
|
||||
/** Maximum depth value possible for IPv4 LPM. */
|
||||
#define RTE_LPM_MAX_DEPTH 32
|
||||
#define RTE_LPM_MAX_DEPTH 32
|
||||
|
||||
/** Total number of tbl24 entries. */
|
||||
#define RTE_LPM_TBL24_NUM_ENTRIES (1 << 24)
|
||||
/** @internal Total number of tbl24 entries. */
|
||||
#define RTE_LPM_TBL24_NUM_ENTRIES (1 << 24)
|
||||
|
||||
/** Number of entries in a tbl8 group. */
|
||||
#define RTE_LPM_TBL8_GROUP_NUM_ENTRIES 256
|
||||
/** @internal Number of entries in a tbl8 group. */
|
||||
#define RTE_LPM_TBL8_GROUP_NUM_ENTRIES 256
|
||||
|
||||
/** Total number of tbl8 groups in the tbl8. */
|
||||
#define RTE_LPM_TBL8_NUM_GROUPS 256
|
||||
/** @internal Total number of tbl8 groups in the tbl8. */
|
||||
#define RTE_LPM_TBL8_NUM_GROUPS 256
|
||||
|
||||
/** Total number of tbl8 entries. */
|
||||
#define RTE_LPM_TBL8_NUM_ENTRIES (RTE_LPM_TBL8_NUM_GROUPS * \
|
||||
/** @internal Total number of tbl8 entries. */
|
||||
#define RTE_LPM_TBL8_NUM_ENTRIES (RTE_LPM_TBL8_NUM_GROUPS * \
|
||||
RTE_LPM_TBL8_GROUP_NUM_ENTRIES)
|
||||
|
||||
/** Macro to enable/disable run-time checks. */
|
||||
/** @internal Macro to enable/disable run-time checks. */
|
||||
#if defined(RTE_LIBRTE_LPM_DEBUG)
|
||||
#define RTE_LPM_RETURN_IF_TRUE(cond, retval) do { \
|
||||
if (cond) return (retval); \
|
||||
#define RTE_LPM_RETURN_IF_TRUE(cond, retval) do { \
|
||||
if (cond) return (retval); \
|
||||
} while (0)
|
||||
#else
|
||||
#define RTE_LPM_RETURN_IF_TRUE(cond, retval)
|
||||
#endif
|
||||
|
||||
/** Tbl24 entry structure. */
|
||||
/** @internal bitmask with valid and ext_entry/valid_group fields set */
|
||||
#define RTE_LPM_VALID_EXT_ENTRY_BITMASK 0x0300
|
||||
|
||||
/** Bitmask used to indicate successful lookup */
|
||||
#define RTE_LPM_LOOKUP_SUCCESS 0x0100
|
||||
|
||||
/** @internal Tbl24 entry structure. */
|
||||
struct rte_lpm_tbl24_entry {
|
||||
/* Using single uint8_t to store 3 values. */
|
||||
uint8_t valid :1; /**< Validation flag. */
|
||||
@ -98,7 +108,7 @@ struct rte_lpm_tbl24_entry {
|
||||
};
|
||||
};
|
||||
|
||||
/** Tbl8 entry structure. */
|
||||
/** @internal Tbl8 entry structure. */
|
||||
struct rte_lpm_tbl8_entry {
|
||||
/* Using single uint8_t to store 3 values. */
|
||||
uint8_t valid :1; /**< Validation flag. */
|
||||
@ -107,19 +117,19 @@ struct rte_lpm_tbl8_entry {
|
||||
uint8_t next_hop; /**< next hop. */
|
||||
};
|
||||
|
||||
/** Rule structure. */
|
||||
/** @internal Rule structure. */
|
||||
struct rte_lpm_rule {
|
||||
uint32_t ip; /**< Rule IP address. */
|
||||
uint8_t next_hop; /**< Rule next hop. */
|
||||
};
|
||||
|
||||
/** LPM structure. */
|
||||
/** @internal LPM structure. */
|
||||
struct rte_lpm {
|
||||
TAILQ_ENTRY(rte_lpm) next; /**< Next in list. */
|
||||
|
||||
/* LPM metadata. */
|
||||
char name[RTE_LPM_NAMESIZE]; /**< Name of the lpm. */
|
||||
int mem_location; /**< Location of memory to be allocated. */
|
||||
int mem_location; /**< @deprecated @see RTE_LPM_HEAP and RTE_LPM_MEMZONE. */
|
||||
uint32_t max_rules_per_depth; /**< Max. balanced rules per lpm. */
|
||||
uint32_t used_rules_at_depth[RTE_LPM_MAX_DEPTH]; /**< Rules / depth. */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user