MPLS Mcast
[vpp.git] / src / vnet / adj / adj.c
index 7cf9e9d..36dfe50 100644 (file)
@@ -18,6 +18,7 @@
 #include <vnet/adj/adj_glean.h>
 #include <vnet/adj/adj_midchain.h>
 #include <vnet/adj/adj_mcast.h>
+#include <vnet/adj/adj_delegate.h>
 #include <vnet/fib/fib_node_list.h>
 
 /* Adjacency packet/byte counters indexed by adjacency index. */
@@ -57,13 +58,18 @@ adj_alloc (fib_protocol_t proto)
     vlib_validate_combined_counter(&adjacency_counters,
                                    adj_get_index(adj));
 
-    adj->rewrite_header.sw_if_index = ~0;
-    adj->lookup_next_index = 0;
-
     fib_node_init(&adj->ia_node,
                   FIB_NODE_TYPE_ADJ);
+
     adj->ia_nh_proto = proto;
     adj->ia_flags = 0;
+    adj->rewrite_header.sw_if_index = ~0;
+    adj->lookup_next_index = 0;
+    adj->ia_delegates = NULL;
+
+    /* lest it become a midchain in the future */
+    memset(&adj->sub_type.midchain.next_dpo, 0,
+           sizeof(adj->sub_type.midchain.next_dpo));
 
     ip4_main.lookup_main.adjacency_heap = adj_pool;
     ip6_main.lookup_main.adjacency_heap = adj_pool;
@@ -116,17 +122,28 @@ format_ip_adjacency (u8 * s, va_list * args)
     case IP_LOOKUP_NEXT_MCAST:
        s = format (s, "%U", format_adj_mcast, adj_index, 0);
        break;
+    case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
+       s = format (s, "%U", format_adj_mcast_midchain, adj_index, 0);
+       break;
     default:
        break;
     }
 
     if (fiaf & FORMAT_IP_ADJACENCY_DETAIL)
     {
+        adj_delegate_type_t adt;
+        adj_delegate_t *aed;
         vlib_counter_t counts;
 
         vlib_get_combined_counter(&adjacency_counters, adj_index, &counts);
         s = format (s, "\n counts:[%Ld:%Ld]", counts.packets, counts.bytes);
        s = format (s, "\n locks:%d", adj->ia_node.fn_locks);
+       s = format(s, "\n delegates:\n  ");
+        FOR_EACH_ADJ_DELEGATE(adj, adt, aed,
+        {
+            s = format(s, "  %U\n", format_adj_deletegate, aed);
+        });
+
        s = format(s, "\n children:\n  ");
        s = fib_node_children_format(adj->ia_node.fn_children, s);
     }
@@ -170,10 +187,15 @@ adj_last_lock_gone (ip_adjacency_t *adj)
                         adj->rewrite_header.sw_if_index);
        break;
     case IP_LOOKUP_NEXT_MCAST:
+    case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
        adj_mcast_remove(adj->ia_nh_proto,
                         adj->rewrite_header.sw_if_index);
        break;
-    default:
+    case IP_LOOKUP_NEXT_DROP:
+    case IP_LOOKUP_NEXT_PUNT:
+    case IP_LOOKUP_NEXT_LOCAL:
+    case IP_LOOKUP_NEXT_ICMP_ERROR:
+    case IP_LOOKUP_N_NEXT:
        /*
         * type not stored in any DB from which we need to remove it
         */
@@ -183,6 +205,8 @@ adj_last_lock_gone (ip_adjacency_t *adj)
     vlib_worker_thread_barrier_release(vm);
 
     fib_node_deinit(&adj->ia_node);
+    ASSERT(0 == vec_len(adj->ia_delegates));
+    vec_free(adj->ia_delegates);
     pool_put(adj_pool, adj);
 }
 
@@ -322,6 +346,7 @@ adj_walk (u32 sw_if_index,
     FOR_EACH_FIB_IP_PROTOCOL(proto)
     {
         adj_nbr_walk(sw_if_index, proto, cb, ctx);
+        adj_mcast_walk(sw_if_index, proto, cb, ctx);
     }
 }
 
@@ -351,6 +376,33 @@ adj_get_sw_if_index (adj_index_t ai)
     return (adj->rewrite_header.sw_if_index);
 }
 
+/**
+ * @brief Return true if the adjacency is 'UP', i.e. can be used for forwarding
+ * 0 is down, !0 is up.
+ */
+int
+adj_is_up (adj_index_t ai)
+{
+    const adj_delegate_t *aed;
+
+    aed = adj_delegate_get(adj_get(ai), ADJ_DELEGATE_BFD);
+
+    if (NULL == aed)
+    {
+        /*
+         * no BFD tracking - resolved
+         */
+        return (!0);
+    }
+    else
+    {
+        /*
+         * defer to the state of the BFD tracking
+         */
+        return (ADJ_BFD_STATE_UP == aed->ad_bfd_state);
+    }
+}
+
 /**
  * @brief Return the rewrite string of the adjacency
  */
@@ -501,9 +553,9 @@ adj_show (vlib_main_t * vm,
  * [@0]
  * [@1]  glean: loop0
  * [@2] ipv4 via 1.0.0.2 loop0: IP4: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
- * [@3] mpls via 1.0.0.2 loop0: MPLS_UNICAST: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
+ * [@3] mpls via 1.0.0.2 loop0: MPLS: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
  * [@4] ipv4 via 1.0.0.3 loop0: IP4: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
- * [@5] mpls via 1.0.0.3 loop0: MPLS_UNICAST: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
+ * [@5] mpls via 1.0.0.3 loop0: MPLS: 00:00:22:aa:bb:cc -> 00:00:11:aa:bb:cc
  * @cliexend
  ?*/
 VLIB_CLI_COMMAND (adj_show_command, static) = {