Changeset 4188 for pjproject/trunk/tests/pjsua/mod_sipp.py
- Timestamp:
- Jun 29, 2012 9:01:17 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/tests/pjsua/mod_sipp.py
r4187 r4188 1 1 # $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 2 22 import ctypes 3 23 import time … … 23 43 #SIPP_PATH = '"C:\\Program Files (x86)\\Sipp_3.2\\sipp.exe"' 24 44 SIPP_PATH = 'sipp' 25 SIPP_PARAM = "-i 127.0.0.1 -p 6000 -m 1 127.0.0.1" 45 SIPP_PORT = 6000 46 SIPP_PARAM = "-m 1 -i 127.0.0.1 -p " + str(SIPP_PORT) 26 47 SIPP_TIMEOUT = 60 27 48 # On BG mode, SIPp doesn't require special terminal … … 31 52 #SIPP_BG_MODE = not G_INUNIX 32 53 33 # Will be updated based on configurationfile (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) 34 55 PJSUA_INST_PARAM = [] 35 56 PJSUA_EXPECTS = [] 36 57 37 # Default PJSUA param if configuration file (the corresponding .py file)is not available:58 # Default PJSUA param if test driver is not available: 38 59 # - no-tcp as SIPp is on UDP only 39 60 # - id, username, and realm: to allow PJSUA sending re-INVITE with auth after receiving 401/407 response … … 48 69 49 70 50 # Init PJSUA test instance 71 # Functions for resolving macros in the test driver 72 def resolve_pjsua_port(mo): 73 return str(PJSUA_INST_PARAM[int(mo.group(1))].sip_port) 74 75 def resolve_pjsua_uri(mo): 76 return PJSUA_INST_PARAM[int(mo.group(1))].uri[1:-1] 77 78 def 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 51 87 if os.access(SIPP_SCEN_XML[:-4]+".py", os.R_OK): 52 # Load from configurationfile (the corresponding .py file), if any88 # Load test driver file (the corresponding .py file), if any 53 89 cfg_file = imp.load_source("cfg_file", SIPP_SCEN_XML[:-4]+".py") 54 90 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)) 56 93 PJSUA_EXPECTS = cfg_file.PJSUA_EXPECTS 57 94 else: 58 # Just use the SIPp XML scenario95 # Generate default test driver 59 96 if os.path.basename(SIPP_SCEN_XML)[0:3] == "uas": 60 97 # 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) 62 99 else: 63 100 # auto answer when SIPp is as UAC 64 101 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)) 67 103 68 104 … … 72 108 sipp_proc = None 73 109 74 # run SIPp75 110 sipp_param = SIPP_PARAM + " -sf " + SIPP_SCEN_XML 76 111 if SIPP_BG_MODE: … … 78 113 if SIPP_TIMEOUT: 79 114 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 80 120 fullcmd = os.path.normpath(SIPP_PATH) + " " + sipp_param 81 121 print "Running SIPP: " + fullcmd … … 162 202 ua_idx = expect[0] 163 203 expect_st = expect[1] 164 send_cmd = expect[2]204 send_cmd = resolve_driver_macros(expect[2]) 165 205 # Handle exception in pjsua flow, to avoid zombie SIPp process 166 206 try:
Note: See TracChangeset
for help on using the changeset viewer.