LISP: Do not show P-ITR generated mapping
[vpp.git] / src / vnet / lisp-cp / one_api.c
index 8fdf082..2892409 100644 (file)
 
 #include <vnet/vnet_msg_enum.h>
 
-#define vl_api_remote_locator_t_endian vl_noop_handler
-#define vl_api_remote_locator_t_print vl_noop_handler
-#define vl_api_local_locator_t_endian vl_noop_handler
-#define vl_api_local_locator_t_print vl_noop_handler
+#define vl_api_one_remote_locator_t_endian vl_noop_handler
+#define vl_api_one_remote_locator_t_print vl_noop_handler
+#define vl_api_one_local_locator_t_endian vl_noop_handler
+#define vl_api_one_local_locator_t_print vl_noop_handler
 
 #define vl_api_one_add_del_locator_set_t_endian vl_noop_handler
 #define vl_api_one_add_del_locator_set_t_print vl_noop_handler
 
 #include <vlibapi/api_helper_macros.h>
 
+#define REPLY_DETAILS(t, body)                                  \
+do {                                                            \
+    unix_shared_memory_queue_t * q;                             \
+    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));                     \
+    rmp->_vl_msg_id = ntohs((t));                               \
+    rmp->context = mp->context;                                 \
+    do {body;} while (0);                                       \
+    vl_msg_api_send_shmem (q, (u8 *)&rmp);                      \
+} while(0);
+
 #define foreach_vpe_api_msg                             \
 _(ONE_ADD_DEL_LOCATOR_SET, one_add_del_locator_set)                     \
 _(ONE_ADD_DEL_LOCATOR, one_add_del_locator)                             \
@@ -90,13 +105,17 @@ _(SHOW_ONE_PITR, show_one_pitr)                                         \
 _(SHOW_ONE_MAP_REQUEST_MODE, show_one_map_request_mode)                 \
 _(ONE_USE_PETR, one_use_petr)                                           \
 _(SHOW_ONE_USE_PETR, show_one_use_petr)                                 \
+_(SHOW_ONE_STATS_ENABLE_DISABLE, show_one_stats_enable_disable)         \
+_(ONE_STATS_ENABLE_DISABLE, one_stats_enable_disable)                   \
+_(ONE_STATS_DUMP, one_stats_dump)                                       \
+
 
 static locator_t *
-unformat_one_locs (vl_api_remote_locator_t * rmt_locs, u32 rloc_num)
+unformat_one_locs (vl_api_one_remote_locator_t * rmt_locs, u32 rloc_num)
 {
   u32 i;
   locator_t *locs = 0, loc;
-  vl_api_remote_locator_t *r;
+  vl_api_one_remote_locator_t *r;
 
   for (i = 0; i < rloc_num; i++)
     {
@@ -121,7 +140,7 @@ vl_api_one_add_del_locator_set_t_handler (vl_api_one_add_del_locator_set_t *
   int rv = 0;
   vnet_lisp_add_del_locator_set_args_t _a, *a = &_a;
   locator_t locator;
-  vl_api_local_locator_t *ls_loc;
+  vl_api_one_local_locator_t *ls_loc;
   u32 ls_index = ~0, locator_num;
   u8 *locator_name = NULL;
   int i;
@@ -444,9 +463,24 @@ vl_api_show_one_use_petr_t_handler (vl_api_show_one_use_petr_t * mp)
   /* *INDENT-OFF* */
   REPLY_MACRO2 (VL_API_SHOW_ONE_USE_PETR_REPLY,
   {
-      rmp->status = status;
-      gid_address_put (rmp->address, &addr);
-      rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
+    rmp->status = status;
+    ip_address_t *ip = &gid_address_ip (&addr);
+    switch (ip_addr_version (ip))
+      {
+      case IP4:
+        clib_memcpy (rmp->address, &ip_addr_v4 (ip),
+                     sizeof (ip_addr_v4 (ip)));
+        break;
+
+      case IP6:
+        clib_memcpy (rmp->address, &ip_addr_v6 (ip),
+                     sizeof (ip_addr_v6 (ip)));
+        break;
+
+      default:
+        ASSERT (0);
+      }
+    rmp->is_ip4 = (gid_address_ip_version (&addr) == IP4);
   });
   /* *INDENT-ON* */
 }
@@ -738,6 +772,9 @@ send_one_eid_table_details (mapping_t * mapit,
   u8 *mac = 0;
   ip_prefix_t *ip_prefix = NULL;
 
+  if (mapit->pitr_set)
+    return;
+
   switch (filter)
     {
     case 0:                    /* all mappings */
@@ -1256,6 +1293,89 @@ vl_api_show_one_pitr_t_handler (vl_api_show_one_pitr_t * mp)
   /* *INDENT-ON* */
 }
 
+static void
+  vl_api_show_one_stats_enable_disable_t_handler
+  (vl_api_show_one_stats_enable_disable_t * mp)
+{
+  vl_api_show_one_stats_enable_disable_reply_t *rmp = NULL;
+  vnet_api_error_t rv = 0;
+
+  /* *INDENT-OFF* */
+  REPLY_MACRO2 (VL_API_SHOW_ONE_STATS_ENABLE_DISABLE_REPLY,
+  ({
+    rmp->is_en = vnet_lisp_stats_enable_disable_state ();
+  }));
+  /* *INDENT-ON* */
+}
+
+static void
+  vl_api_one_stats_enable_disable_t_handler
+  (vl_api_one_stats_enable_disable_t * mp)
+{
+  vl_api_one_enable_disable_reply_t *rmp = NULL;
+
+  vnet_api_error_t rv = vnet_lisp_stats_enable_disable (mp->is_en);
+  REPLY_MACRO (VL_API_ONE_ENABLE_DISABLE_REPLY);
+}
+
+static void
+lisp_fid_addr_to_api (fid_address_t * fid, u8 * dst, u8 * api_eid_type,
+                     u8 * prefix_length)
+{
+  switch (fid_addr_type (fid))
+    {
+    case FID_ADDR_IP_PREF:
+      *prefix_length = fid_addr_prefix_length (fid);
+      if (fid_addr_ip_version (fid) == IP4)
+       {
+         *api_eid_type = 0;    /* ipv4 type */
+         clib_memcpy (dst, &fid_addr_ippref (fid), 4);
+       }
+      else
+       {
+         *api_eid_type = 1;    /* ipv6 type */
+         clib_memcpy (dst, &fid_addr_ippref (fid), 16);
+       }
+      break;
+    case FID_ADDR_MAC:
+      *api_eid_type = 2;       /* l2 mac type */
+      mac_copy (dst, fid_addr_mac (fid));
+      break;
+    default:
+      ASSERT (0);
+    }
+}
+
+static void
+vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
+{
+  vl_api_one_stats_details_t *rmp;
+  lisp_api_stats_t *stats, *stat;
+  u8 rv = 0;
+
+  stats = vnet_lisp_get_stats ();
+  vec_foreach (stat, stats)
+  {
+      /* *INDENT-OFF* */
+      REPLY_DETAILS (VL_API_ONE_STATS_DETAILS,
+      ({
+        lisp_fid_addr_to_api (&stat->deid, rmp->deid, &rmp->eid_type,
+                              &rmp->deid_pref_len);
+        lisp_fid_addr_to_api (&stat->seid, rmp->seid, &rmp->eid_type,
+                              &rmp->seid_pref_len);
+        rmp->vni = clib_host_to_net_u32 (stat->vni);
+
+        rmp->is_ip4 = ip_addr_version (&stat->rmt_rloc) == IP4 ? 1 : 0;
+        ip_address_copy_addr (rmp->rloc, &stat->rmt_rloc);
+        ip_address_copy_addr (rmp->lloc, &stat->loc_rloc);
+
+        rmp->pkt_count = clib_host_to_net_u32 (stat->stats.pkt_count);
+        rmp->bytes = clib_host_to_net_u32 (stat->stats.bytes);
+      }));
+      /* *INDENT-ON* */
+  }
+}
+
 /*
  * one_api_hookup
  * Add vpe's API message handlers to the table.
@@ -1271,7 +1391,7 @@ static void
 setup_message_id_table (api_main_t * am)
 {
 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
-  foreach_vl_msg_name_crc_lisp;
+  foreach_vl_msg_name_crc_one;
 #undef _
 }