Пример #1
0
 def __init__(self, global_config, bodys, portrange, test_timeout):
     global_config['_sip_tm'] = SipTransactionManager(
         global_config, self.recvRequest)
     Timeout(self.timeout, test_timeout, 1)
     self.bodys = bodys
     self.global_config = global_config
     self.portrange = portrange
Пример #2
0
    def __init__(self, tcfg):
        tcfg.global_config['_sip_tm'] = SipTransactionManager(
            tcfg.global_config, self.recvRequest)

        i = 0
        ttype = tcfg.ttype
        if len(ttype) == 1:
            ttype += ttype
        atests = [a_cfg(x) for x in ALL_TESTS * len(ttype)]
        for subtest_cfg in atests:
            subtest_class = subtest_cfg.test_class
            if tcfg.tests != None and subtest_class.cli not in tcfg.tests:
                subtest_cfg.disabled = True
                i += 1
                continue
            subtest_cfg.disabled = False
            cli = subtest_class.cli
            if i >= len(ALL_TESTS):
                atype = ttype[1]
            else:
                atype = ttype[0]
            cli += '_ipv%s' % atype[-1]
            subtest_cfg.tcfg = tcfg.gen_tccfg(atype, self.subtest_done, cli)
            print('tcfg.gen_tccfg(%s, self.subtest_done, %s)' % (atype, cli))
            i += 1
        shuffle(atests)
        for subtest_cfg in atests:
            if subtest_cfg.disabled:
                continue
            subtest = subtest_cfg.test_class(subtest_cfg.tcfg)
            self.nsubtests_running += 1
        self.rval = self.nsubtests_running
        Timeout(self.timeout, tcfg.test_timeout, 1)
Пример #3
0
def main_func():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'fl:p:n:L:')
    except getopt.GetoptError:
        print(
            'usage: b2bua.py [-l addr] [-p port] [-n addr] [-f] [-L logfile]')
        sys.exit(1)
    laddr = None
    lport = None
    logfile = '/var/log/sippy.log'
    global_config = {'nh_addr': ['192.168.0.102', 5060]}
    foreground = False
    for o, a in opts:
        if o == '-f':
            foreground = True
            continue
        if o == '-l':
            laddr = a
            continue
        if o == '-p':
            lport = int(a)
            continue
        if o == '-L':
            logfile = a
        if o == '-n':
            if a.startswith('['):
                parts = a.split(']', 1)
                global_config['nh_addr'] = [parts[0] + ']', 5060]
                parts = parts[1].split(':', 1)
            else:
                parts = a.split(':', 1)
                global_config['nh_addr'] = [parts[0], 5060]
            if len(parts) == 2:
                global_config['nh_addr'][1] = int(parts[1])
            continue
    global_config['nh_addr'] = tuple(global_config['nh_addr'])

    if not foreground:
        daemonize(logfile)

    SipConf.my_uaname = 'Sippy B2BUA (Simple)'
    SipConf.allow_formats = (0, 8, 18, 100, 101)
    global_config['_sip_address'] = SipConf.my_address
    global_config['_sip_port'] = SipConf.my_port
    if laddr != None:
        global_config['_sip_address'] = laddr
    if lport != None:
        global_config['_sip_port'] = lport
    global_config['_sip_logger'] = SipLogger('b2bua')

    cmap = CallMap(global_config)

    global_config['_sip_tm'] = SipTransactionManager(global_config,
                                                     cmap.recvRequest)

    reactor.run(installSignalHandlers=True)
Пример #4
0
    def __init__(self, global_config, body, portrange, tests, test_timeout):
        global_config['_sip_tm'] = SipTransactionManager(
            global_config, self.recvRequest)

        for subtest_class in ALL_TESTS * 2:
            if subtest_class.cli not in tests:
                continue
            sdp_body = body.getCopy()
            fillhostport(sdp_body, portrange, subtest_class.atype)
            subtest = subtest_class(global_config, sdp_body, self.subtest_done,
                                    portrange)
            self.nsubtests_running += 1
        self.rval = self.nsubtests_running
        Timeout(self.timeout, test_timeout, 1)
Пример #5
0
 def __init__(self, global_config, authname=None, authpass=None):
     self.global_config = global_config
     self.authname = authname
     self.authpass = authpass
     SipTransactionManager.nworkers_udp = 1
     global_config['_sip_tm'] = SipTransactionManager(
         global_config, self.recvRequest)
     self.body = MsgBody(body_txt)
     self.body.parse()
     proxy, port = global_config['nh_addr']
     aor = SipURL(username=self.cli, host=proxy, port=port)
     caddr = local4remote(proxy)
     cport = global_config['_sip_port']
     contact = SipURL(username=self.cli, host=caddr, port=cport)
     ragent = SipRegistrationAgent(global_config,
                                   aor,
                                   contact,
                                   user=self.authname,
                                   passw=self.authpass)
     ragent.doregister()
Пример #6
0
def main_func():
    global_config = MyConfigParser()
    global_config['digest_auth'] = True
    global_config['start_acct_enable'] = False
    global_config['keepalive_ans'] = 0
    global_config['keepalive_orig'] = 0
    global_config['auth_enable'] = True
    global_config['acct_enable'] = True
    global_config['_pass_headers'] = []
    global_config['_orig_argv'] = sys.argv[:]
    global_config['_orig_cwd'] = os.getcwd()
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], 'fDl:p:d:P:L:s:a:t:T:k:m:A:ur:F:R:h:c:M:HC:W:',
            global_config.get_longopts())
    except getopt.GetoptError:
        usage(global_config)
    global_config['foreground'] = False
    global_config['pidfile'] = '/var/run/b2bua.pid'
    global_config['logfile'] = '/var/log/b2bua.log'
    global_config['b2bua_socket'] = '/var/run/b2bua.sock'
    global_config['_sip_address'] = SipConf.my_address
    global_config['_sip_port'] = SipConf.my_port
    global_config['_my_pid'] = os.getpid()
    rtp_proxy_clients = []
    writeconf = None
    for o, a in opts:
        if o == '-f':
            global_config['foreground'] = True
            continue
        if o == '-l':
            global_config.check_and_set('sip_address', a)
            continue
        if o == '-p':
            global_config.check_and_set('sip_port', a)
            continue
        if o == '-P':
            global_config.check_and_set('pidfile', a)
            continue
        if o == '-L':
            global_config.check_and_set('logfile', a)
            continue
        if o == '-s':
            global_config.check_and_set('static_route', a)
            continue
        if o == '-a':
            global_config.check_and_set('accept_ips', a)
            continue
        if o == '-D':
            global_config['digest_auth'] = False
            continue
        if o == '-A':
            acct_level = int(a.strip())
            if acct_level == 0:
                global_config['acct_enable'] = False
                global_config['start_acct_enable'] = False
            elif acct_level == 1:
                global_config['acct_enable'] = True
                global_config['start_acct_enable'] = False
            elif acct_level == 2:
                global_config['acct_enable'] = True
                global_config['start_acct_enable'] = True
            else:
                sys.__stderr__.write(
                    'ERROR: -A argument not in the range 0-2\n')
                usage(global_config, True)
            continue
        if o == '-t':
            global_config.check_and_set('static_tr_in', a)
            continue
        if o == '-T':
            global_config.check_and_set('static_tr_out', a)
            continue
        if o == '-k':
            ka_level = int(a.strip())
            if ka_level == 0:
                pass
            elif ka_level == 1:
                global_config['keepalive_ans'] = 32
            elif ka_level == 2:
                global_config['keepalive_orig'] = 32
            elif ka_level == 3:
                global_config['keepalive_ans'] = 32
                global_config['keepalive_orig'] = 32
            else:
                sys.__stderr__.write(
                    'ERROR: -k argument not in the range 0-3\n')
                usage(global_config, True)
        if o == '-m':
            global_config.check_and_set('max_credit_time', a)
            continue
        if o == '-u':
            global_config['auth_enable'] = False
            continue
        if o == '-r':
            global_config.check_and_set('rtp_proxy_client', a)
            continue
        if o == '-F':
            global_config.check_and_set('allowed_pts', a)
            continue
        if o == '-R':
            global_config.check_and_set('radiusclient.conf', a)
            continue
        if o == '-h':
            for a in a.split(','):
                global_config.check_and_set('pass_header', a)
            continue
        if o == '-c':
            global_config.check_and_set('b2bua_socket', a)
            continue
        if o == '-M':
            global_config.check_and_set('max_radiusclients', a)
            continue
        if o == '-H':
            global_config['hide_call_id'] = True
            continue
        if o in ('-C', '--config'):
            global_config.read(a.strip())
            continue
        if o.startswith('--'):
            global_config.check_and_set(o[2:], a)
            continue
        if o == '-W':
            writeconf = a.strip()
            continue

    if '_rtp_proxy_clients' in global_config:
        for a in global_config['_rtp_proxy_clients']:
            rtp_proxy_clients.append(a)

    if 'static_route' in global_config:
        global_config['_static_route'] = B2BRoute(
            global_config['static_route'])
    elif not global_config['auth_enable']:
        sys.__stderr__.write(
            'ERROR: static route should be specified when Radius auth is disabled\n'
        )
        usage(global_config, True)

    if writeconf != None:
        global_config.write(open(writeconf, 'w'))

    if not global_config['foreground']:
        daemonize(logfile=global_config['logfile'])

    global_config['_sip_logger'] = SipLogger('b2bua')

    if len(rtp_proxy_clients) > 0:
        global_config['_rtp_proxy_clients'] = []
        for address in rtp_proxy_clients:
            global_config['_rtp_proxy_clients'].append(
                Rtp_proxy_client(global_config, spath=address))

    if global_config['auth_enable'] or global_config['acct_enable']:
        global_config['_radius_client'] = RadiusAuthorisation(global_config)
    global_config['_uaname'] = 'Sippy B2BUA (RADIUS)'

    global_config['_cmap'] = CallMap(global_config)
    if 'sip_proxy' in global_config:
        host_port = global_config['sip_proxy'].split(':', 1)
        if len(host_port) == 1:
            global_config['_sip_proxy'] = (host_port[0], 5060)
        else:
            global_config['_sip_proxy'] = (host_port[0], int(host_port[1]))
        global_config['_cmap'].proxy = StatefulProxy(
            global_config, global_config['_sip_proxy'])

    if global_config.getdefault('xmpp_b2bua_id', None) != None:
        global_config['_xmpp_mode'] = True
    global_config['_sip_tm'] = SipTransactionManager(
        global_config, global_config['_cmap'].recvRequest)
    global_config['_sip_tm'].nat_traversal = global_config.getdefault(
        'nat_traversal', False)

    cmdfile = global_config['b2bua_socket']
    if cmdfile.startswith('unix:'):
        cmdfile = cmdfile[5:]
    cli_server = CLIConnectionManager(global_config['_cmap'].recvCommand,
                                      cmdfile)

    if not global_config['foreground']:
        open(global_config['pidfile'], 'w').write(str(os.getpid()) + '\n')
        Signal(SIGUSR1, reopen, SIGUSR1, global_config['logfile'])

    ED2.loop()
Пример #7
0
 def __init__(self, tcfg):
     tcfg.global_config['_sip_tm'] = SipTransactionManager(
         tcfg.global_config, self.recvRequest)
     Timeout(self.timeout, tcfg.test_timeout, 1)
     self.tcfg = tcfg
Пример #8
0
        os.dup2(fd, sys.__stderr__.fileno())
        os.close(fd)

    global_config['_sip_logger'] = SipLogger('b2bua')

    if len(rtp_proxy_clients) > 0:
        global_config['_rtp_proxy_clients'] = []
        for address in rtp_proxy_clients:
            global_config['_rtp_proxy_clients'].append(
                Rtp_proxy_client(global_config, address))

    if global_config['auth_enable'] or global_config['acct_enable']:
        global_config['_radius_client'] = RadiusAuthorisation(global_config)
    SipConf.my_uaname = 'Sippy B2BUA (RADIUS)'

    global_config['_cmap'] = CallMap(global_config)

    global_config['_sip_tm'] = SipTransactionManager(
        global_config, global_config['_cmap'].recvRequest)

    cmdfile = global_config['b2bua_socket']
    if cmdfile.startswith('unix:'):
        cmdfile = cmdfile[5:]
    cli_server = Cli_server_local(global_config['_cmap'].recvCommand, cmdfile)

    if not global_config['foreground']:
        file(global_config['pidfile'], 'w').write(str(os.getpid()) + '\n')
        Signal(SIGUSR1, reopen, SIGUSR1, global_config['logfile'])

    reactor.run(installSignalHandlers=True)
Пример #9
0
def main_func():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'fl:p:n:L:')
    except getopt.GetoptError:
        print(
            'usage: b2bua.py [-l addr] [-p port] [-n addr] [-f] [-L logfile]')
        sys.exit(1)
    laddr = None
    lport = None
    logfile = '/var/log/sippy.log'
    global_config = {'nh_addr': ['127.0.0.1', 5060]}
    foreground = False
    for o, a in opts:
        if o == '-f':
            foreground = True
            continue
        if o == '-l':
            laddr = a
            continue
        if o == '-p':
            lport = int(a)
            continue
        if o == '-L':
            logfile = a
        if o == '-n':
            if a.startswith('['):
                parts = a.split(']', 1)
                global_config['nh_addr'] = [parts[0] + ']', 5060]
                parts = parts[1].split(':', 1)
            else:
                parts = a.split(':', 1)
                global_config['nh_addr'] = [parts[0], 5060]
            if len(parts) == 2:
                global_config['nh_addr'][1] = int(parts[1])
            continue
    global_config['nh_addr'] = tuple(global_config['nh_addr'])

    if not foreground:
        daemonize(logfile)

    SipConf.my_uaname = 'vos 2.1.10'
    SipConf.allow_formats = (0, 8, 18, 100, 101)
    global_config['_sip_address'] = SipConf.my_address
    global_config['_sip_port'] = SipConf.my_port
    if laddr != None:
        global_config['_sip_address'] = laddr
    if lport != None:
        global_config['_sip_port'] = lport
    global_config['_sip_logger'] = SipLogger('b2bua')
    # global_config['_invite_session'] = FuturesSession(max_workers=200)
    global_config['_request_session'] = FuturesSession(max_workers=200)

    global_config['_sip_logger'].write(global_config['_sip_address'], ":",
                                       global_config['_sip_port'])

    cmap = CallMap(global_config)

    global_config['_sip_tm'] = SipTransactionManager(global_config,
                                                     cmap.recvRequest)

    ED2.loop()