From 0acd9a29385e543590e3c781b5eb68a149caa5a3 Mon Sep 17 00:00:00 2001 From: Chris McCarthy Date: Fri, 9 Feb 2024 10:27:22 +0000 Subject: [PATCH] #2248 - Removed redundant code and added more documentation from PR suggestions --- .../network/base_hardware.rst | 48 +++++++++++++------ .../simulator/network/hardware/base.py | 4 -- .../simulator/system/core/packet_capture.py | 2 +- .../_system/_services/test_web_server.py | 16 ------- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/docs/source/simulation_components/network/base_hardware.rst b/docs/source/simulation_components/network/base_hardware.rst index 10ed59c6..c7545810 100644 --- a/docs/source/simulation_components/network/base_hardware.rst +++ b/docs/source/simulation_components/network/base_hardware.rst @@ -21,24 +21,42 @@ NetworkInterface Node ==== +The Node class stands as a central component in ``base.py``, acting as the superclass for all network nodes within a +PrimAITE simulation. -The Node class is the most crucial component defined in base.py, serving as the parent class for all nodes within a -PrimAITE network simulation. -It encapsulates the following key attributes and behaviors: -- ``hostname`` - The node's hostname on the network. -- ``network_interfaces`` - Dict of NetworkInterface objects attached to the node. -- ``operating_state`` - The hardware state (on/off) of the node. -- ``sys_log`` - System log to record node events. -- ``session_manager`` - Manages user sessions on the node. -- ``software_manager`` - Manages software and services installed on the node. -- ``connect_nic()`` - Connects a NetworkInterface to the node. -- ``disconnect_nic()`` - Disconnects a NetworkInterface from the node. -- ``receive_frame()`` - Receive and process an incoming network frame. -- ``apply_timestep()`` - Progresses node state for a simulation timestep. -- ``power_on()`` - Powers on the node and enables NICs. -- ``power_off()`` - Powers off the node and disables NICs. +Node Attributes +--------------- + + +- **hostname**: The network hostname of the node. +- **operating_state**: Indicates the current hardware state of the node. +- **network_interfaces**: Maps interface names to NetworkInterface objects on the node. +- **network_interface**: Maps port IDs to ``NetworkInterface`` objects on the node. +- **dns_server**: Specifies DNS servers for domain name resolution. +- **start_up_duration**: The time it takes for the node to become fully operational after being powered on. +- **shut_down_duration**: The time required for the node to properly shut down. +- **sys_log**: A system log for recording events related to the node. +- **session_manager**: Manages user sessions within the node. +- **software_manager**: Controls the installation and management of software and services on the node. + +Node Behaviours/Functions +------------------------- + + +- **connect_nic()**: Connects a ``NetworkInterface`` to the node for network communication. +- **disconnect_nic()**: Removes a ``NetworkInterface`` from the node. +- **receive_frame()**: Handles the processing of incoming network frames. +- **apply_timestep()**: Advances the state of the node according to the simulation timestep. +- **power_on()**: Initiates the node, enabling all connected Network Interfaces and starting all Services and + Applications, taking into account the `start_up_duration`. +- **power_off()**: Stops the node's operations, adhering to the `shut_down_duration`. +- **ping()**: Sends ICMP echo requests to a specified IP address to test connectivity. +- **has_enabled_network_interface()**: Checks if the node has any network interfaces enabled, facilitating network + communication. +- **show()**: Provides a summary of the node's current state, including network interfaces, operational status, and + other key attributes. The Node class handles installation of system software, network connectivity, frame processing, system logging, and diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index 541e6428..f5bd5ff5 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -725,10 +725,6 @@ class Node(SimComponent): self._install_system_software() self.set_original_state() - # def model_post_init(self, __context: Any) -> None: - # self._install_system_software() - # self.set_original_state() - def set_original_state(self): """Sets the original state.""" for software in self.software_manager.software.values(): diff --git a/src/primaite/simulator/system/core/packet_capture.py b/src/primaite/simulator/system/core/packet_capture.py index 3f34cad8..fb8a1624 100644 --- a/src/primaite/simulator/system/core/packet_capture.py +++ b/src/primaite/simulator/system/core/packet_capture.py @@ -102,7 +102,7 @@ class PacketCapture: def capture_outbound(self, frame): # noqa - I'll have a circular import and cant use if TYPE_CHECKING ;( """ - Capture an inbound Frame and log it. + Capture an outbound Frame and log it. :param frame: The PCAP frame to capture. """ diff --git a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py index 0d9d68b7..6fac0bcf 100644 --- a/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py +++ b/tests/unit_tests/_primaite/_simulator/_system/_services/test_web_server.py @@ -52,19 +52,3 @@ def test_handling_get_request_home_page(web_server): response: HttpResponsePacket = web_server_service._handle_get_request(payload=payload) assert response.status_code == HttpStatusCode.OK - - -# def test_process_http_request_get(web_server): -# payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/") -# -# web_server_service: WebServer = web_server.software_manager.software.get("WebServer") -# -# assert web_server_service._process_http_request(payload=payload) is True -# -# -# def test_process_http_request_method_not_allowed(web_server): -# payload = HttpRequestPacket(request_method=HttpRequestMethod.DELETE, request_url="http://domain.com/") -# -# web_server_service: WebServer = web_server.software_manager.software.get("WebServer") -# -# assert web_server_service._process_http_request(payload=payload) is False