!
! RMIF Remote reuse test case
!
! When reusing an existing Remote, which happens when two OPEN messages
! are sent to an RMIF server at once. You will receive some PKTDROP LINKERR
! messages. Once the LINKERR occurs there is no way for the Remote to recover.
!
! <sPort>   - The KNOWN port of the server.  Client uses any available port.
! <msgCnt>  - The number of messages the client (sender) will send out.
!             Note, if you increase this, you may also have to increase the
!             test timeout value. Note, that, since we are expecting this test
!             case to cause packet  drops, the expected received messages
!             should be (msgCnt - number of packets dropped).
! <timeout> - The timeout (max time) that this test should run before aborting
!
! @bug     1051
! @author  Neon Ngo
! @since   NeXtMidas 2.5.1
!
startmacro L:sPort[-1] L:msgCnt[300] D:timeout[40] L:windowSize[80]
  switch DEBUG         debug        GET DEF=false    SDEF=true
  switch DEBUGSERVER   debugs       GET DEF=^debug   SDEF=true
  switch DEBUGCLIENT   debugc       GET DEF=^debug   SDEF=true
  switch VERBOSE       verbose      GET DEF=false    SDEF=true
  switch VERBOSESERVER verboses     GET DEF=^verbose SDEF=true
  switch VERBOSECLIENT verbosec     GET DEF=^verbose SDEF=true
  switch STATEM        statemachine GET DEF=false    SDEF=true

  invoke headless nxm.sys.lib.Shell.isHeadless()
  if statemachine then
    info "SKIPPING ^reg.main.name remote reuse is not suuported with /STATEM."
  else
    timer set

    ! call RMIF test framewwork standard setup (see included standard_rmif_procs.mminc)
    call standardSetup timeout sPort
    pipe on
      %test_rmif_remote_reuse_server/id=SERVER/STATEM=^statemachine/DEBUG=^debugs/VERBOSE=^verboses/BG this ^sPort ^msgCnt ^timeout
      %test_rmif_remote_reuse_client/id=CLIENT/STATEM=^statemachine/DEBUG=^debugc/VERBOSE=^verbosec/BG this ^sPort msgCnt=^msgCnt windowSize=^windowSize
    pipe off

    timer elapse
  endif
endmacro

!******************************************************************************!
procedure processMessage m:msg
  if debug then
    say "^reg.main.name: Got message name=^msg.name fid=^msg.fid info=^msg.info data=^msg.data"
  endif

  if msg.name EQS CLIENT_TEST AND msg.info EQ 1 then
    ! tell RMIF server (receiver) macro to decrease it expected packet count by 1
    message FUNC=send ID=SERVER NAME=DECREASE_MSG_COUNT DATA=1
  else
    call processStandardMessages
  endif
return

! These are a set of standard procedures
include standard_rmif_procs.mminc
