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.

File:
1 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: 
Note: See TracChangeset for help on using the changeset viewer.