mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
inlet/flow: add tests for ICMP and Netflow
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/google/gopacket/pcapgo"
|
"github.com/google/gopacket/pcapgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReadPcapPayload reads and parses a PCAP file and return the payload (after Layer 4).
|
// ReadPcapPayload reads and parses a PCAP file and return the payload (Layer 4).
|
||||||
func ReadPcapPayload(t testing.TB, pcapfile string) []byte {
|
func ReadPcapPayload(t testing.TB, pcapfile string) []byte {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
f, err := os.Open(pcapfile)
|
f, err := os.Open(pcapfile)
|
||||||
|
|||||||
@@ -234,3 +234,75 @@ func TestTemplatesMixedWithData(t *testing.T) {
|
|||||||
t.Fatalf("Metrics after data (-got, +want):\n%s", diff)
|
t.Fatalf("Metrics after data (-got, +want):\n%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDecodeICMP(t *testing.T) {
|
||||||
|
r := reporter.NewMock(t)
|
||||||
|
nfdecoder := New(r, decoder.Dependencies{Schema: schema.NewMock(t).EnableAllColumns()})
|
||||||
|
|
||||||
|
data := helpers.ReadPcapPayload(t, filepath.Join("testdata", "icmp-1.pcap"))
|
||||||
|
got := nfdecoder.Decode(decoder.RawFlow{Payload: data, Source: net.ParseIP("127.0.0.1")})
|
||||||
|
data = helpers.ReadPcapPayload(t, filepath.Join("testdata", "icmp-2.pcap"))
|
||||||
|
got = append(got, nfdecoder.Decode(decoder.RawFlow{Payload: data, Source: net.ParseIP("127.0.0.1")})...)
|
||||||
|
|
||||||
|
expectedFlows := []*schema.FlowMessage{
|
||||||
|
{
|
||||||
|
ExporterAddress: netip.MustParseAddr("::ffff:127.0.0.1"),
|
||||||
|
SrcAddr: netip.MustParseAddr("2001:db8::"),
|
||||||
|
DstAddr: netip.MustParseAddr("2001:db8::1"),
|
||||||
|
ProtobufDebug: map[schema.ColumnKey]interface{}{
|
||||||
|
schema.ColumnBytes: 104,
|
||||||
|
schema.ColumnDstPort: 32768,
|
||||||
|
schema.ColumnEType: 34525,
|
||||||
|
schema.ColumnICMPv6Type: 128, // Code: 0
|
||||||
|
schema.ColumnPackets: 1,
|
||||||
|
schema.ColumnProto: 58,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ExporterAddress: netip.MustParseAddr("::ffff:127.0.0.1"),
|
||||||
|
SrcAddr: netip.MustParseAddr("2001:db8::1"),
|
||||||
|
DstAddr: netip.MustParseAddr("2001:db8::"),
|
||||||
|
ProtobufDebug: map[schema.ColumnKey]interface{}{
|
||||||
|
schema.ColumnBytes: 104,
|
||||||
|
schema.ColumnDstPort: 33024,
|
||||||
|
schema.ColumnEType: 34525,
|
||||||
|
schema.ColumnICMPv6Type: 129, // Code: 0
|
||||||
|
schema.ColumnPackets: 1,
|
||||||
|
schema.ColumnProto: 58,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ExporterAddress: netip.MustParseAddr("::ffff:127.0.0.1"),
|
||||||
|
SrcAddr: netip.MustParseAddr("::ffff:203.0.113.4"),
|
||||||
|
DstAddr: netip.MustParseAddr("::ffff:203.0.113.5"),
|
||||||
|
ProtobufDebug: map[schema.ColumnKey]interface{}{
|
||||||
|
schema.ColumnBytes: 84,
|
||||||
|
schema.ColumnDstPort: 2048,
|
||||||
|
schema.ColumnEType: 2048,
|
||||||
|
schema.ColumnICMPv4Type: 8, // Code: 0
|
||||||
|
schema.ColumnPackets: 1,
|
||||||
|
schema.ColumnProto: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ExporterAddress: netip.MustParseAddr("::ffff:127.0.0.1"),
|
||||||
|
SrcAddr: netip.MustParseAddr("::ffff:203.0.113.5"),
|
||||||
|
DstAddr: netip.MustParseAddr("::ffff:203.0.113.4"),
|
||||||
|
ProtobufDebug: map[schema.ColumnKey]interface{}{
|
||||||
|
schema.ColumnBytes: 84,
|
||||||
|
schema.ColumnEType: 2048,
|
||||||
|
schema.ColumnPackets: 1,
|
||||||
|
schema.ColumnProto: 1,
|
||||||
|
// Type/Code = 0
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, f := range got {
|
||||||
|
f.TimeReceived = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if diff := helpers.Diff(got, expectedFlows); diff != "" {
|
||||||
|
t.Fatalf("Decode() (-got, +want):\n%s", diff)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
BIN
inlet/flow/decoder/netflow/testdata/icmp-1.pcap
vendored
Normal file
BIN
inlet/flow/decoder/netflow/testdata/icmp-1.pcap
vendored
Normal file
Binary file not shown.
BIN
inlet/flow/decoder/netflow/testdata/icmp-2.pcap
vendored
Normal file
BIN
inlet/flow/decoder/netflow/testdata/icmp-2.pcap
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user