static uint64_t get_usec(TWAMPTimestamp ts) { struct timeval tv; timestamp_to_timeval(&ts, &tv); return tv.tv_sec * 1000000 + tv.tv_usec; }
int seconds_to_midnight(tstamp_t ts) { struct timeval tv; struct tm tmv; int save_daylight; long save_timezone; timestamp_to_timeval(ts, &tv); save_daylight = daylight; daylight = 0; save_timezone = timezone; timezone = 0; (void) gmtime_r(&tv.tv_sec, &tmv); daylight = save_daylight; timezone = save_timezone; return (60*(60*(23-tmv.tm_hour) + (59-tmv.tm_min)) + (59-tmv.tm_sec) + 2); }
void print_metrics(int j, int port, ReflectorUPacket pack) { struct timeval recv_resp_time, send_time, recv_time, reflect_time; /* Get Time of the received TWAMP-Test response message */ gettimeofday(&recv_resp_time, NULL); /* Get the timestamps from the reflected message */ timestamp_to_timeval(&pack.sender_time, &send_time); timestamp_to_timeval(&pack.receive_time, &recv_time); timestamp_to_timeval(&pack.time, &reflect_time); /* Print different metrics */ /* Compute round-trip */ fprintf(stderr, "Round-trip time for TWAMP-Test packet %d for port %hd is %" PRIu64 " [usec]\n", j, port, get_time_difference(&recv_resp_time, &send_time)); fprintf(stderr, "Receive time - Send time for TWAMP-Test" " packet %d for port %d is %" PRIu64 " [usec]\n", j, port, get_time_difference(&recv_time, &send_time)); fprintf(stderr, "Reflect time - Send time for TWAMP-Test" " packet %d for port %d is %" PRIu64 " [usec]\n", j, port, get_time_difference(&reflect_time, &send_time)); }
/* * Similar to the timestamp_to_datestring() function above. * * Returns a string representation of the current date/time, * suitable for DB filenames: YYYYMMDDHHMMSS. * * As an example, for a database Foo the filename is: * * FooYYYYMMDDHHMMSS.db */ char *timestamp_to_filestring(tstamp_t ts) { char buf[64]; struct timeval tv; struct tm tmv; int save_daylight; long save_timezone; timestamp_to_timeval(ts, &tv); save_daylight = daylight; daylight = 0; save_timezone = timezone; timezone = 0; (void) gmtime_r(&tv.tv_sec, &tmv); daylight = save_daylight; timezone = save_timezone; sprintf(buf, "%4d%02d%02d%02d%02d%02d", tmv.tm_year+1900, tmv.tm_mon+1, tmv.tm_mday, tmv.tm_hour, tmv.tm_min, tmv.tm_sec); return str_dupl(buf); }