/********************** PALS-IT REXX PROLOGUE ********************************/
/*                                                                           */
/* Testcase Name:     ITLFTP01.CMD                                           */
/*                                                                           */
/* Descriptive Name:  TCP/IP FTP and PING  Exerciser                         */
/*                                                                           */
/* FUNCTION TESTED:   TCP/IP PING and Remote File Access                     */
/*                                                                           */
/* TESTCASE OBJECTIVE:                                                       */
/*    DESCRIPTION:                                                           */
/*                                                                           */
/*        This test loops 400 times  unless told otherwise (in parms).       */
/*        TCP/IP addresses will be pinged from this address and              */
/*          FTP'ed to copy a remote file to the calling workstation.         */
/*                                                                           */
/*     END_OF_DESCRIPTION                                                    */
/*                                                                           */
/*    TESTABLE ITEMS:                                                        */
/*        TCP/IP ftp function                                                */
/*                                                                           */
/*    FEATURE TESTED:                                                        */
/*                                                                           */
/* DEPENDENCIES:                                                             */
/*     - The HOSTS file in the ETC directory must contain the IP             */
/*        addresses and host names of all participating workstations.        */
/*     - The TCPNBK.LST file in the MPTN\ETC directory on the FTP server   */
/*        system must have the following information:                         */
/*            user:  targetwkstid                                                   */
/*            password:  (this will be encrypted)                                  */
/*        and in the FTPD section:                                                    */
/*            active=1                                                                */
/*            read=c:\itlutil                                                         */
/*            canread=1                                                               */
/*            write=c:\itlutil                                                        */
/*            canwrite=1                                                                      */
/*                                                                                   */
/*                                                                           */
/* MANUAL INTERVENTION                                                       */
/*    None                                                                   */
/*                                                                           */
/*    PREREQUISITES:                                                         */
/*     - TCP/IP and Sockets for Anynet must be properly configured           */
/*        for all participating workstations.                                */
/*                                                                           */
/*    Input Parameters:                                                      */
/*                                                                           */
/*      -address  = the TCP/IP address of the system to be pinged            */
/*                  or ftp'ed                                                */
/*      -loops     = the number of iterations that test will be executed     */
/*                                                                           */
/*    Outputs:                                                               */
/*        - RC = 0 if function is successful   RC <> 0 if function failed    */
/*                                                                           */
/*    SPECIAL NOTES:                                                         */
/*                                                                           */
/*                                                                           */
/*                                                                           */
/* RESTRICTIONS:                                                             */
/*    none                                                                   */
/*                                                                           */
/* CHANGE ACTIVITY:                                                          */
/*   Ver  Date      NAME              Comments                               */
/*                 P. Podlipny    Initial creation                           */
/*                 J. Garcia      Added log file information                 */
/*   1.0  8/02/95  M. Biggs       Added remote file access calls             */
/*   1.1  2/21/96  R. Hartsig     Corrected FTP and log reporting problems;  */
/*                 M. Biggs       added Special Notes in Prologue            */
/*        2/22/96  J. Garcia      Implemented SCELOG calls & added map to get*/
/*                                rid of NetWare connections to L:.          */
/*        9/17/96  R. Bassemir    Modified the test for ITL use, added       */
/*                                loggoing to the itlutil directory          */
/*   2.0  2/02/97  R. Bassemir    Modified for use in the Warp test kit      */
/*   2.1  5/19/97  R. Bassemir    Changed the name of the log file to        */
/*                                represent the system it was running on     */
/*   2.2  6/16/97  R. Bassemir    Added history file, log status back to the */
/*                                shared directory of system it is testing   */
/*   3.0  6/16/97  R. Bassemir    Copied from ITLFTP02 for the self test kit */
/*                                                                           */
/*        7/03/97  S. Hudson     Change to use OS2DRV instead of hardcode c  */
/*        7/15/97  S. Hudson     Change to use common functions for methods  */
/*                               of creating history,log files, extracting   */
/*                               local system names, duration times.         */
/*        8/16/97  S. Hudson     Add 3sec sleep aft copy before net use /d   */
/*                               for files to be released before dropping net*/
/*        8/21/97  S. Hudson     Change number loops to 300 about 2 hours.   */
/*        5/05/99  T. Hughes     Added additional error checking               */
/*        5/06/99  T. Hughes     Changing FTP test to use REXXFTP commands */
/*                                   instead of using NETRC to run test           */
/*                                                                           */
/*                                                                           */
/*****************************-ENDPROLOGUE-***********************************/
arg loops sleeptime address  .
TRACE  off

/**************************************************************************/
/* USE OS2 ENVIRONMENT VARIABLE COMSPEC= TO FIND OS/2 BOOT DRIVE.         */
/**************************************************************************/
cmspec = value('COMSPEC',,'OS2ENVIRONMENT');
os2drv = left(cmspec,1)||':'

if loops = '?' then SIGNAL HELP

if loops = ' ' then loops = 300

if sleeptime = ' ' then sleeptime = 5

if address = ' ' then address = 'it01s01'

/*****************************************************************************/
/*****************************************************************************/
CALL RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
CALL RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
CALL SysLoadFuncs
CALL RxFuncAdd 'SysFileSearch','RexxUtil','SysFileSearch'
CALL RxFuncAdd 'FtpLoadFuncs','rxFtp','FtpLoadFuncs'
CALL FtpLoadFuncs

/***************** determine NETBIOS name **local system*************/
CALL SysFileSearch 'Computername',os2drv'\ibmlan\ibmlan.ini','file.'
localname = strip(subword(file.1,3,1))

/***************** define the log file and history file *************/
logfile = os2drv'\'||substr(localname,5,3)'logs\itlftp01.'||substr(localname,5,3)
histfile = os2drv'\'||substr(localname,5,3)'logs\itlftp01.'||substr(localname,5,3)'.history'
pinglog = os2drv'\'||substr(localname,5,3)'logs\pinglog.'||substr(localname,5,3)

/***************** initialize a history file **************************/
res = lineout(histfile, '***** 'time() date()' ITLFTP01 History *****')
res = lineout(histfile)

/***************** copy existing file to history ********************/
'copy 'histfile'+'logfile' 'histfile
'erase 'logfile

/**************** start a new log file *****************************/
res = lineout(logfile, '***** 'time() date()' ITLFTP01 STARTING *****')
res = lineout(logfile, 'localname wkst='address' sleeptime='sleeptime)
res = lineout(logfile, 'number of requested loops='loops)
res = lineout(logfile)
start_time = date('u') time('c')

/******* determine the next available DRIVE for a net use ******/
ndrive = nextfree()
if ndrive = 0 then
   do
      say '- There are NO free DRIVES for the NET USE '
      say '           *** This test will end now.'
      exit
   end /* do */

'net use 'ndrive' s01logs'                  /* get network resource          */
'erase 'ndrive||substr(logfile,12,12)       /* erase logfile on S01 if there */

Call SysSleep 3

'net use 'ndrive' /delete'                  /* drop the network resource     */

count = 0
/*****************************************************************************/
/****************** start the actual test case *******************************/
do until count = loops
     'ping 'address '56 3 >' pinglog
     CALL SysFileSearch 'packet loss', pinglog ,'ping.'
     parse upper var ping.1 . ',' . ',' percent '%' .
     packetloss = strip(percent)
     if packetloss > 0 then
       do
          say "error from ping"
          res = lineout(logfile, 'tcpip ping failed')
          res = lineout(logfile)
          cause = 'ping'
          call Bad_exit cause
       end
     else do
          say "Continuing normally."
          end
     /***********************************************************************/
     userid = localname||'u'
     parse upper var userid userid
     password = 'upw'||substr(localname,3,5)
     parse upper var password password
     file = '2mb.dat'

     say 'Ftp_ing to address 'address
     rc = FtpSetUser(address,userid,password)
     if rc <> 1 then
       do
         res = lineout(logfile, 'Error setting host/id/password')
         res = lineout(logfile)
         call ftpfail
       end
     say 'Recieving file ' file ' from address ' address
     rc = FtpGet(file,file,"Binary")
     if rc <> 0 then
       do
         res = lineout(logfile,'Error recieving file 'file' from address 'address)
         res = lineout(logfile)
         call ftpfail
       end
     say 'Putting file ' file ' to address ' address ' as ' localname'.ftp'
     rc = FtpPut(file,localname'.ftp',"Binary")
     if rc <> 0 then
       do
         res = lineout(logfile,'Error putting file 'file' to address 'address' as 'localname'.ftp')
         res = lineout(logfile)
         call ftpfail
       end
     else
       do
         rc = FtpLogoff()
         say "Continuing normally."
       end
     count = count + 1
     etime = time('e')
     emin  = trunc(etime / 60,2)
     ehrs  = trunc(emin  / 60,2)
     if ehrs < 1 then etimestamp = emin' MIN'
       else etimestamp = ehrs' HRS'
     fmsg = 'itlftp02> COMPLETED PASS: 'count' START: 'start_time' ELP: 'etimestamp
     res = lineout(logfile, fmsg)
     res = lineout(logfile)
     SAY' Pass 'count' done ...Sleeping for 'sleeptime' seconds'
     call SysSleep sleeptime
end   /* end for the do unitl count = loops */

/******************* write the successfully message *************************/
res = lineout(logfile, '***** 'time() date()' ITLFTP01 Completed successfully *****')
res = lineout(logfile)

/****** net use to the appropriate resource to log results *****************/
'NET USE 'ndrive' S01LOGS'                        /* get network resource        */
'copy 'logfile' 'ndrive'*.*'

Call SysSleep 3

'NET USE 'ndrive' /DELETE'                        /* drop the network resource   */

exit
ftpfail:
     say "Error from ftp"
     res = lineout(logfile, 'TCPIP FTP Failed')
     res = lineout(logfile)
     cause = 'ftp'
     call Bad_exit cause
end

/*************** bad exit routine ****************************/
BAD_EXIT:
arg cause

if cause = ping then do
  res = lineout(logfile, '***** 'time() date()' ITLFTP01 Failed on a tcpip ping to 'address)
  res = lineout(logfile, '***** Check to be sure TCPIP is intalled and configured ******')
  res = lineout(logfile)
end

if cause = ftp then do
  res = lineout(logfile, '***** 'time() date()' ITLFTP01 Failed on the ftp command *****')
  res = lineout(logfile, '***** Check to be sure the ftp server is up and running ******')
  res = lineout(logfile)
end

/****** run failed, copy log file back to S01 ******/
res = lineout(logfile, '***** 'time() date()' ITLFTP01 failed refer to above messages *****')
res = lineout(logfile)

'NET USE 'ndrive' S01LOGS'                        /* get network resource        */
'copy 'logfile' 'ndrive'*.*'

Call SysSleep 3

'NET USE 'ndrive' /DELETE'                        /* drop the network resource   */

exit

/*************** help screen *********************************/
HELP:
SAY ' This test case will exercise a FTP server.  It is designed to test'
say ' the domain controller IT01S01.'
say ' The syntax is:'
SAY ' '
SAY ' ITLFTP01 loops sleeptime address '
SAY ' '
SAY '    - address = address of the workstation to ping and ftp '
say '                the default is it01s01'
SAY '    - loops = number to iterations to execute (default is 400)'
SAY '    - sleeptime = number of seconds between passes (default is 30)'
SAY ' '
SAY ' Notes: These parameters are position dependent. If you want to '
SAY '        change the address of the localname workstation you must '
say '        also change specify the number of loops and sleeptime'
say ' '

exit
