diff mbox

[ovs-dev,1/2] ofproto-dpif-ipfix: Use common OVS functions for getting current time.

Message ID 20170606010451.14125-1-blp@ovn.org
State Accepted
Headers show

Commit Message

Ben Pfaff June 6, 2017, 1:04 a.m. UTC
OVS has common infrastructure functions for getting the current time, but
this code was not using them.  It is not clear why, so this commit changes
it to use them.

Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 ofproto/ofproto-dpif-ipfix.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

Comments

Andy Zhou Aug. 7, 2017, 8:27 p.m. UTC | #1
On Mon, Jun 5, 2017 at 6:04 PM, Ben Pfaff <blp@ovn.org> wrote:
> OVS has common infrastructure functions for getting the current time, but
> this code was not using them.  It is not clear why, so this commit changes
> it to use them.
>
> Signed-off-by: Ben Pfaff <blp@ovn.org>

Acked-by: Andy Zhou <azhou@ovn.org>
Ben Pfaff Aug. 9, 2017, 8:07 p.m. UTC | #2
On Mon, Aug 07, 2017 at 01:27:37PM -0700, Andy Zhou wrote:
> On Mon, Jun 5, 2017 at 6:04 PM, Ben Pfaff <blp@ovn.org> wrote:
> > OVS has common infrastructure functions for getting the current time, but
> > this code was not using them.  It is not clear why, so this commit changes
> > it to use them.
> >
> > Signed-off-by: Ben Pfaff <blp@ovn.org>
> 
> Acked-by: Andy Zhou <azhou@ovn.org>

Thanks, I applied this to master (only).
diff mbox

Patch

diff --git a/ofproto/ofproto-dpif-ipfix.c b/ofproto/ofproto-dpif-ipfix.c
index 23fc51b7b053..5589b0ea05e1 100644
--- a/ofproto/ofproto-dpif-ipfix.c
+++ b/ofproto/ofproto-dpif-ipfix.c
@@ -1602,6 +1602,14 @@  ipfix_update_stats(struct dpif_ipfix_exporter *exporter,
     }
 }
 
+/* Returns the current time in the form used by IPFIX (microseconds since the
+ * epoch). */
+static uint64_t
+ipfix_now(void)
+{
+    return time_wall_msec() * 1000ULL;
+}
+
 /* Add an entry into a flow cache.  The entry is either aggregated into
  * an existing entry with the same flow key and free()d, or it is
  * inserted into the cache. And IPFIX stats will be updated */
@@ -1829,7 +1837,6 @@  ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry,
     flow_key->flow_key_msg_part_size = dp_packet_size(&msg);
 
     {
-        struct timeval now;
         uint64_t layer2_octet_delta_count;
 
         /* Calculate the total matched octet count by considering as
@@ -1837,8 +1844,7 @@  ipfix_cache_entry_init(struct ipfix_flow_cache_entry *entry,
          * length. */
         layer2_octet_delta_count = packet_delta_count * ethernet_total_length;
 
-        xgettimeofday(&now);
-        entry->flow_end_timestamp_usec = now.tv_usec + 1000000LL * now.tv_sec;
+        entry->flow_end_timestamp_usec = ipfix_now();
         entry->flow_start_timestamp_usec = entry->flow_end_timestamp_usec;
         entry->packet_delta_count = packet_delta_count;
         entry->layer2_octet_delta_count = layer2_octet_delta_count;
@@ -2236,19 +2242,12 @@  dpif_ipfix_cache_expire(struct dpif_ipfix_exporter *exporter,
 static void
 get_export_time_now(uint64_t *export_time_usec, uint32_t *export_time_sec)
 {
-    struct timeval export_time;
-    xgettimeofday(&export_time);
-
-    *export_time_usec = export_time.tv_usec + 1000000LL * export_time.tv_sec;
+    *export_time_usec = ipfix_now();
 
     /* The IPFIX start and end deltas are negative deltas relative to
      * the export time, so set the export time 1 second off to
      * calculate those deltas. */
-    if (export_time.tv_usec == 0) {
-        *export_time_sec = export_time.tv_sec;
-    } else {
-        *export_time_sec = export_time.tv_sec + 1;
-    }
+    *export_time_sec = DIV_ROUND_UP(*export_time_usec, 1000000);
 }
 
 static void