Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

producer: mpls label, timediff multiplier, time_flow #284

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions producer/proto/producer_nf.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,9 @@ func ConvertNetFlowDataSet(flowMessage *ProtoProducerMessage, version uint16, ba
return err
}
if len(flowMessage.MplsLabel) < 2 {
flowMessage.MplsLabel = make([]uint32, 2)
tmpLabels := make([]uint32, 2)
copy(tmpLabels, flowMessage.MplsLabel)
flowMessage.MplsLabel = tmpLabels
}
flowMessage.MplsLabel[1] = uint32(mplsLabel >> 4)
case netflow.IPFIX_FIELD_mplsLabelStackSection3:
Expand All @@ -527,7 +529,9 @@ func ConvertNetFlowDataSet(flowMessage *ProtoProducerMessage, version uint16, ba
return err
}
if len(flowMessage.MplsLabel) < 3 {
flowMessage.MplsLabel = make([]uint32, 3)
tmpLabels := make([]uint32, 3)
copy(tmpLabels, flowMessage.MplsLabel)
flowMessage.MplsLabel = tmpLabels
}
flowMessage.MplsLabel[2] = uint32(mplsLabel >> 4)
case netflow.IPFIX_FIELD_mplsTopLabelIPv4Address:
Expand All @@ -544,15 +548,15 @@ func ConvertNetFlowDataSet(flowMessage *ProtoProducerMessage, version uint16, ba
if err := DecodeUNumber(v, &timeFirstSwitched); err != nil {
return err
}
timeDiff := (uptime - timeFirstSwitched)
flowMessage.TimeFlowStartNs = baseTimeNs - uint64(timeDiff)*1000000000
timeDiff := (int64(uptime) - int64(timeFirstSwitched))
flowMessage.TimeFlowStartNs = uint64(int64(baseTime)*1000-timeDiff) * 1000000
case netflow.NFV9_FIELD_LAST_SWITCHED:
var timeLastSwitched uint32
if err := DecodeUNumber(v, &timeLastSwitched); err != nil {
return err
}
timeDiff := (uptime - timeLastSwitched)
flowMessage.TimeFlowEndNs = baseTimeNs - uint64(timeDiff)*1000000000
timeDiff := (int64(uptime) - int64(timeLastSwitched))
flowMessage.TimeFlowEndNs = uint64(int64(baseTime)*1000-timeDiff) * 1000000
}
} else if version == 10 {
switch df.Type {
Expand Down
40 changes: 37 additions & 3 deletions producer/proto/producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,31 @@ func TestProcessMessageNetFlow(t *testing.T) {
Type: netflow.NFV9_FIELD_IPV4_SRC_ADDR,
Value: []byte{10, 0, 0, 1},
},
netflow.DataField{
Type: netflow.NFV9_FIELD_FIRST_SWITCHED,
// 218432176
Value: []byte{0x0d, 0x05, 0x02, 0xb0},
},
netflow.DataField{
Type: netflow.NFV9_FIELD_LAST_SWITCHED,
// 218432192
Value: []byte{0x0d, 0x05, 0x02, 0xc0},
},
netflow.DataField{
Type: netflow.NFV9_FIELD_MPLS_LABEL_1,
// 24041
Value: []byte{0x05, 0xde, 0x94},
},
netflow.DataField{
Type: netflow.NFV9_FIELD_MPLS_LABEL_2,
// 211992
Value: []byte{0x33, 0xc1, 0x85},
},
netflow.DataField{
Type: netflow.NFV9_FIELD_MPLS_LABEL_3,
// 48675
Value: []byte{0x0b, 0xe2, 0x35},
},
},
},
}
Expand All @@ -28,11 +53,20 @@ func TestProcessMessageNetFlow(t *testing.T) {
}

pktnf9 := netflow.NFv9Packet{
FlowSets: dfs,
SystemUptime: 218432000,
UnixSeconds: 1705732882,
FlowSets: dfs,
}
testsr := &SingleSamplingRateSystem{1}
_, err := ProcessMessageNetFlowV9Config(&pktnf9, testsr, nil)
assert.Nil(t, err)
msgs, err := ProcessMessageNetFlowV9Config(&pktnf9, testsr, nil)
if assert.Nil(t, err) && assert.Len(t, msgs, 1) {
msg, ok := msgs[0].(*ProtoProducerMessage)
if assert.True(t, ok) {
assert.Equal(t, msg.TimeFlowStartNs, uint64(1705732882176000000))
assert.Equal(t, msg.TimeFlowEndNs, uint64(1705732882192000000))
assert.Equal(t, msg.MplsLabel, []uint32{24041, 211992, 48675})
}
}

pktipfix := netflow.IPFIXPacket{
FlowSets: dfs,
Expand Down