Skip to content

Commit c4213f2

Browse files
committed
add extended_timestamp
1 parent 45fe927 commit c4213f2

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Process this file with autoconf to produce a configure script.
33

44
AC_PREREQ([2.71])
5-
AC_INIT([sflowtool],[6.08])
5+
# change version in spec file too
6+
AC_INIT([sflowtool],[6.09])
67
AC_CONFIG_SRCDIR([src/sflowtool.c])
78
AM_INIT_AUTOMAKE
89
AC_PROG_CC

sflowtool.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Summary: tool to ascii-print or forward sFlow datagrams
22
Name: sflowtool
3-
Version: 6.07
3+
Version: 6.09
44
Release: 1%{?dist}
55
License: https://www.inmon.com/technology/sflowlicense.txt
66
Group: Productivity/Networking/Diagnostic

src/sflow.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,16 @@ typedef struct _SFLExtended_linux_reason {
661661
} SFLExtended_linux_reason;
662662
#define SFL_MAX_LINUX_REASON_LEN 64
663663

664+
/* Precision Timestamp */
665+
/* opaque = flow_data; enterprise = 0; format = 1043 */
666+
/* Time in relative to the UNIX epoch starting in 1970 using the
667+
Coordinated Universal Time (UTC). Agent should report most accurate
668+
synchronized time available, e.g. Atomic, PTP, NTP, etc. */
669+
670+
typedef struct {
671+
uint64_t nanoseconds;
672+
} SFLExtended_timestamp;
673+
664674
enum SFLFlow_type_tag {
665675
/* enterprise = 0, format = ... */
666676
SFLFLOW_HEADER = 1, /* Packet headers are sampled */
@@ -700,6 +710,7 @@ enum SFLFlow_type_tag {
700710
SFLFLOW_EX_Q_DEPTH = 1040,
701711
SFLFLOW_EX_HW_TRAP = 1041,
702712
SFLFLOW_EX_LINUX_REASON = 1042,
713+
SFLFLOW_EX_TIMESTAMP = 1043,
703714
SFLFLOW_EX_SOCKET4 = 2100,
704715
SFLFLOW_EX_SOCKET6 = 2101,
705716
SFLFLOW_EX_PROXYSOCKET4 = 2102,
@@ -752,6 +763,7 @@ typedef union _SFLFlow_type {
752763
SFLExtended_egress_queue egress_queue;
753764
SFLExtended_queue_depth queue_depth;
754765
SFLExtended_transit_delay transit_delay;
766+
SFLExtended_timestamp timestamp;
755767
} SFLFlow_type;
756768

757769
typedef struct _SFLFlow_sample_element {

src/sflowtool.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ typedef struct _SFSample {
422422
/* counter blocks */
423423
uint32_t statsSamplingInterval;
424424
uint32_t counterBlockVersion;
425+
426+
/* timetamp */
427+
uint64_t timestamp_nS;
425428
} s;
426429

427430
/* exception handler context */
@@ -1103,6 +1106,17 @@ static char *printTimestamp(time_t ts, SFStr *sb) {
11031106
return SFStr_str(sb);
11041107
}
11051108

1109+
static char *printTimestamp_nS(uint64_t nS, SFStr *sb) {
1110+
SFStr_init(sb);
1111+
uint64_t gig = (uint64_t)1e9;
1112+
time_t ts = nS / gig;
1113+
uint64_t fract = nS % gig;
1114+
SFStr_append_timestamp(sb, ts);
1115+
SFStr_append(sb, ".");
1116+
SFStr_append_U64(sb, "%"PRIu64, fract);
1117+
return SFStr_str(sb);
1118+
}
1119+
11061120
static char *printOUI(uint8_t *oui, SFStr *sb) {
11071121
SFStr_init(sb);
11081122
SFStr_append_hex(sb, oui, 3, NO, YES, '-');
@@ -3896,6 +3910,20 @@ static void readExtendedLinuxReason(SFSample *sample)
38963910
}
38973911
}
38983912

3913+
/*_________________----------------------------__________________
3914+
_________________ readExtendedTimestamp __________________
3915+
-----------------____________________________------------------
3916+
*/
3917+
3918+
static void readExtendedTimestamp(SFSample *sample)
3919+
{
3920+
SFStr buf;
3921+
sf_logf(sample, "extendedType", "timestamp");
3922+
sample->s.timestamp_nS = getData64(sample);
3923+
sf_logf_U64(sample, "timestamp_nS", sample->s.timestamp_nS);
3924+
// sf_logf(sample, "timestamp_fmt", printTimestamp_nS(sample->s.timestamp_nS, &buf));
3925+
}
3926+
38993927
/*_________________---------------------------__________________
39003928
_________________ readFlowSample_v2v4 __________________
39013929
-----------------___________________________------------------
@@ -4091,6 +4119,7 @@ static void readFlowSampleElements(SFSample *sample)
40914119
case SFLFLOW_EX_EGRESS_Q: readExtendedEgressQueue(sample); break;
40924120
case SFLFLOW_EX_TRANSIT: readExtendedTransitDelay(sample); break;
40934121
case SFLFLOW_EX_Q_DEPTH: readExtendedQueueDepth(sample); break;
4122+
case SFLFLOW_EX_TIMESTAMP: readExtendedTimestamp(sample); break;
40944123
/* In discard samples, any of the above may appear along with the following. */
40954124
case SFLFLOW_EX_FUNCTION: readExtendedFunction(sample); break;
40964125
case SFLFLOW_EX_HW_TRAP: readExtendedHardwareTrap(sample); break;

0 commit comments

Comments
 (0)