#2139 - Included a test that tests services over multi-hop routing. Added some PR suggestions around logging.
This commit is contained in:
@@ -590,8 +590,8 @@ class RouterARPCache(ARPCache):
|
|||||||
self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address])
|
self.send_arp_request(route.next_hop_ip_address, ignore_networks=[frame.ip.src_ip_address])
|
||||||
return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True)
|
return self.process_arp_packet(from_nic, frame, route_table, is_reattempt=True)
|
||||||
else:
|
else:
|
||||||
pass
|
self.sys_log.info("Ignoring ARP request as destination unavailable/No ARP entry found")
|
||||||
# TODO: destination unavailable/No ARP netry found
|
return
|
||||||
else:
|
else:
|
||||||
arp_reply = arp_packet.generate_reply(from_nic.mac_address)
|
arp_reply = arp_packet.generate_reply(from_nic.mac_address)
|
||||||
self.send_arp_reply(arp_reply, from_nic)
|
self.send_arp_reply(arp_reply, from_nic)
|
||||||
@@ -797,7 +797,7 @@ class Router(Node):
|
|||||||
return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True)
|
return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True)
|
||||||
|
|
||||||
if not nic.enabled:
|
if not nic.enabled:
|
||||||
# TODO: Add sys_log here
|
self.sys_log.info(f"Frame dropped as NIC {nic} is not enabled")
|
||||||
return
|
return
|
||||||
|
|
||||||
if frame.ip.dst_ip_address in nic.ip_network:
|
if frame.ip.dst_ip_address in nic.ip_network:
|
||||||
@@ -829,7 +829,7 @@ class Router(Node):
|
|||||||
return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True)
|
return self.process_frame(frame=frame, from_nic=from_nic, re_attempt=True)
|
||||||
|
|
||||||
if not nic.enabled:
|
if not nic.enabled:
|
||||||
# TODO: Add sys_log here
|
self.sys_log.info(f"Frame dropped as NIC {nic} is not enabled")
|
||||||
return
|
return
|
||||||
|
|
||||||
from_port = self._get_port_of_nic(from_nic)
|
from_port = self._get_port_of_nic(from_nic)
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class Switch(Node):
|
|||||||
self._add_mac_table_entry(src_mac, incoming_port)
|
self._add_mac_table_entry(src_mac, incoming_port)
|
||||||
|
|
||||||
outgoing_port = self.mac_address_table.get(dst_mac)
|
outgoing_port = self.mac_address_table.get(dst_mac)
|
||||||
if outgoing_port and dst_mac != "ff:ff:ff:ff:ff:ff":
|
if outgoing_port and dst_mac.lower() != "ff:ff:ff:ff:ff:ff":
|
||||||
outgoing_port.send_frame(frame)
|
outgoing_port.send_frame(frame)
|
||||||
else:
|
else:
|
||||||
# If the destination MAC is not in the table, flood to all ports except incoming
|
# If the destination MAC is not in the table, flood to all ports except incoming
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ from primaite.simulator.network.hardware.nodes.computer import Computer
|
|||||||
from primaite.simulator.network.hardware.nodes.router import ACLAction, Router
|
from primaite.simulator.network.hardware.nodes.router import ACLAction, Router
|
||||||
from primaite.simulator.network.transmission.network_layer import IPProtocol
|
from primaite.simulator.network.transmission.network_layer import IPProtocol
|
||||||
from primaite.simulator.network.transmission.transport_layer import Port
|
from primaite.simulator.network.transmission.transport_layer import Port
|
||||||
|
from primaite.simulator.system.services.ntp.ntp_client import NTPClient
|
||||||
|
from primaite.simulator.system.services.ntp.ntp_server import NTPServer
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
@@ -143,3 +145,41 @@ def test_with_routes_can_ping(multi_hop_network):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert pc_a.ping(pc_b.ethernet_port[1].ip_address)
|
assert pc_a.ping(pc_b.ethernet_port[1].ip_address)
|
||||||
|
|
||||||
|
|
||||||
|
def test_routing_services(multi_hop_network):
|
||||||
|
pc_a = multi_hop_network.get_node_by_hostname("pc_a")
|
||||||
|
|
||||||
|
pc_b = multi_hop_network.get_node_by_hostname("pc_b")
|
||||||
|
|
||||||
|
pc_a.software_manager.install(NTPClient)
|
||||||
|
ntp_client = pc_a.software_manager.software["NTPClient"]
|
||||||
|
ntp_client.start()
|
||||||
|
|
||||||
|
pc_b.software_manager.install(NTPServer)
|
||||||
|
pc_b.software_manager.software["NTPServer"].start()
|
||||||
|
|
||||||
|
ntp_client.configure(ntp_server_ip_address=pc_b.ethernet_port[1].ip_address)
|
||||||
|
|
||||||
|
router_1: Router = multi_hop_network.get_node_by_hostname("router_1") # noqa
|
||||||
|
router_2: Router = multi_hop_network.get_node_by_hostname("router_2") # noqa
|
||||||
|
|
||||||
|
router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.NTP, dst_port=Port.NTP, position=21)
|
||||||
|
router_2.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.NTP, dst_port=Port.NTP, position=21)
|
||||||
|
|
||||||
|
assert ntp_client.time is None
|
||||||
|
ntp_client.request_time()
|
||||||
|
assert ntp_client.time is None
|
||||||
|
|
||||||
|
# Configure Route from Router 1 to PC B subnet
|
||||||
|
router_1.route_table.add_route(
|
||||||
|
address="192.168.2.0", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.2"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Configure Route from Router 2 to PC A subnet
|
||||||
|
router_2.route_table.add_route(
|
||||||
|
address="192.168.0.2", subnet_mask="255.255.255.0", next_hop_ip_address="192.168.1.1"
|
||||||
|
)
|
||||||
|
|
||||||
|
ntp_client.request_time()
|
||||||
|
assert ntp_client.time is not None
|
||||||
|
|||||||
Reference in New Issue
Block a user