Browse Source

Remove obsolete benchmark tests

pull/18/head
Lukas Matt 10 months ago
parent
commit
b49218b36e
1 changed files with 0 additions and 115 deletions
  1. +0
    -115
      netfilter/nfq_test.go

+ 0
- 115
netfilter/nfq_test.go View File

@@ -1,115 +0,0 @@
package netfilter

import (
"net"
"testing"
"io/ioutil"

"github.com/rs/zerolog"
nfqueue "tea.fen.gg/fengg/go-nfqueue"
)

var id uint32 = 1
var payload = make([]byte, 128)
var dnsPayload = make([]byte, 128)
var invalidPayload = []byte("")
var attr = nfqueue.Attribute{
PacketID: &id,
Payload: &payload,
}
var dnsAttr = nfqueue.Attribute{
PacketID: &id,
Payload: &dnsPayload,
}
var invalidAttr = nfqueue.Attribute{
PacketID: &id,
Payload: &invalidPayload,
}

func init() {
// disable logger
logger = zerolog.New(ioutil.Discard)

payload[9] = byte(2)
payload[12], payload[13], payload[14], payload[15] = byte(1), byte(1), byte(1), byte(1)
payload[16], payload[17], payload[18], payload[19] = byte(1), byte(1), byte(1), byte(1)
copy(dnsPayload, payload)

dnsPayload[2], dnsPayload[3] = 0x00, 0x35 // port 53
dnsPacket := []byte{
0x04, 0x6d, 0x61, 0x74, 0x74, 0x02,
0x77, 0x66, 0x00, 0x00, 0x01, 0x00, 0x01,
}
copy(dnsPayload[40:54], dnsPacket[:])
}

func BenchmarkQueue(b *testing.B) {
var patterns Patterns
var connections Connections

queue := NewQueue(1)
b.Run("with 100000 invalid packets", func(b *testing.B) {
for i := 0; i < 100000; i++ {
queue.Handle(invalidAttr)
}
})
b.Run("with 100000 valid packets", func(b *testing.B) {
for i := 0; i < 100000; i++ {
queue.Handle(attr)
}
})

for i := 0; i < 1000; i++ {
conn := Connection{}
conn.Protocol = Protocol(3)
conn.Destination = ConnectionInfo{
IP: NetIP(net.IPv4(byte(2), byte(2), byte(2), byte(2))),
}
connections = append(connections, conn)
}
queue.UpdateUserBlocked(connections)

b.Run("valid packets plus 1000 user rules", func(b *testing.B) {
for i := 0; i < 100000; i++ {
queue.Handle(attr)
}
})

for i := 0; i < 1000; i++ {
pattern := Pattern{
BaseTable: &BaseTable{ID: 1},
Host: "192.168.178.1",
DNS: false,
}
patterns = append(patterns, pattern)
}
queue.UpdateSystemBlocked(patterns)

b.Run("valid packets plus 1000 user 1000 system IP rules", func(b *testing.B) {
for i := 0; i < 100000; i++ {
queue.Handle(attr)
}
})

for i := 0; i < 1000; i++ {
pattern := Pattern{
BaseTable: &BaseTable{ID: 1},
Host: "some.tld",
DNS: true,
}
patterns = append(patterns, pattern)
}
queue.UpdateSystemBlocked(patterns)

b.Run("valid packets plus 1000 user 2000 system IP DNS rules", func(b *testing.B) {
for i := 0; i < 100000; i++ {
queue.Handle(attr)
}
})

b.Run("valid DNS packets plus 1000 user 2000 system IP DNS rules", func(b *testing.B) {
for i := 0; i < 100000; i++ {
queue.Handle(dnsAttr)
}
})
}

Loading…
Cancel
Save