bstinson / centos / t_functional

Forked from centos/t_functional 4 years ago
Clone

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
Christoph Galuschka adb04e
  ping -q -c $COUNT -i 0.25 ${BASH_REMATCH[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 )
Athmane Madjoudj 3399eb
  # The script will allways work, but if the log does not contain
Christoph Galuschka adb04e
  # what we expect, we will log it
Christoph Galuschka adb04e
  if [ $WORKING == $[COUNT*2] ]
Christoph Galuschka adb04e
    then
Christoph Galuschka adb04e
    ret_val=0
Christoph Galuschka adb04e
  else
Christoph Galuschka adb04e
    t_Log "ping to Default-Gateway droped pakets!! Only "$WORKING" of "$[COUNT*2]" entries were found!!"
Christoph Galuschka adb04e
    ret_val=1
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