From 2919be3796e41e1694c1e0e5cdd67b237f529ad7 Mon Sep 17 00:00:00 2001 From: SunilSamra Date: Thu, 17 Aug 2023 14:20:09 +0100 Subject: [PATCH] #1752 - Added web_browser.py application for DNS modelling --- .../simulator/network/protocols/dns.py | 7 +- .../system/applications/web_browser.py | 76 +++++++++++++++++++ 2 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/primaite/simulator/system/applications/web_browser.py diff --git a/src/primaite/simulator/network/protocols/dns.py b/src/primaite/simulator/network/protocols/dns.py index fa88652c..b8f0d8bd 100644 --- a/src/primaite/simulator/network/protocols/dns.py +++ b/src/primaite/simulator/network/protocols/dns.py @@ -5,17 +5,18 @@ from typing import Optional from pydantic import BaseModel - +""" class DNSEntry(BaseModel): - """ + Represents an entry in the DNS cache. :param domain_name: The domain name which a node would like to access. :param ip_address: The IP address through which the domain name is reachable. - """ + domain_name: str ip_address: IPv4Address +""" class DNSRequest(BaseModel): diff --git a/src/primaite/simulator/system/applications/web_browser.py b/src/primaite/simulator/system/applications/web_browser.py new file mode 100644 index 00000000..b30f9946 --- /dev/null +++ b/src/primaite/simulator/system/applications/web_browser.py @@ -0,0 +1,76 @@ +from abc import abstractmethod +from ipaddress import IPv4Address +from typing import Any, Dict, List, Optional + +from primaite.simulator.system.applications.application import Application + + +class WebBrowser(Application): + """ + Represents a web browser in the simulation environment. + + The application requests and loads web pages using its domain name and requesting IP addresses using DNS. + """ + + domain_name: str + "The domain name of the webpage." + domain_name_ip_address: Optional[IPv4Address] + "The IP address of the domain name for the webpage." + history: Dict[str] + "A dict that stores all of the previous domain names." + + @abstractmethod + def describe_state(self) -> Dict: + """ + Describes the current state of the software. + + The specifics of the software's state, including its health, criticality, + and any other pertinent information, should be implemented in subclasses. + + :return: A dictionary containing key-value pairs representing the current state of the software. + :rtype: Dict + """ + pass + + def apply_action(self, action: List[str]) -> None: + """ + Applies a list of actions to the Application. + + :param action: A list of actions to apply. + """ + pass + + def reset_component_for_episode(self, episode: int): + """ + Resets the Application component for a new episode. + + This method ensures the Application is ready for a new episode, including resetting any + stateful properties or statistics, and clearing any message queues. + """ + self.domain_name = "" + self.domain_name_ip_address = None + self.history = {} + + def send(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Sends a payload to the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to send. + :return: True if successful, False otherwise. + """ + pass + + def receive(self, payload: Any, session_id: str, **kwargs) -> bool: + """ + Receives a payload from the SessionManager. + + The specifics of how the payload is processed and whether a response payload + is generated should be implemented in subclasses. + + :param payload: The payload to receive. + :return: True if successful, False otherwise. + """ + pass