#2887 - Merge in changes on dev to resolve conflicts. All tests should now pass
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
# © Crown-owned copyright 2025, Defence Science and Technology Laboratory UK
|
# © Crown-owned copyright 2025, Defence Science and Technology Laboratory UK
|
||||||
"""PrimAITE game - Encapsulates the simulation and agents."""
|
"""PrimAITE game - Encapsulates the simulation and agents."""
|
||||||
from ipaddress import IPv4Address
|
|
||||||
from typing import Dict, List, Optional, Union
|
from typing import Dict, List, Optional, Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|||||||
@@ -1493,6 +1493,7 @@ class Node(SimComponent, ABC):
|
|||||||
:param hostname: The node hostname on the network.
|
:param hostname: The node hostname on the network.
|
||||||
:param operating_state: The node operating state, either ON or OFF.
|
:param operating_state: The node operating state, either ON or OFF.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
operating_state: NodeOperatingState = NodeOperatingState.OFF
|
operating_state: NodeOperatingState = NodeOperatingState.OFF
|
||||||
"The hardware state of the node."
|
"The hardware state of the node."
|
||||||
network_interfaces: Dict[str, NetworkInterface] = {}
|
network_interfaces: Dict[str, NetworkInterface] = {}
|
||||||
@@ -1573,6 +1574,7 @@ class Node(SimComponent, ABC):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def dns_server(self) -> Optional[IPv4Address]:
|
def dns_server(self) -> Optional[IPv4Address]:
|
||||||
|
"""Convenience method to access the dns_server IP."""
|
||||||
return self.config.dns_server
|
return self.config.dns_server
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -1625,7 +1627,9 @@ class Node(SimComponent, ABC):
|
|||||||
dns_server=kwargs["config"].dns_server,
|
dns_server=kwargs["config"].dns_server,
|
||||||
)
|
)
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.operating_state = NodeOperatingState.ON if not (p := kwargs["config"].operating_state) else NodeOperatingState[p.upper()]
|
self.operating_state = (
|
||||||
|
NodeOperatingState.ON if not (p := kwargs["config"].operating_state) else NodeOperatingState[p.upper()]
|
||||||
|
)
|
||||||
self._install_system_software()
|
self._install_system_software()
|
||||||
self.session_manager.node = self
|
self.session_manager.node = self
|
||||||
self.session_manager.software_manager = self.software_manager
|
self.session_manager.software_manager = self.software_manager
|
||||||
|
|||||||
@@ -55,7 +55,10 @@ class HostARP(ARP):
|
|||||||
|
|
||||||
:return: The NIC associated with the default gateway if it exists in the ARP cache; otherwise, None.
|
:return: The NIC associated with the default gateway if it exists in the ARP cache; otherwise, None.
|
||||||
"""
|
"""
|
||||||
if self.software_manager.node.config.default_gateway and self.software_manager.node.has_enabled_network_interface:
|
if (
|
||||||
|
self.software_manager.node.config.default_gateway
|
||||||
|
and self.software_manager.node.has_enabled_network_interface
|
||||||
|
):
|
||||||
return self.get_arp_cache_network_interface(self.software_manager.node.config.default_gateway)
|
return self.get_arp_cache_network_interface(self.software_manager.node.config.default_gateway)
|
||||||
|
|
||||||
def _get_arp_cache_mac_address(
|
def _get_arp_cache_mac_address(
|
||||||
|
|||||||
@@ -58,24 +58,28 @@ def client_server_routed() -> Network:
|
|||||||
router_1.enable_port(2)
|
router_1.enable_port(2)
|
||||||
|
|
||||||
# Client 1
|
# Client 1
|
||||||
client_1 = Computer(config=dict(
|
client_1 = Computer(
|
||||||
|
config=dict(
|
||||||
hostname="client_1",
|
hostname="client_1",
|
||||||
ip_address="192.168.2.2",
|
ip_address="192.168.2.2",
|
||||||
subnet_mask="255.255.255.0",
|
subnet_mask="255.255.255.0",
|
||||||
default_gateway="192.168.2.1",
|
default_gateway="192.168.2.1",
|
||||||
start_up_duration=0,
|
start_up_duration=0,
|
||||||
))
|
)
|
||||||
|
)
|
||||||
client_1.power_on()
|
client_1.power_on()
|
||||||
network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1])
|
network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1])
|
||||||
|
|
||||||
# Server 1
|
# Server 1
|
||||||
server_1 = Server(config=dict(
|
server_1 = Server(
|
||||||
|
config=dict(
|
||||||
hostname="server_1",
|
hostname="server_1",
|
||||||
ip_address="192.168.1.2",
|
ip_address="192.168.1.2",
|
||||||
subnet_mask="255.255.255.0",
|
subnet_mask="255.255.255.0",
|
||||||
default_gateway="192.168.1.1",
|
default_gateway="192.168.1.1",
|
||||||
start_up_duration=0,
|
start_up_duration=0,
|
||||||
))
|
)
|
||||||
|
)
|
||||||
server_1.power_on()
|
server_1.power_on()
|
||||||
network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.network_interface[1])
|
network.connect(endpoint_b=server_1.network_interface[1], endpoint_a=switch_1.network_interface[1])
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ class FTPServer(FTPServiceABC, identifier="FTPServer"):
|
|||||||
"""Convenience method for accessing FTP server password."""
|
"""Convenience method for accessing FTP server password."""
|
||||||
return self.config.server_password
|
return self.config.server_password
|
||||||
|
|
||||||
|
|
||||||
def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket:
|
def _process_ftp_command(self, payload: FTPPacket, session_id: Optional[str] = None, **kwargs) -> FTPPacket:
|
||||||
"""
|
"""
|
||||||
Process the command in the FTP Packet.
|
Process the command in the FTP Packet.
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ class NTPClient(Service, identifier="NTPClient"):
|
|||||||
|
|
||||||
config: "NTPClient.ConfigSchema" = Field(default_factory=lambda: NTPClient.ConfigSchema())
|
config: "NTPClient.ConfigSchema" = Field(default_factory=lambda: NTPClient.ConfigSchema())
|
||||||
|
|
||||||
|
|
||||||
time: Optional[datetime] = None
|
time: Optional[datetime] = None
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ from primaite.config.load import data_manipulation_config_path
|
|||||||
from primaite.simulator.network.container import Network
|
from primaite.simulator.network.container import Network
|
||||||
from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState
|
from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState
|
||||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||||
from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter
|
|
||||||
from primaite.simulator.network.hardware.nodes.network.firewall import Firewall
|
from primaite.simulator.network.hardware.nodes.network.firewall import Firewall
|
||||||
|
from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter
|
||||||
from tests.integration_tests.configuration_file_parsing import BASIC_CONFIG, DMZ_NETWORK, load_config
|
from tests.integration_tests.configuration_file_parsing import BASIC_CONFIG, DMZ_NETWORK, load_config
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ from primaite.simulator.sim_container import Simulation
|
|||||||
|
|
||||||
def test_file_observation():
|
def test_file_observation():
|
||||||
sim = Simulation()
|
sim = Simulation()
|
||||||
pc: Computer = Computer.from_config(config={"type":"computer",
|
pc: Computer = Computer.from_config(
|
||||||
"hostname":"beep",
|
config={"type": "computer", "hostname": "beep", "ip_address": "123.123.123.123", "subnet_mask": "255.255.255.0"}
|
||||||
"ip_address":"123.123.123.123",
|
)
|
||||||
"subnet_mask":"255.255.255.0"})
|
|
||||||
sim.network.add_node(pc)
|
sim.network.add_node(pc)
|
||||||
f = pc.file_system.create_file(file_name="dog.png")
|
f = pc.file_system.create_file(file_name="dog.png")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user