MPLS Mcast
[vpp.git] / src / vnet / lisp-gpe / lisp_gpe_fwd_entry.c
index 46cffda..d2954e9 100644 (file)
@@ -88,6 +88,7 @@ ip_dst_fib_add_route (u32 dst_fib_index, const ip_prefix_t * dst_prefix)
                                          (ip_prefix_version (dst_prefix) ==
                                           IP6 ? DPO_PROTO_IP6 :
                                           DPO_PROTO_IP4),
+                                         LOOKUP_UNICAST,
                                          LOOKUP_INPUT_SRC_ADDR,
                                          LOOKUP_TABLE_FROM_CONFIG,
                                          &src_lkup_dpo);
@@ -283,12 +284,21 @@ static void
 create_fib_entries (lisp_gpe_fwd_entry_t * lfe)
 {
   dpo_proto_t dproto;
-
+  ip_prefix_t ippref;
   dproto = (ip_prefix_version (&lfe->key->rmt.ippref) == IP4 ?
            DPO_PROTO_IP4 : DPO_PROTO_IP6);
 
-  lfe->src_fib_index = ip_dst_fib_add_route (lfe->eid_fib_index,
-                                            &lfe->key->rmt.ippref);
+  if (lfe->is_src_dst)
+    {
+      lfe->src_fib_index = ip_dst_fib_add_route (lfe->eid_fib_index,
+                                                &lfe->key->rmt.ippref);
+      memcpy (&ippref, &lfe->key->lcl.ippref, sizeof (ippref));
+    }
+  else
+    {
+      lfe->src_fib_index = lfe->eid_fib_index;
+      memcpy (&ippref, &lfe->key->rmt.ippref, sizeof (ippref));
+    }
 
   if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE == lfe->type)
     {
@@ -310,44 +320,29 @@ create_fib_entries (lisp_gpe_fwd_entry_t * lfe)
          dpo_copy (&dpo, drop_dpo_get (dproto));
          break;
        }
-      ip_src_fib_add_route_w_dpo (lfe->src_fib_index,
-                                 &lfe->key->lcl.ippref, &dpo);
+      ip_src_fib_add_route_w_dpo (lfe->src_fib_index, &ippref, &dpo);
       dpo_reset (&dpo);
     }
   else
     {
-      ip_src_fib_add_route (lfe->src_fib_index,
-                           &lfe->key->lcl.ippref, lfe->paths);
+      ip_src_fib_add_route (lfe->src_fib_index, &ippref, lfe->paths);
     }
 }
 
 static void
 delete_fib_entries (lisp_gpe_fwd_entry_t * lfe)
 {
-  ip_src_dst_fib_del_route (lfe->src_fib_index,
-                           &lfe->key->lcl.ippref,
-                           lfe->eid_fib_index, &lfe->key->rmt.ippref);
-}
+  fib_prefix_t dst_fib_prefix;
 
-static void
-gid_to_dp_address (gid_address_t * g, dp_address_t * d)
-{
-  switch (gid_address_type (g))
+  if (lfe->is_src_dst)
+    ip_src_dst_fib_del_route (lfe->src_fib_index,
+                             &lfe->key->lcl.ippref,
+                             lfe->eid_fib_index, &lfe->key->rmt.ippref);
+  else
     {
-    case GID_ADDR_IP_PREFIX:
-    case GID_ADDR_SRC_DST:
-      ip_prefix_copy (&d->ippref, &gid_address_ippref (g));
-      d->type = FID_ADDR_IP_PREF;
-      break;
-    case GID_ADDR_MAC:
-      mac_copy (&d->mac, &gid_address_mac (g));
-      d->type = FID_ADDR_MAC;
-      break;
-    case GID_ADDR_NSH:
-    default:
-      d->nsh = gid_address_nsh (g).spi << 8 | gid_address_nsh (g).si;
-      d->type = FID_ADDR_NSH;
-      break;
+      ip_prefix_to_fib_prefix (&lfe->key->rmt.ippref, &dst_fib_prefix);
+      fib_table_entry_delete (lfe->src_fib_index, &dst_fib_prefix,
+                             FIB_SOURCE_LISP);
     }
 }
 
@@ -457,6 +452,7 @@ add_ip_fwd_entry (lisp_gpe_main_t * lgm,
   lfe->eid_table_id = a->table_id;
   lfe->eid_fib_index = fib_table_find_or_create_and_lock (fproto,
                                                          lfe->eid_table_id);
+  lfe->is_src_dst = a->is_src_dst;
 
   if (LISP_GPE_FWD_ENTRY_TYPE_NEGATIVE != lfe->type)
     {
@@ -464,7 +460,6 @@ add_ip_fwd_entry (lisp_gpe_main_t * lgm,
     }
 
   create_fib_entries (lfe);
-
   return (0);
 }
 
@@ -808,13 +803,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 +837,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)
@@ -1177,6 +1172,70 @@ vnet_lisp_gpe_add_del_fwd_entry (vnet_lisp_gpe_add_del_fwd_entry_args_t * a,
     }
 }
 
+void
+vnet_lisp_flush_stats (void)
+{
+  lisp_gpe_main_t *lgm = vnet_lisp_gpe_get_main ();
+  lisp_stats_t *stat;
+
+  /* *INDENT-OFF* */
+  pool_foreach (stat, lgm->lisp_stats_pool,
+  {
+    stat->pkt_count = 0;
+    stat->bytes = 0;
+  });
+  /* *INDENT-ON* */
+}
+
+static void
+lisp_del_adj_stats (lisp_gpe_main_t * lgm, u32 fwd_entry_index, u32 ti)
+{
+  hash_pair_t *hp;
+  lisp_stats_key_t key;
+  void *key_copy;
+  uword *p;
+  lisp_stats_t *s;
+
+  memset (&key, 0, sizeof (key));
+  key.fwd_entry_index = fwd_entry_index;
+  key.tunnel_index = ti;
+
+  p = hash_get_mem (lgm->lisp_stats_index_by_key, &key);
+  if (p)
+    {
+      s = pool_elt_at_index (lgm->lisp_stats_pool, p[0]);
+      hp = hash_get_pair (lgm->lisp_stats_index_by_key, &key);
+      key_copy = (void *) (hp->key);
+      hash_unset_mem (lgm->lisp_stats_index_by_key, &key);
+      clib_mem_free (key_copy);
+      pool_put (lgm->lisp_stats_pool, s);
+    }
+}
+
+void
+vnet_lisp_del_fwd_stats (vnet_lisp_gpe_add_del_fwd_entry_args_t * a,
+                        u32 fwd_entry_index)
+{
+  lisp_gpe_main_t *lgm = &lisp_gpe_main;
+  lisp_gpe_fwd_entry_key_t fe_key;
+  lisp_gpe_fwd_entry_t *lfe;
+  lisp_fwd_path_t *path;
+  const lisp_gpe_adjacency_t *ladj;
+
+  lfe = find_fwd_entry (lgm, a, &fe_key);
+  if (!lfe)
+    return;
+
+  if (LISP_GPE_FWD_ENTRY_TYPE_NORMAL != lfe->type)
+    return;
+
+  vec_foreach (path, lfe->paths)
+  {
+    ladj = lisp_gpe_adjacency_get (path->lisp_adj);
+    lisp_del_adj_stats (lgm, fwd_entry_index, ladj->tunnel_index);
+  }
+}
+
 /**
  * @brief Flush all the forwrding entries
  */