Add client-side msg_name_and_crc -> msg_index table
[vpp.git] / plugins / flowperpkt-plugin / flowperpkt / flowperpkt.c
index 824fc50..529b919 100644 (file)
@@ -59,10 +59,10 @@ flowperpkt_main_t flowperpkt_main;
 
 /* Define the per-interface configurable feature */
 /* *INDENT-OFF* */
-VNET_IP4_TX_FEATURE_INIT (flow_perpacket, static) = {
+VNET_FEATURE_INIT (flow_perpacket, static) = {
+  .arc_name = "ip4-output",
   .node_name = "flowperpkt",
-  .runs_before = (char *[]){"interface-output", 0},
-  .feature_index = &flowperpkt_main.ip4_tx_feature_index,
+  .runs_before = VNET_FEATURES ("interface-output"),
 };
 /* *INDENT-ON* */
 
@@ -249,11 +249,6 @@ flowperpkt_data_callback (flow_report_main_t * frm,
 static int flowperpkt_tx_interface_add_del_feature
   (flowperpkt_main_t * fm, u32 sw_if_index, int is_add)
 {
-  u32 ci;
-  ip4_main_t *im = &ip4_main;
-  ip_lookup_main_t *lm = &im->lookup_main;
-  vnet_feature_config_main_t *cm = &lm->feature_config_mains[VNET_IP_TX_FEAT];
-  u32 feature_index;
   flow_report_main_t *frm = &flow_report_main;
   vnet_flow_report_add_del_args_t _a, *a = &_a;
   int rv;
@@ -276,18 +271,9 @@ static int flowperpkt_tx_interface_add_del_feature
        }
     }
 
-  feature_index = fm->ip4_tx_feature_index;
+  vnet_feature_enable_disable ("ip4-output", "flowperpkt", sw_if_index,
+                              is_add, 0, 0);
 
-  ci = cm->config_index_by_sw_if_index[sw_if_index];
-  ci = (is_add
-       ? vnet_config_add_feature
-       : vnet_config_del_feature)
-    (fm->vlib_main, &cm->config_main,
-     ci, feature_index, 0 /* config struct */ ,
-     0 /* sizeof config struct */ );
-  cm->config_index_by_sw_if_index[sw_if_index] = ci;
-
-  vnet_config_update_tx_feature_count (lm, cm, sw_if_index, is_add);
   return 0;
 }
 
@@ -452,6 +438,19 @@ flowperpkt_plugin_api_hookup (vlib_main_t * vm)
   return 0;
 }
 
+#define vl_msg_name_crc_list
+#include <flowperpkt/flowperpkt_all_api_h.h>
+#undef vl_msg_name_crc_list
+
+static void
+setup_message_id_table (flowperpkt_main_t * fm, api_main_t * am)
+{
+#define _(id,n,crc) \
+  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + fm->msg_id_base);
+  foreach_vl_msg_name_crc_flowperpkt;
+#undef _
+}
+
 /**
  * @brief Set up the API message handling tables
  * @param vm vlib_main_t * vlib main data structure pointer
@@ -476,6 +475,9 @@ flowperpkt_init (vlib_main_t * vm)
   /* Hook up message handlers */
   error = flowperpkt_plugin_api_hookup (vm);
 
+  /* Add our API messages to the global name_crc hash table */
+  setup_message_id_table (fm, &api_main);
+
   vec_free (name);
 
   /* Decide how many worker threads we have */
@@ -486,6 +488,10 @@ flowperpkt_init (vlib_main_t * vm)
   vec_validate (fm->frames_per_worker, num_threads - 1);
   vec_validate (fm->next_record_offset_per_worker, num_threads - 1);
 
+  /* Set up time reference pair */
+  fm->vlib_time_0 = vlib_time_now (vm);
+  fm->nanosecond_time_0 = unix_time_now_nsec ();
+
   return error;
 }