diff --git a/test/common.py b/test/common.py index 84662b8..928914f 100644 --- a/test/common.py +++ b/test/common.py @@ -1,216 +1,215 @@ # Copyright (C) 2008 AG Projects # -import sys -sys.path.append(".") -sys.path.append("..") +import sys; sys.path.extend(['.', '..']) import os import random import string import struct import mediaproxy from application.configuration import * from application.process import process from application.system import host from twisted.internet import reactor from twisted.internet.defer import Deferred, DeferredList, succeed from twisted.internet.protocol import DatagramProtocol, ClientFactory from twisted.internet.task import LoopingCall from twisted.protocols.basic import LineOnlyReceiver from mediaproxy.headers import EncodingDict process.configuration.user_directory = None process.configuration.subdirectory = mediaproxy.mediaproxy_subdirectory class Config(ConfigSection): __cfgfile__ = mediaproxy.configuration_file __section__ = 'Dispatcher' - socket = "/run/mediaproxy/dispatcher.sock" + socket = '/run/mediaproxy/dispatcher.sock' random_data = os.urandom(512) -stun_data = struct.pack("!HHIIII", 0x0001, 0, 0x2112A442, 0, 0, 0) +stun_data = struct.pack('!HHIIII', 0x0001, 0, 0x2112A442, 0, 0, 0) default_host_ip = host.default_ip class OpenSIPSControlClientProtocol(LineOnlyReceiver): def __init__(self): self.defer = None def lineReceived(self, line): - if line == "error": - print "got error from dispatcher!" + if line == 'error': + print('got error from dispatcher!') reactor.stop() elif self.defer is not None: - print "got ip/ports from dispatcher: %s" % line - ip, ports = line.split(" ", 1) + print('got ip/ports from dispatcher: %s' % line) + ip, ports = line.split(' ', 1) defer = self.defer self.defer = None defer.callback((ip, [int(i) for i in ports.split()])) else: - print "got reply from dispatcher: %s" % line + print('got reply from dispatcher: %s' % line) defer = self.defer self.defer = None defer.callback(line) def _send_command(self, command, headers): self.defer = Deferred() data = self.delimiter.join([command] + ['%s: %s' % item for item in headers.iteritems()]) + 2*self.delimiter - # print("writing on socket:\n%s" % data) + # print('writing on socket:\n%s' % data) self.transport.write(data) return self.defer def update(self, **kw_args): - return self._send_command("update", EncodingDict(kw_args)) + return self._send_command('update', EncodingDict(kw_args)) def remove(self, **kw_args): - return self._send_command("remove", EncodingDict(kw_args)) + return self._send_command('remove', EncodingDict(kw_args)) class OpenSIPSConnectorFactory(ClientFactory): protocol = OpenSIPSControlClientProtocol def __init__(self): self.defer = Deferred() def buildProtocol(self, addr): prot = ClientFactory.buildProtocol(self, addr) reactor.callLater(0, self.defer.callback, prot) return prot class MediaReceiverProtocol(DatagramProtocol): def __init__(self, endpoint, index): self.endpoint = endpoint self.index = index self.loop = None self.received_media = False self.defer = Deferred() def datagramReceived(self, data, (host, port)): if not self.received_media: self.received_media = True - print "received media %d for %s from %s:%d" % (self.index, self.endpoint.name, host, port) + print('received media %d for %s from %s:%d' % (self.index, self.endpoint.name, host, port)) self.defer.callback(None) def connectionRefused(self): - print "connection refused for media %d for %s" % (self.index, self.endpoint.name) + print('connection refused for media %d for %s' % (self.index, self.endpoint.name)) class Endpoint(object): def __init__(self, sip_uri, user_agent, is_caller): if is_caller: - self.name = "caller" + self.name = 'caller' else: - self.name = "callee" + self.name = 'callee' self.sip_uri = sip_uri self.user_agent = user_agent - self.tag = "".join(random.sample(string.ascii_lowercase, 8)) + self.tag = ''.join(random.sample(string.ascii_lowercase, 8)) self.connectors = [] self.media = [] self.cseq = 1 def set_media(self, media): assert(len(self.connectors) == 0) self.media = media for index, (media_type, port, direction, parameters) in enumerate(self.media): if port != 0: protocol = MediaReceiverProtocol(self, index) connector = reactor.listenUDP(port, protocol) else: connector = None self.connectors.append(connector) return DeferredList([connector.protocol.defer for connector in self.connectors if connector is not None]) def get_media(self, use_old_hold): if use_old_hold: - ip = "0.0.0.0" + ip = '0.0.0.0' else: ip = default_host_ip return [(media_type, ip, port, direction, parameters) for media_type, port, direction, parameters in self.media] def start_media(self, ip, ports, send_stun=False): for port, connector in zip(ports, self.connectors): if connector is not None: protocol = connector.protocol if port != 0: protocol.transport.connect(ip, port) protocol.loop = LoopingCall(protocol.transport.write, send_stun and stun_data or random_data) protocol.loop.start(random.uniform(0.5, 1)) else: protocol.defer.callback(None) def stop_media(self): defers = [] for connector in self.connectors: if connector is not None: if connector.protocol.loop is not None: connector.protocol.loop.stop() connector.protocol.loop = None defer = connector.stopListening() if defer is not None: defers.append(defer) self.connectors = [] if defers: return DeferredList(defers) else: return succeed(None) class Session(object): def __init__(self, caller, callee): self.caller = caller self.callee = callee - self.call_id = "".join(random.sample(string.ascii_letters, 24)) + self.call_id = ''.join(random.sample(string.ascii_letters, 24)) def _get_parties(self, party): party = getattr(self, party) if party is self.caller: other = self.callee else: other = self.caller return party, other def do_update(self, opensips, party, type, is_final, use_old_hold=False): party, other = self._get_parties(party) - if type == "request": + if type == 'request': from_tag = party.tag to_tag = other.tag from_uri = party.sip_uri to_uri = other.sip_uri cseq = party.cseq else: from_tag = other.tag to_tag = party.tag from_uri = other.sip_uri to_uri = party.sip_uri cseq = other.cseq if is_final: defer = opensips.update(call_id=self.call_id, from_tag=from_tag, to_tag=to_tag, from_uri=from_uri, to_uri=to_uri, cseq=cseq, user_agent=party.user_agent, media=party.get_media(use_old_hold), type=type, dialog_id='1234567890') else: defer = opensips.update(call_id=self.call_id, from_tag=from_tag, to_tag=to_tag, from_uri=from_uri, to_uri=to_uri, cseq=cseq, user_agent=party.user_agent, media=party.get_media(use_old_hold), type=type, dialog_id='1234567890') if is_final: - if type == "request": + if type == 'request': party.cseq += 1 else: other.cseq += 1 return defer def do_remove(self, opensips, party): party, other = self._get_parties(party) - opensips.remove(call_id = self.call_id, from_tag = party.tag, to_tag = other.tag) + opensips.remove(call_id=self.call_id, from_tag=party.tag, to_tag=other.tag) + def connect_to_dispatcher(): factory = OpenSIPSConnectorFactory() connector = reactor.connectUNIX(Config.socket, factory) return connector, factory.defer diff --git a/test/holdtest1.py b/test/holdtest1.py index 49b234c..407a356 100644 --- a/test/holdtest1.py +++ b/test/holdtest1.py @@ -1,111 +1,126 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a session that starts with 1 audio stream, then gets put on hold by the caller for 5 minutes, the gets taken out of hold again. This -test uses the newer "sendonly" direction attribute to indicate hold status. +test uses the newer 'sendonly' direction attribute to indicate hold status. """ from common import * + def phase1(protocol, session): - print "setting up audio stream" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {})]) + print('setting up audio stream') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) defer = succeed(None) defer.addCallback(caller_update, protocol, session, media_defer, phase2) return defer + def phase2(result, protocol, session): - print "setting stream on hold" - session.caller.set_media([("audio", 40000, "sendonly", {})]) - session.callee.set_media([("audio", 50000, "recvonly", {})]) - defer = session.do_update(protocol, "caller", "request", False) + print('setting stream on hold') + session.caller.set_media([('audio', 40000, 'sendonly', {})]) + session.callee.set_media([('audio', 50000, 'recvonly', {})]) + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update_hold, protocol, session) return defer + def callee_update_hold(result, protocol, session): - print "updating hold for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('updating hold for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(wait_hold, protocol, session) return defer + def wait_hold(result, protocol, session): - print "on hold, waiting 5 minutes..." + print('on hold, waiting 5 minutes...') defer = Deferred() defer.addCallback(stop_media_hold, protocol, session) reactor.callLater(300, defer.callback, None) return defer + def stop_media_hold(result, protocol, session): - print "stopping media for hold" + print('stopping media for hold') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(phase3, protocol, session) return defer + def phase3(result, protocol, session): - print "continuing audio stream" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {})]) + print('continuing audio stream') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) defer = succeed(None) defer.addCallback(caller_update, protocol, session, media_defer, kthxbye) return defer + def caller_update(result, protocol, session, media_defer, do_after): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, media_defer, do_after) return defer + def callee_update(callee_addr, protocol, session, media_defer, do_after): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, media_defer, do_after) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, media_defer, do_after): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait, protocol, session, do_after) return media_defer + def wait(result, protocol, session, do_after): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session, do_after) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session, do_after): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(do_after, protocol, session) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - callee = Endpoint("Bob ", "Callee UA", False) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + callee = Endpoint('Bob ', 'Callee UA', False) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(phase1, session) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/holdtest2.py b/test/holdtest2.py index 85e6fb3..95038df 100644 --- a/test/holdtest2.py +++ b/test/holdtest2.py @@ -1,111 +1,126 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a session that starts with 1 audio stream, then gets put on hold by the caller for 5 minutes, the gets taken out of hold again. This test uses the older 0.0.0.0 IP address to indicate hold status. """ from common import * + def phase1(protocol, session): - print "setting up audio stream" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {})]) + print('setting up audio stream') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) defer = succeed(None) defer.addCallback(caller_update, protocol, session, media_defer, phase2) return defer + def phase2(result, protocol, session): - print "setting stream on hold" - session.caller.set_media([("audio", 40000, "sendrecv", {})]) - session.callee.set_media([("audio", 50000, "sendrecv", {})]) - defer = session.do_update(protocol, "caller", "request", False, True) + print('setting stream on hold') + session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + session.callee.set_media([('audio', 50000, 'sendrecv', {})]) + defer = session.do_update(protocol, 'caller', 'request', False, True) defer.addCallback(callee_update_hold, protocol, session) return defer + def callee_update_hold(result, protocol, session): - print "updating hold for callee" - defer = session.do_update(protocol, "callee", "reply", True, True) + print('updating hold for callee') + defer = session.do_update(protocol, 'callee', 'reply', True, True) defer.addCallback(wait_hold, protocol, session) return defer + def wait_hold(result, protocol, session): - print "on hold, waiting 5 minutes..." + print('on hold, waiting 5 minutes...') defer = Deferred() defer.addCallback(stop_media_hold, protocol, session) reactor.callLater(300, defer.callback, None) return defer + def stop_media_hold(result, protocol, session): - print "stopping media for hold" + print('stopping media for hold') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(phase3, protocol, session) return defer + def phase3(result, protocol, session): - print "continuing audio stream" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {})]) + print('continuing audio stream') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) defer = succeed(None) defer.addCallback(caller_update, protocol, session, media_defer, kthxbye) return defer + def caller_update(result, protocol, session, media_defer, do_after): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, media_defer, do_after) return defer + def callee_update(callee_addr, protocol, session, media_defer, do_after): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, media_defer, do_after) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, media_defer, do_after): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait, protocol, session, do_after) return media_defer + def wait(result, protocol, session, do_after): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session, do_after) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session, do_after): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(do_after, protocol, session) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - callee = Endpoint("Bob ", "Callee UA", False) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + callee = Endpoint('Bob ', 'Callee UA', False) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(phase1, session) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/holdtest3.py b/test/holdtest3.py index f31a976..0d519c2 100644 --- a/test/holdtest3.py +++ b/test/holdtest3.py @@ -1,91 +1,103 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a session that starts with 1 audio stream, then gets put on hold by the caller and stops without a BYE after 10 seconds. It is meant to test the on hold timeout. """ from common import * + def phase1(protocol, session): - print "setting up audio stream" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {})]) + print('setting up audio stream') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) defer = succeed(None) defer.addCallback(caller_update, protocol, session, media_defer, phase2) return defer + def phase2(result, protocol, session): - print "setting stream on hold" - session.caller.set_media([("audio", 40000, "sendonly", {})]) - session.callee.set_media([("audio", 50000, "recvonly", {})]) - defer = session.do_update(protocol, "caller", "request", False) + print('setting stream on hold') + session.caller.set_media([('audio', 40000, 'sendonly', {})]) + session.callee.set_media([('audio', 50000, 'recvonly', {})]) + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update_hold, protocol, session) return defer + def callee_update_hold(result, protocol, session): - print "updating hold for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('updating hold for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(wait_hold, protocol, session) return defer + def wait_hold(result, protocol, session): - print "on hold, waiting 10 seconds..." + print('on hold, waiting 10 seconds...') defer = Deferred() reactor.callLater(10, defer.callback, None) return defer + def caller_update(result, protocol, session, media_defer, do_after): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, media_defer, do_after) return defer + def callee_update(callee_addr, protocol, session, media_defer, do_after): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, media_defer, do_after) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, media_defer, do_after): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait, protocol, session, do_after) return media_defer + def wait(result, protocol, session, do_after): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session, do_after) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session, do_after): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(do_after, protocol, session) return defer + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - callee = Endpoint("Bob ", "Callee UA", False) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + callee = Endpoint('Bob ', 'Callee UA', False) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(phase1, session) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/icetest1.py b/test/icetest1.py index 2127dce..6110cbf 100644 --- a/test/icetest1.py +++ b/test/icetest1.py @@ -1,85 +1,96 @@ #!/usr/bin/env python # Copyright (C) 2009 AG Projects # """ This test simulates a call flow with ICE where the relay is NOT selected as a candidate: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will send probing STUN requests for a few seconds - Both parties will stop the probes and not send media through the relay - After 4 minutes, the callee will send a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_stun, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_stun((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting STUN probes for both parties" + print('starting STUN probes for both parties') session.caller.start_media(caller_ip, caller_ports, send_stun=True) session.callee.start_media(callee_ip, callee_ports, send_stun=True) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait_stun, session, protocol) return defer + def wait_stun(result, session, protocol): - print "got STUN probes, waiting 3 seconds" + print('got STUN probes, waiting 3 seconds') defer = Deferred() defer.addCallback(stop_stun_caller, session, protocol) reactor.callLater(3, defer.callback, None) return defer + def stop_stun_caller(result, session, protocol): - print "stopping STUN probes for caller" + print('stopping STUN probes for caller') defer = session.caller.stop_media() defer.addCallback(stop_stun_callee, session, protocol) return defer + def stop_stun_callee(result, session, protocol): - print "stopping STUN probes for callee" + print('stopping STUN probes for callee') defer = session.callee.stop_media() defer.addCallback(wait_end, session, protocol) return defer + def wait_end(result, session, protocol): - print "media is flowing via a different path than the relay for 4 minutes" + print('media is flowing via a different path than the relay for 4 minutes') defer = Deferred() defer.addCallback(end, session, protocol) reactor.callLater(240, defer.callback, None) return defer + def end(result, session, protocol): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {"ice":"yes"})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {"ice":"yes"})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {'ice': 'yes'})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {'ice': 'yes'})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/icetest2.py b/test/icetest2.py index 729f069..056ee88 100644 --- a/test/icetest2.py +++ b/test/icetest2.py @@ -1,102 +1,115 @@ #!/usr/bin/env python # Copyright (C) 2009 AG Projects # """ This test simulates a call flow with ICE where the relay is selected as a candidate: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will send probing STUN requests for a few seconds - Both parties will stop the probes and start sending media through the relay (Note that a re-INVITE will be sent, this is due to a limitatin in the test framework) - After 5 seconds, the caller will send a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting STUN probes for both parties" + print('starting STUN probes for both parties') session.caller.start_media(caller_ip, caller_ports, send_stun=True) session.callee.start_media(callee_ip, callee_ports, send_stun=True) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got STUN, waiting 5 seconds" + print('got STUN, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session): - print "stopping STUN probes" + print('stopping STUN probes') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(change_callee, protocol, session) return defer + def change_callee(result, protocol, session): - print "sending new update for callee" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {"ice":"yes"})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {"ice":"yes"})]) + print('sending new update for callee') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {'ice': 'yes'})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {'ice': 'yes'})]) media_defer = DeferredList([caller_media, callee_media]) - defer = session.do_update(protocol, "callee", "request", False) + defer = session.do_update(protocol, 'callee', 'request', False) defer.addCallback(change_caller, protocol, session, media_defer) return defer + def change_caller((caller_ip, caller_ports), protocol, session, media_defer): - print "sending new update for caller" - defer = session.do_update(protocol, "caller", "reply", True) + print('sending new update for caller') + defer = session.do_update(protocol, 'caller', 'reply', True) defer.addCallback(start_new_media, protocol, session, media_defer, caller_ip, caller_ports) return defer + def start_new_media((callee_ip, callee_ports), protocol, session, media_defer, caller_ip, caller_ports): - print "starting media" + print('starting media') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait2, protocol, session) return media_defer + def wait2(result, protocol, session): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {"ice":"yes"})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {"ice":"yes"})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {'ice': 'yes'})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {'ice': 'yes'})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/multitest1.py b/test/multitest1.py index df8d382..a7a9920 100644 --- a/test/multitest1.py +++ b/test/multitest1.py @@ -1,66 +1,74 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a normal call flow: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will start sending media - Media will flow for 5 seconds - The callee will send a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 30 seconds" + print('got media, waiting 30 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(30, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/multitest2.py b/test/multitest2.py index 9f75b18..1ce37f0 100644 --- a/test/multitest2.py +++ b/test/multitest2.py @@ -1,66 +1,74 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a normal call flow: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will start sending media - Media will flow for 5 seconds - The callee will send a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 35 seconds" + print('got media, waiting 35 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(35, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40001, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50001, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40001, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50001, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/multitest3.py b/test/multitest3.py index 778fb7f..75dd3d6 100644 --- a/test/multitest3.py +++ b/test/multitest3.py @@ -1,66 +1,74 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a normal call flow: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will start sending media - Media will flow for 5 seconds - The callee will send a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 25 seconds" + print('got media, waiting 25 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(25, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40002, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50002, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40002, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50002, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/multitest4.py b/test/multitest4.py index d9ceac0..0f19140 100644 --- a/test/multitest4.py +++ b/test/multitest4.py @@ -1,66 +1,74 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a normal call flow: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will start sending media - Media will flow for 5 seconds - The callee will send a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 40 seconds" + print('got media, waiting 40 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(40, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40004, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50004, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40004, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50004, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/setuptest1.py b/test/setuptest1.py index 76a12eb..6239ea3 100644 --- a/test/setuptest1.py +++ b/test/setuptest1.py @@ -1,35 +1,39 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test scenario simulates the caller sending an INVITE, nothing is received in return. The relay should discard the session after a while. """ from common import * + def caller_update(protocol, session): - print "doing update for caller" - return session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + return session.do_update(protocol, 'caller', 'request', False) + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/setuptest2.py b/test/setuptest2.py index cdf09cd..efed2cb 100644 --- a/test/setuptest2.py +++ b/test/setuptest2.py @@ -1,66 +1,74 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a normal call flow: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will start sending media - Media will flow for 5 seconds - The callee will send a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/setuptest3.py b/test/setuptest3.py index 97a77fc..9bba743 100644 --- a/test/setuptest3.py +++ b/test/setuptest3.py @@ -1,66 +1,74 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a normal call flow without a BYE: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will start sending media - Media will flow for 5 seconds - Both parties will stop sending media """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session): - print "stopping media for callee" + print('stopping media for callee') return session.callee.stop_media() + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/setuptest4.py b/test/setuptest4.py index ab4b79d..3b9ab00 100644 --- a/test/setuptest4.py +++ b/test/setuptest4.py @@ -1,76 +1,85 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a normal call flow, with an added ACK confirming the SDP: - The caller sends an INVITE - the callee sends a 200 OK - Both parties will start sending media - the caller sends an ACK with SDP - Media will flow for 5 seconds - The callee will send a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", False) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', False) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(caller_ack, protocol, session, callee_ip, callee_ports) return defer + def caller_ack(result, protocol, session, callee_ip, callee_ports): - print "got media, doing ACK for caller" - defer = session.do_update(protocol, "caller", "request", True) + print('got media, doing ACK for caller') + defer = session.do_update(protocol, 'caller', 'request', True) defer.addCallback(wait, protocol, session, callee_ip, callee_ports) return defer + def wait((callee_ack_ip, callee_ack_ports), protocol, session, callee_ip, callee_ports): - print "waiting 5 seconds" - assert(callee_ack_ip == callee_ip) - assert(callee_ack_ports == callee_ports) + print('waiting 5 seconds') + assert (callee_ack_ip == callee_ip) + assert (callee_ack_ports == callee_ports) defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/setuptest5.py b/test/setuptest5.py index bd9895d..23e6993 100644 --- a/test/setuptest5.py +++ b/test/setuptest5.py @@ -1,66 +1,74 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates call setup where no SDP is sent in the INVITE: - the callee sends a 200 OK - the caller sends a ACK with SDP - Both parties will start sending media - Media will flow for 5 seconds - The callee will send a BYE """ from common import * + def callee_update(protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", False) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', False) defer.addCallback(caller_update, protocol, session, caller_media, callee_media) return defer + def caller_update(caller_addr, protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", True) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', True) defer.addCallback(do_media, caller_addr, protocol, session, caller_media, callee_media) return defer + def do_media((callee_ip, callee_ports), (caller_ip, caller_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(callee_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/setuptest6.py b/test/setuptest6.py index ab2d9da..4676a25 100644 --- a/test/setuptest6.py +++ b/test/setuptest6.py @@ -1,78 +1,88 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a session in which the caller proposes 3 streams in the -INTIVE and the callee rejects two of these. +INVITE and the callee rejects two of these. - The caller sends an INVITE with 1 video stream and 2 audio streams - the callee sends a 200 OK with the ports for two of the streams set to 0 - Both parties start sending media - Media flows for 5 seconds - The callee sends a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(change_caller1, callee_addr, protocol, session, caller_media, callee_media) return defer + def change_caller1(caller_addr, callee_addr, protocol, session, caller_media, callee_media): - print "stopping media for caller" + print('stopping media for caller') defer = session.caller.stop_media() defer.addCallback(change_caller2, caller_addr, callee_addr, protocol, session, callee_media) return defer + def change_caller2(result, caller_addr, callee_addr, protocol, session, callee_media): - print "setting new media for caller" - caller_media = caller.set_media([("audio", 0, "sendrecv", {}), ("video", 0, "sendrecv", {}), ("audio", 40020, "sendrecv", {})]) + print('setting new media for caller') + caller_media = caller.set_media([('audio', 0, 'sendrecv', {}), ('video', 0, 'sendrecv', {}), ('audio', 40020, 'sendrecv', {})]) return do_media(caller_addr, callee_addr, protocol, session, caller_media, callee_media) + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {}), ("video", 40010, "sendrecv", {}), ("audio", 40020, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 0, "sendrecv", {}), ("video", 0, "sendrecv", {}), ("audio", 50020, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {}), ('video', 40010, 'sendrecv', {}), ('audio', 40020, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 0, 'sendrecv', {}), ('video', 0, 'sendrecv', {}), ('audio', 50020, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/setuptest7.py b/test/setuptest7.py index 167005f..c0950ec 100644 --- a/test/setuptest7.py +++ b/test/setuptest7.py @@ -1,64 +1,72 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a normal call flow: - The caller sends an INVITE with a media stream with port=0 - The callee sends a 200 OK - The callee will send a BYE after 5 seconds """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "callee") + print('sending remove') + return session.do_remove(protocol, 'callee') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) caller_media = caller.set_media([('audio', 0, 'sendrecv', {})]) - callee = Endpoint("Bob ", "Callee UA", False) + callee = Endpoint('Bob ', 'Callee UA', False) callee_media = callee.set_media([('audio', 40000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/updatetest1.py b/test/updatetest1.py index 12a0e33..423dbd4 100644 --- a/test/updatetest1.py +++ b/test/updatetest1.py @@ -1,98 +1,110 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a call setup with an updated reply from the callee: - The caller sends an INVITE - The callee replies with .e.g a 183 - Both parties start sending media - Media flows for 5 seconds - Media stops - The callee sends a 200 OK with a new port - Media flows again for 5 seconds - The caller sends a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", False) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', False) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session, callee_ip, callee_ports) return defer + def wait(result, protocol, session, callee_ip, callee_ports): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session, callee_ip, callee_ports) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session, callee_ip, callee_ports): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(change_callee, protocol, session, callee_ip, callee_ports) return defer + def change_callee(result, protocol, session, callee_ip, callee_ports): - print "sending new update for callee" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50020, "sendrecv", {})]) + print('sending new update for callee') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50020, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) - defer = session.do_update(protocol, "callee", "reply", True) + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(start_new_media, protocol, session, media_defer, callee_ip, callee_ports) return defer + def start_new_media((caller_ip, caller_ports), protocol, session, media_defer, callee_ip, callee_ports): - print "starting new media" + print('starting new media') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait2, protocol, session) return media_defer + def wait2(result, protocol, session): - print "got new media, waiting 5 seconds" + print('got new media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/updatetest2.py b/test/updatetest2.py index 70548dc..c354ed3 100644 --- a/test/updatetest2.py +++ b/test/updatetest2.py @@ -1,103 +1,116 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a session with audio and video media flowing, after which the callee removes the video stream and only audio flows: - caller sends INVITE, callee sends 200 ok - audio and video media flows for 5 seconds - callee proposes to keep only the audio stream using a re-INVITE, caller sends OK - audio media flows for 5 seconds - caller sends BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(change_callee, protocol, session) return defer + def change_callee(result, protocol, session): - print "sending new update for callee" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {})]) + print('sending new update for callee') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) - defer = session.do_update(protocol, "callee", "request", False) + defer = session.do_update(protocol, 'callee', 'request', False) defer.addCallback(change_caller, protocol, session, media_defer) return defer + def change_caller((caller_ip, caller_ports), protocol, session, media_defer): - print "sending new update for caller" - defer = session.do_update(protocol, "caller", "reply", True) + print('sending new update for caller') + defer = session.do_update(protocol, 'caller', 'reply', True) defer.addCallback(start_new_media, protocol, session, media_defer, caller_ip, caller_ports) return defer + def start_new_media((callee_ip, callee_ports), protocol, session, media_defer, caller_ip, caller_ports): - print "starting new media" + print('starting new media') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait2, protocol, session) return media_defer + def wait2(result, protocol, session): - print "got new media, waiting 5 seconds" + print('got new media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {}), ("video", 40010, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {}), ("video", 50010, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {}), ('video', 40010, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {}), ('video', 50010, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/updatetest3.py b/test/updatetest3.py index c0f03e2..aaf24fd 100644 --- a/test/updatetest3.py +++ b/test/updatetest3.py @@ -1,92 +1,104 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a session that starts with only video, then two audio streams are added and finally only one of the audio streams remains. """ from common import * + def phase1(protocol, session): - print "setting up 1 video stream" - caller_media = session.caller.set_media([("video", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("video", 50000, "sendrecv", {})]) + print('setting up 1 video stream') + caller_media = session.caller.set_media([('video', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('video', 50000, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) defer = succeed(None) defer.addCallback(caller_update, protocol, session, media_defer, phase2) return defer + def phase2(result, protocol, session): - print "adding 2 audio streams" - caller_media = session.caller.set_media([("video", 40000, "sendrecv", {}), ("audio", 40010, "sendrecv", {}), ("audio", 40020, "sendrecv", {})]) - callee_media = session.callee.set_media([("video", 50000, "sendrecv", {}), ("audio", 50010, "sendrecv", {}), ("audio", 50020, "sendrecv", {})]) + print('adding 2 audio streams') + caller_media = session.caller.set_media([('video', 40000, 'sendrecv', {}), ('audio', 40010, 'sendrecv', {}), ('audio', 40020, 'sendrecv', {})]) + callee_media = session.callee.set_media([('video', 50000, 'sendrecv', {}), ('audio', 50010, 'sendrecv', {}), ('audio', 50020, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) defer = succeed(None) defer.addCallback(caller_update, protocol, session, media_defer, phase3) return defer + def phase3(result, protocol, session): - print "removing 1 video and 1 audio stream" - caller_media = session.caller.set_media([("audio", 40020, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50020, "sendrecv", {})]) + print('removing 1 video and 1 audio stream') + caller_media = session.caller.set_media([('audio', 40020, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50020, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) defer = succeed(None) defer.addCallback(caller_update, protocol, session, media_defer, kthxbye) return defer + def caller_update(result, protocol, session, media_defer, do_after): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, media_defer, do_after) return defer + def callee_update(callee_addr, protocol, session, media_defer, do_after): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, media_defer, do_after) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, media_defer, do_after): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait, protocol, session, do_after) return media_defer + def wait(result, protocol, session, do_after): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session, do_after) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session, do_after): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(do_after, protocol, session) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - callee = Endpoint("Bob ", "Callee UA", False) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + callee = Endpoint('Bob ', 'Callee UA', False) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(phase1, session) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/updatetest4.py b/test/updatetest4.py index 62a9832..07fa848 100644 --- a/test/updatetest4.py +++ b/test/updatetest4.py @@ -1,102 +1,115 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a session with audio media flowing, after which the callee changes the port of the media, e.g. through an UPDATE: - caller sends INVITE, callee sends 200 ok - audio and video media flows for 5 seconds - callee changes the port of the audio stream through an UPATE or re-INVITE - audio media flows for 5 seconds - caller sends BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(change_callee, protocol, session) return defer + def change_callee(result, protocol, session): - print "sending new update for callee" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50010, "sendrecv", {})]) + print('sending new update for callee') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50010, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) - defer = session.do_update(protocol, "callee", "request", False) + defer = session.do_update(protocol, 'callee', 'request', False) defer.addCallback(change_caller, protocol, session, media_defer) return defer + def change_caller((caller_ip, caller_ports), protocol, session, media_defer): - print "sending new update for caller" - defer = session.do_update(protocol, "caller", "reply", True) + print('sending new update for caller') + defer = session.do_update(protocol, 'caller', 'reply', True) defer.addCallback(start_new_media, protocol, session, media_defer, caller_ip, caller_ports) return defer + def start_new_media((callee_ip, callee_ports), protocol, session, media_defer, caller_ip, caller_ports): - print "starting new media" + print('starting new media') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait2, protocol, session) return media_defer + def wait2(result, protocol, session): - print "got new media, waiting 5 seconds" + print('got new media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/updatetest5.py b/test/updatetest5.py index 3bae3ad..c00bb70 100644 --- a/test/updatetest5.py +++ b/test/updatetest5.py @@ -1,132 +1,148 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a call setup with an updated reply from the callee: - The caller sends an INVITE - The callee replies with a provisional response containg SDP e.g. 183 - Both parties start sending media - Media flows for 5 seconds - Media stops - The callee sends another 183 with new port and to-tag (e.g. when the first PSTN gateway failed) - Both parties start sending media - Media flows for 5 seconds - Media stops - The callee sends a 200 OK with a new port - Media flows again for 5 seconds - The caller sends a BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", False) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', False) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session, callee_ip, callee_ports) return defer + def wait(result, protocol, session, callee_ip, callee_ports): - print "got media, waiting 5 seconds" + print('got media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session, callee_ip, callee_ports) reactor.callLater(5, defer.callback, None) return defer + def stop_media(result, protocol, session, callee_ip, callee_ports): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(change_callee_prov, protocol, session, callee_ip, callee_ports) return defer + def change_callee_prov(result, protocol, session, callee_ip, callee_ports): - print "sending new provisional update for callee" - session.callee.tag = "newtotag" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50010, "sendrecv", {})]) + print('sending new provisional update for callee') + session.callee.tag = 'newtotag' + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50010, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) - defer = session.do_update(protocol, "callee", "reply", False) + defer = session.do_update(protocol, 'callee', 'reply', False) defer.addCallback(start_new_media_prov, protocol, session, media_defer, callee_ip, callee_ports) return defer + def start_new_media_prov((caller_ip, caller_ports), protocol, session, media_defer, callee_ip, callee_ports): - print "starting new media" + print('starting new media') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait2, protocol, session, callee_ip, callee_ports) return media_defer + def wait2(result, protocol, session, callee_ip, callee_ports): - print "got new media, waiting 5 seconds" + print('got new media, waiting 5 seconds') defer = Deferred() defer.addCallback(stop_media_prov, protocol, session, callee_ip, callee_ports) reactor.callLater(5, defer.callback, None) return defer + def stop_media_prov(result, protocol, session, callee_ip, callee_ports): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(change_callee, protocol, session, callee_ip, callee_ports) return defer + def change_callee(result, protocol, session, callee_ip, callee_ports): - print "sending new update for callee" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50020, "sendrecv", {})]) + print('sending new update for callee') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50020, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) - defer = session.do_update(protocol, "callee", "reply", True) + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(start_new_media, protocol, session, media_defer, callee_ip, callee_ports) return defer + def start_new_media((caller_ip, caller_ports), protocol, session, media_defer, callee_ip, callee_ports): - print "starting new media" + print('starting new media') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait3, protocol, session) return media_defer + def wait3(result, protocol, session): - print "got new media, waiting 5 seconds" + print('got new media, waiting 5 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(5, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run() diff --git a/test/updatetest6.py b/test/updatetest6.py index ae5b7d2..a090cab 100644 --- a/test/updatetest6.py +++ b/test/updatetest6.py @@ -1,142 +1,160 @@ #!/usr/bin/env python # Copyright (C) 2008 AG Projects # """ This test simulates a session with audio and video media flowing, after which the callee removes the video stream and only audio flows. After a while, the video stream is introduced back and both audio and video flow for a while: - caller sends INVITE, callee sends 200 ok - audio and video media flows for 15 seconds - callee proposes to keep only the audio stream using a re-INVITE, caller sends OK - audio media flows for 15 seconds - callee proposes to reintroduce a video stream using a re-INVITE, caller sends OK - audio and video media flows for 15 seconds - caller sends BYE """ from common import * + def caller_update(protocol, session, caller_media, callee_media): - print "doing update for caller" - defer = session.do_update(protocol, "caller", "request", False) + print('doing update for caller') + defer = session.do_update(protocol, 'caller', 'request', False) defer.addCallback(callee_update, protocol, session, caller_media, callee_media) return defer + def callee_update(callee_addr, protocol, session, caller_media, callee_media): - print "doing update for callee" - defer = session.do_update(protocol, "callee", "reply", True) + print('doing update for callee') + defer = session.do_update(protocol, 'callee', 'reply', True) defer.addCallback(do_media, callee_addr, protocol, session, caller_media, callee_media) return defer + def do_media((caller_ip, caller_ports), (callee_ip, callee_ports), protocol, session, caller_media, callee_media): - print "starting media for both parties" + print('starting media for both parties') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) defer = DeferredList([caller_media, callee_media]) defer.addCallback(wait, protocol, session) return defer + def wait(result, protocol, session): - print "got media, waiting 15 seconds" + print('got media, waiting 15 seconds') defer = Deferred() defer.addCallback(stop_media, protocol, session) reactor.callLater(15, defer.callback, None) return defer + def stop_media(result, protocol, session): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(change_callee, protocol, session) return defer + def change_callee(result, protocol, session): - print "sending new update for callee" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {}), ("video", 0, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {}), ("video", 0, "sendrecv", {})]) + print('sending new update for callee') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {}), ('video', 0, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {}), ('video', 0, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) - defer = session.do_update(protocol, "callee", "request", False) + defer = session.do_update(protocol, 'callee', 'request', False) defer.addCallback(change_caller, protocol, session, media_defer) return defer + def change_caller((caller_ip, caller_ports), protocol, session, media_defer): - print "sending new update for caller" - defer = session.do_update(protocol, "caller", "reply", True) + print('sending new update for caller') + defer = session.do_update(protocol, 'caller', 'reply', True) defer.addCallback(start_new_media, protocol, session, media_defer, caller_ip, caller_ports) return defer + def start_new_media((callee_ip, callee_ports), protocol, session, media_defer, caller_ip, caller_ports): - print "starting new media" + print('starting new media') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait2, protocol, session) return media_defer + def wait2(result, protocol, session): - print "got new media, waiting 15 seconds" + print('got new media, waiting 15 seconds') defer = Deferred() defer.addCallback(stop_media2, protocol, session) reactor.callLater(15, defer.callback, None) return defer + def stop_media2(result, protocol, session): - print "stopping media" + print('stopping media') defer = DeferredList([session.caller.stop_media(), session.callee.stop_media()]) defer.addCallback(change_callee2, protocol, session) return defer + def change_callee2(result, protocol, session): - print "sending new update for callee" - caller_media = session.caller.set_media([("audio", 40000, "sendrecv", {}), ("video", 40010, "sendrecv", {})]) - callee_media = session.callee.set_media([("audio", 50000, "sendrecv", {}), ("video", 50010, "sendrecv", {})]) + print('sending new update for callee') + caller_media = session.caller.set_media([('audio', 40000, 'sendrecv', {}), ('video', 40010, 'sendrecv', {})]) + callee_media = session.callee.set_media([('audio', 50000, 'sendrecv', {}), ('video', 50010, 'sendrecv', {})]) media_defer = DeferredList([caller_media, callee_media]) - defer = session.do_update(protocol, "callee", "request", False) + defer = session.do_update(protocol, 'callee', 'request', False) defer.addCallback(change_caller2, protocol, session, media_defer) return defer + def change_caller2((caller_ip, caller_ports), protocol, session, media_defer): - print "sending new update for caller" - defer = session.do_update(protocol, "caller", "reply", True) + print('sending new update for caller') + defer = session.do_update(protocol, 'caller', 'reply', True) defer.addCallback(start_new_media2, protocol, session, media_defer, caller_ip, caller_ports) return defer + def start_new_media2((callee_ip, callee_ports), protocol, session, media_defer, caller_ip, caller_ports): - print "starting new media" + print('starting new media') session.caller.start_media(caller_ip, caller_ports) session.callee.start_media(callee_ip, callee_ports) media_defer.addCallback(wait3, protocol, session) return media_defer + def wait3(result, protocol, session): - print "got new media, waiting 15 seconds" + print('got new media, waiting 15 seconds') defer = Deferred() defer.addCallback(kthxbye, protocol, session) reactor.callLater(15, defer.callback, None) return defer + def kthxbye(result, protocol, session): - print "sending remove" - return session.do_remove(protocol, "caller") + print('sending remove') + return session.do_remove(protocol, 'caller') + def disconnect(result, connector): - print "disconnecting" + print('disconnecting') connector.disconnect() reactor.callLater(1, reactor.stop) + def catch_all_err(failure): - print failure + print(failure) + -if __name__ == "__main__": - caller = Endpoint("Alice ", "Caller UA", True) - caller_media = caller.set_media([("audio", 40000, "sendrecv", {}), ("video", 40010, "sendrecv", {})]) - callee = Endpoint("Bob ", "Callee UA", False) - callee_media = callee.set_media([("audio", 50000, "sendrecv", {}), ("video", 50010, "sendrecv", {})]) +if __name__ == '__main__': + caller = Endpoint('Alice ', 'Caller UA', True) + caller_media = caller.set_media([('audio', 40000, 'sendrecv', {}), ('video', 40010, 'sendrecv', {})]) + callee = Endpoint('Bob ', 'Callee UA', False) + callee_media = callee.set_media([('audio', 50000, 'sendrecv', {}), ('video', 50010, 'sendrecv', {})]) session = Session(caller, callee) connector, defer = connect_to_dispatcher() defer.addCallback(caller_update, session, caller_media, callee_media) defer.addCallback(disconnect, connector) defer.addErrback(catch_all_err) reactor.run()