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

change direction type in GenericMap back to int #507

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
2 changes: 1 addition & 1 deletion pkg/decode/decode_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/decode/decode_protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/ipfix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
19 changes: 8 additions & 11 deletions pkg/model/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/pbflow/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}

Expand Down
Loading