From 636ec0cdd4b80dcb3136d9d7ee7c0f5872351a08 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Wed, 19 Jun 2024 11:31:13 +0100 Subject: [PATCH] #26661 - Added tests for testing arp doesn't work but also doesn't crash the network if attempting to resolve a broadcast or network address --- tests/integration_tests/system/test_arp.py | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/integration_tests/system/test_arp.py diff --git a/tests/integration_tests/system/test_arp.py b/tests/integration_tests/system/test_arp.py new file mode 100644 index 00000000..be8656aa --- /dev/null +++ b/tests/integration_tests/system/test_arp.py @@ -0,0 +1,50 @@ +# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK +from primaite.simulator.network.hardware.nodes.network.router import RouterARP +from primaite.simulator.system.services.arp.arp import ARP +from tests.integration_tests.network.test_routing import multi_hop_network + + +def test_arp_from_host_to_default_gateway(multi_hop_network): + pc_a = multi_hop_network.get_node_by_hostname("pc_a") + router_1 = multi_hop_network.get_node_by_hostname("router_1") + + pc_a_arp: ARP = pc_a.software_manager.arp + + expected_result = router_1.network_interface[2].mac_address + actual_result = pc_a_arp.get_arp_cache_mac_address(router_1.network_interface[2].ip_address) + + assert actual_result == expected_result + + +def test_arp_from_router_to_router(multi_hop_network): + router_1 = multi_hop_network.get_node_by_hostname("router_1") + router_2 = multi_hop_network.get_node_by_hostname("router_2") + + router_1_arp: RouterARP = router_1.software_manager.arp + + expected_result = router_2.network_interface[1].mac_address + actual_result = router_1_arp.get_arp_cache_mac_address(router_2.network_interface[1].ip_address) + + assert actual_result == expected_result + + +def test_arp_fails_for_broadcast_address_between_routers(multi_hop_network): + router_1 = multi_hop_network.get_node_by_hostname("router_1") + + router_1_arp: RouterARP = router_1.software_manager.arp + + expected_result = None + actual_result = router_1_arp.get_arp_cache_mac_address(router_1.network_interface[1].ip_network.broadcast_address) + + assert actual_result == expected_result + + +def test_arp_fails_for_network_address_between_routers(multi_hop_network): + router_1 = multi_hop_network.get_node_by_hostname("router_1") + + router_1_arp: RouterARP = router_1.software_manager.arp + + expected_result = None + actual_result = router_1_arp.get_arp_cache_mac_address(router_1.network_interface[1].ip_network.network_address) + + assert actual_result == expected_result