1#!/bin/sh 2# This file is part of the nfdump project. 3# 4# Copyright (c) 2004, SWITCH - Teleinformatikdienste fuer Lehre und Forschung 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions are met: 9# 10# * Redistributions of source code must retain the above copyright notice, 11# this list of conditions and the following disclaimer. 12# * Redistributions in binary form must reproduce the above copyright notice, 13# this list of conditions and the following disclaimer in the documentation 14# and/or other materials provided with the distribution. 15# * Neither the name of SWITCH nor the names of its contributors may be 16# used to endorse or promote products derived from this software without 17# specific prior written permission. 18# 19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29# POSSIBILITY OF SUCH DAMAGE. 30# 31# $Author: haag $ 32# 33# $Id: test.sh 56 2010-02-08 13:37:55Z haag $ 34# 35# $LastChangedRevision: 56 $ 36# 37# 38 39set -e 40TZ=MET 41export TZ 42 43# Check for correct output 44./nfgen | ./nfdump -q -o raw > test1.out 45diff -u test1.out nfdump.test.out 46 47# compressed flow test 48./nfgen | ./nfdump -z -q -w test.flows 49./nfdump -q -r test.flows -o raw > test2.out 50diff -u test2.out nfdump.test.out 51 52./nfdump -q -r test.flows -O tstart -o raw > test3.out 53diff -u test3.out nfdump.test.out 54 55./nfdump -r test.flows -O tstart -z -w test2.flows 56./nfdump -q -r test2.flows -o raw > test4.out 57diff test4.out nfdump.test.out > test4.diff || true 58diff test4.diff nfdump.test2.diff 59 60 61# uncompressed flow test 62rm -f test.flows test2.out 63./nfgen | ./nfdump -q -w test.flows 64./nfdump -q -r test.flows -o raw > test2.out 65diff -u test2.out nfdump.test.out 66 67rm -r test1.out test2.out 68 69# create tmp dir for flow replay 70if [ -d tmp ]; then 71 rm -f tmp/* 72 rmdir tmp 73fi 74mkdir tmp 75 76# Start nfcapd on localhost and replay flows 77echo 78echo -n Starting nfcapd ... 79./nfcapd -p 65530 -T '*' -l tmp -D -P tmp/pidfile 80sleep 1 81echo done. 82echo -n Replay flows ... 83./nfreplay -r test.flows -v9 -H 127.0.0.1 -p 65530 84echo done. 85sleep 1 86 87echo -n Terminate nfcapd ... 88kill -TERM `cat tmp/pidfile`; 89sleep 1 90echo done. 91 92if [ -f tmp/pidfile ]; then 93 echo nfcapd does not terminate 94 exit 95fi 96 97# supress 'received at' as this is always different 98./nfdump -r tmp/nfcapd.* -q -o raw | grep -v 'received at' > test5.out 99# nfdump 1.6.5 and later always use 64 bits. therefore we have a predictable diff 100# so diff the diff 101diff test5.out nfdump.test.out > test5.diff || true 102diff test5.diff nfdump.test.diff 103 104mkdir memck.$$ 105# OpenBSD 106export MALLOC_OPTIONS=AFGJS 107# MacOSX 108export MallocGuardEdges=1 109export MallocStackLogging=1 110export MallocStackLoggingDirectory=memck.$$ 111export MallocScribble=1 112export MallocErrorAbort=1 113export MallocCorruptionAbort=1 114./nfdump -r test.flows 'host 172.16.14.18' 115./nfdump -r test.flows -s ip 'host 172.16.14.18' 116./nfdump -r test.flows -s record 'host 172.16.14.18' 117./nfdump -r test.flows -w test-2.flows 'host 172.16.14.18' 118./nfdump -r test.flows -O tstart -w test-2.flows 'host 172.16.14.18' 119./nfanon -K abcdefghijklmnopqrstuvwxyz012345 -r test.flows -w anon.flows 120./nfdump -J 0 -r test.flows 121./nfdump -J 1 -r test.flows 122./nfdump -J 2 -r test.flows 123./nfdump -J 3 -r test.flows 124./nfdump -J 2 -r test.flows 125./nfdump -J 1 -r test.flows 126./nfdump -J 0 -r test.flows 127./nfdump -q -r test.flows -o raw > test2.out 128diff -u test2.out nfdump.test.out 129rm -f tmp/nfcapd.* test*.out test*.flows 130[ -d tmp ] && rmdir tmp 131[ -d memck.$$ ] && rm -rf memck.$$ 132 133 134echo All tests successful. || rm -rf memck.$$ 135