-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathalice_main.py
132 lines (120 loc) · 4.16 KB
/
alice_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python2
#
# Copyright (c) 2015 Sippy Software, Inc. All rights reserved.
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import sys, getopt
from time import sleep
from sippy.MsgBody import MsgBody
from sippy.SipLogger import SipLogger
from sippy.SipConf import SipConf
from sippy.Core.EventDispatcher import ED2
from .lib.PortRange import PortRange
from .lib.test_config import test_config
body_txt = 'v=0\r\n' + \
'o=- 380960 380960 IN IP4 192.168.22.95\r\n' + \
's=-\r\n' + \
'c=IN IP4 192.168.22.95\r\n' + \
't=0 0\r\n' + \
'm=audio 16474 RTP/AVP 18 0 2 4 8 96 97 98 101\r\n' + \
'a=rtpmap:18 G729a/8000\r\n' + \
'a=rtpmap:0 PCMU/8000\r\n' + \
'a=rtpmap:2 G726-32/8000\r\n' + \
'a=rtpmap:4 G723/8000\r\n' + \
'a=rtpmap:8 PCMA/8000\r\n' + \
'a=rtpmap:96 G726-40/8000\r\n' + \
'a=rtpmap:97 G726-24/8000\r\n' + \
'a=rtpmap:98 G726-16/8000\r\n' + \
'a=rtpmap:101 telephone-event/8000\r\n' + \
'a=fmtp:101 0-15\r\n' + \
'a=ptime:30\r\n' + \
'a=sendrecv\r\n' + \
'\r\n'
def main_func():
global_config = {}
try:
opts, args = getopt.getopt(sys.argv[1:], 'Dp:t:l:P:T:46n:N:w:')
except getopt.GetoptError:
usage(global_config)
tcfg = test_config(global_config)
ttype = []
pre_wait = None
dry_run = False
for o, a in opts:
if o == '-p':
tcfg.portrange = PortRange(a.strip())
continue
if o == '-t':
if a != '*':
tcfg.tests = tuple(['alice_' + x for x in a.split(',')])
else:
tcfg.tests = None
continue
if o == '-l':
saddr = a.strip()
if saddr == '*':
saddr = SipConf.my_address
global_config['_sip_address'] = saddr
continue
if o == '-P':
global_config['_sip_port'] = int(a)
continue
if o == '-T':
tcfg.test_timeout = int(a)
continue
if o == '-4':
ttype.append('IP4')
continue
if o == '-6':
ttype.append('IP6')
continue
if o == '-n':
nh_address4 = a.split(':', 1)
nh_address4[1] = int(nh_address4[1])
tcfg.nh_address4 = tuple(nh_address4)
continue
if o == '-N':
nh_address6 = a.rsplit(':', 1)
nh_address6[1] = int(nh_address6[1])
tcfg.nh_address6 = tuple(nh_address6)
continue
if o == '-w':
pre_wait = float(a)
continue
if o == '-D':
dry_run = True
continue
if len(ttype) > 0:
tcfg.ttype = tuple(ttype)
tcfg.body = MsgBody(body_txt)
tcfg.body.parse()
sl = SipLogger('alice_ua')
global_config['_sip_logger'] = sl
from .lib.alice_testcore import a_test
if pre_wait != None:
sleep(pre_wait)
acore = a_test(tcfg)
if not dry_run:
ED2.loop()
sys.exit(acore.rval)