diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 36716f27..82fae164 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -137,7 +137,6 @@ class NetworkInterface(SimComponent, ABC): ) if CAPTURE_NMNE: state.update({"nmne": {k: v for k, v in self.nmne.items()}}) - self.nmne.clear() return state @abstractmethod @@ -254,6 +253,15 @@ class NetworkInterface(SimComponent, ABC): """ return f"Port {self.port_name if self.port_name else self.port_num}: {self.mac_address}" + def apply_timestep(self, timestep: int) -> None: + """ + Apply a timestep evolution to this component. + + This just clears the nmne count back to 0.tests/integration_tests/network/test_capture_nmne.py + """ + super().apply_timestep(timestep=timestep) + self.nmne.clear() + class WiredNetworkInterface(NetworkInterface, ABC): """ @@ -884,6 +892,9 @@ class Node(SimComponent): """ super().apply_timestep(timestep=timestep) + for network_interface in self.network_interfaces.values(): + network_interface.apply_timestep(timestep=timestep) + # count down to boot up if self.start_up_countdown > 0: self.start_up_countdown -= 1 diff --git a/tests/integration_tests/network/test_capture_nmne.py b/tests/integration_tests/network/test_capture_nmne.py index d48b3784..698bfc72 100644 --- a/tests/integration_tests/network/test_capture_nmne.py +++ b/tests/integration_tests/network/test_capture_nmne.py @@ -94,6 +94,7 @@ def test_describe_state_nmne(uc2_network): # Assert that initially, there are no captured MNEs on both web and database servers web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {} assert db_server_nic_state["nmne"] == {} @@ -103,6 +104,7 @@ def test_describe_state_nmne(uc2_network): # Check that it does not trigger an MNE capture. web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {} assert db_server_nic_state["nmne"] == {} @@ -112,6 +114,7 @@ def test_describe_state_nmne(uc2_network): # Check that the web server's outbound interface and the database server's inbound interface register the MNE web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} @@ -121,6 +124,7 @@ def test_describe_state_nmne(uc2_network): # Check that no additional MNEs are captured web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {} assert db_server_nic_state["nmne"] == {} @@ -130,6 +134,7 @@ def test_describe_state_nmne(uc2_network): # Check that the web server and database server interfaces register an additional MNE web_server_nic_state = web_server_nic.describe_state() db_server_nic_state = db_server_nic.describe_state() + uc2_network.apply_timestep(timestep=0) assert web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}} assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 1}}}} @@ -190,3 +195,4 @@ def test_capture_nmne_observations(uc2_network): # Assert that the observed NMNEs match the expected values for both NICs assert web_nic_obs["outbound"] == expected_nmne assert db_nic_obs["inbound"] == expected_nmne + uc2_network.apply_timestep(timestep=0)