Add sw_interface_clear_stats API call
[vpp.git] / vpp / api / api.c
index e14eef6..40cfa27 100644 (file)
 #undef __included_bihash_template_h__
 #include <vnet/l2/l2_fib.h>
 
-#if DPDK > 0
 #if IPSEC > 0
 #include <vnet/ipsec/ipsec.h>
 #endif /* IPSEC */
+#if DPDK > 0
 #include <vnet/devices/virtio/vhost-user.h>
 #endif
 
@@ -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,
@@ -2374,6 +2433,7 @@ static void send_sw_interface_details (vpe_api_main_t * am,
                       VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT);
     mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >>
                      VNET_HW_INTERFACE_FLAG_SPEED_SHIFT);
+    mp->link_mtu = ntohs(hi->max_packet_bytes);
 
     strncpy ((char *) mp->interface_name, 
              (char *) interface_name, ARRAY_LEN(mp->interface_name)-1);
@@ -3551,7 +3611,8 @@ vl_api_create_vhost_user_if_t_handler (vl_api_create_vhost_user_if_t *mp)
 
     rv = dpdk_vhost_user_create_if(vnm, vm, (char *)mp->sock_filename,
                               mp->is_server, &sw_if_index, (u64)~0,
-                              mp->renumber, ntohl(mp->custom_dev_instance));
+                              mp->renumber, ntohl(mp->custom_dev_instance),
+                              (mp->use_custom_mac)?mp->mac_address:NULL);
 
     REPLY_MACRO2(VL_API_CREATE_VHOST_USER_IF_REPLY,
     ({