Skip to content

Commit

Permalink
Add new field to ipfix exporter for flowRtt (#603)
Browse files Browse the repository at this point in the history
* add new field to ipfix exporter for flowRtt

* go fmt

* fix type on timeFlowRttNs field

* rebase

* rebase

* add test case for timeflowrttns

* fix type in ipfix unit test

* increase number of returned fields in ipfix test

* fix type in ipfix unit test

* fix type in ipfix unit test

* fix

* fmt

* year 2024

---------

Co-authored-by: Brandon Hale <[email protected]>
  • Loading branch information
bhale and bhale-ibm authored Feb 26, 2024
1 parent 26a20d2 commit 91917e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkg/pipeline/write/testnorace/write_ipfix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestEnrichedIPFIXFlow(t *testing.T) {
assert.Equal(t, uint16(10), tplv4Msg.GetVersion())
templateSet := tplv4Msg.GetSet()
templateElements := templateSet.GetRecords()[0].GetOrderedElementList()
assert.Len(t, templateElements, 20)
assert.Len(t, templateElements, 21)
assert.Equal(t, uint32(0), templateElements[0].GetInfoElement().EnterpriseId)

// Check data
Expand Down Expand Up @@ -176,6 +176,8 @@ func matchElement(t *testing.T, element entities.InfoElementWithValue, flow conf
assert.Equal(t, flow["SrcK8S_HostName"], element.GetStringValue())
case "destinationNodeName":
assert.Equal(t, flow["DstK8S_HostName"], element.GetStringValue())
case "timeFlowRttNs":
assert.Equal(t, uint64(flow["TimeFlowRttNs"].(int64)), element.GetUnsigned64Value())
case "sourceMacAddress":
case "destinationMacAddress":
// Getting some discrepancies here, need to figure out why
Expand Down
15 changes: 13 additions & 2 deletions pkg/pipeline/write/write_ipfix.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 IBM, Inc.
* Copyright (C) 2024 IBM, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,7 +77,7 @@ var (
"destinationNodeName",
}
CustomNetworkFields = []string{
// TODO
"timeFlowRttNs",
}
)

Expand Down Expand Up @@ -150,6 +150,11 @@ func loadCustomRegistry(EnterpriseID uint32) error {
ilog.WithError(err).Errorf("Failed to register element")
return err
}
err = registry.PutInfoElement((*entities.NewInfoElement("timeFlowRttNs", 7740, entities.Unsigned64, EnterpriseID, 8)), EnterpriseID)
if err != nil {
ilog.WithError(err).Errorf("Failed to register element")
return err
}
return nil
}

Expand Down Expand Up @@ -336,6 +341,12 @@ func setStandardIEValue(record config.GenericMap, ieValPtr *entities.InfoElement
} else {
return fmt.Errorf("unable to find interface in record")
}
case "timeFlowRttNs":
if record["TimeFlowRttNs"] != nil {
ieVal.SetUnsigned64Value(uint64(record["TimeFlowRttNs"].(int64)))
} else {
return fmt.Errorf("unable to find timeflowrtt in record")
}
}
return nil
}
Expand Down

0 comments on commit 91917e3

Please sign in to comment.