예제 #1
0
def ConnectCsta(user_range, localIP=util.getLocalIP()):
    " Open the connections for the users "
    connection_pool = {}
    # We set 0 port to connect to any available port
    for user in user_range:
        C = TCPClient(localIP, 0)
        C.connect(parameters["dest_ip_csta"], 1040)

        inBytes = C.waitForData()
        req = parseBytes_csta(inBytes)

        resp = buildMessageFromFile(getxml("SystemStatusResponse.xml"),
                                    parameters,
                                    eventid=req.eventid)
        C.send(resp.contents())

        reg = buildMessageFromFile(getxml("SystemRegister.xml"),
                                   parameters,
                                   eventid=0)
        C.send(reg.contents())

        inBytes = C.waitForData()
        reg_resp = parseBytes_csta(inBytes)

        connection_pool[user] = C
    return connection_pool
예제 #2
0
    def csta_connect(self, local_address, destination_address, protocol="tcp"):
        """ Connect to CSTA Server """
        if not "source_ip" in self.parameters:
            #raise Exception("Must connect SIP first")
            local_ip, local_port = local_address
            self.ip = local_ip
            self.port = local_port
            self.parameters["source_ip"] = local_ip
            self.parameters["source_port"] = local_port
            self.parameters["transport"] = protocol
        else:
            local_ip = self.parameters["source_ip"]
            local_port = 0
        dest_ip, dest_port = destination_address
        # Only TCP implemented
        # 0 means bind to any available local port
        csta_link = TCPClient(local_ip, local_port)
        self.csta_links.append(csta_link)
        csta_link.connect(dest_ip, dest_port)

        inBytes = csta_link.waitForData()
        req = parseBytes_csta(inBytes)

        resp = buildMessageFromFile(get_xml("SystemStatusResponse.xml"), self.parameters, eventid=req.eventid)
        csta_link.send(resp.contents())

        reg = buildMessageFromFile(get_xml("SystemRegister.xml"), self.parameters, eventid=0)
        csta_link.send(reg.contents())

        inBytes = csta_link.waitForData()
        reg_resp = parseBytes_csta(inBytes)
        assert reg_resp.event == "SystemRegisterResponse", 'Tried to start a new dialog with a SIP Response'
        return csta_link
예제 #3
0
def WaitForCstaEvents(user, assertLeg=None):
    "Waits for CSTA messages until the CSTA link is not valid"

    if assertLeg in ("originator", "initiator", "A", "Aside", "caller"):
        assertMessageQueue = [
            "ServiceInitiatedEvent", "OriginatedEvent", "DeliveredEvent",
            "EstablishedEvent", "ConnectionClearedEvent"
        ]
    elif assertLeg in ("destination", "target", "B", "Bside", "callee"):
        assertMessageQueue = [
            "DeliveredEvent", "EstablishedEvent", "ConnectionClearedEvent"
        ]
    else:
        assertMessageQueue = []

    L = linkCsta[user]
    while L:
        try:
            inBytes = L.waitForCstaData()
            inmessage = parseBytes_csta(inBytes)
            if assertMessageQueue:
                expectedEvent = assertMessageQueue.pop(0)
                assert inmessage.event == expectedEvent, \
                    "User {} expected {} but got {}".format(user, expectedEvent, inmessage.event)
            # print("User:{} received {}".format(user,inmessage))
        except timeout:
            pass
        finally:
            L = linkCsta[user]
예제 #4
0
 def wait_for_csta_message(self, message_type, ignore_messages=(), new_dialog=False, timeout=5.0):
     """
     Wait for CSTA message
     :param message_type: The message to wait for
     :param ignore_messages: Messages to ignore
     :param new_dialog: If False, the incoming session ID must be the same as the one of the message we last sent (same dialog)
     :param timeout: Defined timeout in seconds.
     :return: the CstaMessage received
     """
     inmessage = None
     while not inmessage or inmessage.event in ignore_messages:
         in_bytes = self.csta_links[0].waitForCstaData(timeout=timeout)
         inmessage = parseBytes_csta(in_bytes)
     assert inmessage.event == message_type, \
         '{}: Got "{}" while expecting "{}"'.format(self.number, inmessage.event, message_type)
     if inmessage.eventid != 9999 and not new_dialog:
         assert inmessage.eventid == self.eventid, \
             '{}: Wrong event id received: {} \n' \
             'Event id expected: {}\n' \
             'Last message sent: \n{}' \
             '\nMessage received:\n{}\n'.format(self.number,
                                                inmessage.eventid,
                                                self.eventid,
                                                self.last_sent_csta_message,
                                                inmessage)
         self.update_call_parameters(inmessage)
     return inmessage
예제 #5
0
    def wait_for_csta_events(self, csta_link, assert_leg=None):
        """ Waits for CSTA messages until the CSTA link is not valid """
        if not csta_link:
            csta_link = self.csta_links[0]
        if assert_leg in ("originator", "initiator", "A", "Aside", "caller"):
            assert_message_queue = ["ServiceInitiatedEvent", "OriginatedEvent", "DeliveredEvent", "EstablishedEvent",
                                    "ConnectionClearedEvent"]
        elif assert_leg in ("destination", "target", "B", "Bside", "callee"):
            assert_message_queue = ["DeliveredEvent", "EstablishedEvent", "ConnectionClearedEvent"]
        else:
            assert_message_queue = []

        # reset_queue = assert_message_queue[:]

        while self.csta_links:
            # Close and unset csta_link to stop the thread
            try:
                in_bytes = csta_link.waitForCstaData(timeout=1.0)
                inmessage = parseBytes_csta(in_bytes)
                # if assert_leg and not assert_message_queue:
                    # Reset queue in case it needs to be reused
                    # assert_message_queue = reset_queue[:]
                if assert_message_queue:
                    expected_event = assert_message_queue.pop(0)
                    assert inmessage.event == expected_event, \
                        "User {} expected {} but got {}".format(self.parameters["user"], expected_event,
                                                                inmessage.event)
                # print("User:{} received {}".format(user,inmessage))
            except timeout:
                pass
예제 #6
0
 def monitor_start(self):
     """ Connect a CSTA client link, send MonitorStart """
     csta_link = self.csta_links[0]
     m = buildMessageFromFile(get_xml("MonitorStart.xml"), self.parameters, eventid=1)
     csta_link.send(m.contents())
     in_bytes = csta_link.waitForData()
     inmessage = parseBytes_csta(in_bytes)
     assert inmessage.event == "MonitorStartResponse", "Sent:{}  Received:{}".format(m.event, str(inmessage))
예제 #7
0
def MonitorStart(user):
    parameters["user"] = user
    L = linkCsta[user]
    parameters["source_port"] = L.port
    m = buildMessageFromFile(getxml("MonitorStart.xml"), parameters, eventid=1)
    L.send(m.contents())
    inBytes = L.waitForData()
    inmessage = parseBytes_csta(inBytes)
    assert inmessage.event == "MonitorStartResponse", "Sent:{}  Received:{}".format(
        m.event, str(inmessage))