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 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)
183 ply_8_init (p, init_leaf, leaf_prefix_len, ply_base_len);
230 uword new_leaf_dst_address_bits)
247 new_leaf_dst_address_bits);
251 else if (new_leaf_dst_address_bits >=
254 __sync_val_compare_and_swap (&ply->
leaves[i], old_leaf, new_leaf);
265 u32 old_ply_index,
u32 dst_address_byte_index)
268 i32 n_dst_bits_next_plies;
278 n_dst_bits_next_plies =
284 if (n_dst_bits_next_plies <= 0)
287 uword old_leaf_is_terminal;
288 u32 i, n_dst_bits_this_ply;
291 n_dst_bits_this_ply =
clib_min (8, -n_dst_bits_next_plies);
297 for (i = dst_byte; i < dst_byte + (1 << n_dst_bits_this_ply); i++)
310 if (old_leaf_is_terminal)
319 __sync_val_compare_and_swap (&old_ply->
leaves[i], old_leaf,
337 else if (!old_leaf_is_terminal)
342 set_leaf (m, a, new_ply - ip4_ply_pool,
343 dst_address_byte_index + 1);
359 ply_base_len = 8 * (dst_address_byte_index + 1);
361 old_leaf = old_ply->
leaves[dst_byte];
371 [dst_byte], ply_base_len),
378 __sync_val_compare_and_swap (&old_ply->
leaves[dst_byte], old_leaf,
390 set_leaf (m, a, new_ply - ip4_ply_pool, dst_address_byte_index + 1);
400 i32 n_dst_bits_next_plies;
413 if (n_dst_bits_next_plies <= 0)
416 uword old_leaf_is_terminal;
417 u32 i, n_dst_bits_this_ply;
426 for (i = 0; i < (1 << n_dst_bits_this_ply); i++)
431 slot = clib_net_to_host_u16 (dst_byte);
433 slot = clib_host_to_net_u16 (slot);
435 old_leaf = old_ply->
leaves[slot];
445 if (old_leaf_is_terminal)
451 __sync_val_compare_and_swap (&old_ply->
leaves[slot],
464 else if (!old_leaf_is_terminal)
469 set_leaf (m, a, new_ply - ip4_ply_pool, 2);
487 old_leaf = old_ply->
leaves[dst_byte];
494 [dst_byte], ply_base_len),
498 __sync_val_compare_and_swap (&old_ply->
leaves[dst_byte], old_leaf,
506 set_leaf (m, a, new_ply - ip4_ply_pool, 2);
516 i32 n_dst_bits_next_plies;
517 i32 i, n_dst_bits_this_ply, old_leaf_is_terminal;
523 n_dst_bits_next_plies =
527 if (n_dst_bits_next_plies < 0)
528 dst_byte &= ~
pow2_mask (-n_dst_bits_next_plies);
530 n_dst_bits_this_ply =
531 n_dst_bits_next_plies <= 0 ? -n_dst_bits_next_plies : 0;
532 n_dst_bits_this_ply =
clib_min (8, n_dst_bits_this_ply);
536 for (i = dst_byte; i < dst_byte + (1 << n_dst_bits_this_ply); i++)
541 if (old_leaf == del_leaf
542 || (!old_leaf_is_terminal
544 dst_address_byte_index + 1)))
566 else if (dst_address_byte_index)
588 i32 n_dst_bits_next_plies;
589 i32 i, n_dst_bits_this_ply, old_leaf_is_terminal;
600 n_dst_bits_this_ply = (n_dst_bits_next_plies <= 0 ?
607 for (i = 0; i < (1 << n_dst_bits_this_ply); i++)
611 slot = clib_net_to_host_u16 (dst_byte);
613 slot = clib_host_to_net_u16 (slot);
615 old_leaf = old_ply->
leaves[slot];
618 if (old_leaf == del_leaf
619 || (!old_leaf_is_terminal
632 u32 dst_address_length,
u32 adj_index)
649 u32 dst_address_length,
651 u32 cover_address_length,
u32 cover_adj_index)
674 bytes =
sizeof (p[0]);
714 #define FORMAT_PLY(s, _p, _i, _base_address, _ply_max_len, _indent) \ 718 ip4_fib_mtrie_leaf_t _l = p->leaves[(_i)]; \ 720 a = (_base_address) + ((_i) << (32 - (_ply_max_len))); \ 721 ia.as_u32 = clib_host_to_net_u32 (a); \ 722 ia_length = (_p)->dst_address_bits_of_leaves[(_i)]; \ 723 s = format (s, "\n%U%20U %U", \ 724 format_white_space, (_indent) + 2, \ 725 format_ip4_address_and_length, &ia, ia_length, \ 726 format_ip4_fib_mtrie_leaf, _l); \ 728 if (ip4_fib_mtrie_leaf_is_next_ply (_l)) \ 729 s = format (s, "\n%U%U", \ 730 format_white_space, (_indent) + 2, \ 731 format_ip4_fib_mtrie_ply, m, a, \ 732 ip4_fib_mtrie_leaf_get_next_ply_index (_l)); \ 740 u32 base_address = va_arg (*va,
u32);
741 u32 ply_index = va_arg (*va,
u32);
748 s =
format (s,
"ply index %d, %d non-empty leaves", ply_index,
768 u32 base_address = 0;
771 s =
format (s,
"%d plies, memory usage %U\n",
774 s =
format (s,
"root-ply");
781 slot = clib_host_to_net_u16 (i);
static ip4_fib_mtrie_8_ply_t * get_next_ply_for_leaf(ip4_fib_mtrie_t *m, ip4_fib_mtrie_leaf_t l)
sll srl srl sll sra u16x4 i
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)
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)
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)
static uword mtrie_memory_usage(ip4_fib_mtrie_t *m)
#define VLIB_INIT_FUNCTION(x)
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]
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)
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)
ip4_address_t dst_address
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
u8 dst_address_bits_of_leaves[256]
Prefix length for leaves/ply.
ip4_fib_mtrie_16_ply_t root_ply
Embed the PLY with the mtrie struct.
#define PLY_INIT(p, init, prefix_len, ply_base_len)
static clib_error_t * ip4_mtrie_module_init(vlib_main_t *vm)
#define FORMAT_PLY(s, _p, _i, _base_address, _ply_max_len, _indent)
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.