Skip to content

Commit

Permalink
Add tests for pcap reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Zadamsa committed Jul 28, 2024
1 parent 6388b77 commit ae744d7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
Binary file added pcaps/invalid_ipv6_ext_len.pcap
Binary file not shown.
7 changes: 5 additions & 2 deletions tests/functional/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ TESTS=basic.sh \
ssadetector.sh \
vlan.sh \
nettisa.sh \
mqtt.sh
mqtt.sh \
invalid_ipv6_ext_len.sh

if WITH_QUIC
TESTS+=\
Expand Down Expand Up @@ -52,6 +53,7 @@ EXTRA_DIST=common.sh \
ssadetector.sh \
vlan.sh \
mqtt.sh \
invalid_ipv6_ext_len.sh \
reference/basic \
reference/basicplus \
reference/pstats \
Expand All @@ -75,7 +77,8 @@ EXTRA_DIST=common.sh \
reference/ssadetector \
reference/vlan \
reference/nettisa \
reference/mqtt
reference/mqtt \
reference/invalid_ipv6_ext_len

clean-local:
rm -rf output
8 changes: 8 additions & 0 deletions tests/functional/invalid_ipv6_ext_len.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

test -z "$srcdir" && export srcdir=.

. $srcdir/pcapreader.sh

run_pcap_reader_test "$pcap_dir/invalid_ipv6_ext_len.pcap" invalid_ipv6_ext_len

54 changes: 54 additions & 0 deletions tests/functional/pcapreader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

export LC_ALL=C
export LANG=C

test -z "$srcdir" && export srcdir=.

ipfixprobe_bin=../../ipfixprobe
if [ -x ../../../logger/logger ]; then
logger_bin=../../../logger/logger
elif [ -x /usr/local/bin/logger ]; then
logger_bin=/usr/local/bin/logger
else
logger_bin=/usr/bin/nemea/logger
fi

pcap_dir=$srcdir/../../pcaps
ref_dir=$srcdir/reference
output_dir=./output
file_out="$$.data"

# Usage: run_pcap_reader_test <data file> <reference fie>
run_pcap_reader_test() {
if ! [ -f "$ipfixprobe_bin" ]; then
echo "ipfixprobe not compiled"
return 77
fi

if ! `"$ipfixprobe_bin" -h unirec |head -1 | grep -q '^unirec'`; then
echo "compiled without NEMEA"
return 77
fi

if ! [ -f "$logger_bin" ]; then
echo "logger not compiled"
return 77
fi

if ! [ -d "$output_dir" ]; then
mkdir "$output_dir"
fi

"$ipfixprobe_bin" -i "pcap;file=$1" -o "unirec;ifc=f:${output_dir}/${file_out}:buffer=off:timeout=WAIT;id=0" >/dev/null
"$logger_bin" -i f:"$output_dir/$file_out" -t | sort > "$output_dir/$2"
rm "$output_dir/$file_out"

if sort "$ref_dir/$2" | diff -u "$output_dir/$2" -s - ; then
echo "$2 pcap reader test OK"
else
echo "$2 pcap reader test FAILED"
return 1
fi
}

2 changes: 2 additions & 0 deletions tests/functional/reference/invalid_ipv6_ext_len
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
6785:c903::a002:8018:202e:0,1a00:a1a1:a1a1:a1a1:a1a1:a1a1:9ba1:a117,40,0,0,2014-11-10T03:32:08.002213,2014-11-10T03:32:08.002213,00:00:00:00:00:00,00:00:00:00:00:00,1,0,0,0,0,1,0,0
ipaddr DST_IP,ipaddr SRC_IP,uint64 BYTES,uint64 BYTES_REV,uint64 LINK_BIT_FIELD,time TIME_FIRST,time TIME_LAST,macaddr DST_MAC,macaddr SRC_MAC,uint32 PACKETS,uint32 PACKETS_REV,uint16 DST_PORT,uint16 SRC_PORT,uint8 DIR_BIT_FIELD,uint8 PROTOCOL,uint8 TCP_FLAGS,uint8 TCP_FLAGS_REV

0 comments on commit ae744d7

Please # to comment.