diff --git a/network/network.py b/network/network.py index af6f0913..543a60f3 100644 --- a/network/network.py +++ b/network/network.py @@ -39,9 +39,6 @@ def get_config(): target_mask = host_mask if doc_ip is not None: - octets = doc_ip.split('.') - fourth_octet = int(octets[3]) + 1 - doc_ip = '.'.join(octets[:3] + [str(fourth_octet)]) host_ip = doc_ip return host_ip, target_ip, target_mask @@ -52,26 +49,26 @@ def target_setup(p, iface, ip, netmask): psh.assert_prompt_after_cmd(p, ifconfig_setup_cmd, "success") -def con_setup(dut: Dut, host_ip, host_port): +def con_setup(dut: Dut, host_ip, target_ip, port): try: host_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - host_socket.bind((host_ip, host_port)) + host_socket.bind((host_ip, port)) host_socket.listen() except socket.error as e: print(f"Failed to create socket: {e}") exit(1) - dut.send(f"/bin/test-network {host_ip}:{host_port}\n") - dut.expect(f"/bin/test-network {host_ip}:{host_port}" + psh.EOL) + dut.send(f"/bin/test-network {target_ip}:{port}\n") + dut.expect(f"/bin/test-network {target_ip}:{port}" + psh.EOL) ready_to_read, _, _ = select.select([host_socket], [], [], 20) if ready_to_read: peer_socket, _ = host_socket.accept() else: - print("connect timeout") + peer_socket = None host_socket.close() @@ -99,10 +96,11 @@ def harness(dut: Dut, ctx: TestContext, result: TestResult): print(target_ip) print(target_mask) - target_setup(dut, 'en1', target_ip, target_mask) - peer_socket = con_setup(dut, host_ip, port) + target_setup(dut, 'en1', host_ip, target_ip, target_mask) + peer_socket = con_setup(dut, host_ip, target_ip, port) random_bytes = bytes([random.randint(0, 255) for _ in range(128)]) - peer_socket.send(random_bytes) + if peer_socket is not None: + peer_socket.send(random_bytes) while True: idx = dut.expect([assert_re, result_re, result_fail_re, final_re], timeout=timeout_val)