bstinson / centos / t_functional

Forked from centos/t_functional 3 years ago
Clone

Blame tests/p_tcpdump/01_tcpdump_nic.sh

Christoph Galuschka adb04e
#!/bin/sh
Christoph Galuschka 14b795
# Author: Christoph Galuschka <tigalch@tigalch.org>
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 25699e
# Grabing Default-Router if NIC
e8136b
def_gw=$(ip route list default|grep "default via"|head -n 1|awk '{print $3}')
85f46c
eth_int=$(ip addr|grep -B 1 "link/ether"|head -n 1|awk '{print $2}'|tr -d ':')
85f46c
Christoph Galuschka adb04e
  t_Log "Found Default-GW - starting tcpdump test"
Christoph Galuschka 25699e
  #Dumping 4 pings via NIC to file
Christoph Galuschka 25699e
  FILE='/var/tmp/nic_test.pcap'
Christoph Galuschka adb04e
  COUNT='4'
85f46c
  tcpdump -i $eth_int -q -n -p -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
e8136b
  ping -q -c $COUNT -i 0.25 ${def_gw} > /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 )
Karanbir Singh 23b6ba
  if [ $SKIP_QA_HARNESS -eq 1 ]
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 df4b35
    if [ $WORKING == $[COUNT*2] ] || [ $WORKING -gt $[COUNT*2] ]
Christoph Galuschka 135aec
      then
Christoph Galuschka df4b35
      t_Log "QA-harness: ping to Default-Gateway looks OK. At least "$[COUNT*2]" pakets ("$WORKING") 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
# Remove file afterwards
Christoph Galuschka adb04e
/bin/rm $FILE
Christoph Galuschka adb04e
Christoph Galuschka adb04e
t_CheckExitStatus $ret_val