diff --git a/pkg/decode/decode_protobuf.go b/pkg/decode/decode_protobuf.go index 7f9fe6170..9bdd7d14e 100644 --- a/pkg/decode/decode_protobuf.go +++ b/pkg/decode/decode_protobuf.go @@ -67,7 +67,7 @@ func RecordToMap(fr *model.Record) config.GenericMap { "AgentIP": fr.AgentIP.String(), } - var directions []uint8 + var directions []int var interfaces []string for _, intf := range fr.Interfaces { directions = append(directions, intf.Direction) diff --git a/pkg/decode/decode_protobuf_test.go b/pkg/decode/decode_protobuf_test.go index 061cc1523..0f2a6c7c3 100644 --- a/pkg/decode/decode_protobuf_test.go +++ b/pkg/decode/decode_protobuf_test.go @@ -102,7 +102,7 @@ func TestPBFlowToMap(t *testing.T) { assert.NotZero(t, out["TimeReceived"]) delete(out, "TimeReceived") assert.Equal(t, config.GenericMap{ - "IfDirections": []uint8{0, 1}, + "IfDirections": []int{0, 1}, "Bytes": uint64(456), "SrcAddr": "1.2.3.4", "DstAddr": "5.6.7.8", diff --git a/pkg/exporter/ipfix.go b/pkg/exporter/ipfix.go index 60deb2f79..36c2a8889 100644 --- a/pkg/exporter/ipfix.go +++ b/pkg/exporter/ipfix.go @@ -296,7 +296,7 @@ func setIEValue(record *model.Record, ieValPtr *entities.InfoElementWithValue) { case "ethernetType": ieVal.SetUnsigned16Value(record.Metrics.EthProtocol) case "flowDirection": - ieVal.SetUnsigned8Value(record.Interfaces[0].Direction) + ieVal.SetUnsigned8Value(uint8(record.Interfaces[0].Direction)) case "sourceMacAddress": ieVal.SetMacAddressValue(record.Metrics.SrcMac[:]) case "destinationMacAddress": diff --git a/pkg/model/record.go b/pkg/model/record.go index cc56dffb2..0698e771d 100644 --- a/pkg/model/record.go +++ b/pkg/model/record.go @@ -14,13 +14,10 @@ import ( // Values according to field 61 in https://www.iana.org/assignments/ipfix/ipfix.xhtml const ( - DirectionIngress = uint8(0) - DirectionEgress = uint8(1) -) -const MacLen = 6 - -// IPv4Type / IPv6Type value as defined in IEEE 802: https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml -const ( + DirectionIngress = 0 + DirectionEgress = 1 + MacLen = 6 + // IPv4Type / IPv6Type value as defined in IEEE 802: https://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml IPv6Type = 0x86DD NetworkEventsMaxEventsMD = 8 MaxNetworkEvents = 4 @@ -84,13 +81,13 @@ func NewRecord( TimeFlowStart: currentTime.Add(-startDelta), TimeFlowEnd: currentTime.Add(-endDelta), AgentIP: agentIP, - Interfaces: []IntfDir{NewIntfDir(interfaceNamer(int(metrics.IfIndexFirstSeen)), metrics.DirectionFirstSeen)}, + Interfaces: []IntfDir{NewIntfDir(interfaceNamer(int(metrics.IfIndexFirstSeen)), int(metrics.DirectionFirstSeen))}, } if metrics.AdditionalMetrics != nil { for i := uint8(0); i < record.Metrics.AdditionalMetrics.NbObservedIntf; i++ { record.Interfaces = append(record.Interfaces, NewIntfDir( interfaceNamer(int(metrics.AdditionalMetrics.ObservedIntf[i].IfIndex)), - metrics.AdditionalMetrics.ObservedIntf[i].Direction, + int(metrics.AdditionalMetrics.ObservedIntf[i].Direction), )) } if metrics.AdditionalMetrics.FlowRtt != 0 { @@ -106,10 +103,10 @@ func NewRecord( type IntfDir struct { Interface string - Direction uint8 + Direction int } -func NewIntfDir(intf string, dir uint8) IntfDir { return IntfDir{Interface: intf, Direction: dir} } +func NewIntfDir(intf string, dir int) IntfDir { return IntfDir{Interface: intf, Direction: dir} } func networkEventsMDExist(events [MaxNetworkEvents][NetworkEventsMaxEventsMD]uint8, md [NetworkEventsMaxEventsMD]uint8) bool { for _, e := range events { diff --git a/pkg/pbflow/proto.go b/pkg/pbflow/proto.go index 4aaa89d38..ccbc8c6ab 100644 --- a/pkg/pbflow/proto.go +++ b/pkg/pbflow/proto.go @@ -210,7 +210,7 @@ func PBToFlow(pb *Record) *model.Record { if len(pb.GetDupList()) != 0 { for _, entry := range pb.GetDupList() { - out.Interfaces = append(out.Interfaces, model.NewIntfDir(entry.Interface, uint8(entry.Direction))) + out.Interfaces = append(out.Interfaces, model.NewIntfDir(entry.Interface, int(entry.Direction))) } }