misc: ipfix process node wait time adjustment 61/32161/4
authorMatthew Smith <mgsmith@netgate.com>
Wed, 28 Apr 2021 16:48:39 +0000 (11:48 -0500)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Wed, 5 May 2021 10:36:13 +0000 (10:36 +0000)
Type: fix

The ipfix process node has a hardcoded 5s sleep between sending packets.
The interval between template packets is configurable, but the timing
of packets being sent does not match configuration because of the time
being hardcoded. E.g. -

With template interval set to 3s, a packet will be sent every 5s.
With template interval set to 8s, a packet will be sent every 10s.

Honor the configuration by reducing the wait time to less than 5s if a
template will need to be sent less than 5s from the current time.

Change-Id: I8c11f7bc502ce5b20b6e82a7e7a135a8805a2bad
Signed-off-by: Matthew Smith <mgsmith@netgate.com>
src/vnet/ipfix-export/flow_report.c
src/vnet/ipfix-export/ipfix_export.api

index 5d25bb5..760de5f 100644 (file)
@@ -260,7 +260,8 @@ flow_report_process (vlib_main_t * vm,
   u32 template_bi;
   u32 *to_next;
   int send_template;
-  f64 now;
+  f64 now, wait_time;
+  f64 def_wait_time = 5.0;
   int rv;
   uword event_type;
   uword *event_data = 0;
@@ -276,14 +277,20 @@ flow_report_process (vlib_main_t * vm,
   ip4_lookup_node = vlib_get_node_by_name (vm, (u8 *) "ip4-lookup");
   ip4_lookup_node_index = ip4_lookup_node->index;
 
+  wait_time = def_wait_time;
+
   while (1)
     {
-      vlib_process_wait_for_event_or_clock (vm, 5.0);
+      vlib_process_wait_for_event_or_clock (vm, wait_time);
       event_type = vlib_process_get_events (vm, &event_data);
       vec_reset_length (event_data);
 
+      /* 5s delay by default, possibly reduced by template intervals */
+      wait_time = def_wait_time;
+
       vec_foreach (fr, frm->reports)
       {
+       f64 next_template;
        now = vlib_time_now (vm);
 
        /* Need to send a template packet? */
@@ -299,6 +306,11 @@ flow_report_process (vlib_main_t * vm,
        if (rv < 0)
          continue;
 
+       /* decide if template should be sent sooner than current wait time */
+       next_template =
+         (fr->last_template_sent + frm->template_interval) - now;
+       wait_time = clib_min (wait_time, next_template);
+
        nf = vlib_get_frame_to_node (vm, ip4_lookup_node_index);
        nf->n_vectors = 0;
        to_next = vlib_frame_vector_args (nf);
index 147d790..a70b72b 100644 (file)
@@ -13,7 +13,7 @@
  * limitations under the License.
  */
 
-option version = "2.0.2";
+option version = "2.0.3";
 
 import "vnet/ip/ip_types.api";