The proposed fix won’t work correctly with multiple threads. 

 

Instead, please address the issue in pcap_write(...) by adding an offset 
argument and passing the required offset as f64 seconds since the epoch:

 

   f64 seconds_since_vpp_started = vlib_time_now(vm);

   f64 seconds_since_the_epoch = unix_time_now();

   f64 vpp_start_time = seconds_since_the_epoch – seconds_since_vpp_started;

 

 

In the while-loop which writes out pm->pcap_data, add the supplied offset to 
each packet header timestamp. Simplest to convert the stored (sec,usec) data 
back to f64 seconds, add the supplied constant, then store as (sec,usec).

 

HTH... Dave

 

From: [email protected] <[email protected]> On Behalf Of 
[email protected]
Sent: Thursday, April 15, 2021 9:55 AM
To: [email protected]
Subject: [vpp-dev] Clock time in pcap

 

Hello Team,
       I observe that timestamp captured in pcap collected on VPP with below 
command captures the time since VPP started rather than the clock time.

"pcap trace rx tx max 10000 intfc any file rxt.pcap"

Further looking into code(version 20.05), I observe that time since VPP 
restarted is being set.
Code reference below.

static inline void

pcap_add_buffer (pcap_main_t * pm,

                 struct vlib_main_t *vm, u32 buffer_index,

                 u32 n_bytes_in_trace)

{

  vlib_buffer_t *b = vlib_get_buffer (vm, buffer_index);

  u32 n = vlib_buffer_length_in_chain (vm, b);

  i32 n_left = clib_min (n_bytes_in_trace, n);

  f64 time_now = vlib_time_now (vm);       <<-------------------------------

...
}

After modifying code as below, packets are timestamped with clock time.

src/vppinfra/pcap.h

++#include <vppinfra/time_range.h>

  /** Min/Max Packet bytes */

  u32 min_packet_bytes, max_packet_bytes;

 

  /** Time */

++  clib_timebase_t timebase;

} pcap_main_t;


src/vppinfra/pcap_funcs.h

pcap_add_packet()
{

 ++ vlib_main_t *vm = vlib_get_main();

 

 ++ if(!(pm->timebase.clib_time))

  ++{

  ++    clib_timebase_init (&(pm->timebase), 0 /* GMT */ ,

   ++                   CLIB_TIMEBASE_DAYLIGHT_NONE,

  ++                    &vm->clib_time /* share the system clock */ );

++  }

++  time_now = clib_timebase_now(&(pm->timebase));

 

}

My questions below.
1)Currently in fdio version 20.05 packets captured in pcap are timestamped with 
the time since VPP restarted.
   Is this understanding correct?
2) If answer to above question is "YES", then is the fix correct?

Thanks,
Srini

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#19215): https://lists.fd.io/g/vpp-dev/message/19215
Mute This Topic: https://lists.fd.io/mt/82117060/21656
Group Owner: [email protected]
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to