Skip to content

Commit c600dcb

Browse files
committed
include extended_timestamp (nS wallclock UTC) in the export when it is supplied with PSAMPLE and DROPMON
1 parent 6949d81 commit c600dcb

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

hsflowd.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Summary: host sFlow daemon
22
Name: hsflowd
3-
Version: 2.1.17
3+
Version: 2.1.18
44
Release: 1
55
License: http://sflow.net/license.html
66
Group: Applications/Internet

src/Linux/hsflowd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ extern "C" {
482482
uint32_t egressQ_id;
483483
uint64_t egressQ_byts;
484484
uint64_t transit_nS;
485+
uint64_t timestamp_nS;
485486
uint32_t hdr_len;
486487
u_char *hdr;
487488
} HSPPSample;

src/Linux/mod_dropmon.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ That would allow everything to stay on the stack as it does here, which has nice
728728
SFLFlow_sample_element fnElem = { .tag=SFLFLOW_EX_FUNCTION };
729729
SFLFlow_sample_element hwElem = { .tag=SFLFLOW_EX_HW_TRAP };
730730
SFLFlow_sample_element rnElem = { .tag=SFLFLOW_EX_LINUX_REASON };
731+
SFLFlow_sample_element tsElem = { .tag=SFLFLOW_EX_TIMESTAMP };
731732

732733
// and some parameters to pick up for cross-check below
733734
uint32_t trunc_len=0;
@@ -737,6 +738,7 @@ That would allow everything to stay on the stack as it does here, which has nice
737738
char *hw_name=NULL;
738739
char *sw_symbol=NULL;
739740
char *reason=NULL;
741+
uint64_t timestamp_nS=0;
740742

741743
// increment counter for threshold check
742744
mdata->totalDrops_thisTick++;
@@ -793,7 +795,8 @@ That would allow everything to stay on the stack as it does here, which has nice
793795
}
794796
break;
795797
case NET_DM_ATTR_TIMESTAMP:
796-
EVDebug(mod, 4, "u64=TIMESTAMP=%"PRIu64, *(uint64_t *)datap);
798+
timestamp_nS = *(uint64_t *)datap;
799+
EVDebug(mod, 4, "u64=TIMESTAMP=%"PRIu64, timestamp_nS);
797800
break;
798801
case NET_DM_ATTR_PROTO:
799802
skb_protocol = *(uint16_t *)datap;
@@ -957,7 +960,10 @@ That would allow everything to stay on the stack as it does here, which has nice
957960
rnElem.flowType.linux_reason.reason.len = my_strlen(reason);
958961
SFLADD_ELEMENT(&discard, &rnElem);
959962
}
960-
963+
if(timestamp_nS) {
964+
tsElem.flowType.timestamp.nanoseconds = timestamp_nS;
965+
SFLADD_ELEMENT(&discard, &tsElem);
966+
}
961967
HSPPendingEvtSample es = { .notifier = notifier, .discard = &discard };
962968
if(mdata->evt_intf_es)
963969
EVEventTx(mod, mdata->evt_intf_es, &es, sizeof(es));

src/Linux/mod_psample.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,16 @@ extern "C" {
302302
ADD_TO_LIST(ext_elems, transit);
303303
}
304304
break;
305+
case HSP_PSAMPLE_ATTR_TIMESTAMP:
306+
{
307+
// wall clock timestamp - unixtime UTC (nS)
308+
SFLFlow_sample_element *tstamp = my_calloc(sizeof(SFLFlow_sample_element));
309+
tstamp->tag = SFLFLOW_EX_TIMESTAMP;
310+
psmp.timestamp_nS = *(uint64_t *)datap;
311+
tstamp->flowType.timestamp.nanoseconds = psmp.timestamp_nS;
312+
ADD_TO_LIST(ext_elems, tstamp);
313+
}
314+
break;
305315
}
306316
}
307317

src/sflow/sflow.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,16 @@ typedef struct {
509509
} SFLExtended_queue_depth;
510510
#define XDRSIZ_SFLEXTENDED_Q_DEPTH 4
511511

512+
/* Precision Timestamp */
513+
/* opaque = flow_data; enterprise = 0; format = 1043 */
514+
/* Time in relative to the UNIX epoch starting in 1970 using the
515+
Coordinated Universal Time (UTC). Agent should report most accurate
516+
synchronized time available, e.g. Atomic, PTP, NTP, etc. */
517+
518+
typedef struct {
519+
uint64_t nanoseconds;
520+
} SFLExtended_timestamp;
521+
512522
enum SFLFlow_type_tag {
513523
/* enterprise = 0, format = ... */
514524
SFLFLOW_HEADER = 1, /* Packet headers are sampled */
@@ -543,6 +553,7 @@ enum SFLFlow_type_tag {
543553
SFLFLOW_EX_Q_DEPTH = 1040,
544554
SFLFLOW_EX_HW_TRAP = 1041,
545555
SFLFLOW_EX_LINUX_REASON = 1042,
556+
SFLFLOW_EX_TIMESTAMP = 1043,
546557
SFLFLOW_EX_SOCKET4 = 2100, /* server socket */
547558
SFLFLOW_EX_SOCKET6 = 2101, /* server socket */
548559
SFLFLOW_EX_PROXY_SOCKET4 = 2102, /* back-end (client) socket */
@@ -590,6 +601,7 @@ typedef union _SFLFlow_type {
590601
SFLExtended_transit_delay transit_delay;
591602
SFLExtended_hw_trap hw_trap;
592603
SFLExtended_linux_reason linux_reason;
604+
SFLExtended_timestamp timestamp;
593605
} SFLFlow_type;
594606

595607
typedef struct _SFLFlow_sample_element {

src/sflow/sflow_receiver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ static int xdr_enc_flow_sample_elements(SFDBuf *pktsmp, SFLFlow_sample_element *
375375
case SFLFLOW_EX_Q_DEPTH: sfd_xdr_enc_int32(pktsmp, elem->flowType.queue_depth.depth); break;
376376
case SFLFLOW_EX_HW_TRAP: xdr_enc_hw_trap(pktsmp, &elem->flowType.hw_trap); break;
377377
case SFLFLOW_EX_LINUX_REASON: xdr_enc_sflstring(pktsmp, &elem->flowType.linux_reason.reason); break;
378+
case SFLFLOW_EX_TIMESTAMP: sfd_xdr_enc_int64(pktsmp, elem->flowType.timestamp.nanoseconds); break;
378379
default:
379380
return -1;
380381
}

0 commit comments

Comments
 (0)