Beispiel #1
0
    def rtpp_reply_l(self, rval, sdata):
        #print 'rtpp_reply', sdata
        if rval == 'E71':
            print 'bingo 2'
            Timeout(self.issue_command_l, 2 * random(), 1, sdata)
            return
        if rval == None or rval.startswith('E'):
            print ('rtpp_reply_l: error: %s, original command: %s' % \
              (str(rval), sdata.command_l))
            reactor.stop()
            return

        if random() > 0.5:
            # let 50% of the sessions timeout, disconnect the rest after
            # 8.5-58.5 seconds explicitly
            tout = 8.5 + (50.0 * random())
            if random() > 0.5:
                Timeout(self.issue_command_d, tout, 1, sdata.command_d_b1)
            else:
                Timeout(self.issue_command_d, tout, 1, sdata.command_d_b2)
        self.rcodes.append(rval)
        self.rremain -= 1
        if self.rremain == 0:
            reactor.stop()
        self.issue_command()
Beispiel #2
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
Beispiel #3
0
 def __init__(self, global_config):
     self.global_config = global_config
     self.ccmap = []
     self.el = Timeout(self.GClector, 60, -1)
     Signal(SIGHUP, self.discAll, SIGHUP)
     Signal(SIGUSR2, self.toggleDebug, SIGUSR2)
     Signal(SIGPROF, self.safeRestart, SIGPROF)
Beispiel #4
0
 def placeOriginate(self, oroute):
     cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData()
     cld = oroute.cld
     self.huntstop_scodes = oroute.params.get('huntstop_scodes', ())
     if self.global_config.has_key('static_tr_out'):
         cld = re_replace(self.global_config['static_tr_out'], cld)
     if oroute.hostport == 'sip-ua':
         host = self.source[0]
         nh_address, same_af = self.source, True
     else:
         host = oroute.hostonly
         nh_address, same_af = oroute.getNHAddr(self.source)
     if not oroute.forward_on_fail and self.global_config['acct_enable']:
         self.acctO = RadiusAccounting(self.global_config, 'originate', \
           send_start = self.global_config['start_acct_enable'], lperiod = \
           self.global_config.getdefault('alive_acct_int', None))
         self.acctO.ms_precision = self.global_config.getdefault(
             'precise_acct', False)
         self.acctO.setParams(oroute.params.get('bill-to', self.username), oroute.params.get('bill-cli', oroute.cli), \
           oroute.params.get('bill-cld', cld), self.cGUID, self.cId, host)
     else:
         self.acctO = None
     self.acctA.credit_time = oroute.credit_time
     conn_handlers = [self.oConn]
     disc_handlers = []
     if not oroute.forward_on_fail and self.global_config['acct_enable']:
         disc_handlers.append(self.acctO.disc)
     self.uaO = UA(self.global_config, self.recvEvent, oroute.user, oroute.passw, nh_address, oroute.credit_time, tuple(conn_handlers), \
       tuple(disc_handlers), tuple(disc_handlers), dead_cbs = (self.oDead,), expire_time = oroute.expires, \
       no_progress_time = oroute.no_progress_expires, extra_headers = oroute.extra_headers)
     self.uaO.local_ua = self.global_config['_uaname']
     if self.source != oroute.params.get('outbound_proxy', None):
         self.uaO.outbound_proxy = oroute.params.get('outbound_proxy', None)
     if self.rtp_proxy_session != None and oroute.params.get('rtpp', True):
         self.uaO.on_local_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
         self.uaO.on_remote_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
         self.rtp_proxy_session.caller.raddress = nh_address
         if body != None:
             body = body.getCopy()
         self.proxied = True
     self.uaO.kaInterval = self.global_config['keepalive_orig']
     if oroute.params.has_key('group_timeout'):
         timeout, skipto = oroute.params['group_timeout']
         Timeout(self.group_expires, timeout, 1, skipto)
     if self.global_config.getdefault('hide_call_id', False):
         cId = SipCallId(
             md5(str(cId)).hexdigest() + ('-b2b_%d' % oroute.rnum))
     else:
         cId += '-b2b_%d' % oroute.rnum
     event = CCEventTry((cId, cGUID, oroute.cli, cld, body, auth, \
       oroute.params.get('caller_name', self.caller_name)))
     if self.eTry.max_forwards != None:
         event.max_forwards = self.eTry.max_forwards - 1
         if event.max_forwards <= 0:
             self.uaA.recvEvent(CCEventFail((483, 'Too Many Hops')))
             self.state = CCStateDead
             return
     event.reason = self.eTry.reason
     self.uaO.recvEvent(event)
Beispiel #5
0
 def connect(self, ua):
     #if random() > 0.3:
     #    ua.recvEvent(CCEventFail((666, 'Random Failure')))
     #    return
     event = CCEventConnect((200, 'OK', self.body), origin='switch')
     Timeout(self.disconnect, self.disconnect_ival, 1, ua)
     ua.recvEvent(event)
     self.connect_done = True
Beispiel #6
0
    def rtpp_reply_u(self, rval, sdata):
        #print 'rtpp_reply'
        if rval == 'E72':
            print 'bingo 1'
            Timeout(self.issue_command, 3 * random())
            return
        if rval == None or rval.startswith('E'):
            print ('rtpp_reply_u: error: %s, original command: %s' % \
              (str(rval), sdata.command_u))
            reactor.stop()
            return

        self.rcodes.append(rval)

        if random() < 0.1:
             Timeout(self.issue_command_d, 10 * random(), 1, sdata.command_d_c)
             self.issue_command()
        else:
             self.issue_command_l(sdata)
Beispiel #7
0
 def __init__(self, name, global_config, address, cmd_out_address):
     self.call_id_map = []
     self.call_id_map_old = []
     self.name = name
     self.global_config = global_config
     self.asess_filtered = rc_filter(0.9)
     self.cmd_out_address = cmd_out_address
     if cmd_out_address != None:
         bind_address = (cmd_out_address, 0)
     else:
         bind_address = None
     Rtp_proxy_client.__init__(self, global_config, address, bind_address = bind_address)
     self.timer = Timeout(self.call_id_map_aging, 600, -1)
Beispiel #8
0
    def rtpp_reply_u(self, rval, sdata):
        #print 'rtpp_reply'
        if rval == 'E72':
            print 'bingo 1'
            Timeout(self.issue_command, 3 * random())
            return
        if rval == None or rval.startswith('E'):
            print('error: %s' % str(rval))
            reactor.stop()
            return

        self.rcodes.append(rval)
        self.issue_command_l(sdata)
Beispiel #9
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)
Beispiel #10
0
 def answer(self, global_config, body, req, sip_t):
     in_body = req.getBody()
     in_body.parse()
     if not checkhostport(in_body, self.portrange, self.atype):
         self.nerrs += 1
         raise ValueError('Bob(%s): hostport validation has failed' %
                          str(self.__class__))
     # New dialog
     uaA = UA(global_config, self.recvEvent, disc_cbs = (self.disconnected,), \
       fail_cbs = (self.disconnected,), dead_cbs = (self.alldone,))
     uaA.godead_timeout = 10
     uaA.compact_sip = self.compact_sip
     Timeout(self.ring, self.ring_ival, 1, uaA)
     self.body = body
     return uaA.recvRequest(req, sip_t)
Beispiel #11
0
    def rtpp_reply_l(self, rval, sdata):
        #print 'rtpp_reply'
        if rval == 'E71':
            print 'bingo 2'
            Timeout(self.issue_command_l, 2 * random(), 1, sdata)
            return
        if rval == None or rval.startswith('E'):
            print('error: %s' % str(rval))
            reactor.stop()
            return

        self.rcodes.append(rval)
        self.rremain -= 1
        if self.rremain == 0:
            reactor.stop()
        self.issue_command()
Beispiel #12
0
 def __init__(self, global_config, name, address = '/var/run/rtpproxy.sock', dry_run = False):
     self.active = []
     self.pending = []
     self.l1rcache = {}
     self.l2rcache = {}
     if len(address) == 2:
         if not dry_run:
             uopts = Udp_server_opts(address, self.up_command_udp)
             self.ccm = Udp_server(global_config, uopts)
     else:
         sown = global_config.get('_rtpc_sockowner', None)
         if not dry_run:
             self.ccm = Cli_server_local(self.up_command, address, sown)
             self.ccm.protocol.expect_lf = False
     self.global_config = global_config
     self.name = name
     self.address = address
     self.commands_inflight = []
     self.cache_purge_el = Timeout(self.rCachePurge, 10, -1)
            continue
        if o == '-S':
            sippy_path = a.strip()
            continue
        if o == '-o':
            fname = a.strip()
            if fname == '-':
                file_out = sys.stdout
            else:
                file_out = file(fname, 'w')
        if o == '-t':
            timeout = float(a.strip())
            continue

    if sippy_path != None:
        sys.path.insert(0, sippy_path)

    from sippy.Cli_server_local import Cli_server_local
    from sippy.Cli_server_tcp import Cli_server_tcp
    from sippy.Timeout import Timeout

    ch = cli_handler(file_out)
    if stype == 'unix':
        cs = Cli_server_local(ch.command_received, spath)
    else:
        cs = Cli_server_tcp(ch.command_received, spath)
    if timeout != None:
        Timeout(ch.done, timeout)
    reactor.run(installSignalHandlers=1)
    sys.exit(ch.rval)
Beispiel #14
0
 def placeOriginate(self, args):
     cId, cGUID, cli, cld, body, auth, caller_name = self.eTry.getData()
     rnum, host, cld, credit_time, expires, no_progress_expires, forward_on_fail, user, passw, cli, \
       parameters = args
     self.huntstop_scodes = parameters.get('huntstop_scodes', ())
     if self.global_config.has_key('static_tr_out'):
         cld = re_replace(self.global_config['static_tr_out'], cld)
     if host == 'sip-ua':
         host = self.source[0]
         port = self.source[1]
     else:
         if host.startswith('['):
             # IPv6
             host = host.split(']', 1)
             port = host[1].split(':', 1)
             host = host[0] + ']'
             if len(port) > 1:
                 port = int(port[1])
             else:
                 port = SipConf.default_port
         else:
             # IPv4
             host = host.split(':', 1)
             if len(host) > 1:
                 port = int(host[1])
             else:
                 port = SipConf.default_port
             host = host[0]
     if not forward_on_fail and self.global_config['acct_enable']:
         self.acctO = RadiusAccounting(self.global_config, 'originate', \
           send_start = self.global_config['start_acct_enable'], lperiod = \
           self.global_config.getdefault('alive_acct_int', None))
         self.acctO.ms_precision = self.global_config.getdefault('precise_acct', False)
         self.acctO.setParams(parameters.get('bill-to', self.username), parameters.get('bill-cli', cli), \
           parameters.get('bill-cld', cld), self.cGUID, self.cId, host)
     else:
         self.acctO = None
     self.acctA.credit_time = credit_time
     conn_handlers = [self.oConn]
     disc_handlers = []
     if not forward_on_fail and self.global_config['acct_enable']:
         disc_handlers.append(self.acctO.disc)
     self.uaO = UA(self.global_config, self.recvEvent, user, passw, (host, port), credit_time, tuple(conn_handlers), \
       tuple(disc_handlers), tuple(disc_handlers), dead_cbs = (self.oDead,), expire_time = expires, \
       no_progress_time = no_progress_expires, extra_headers = parameters.get('extra_headers', None))
     if self.source != parameters.get('outbound_proxy', None):
         self.uaO.outbound_proxy = parameters.get('outbound_proxy', None)
     if self.rtp_proxy_session != None and parameters.get('rtpp', True):
         self.uaO.on_local_sdp_change = self.rtp_proxy_session.on_caller_sdp_change
         self.uaO.on_remote_sdp_change = self.rtp_proxy_session.on_callee_sdp_change
         self.rtp_proxy_session.caller_raddress = (host, port)
         if body != None:
             body = body.getCopy()
             body.content += 'a=nortpproxy:yes\r\n'
         self.proxied = True
     self.uaO.kaInterval = self.global_config['keepalive_orig']
     if parameters.has_key('group_timeout'):
         timeout, skipto = parameters['group_timeout']
         Timeout(self.group_expires, timeout, 1, skipto)
     if self.global_config.getdefault('hide_call_id', False):
         cId = SipCallId(md5(str(cId)).hexdigest() + ('-b2b_%d' % rnum))
     else:
         cId += '-b2b_%d' % rnum
     event = CCEventTry((cId, cGUID, cli, cld, body, auth, \
       parameters.get('caller_name', self.caller_name)))
     event.reason = self.eTry.reason
     self.uaO.recvEvent(event)
Beispiel #15
0
 def connected(self, ua, rtime, origin):
     Timeout(self.disconnect, self.disconnect_ival, 1, ua)
     self.connect_done = True
Beispiel #16
0
 def ring(self, ua):
     event = CCEventRing((180, 'Ringing', None), origin='switch')
     Timeout(self.connect, self.answer_ival, 1, ua)
     ua.recvEvent(event)
     self.ring_done = True
Beispiel #17
0
 def __init__(self, name, *args, **kwargs):
     self.call_id_map = []
     self.call_id_map_old = []
     self.name = name
     Rtp_proxy_client.__init__(self, *args, **kwargs)
     self.timer = Timeout(self.call_id_map_aging, 600, -1)
Beispiel #18
0
 def ring(self, ua):
     event = CCEventRing((183, 'Session Progress', self.body), \
       origin = 'switch')
     Timeout(self.connect, self.answer_ival, 1, ua)
     ua.recvEvent(event)
     self.ring_done = True