diff --git a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py index 2ca854d4..5e52de7e 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/wireless_router.py @@ -263,6 +263,9 @@ class WirelessRouter(Router, identifier="wireless_router"): :rtype: WirelessRouter """ router = cls(config=cls.ConfigSchema(**config)) + router.operating_state = ( + NodeOperatingState.ON if not (p := config.get("operating_state")) else NodeOperatingState[p.upper()] + ) if "router_interface" in config: ip_address = config["router_interface"]["ip_address"] subnet_mask = config["router_interface"]["subnet_mask"] @@ -294,7 +297,4 @@ class WirelessRouter(Router, identifier="wireless_router"): next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), metric=float(route.get("metric", 0)), ) - router.operating_state = ( - NodeOperatingState.ON if not (p := config.get("operating_state")) else NodeOperatingState[p.upper()] - ) return router diff --git a/src/primaite/simulator/system/services/database/database_service.py b/src/primaite/simulator/system/services/database/database_service.py index 4ba4c4d4..fc56483d 100644 --- a/src/primaite/simulator/system/services/database/database_service.py +++ b/src/primaite/simulator/system/services/database/database_service.py @@ -31,12 +31,11 @@ class DatabaseService(Service, identifier="DatabaseService"): type: str = "DatabaseService" backup_server_ip: Optional[IPv4Address] = None + db_password: Optional[str] = None + """Password that needs to be provided by clients if they want to connect to the DatabaseService.""" config: "DatabaseService.ConfigSchema" = Field(default_factory=lambda: DatabaseService.ConfigSchema()) - password: Optional[str] = None - """Password that needs to be provided by clients if they want to connect to the DatabaseService.""" - backup_server_ip: IPv4Address = None """IP address of the backup server.""" @@ -217,7 +216,7 @@ class DatabaseService(Service, identifier="DatabaseService"): SoftwareHealthState.FIXING, SoftwareHealthState.COMPROMISED, ]: - if self.password == password: + if self.config.db_password == password: status_code = 200 # ok connection_id = self._generate_connection_id() # try to create connection diff --git a/src/primaite/simulator/system/services/dns/dns_client.py b/src/primaite/simulator/system/services/dns/dns_client.py index 0756eb05..3ff5b930 100644 --- a/src/primaite/simulator/system/services/dns/dns_client.py +++ b/src/primaite/simulator/system/services/dns/dns_client.py @@ -22,11 +22,13 @@ class DNSClient(Service, identifier="DNSClient"): type: str = "DNSClient" + dns_server: Optional[IPv4Address] = None + "The DNS Server the client sends requests to." + config: "DNSClient.ConfigSchema" = Field(default_factory=lambda: DNSClient.ConfigSchema()) dns_cache: Dict[str, IPv4Address] = {} "A dict of known mappings between domain/URLs names and IPv4 addresses." - dns_server: Optional[IPv4Address] = None - "The DNS Server the client sends requests to." + def __init__(self, **kwargs): kwargs["name"] = "DNSClient" diff --git a/src/primaite/simulator/system/services/ftp/ftp_server.py b/src/primaite/simulator/system/services/ftp/ftp_server.py index 054bfe15..a5b59ec9 100644 --- a/src/primaite/simulator/system/services/ftp/ftp_server.py +++ b/src/primaite/simulator/system/services/ftp/ftp_server.py @@ -23,14 +23,17 @@ class FTPServer(FTPServiceABC, identifier="FTPServer"): config: "FTPServer.ConfigSchema" = Field(default_factory=lambda: FTPServer.ConfigSchema()) - server_password: Optional[str] = None - """Password needed to connect to FTP server. Default is None.""" + class ConfigSchema(Service.ConfigSchema): """ConfigSchema for FTPServer.""" type: str = "FTPServer" + server_password: Optional[str] = None + """Password needed to connect to FTP server. Default is None.""" + + def __init__(self, **kwargs): kwargs["name"] = "FTPServer" kwargs["port"] = PORT_LOOKUP["FTP"] diff --git a/src/primaite/simulator/system/services/ntp/ntp_client.py b/src/primaite/simulator/system/services/ntp/ntp_client.py index fb470faf..b27d1241 100644 --- a/src/primaite/simulator/system/services/ntp/ntp_client.py +++ b/src/primaite/simulator/system/services/ntp/ntp_client.py @@ -22,10 +22,12 @@ class NTPClient(Service, identifier="NTPClient"): type: str = "NTPClient" + ntp_server_ip: Optional[IPv4Address] = None + "The NTP server the client sends requests to." + config: "NTPClient.ConfigSchema" = Field(default_factory=lambda: NTPClient.ConfigSchema()) - ntp_server: Optional[IPv4Address] = None - "The NTP server the client sends requests to." + time: Optional[datetime] = None def __init__(self, **kwargs): @@ -42,8 +44,8 @@ class NTPClient(Service, identifier="NTPClient"): :param ntp_server_ip_address: IPv4 address of NTP server. :param ntp_client_ip_Address: IPv4 address of NTP client. """ - self.ntp_server = ntp_server_ip_address - self.sys_log.info(f"{self.name}: ntp_server: {self.ntp_server}") + self.config.ntp_server_ip = ntp_server_ip_address + self.sys_log.info(f"{self.name}: ntp_server: {self.config.ntp_server_ip}") def describe_state(self) -> Dict: """ @@ -105,10 +107,10 @@ class NTPClient(Service, identifier="NTPClient"): def request_time(self) -> None: """Send request to ntp_server.""" - if self.ntp_server: + if self.config.ntp_server_ip: self.software_manager.session_manager.receive_payload_from_software_manager( payload=NTPPacket(), - dst_ip_address=self.ntp_server, + dst_ip_address=self.config.ntp_server_ip, src_port=self.port, dst_port=self.port, ip_protocol=self.protocol, diff --git a/tests/conftest.py b/tests/conftest.py index 6ac227ef..765ed8dc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -387,7 +387,6 @@ def install_stuff_to_sim(sim: Simulation): "ip_address": "10.0.1.2", "subnet_mask": "255.255.255.0", "default_gateway": "10.0.1.1", - "start_up_duration": 0, } client_1: Computer = Computer.from_config(config=client_1_cfg) client_1.power_on() diff --git a/tests/integration_tests/extensions/services/extended_service.py b/tests/integration_tests/extensions/services/extended_service.py index ba247369..11adc53b 100644 --- a/tests/integration_tests/extensions/services/extended_service.py +++ b/tests/integration_tests/extensions/services/extended_service.py @@ -31,14 +31,14 @@ class ExtendedService(Service, identifier="ExtendedService"): type: str = "ExtendedService" + backup_server_ip: IPv4Address = None + """IP address of the backup server.""" + config: "ExtendedService.ConfigSchema" = Field(default_factory=lambda: ExtendedService.ConfigSchema()) password: Optional[str] = None """Password that needs to be provided by clients if they want to connect to the DatabaseService.""" - backup_server_ip: IPv4Address = None - """IP address of the backup server.""" - latest_backup_directory: str = None """Directory of latest backup."""