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
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
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
"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" m = prepareMessage(message["Register_1"], parameters) print(m) C.send(m) inmessage = C.waitForData() response = parseBytes(inmessage)