Line data Source code
1 : #ifndef HEADER_fd_src_waltz_ip_fd_fib4_private_h 2 : #define HEADER_fd_src_waltz_ip_fd_fib4_private_h 3 : 4 : #include "fd_fib4.h" 5 : #include "../../util/fd_util.h" 6 : 7 : struct __attribute__((aligned(16))) fd_fib4_key { 8 : /* FIXME optimize this to 8 bytes? */ 9 : uint addr; /* prefix bits, little endian (low bits outside of mask are undefined) */ 10 : uint mask; /* bit pattern */ 11 : uint prio; /* lower is higher */ 12 : int mask_bits; /* precompute mask bits for comparison */ 13 : }; 14 : 15 : typedef struct fd_fib4_key fd_fib4_key_t; 16 : 17 : struct fd_fib4_hmap_key { 18 : uint dst_addr; 19 : uint prio; /* lower is higher */ 20 : }; 21 : 22 : typedef struct fd_fib4_hmap_key fd_fib4_hmap_key_t; 23 : 24 : struct __attribute__((aligned(16))) fd_fib4_hmap_entry { 25 : fd_fib4_hmap_key_t key; 26 : fd_fib4_hop_t next_hop; /* 16 bytes */ 27 : }; 28 : 29 : typedef struct fd_fib4_hmap_entry fd_fib4_hmap_entry_t; 30 : 31 : static inline uint 32 1386 : fd_fib4_hmap_entry_hash( uint dst_addr, ulong seed ) { 33 1386 : return fd_uint_hash( dst_addr ^ ((uint)seed) ); 34 1386 : } 35 : 36 : #define MAP_NAME fd_fib4_hmap 37 2364 : #define MAP_ELE_T fd_fib4_hmap_entry_t 38 : #define MAP_KEY_T fd_fib4_hmap_key_t 39 330 : #define MAP_KEY key 40 132 : #define MAP_KEY_EQ(k0,k1) (((k0)->dst_addr==(k1)->dst_addr) & ((k0)->prio==(k1)->prio)) 41 942 : #define MAP_KEY_HASH(k,s) fd_fib4_hmap_entry_hash( (k)->dst_addr, (s) ) 42 5106 : #define MAP_ELE_IS_FREE(ele) ((ele)->next_hop.rtype==FD_FIB4_RTYPE_UNSPEC) 43 21 : #define MAP_ELE_FREE(ctx,ele) do { (void)(ctx); (ele)->next_hop.rtype = FD_FIB4_RTYPE_UNSPEC; } while(0) 44 6 : #define MAP_ELE_MOVE(ctx,dst,src) do { (void)(ctx); *(dst) = *(src); (src)->next_hop.rtype = FD_FIB4_RTYPE_UNSPEC; } while(0) 45 : #include "../../util/tmpl/fd_map_slot.c" 46 : 47 : FD_STATIC_ASSERT( sizeof(fd_fib4_hmap_entry_t)==32UL, hmap_entry_size ); 48 : 49 : FD_STATIC_ASSERT( sizeof( fd_fib4_hmap_t)<=sizeof(( (fd_fib4_t){0}).hmap_join), "hmap_join is too small" ); 50 : 51 : struct __attribute__((aligned(FD_FIB4_ALIGN))) fd_fib4_priv { 52 : ulong hmap_offset; 53 : ulong hmap_cnt; 54 : ulong hmap_max; 55 : ulong cnt; 56 : ulong max; 57 : ulong hop_off; 58 : ulong seed; 59 : /* fd_fib4_key_t[] follows */ 60 : /* fd_fib4_hop_t[] follows */ 61 : /* hmap_mem follows */ 62 : }; 63 : typedef struct fd_fib4_priv fd_fib4_priv_t; 64 : 65 : FD_FN_CONST static inline ulong 66 414 : fd_fib4_key_tbl_laddr( fd_fib4_priv_t const * fib ) { 67 414 : return (ulong)fib + sizeof(fd_fib4_priv_t); 68 414 : } 69 : 70 : FD_FN_PURE static inline ulong 71 414 : fd_fib4_hop_tbl_laddr( fd_fib4_priv_t const * fib ) { 72 414 : return (ulong)fib + fib->hop_off; 73 414 : } 74 : 75 252 : FD_FN_CONST static inline fd_fib4_key_t const * fd_fib4_key_tbl_const( fd_fib4_priv_t const * fib ) { return (fd_fib4_key_t const *)fd_fib4_key_tbl_laddr( fib ); } 76 162 : FD_FN_CONST static inline fd_fib4_key_t * fd_fib4_key_tbl ( fd_fib4_priv_t * fib ) { return (fd_fib4_key_t *) fd_fib4_key_tbl_laddr( fib ); } 77 252 : FD_FN_CONST static inline fd_fib4_hop_t const * fd_fib4_hop_tbl_const( fd_fib4_priv_t const * fib ) { return (fd_fib4_hop_t const *)fd_fib4_hop_tbl_laddr( fib ); } 78 162 : FD_FN_CONST static inline fd_fib4_hop_t * fd_fib4_hop_tbl ( fd_fib4_priv_t * fib ) { return (fd_fib4_hop_t *) fd_fib4_hop_tbl_laddr( fib ); } 79 : 80 69 : static inline void * fd_fib4_hmap_mem( fd_fib4_priv_t * priv ) { 81 69 : return (void *)( (ulong)priv + priv->hmap_offset); 82 69 : } 83 : 84 : /* Get the hashmap's total capacity (50% extra capacity beyond the requested size to optimize performance) */ 85 135 : static inline ulong fd_fib4_hmap_get_ele_max ( ulong max_cnt ) { return fd_ulong_pow2_up( max_cnt + ( max_cnt>>1 ) ); } 86 : /* Get the hashmap's probe limit (75% of total capacity). Higher than requested size to avoid probe failure */ 87 69 : static inline ulong fd_fib4_hmap_get_probe_max ( ulong elem_max ) { return elem_max - ( elem_max>>2 ); } 88 : 89 : #endif /* HEADER_fd_src_waltz_ip_fd_fib4_private_h */