Skip to content

Commit

Permalink
change direction type in GenericMap back to int
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Jan 14, 2025
1 parent 2c96c42 commit 65c3ec8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
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.SetUnsigned32Value(uint32(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

0 comments on commit 65c3ec8

Please sign in to comment.