diff --git a/src/primaite/config/_package_data/data_manipulation.yaml b/src/primaite/config/_package_data/data_manipulation.yaml index b6899b79..c68480cf 100644 --- a/src/primaite/config/_package_data/data_manipulation.yaml +++ b/src/primaite/config/_package_data/data_manipulation.yaml @@ -226,16 +226,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -924,56 +924,44 @@ simulation: - ref: client_2_dns_client type: DNSClient - - links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/src/primaite/config/_package_data/data_manipulation_marl.yaml b/src/primaite/config/_package_data/data_manipulation_marl.yaml index 86759b2d..9ec2a1f2 100644 --- a/src/primaite/config/_package_data/data_manipulation_marl.yaml +++ b/src/primaite/config/_package_data/data_manipulation_marl.yaml @@ -228,16 +228,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -803,16 +803,16 @@ agents: label: LINKS options: link_references: - - router_1___switch_1 - - router_1___switch_2 - - switch_1___domain_controller - - switch_1___web_server - - switch_1___database_server - - switch_1___backup_server - - switch_1___security_suite - - switch_2___client_1 - - switch_2___client_2 - - switch_2___security_suite + - router_1:eth-1<->switch_1:eth-8 + - router_1:eth-2<->switch_2:eth-8 + - switch_1:eth-1<->domain_controller:eth-1 + - switch_1:eth-2<->web_server:eth-1 + - switch_1:eth-3<->database_server:eth-1 + - switch_1:eth-4<->backup_server:eth-1 + - switch_1:eth-7<->security_suite:eth-1 + - switch_2:eth-1<->client_1:eth-1 + - switch_2:eth-2<->client_2:eth-1 + - switch_2:eth-7<->security_suite:eth-2 - type: "NONE" label: ICS options: {} @@ -1505,53 +1505,43 @@ simulation: links: - - ref: router_1___switch_1 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 1 endpoint_b_ref: switch_1 endpoint_b_port: 8 - - ref: router_1___switch_2 - endpoint_a_ref: router_1 + - endpoint_a_ref: router_1 endpoint_a_port: 2 endpoint_b_ref: switch_2 endpoint_b_port: 8 - - ref: switch_1___domain_controller - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 1 endpoint_b_ref: domain_controller endpoint_b_port: 1 - - ref: switch_1___web_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 2 endpoint_b_ref: web_server endpoint_b_port: 1 - - ref: switch_1___database_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 3 endpoint_b_ref: database_server endpoint_b_port: 1 - - ref: switch_1___backup_server - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 4 endpoint_b_ref: backup_server endpoint_b_port: 1 - - ref: switch_1___security_suite - endpoint_a_ref: switch_1 + - endpoint_a_ref: switch_1 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 1 - - ref: switch_2___client_1 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 1 endpoint_b_ref: client_1 endpoint_b_port: 1 - - ref: switch_2___client_2 - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 2 endpoint_b_ref: client_2 endpoint_b_port: 1 - - ref: switch_2___security_suite - endpoint_a_ref: switch_2 + - endpoint_a_ref: switch_2 endpoint_a_port: 7 endpoint_b_ref: security_suite endpoint_b_port: 2 diff --git a/src/primaite/game/agent/observations/link_observation.py b/src/primaite/game/agent/observations/link_observation.py index be08657d..b55aae46 100644 --- a/src/primaite/game/agent/observations/link_observation.py +++ b/src/primaite/game/agent/observations/link_observation.py @@ -82,7 +82,7 @@ class LinkObservation(AbstractObservation, identifier="LINK"): :return: Constructed link observation instance. :rtype: LinkObservation """ - link_reference = game.ref_map_links[config.link_reference] + link_reference = config.link_reference if parent_where == []: where = ["network", "links", link_reference] else: diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 6ba7e63c..034d11bc 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -111,9 +111,6 @@ class PrimaiteGame: self.ref_map_applications: Dict[str, str] = {} """Mapping from human-readable application reference to application object. Used for parsing config files.""" - self.ref_map_links: Dict[str, str] = {} - """Mapping from human-readable link reference to link object. Used when parsing config files.""" - self.save_step_metadata: bool = False """Whether to save the RL agents' action, environment state, and other data at every single step.""" @@ -409,8 +406,7 @@ class PrimaiteGame: endpoint_b = node_b.network_interface[link_cfg["endpoint_b_port"]] else: endpoint_b = node_b.network_interface[link_cfg["endpoint_b_port"]] - new_link = net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) - game.ref_map_links[link_cfg["ref"]] = new_link.uuid + net.connect(endpoint_a=endpoint_a, endpoint_b=endpoint_b) # 3. create agents agents_cfg = cfg.get("agents", []) diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index 92ee9f0d..cfe66d89 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -225,18 +225,19 @@ class Network(SimComponent): } ) # Update the links one-by-one. The key is a 4-tuple of `hostname_a, port_a, hostname_b, port_b` - for uuid, link in self.links.items(): + for _, link in self.links.items(): node_a = link.endpoint_a._connected_node node_b = link.endpoint_b._connected_node hostname_a = node_a.hostname if node_a else None hostname_b = node_b.hostname if node_b else None port_a = link.endpoint_a.port_num port_b = link.endpoint_b.port_num - state["links"][uuid] = link.describe_state() - state["links"][uuid]["hostname_a"] = hostname_a - state["links"][uuid]["hostname_b"] = hostname_b - state["links"][uuid]["port_a"] = port_a - state["links"][uuid]["port_b"] = port_b + link_key = f"{hostname_a}:eth-{port_a}<->{hostname_b}:eth-{port_b}" + state["links"][link_key] = link.describe_state() + state["links"][link_key]["hostname_a"] = hostname_a + state["links"][link_key]["hostname_b"] = hostname_b + state["links"][link_key]["port_a"] = port_a + state["links"][link_key]["port_b"] = port_b return state