67 l = 1 + 2 * adj_index;
95 #define PLY_X4_SPLAT_INIT(init_x4, init) \ 96 init_x4 = u32x4_splat (init); 98 #define PLY_X4_SPLAT_INIT(init_x4, init) \ 101 y.as_u32[0] = init; \ 102 y.as_u32[1] = init; \ 103 y.as_u32[2] = init; \ 104 y.as_u32[3] = init; \ 105 init_x4 = y.as_u32x4; \ 109 #ifdef CLIB_HAVE_VEC128 110 #define PLY_INIT_LEAVES(p) \ 114 PLY_X4_SPLAT_INIT(init_x4, init); \ 115 for (l = p->leaves_as_u32x4; \ 116 l < p->leaves_as_u32x4 + ARRAY_LEN (p->leaves_as_u32x4); \ 126 #define PLY_INIT_LEAVES(p) \ 130 for (l = p->leaves; l < p->leaves + ARRAY_LEN (p->leaves); l += 4) \ 140 #define PLY_INIT(p, init, prefix_len, ply_base_len) \ 147 p->n_non_empty_leafs = (prefix_len > ply_base_len ? \ 148 ARRAY_LEN (p->leaves) : 0); \ 149 clib_memset (p->dst_address_bits_of_leaves, prefix_len, \ 150 sizeof (p->dst_address_bits_of_leaves)); \ 151 p->dst_address_bits_base = ply_base_len; \ 154 PLY_INIT_LEAVES(p); \ 161 PLY_INIT (p, init, prefix_len, ply_base_len);
176 u32 leaf_prefix_len,
u32 ply_base_len)
186 ply_8_init (p, init_leaf, leaf_prefix_len, ply_base_len);
233 uword new_leaf_dst_address_bits)
250 new_leaf_dst_address_bits);
254 else if (new_leaf_dst_address_bits >=
268 u32 old_ply_index,
u32 dst_address_byte_index)
271 i32 n_dst_bits_next_plies;
281 n_dst_bits_next_plies =
287 if (n_dst_bits_next_plies <= 0)
290 uword old_leaf_is_terminal;
291 u32 i, n_dst_bits_this_ply;
294 n_dst_bits_this_ply =
clib_min (8, -n_dst_bits_next_plies);
300 for (i = dst_byte; i < dst_byte + (1 << n_dst_bits_this_ply); i++)
313 if (old_leaf_is_terminal)
340 else if (!old_leaf_is_terminal)
345 set_leaf (m, a, new_ply - ip4_ply_pool,
346 dst_address_byte_index + 1);
362 ply_base_len = 8 * (dst_address_byte_index + 1);
364 old_leaf = old_ply->
leaves[dst_byte];
393 set_leaf (m, a, new_ply - ip4_ply_pool, dst_address_byte_index + 1);
403 i32 n_dst_bits_next_plies;
416 if (n_dst_bits_next_plies <= 0)
419 uword old_leaf_is_terminal;
420 u32 i, n_dst_bits_this_ply;
429 for (i = 0; i < (1 << n_dst_bits_this_ply); i++)
434 slot = clib_net_to_host_u16 (dst_byte);
436 slot = clib_host_to_net_u16 (slot);
438 old_leaf = old_ply->
leaves[slot];
448 if (old_leaf_is_terminal)
467 else if (!old_leaf_is_terminal)
472 set_leaf (m, a, new_ply - ip4_ply_pool, 2);
490 old_leaf = old_ply->
leaves[dst_byte];
509 set_leaf (m, a, new_ply - ip4_ply_pool, 2);
519 i32 n_dst_bits_next_plies;
520 i32 i, n_dst_bits_this_ply, old_leaf_is_terminal;
526 n_dst_bits_next_plies =
530 if (n_dst_bits_next_plies < 0)
531 dst_byte &= ~
pow2_mask (-n_dst_bits_next_plies);
533 n_dst_bits_this_ply =
534 n_dst_bits_next_plies <= 0 ? -n_dst_bits_next_plies : 0;
535 n_dst_bits_this_ply =
clib_min (8, n_dst_bits_this_ply);
539 for (i = dst_byte; i < dst_byte + (1 << n_dst_bits_this_ply); i++)
544 if (old_leaf == del_leaf
545 || (!old_leaf_is_terminal
547 dst_address_byte_index + 1)))
567 else if (dst_address_byte_index)
589 i32 n_dst_bits_next_plies;
590 i32 i, n_dst_bits_this_ply, old_leaf_is_terminal;
601 n_dst_bits_this_ply = (n_dst_bits_next_plies <= 0 ?
608 for (i = 0; i < (1 << n_dst_bits_this_ply); i++)
612 slot = clib_net_to_host_u16 (dst_byte);
614 slot = clib_host_to_net_u16 (slot);
616 old_leaf = old_ply->
leaves[slot];
619 if (old_leaf == del_leaf
620 || (!old_leaf_is_terminal
633 u32 dst_address_length,
u32 adj_index)
650 u32 dst_address_length,
652 u32 cover_address_length,
u32 cover_adj_index)
675 bytes =
sizeof (p[0]);
715 #define FORMAT_PLY(s, _p, _a, _i, _base_address, _ply_max_len, _indent) \ 719 ip4_fib_mtrie_leaf_t _l = p->leaves[(_i)]; \ 721 a = (_base_address) + ((_a) << (32 - (_ply_max_len))); \ 722 ia.as_u32 = clib_host_to_net_u32 (a); \ 723 ia_length = (_p)->dst_address_bits_of_leaves[(_i)]; \ 724 s = format (s, "\n%U%U %U", \ 725 format_white_space, (_indent) + 4, \ 726 format_ip4_address_and_length, &ia, ia_length, \ 727 format_ip4_fib_mtrie_leaf, _l); \ 729 if (ip4_fib_mtrie_leaf_is_next_ply (_l)) \ 730 s = format (s, "\n%U", \ 731 format_ip4_fib_mtrie_ply, m, a, (_indent) + 8, \ 732 ip4_fib_mtrie_leaf_get_next_ply_index (_l)); \ 740 u32 base_address = va_arg (*va,
u32);
741 u32 indent = va_arg (*va,
u32);
742 u32 ply_index = va_arg (*va,
u32);
747 s =
format (s,
"%Uply index %d, %d non-empty leaves",
766 int verbose = va_arg (*va,
int);
768 u32 base_address = 0;
771 s =
format (s,
"%d plies, memory usage %U\n",
774 s =
format (s,
"root-ply");
779 s =
format (s,
"root-ply");
786 slot = clib_host_to_net_u16 (i);
790 s =
FORMAT_PLY (s, p, i, slot, base_address, 16, 0);
799 #define IP4_FIB_DEFAULT_MTRIE_HEAP_SIZE (32<<20) 811 #if USE_DLMALLOC == 0
static ip4_fib_mtrie_8_ply_t * get_next_ply_for_leaf(ip4_fib_mtrie_t *m, ip4_fib_mtrie_leaf_t l)
static ip4_fib_mtrie_leaf_t ply_create(ip4_fib_mtrie_t *m, ip4_fib_mtrie_leaf_t init_leaf, u32 leaf_prefix_len, u32 ply_base_len)
#define PLY_INIT_LEAVES(p)
static void set_leaf(ip4_fib_mtrie_t *m, const ip4_fib_mtrie_set_unset_leaf_args_t *a, u32 old_ply_index, u32 dst_address_byte_index)
void * mheap_alloc(void *memory, uword size)
ip4_fib_mtrie_8_ply_t * ip4_ply_pool
Global pool of IPv4 8bit PLYs.
ip4_fib_mtrie_leaf_t leaves[256]
static void unset_root_leaf(ip4_fib_mtrie_t *m, const ip4_fib_mtrie_set_unset_leaf_args_t *a)
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static u32 ip4_fib_mtrie_leaf_is_non_empty(ip4_fib_mtrie_8_ply_t *p, u8 dst_byte)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
u8 dst_address_bits_of_leaves[PLY_16_SIZE]
Prefix length for terminal leaves.
#define IP4_FIB_MTRIE_LEAF_EMPTY
One ply of the 4 ply mtrie fib.
static void set_ply_with_more_specific_leaf(ip4_fib_mtrie_t *m, ip4_fib_mtrie_8_ply_t *ply, ip4_fib_mtrie_leaf_t new_leaf, uword new_leaf_dst_address_bits)
#define VLIB_INIT_FUNCTION(x)
#define FORMAT_PLY(s, _p, _a, _i, _base_address, _ply_max_len, _indent)
static uword pow2_mask(uword x)
void ip4_mtrie_free(ip4_fib_mtrie_t *m)
Free an mtrie, It must be emty when free'd.
ip4_fib_mtrie_leaf_t leaves[PLY_16_SIZE]
#define IP4_FIB_DEFAULT_MTRIE_HEAP_SIZE
Default heap size for the IPv4 mtries.
static u32 ip4_fib_mtrie_leaf_get_adj_index(ip4_fib_mtrie_leaf_t n)
From the stored slot value extract the LB index value.
void ip4_mtrie_init(ip4_fib_mtrie_t *m)
Initialise an mtrie.
static u8 * format_ip4_fib_mtrie_leaf(u8 *s, va_list *va)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u8 * format_ip4_fib_mtrie(u8 *s, va_list *va)
uword mtrie_heap_size
Heapsize for the Mtries.
static void set_root_leaf(ip4_fib_mtrie_t *m, const ip4_fib_mtrie_set_unset_leaf_args_t *a)
#define pool_put(P, E)
Free an object E in pool P.
static uword mtrie_ply_memory_usage(ip4_fib_mtrie_t *m, ip4_fib_mtrie_8_ply_t *p)
void * mtrie_mheap
The memory heap for the mtries.
ip4_address_t dst_address
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
u8 dst_address_bits_of_leaves[256]
Prefix length for leaves/ply.
DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked)
uword ip4_fib_mtrie_memory_usage(ip4_fib_mtrie_t *m)
return the memory used by the table
ip4_fib_mtrie_16_ply_t root_ply
Embed the PLY with the mtrie struct.
static void * clib_mem_set_heap(void *heap)
#define PLY_INIT(p, init, prefix_len, ply_base_len)
#define clib_atomic_cmp_and_swap(addr, old, new)
static clib_error_t * ip4_mtrie_module_init(vlib_main_t *vm)
i32 n_non_empty_leafs
Number of non-empty leafs (whether terminal or not).
static u32 ip4_fib_mtrie_leaf_is_next_ply(ip4_fib_mtrie_leaf_t n)
i32 dst_address_bits_base
The length of the ply's coviering prefix.
void ip4_fib_mtrie_route_add(ip4_fib_mtrie_t *m, const ip4_address_t *dst_address, u32 dst_address_length, u32 adj_index)
Add a route/rntry to the mtrie.
static ip4_fib_mtrie_leaf_t ip4_fib_mtrie_leaf_set_adj_index(u32 adj_index)
ip4_main_t ip4_main
Global ip4 main structure.
static u32 ip4_fib_mtrie_leaf_get_next_ply_index(ip4_fib_mtrie_leaf_t n)
void ip4_fib_mtrie_route_del(ip4_fib_mtrie_t *m, const ip4_address_t *dst_address, u32 dst_address_length, u32 adj_index, u32 cover_address_length, u32 cover_adj_index)
remove a route/rntry to the mtrie
#define CLIB_CACHE_LINE_BYTES
static uword unset_leaf(ip4_fib_mtrie_t *m, const ip4_fib_mtrie_set_unset_leaf_args_t *a, ip4_fib_mtrie_8_ply_t *old_ply, u32 dst_address_byte_index)
static u8 * format_ip4_fib_mtrie_ply(u8 *s, va_list *va)
static void ply_16_init(ip4_fib_mtrie_16_ply_t *p, ip4_fib_mtrie_leaf_t init, uword prefix_len)
static u32 ip4_fib_mtrie_leaf_is_terminal(ip4_fib_mtrie_leaf_t n)
Is the leaf terminal (i.e.
static void ply_8_init(ip4_fib_mtrie_8_ply_t *p, ip4_fib_mtrie_leaf_t init, uword prefix_len, u32 ply_base_len)
static ip4_fib_mtrie_leaf_t ip4_fib_mtrie_leaf_set_next_ply_index(u32 i)
static uword pool_elts(void *v)
Number of active elements in a pool.