summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Kotucek <pkotucek@cisco.com>2016-03-03 13:27:11 +0100
committerGerrit Code Review <gerrit@fd.io>2016-03-07 14:07:22 +0000
commit00bbf276be22fa0458366d4dd3f4daf4e55d13e7 (patch)
tree4c2afba9a866d6200362a26df8a5789471b340a0
parent433688dbdcaa550f7cdb6314742fb46c0c95d5d8 (diff)
Add sw_interface_clear_stats API call
Change-Id: I0731357744ddcb890efaebd81aac5370449a90e3 Signed-off-by: Pavel Kotucek <pkotucek@cisco.com>
-rw-r--r--vpp-api-test/vat/api_format.c44
-rw-r--r--vpp/api/api.c61
-rw-r--r--vpp/api/custom_dump.c15
-rw-r--r--vpp/api/vpe.api20
4 files changed, 134 insertions, 6 deletions
diff --git a/vpp-api-test/vat/api_format.c b/vpp-api-test/vat/api_format.c
index b6f09021d5b..50153fe3202 100644
--- a/vpp-api-test/vat/api_format.c
+++ b/vpp-api-test/vat/api_format.c
@@ -620,7 +620,7 @@ static void vl_api_sw_interface_set_flags_t_handler_json
/* JSON output not supported */
}
-static void vl_api_cli_reply_t_handler
+static void vl_api_cli_reply_t_handler
(vl_api_cli_reply_t * mp)
{
vat_main_t * vam = &vat_main;
@@ -1896,7 +1896,8 @@ _(map_add_del_rule_reply) \
_(want_interface_events_reply) \
_(want_stats_reply) \
_(cop_interface_enable_disable_reply) \
-_(cop_whitelist_enable_disable_reply)
+_(cop_whitelist_enable_disable_reply) \
+_(sw_interface_clear_stats_reply)
#define _(n) \
static void vl_api_##n##_t_handler \
@@ -2049,7 +2050,8 @@ _(WANT_STATS_REPLY, want_stats_reply) \
_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
-_(GET_NODE_GRAPH_REPLY, get_node_graph_reply)
+_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
+_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply)
/* M: construct, but don't yet send a message */
@@ -2670,6 +2672,39 @@ static int api_sw_interface_set_flags (vat_main_t * vam)
W;
}
+static int api_sw_interface_clear_stats (vat_main_t * vam)
+{
+ unformat_input_t * i = vam->input;
+ vl_api_sw_interface_clear_stats_t *mp;
+ f64 timeout;
+ u32 sw_if_index;
+ u8 sw_if_index_set = 0;
+
+ /* Parse args required to build the message */
+ while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
+ if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
+ sw_if_index_set = 1;
+ else if (unformat (i, "sw_if_index %d", &sw_if_index))
+ sw_if_index_set = 1;
+ else
+ break;
+ }
+
+ /* Construct the API message */
+ M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
+
+ if (sw_if_index_set == 1)
+ mp->sw_if_index = ntohl (sw_if_index);
+ else
+ mp->sw_if_index = ~0;
+
+ /* send it... */
+ S;
+
+ /* Wait for a reply, return the good/bad news... */
+ W;
+}
+
static int api_sw_interface_add_del_address (vat_main_t * vam)
{
unformat_input_t * i = vam->input;
@@ -9064,7 +9099,8 @@ _(get_first_msg_id, "client <name>") \
_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
"fib-id <nn> [ip4][ip6][default]") \
-_(get_node_graph, " ")
+_(get_node_graph, " ") \
+_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>")
/* List of command functions, CLI names map directly to functions */
#define foreach_cli_function \
diff --git a/vpp/api/api.c b/vpp/api/api.c
index 2c0b4b3c013..40cfa27bb11 100644
--- a/vpp/api/api.c
+++ b/vpp/api/api.c
@@ -311,7 +311,8 @@ _(MAP_RULE_DUMP, map_rule_dump) \
_(MAP_SUMMARY_STATS, map_summary_stats) \
_(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
_(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
-_(GET_NODE_GRAPH, get_node_graph)
+_(GET_NODE_GRAPH, get_node_graph) \
+_(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats)
#define QUOTE_(x) #x
#define QUOTE(x) QUOTE_(x)
@@ -2351,6 +2352,64 @@ static void vl_api_sw_interface_set_flags_t_handler (
REPLY_MACRO(VL_API_SW_INTERFACE_SET_FLAGS_REPLY);
}
+static void vl_api_sw_interface_clear_stats_t_handler (
+ vl_api_sw_interface_clear_stats_t * mp)
+{
+ vl_api_sw_interface_clear_stats_reply_t *rmp;
+
+ vnet_main_t * vnm = vnet_get_main();
+ vnet_interface_main_t * im = &vnm->interface_main;
+ vlib_simple_counter_main_t * sm;
+ vlib_combined_counter_main_t * cm;
+ static vnet_main_t ** my_vnet_mains;
+ int i, j, n_counters;
+
+ int rv = 0;
+
+ vec_reset_length (my_vnet_mains);
+
+ for (i = 0; i < vec_len (vnet_mains); i++)
+ {
+ if (vnet_mains[i])
+ vec_add1 (my_vnet_mains, vnet_mains[i]);
+ }
+
+ if (vec_len (vnet_mains) == 0)
+ vec_add1 (my_vnet_mains, vnm);
+
+ n_counters = vec_len (im->combined_sw_if_counters);
+
+ for (j = 0; j < n_counters; j++)
+ {
+ for (i = 0; i < vec_len(my_vnet_mains); i++)
+ {
+ im = &my_vnet_mains[i]->interface_main;
+ cm = im->combined_sw_if_counters + j;
+ if (mp->sw_if_index == (u32)~0)
+ vlib_clear_combined_counters (cm);
+ else
+ vlib_zero_combined_counter (cm, ntohl(mp->sw_if_index));
+ }
+ }
+
+ n_counters = vec_len (im->sw_if_counters);
+
+ for (j = 0; j < n_counters; j++)
+ {
+ for (i = 0; i < vec_len(my_vnet_mains); i++)
+ {
+ im = &my_vnet_mains[i]->interface_main;
+ sm = im->sw_if_counters + j;
+ if (mp->sw_if_index == (u32)~0)
+ vlib_clear_simple_counters (sm);
+ else
+ vlib_zero_simple_counter (sm, ntohl(mp->sw_if_index));
+ }
+ }
+
+ REPLY_MACRO(VL_API_SW_INTERFACE_CLEAR_STATS_REPLY);
+}
+
static void send_sw_interface_details (vpe_api_main_t * am,
unix_shared_memory_queue_t *q,
vnet_sw_interface_t * swif,
diff --git a/vpp/api/custom_dump.c b/vpp/api/custom_dump.c
index 6a402ead744..6bdbdc55803 100644
--- a/vpp/api/custom_dump.c
+++ b/vpp/api/custom_dump.c
@@ -1727,6 +1727,18 @@ static void * vl_api_cop_whitelist_enable_disable_t_print
FINISH;
}
+static void *vl_api_sw_interface_clear_stats_t_print
+(vl_api_sw_interface_clear_stats_t * mp, void *handle)
+{
+ u8 * s;
+
+ s = format (0, "SCRIPT: sw_interface_clear_stats ");
+ if (mp->sw_if_index != ~0)
+ s = format (s, "sw_if_index %d ", ntohl(mp->sw_if_index));
+
+ FINISH;
+}
+
#define foreach_custom_print_function \
_(CREATE_LOOPBACK, create_loopback) \
_(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
@@ -1808,7 +1820,8 @@ _(IP_DUMP, ip_dump) \
_(DELETE_LOOPBACK, delete_loopback) \
_(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del) \
_(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable) \
-_(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable)
+_(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable) \
+_(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats)
void vl_msg_api_custom_dump_configure (api_main_t *am)
{
diff --git a/vpp/api/vpe.api b/vpp/api/vpe.api
index 2af4f503e8f..29cd1badcbc 100644
--- a/vpp/api/vpe.api
+++ b/vpp/api/vpe.api
@@ -2842,3 +2842,23 @@ define get_node_graph_reply {
i32 retval;
u64 reply_in_shmem;
};
+
+/** \brief Clear interface statistics
+ @param client_index - opaque cookie to identify the sender
+ @param context - sender context, to match reply w/ request
+ @param sw_if_index - index of the interface to clear statistics
+*/
+define sw_interface_clear_stats {
+ u32 client_index;
+ u32 context;
+ u32 sw_if_index;
+};
+
+/** \brief Reply to sw_interface_clear_stats
+ @param context - sender context which was passed in the request
+ @param retval - return code of the set flags request
+*/
+define sw_interface_clear_stats_reply {
+ u32 context;
+ i32 retval;
+};