/********************** PALS-IT REXX PROLOGUE ********************************/
/*                                                                           */
/* Testcase Name:     ITLMSG.CMD                                             */
/*                                                                           */
/* Descriptive Name:  LAN SERVER MESSAGING EXERCISER                         */
/*                                                                           */
/* FUNCTION TESTED:   Messaging between requesters                           */
/*                                                                           */
/* TESTCASE OBJECTIVE:                                                       */
/*    DESCRIPTION:                                                           */
/*        Generate a source of messages between multiple LAN Requesters.     */
/*        The command is executed on the sending requester.  The command     */
/*        is passed three parms.  The first two specify target machines      */
/*        to receive the message.  The third tells how many loops to         */
/*        make. There is a pause between messages.                           */
/*    END_OF_DESCRIPTION                                                     */
/*                                                                           */
/*    TESTABLE ITEMS:                                                        */
/*        Lan Requester                                                      */
/*                                                                           */
/* DEPENDENCIES:                                                             */
/*                                                                           */
/*        The NEXTFREE.CMD file needs to be available                        */
/*                                                                           */
/* MANUAL INTERVENTION                                                       */
/*    None                                                                   */
/*                                                                           */
/*    PREREQUISITES:                                                         */
/*                                                                           */
/*                                                                           */
/*    Input Parameters:                                                      */
/*                                                                           */
/*        - The receiving machines and the number of messages                */
/*                                                                           */
/*    Outputs:                                                               */
/*        - RC= 0 if successful      RC=8 if failed                          */
/*                                                                           */
/*    SPECIAL NOTES:                                                         */
/*                                                                           */
/*        - None.                                                            */
/*                                                                           */
/* RESTRICTIONS:                                                             */
/*    none                                                                   */
/*                                                                           */
/* CHANGE ACTIVITY:                                                          */
/*   Ver  Date      NAME         Comments                                    */
/*   1.0  03/10/94  R.Bassemir    Initial release.                           */
/*   1.1  02/06/95  R. Bassemir   Clean up exec's help                       */
/*   1.2  10/17/96  R. Bassemir   Added logging of failed messages           */
/*   1.3  05/19/97  R. Bassemir   Implemented parm passing & set the log     */
/*                                name according to the system id            */
/*   1.4  06/03/97  R.Bassemir    Set defaults depending on which system the */
/*                                test case is running on (assumes ITxxyyy   */
/*                                naming convention)                         */
/*   1.5  06/04/97  R.Bassemir    Added copy of log files to remote DRIVES   */
/*                                along with adding nextfree DRIVE function  */
/*                                added a history log file                   */
/*   1.6  06/09/97  R.Bassemir    Cleaned up some messages                   */
/*                                                                           */
/*        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.         */
/*       11/03/97 S.Hudson-R.Bassemir Change to broadcast message for recvr1 */
/*                                    instead of only to domain or server to */
/*                                    allow msg testing with SMP servers.    */
/*                                                                           */
/*****************************-END PROLOGUE-**********************************/
arg recvr1 recvr2 loops
TRACE  off

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

if recvr1 = "?" then signal HELP        /* jump to help text */

if loops = "" then loops = 100         /* set default loop count */


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

/***************** 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\itlmsg.'||substr(localname,5,3)
histfile = os2drv'\'||substr(localname,5,3)'logs\itlmsg.'||substr(localname,5,3)'.history'

/***************** initialize a history file **************************/
res = lineout(histfile, '***** 'time() date()' ITLMSG 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()' ITLMSG STARTING *****')
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 */

/****** set the default targets when no parms are passed ***********/

recvr1 = '/D:IT01D01D'
/*---------------------------------------*/
/*  if recvr1 = "" then do               */
/*    if localname = 'IT01R01' then do   */
/*       recvr1 = 'IT01D01'              */
/*       end                             */
/*    else                               */
/*    if localname = 'IT01D01' then do   */
/*     recvr1 = 'IT01S01'                */
/*     end                               */
/*  else                                 */
/*  if localname = 'IT01R02' then do     */
/*     recvr1 = 'IT01D01'                */
/*     end                               */
/*  end                                  */
/*---------------------------------------*/

if recvr2 = "" then do
  if localname = 'IT01R01' then do
     recvr2 = 'IT01R02'
     end
  else
  if localname = 'IT01D01' then do
     recvr2 = 'IT01R01'
     end
  else
  if localname = 'IT01R02' then do
     recvr2 = 'IT01R01'
     end
end

/***** set the default targets when no parms are passed ***********/
if localname = 'IT01R01' then do
   resource = 'd01logs'
   end
else
if localname = 'IT01D01' then do
   resource = '\\it01r01\r01logs'
   end
else
if localname = 'IT01R02' then do
   resource = 'd01logs'
   end

res = lineout(logfile, 'wkst #1='recvr1 'wkst #2='recvr2)
res = lineout(logfile)

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

CALL SysSleep 3

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


failmsg1=0
failmsg2=0
count = 1                                    /* initialize counter     */

/*****************************************************************************/
/*****************************************************************************/
do until count>loops                          /* set up the do until loop    */
   'NET SEND 'RECVR1'  Messaging exerciser is running, message number 'count
   IF RC \= 0 then do                         /* exit if the command failed  */
      SAY 'Message was not successfully sent to requester  'recvr1
      DATETIME = DATE() TIME()                /* set time and date           */
      SAY DATETIME  'Pass number  ' count     /* output date and time        */
      fmsg = 'Unsuccessful at sending message to 'recvr1' at 'datetime
      res = lineout(logfile, fmsg)
      res = lineout(logfile)
      failmsg1=failmsg1+1
    END                                       /* end the IF RC\=0 statement  */

   'NET SEND 'RECVR2'  Messaging exerciser is running, message number 'count
   IF RC \= 0 then do                         /* exit if the command failed  */
      SAY 'Message was not successfully sent to requester 'recvr2
      DATETIME = DATE() TIME()                /* set time and date           */
      SAY DATETIME  'Pass number  ' count     /* output date and time        */
      fmsg = 'Unsuccessful at sending message to 'recvr2' at 'datetime
      res = lineout(logfile, fmsg)
      res = lineout(logfile)
      failmsg2=failmsg2+1
    END                                         /* end the IF RC\=0 statement  */

   SAY'There have been ' (2*count) ' messages sent.'
   count=count+1                                /* increment message counter   */
   SAY'...Sleeping for 30 seconds'
   call SysSleep 30
end                                          /* end do until count=loops    */

/* ************************************************************************ */

fmsg = 'Testing has completed for 'loops' iterations at 'date()'  'time()
res = lineout(logfile, fmsg)

fmsg = 'A total of 'loops*2' messages have been attempted'
res = lineout(logfile, fmsg)

fmsg = failmsg1' messages out of 'loops' failed to be sent to 'recvr1
res = lineout(logfile, fmsg)

fmsg = failmsg2' messages out of 'loops' failed to be sent to 'recvr2
res = lineout(logfile, fmsg)
res = lineout(logfile)

if failmsg1=0 & failmsg2=0 then do
   res = lineout(logfile, '***** 'time() date()' ITLMSG Completed successfully *****')
   res = lineout(logfile)
   end
else do
     fmsg = 'Messages were lost or unsuccessful as indicated above.'
     res = lineout(logfile, fmsg)
     res = lineout(logfile, '***** 'time() date()' ITLMSG failed  *****')
     res = lineout(logfile)
     end


/****** net use to the appropriate resource to log results *****************/
'net use 'ndrive' 'resource
'erase 'ndrive||substr(logfile,12,10)  /*erase existing log file if present */
'copy 'logfile' 'ndrive'*.*'

CALL SysSleep 3

'net use 'ndrive' /delete'

exit



HELP:
say 'This program will send LAN Server net messages. This program loops '
say 'and for every loop it will send two messages (one message to each '
say 'workstation specified).  The syntax is: '
say ' '
say '   ITLMSG workstation1 workstation2 loops '
say ' '
say 'Where:  workstation1 is the first workstation  to send a message'
say '                 (a default is chosen if none is supplied)'
say '        workstation2 is the second workstation to send a message'
say '                 (a default is chosen if none is supplied)'
say '        loops is the number of loops (or passes) to make'
say '                 (the default is 100)'
say ' '
say ' Notes: -If you want to specify your own workstation1 and workstation2'
say '         parameters then you must also specify a count parameter'
say '        -The parameters are position dependent '
say '        -You may want to disable the netpopup service if using a OS/2 '
say '         workstation so you do not get the constant popup windows.'
say '         Use the NET STOP NETPOPUP command to do this'
EXIT
