Change the nmne clear to happen at apply_timestep instead of within describe_state
This commit is contained in:
@@ -137,7 +137,6 @@ class NetworkInterface(SimComponent, ABC):
|
|||||||
)
|
)
|
||||||
if CAPTURE_NMNE:
|
if CAPTURE_NMNE:
|
||||||
state.update({"nmne": {k: v for k, v in self.nmne.items()}})
|
state.update({"nmne": {k: v for k, v in self.nmne.items()}})
|
||||||
self.nmne.clear()
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
@abstractmethod
|
@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}"
|
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):
|
class WiredNetworkInterface(NetworkInterface, ABC):
|
||||||
"""
|
"""
|
||||||
@@ -884,6 +892,9 @@ class Node(SimComponent):
|
|||||||
"""
|
"""
|
||||||
super().apply_timestep(timestep=timestep)
|
super().apply_timestep(timestep=timestep)
|
||||||
|
|
||||||
|
for network_interface in self.network_interfaces.values():
|
||||||
|
network_interface.apply_timestep(timestep=timestep)
|
||||||
|
|
||||||
# count down to boot up
|
# count down to boot up
|
||||||
if self.start_up_countdown > 0:
|
if self.start_up_countdown > 0:
|
||||||
self.start_up_countdown -= 1
|
self.start_up_countdown -= 1
|
||||||
|
|||||||
@@ -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
|
# Assert that initially, there are no captured MNEs on both web and database servers
|
||||||
web_server_nic_state = web_server_nic.describe_state()
|
web_server_nic_state = web_server_nic.describe_state()
|
||||||
db_server_nic_state = db_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 web_server_nic_state["nmne"] == {}
|
||||||
assert db_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.
|
# Check that it does not trigger an MNE capture.
|
||||||
web_server_nic_state = web_server_nic.describe_state()
|
web_server_nic_state = web_server_nic.describe_state()
|
||||||
db_server_nic_state = db_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 web_server_nic_state["nmne"] == {}
|
||||||
assert db_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
|
# 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()
|
web_server_nic_state = web_server_nic.describe_state()
|
||||||
db_server_nic_state = db_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 web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}}
|
||||||
assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"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
|
# Check that no additional MNEs are captured
|
||||||
web_server_nic_state = web_server_nic.describe_state()
|
web_server_nic_state = web_server_nic.describe_state()
|
||||||
db_server_nic_state = db_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 web_server_nic_state["nmne"] == {}
|
||||||
assert db_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
|
# Check that the web server and database server interfaces register an additional MNE
|
||||||
web_server_nic_state = web_server_nic.describe_state()
|
web_server_nic_state = web_server_nic.describe_state()
|
||||||
db_server_nic_state = db_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 web_server_nic_state["nmne"] == {"direction": {"outbound": {"keywords": {"*": 1}}}}
|
||||||
assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"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 that the observed NMNEs match the expected values for both NICs
|
||||||
assert web_nic_obs["outbound"] == expected_nmne
|
assert web_nic_obs["outbound"] == expected_nmne
|
||||||
assert db_nic_obs["inbound"] == expected_nmne
|
assert db_nic_obs["inbound"] == expected_nmne
|
||||||
|
uc2_network.apply_timestep(timestep=0)
|
||||||
|
|||||||
Reference in New Issue
Block a user