Newer
Older
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
Mohamed S. Mahmoud
committed
"github.com/netobserv/netobserv-ebpf-agent/pkg/ebpf"
)
func TestPacketAggregation(t *testing.T) {
type testCase struct {
Mohamed S. Mahmoud
committed
input []ebpf.BpfFlowMetrics
Mohamed S. Mahmoud
committed
expected ebpf.BpfFlowMetrics
}
tcs := []testCase{{
Mohamed S. Mahmoud
committed
input: []ebpf.BpfFlowMetrics{
{Packets: 0, Bytes: 0, StartMonoTimeTs: 0, EndMonoTimeTs: 0, Flags: 1},
{Packets: 0x7, Bytes: 0x22d, StartMonoTimeTs: 0x176a790b240b, EndMonoTimeTs: 0x176a792a755b, Flags: 1},
{Packets: 0x0, Bytes: 0x0, StartMonoTimeTs: 0x0, EndMonoTimeTs: 0x0, Flags: 1},
{Packets: 0x0, Bytes: 0x0, StartMonoTimeTs: 0x0, EndMonoTimeTs: 0x0, Flags: 1},
},
Mohamed S. Mahmoud
committed
expected: ebpf.BpfFlowMetrics{
Packets: 0x7, Bytes: 0x22d, StartMonoTimeTs: 0x176a790b240b, EndMonoTimeTs: 0x176a792a755b, Flags: 1,
Mohamed S. Mahmoud
committed
input: []ebpf.BpfFlowMetrics{
{Packets: 0x3, Bytes: 0x5c4, StartMonoTimeTs: 0x17f3e9613a7f, EndMonoTimeTs: 0x17f3e979816e, Flags: 1},
{Packets: 0x2, Bytes: 0x8c, StartMonoTimeTs: 0x17f3e9633a7f, EndMonoTimeTs: 0x17f3e96f164e, Flags: 1},
{Packets: 0x0, Bytes: 0x0, StartMonoTimeTs: 0x0, EndMonoTimeTs: 0x0, Flags: 1},
{Packets: 0x0, Bytes: 0x0, StartMonoTimeTs: 0x0, EndMonoTimeTs: 0x0, Flags: 1},
},
Mohamed S. Mahmoud
committed
expected: ebpf.BpfFlowMetrics{
Mohamed S. Mahmoud
committed
Packets: 0x5, Bytes: 0x5c4 + 0x8c, StartMonoTimeTs: 0x17f3e9613a7f, EndMonoTimeTs: 0x17f3e979816e, Flags: 1,
Mohamed S. Mahmoud
committed
ft := MapTracer{}
for i, tc := range tcs {
t.Run(fmt.Sprint(i), func(t *testing.T) {
assert.Equal(t,
tc.expected,
Mohamed S. Mahmoud
committed
*ft.aggregate(tc.input))