Changeset 4188


Ignore:
Timestamp:
Jun 29, 2012 9:01:17 AM (12 years ago)
Author:
nanang
Message:

Re #1523: use random port for PJSUA instance(s) and configurable SIPp port.

Location:
pjproject/trunk/tests/pjsua
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/tests/pjsua/mod_sipp.py

    r4187 r4188  
    11# $Id$ 
     2 
     3## Automatic test module for SIPp. 
     4## 
     5## This module will need a test driver for each SIPp scenario: 
     6## - For simple scenario, i.e: make/receive call (including auth), this 
     7##   test module can auto-generate a default test driver, i.e: make call 
     8##   or apply auto answer. Just name the SIPp scenario using "uas" or 
     9##   "uac" prefix accordingly. 
     10## - Custom test driver can be defined in a python script file containing 
     11##   a list of the PJSUA instances and another list for PJSUA expects/ 
     12##   commands. The custom test driver file must use the same filename as 
     13##   the SIPp XML scenario. See samples of SIPp scenario + its driver 
     14##   in tests/pjsua/scripts-sipp/ folder for detail. 
     15## 
     16##   Here are defined macros that can be used in the custom driver: 
     17##   - $SIPP_PORT           : SIPp binding port 
     18##   - $SIPP_URI            : SIPp SIP URI 
     19##   - $PJSUA_PORT[N]       : binding port of PJSUA instance #N 
     20##   - $PJSUA_URI[N]        : SIP URI of PJSUA instance #N 
     21 
    222import ctypes 
    323import time 
     
    2343#SIPP_PATH = '"C:\\Program Files (x86)\\Sipp_3.2\\sipp.exe"' 
    2444SIPP_PATH = 'sipp' 
    25 SIPP_PARAM = "-i 127.0.0.1 -p 6000 -m 1 127.0.0.1" 
     45SIPP_PORT    = 6000 
     46SIPP_PARAM = "-m 1 -i 127.0.0.1 -p " + str(SIPP_PORT) 
    2647SIPP_TIMEOUT = 60 
    2748# On BG mode, SIPp doesn't require special terminal 
     
    3152#SIPP_BG_MODE = not G_INUNIX 
    3253 
    33 # Will be updated based on configuration file (a .py file whose the same name as SIPp XML file) 
     54# Will be updated based on the test driver file (a .py file whose the same name as SIPp XML file) 
    3455PJSUA_INST_PARAM = [] 
    3556PJSUA_EXPECTS = [] 
    3657 
    37 # Default PJSUA param if configuration file (the corresponding .py file) is not available: 
     58# Default PJSUA param if test driver is not available: 
    3859# - no-tcp as SIPp is on UDP only 
    3960# - id, username, and realm: to allow PJSUA sending re-INVITE with auth after receiving 401/407 response 
     
    4869 
    4970 
    50 # Init PJSUA test instance 
     71# Functions for resolving macros in the test driver 
     72def resolve_pjsua_port(mo): 
     73    return str(PJSUA_INST_PARAM[int(mo.group(1))].sip_port) 
     74 
     75def resolve_pjsua_uri(mo): 
     76    return PJSUA_INST_PARAM[int(mo.group(1))].uri[1:-1] 
     77 
     78def resolve_driver_macros(st): 
     79    st = re.sub("\$SIPP_PORT", str(SIPP_PORT), st) 
     80    st = re.sub("\$SIPP_URI", "sip:sipp@127.0.0.1:"+str(SIPP_PORT), st) 
     81    st = re.sub("\$PJSUA_PORT\[(\d+)\]", resolve_pjsua_port, st) 
     82    st = re.sub("\$PJSUA_URI\[(\d+)\]", resolve_pjsua_uri, st) 
     83    return st 
     84 
     85 
     86# Init test driver 
    5187if os.access(SIPP_SCEN_XML[:-4]+".py", os.R_OK): 
    52     # Load from configuration file (the corresponding .py file), if any 
     88    # Load test driver file (the corresponding .py file), if any 
    5389    cfg_file = imp.load_source("cfg_file", SIPP_SCEN_XML[:-4]+".py") 
    5490    for ua_idx, ua_param in enumerate(cfg_file.PJSUA): 
    55         PJSUA_INST_PARAM.append(InstanceParam("pjsua"+str(ua_idx+1), ua_param, sip_port=5060+ua_idx*2)) 
     91        ua_param = resolve_driver_macros(ua_param) 
     92        PJSUA_INST_PARAM.append(InstanceParam("pjsua"+str(ua_idx), ua_param)) 
    5693    PJSUA_EXPECTS = cfg_file.PJSUA_EXPECTS 
    5794else: 
    58     # Just use the SIPp XML scenario 
     95    # Generate default test driver 
    5996    if os.path.basename(SIPP_SCEN_XML)[0:3] == "uas": 
    6097        # auto make call when SIPp is as UAS 
    61         ua_param = PJSUA_DEF_PARAM + " sip:127.0.0.1:6000" 
     98        ua_param = PJSUA_DEF_PARAM + " sip:127.0.0.1:" + str(SIPP_PORT) 
    6299    else: 
    63100        # auto answer when SIPp is as UAC 
    64101        ua_param = PJSUA_DEF_PARAM + " --auto-answer=200"  
    65     PJSUA_INST_PARAM.append(InstanceParam("pjsua", ua_param, sip_port=5060)) 
    66      
     102    PJSUA_INST_PARAM.append(InstanceParam("pjsua", ua_param)) 
    67103 
    68104 
     
    72108    sipp_proc = None 
    73109 
    74     # run SIPp 
    75110    sipp_param = SIPP_PARAM + " -sf " + SIPP_SCEN_XML 
    76111    if SIPP_BG_MODE: 
     
    78113    if SIPP_TIMEOUT: 
    79114        sipp_param = sipp_param + " -timeout "+str(SIPP_TIMEOUT)+"s -timeout_error" + " -deadcall_wait "+str(SIPP_TIMEOUT)+"s" 
     115 
     116    # add target param 
     117    sipp_param = sipp_param + " 127.0.0.1:" + str(PJSUA_INST_PARAM[0].sip_port) 
     118 
     119    # run SIPp 
    80120    fullcmd = os.path.normpath(SIPP_PATH) + " " + sipp_param 
    81121    print "Running SIPP: " + fullcmd 
     
    162202        ua_idx = expect[0] 
    163203        expect_st = expect[1] 
    164         send_cmd = expect[2] 
     204        send_cmd = resolve_driver_macros(expect[2]) 
    165205        # Handle exception in pjsua flow, to avoid zombie SIPp process 
    166206        try: 
  • pjproject/trunk/tests/pjsua/scripts-sipp/strict-route.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id=sip:pjsua@localhost --username=pjsua --realm=* sip:sipp@localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 --id=sip:pjsua@localhost --username=pjsua --realm=* $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, "ACK sip:proxy@.* SIP/2\.0", ""], 
  • pjproject/trunk/tests/pjsua/scripts-sipp/transfer-attended.py

    r4183 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio",    # UA0 @ port 5060 
    6          "--null-audio",    # UA1 @ port 5062 
    7          "--null-audio"     # UA2 @ port 5064 
     5PJSUA = ["--null-audio",    # UA0 
     6         "--null-audio",    # UA1 
     7         "--null-audio"     # UA2 
    88        ] 
    99 
     
    1111                 # A calls B 
    1212                 [0, "", "m"], 
    13                  [0, "", "sip:localhost:5062"], 
     13                 [0, "", "$PJSUA_URI[1]"], 
    1414                 [0, const.STATE_CALLING, ""], 
    1515                 [1, const.EVENT_INCOMING_CALL, "a"], 
     
    2525                 # B calls C 
    2626                 [1, "", "m"], 
    27                  [1, "", "sip:localhost:5064"], 
     27                 [1, "", "$PJSUA_URI[2]"], 
    2828                 [1, const.STATE_CALLING, ""], 
    2929                 [2, const.EVENT_INCOMING_CALL, "a"], 
  • pjproject/trunk/tests/pjsua/scripts-sipp/transfer-unattended.py

    r4183 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio",    # UA0 @ port 5060 
    6          "--null-audio",    # UA1 @ port 5062 
    7          "--null-audio"     # UA2 @ port 5064 
     5PJSUA = ["--null-audio",    # UA0 
     6         "--null-audio",    # UA1 
     7         "--null-audio"     # UA2 
    88        ] 
    99 
     
    1111                 # A calls B 
    1212                 [0, "", "m"], 
    13                  [0, "", "sip:localhost:5062"], 
     13                 [0, "", "$PJSUA_URI[1]"], 
    1414                 [0, const.STATE_CALLING, ""], 
    1515                 [1, const.EVENT_INCOMING_CALL, "a"], 
     
    2020                 # B transfer A to C 
    2121                 [1, "", "x"], 
    22                  [1, "", "sip:localhost:5064"], 
     22                 [1, "", "$PJSUA_URI[2]"], 
    2323                 [0, const.STATE_CALLING, ""], 
    2424                 [2, const.EVENT_INCOMING_CALL, "a"], 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-answer-200-reinvite-without-sdp.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 sip:localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, const.STATE_CONFIRMED, "v"]] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-answer-200-update-without-sdp.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 sip:localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, const.STATE_CONFIRMED, "U"]] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-auth.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id=sip:a@localhost --username=a --realm=* --registrar=sip:localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 --id=sip:a@localhost --username=a --realm=* --registrar=$SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-cancel-no-final.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 sip:localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, const.STATE_EARLY, "h"]] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-mwi-0.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --mwi"] 
     5PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:$SIPP_PORT --mwi"] 
    66 
    77PJSUA_EXPECTS = [] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-mwi.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --mwi"] 
     5PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:$SIPP_PORT --mwi"] 
    66 
    77PJSUA_EXPECTS = [] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-reinv-glare.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 sip:localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, const.STATE_CONFIRMED, "U"]] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-subscribe-late-notify.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, "", "s"], 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-subscribe-multipart-notify.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, "", "s"], 
    88                 [0, "Subscribe presence of:", "1"], 
    9                  [0, "sip:sipp@localhost:6000 .* Online", ""], 
     9                 [0, "status is Online", ""], 
    1010                 [0, "subscription state is TERMINATED", ""] 
    1111                 ] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-subscribe-notify-terminate.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, "", "s"], 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-subscribe-refresh-481.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, "", "s"], 
    88                 [0, "Subscribe presence of:", "1"], 
    9                  [0, "sip:sipp@localhost:6000 .* Online", ""], 
     9                 [0, "status is Online", ""], 
    1010                 [0, "subscription state is TERMINATED", ""] 
    1111                 ] 
  • pjproject/trunk/tests/pjsua/scripts-sipp/uas-subscribe-terminated-retry.py

    r4177 r4188  
    33import inc_const as const 
    44 
    5 PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"] 
     5PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"] 
    66 
    77PJSUA_EXPECTS = [[0, "", "s"], 
Note: See TracChangeset for help on using the changeset viewer.