LISP: add stats API/CLI 63/5663/2
authorFilip Tehlar <ftehlar@cisco.com>
Wed, 8 Mar 2017 07:46:51 +0000 (08:46 +0100)
committerFlorin Coras <florin.coras@gmail.com>
Wed, 8 Mar 2017 08:54:39 +0000 (08:54 +0000)
Change-Id: I5c5b4d680359cf3635c2d7b0088ea2ba6a428f93
Signed-off-by: Filip Tehlar <ftehlar@cisco.com>
src/vnet/lisp-cp/control.c
src/vnet/lisp-cp/control.h
src/vnet/lisp-cp/one.api
src/vnet/lisp-cp/one_api.c
src/vnet/lisp-cp/one_cli.c

index ac11d89..c7853ca 100644 (file)
@@ -3801,6 +3801,29 @@ send_map_resolver_service (vlib_main_t * vm,
   return 0;
 }
 
+vnet_api_error_t
+vnet_lisp_stats_enable_disable (u8 enable)
+{
+  lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+
+  if (vnet_lisp_enable_disable_status () == 0)
+    return VNET_API_ERROR_LISP_DISABLED;
+
+  lcm->stats_enabled = enable;
+  return 0;
+}
+
+u8
+vnet_lisp_stats_enable_disable_state (void)
+{
+  lisp_cp_main_t *lcm = vnet_lisp_cp_get_main ();
+
+  if (vnet_lisp_enable_disable_status () == 0)
+    return VNET_API_ERROR_LISP_DISABLED;
+
+  return lcm->stats_enabled;
+}
+
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (lisp_retry_service_node,static) = {
     .function = send_map_resolver_service,
index 14f3bae..933b34b 100644 (file)
@@ -210,6 +210,9 @@ typedef struct
   /* timing wheel for mappping timeouts */
   timing_wheel_t wheel;
 
+  /* statistics */
+  u8 stats_enabled;
+
   /* commodity */
   ip4_main_t *im4;
   ip6_main_t *im6;
@@ -332,6 +335,9 @@ lisp_get_petr_mapping (lisp_cp_main_t * lcm)
   return pool_elt_at_index (lcm->mapping_pool, lcm->petr_map_index);
 }
 
+u8 vnet_lisp_stats_enable_disable_state (void);
+vnet_api_error_t vnet_lisp_stats_enable_disable (u8 enable);
+
 #endif /* VNET_CONTROL_H_ */
 
 /*
index 14f6d47..436c808 100644 (file)
@@ -877,3 +877,58 @@ define show_one_pitr_reply
   u8 status;
   u8 locator_set_name[64];
 };
+
+define one_stats_dump
+{
+  u32 client_index;
+  u32 context;
+};
+
+define one_stats_details
+{
+  u32 context;
+  u32 vni;
+  u8 eid_type;
+  u8 deid[16];
+  u8 seid[16];
+  u8 deid_pref_len;
+  u8 seid_pref_len;
+  u8 is_ip4;
+  u8 rloc[16];
+  u8 lloc[16];
+
+  u32 pkt_count;
+  u32 bytes;
+};
+
+define one_stats_enable_disable
+{
+  u32 client_index;
+  u32 context;
+  u8 is_en;
+};
+
+define one_stats_enable_disable_reply
+{
+  u32 context;
+  i32 retval;
+};
+
+define show_one_stats_enable_disable
+{
+  u32 client_index;
+  u32 context;
+};
+
+define show_one_stats_enable_disable_reply
+{
+  u32 context;
+  i32 retval;
+  u8 is_en;
+};
+
+/*
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
index d0a9309..ff00bf5 100644 (file)
@@ -90,6 +90,10 @@ _(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_one_remote_locator_t * rmt_locs, u32 rloc_num)
@@ -1256,6 +1260,37 @@ 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
+vl_api_one_stats_dump_t_handler (vl_api_one_stats_dump_t * mp)
+{
+
+}
+
 /*
  * one_api_hookup
  * Add vpe's API message handlers to the table.
index 0582130..2ceeaf4 100644 (file)
@@ -1642,6 +1642,62 @@ VLIB_CLI_COMMAND (one_show_rloc_probe_state_command) = {
 };
 /* *INDENT-ON* */
 
+static clib_error_t *
+lisp_show_stats_command_fn (vlib_main_t * vm,
+                           unformat_input_t * input,
+                           vlib_cli_command_t * cmd)
+{
+  u8 is_enabled = vnet_lisp_stats_enable_disable_state ();
+  vlib_cli_output (vm, "%s\n", is_enabled ? "enabled" : "disabled");
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (one_show_stats_command) = {
+    .path = "show one stats",
+    .short_help = "show ONE statistics",
+    .function = lisp_show_stats_command_fn,
+};
+/* *INDENT-ON* */
+
+static clib_error_t *
+lisp_stats_enable_disable_command_fn (vlib_main_t * vm,
+                                     unformat_input_t * input,
+                                     vlib_cli_command_t * cmd)
+{
+  unformat_input_t _line_input, *line_input = &_line_input;
+  u8 enable = 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, "enable"))
+       enable = 1;
+      else if (unformat (line_input, "disable"))
+       enable = 0;
+      else
+       {
+         clib_warning ("Error: expected enable/disable!");
+         goto done;
+       }
+    }
+  vnet_lisp_stats_enable_disable (enable);
+done:
+  unformat_free (line_input);
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND (one_stats_enable_disable_command) = {
+    .path = "one stats",
+    .short_help = "enable/disable ONE statistics collecting",
+    .function = lisp_stats_enable_disable_command_fn,
+};
+/* *INDENT-ON* */
+
 /*
  * fd.io coding-style-patch-verification: ON
  *