VPP-376: Refactor LISP dump API + VAT
[vpp.git] / vnet / vnet / lisp-cp / control.c
index d7ac3c5..16d7bfa 100644 (file)
@@ -235,7 +235,7 @@ dp_del_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
   u32 sw_if_index;
   a->is_add = 0;
   a->locator_pairs = fe->locator_pairs;
-  a->vni = gid_address_vni (&a->rmt_eid);
+  a->vni = gid_address_vni (&fe->deid);
   gid_address_copy (&a->rmt_eid, &fe->deid);
 
   vnet_lisp_gpe_add_del_fwd_entry (a, &sw_if_index);
@@ -1049,6 +1049,12 @@ lisp_add_del_remote_mapping_command_fn (vlib_main_t * vm,
       else if (unformat (line_input, "rloc %U", unformat_ip_address,
                         &gid_address_ip (&rloc.address)))
        {
+         /* since rloc is stored in ip prefix we need to set prefix length */
+         ip_prefix_t *pref = &gid_address_ippref (&rloc.address);
+
+         u8 version = gid_address_ip_version (&rloc.address);
+         ip_prefix_len (pref) = ip_address_max_len (version);
+
          vec_add1 (rlocs, rloc);
          curr_rloc = &rlocs[vec_len (rlocs) - 1];
        }
@@ -1710,7 +1716,7 @@ vnet_lisp_add_del_locator (vnet_lisp_add_del_locator_set_args_t * a,
        vec_validate (lcm->locator_to_locator_sets, loc_index);
        ls_indexes = vec_elt_at_index (lcm->locator_to_locator_sets,
                                       loc_index);
-       vec_add1 (ls_indexes[0], ls_index);
+       vec_add1 (ls_indexes[0], p[0]);
       }
     }
   else
@@ -2005,12 +2011,42 @@ lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
                                    vlib_cli_command_t * cmd)
 {
   hash_pair_t *p;
+  unformat_input_t _line_input, *line_input = &_line_input;
   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+  uword *vni_table = 0;
+  u8 is_l2 = 0;
 
-  vlib_cli_output (vm, "%=10s%=10s", "VNI", "VRF");
+  /* Get a line of input. */
+  if (!unformat_user (input, unformat_line_input, line_input))
+    return 0;
+
+  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (line_input, "l2"))
+       {
+         vni_table = lcm->bd_id_by_vni;
+         is_l2 = 1;
+       }
+      else if (unformat (line_input, "l3"))
+       {
+         vni_table = lcm->table_id_by_vni;
+         is_l2 = 0;
+       }
+      else
+       return clib_error_return (0, "parse error: '%U'",
+                                 format_unformat_error, line_input);
+    }
+
+  if (!vni_table)
+    {
+      vlib_cli_output (vm, "Error: expected l2|l3 param!\n");
+      return 0;
+    }
+
+  vlib_cli_output (vm, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
 
   /* *INDENT-OFF* */
-  hash_foreach_pair (p, lcm->table_id_by_vni,
+  hash_foreach_pair (p, vni_table,
   ({
     vlib_cli_output (vm, "%=10d%=10d", p->key, p->value[0]);
   }));
@@ -2022,7 +2058,7 @@ lisp_show_eid_table_map_command_fn (vlib_main_t * vm,
 /* *INDENT-OFF* */
 VLIB_CLI_COMMAND (lisp_show_eid_table_map_command) = {
     .path = "show lisp eid-table map",
-    .short_help = "show lisp eid-table vni to vrf mappings",
+    .short_help = "show lisp eid-table l2|l3",
     .function = lisp_show_eid_table_map_command_fn,
 };
 /* *INDENT-ON* */
@@ -2183,7 +2219,7 @@ lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
   u32 *locit;
   lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
 
-  vlib_cli_output (vm, "%=20s%=16s%=16s%=16s", "Locator-set", "Locator",
+  vlib_cli_output (vm, "%s%=16s%=16s%=16s", "Locator-set", "Locator",
                   "Priority", "Weight");
 
   /* *INDENT-OFF* */
@@ -2193,11 +2229,11 @@ lisp_cp_show_locator_sets_command_fn (vlib_main_t * vm,
     int next_line = 0;
     if (lsit->local)
       {
-        msg = format (msg, "%=16v", lsit->name);
+        msg = format (msg, "%v", lsit->name);
       }
     else
       {
-        msg = format (msg, "%=16s", "remote");
+        msg = format (msg, "<%s-%d>", "remote", lsit - lcm->locator_set_pool);
       }
     vec_foreach (locit, lsit->locator_indices)
       {
@@ -3018,12 +3054,8 @@ lisp_cp_lookup (vlib_main_t * vm, vlib_node_runtime_t * node,
 
              memset (tr, 0, sizeof (*tr));
              gid_address_copy (&tr->dst_eid, &dst);
-             if (vec_len (lcm->map_resolvers) > 0)
-               {
-                 clib_memcpy (&tr->map_resolver_ip,
-                              vec_elt_at_index (lcm->map_resolvers, 0),
-                              sizeof (ip_address_t));
-               }
+             ip_address_copy (&tr->map_resolver_ip,
+                              &lcm->active_map_resolver);
            }
          gid_address_free (&dst);
          gid_address_free (&src);
@@ -3342,6 +3374,7 @@ lisp_cp_init (vlib_main_t * vm)
   lcm->vnet_main = vnet_get_main ();
   lcm->mreq_itr_rlocs = ~0;
   lcm->lisp_pitr = 0;
+  memset (&lcm->active_map_resolver, 0, sizeof (lcm->active_map_resolver));
 
   lcm->pending_map_request_lock =
     clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);