mroute routers in the stats segment
[vpp.git] / src / vnet / mfib / mfib_entry.c
index 847f25e..7427334 100644 (file)
@@ -199,14 +199,12 @@ format_mfib_entry (u8 * s, va_list * args)
             {
                 s = fib_path_list_format(msrc->mfes_pl, s);
             }
-            s = format (s, "    Extensions:\n",
-                        mfib_source_names[msrc->mfes_src]);
+            s = format (s, "    Extensions:\n");
             hash_foreach(path_index, mpi, msrc->mfes_exts,
             ({
                 s = format(s, "     %U\n", format_mfib_entry_path_ext, mpi);
             }));
-            s = format (s, "    Interface-Forwarding:\n",
-                        mfib_source_names[msrc->mfes_src]);
+            s = format (s, "    Interface-Forwarding:\n");
             hash_foreach(sw_if_index, mfi, msrc->mfes_itfs,
             ({
                 s = format(s, "    %U\n", format_mfib_itf, mfi);
@@ -219,7 +217,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),
@@ -240,9 +241,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);
 }
 
@@ -302,7 +301,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;
 
@@ -336,6 +335,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)
 {
@@ -368,62 +378,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,
@@ -451,7 +405,7 @@ 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);
@@ -466,6 +420,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);
 
@@ -529,7 +484,7 @@ typedef struct mfib_entry_collect_forwarding_ctx_t_
     mfib_entry_src_t *msrc;
 } mfib_entry_collect_forwarding_ctx_t;
 
-static int
+static fib_path_list_walk_rc_t
 mfib_entry_src_collect_forwarding (fib_node_index_t pl_index,
                                    fib_node_index_t path_index,
                                    void *arg)
@@ -544,7 +499,7 @@ mfib_entry_src_collect_forwarding (fib_node_index_t pl_index,
      */
     if (!fib_path_is_resolved(path_index))
     {
-        return (!0);
+        return (FIB_PATH_LIST_WALK_CONTINUE);
     }
 
     /*
@@ -558,7 +513,7 @@ mfib_entry_src_collect_forwarding (fib_node_index_t pl_index,
     if (NULL != path_ext &&
         !(path_ext->mfpe_flags & MFIB_ITF_FLAG_FORWARD))
     {
-        return (!0);
+        return (FIB_PATH_LIST_WALK_CONTINUE);
     }
     
     switch (ctx->fct)
@@ -581,11 +536,12 @@ 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;
     }
 
-    return (!0);
+    return (FIB_PATH_LIST_WALK_CONTINUE);
 }
 
 static void
@@ -596,6 +552,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)
     {
@@ -660,6 +625,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
     {
@@ -801,18 +777,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);
 
@@ -864,9 +838,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);
@@ -902,37 +876,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);
+                }
             }
         }
     }
@@ -981,7 +950,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);
+            }
         }
     }
 
@@ -1100,6 +1083,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)
 {
@@ -1199,6 +1248,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,