Add NSH to GPE decap path 02/5502/10
authorFlorin Coras <fcoras@cisco.com>
Thu, 23 Feb 2017 07:38:08 +0000 (23:38 -0800)
committerFlorin Coras <fcoras@cisco.com>
Sun, 26 Feb 2017 02:36:51 +0000 (18:36 -0800)
Change-Id: I97681322fa9ca81736100b4d32eab84868886c7b
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vnet/lisp-gpe/decap.c
src/vnet/lisp-gpe/interface.c
src/vnet/lisp-gpe/lisp_gpe.c
src/vnet/lisp-gpe/lisp_gpe.h
src/vnet/lisp-gpe/lisp_gpe_fwd_entry.c

index 637d4a7..5fd449c 100644 (file)
@@ -89,6 +89,8 @@ next_index_to_iface (lisp_gpe_main_t * lgm, u32 next_index)
     return &lgm->l3_ifaces;
   else if (LISP_GPE_INPUT_NEXT_L2_INPUT == next_index)
     return &lgm->l2_ifaces;
+  else if (LISP_GPE_INPUT_NEXT_NSH_INPUT == next_index)
+    return &lgm->nsh_ifaces;
   clib_warning ("next_index not associated to an interface!");
   return 0;
 }
@@ -492,6 +494,52 @@ VLIB_REGISTER_NODE (lisp_gpe_ip6_input_node) = {
 };
 /* *INDENT-ON* */
 
+/**
+ * Adds arc from lisp-gpe-input to nsh-input if nsh-input is available
+ */
+static void
+gpe_add_arc_from_input_to_nsh ()
+{
+  lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main ();
+  vlib_main_t *vm = lgm->vlib_main;
+  vlib_node_t *nsh_input;
+
+  /* Arc already exists */
+  if (next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH]
+      != LISP_GPE_INPUT_NEXT_DROP)
+    return;
+
+  /* Check if nsh-input is available */
+  if ((nsh_input = vlib_get_node_by_name (vm, (u8 *) "nsh-input")))
+    {
+      u32 slot4, slot6;
+      slot4 = vlib_node_add_next_with_slot (vm, lisp_gpe_ip4_input_node.index,
+                                           nsh_input->index,
+                                           LISP_GPE_NEXT_PROTO_NSH);
+      slot6 = vlib_node_add_next_with_slot (vm, lisp_gpe_ip6_input_node.index,
+                                           nsh_input->index,
+                                           LISP_GPE_NEXT_PROTO_NSH);
+      ASSERT (slot4 == slot6 && slot4 == LISP_GPE_INPUT_NEXT_NSH_INPUT);
+
+      next_proto_to_next_index[LISP_GPE_NEXT_PROTO_NSH] = slot4;
+    }
+}
+
+/** GPE decap init function. */
+clib_error_t *
+gpe_decap_init (vlib_main_t * vm)
+{
+  clib_error_t *error = 0;
+
+  if ((error = vlib_call_init_function (vm, lisp_gpe_init)))
+    return error;
+
+  gpe_add_arc_from_input_to_nsh ();
+  return 0;
+}
+
+VLIB_INIT_FUNCTION (gpe_decap_init);
+
 /*
  * fd.io coding-style-patch-verification: ON
  *
index 19ac22e..1335927 100644 (file)
@@ -899,22 +899,6 @@ lisp_gpe_add_del_iface_command_fn (vlib_main_t * vm, unformat_input_t * input,
        lisp_gpe_tenant_l3_iface_unlock (vni);
     }
 
-  if (nsh_iface)
-    {
-      if (is_add)
-       {
-         if (~0 == lisp_gpe_add_nsh_iface (&lisp_gpe_main))
-           {
-             error = clib_error_return (0, "NSH interface not created");
-             goto done;
-           }
-         else
-           {
-             lisp_gpe_del_nsh_iface (&lisp_gpe_main);
-           }
-       }
-    }
-
 done:
   unformat_free (line_input);
 
index f2fbcbd..479a626 100644 (file)
@@ -326,6 +326,7 @@ lisp_gpe_init (vlib_main_t * vm)
                         lisp_gpe_ip4_input_node.index, 1 /* is_ip4 */ );
   udp_register_dst_port (vm, UDP_DST_PORT_lisp_gpe6,
                         lisp_gpe_ip6_input_node.index, 0 /* is_ip4 */ );
+
   return 0;
 }
 
index e92df38..c498b7c 100644 (file)
@@ -65,6 +65,9 @@ typedef enum
     LISP_GPE_INPUT_N_NEXT,
 } lisp_gpe_input_next_t;
 
+/* Arc to nsh-input added only if nsh-input exists */
+#define LISP_GPE_INPUT_NEXT_NSH_INPUT 4
+
 typedef enum
 {
 #define lisp_gpe_error(n,s) LISP_GPE_ERROR_##n,
index 46cffda..2eb5ced 100644 (file)
@@ -808,13 +808,13 @@ add_l2_fwd_entry (lisp_gpe_main_t * lgm,
  * @return next node index.
  */
 const dpo_id_t *
-lisp_nsh_fib_lookup (lisp_gpe_main_t * lgm, u32 spi_si)
+lisp_nsh_fib_lookup (lisp_gpe_main_t * lgm, u32 spi_si_net_order)
 {
   int rv;
   BVT (clib_bihash_kv) kv, value;
 
   memset (&kv, 0, sizeof (kv));
-  kv.key[0] = spi_si;
+  kv.key[0] = spi_si_net_order;
   rv = BV (clib_bihash_search_inline_2) (&lgm->nsh_fib, &kv, &value);
 
   if (rv != 0)
@@ -842,14 +842,14 @@ lisp_nsh_fib_lookup (lisp_gpe_main_t * lgm, u32 spi_si)
  * @return ~0 or value of overwritten entry.
  */
 static u32
-lisp_nsh_fib_add_del_entry (u32 spi_si, u32 lfei, u8 is_add)
+lisp_nsh_fib_add_del_entry (u32 spi_si_host_order, u32 lfei, u8 is_add)
 {
   lisp_gpe_main_t *lgm = &lisp_gpe_main;
   BVT (clib_bihash_kv) kv, value;
   u32 old_val = ~0;
 
   memset (&kv, 0, sizeof (kv));
-  kv.key[0] = spi_si;
+  kv.key[0] = clib_host_to_net_u32 (spi_si_host_order);
   kv.value = 0ULL;
 
   if (BV (clib_bihash_search) (&lgm->nsh_fib, &kv, &value) == 0)