Skip to content

Commit

Permalink
add test, fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
lspgn committed May 19, 2024
1 parent 60b9f63 commit 6da4615
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion producer/proto/producer_nf.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func ConvertNetFlowDataSet(flowMessage *ProtoProducerMessage, version uint16, ba
default:
if version == 9 {
// NetFlow v9 time works with a differential based on router's uptime
uptimeNs := uint64(uptime * 1e6) // uptime is in milliseconds in NetFlow v9, converts to nanoseconds
uptimeNs := uint64(uptime) * 1e6 // uptime is in milliseconds in NetFlow v9, converts to nanoseconds
switch df.Type {
case netflow.NFV9_FIELD_FIRST_SWITCHED:
var timeFirstSwitched uint32
Expand All @@ -547,6 +547,7 @@ func ConvertNetFlowDataSet(flowMessage *ProtoProducerMessage, version uint16, ba
}
timeDiff := (uptimeNs - uint64(timeFirstSwitched)*1e6)
flowMessage.TimeFlowStartNs = baseTimeNs - timeDiff

case netflow.NFV9_FIELD_LAST_SWITCHED:
var timeLastSwitched uint32
if err := DecodeUNumber(v, &timeLastSwitched); err != nil {
Expand Down
13 changes: 13 additions & 0 deletions producer/proto/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,16 @@ func TestProcessIPv4Fragment(t *testing.T) {
assert.Equal(t, uint32(24025), flowMessage.FragmentId)
assert.Equal(t, uint32(185), flowMessage.FragmentOffset)
}

func TestNetFlowV9Time(t *testing.T) {
var flowMessage ProtoProducerMessage
err := ConvertNetFlowDataSet(&flowMessage, 9, 1704067200, 2000, []netflow.DataField{
netflow.DataField{
Type: netflow.NFV9_FIELD_FIRST_SWITCHED,
Value: []byte{0x0, 0x0, 0x03, 0xe8}, // 1000
},
}, nil, nil)
assert.Nil(t, err)
assert.Equal(t, uint64(1704067199)*1e9, flowMessage.TimeFlowStartNs)

}

0 comments on commit 6da4615

Please sign in to comment.