Add sw_interface_clear_stats API call
[vpp.git] / vpp / api / api.c
index 1390291..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
 
@@ -310,7 +310,9 @@ _(MAP_DOMAIN_DUMP, map_domain_dump)                                     \
 _(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)
+_(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable)          \
+_(GET_NODE_GRAPH, get_node_graph)                                       \
+_(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats)
 
 #define QUOTE_(x) #x
 #define QUOTE(x) QUOTE_(x)
@@ -2350,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,
@@ -2373,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);
@@ -3550,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,
     ({
@@ -4905,6 +4967,35 @@ static void vl_api_cop_whitelist_enable_disable_t_handler
     REPLY_MACRO(VL_API_COP_WHITELIST_ENABLE_DISABLE_REPLY);
 }
 
+static void vl_api_get_node_graph_t_handler
+(vl_api_get_node_graph_t * mp)
+{
+    int rv = 0;
+    u8 * vector = 0;
+    api_main_t * am = &api_main;
+    vlib_main_t * vm = vlib_get_main();
+    void * oldheap;
+    vl_api_get_node_graph_reply_t * rmp;
+    
+    pthread_mutex_lock (&am->vlib_rp->mutex);
+    oldheap = svm_push_data_heap (am->vlib_rp);
+    
+    /* 
+     * Keep the number of memcpy ops to a minimum (e.g. 1).
+     * The current size of the serialized vector is
+     * slightly under 4K.
+     */
+    vec_validate (vector, 4095);
+    vec_reset_length (vector);
+
+    vector = vlib_node_serialize (&vm->node_main, vector);
+    
+    svm_pop_heap (oldheap);
+    pthread_mutex_unlock (&am->vlib_rp->mutex);
+
+    REPLY_MACRO2(VL_API_GET_NODE_GRAPH_REPLY,
+                 rmp->reply_in_shmem = (uword) vector);
+}
 
 #define BOUNCE_HANDLER(nn)                                              \
 static void vl_api_##nn##_t_handler (                                   \