From 65355f83e85874dfa1f3ca941ecc90cf10254332 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Thu, 23 Jan 2025 09:52:14 +0000 Subject: [PATCH] #2887 - Commit before switching branch --- src/primaite/game/game.py | 2 - .../network/hardware/nodes/host/server.py | 2 +- .../hardware/nodes/network/firewall.py | 7 --- .../network/hardware/nodes/network/router.py | 47 ++----------------- 4 files changed, 5 insertions(+), 53 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 009a376f..6a902c40 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -266,8 +266,6 @@ class PrimaiteGame: for node_cfg in nodes_cfg: n_type = node_cfg["type"] - # node_config: dict = node_cfg["config"] - print(f"{n_type}:{node_cfg}") new_node = None if n_type in Node._registry: diff --git a/src/primaite/simulator/network/hardware/nodes/host/server.py b/src/primaite/simulator/network/hardware/nodes/host/server.py index 1b3f6c58..f1abefc2 100644 --- a/src/primaite/simulator/network/hardware/nodes/host/server.py +++ b/src/primaite/simulator/network/hardware/nodes/host/server.py @@ -51,4 +51,4 @@ class Printer(HostNode, identifier="printer"): class ConfigSchema(HostNode.ConfigSchema): """Configuration Schema for Printer class.""" - hostname: ClassVar[str] = "printer" \ No newline at end of file + hostname: str = "printer" \ No newline at end of file diff --git a/src/primaite/simulator/network/hardware/nodes/network/firewall.py b/src/primaite/simulator/network/hardware/nodes/network/firewall.py index 2ebfe44a..a30c49bd 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/firewall.py +++ b/src/primaite/simulator/network/hardware/nodes/network/firewall.py @@ -572,13 +572,6 @@ class Firewall(Router, identifier="firewall"): @classmethod def from_config(cls, config: dict) -> "Firewall": """Create a firewall based on a config dict.""" - # firewall = Firewall( - # hostname=config["hostname"], - # operating_state=NodeOperatingState.ON - # if not (p := config.get("operating_state")) - # else NodeOperatingState[p.upper()], - # ) - firewall = Firewall(config = cls.ConfigSchema(**config)) if "ports" in config: diff --git a/src/primaite/simulator/network/hardware/nodes/network/router.py b/src/primaite/simulator/network/hardware/nodes/network/router.py index e475df66..4f9d9ca4 100644 --- a/src/primaite/simulator/network/hardware/nodes/network/router.py +++ b/src/primaite/simulator/network/hardware/nodes/network/router.py @@ -1212,11 +1212,11 @@ class Router(NetworkNode, identifier="router"): network_interface: Dict[int, RouterInterface] = {} "The Router Interfaces on the node by port id." - sys_log: SysLog = None + sys_log: SysLog - acl: AccessControlList = None + acl: AccessControlList - route_table: RouteTable = None + route_table: RouteTable config: "Router.ConfigSchema" @@ -1250,8 +1250,6 @@ class Router(NetworkNode, identifier="router"): self._set_default_acl() - - def _install_system_software(self): """ Installs essential system software and network services on the router. @@ -1403,7 +1401,7 @@ class Router(NetworkNode, identifier="router"): return # Check if it's permitted - permitted, rule = self.config.acl.is_permitted(frame) + permitted, rule = self.acl.is_permitted(frame) if not permitted: at_port = self._get_port_of_nic(from_network_interface) @@ -1576,43 +1574,6 @@ class Router(NetworkNode, identifier="router"): ) print(table) - def setup_router(self, cfg: dict) -> Router: - """TODO: This is the extra bit of Router's from_config metho. Needs sorting.""" - if "ports" in cfg: - for port_num, port_cfg in cfg["ports"].items(): - self.configure_port( - port=port_num, - ip_address=port_cfg["ip_address"], - subnet_mask=IPv4Address(port_cfg.get("subnet_mask", "255.255.255.0")), - ) - if "acl" in cfg: - for r_num, r_cfg in cfg["acl"].items(): - self.config.acl.add_rule( - action=ACLAction[r_cfg["action"]], - src_port=None if not (p := r_cfg.get("src_port")) else PORT_LOOKUP[p], - dst_port=None if not (p := r_cfg.get("dst_port")) else PORT_LOOKUP[p], - protocol=None if not (p := r_cfg.get("protocol")) else PROTOCOL_LOOKUP[p], - src_ip_address=r_cfg.get("src_ip"), - src_wildcard_mask=r_cfg.get("src_wildcard_mask"), - dst_ip_address=r_cfg.get("dst_ip"), - dst_wildcard_mask=r_cfg.get("dst_wildcard_mask"), - position=r_num, - ) - if "routes" in cfg: - for route in cfg.get("routes"): - self.config.route_table.add_route( - address=IPv4Address(route.get("address")), - subnet_mask=IPv4Address(route.get("subnet_mask", "255.255.255.0")), - next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), - metric=float(route.get("metric", 0)), - ) - if "default_route" in cfg: - next_hop_ip_address = cfg["default_route"].get("next_hop_ip_address", None) - if next_hop_ip_address: - self.route_table.set_default_route_next_hop_ip_address(next_hop_ip_address) - return self - - @classmethod def from_config(cls, config: dict, **kwargs) -> "Router": """Create a router based on a config dict.