Blame tests/p_tcpdump/tcpdump_eth0.sh

Christoph Galuschka adb04e
#!/bin/sh
Christoph Galuschka adb04e
# Author: Christoph Galuschka <christoph.galuschka@chello.at>
Christoph Galuschka adb04e
#         Athmane Madjoudj <athmanem@gmail.com>
Christoph Galuschka adb04e
Christoph Galuschka adb04e
t_Log "Running $0 - TCPdump test to Default-GW with IPv4"
Christoph Galuschka adb04e
Christoph Galuschka adb04e
# Grabing Default-Router of eth0
Christoph Galuschka adb04e
IP=$(ip route list default | grep 'default via ')
Christoph Galuschka adb04e
regex='.*via\ (.*)\ dev.*'
Christoph Galuschka adb04e
if [[ $IP =~ $regex ]]
Christoph Galuschka adb04e
  then
Christoph Galuschka adb04e
  t_Log "Found Default-GW - starting tcpdump test"
Christoph Galuschka adb04e
  #Dumping 4 pings via eth0 to file
Christoph Galuschka adb04e
  FILE='/var/tmp/eth0_test.pcap'
Christoph Galuschka adb04e
  COUNT='4'
Christoph Galuschka adb04e
  tcpdump -q -n -p -i eth0 -w $FILE &
Christoph Galuschka adb04e
  # If we don't wait a short time, the first paket will be missed by tcpdump
Christoph Galuschka adb04e
  sleep 1
Athmane Madjoudj 696d12
  ping -q -c $COUNT -i 0.25 ${BASH_REMATCH[1]} > /dev/null 2>&1
Christoph Galuschka adb04e
  sleep 1
Christoph Galuschka adb04e
  killall -s SIGINT tcpdump
Athmane Madjoudj 848fa1
  sleep 1
Christoph Galuschka adb04e
  # reading from file, for each ping we should see two pakets
Christoph Galuschka adb04e
  WORKING=$( tcpdump -r $FILE | grep -ci icmp )
Christoph Galuschka 135aec
  if [ $SKIP_QA_HARNESS ]
Christoph Galuschka adb04e
    then
Christoph Galuschka 135aec
    # treat qa-harness and non qa-harness differently,
Christoph Galuschka 135aec
    # the script will always succeed outside qa, but will log results
Christoph Galuschka adb04e
    ret_val=0
Christoph Galuschka 135aec
    if [ $WORKING != $[COUNT*2] ]
Christoph Galuschka 135aec
      then
Christoph Galuschka 135aec
      t_Log "ping to Default-Gateway did not return the number of pakets we expect. "$WORKING" of "$[COUNT*2]" pakets were dumped to file"
Christoph Galuschka 135aec
    else
Christoph Galuschka 135aec
      t_Log "ping to Default-Gateway looks OK. "$WORKING" of "$[COUNT*2]" pakets were dumped to file"
Christoph Galuschka 135aec
    fi
Christoph Galuschka adb04e
  else
Christoph Galuschka 135aec
    # in qa-harness, which is a controlled environment, the script will fail at odd results
Christoph Galuschka 135aec
    if [ $WORKING == $[COUNT*2] ]
Christoph Galuschka 135aec
      then
Christoph Galuschka 135aec
      t_Log "QA-harness: ping to Default-Gateway looks OK. "$WORKING" of "$[COUNT*2]" pakets were dumped to file"
Christoph Galuschka 135aec
      ret_val=0
Christoph Galuschka 135aec
    else
Christoph Galuschka 135aec
      t_Log "QA-harness: ping to Default-Gateway droped pakets!! Only "$WORKING" of "$[COUNT*2]" entries were found!!"
Christoph Galuschka 135aec
      ret_val=1
Christoph Galuschka 135aec
    fi
Christoph Galuschka adb04e
  fi
Christoph Galuschka adb04e
else
Christoph Galuschka 8f5133
  t_Log "No Default-GW found - skiping test"
Christoph Galuschka adb04e
  ret_val=0
Christoph Galuschka adb04e
fi
Christoph Galuschka adb04e
# Remove file afterwards
Christoph Galuschka adb04e
/bin/rm $FILE
Christoph Galuschka adb04e
Christoph Galuschka adb04e
t_CheckExitStatus $ret_val