Exemplo n.º 1
0
    def start_new_incoming_event_thread(self, csta_link=None, role=None):
        """ Start a new thread to wait for incoming CSTA events

        :role optional argument that can be used to impose certain checks on incoming messages
            Possible values: 1) Any of "originator", "initiator", "A", "Aside", "caller" or
                             2) Any of "destination", "target", "B", "Bside", "callee"

            If any of the group 1) role is selected the incoming messages will be checked to be in the following order:
              "ServiceInitiatedEvent", "OriginatedEvent", "DeliveredEvent", "EstablishedEvent","ConnectionClearedEvent"

            If any of the group 2) role is selected the incoming messages will be checked to be in the following order:
              "DeliveredEvent", "EstablishedEvent", "ConnectionClearedEvent"

            If no role is selected there will be no checks for incoming csta messages

            TODO: Add support for custom message ordering check
        """
        if not csta_link:
            csta_link = self.csta_links[0]
        self.incoming_event_threads.append(util.serverThread(self.wait_for_csta_events,
                                                             csta_link,
                                                             role))
    NumberOfCallers = 10
    NumberOfAgents = 10
    calls = 1
    secondsPer = 1
    pilot = "77911"
    callers = ["302102310" + "%03d" % i for i in range(NumberOfCallers)]
    agents = ["302118840" + "%03d" % i for i in range(NumberOfAgents)]
    link = ConnectSip(callers, baseLocalPort=6280)
    link.update(ConnectSip(agents, baseLocalPort=6280 + NumberOfCallers))
    try:
        for user in callers + agents:
            Register(user)
            sleep(0.1)

        for agent in agents:
            agentThreads.append(util.serverThread(WaitForCall, user))
            sleep(0.1)

        test = util.Load(flow,
                         util.loop(callers),
                         duration=0,
                         quantity=calls,
                         interval=secondsPer)

    finally:
        for user in userPool:
            Unregister(user)
            link[user] = None
            sleep(0.1)
        print("Unregister done")
        # join all threads
Exemplo n.º 3
0
def flow(users):
    usera = next(users)
    userb = next(users)
    parameters["userA"] = usera
    parameters["userB"] = userb
    serverThreads.append(
        util.serverThread(WaitForCstaEvents, usera, assertLeg="A"))
    serverThreads.append(
        util.serverThread(WaitForCstaEvents, userb, assertLeg="B"))
    parameters["source_port"] = link[usera].port
    Invite = buildMessage(message["Invite_SDP_1"], parameters)
    # print(Invite)
    link[usera].send(Invite.contents())

    inBytes = link[usera].waitForData()
    inmessage = parseBytes(inBytes)
    # print("IN:",inmessage)
    assert inmessage.type == "Response" and inmessage.status == "100 Trying", \
        "Sent:\n{}Received:\n{}".format(Invite, inmessage)

    #    inBytes=linkCsta[usera].waitForData()
    #    cstaevent=parseBytes_csta(inBytes)
    #    assert cstaevent.event=="ServiceInitiated", "Expected:{}  Received:{}".format("ServiceInitiated",str(cstaevent))

    inBytes = link[userb].waitForData()
    inmessageb = parseBytes(inBytes)
    # print("IN:",inmessageb)
    assert inmessageb.type == "Request" and inmessageb.method == "INVITE", \
        "A side sent:\n{}and got Trying, but B side received:\n{}".format(Invite, inmessage)

    parameters["source_port"] = link[userb].port
    m = buildMessage(message["Trying_1"], parameters)
    for h in ("To", "From", "CSeq", "Via", "Call-ID"):
        m[h] = inmessageb[h]
    # print(m)
    link[userb].send(m.contents())

    parameters["source_port"] = link[userb].port
    Ringing = buildMessage(message["Ringing_1"], parameters)
    for h in ("To", "From", "CSeq", "Via", "Call-ID"):
        Ringing[h] = inmessageb[h]
    toTag = ";tag=" + util.randStr(8)
    Ringing["To"] = Ringing["To"] + toTag
    # print(Ringing)
    link[userb].send(Ringing.contents())

    inBytes = link[usera].waitForData()
    inmessage = parseBytes(inBytes)
    # print("IN:",inmessage)
    assert inmessage.type == "Response" and inmessage.status == "180 Ringing", \
        "B side sent:\n{}but A side received:\n{}".format(Ringing, inmessage)

    parameters["source_port"] = link[userb].port
    m = buildMessage(message["200_OK_SDP_1"], parameters)
    for h in ("To", "From", "CSeq", "Via", "Call-ID"):
        m[h] = Ringing[h]
    m["To"] = m["To"] + toTag
    # print(m)
    link[userb].send(m.contents())

    inBytes = link[userb].waitForData()
    ack = parseBytes(inBytes)
    # print("IN:",ack)
    assert ack.type == "Request" and ack.method == "ACK", \
        "Sent:\n{}Received:\n{}".format(m, ack)

    inBytes = link[usera].waitForData()
    inmessage = parseBytes(inBytes)
    # print("IN:",inmessage)
    assert inmessage.type == "Response" and inmessage.status == "200 OK", \
        "B side got:\n{}but A side received:\n{}".format(ack, inmessage)

    parameters["source_port"] = link[usera].port
    m = buildMessage(message["Ack_1"], parameters)
    for h in ("To", "From", "Call-ID"):
        m[h] = inmessage[h]
    # print(m)
    link[usera].send(m.contents())

    sleep(talkDuration)

    parameters["source_port"] = link[usera].port
    m = buildMessage(message["Bye_1"], parameters)
    for h in ("To", "From", "Call-ID"):
        m[h] = inmessage[h]
    # print(m)
    link[usera].send(m.contents())

    inBytes = link[usera].waitForData()
    inmessage = parseBytes(inBytes)
    # print("IN:",inmessage)
    assert inmessage.type == "Response" and inmessage.status == "200 OK", \
        "Sent:\n{}Received:\n{}".format(m, inmessage)

    inBytes = link[userb].waitForData()
    Bye = parseBytes(inBytes)
    # print("IN:",Bye)
    assert Bye.type == "Request" and Bye.method == "BYE", \
        "A side sent:\n{}B side received:\n{}".format(m, inmessage)

    parameters["source_port"] = link[userb].port
    m = buildMessage(message["200_OK_1"], parameters)
    for h in ("To", "From", "CSeq", "Via", "Call-ID"):
        m[h] = Bye[h]
    # print(m)
    link[userb].send(m.contents())
    #agents=["302128820"+"%03d" % i for i in range(NumberOfAgents)]

    parameters["dest_ip"] = parameters["dest_ip_orig"]
    link = ConnectSip(callers, baseLocalPort=6280)

    parameters["dest_ip"] = parameters["dest_ip_psap"]
    link.update(ConnectSip(agents, baseLocalPort=6280 + NumberOfCallers))

    try:
        for user in callers + agents:
            Register(user)
            sleep(0.1)

        for agent in agents:
            agentThreads.append(
                util.serverThread(WaitForCall, agent, parameters))
            sleep(0.1)

        test = util.Load(flow,
                         util.loop(callers),
                         pilot,
                         parameters,
                         duration=0,
                         quantity=calls,
                         interval=secondsPer)

    finally:
        for user in callers + agents:
            Unregister(user)
            link[user] = None
            sleep(0.1)
Exemplo n.º 5
0
                      for port in range(13000, 13000 + number_of_users))

    call_taker_ip_pool = (("10.5.45." + str(i), 5566)
                          for i in range(20, 20 + number_of_call_takers))
    agentThreads = []

    try:
        for user, call_taker in zip(users, call_takers):
            setup(user, call_taker, secondary_numbers, user_port_pool,
                  call_taker_ip_pool, 3600)
            sleep(0.5)

        for call_taker, secondary_line in zip(call_takers, secondary_lines):
            call_taker.shutdown = False
            agentThreads.append(
                util.serverThread(wait_for_call, call_taker, secondary_line))
            sleep(0.1)

        test = util.Load(flow,
                         user_pool,
                         secondary_line_pool,
                         duration=5 * 60 * 60,
                         quantity=1,
                         interval=2)
        test.start()
        test.monitor()
    finally:
        for user, call_taker in zip(users, call_takers):
            call_taker.shutdown = True
            tear_down(user, call_taker)
                      range(13000, 13000+number_of_users))

    call_taker_ip_pool = (("10.5.45."+str(i), 5566)
                          for i in
                          range(20, 20+number_of_call_takers))
    agentThreads = []

    try:
        for user, call_taker in zip(users, call_takers):
            connect(user, call_taker, user_port_pool, call_taker_ip_pool)


        register(users, call_takers, secondary_numbers, expiration=360)
        for call_taker, secondary_line in zip(call_takers, secondary_lines):
            call_taker.shutdown = False
            agentThreads.append(util.serverThread(wait_for_call, call_taker, secondary_line))
            sleep(0.1)

        test = util.Load(flow,
                         user_pool,
                         secondary_line_pool,
                         duration=-1,
                         quantity=1,
                         interval=2)
        test.start()
        test.monitor()
    finally:
        for user, call_taker in zip(users, call_takers):
            call_taker.shutdown = True
            tear_down(user, call_taker)