Beispiel #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
Beispiel #2
0
    def connect(self, local_address, destination_address, protocol="tcp"):
        """ Connect to CSTA Server """
        local_ip, local_port = local_address
        self.ip = local_ip
        self.port = local_port
        # params = {"source_ip": local_ip, "source_port": local_port, "transport": protocol}
        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.link = csta_link
        csta_link.connect(dest_ip, dest_port)

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

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

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

        inBytes = csta_link.waitForData()
        reg_resp = parseBytes(inBytes)
        assert reg_resp.event == "SystemRegisterResponse", 'Invalid Response to System Register Request'
        return csta_link
Beispiel #3
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
def ConnectSip(user_range, baseLocalPort, localIP=util.getLocalIP()):
    " Open the connections for the users "
    connection_pool = {}
    localPort = baseLocalPort
    for user in user_range:
        C = TCPClient(localIP, localPort)
        C.connect(data.parameters["dest_ip"], data.parameters["dest_port"])
        connection_pool[user] = C
        localPort = localPort + 1
    return connection_pool
parameters = {
    "dest_ip": "10.2.0.22",
    "dest_port": 5060,
    "transport": "tcp",
    "callId": util.randomCallID(),
    "user": "******",
    "fromTag": util.randomTag(),
    "sourceIP": util.getLocalIP(),
    "sourcePort": 5080,
    "viaBranch": util.randomBranch(),
    "epid": "SC" + util.randHex(3),
    "expires": "360"
}

# Open the connection
C = TCPClient(parameters["sourceIP"], parameters["sourcePort"])
C.connect(parameters["dest_ip"], parameters["dest_port"])

# Register
m = prepareMessage(message["Register_1"], parameters)
print(m)

C.send(m)

inmessage = C.waitForData()
response = parseBytes(inmessage)
print(response)
assert response.status == "200 OK"

# Unregister
parameters["expires"] = "0"
Beispiel #6
0
parameters = util.dict_2({
    "dest_ip": "10.2.0.22",
    "dest_port": 5060,
    "transport": "tcp",
    "callId": util.randomCallID,
    "fromTag": util.randomTag,
    "source_ip": util.getLocalIP,
    "source_port": 5080,
    "viaBranch": util.randomBranch,
    "epid": lambda x=6: "SC" + util.randStr(x),
    "bodyLength": "0",
    "expires": "360"
})

# Open the connections
C = TCPClient(parameters["source_ip"], parameters["source_port"])
C.connect(parameters["dest_ip"], parameters["dest_port"])

link = {usera: C, userb: C}


def Register(user):
    parameters["user"] = user
    m = buildMessage(message["Register_1"], parameters)
    print(m)
    link[user].send(m.contents())
    inBytes = link[user].waitForData()
    inmessage = parseBytes(inBytes)
    print(inmessage)
    assert inmessage.type == "Response" and inmessage.status == "200 OK"