Fix vnet unit tests
[vpp.git] / src / vnet / lisp-cp / control.c
index 5c901f3..c009330 100644 (file)
@@ -44,13 +44,6 @@ typedef struct
   u8 smr_invoked;
 } map_request_args_t;
 
-typedef struct
-{
-  u64 nonce;
-  u8 is_rloc_probe;
-  mapping_t *mappings;
-} map_records_arg_t;
-
 u8
 vnet_lisp_get_map_request_mode (void)
 {
@@ -285,7 +278,7 @@ dp_del_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
   if (fe->is_src_dst)
     gid_address_copy (&a->lcl_eid, &fe->leid);
 
-  vnet_lisp_del_fwd_stats (a, feip[0]);
+  vnet_lisp_gpe_del_fwd_counters (a, feip[0]);
   vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
 
   /* delete entry in fwd table */
@@ -532,10 +525,18 @@ dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
       a->action = rmt_map->action;
     }
 
-  vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
+  rv = vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
+  if (rv)
+    {
+      if (a->locator_pairs)
+       vec_free (a->locator_pairs);
+      return;
+    }
 
-  /* add tunnel to fwd entry table XXX check return value from DP insertion */
+  /* add tunnel to fwd entry table */
   pool_get (lcm->fwd_entry_pool, fe);
+  vnet_lisp_gpe_add_fwd_counters (a, fe - lcm->fwd_entry_pool);
+
   fe->locator_pairs = a->locator_pairs;
   gid_address_copy (&fe->reid, &a->rmt_eid);
 
@@ -1469,6 +1470,58 @@ is_locator_in_locator_set (lisp_cp_main_t * lcm, locator_set_t * ls,
   return 0;
 }
 
+static void
+update_adjacencies_by_map_index (lisp_cp_main_t * lcm, u8 is_local,
+                                u32 mapping_index, u8 remove_only)
+{
+  fwd_entry_t *fwd;
+  mapping_t *map;
+  vnet_lisp_add_del_adjacency_args_t _a, *a = &_a;
+
+  map = pool_elt_at_index (lcm->mapping_pool, mapping_index);
+
+  /* *INDENT-OFF* */
+  pool_foreach(fwd, lcm->fwd_entry_pool,
+  ({
+    if ((is_local && 0 == gid_address_cmp (&map->eid, &fwd->leid)) ||
+        (!is_local && 0 == gid_address_cmp (&map->eid, &fwd->reid)))
+      {
+        a->is_add = 0;
+        gid_address_copy (&a->leid, &fwd->leid);
+        gid_address_copy (&a->reid, &fwd->reid);
+
+        vnet_lisp_add_del_adjacency (a);
+
+        if (!remove_only)
+          {
+            a->is_add = 1;
+            vnet_lisp_add_del_adjacency (a);
+          }
+      }
+    }));
+  /* *INDENT-ON* */
+}
+
+static void
+update_fwd_entries_by_locator_set (lisp_cp_main_t * lcm, u8 is_local,
+                                  u32 ls_index, u8 remove_only)
+{
+  u32 i, *map_indexp;
+  u32 **eid_indexes;
+
+  if (vec_len (lcm->locator_set_to_eids) <= ls_index)
+    return;
+
+  eid_indexes = vec_elt_at_index (lcm->locator_set_to_eids, ls_index);
+
+  for (i = 0; i < vec_len (eid_indexes[0]); i++)
+    {
+      map_indexp = vec_elt_at_index (eid_indexes[0], i);
+      update_adjacencies_by_map_index (lcm, is_local, map_indexp[0],
+                                      remove_only);
+    }
+}
+
 static inline void
 remove_locator_from_locator_set (locator_set_t * ls, u32 * locit,
                                 u32 ls_index, u32 loc_id)
@@ -1551,24 +1604,38 @@ vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a,
   else
     {
       ls_index = p[0];
+      u8 removed;
 
-      itloc = a->locators;
-      loc_id = 0;
-      vec_foreach (locit, ls->locator_indices)
+      vec_foreach (itloc, a->locators)
       {
-       loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
+       removed = 0;
+       loc_id = 0;
+       vec_foreach (locit, ls->locator_indices)
+       {
+         loc = pool_elt_at_index (lcm->locator_pool, locit[0]);
 
-       if (loc->local && loc->sw_if_index == itloc->sw_if_index)
-         {
-           remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
-         }
-       if (0 == loc->local &&
-           !gid_address_cmp (&loc->address, &itloc->address))
-         {
-           remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
-         }
+         if (loc->local && loc->sw_if_index == itloc->sw_if_index)
+           {
+             removed = 1;
+             remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
+           }
+         if (0 == loc->local &&
+             !gid_address_cmp (&loc->address, &itloc->address))
+           {
+             removed = 1;
+             remove_locator_from_locator_set (ls, locit, ls_index, loc_id);
+           }
 
-       loc_id++;
+         if (removed)
+           {
+             /* update fwd entries using this locator in DP */
+             update_fwd_entries_by_locator_set (lcm, loc->local, ls_index,
+                                                vec_len (ls->locator_indices)
+                                                == 0);
+           }
+
+         loc_id++;
+       }
       }
     }
 
@@ -3411,7 +3478,7 @@ done:
   vec_free (itr_rlocs);
 }
 
-static map_records_arg_t *
+map_records_arg_t *
 parse_map_reply (vlib_buffer_t * b)
 {
   locator_t probed;
@@ -3427,6 +3494,11 @@ parse_map_reply (vlib_buffer_t * b)
   mrep_hdr = vlib_buffer_get_current (b);
   a->nonce = MREP_NONCE (mrep_hdr);
   a->is_rloc_probe = MREP_RLOC_PROBE (mrep_hdr);
+  if (!vlib_buffer_has_space (b, sizeof (*mrep_hdr)))
+    {
+      clib_mem_free (a);
+      return 0;
+    }
   vlib_buffer_pull (b, sizeof (*mrep_hdr));
 
   for (i = 0; i < MREP_REC_COUNT (mrep_hdr); i++)
@@ -3608,7 +3680,8 @@ lisp_stats_api_fill (lisp_cp_main_t * lcm, lisp_gpe_main_t * lgm,
                     lisp_api_stats_t * stat, lisp_stats_key_t * key,
                     u32 stats_index)
 {
-  lisp_stats_t *s;
+  vlib_counter_t v;
+  vlib_combined_counter_main_t *cm = &lgm->counters;
   lisp_gpe_fwd_entry_key_t fwd_key;
   const lisp_gpe_tunnel_t *lgt;
   fwd_entry_t *fe;
@@ -3627,8 +3700,8 @@ lisp_stats_api_fill (lisp_cp_main_t * lcm, lisp_gpe_main_t * lgm,
   stat->loc_rloc = lgt->key->lcl;
   stat->rmt_rloc = lgt->key->rmt;
 
-  s = pool_elt_at_index (lgm->lisp_stats_pool, stats_index);
-  stat->stats = *s;
+  vlib_get_combined_counter (cm, stats_index, &v);
+  stat->counters = v;
   return 1;
 }