#!/bin/sh
#***********************************************************************
#   Copyright (c) International Business Machines  Corp., 2000
#
#   This program is free software;  you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#   the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this pronram;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
#  FILE   : host
#
#  PURPOSE: To test the basic functionality of the `netstat` command.
#
#  HISTORY:
#    03/01 Robbie Williamson (robbiew@us.ibm.com)
#      -Ported
#
#
#-----------------------------------------------------------------------
# Uncomment line below for debug output.
#trace_logic=${trace_logic:-"set -x"}
$trace_logic

NUMLOOPS=${NUMLOOPS:-5}
SLEEPTIME=${SLEEPTIME:-0}

#-------------------------------------------------------------------------
# FUNCTION:  do_test
# PURPOSE:   
#            To loop for LOOPCOUNT times 
#            If MAXCOUNT is "-1" the "while"
#            loop will execute until terminated by "intr" signal.
# INPUT:     None.
# OUTPUT:    Informational messages are logged into the run log.
#
#-----------------------------------------------------------------------

do_test() { 
   $trace_logic

   COUNT=1
   while [[ $COUNT -le NUMLOOPS ]]
   do
      for COMMAND in "netstat -s" "netstat -rn" "netstat -i" "netstat -gn" "netstat -apn"
      do
         $COMMAND
         [[ $? -eq 0 ]] || end_testcase "$COMMAND failed" 
      done

      ((COUNT=$COUNT+1))
      sleep $SLEEPTIME
   done
}

#=============================================================================
# FUNCTION NAME:        end_testcase
#
# FUNCTION DESCRIPTION: Clean up
#
# PARAMETERS:           string, IF AND ONLY IF the testcase fails
#
# RETURNS:              None.
#=============================================================================

end_testcase()
{
   $trace_logic

   [[ $# -eq 0 ]] && { echo "Test Successful"; exit 0; }
   echo "Test Failed: $@"
   exit 1
}

#-----------------------------------------------------------------------
#
# FUNCTION:  MAIN
# PURPOSE:   To invoke functions that perform the tasks as described in
#        the design in the prolog above.
# INPUT:     See SETUP in the prolog above.
# OUTPUT:    Logged run results written to testcase run log
#
#-----------------------------------------------------------------------
do_test
end_testcase
