VPP-362 Implement dumping of LISP adjacencies 47/3147/9
authorFilip Tehlar <ftehlar@cisco.com>
Fri, 23 Sep 2016 08:00:52 +0000 (10:00 +0200)
committerFlorin Coras <florin.coras@gmail.com>
Wed, 12 Oct 2016 13:24:03 +0000 (13:24 +0000)
Change-Id: Ieea56f3bf9e749878d9f2b35d39d9f7a9cdabde4
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
vnet/vnet/api_errno.h
vnet/vnet/lisp-cp/control.c
vnet/vnet/lisp-cp/control.h
vpp-api-test/vat/api_format.c
vpp-api/java/jvpp/gen/jvpp_gen.py
vpp-api/python/pneum/api-gen.py
vpp/vpp-api/api.c
vpp/vpp-api/custom_dump.c
vpp/vpp-api/vpe.api
vppapigen/pyvppapigen.py

index 2528322..baf3c61 100644 (file)
@@ -88,7 +88,8 @@ _(INCORRECT_ADJACENCY_TYPE, -94, "Invalid adjacency type for this operation") \
 _(EXCEEDED_NUMBER_OF_RANGES_CAPACITY, -95, "Operation would exceed configured capacity of ranges") \
 _(EXCEEDED_NUMBER_OF_PORTS_CAPACITY, -96, "Operation would exceed capacity of number of ports") \
 _(INVALID_ADDRESS_FAMILY, -97, "Invalid address family")                \
-_(INVALID_SUB_SW_IF_INDEX, -98, "Invalid sub-interface sw_if_index")
+_(INVALID_SUB_SW_IF_INDEX, -98, "Invalid sub-interface sw_if_index")    \
+_(TABLE_TOO_BIG, -99, "Table too big")
 
 typedef enum
 {
index 166c533..8dc4207 100644 (file)
@@ -368,7 +368,7 @@ dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
   u32 sw_if_index;
   uword *feip = 0, *dpid;
   fwd_entry_t *fe;
-  u8 type;
+  u8 type, is_src_dst = 0;
 
   memset (a, 0, sizeof (*a));
 
@@ -392,6 +392,7 @@ dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
                              &gid_address_sd_dst (&dst_map->eid));
       gid_address_sd_to_flat (&a->lcl_eid, &dst_map->eid,
                              &gid_address_sd_src (&dst_map->eid));
+      is_src_dst = 1;
     }
   else
     gid_address_copy (&a->rmt_eid, &dst_map->eid);
@@ -440,10 +441,94 @@ dp_add_fwd_entry (lisp_cp_main_t * lcm, u32 src_map_index, u32 dst_map_index)
   pool_get (lcm->fwd_entry_pool, fe);
   fe->locator_pairs = a->locator_pairs;
   gid_address_copy (&fe->reid, &a->rmt_eid);
+  gid_address_copy (&fe->leid, &src_map->eid);
+  fe->is_src_dst = is_src_dst;
   hash_set (lcm->fwd_entry_by_mapping_index, dst_map_index,
            fe - lcm->fwd_entry_pool);
 }
 
+/**
+ * Returns vector of adjacencies.
+ *
+ * The caller must free the vector returned by this function.
+ *
+ * @param vni virtual network identifier
+ * @return vector of adjacencies
+ */
+lisp_adjacency_t *
+vnet_lisp_adjacencies_get_by_vni (u32 vni)
+{
+  lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+  fwd_entry_t *fwd;
+  lisp_adjacency_t *adjs = 0, adj;
+
+  /* *INDENT-OFF* */
+  pool_foreach(fwd, lcm->fwd_entry_pool,
+  ({
+    if (gid_address_vni (&fwd->reid) != vni)
+      continue;
+
+    gid_address_copy (&adj.reid, &fwd->reid);
+    gid_address_copy (&adj.leid, &fwd->leid);
+    vec_add1 (adjs, adj);
+  }));
+  /* *INDENT-ON* */
+
+  return adjs;
+}
+
+static clib_error_t *
+lisp_show_adjacencies_command_fn (vlib_main_t * vm,
+                                 unformat_input_t * input,
+                                 vlib_cli_command_t * cmd)
+{
+  lisp_adjacency_t *adjs, *adj;
+  vlib_cli_output (vm, "%s %40s\n", "leid", "reid");
+  unformat_input_t _line_input, *line_input = &_line_input;
+  u32 vni = ~0;
+
+  /* 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, "vni %d", &vni))
+       ;
+      else
+       {
+         vlib_cli_output (vm, "parse error: '%U'",
+                          format_unformat_error, line_input);
+         return 0;
+       }
+    }
+
+  if (~0 == vni)
+    {
+      vlib_cli_output (vm, "error: no vni specified!");
+      return 0;
+    }
+
+  adjs = vnet_lisp_adjacencies_get_by_vni (vni);
+
+  vec_foreach (adj, adjs)
+  {
+    vlib_cli_output (vm, "%U %40U\n", format_gid_address, &adj->leid,
+                    format_gid_address, &adj->reid);
+  }
+  vec_free (adjs);
+
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (lisp_show_adjacencies_command) = {
+    .path = "show lisp adjacencies",
+    .short_help = "show lisp adjacencies",
+    .function = lisp_show_adjacencies_command_fn,
+};
+/* *INDENT-ON* */
+
 /**
  * Add/remove mapping to/from map-cache. Overwriting not allowed.
  */
@@ -977,7 +1062,8 @@ lisp_add_del_adjacency (lisp_cp_main_t * lcm, gid_address_t * local_eid,
       return VNET_API_ERROR_LISP_DISABLED;
     }
 
-  remote_mi = gid_dictionary_lookup (&lcm->mapping_index_by_gid, remote_eid);
+  remote_mi = gid_dictionary_sd_lookup (&lcm->mapping_index_by_gid,
+                                       remote_eid, local_eid);
   if (GID_LOOKUP_MISS == remote_mi)
     {
       clib_warning ("Remote eid %U not found. Cannot add adjacency!",
index a65ec4c..7a56d4f 100644 (file)
@@ -39,9 +39,16 @@ typedef struct
 {
   gid_address_t leid;
   gid_address_t reid;
+  u8 is_src_dst;
   locator_pair_t *locator_pairs;
 } fwd_entry_t;
 
+typedef struct
+{
+  gid_address_t leid;
+  gid_address_t reid;
+} lisp_adjacency_t;
+
 typedef enum
 {
   IP4_MISS_PACKET,
@@ -251,6 +258,7 @@ int vnet_lisp_clear_all_remote_adjacencies (void);
 int vnet_lisp_eid_table_map (u32 vni, u32 vrf, u8 is_l2, u8 is_add);
 int vnet_lisp_set_map_request_mode (u8 mode);
 u8 vnet_lisp_get_map_request_mode (void);
+lisp_adjacency_t *vnet_lisp_adjacencies_get_by_vni (u32 vni);
 
 static inline void
 lisp_pending_map_request_lock (lisp_cp_main_t * lcm)
index fec3158..71c6f24 100644 (file)
@@ -2602,6 +2602,78 @@ static void
   vec_free (next_decap_str);
 }
 
+static void
+  vl_api_lisp_adjacencies_get_reply_t_handler
+  (vl_api_lisp_adjacencies_get_reply_t * mp)
+{
+  vat_main_t *vam = &vat_main;
+  u32 i, n;
+  int retval = clib_net_to_host_u32 (mp->retval);
+  vl_api_lisp_adjacency_t *a;
+
+  if (retval)
+    goto end;
+
+  n = clib_net_to_host_u32 (mp->count);
+
+  for (i = 0; i < n; i++)
+    {
+      a = &mp->adjacencies[i];
+      fformat (vam->ofp, "%U %40U\n",
+              format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
+              format_lisp_flat_eid, a->eid_type, a->reid,
+              a->reid_prefix_len);
+    }
+
+end:
+  vam->retval = retval;
+  vam->result_ready = 1;
+}
+
+static void
+  vl_api_lisp_adjacencies_get_reply_t_handler_json
+  (vl_api_lisp_adjacencies_get_reply_t * mp)
+{
+  u8 *s = 0;
+  vat_main_t *vam = &vat_main;
+  vat_json_node_t *e = 0, root;
+  u32 i, n;
+  int retval = clib_net_to_host_u32 (mp->retval);
+  vl_api_lisp_adjacency_t *a;
+
+  if (retval)
+    goto end;
+
+  n = clib_net_to_host_u32 (mp->count);
+  vat_json_init_array (&root);
+
+  for (i = 0; i < n; i++)
+    {
+      e = vat_json_array_add (&root);
+      a = &mp->adjacencies[i];
+
+      vat_json_init_object (e);
+      s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
+                 a->leid_prefix_len);
+      vec_add1 (s, 0);
+      vat_json_object_add_string_copy (e, "leid", s);
+      vec_free (s);
+
+      s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
+                 a->reid_prefix_len);
+      vec_add1 (s, 0);
+      vat_json_object_add_string_copy (e, "reid", s);
+      vec_free (s);
+    }
+
+  vat_json_print (vam->ofp, &root);
+  vat_json_free (&root);
+
+end:
+  vam->retval = retval;
+  vam->result_ready = 1;
+}
+
 static void
 vl_api_lisp_map_resolver_details_t_handler (vl_api_lisp_map_resolver_details_t
                                            * mp)
@@ -3421,6 +3493,8 @@ static void vl_api_flow_classify_details_t_handler_json
 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
+#define vl_api_lisp_adjacencies_get_reply_t_endian vl_noop_handler
+#define vl_api_lisp_adjacencies_get_reply_t_print vl_noop_handler
 
 /*
  * Generate boilerplate reply handlers, which
@@ -3725,6 +3799,7 @@ _(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details)               \
 _(LISP_EID_TABLE_VNI_DETAILS, lisp_eid_table_vni_details)               \
 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details)                     \
 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details)                 \
+_(LISP_ADJACENCIES_GET_REPLY, lisp_adjacencies_get_reply)               \
 _(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply)                       \
 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY,                             \
   lisp_add_del_map_request_itr_rlocs_reply)                             \
@@ -13885,6 +13960,52 @@ api_lisp_gpe_tunnel_dump (vat_main_t * vam)
   return 0;
 }
 
+static int
+api_lisp_adjacencies_get (vat_main_t * vam)
+{
+  unformat_input_t *i = vam->input;
+  vl_api_lisp_adjacencies_get_t *mp;
+  f64 timeout = ~0;
+  u8 vni_set = 0;
+  u32 vni = ~0;
+
+  while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (i, "vni %d", &vni))
+       {
+         vni_set = 1;
+       }
+      else
+       {
+         errmsg ("parse error '%U'\n", format_unformat_error, i);
+         return -99;
+       }
+    }
+
+  if (!vni_set)
+    {
+      errmsg ("vni not set!\n");
+      return -99;
+    }
+
+  if (!vam->json_output)
+    {
+      fformat (vam->ofp, "%s %40s\n", "leid", "reid");
+    }
+
+  M (LISP_ADJACENCIES_GET, lisp_adjacencies_get);
+  mp->vni = clib_host_to_net_u32 (vni);
+
+  /* send it... */
+  S;
+
+  /* Wait for a reply... */
+  W;
+
+  /* NOTREACHED */
+  return 0;
+}
+
 static int
 api_lisp_map_resolver_dump (vat_main_t * vam)
 {
@@ -16237,6 +16358,7 @@ _(lisp_eid_table_vni_dump, "")                                          \
 _(lisp_eid_table_map_dump, "l2|l3")                                     \
 _(lisp_gpe_tunnel_dump, "")                                             \
 _(lisp_map_resolver_dump, "")                                           \
+_(lisp_adjacencies_get, "vni <vni>")                                    \
 _(show_lisp_status, "")                                                 \
 _(lisp_get_map_request_itr_rlocs, "")                                   \
 _(show_lisp_pitr, "")                                                   \
index 4781ea0..80bb4b9 100755 (executable)
@@ -63,7 +63,8 @@ cfg = importlib.import_module(inputfile, package=None)
 
 # FIXME: functions unsupported due to problems with vpe.api
 def is_supported(f_name):
-    return f_name not in {'vnet_ip4_fib_counters', 'vnet_ip6_fib_counters'}
+    return f_name not in {'vnet_ip4_fib_counters', 'vnet_ip6_fib_counters',
+            'lisp_adjacencies_get_reply', 'lisp_adjacencies_get'}
 
 
 def is_request_field(field_name):
index 6718de4..fcf293e 100755 (executable)
@@ -35,6 +35,7 @@ format_struct = {'u8': 'B',
                  'f64' : 'd',
                  'vl_api_ip4_fib_counter_t' : 'IBQQ',
                  'vl_api_ip6_fib_counter_t' : 'QQBQQ',
+                 'vl_api_lisp_adjacency_t' : 'B' * 35,
                  };
 #
 # NB: If new types are introduced in vpe.api, these must be updated.
@@ -47,6 +48,7 @@ type_size = {'u8':   1,
              'f64' : 8,
              'vl_api_ip4_fib_counter_t' : 21,
              'vl_api_ip6_fib_counter_t' : 33,
+             'vl_api_lisp_adjacency_t' : 35,
 };
 
 def get_args(t):
index 0ef6966..84e4d5d 100644 (file)
@@ -170,16 +170,31 @@ do {                                                            \
 #define REPLY_MACRO3(t, n, body)                               \
 do {                                                            \
     unix_shared_memory_queue_t * q;                             \
+    u8 is_error = 0;                                            \
     rv = vl_msg_api_pd_handler (mp, rv);                        \
     q = vl_api_client_index_to_input_queue (mp->client_index);  \
     if (!q)                                                     \
         return;                                                 \
                                                                 \
     rmp = vl_msg_api_alloc (sizeof (*rmp) + n);                 \
+    if (!rmp)                                                   \
+      {                                                         \
+        /* if there isn't enough memory, try to allocate */     \
+        /* some at least for returning an error */              \
+        rmp = vl_msg_api_alloc (sizeof (*rmp));                 \
+        if (!rmp)                                               \
+          return;                                               \
+                                                                \
+        memset (rmp, 0, sizeof (*rmp));                         \
+        rv = VNET_API_ERROR_TABLE_TOO_BIG;                      \
+        is_error = 1;                                           \
+      }                                                         \
+                                                                \
     rmp->_vl_msg_id = ntohs((t));                               \
     rmp->context = mp->context;                                 \
     rmp->retval = ntohl(rv);                                    \
-    do {body;} while (0);                                       \
+    if (!is_error)                                              \
+      do {body;} while (0);                                     \
     vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
 } while(0);
 
@@ -380,6 +395,7 @@ _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump)                           \
 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump)                       \
 _(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump)                     \
 _(LISP_EID_TABLE_VNI_DUMP, lisp_eid_table_vni_dump)                     \
+_(LISP_ADJACENCIES_GET, lisp_adjacencies_get)                           \
 _(SHOW_LISP_STATUS, show_lisp_status)                                   \
 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS,                                   \
   lisp_add_del_map_request_itr_rlocs)                                   \
@@ -6013,6 +6029,72 @@ send_eid_table_vni (u32 vni, unix_shared_memory_queue_t * q, u32 context)
   vl_msg_api_send_shmem (q, (u8 *) & rmp);
 }
 
+static void
+lisp_adjacency_copy (vl_api_lisp_adjacency_t * dst, lisp_adjacency_t * adjs)
+{
+  lisp_adjacency_t *adj;
+  vl_api_lisp_adjacency_t a;
+  u32 i, n = vec_len (adjs);
+
+  for (i = 0; i < n; i++)
+    {
+      adj = vec_elt_at_index (adjs, i);
+      memset (&a, 0, sizeof (a));
+
+      switch (gid_address_type (&adj->reid))
+       {
+       case GID_ADDR_IP_PREFIX:
+         a.reid_prefix_len = gid_address_ippref_len (&adj->reid);
+         a.leid_prefix_len = gid_address_ippref_len (&adj->leid);
+         if (gid_address_ip_version (&adj->reid) == IP4)
+           {
+             a.eid_type = 0;   /* ipv4 type */
+             clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 4);
+             clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 4);
+           }
+         else
+           {
+             a.eid_type = 1;   /* ipv6 type */
+             clib_memcpy (a.reid, &gid_address_ip (&adj->reid), 16);
+             clib_memcpy (a.leid, &gid_address_ip (&adj->leid), 16);
+           }
+         break;
+       case GID_ADDR_MAC:
+         a.eid_type = 2;       /* l2 mac type */
+         mac_copy (a.reid, gid_address_mac (&adj->reid));
+         mac_copy (a.leid, gid_address_mac (&adj->leid));
+         break;
+       default:
+         ASSERT (0);
+       }
+      dst[i] = a;
+    }
+}
+
+static void
+vl_api_lisp_adjacencies_get_t_handler (vl_api_lisp_adjacencies_get_t * mp)
+{
+  vl_api_lisp_adjacencies_get_reply_t *rmp = 0;
+  lisp_adjacency_t *adjs = 0;
+  int rv = 0;
+  vl_api_lisp_adjacency_t a;
+  u32 size = ~0;
+  u32 vni = clib_net_to_host_u32 (mp->vni);
+
+  adjs = vnet_lisp_adjacencies_get_by_vni (vni);
+  size = vec_len (adjs) * sizeof (a);
+
+  /* *INDENT-OFF* */
+  REPLY_MACRO3 (VL_API_LISP_ADJACENCIES_GET_REPLY, size,
+  {
+    rmp->count = clib_host_to_net_u32 (vec_len (adjs));
+    lisp_adjacency_copy (rmp->adjacencies, adjs);
+  });
+  /* *INDENT-ON* */
+
+  vec_free (adjs);
+}
+
 static void
 vl_api_lisp_eid_table_vni_dump_t_handler (vl_api_lisp_eid_table_vni_dump_t *
                                          mp)
index 096c1aa..887c9fc 100644 (file)
@@ -2698,6 +2698,17 @@ static void *vl_api_lisp_eid_table_dump_t_print
   FINISH;
 }
 
+static void *vl_api_lisp_adjacencies_get_t_print
+  (vl_api_lisp_adjacencies_get_t * mp, void *handle)
+{
+  u8 *s;
+
+  s = format (0, "SCRIPT: lisp_adjacencies_get ");
+  s = format (s, "vni %d", clib_net_to_host_u32 (mp->vni));
+
+  FINISH;
+}
+
 static void *vl_api_lisp_eid_table_map_dump_t_print
   (vl_api_lisp_eid_table_map_dump_t * mp, void *handle)
 {
@@ -2989,6 +3000,7 @@ _(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump)                           \
 _(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump)                       \
 _(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump)                         \
 _(LISP_LOCATOR_DUMP, lisp_locator_dump)                                 \
+_(LISP_ADJACENCIES_GET, lisp_adjacencies_get)                           \
 _(IPSEC_GRE_ADD_DEL_TUNNEL, ipsec_gre_add_del_tunnel)                   \
 _(IPSEC_GRE_TUNNEL_DUMP, ipsec_gre_tunnel_dump)                         \
 _(DELETE_SUBIF, delete_subif)                                           \
index a48d345..0fe9d20 100644 (file)
@@ -2946,6 +2946,49 @@ define lisp_eid_table_dump
   u8 filter;
 };
 
+/** \brief LISP adjacency
+    @param eid_type -
+      0 : ipv4
+      1 : ipv6
+      2 : mac
+    @param reid - remote EID
+    @param leid - local EID
+    @param reid_prefix_len - remote EID IP prefix length
+    @param leid_prefix_len - local EID IP prefix length
+  */
+typeonly manual_print manual_endian define lisp_adjacency
+{
+  u8 eid_type;
+  u8 reid[16];
+  u8 leid[16];
+  u8 reid_prefix_len;
+  u8 leid_prefix_len;
+};
+
+/** \brief LISP adjacency reply
+    @param count - number of adjacencies
+    @param adjacencies - array of adjacencies
+  */
+manual_endian manual_print define lisp_adjacencies_get_reply
+{
+  u32 context;
+  i32 retval;
+  u32 count;
+  vl_api_lisp_adjacency_t adjacencies[count];
+};
+
+/** \brief Request for LISP adjacencies
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param vni - filter adjacencies by VNI
+ */
+define lisp_adjacencies_get
+{
+  u32 client_index;
+  u32 context;
+  u32 vni;
+};
+
 /** \brief Shows relationship between vni and vrf/bd
     @param dp_table - VRF index or bridge domain index
     @param vni - vitual network instance
index 901510e..75d6a14 100755 (executable)
@@ -36,6 +36,7 @@ format_struct = {'u8': 'B',
                  'f64' : 'd',
                  'vl_api_ip4_fib_counter_t' : 'IBQQ',
                  'vl_api_ip6_fib_counter_t' : 'QQBQQ',
+                 'vl_api_lisp_adjacency_t' : 'B' * 35
                  };
 #
 # NB: If new types are introduced in vpe.api, these must be updated.
@@ -48,6 +49,7 @@ type_size = {'u8':   1,
              'f64' : 8,
              'vl_api_ip4_fib_counter_t' : 21,
              'vl_api_ip6_fib_counter_t' : 33,
+             'vl_api_lisp_adjacency_t' : 35
 };
 
 def eprint(*args, **kwargs):