X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fmfib%2Fmfib_entry.c;h=90b223e3c253f412387e1dc759227e79ef8389ab;hb=2af0e3a;hp=49792f02ae4a815c00c847544ff8193cd4c753c9;hpb=8142499cd1cb3b8d0168d0e6cf5309c5b4813cc4;p=vpp.git diff --git a/src/vnet/mfib/mfib_entry.c b/src/vnet/mfib/mfib_entry.c index 49792f02ae4..90b223e3c25 100644 --- a/src/vnet/mfib/mfib_entry.c +++ b/src/vnet/mfib/mfib_entry.c @@ -21,32 +21,23 @@ #include #include +/** + * the logger + */ +vlib_log_class_t mfib_entry_logger; + /** * Debug macro */ -#ifdef MFIB_DEBUG -#DEFIne MFIB_ENTRY_DBG(_e, _fmt, _args...) \ +#define MFIB_ENTRY_DBG(_e, _fmt, _args...) \ { \ - u8*__tmp = NULL; \ - __tmp = format(__tmp, "e:[%d:%U", \ + vlib_log_debug(mfib_entry_logger, \ + "e:[%d:%U]: " _fmt, \ mfib_entry_get_index(_e), \ - format_ip46_address, \ - &_e->mfe_prefix.fp_grp_addr, \ - IP46_TYPE_ANY); \ - __tmp = format(__tmp, "/%d,", \ - _e->mfe_prefix.fp_len); \ - __tmp = format(__tmp, "%U]", \ - mfib_entry_get_index(_e), \ - format_ip46_address, \ - &_e->mfe_prefix.fp_src_addr, \ - IP46_TYPE_ANY); \ - __tmp = format(__tmp, _fmt, ##_args); \ - clib_warning("%s", __tmp); \ - vec_free(__tmp); \ + format_mfib_prefix, \ + &_e->mfe_prefix, \ + ##_args); \ } -#else -#define MFIB_ENTRY_DBG(_e, _fmt, _args...) -#endif /** * MFIB extensions to each path @@ -217,7 +208,10 @@ format_mfib_entry (u8 * s, va_list * args) ({ s = format(s, "\n %U", format_mfib_itf, mfi); })); - s = format(s, "\n RPF-ID:%d", mfib_entry->mfe_rpf_id); + if (MFIB_RPF_ID_NONE != mfib_entry->mfe_rpf_id) + { + s = format(s, "\n RPF-ID:%d", mfib_entry->mfe_rpf_id); + } s = format(s, "\n %U-chain\n %U", format_fib_forw_chain_type, mfib_entry_get_default_chain_type(mfib_entry), @@ -238,9 +232,7 @@ format_mfib_entry (u8 * s, va_list * args) static mfib_entry_t* mfib_entry_from_fib_node (fib_node_t *node) { -#if CLIB_DEBUG > 0 ASSERT(FIB_NODE_TYPE_MFIB_ENTRY == node->fn_type); -#endif return ((mfib_entry_t*)node); } @@ -300,7 +292,7 @@ mfib_entry_src_find (const mfib_entry_t *mfib_entry, static mfib_entry_src_t * mfib_entry_src_find_or_create (mfib_entry_t *mfib_entry, - mfib_source_t source) + mfib_source_t source) { mfib_entry_src_t *esrc; @@ -334,6 +326,17 @@ mfib_entry_get_best_src (const mfib_entry_t *mfib_entry) return (bsrc); } +int +mfib_entry_is_sourced (fib_node_index_t mfib_entry_index, + mfib_source_t source) +{ + mfib_entry_t *mfib_entry; + + mfib_entry = mfib_entry_get(mfib_entry_index); + + return (NULL != mfib_entry_src_find(mfib_entry, source, NULL)); +} + static void mfib_entry_src_flush (mfib_entry_src_t *msrc) { @@ -366,62 +369,6 @@ mfib_entry_src_remove (mfib_entry_t *mfib_entry, } } -static void -mfib_entry_last_lock_gone (fib_node_t *node) -{ - mfib_entry_t *mfib_entry; - mfib_entry_src_t *msrc; - - mfib_entry = mfib_entry_from_fib_node(node); - - dpo_reset(&mfib_entry->mfe_rep); - - MFIB_ENTRY_DBG(mfib_entry, "last-lock"); - - vec_foreach(msrc, mfib_entry->mfe_srcs) - { - mfib_entry_src_flush(msrc); - } - - vec_free(mfib_entry->mfe_srcs); - - fib_node_deinit(&mfib_entry->mfe_node); - pool_put(mfib_entry_pool, mfib_entry); -} - -/* - * mfib_entry_back_walk_notify - * - * A back walk has reach this entry. - */ -static fib_node_back_walk_rc_t -mfib_entry_back_walk_notify (fib_node_t *node, - fib_node_back_walk_ctx_t *ctx) -{ - // FIXME - re-evalute - - return (FIB_NODE_BACK_WALK_CONTINUE); -} - -static void -mfib_entry_show_memory (void) -{ - fib_show_memory_usage("multicast-Entry", - pool_elts(mfib_entry_pool), - pool_len(mfib_entry_pool), - sizeof(mfib_entry_t)); -} - -/* - * The MFIB entry's graph node virtual function table - */ -static const fib_node_vft_t mfib_entry_vft = { - .fnv_get = mfib_entry_get_node, - .fnv_last_lock = mfib_entry_last_lock_gone, - .fnv_back_walk = mfib_entry_back_walk_notify, - .fnv_mem_show = mfib_entry_show_memory, -}; - u32 mfib_entry_child_add (fib_node_index_t mfib_entry_index, fib_node_type_t child_type, @@ -449,14 +396,14 @@ mfib_entry_alloc (u32 fib_index, { mfib_entry_t *mfib_entry; - pool_get(mfib_entry_pool, mfib_entry); + pool_get_aligned(mfib_entry_pool, mfib_entry, CLIB_CACHE_LINE_BYTES); fib_node_init(&mfib_entry->mfe_node, FIB_NODE_TYPE_MFIB_ENTRY); /* * Some of the members require non-default initialisation - * so we also init those that don't and thus save on the call to memset. + * so we also init those that don't and thus save on the call to clib_memset. */ mfib_entry->mfe_flags = 0; mfib_entry->mfe_fib_index = fib_index; @@ -464,6 +411,7 @@ mfib_entry_alloc (u32 fib_index, mfib_entry->mfe_srcs = NULL; mfib_entry->mfe_itfs = NULL; mfib_entry->mfe_rpf_id = MFIB_RPF_ID_NONE; + mfib_entry->mfe_pl = FIB_NODE_INDEX_INVALID; dpo_reset(&mfib_entry->mfe_rep); @@ -579,6 +527,7 @@ mfib_entry_src_collect_forwarding (fib_node_index_t pl_index, case FIB_FORW_CHAIN_TYPE_MPLS_EOS: case FIB_FORW_CHAIN_TYPE_ETHERNET: case FIB_FORW_CHAIN_TYPE_NSH: + case FIB_FORW_CHAIN_TYPE_BIER: ASSERT(0); break; } @@ -594,6 +543,15 @@ mfib_entry_stack (mfib_entry_t *mfib_entry, dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry)); + /* + * unlink the enty from the previous path list. + */ + if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_pl) + { + fib_path_list_child_remove(mfib_entry->mfe_pl, + mfib_entry->mfe_sibling); + } + if (NULL != msrc && FIB_NODE_INDEX_INVALID != msrc->mfes_pl) { @@ -658,6 +616,17 @@ mfib_entry_stack (mfib_entry_t *mfib_entry, dpo_reset(&ctx.next_hops[0].path_dpo); vec_free(ctx.next_hops); } + + /* + * link the entry to the path-list. + * The entry needs to be a child so that we receive the back-walk + * updates to recalculate forwarding. + */ + mfib_entry->mfe_pl = msrc->mfes_pl; + mfib_entry->mfe_sibling = + fib_path_list_child_add(mfib_entry->mfe_pl, + FIB_NODE_TYPE_MFIB_ENTRY, + mfib_entry_get_index(mfib_entry)); } else { @@ -799,18 +768,16 @@ mfib_entry_update (fib_node_index_t mfib_entry_index, * entry */ fib_node_index_t old_pl_index; - fib_protocol_t fp; + dpo_proto_t dp; dpo_id_t dpo = DPO_INVALID; - fp = mfib_entry_get_proto(mfib_entry); + dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry)); old_pl_index = msrc->mfes_pl; - dpo_set(&dpo, DPO_REPLICATE, - fib_proto_to_dpo(fp), - repi); + dpo_set(&dpo, DPO_REPLICATE, dp, repi); msrc->mfes_pl = - fib_path_list_create_special(fp, + fib_path_list_create_special(dp, FIB_PATH_LIST_FLAG_EXCLUSIVE, &dpo); @@ -862,9 +829,9 @@ mfib_entry_path_update (fib_node_index_t mfib_entry_index, { fib_node_index_t path_index; mfib_path_ext_t *path_ext; - mfib_itf_flags_t old, new; mfib_entry_t *mfib_entry; mfib_entry_src_t *msrc; + mfib_itf_flags_t old; mfib_entry = mfib_entry_get(mfib_entry_index); ASSERT(NULL != mfib_entry); @@ -900,37 +867,32 @@ mfib_entry_path_update (fib_node_index_t mfib_entry_index, { mfib_itf_t *mfib_itf; - new = itf_flags; - - if (old != new) + if (old != itf_flags) { - if (MFIB_ITF_FLAG_NONE == new) - { - /* - * no more interface flags on this path, remove - * from the data-plane set - */ - mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index); - } - else if (MFIB_ITF_FLAG_NONE == old) + /* + * change of flag contributions + */ + mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs, + rpath[0].frp_sw_if_index); + + if (NULL == mfib_itf) { - /* - * This interface is now contributing - */ mfib_entry_itf_add(msrc, rpath[0].frp_sw_if_index, - mfib_itf_create(rpath[0].frp_sw_if_index, - itf_flags)); + mfib_itf_create(path_index, itf_flags)); } else { - /* - * change of flag contributions - */ - mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs, - rpath[0].frp_sw_if_index); - /* Seen by packets inflight */ - mfib_itf->mfi_flags = new; + if (mfib_itf_update(mfib_itf, + path_index, + itf_flags)) + { + /* + * no more interface flags on this path, remove + * from the data-plane set + */ + mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index); + } } } } @@ -979,7 +941,21 @@ mfib_entry_path_remove (fib_node_index_t mfib_entry_index, mfib_path_ext_remove(msrc, path_index); if (~0 != rpath[0].frp_sw_if_index) { - mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index); + mfib_itf_t *mfib_itf; + + mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs, + rpath[0].frp_sw_if_index); + + if (mfib_itf_update(mfib_itf, + path_index, + MFIB_ITF_FLAG_NONE)) + { + /* + * no more interface flags on this path, remove + * from the data-plane set + */ + mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index); + } } } @@ -1098,6 +1074,72 @@ mfib_entry_cmp_for_sort (void *i1, void *i2) *mfib_entry_index2)); } +static void +mfib_entry_last_lock_gone (fib_node_t *node) +{ + mfib_entry_t *mfib_entry; + mfib_entry_src_t *msrc; + + mfib_entry = mfib_entry_from_fib_node(node); + + dpo_reset(&mfib_entry->mfe_rep); + + MFIB_ENTRY_DBG(mfib_entry, "last-lock"); + + vec_foreach(msrc, mfib_entry->mfe_srcs) + { + mfib_entry_src_flush(msrc); + } + + vec_free(mfib_entry->mfe_srcs); + + fib_node_deinit(&mfib_entry->mfe_node); + pool_put(mfib_entry_pool, mfib_entry); +} + +u32 +mfib_entry_get_stats_index (fib_node_index_t fib_entry_index) +{ + mfib_entry_t *mfib_entry; + + mfib_entry = mfib_entry_get(fib_entry_index); + + return (mfib_entry->mfe_rep.dpoi_index); +} + +/* + * mfib_entry_back_walk_notify + * + * A back walk has reach this entry. + */ +static fib_node_back_walk_rc_t +mfib_entry_back_walk_notify (fib_node_t *node, + fib_node_back_walk_ctx_t *ctx) +{ + mfib_entry_recalculate_forwarding(mfib_entry_from_fib_node(node)); + + return (FIB_NODE_BACK_WALK_CONTINUE); +} + +static void +mfib_entry_show_memory (void) +{ + fib_show_memory_usage("multicast-Entry", + pool_elts(mfib_entry_pool), + pool_len(mfib_entry_pool), + sizeof(mfib_entry_t)); +} + +/* + * The MFIB entry's graph node virtual function table + */ +static const fib_node_vft_t mfib_entry_vft = { + .fnv_get = mfib_entry_get_node, + .fnv_last_lock = mfib_entry_last_lock_gone, + .fnv_back_walk = mfib_entry_back_walk_notify, + .fnv_mem_show = mfib_entry_show_memory, +}; + void mfib_entry_lock (fib_node_index_t mfib_entry_index) { @@ -1156,6 +1198,7 @@ mfib_entry_module_init (void) { fib_node_register_type (FIB_NODE_TYPE_MFIB_ENTRY, &mfib_entry_vft); dpo_register(DPO_MFIB_ENTRY, &mfib_entry_dpo_vft, mfib_entry_nodes); + mfib_entry_logger = vlib_log_register_class("mfib", "entry"); } void @@ -1197,6 +1240,16 @@ mfib_entry_get_fib_index (fib_node_index_t mfib_entry_index) return (mfib_entry->mfe_fib_index); } +const dpo_id_t* +mfib_entry_contribute_ip_forwarding (fib_node_index_t mfib_entry_index) +{ + mfib_entry_t *mfib_entry; + + mfib_entry = mfib_entry_get(mfib_entry_index); + + return (&mfib_entry->mfe_rep); +} + void mfib_entry_contribute_forwarding (fib_node_index_t mfib_entry_index, fib_forward_chain_type_t type,