#2357 - Allowed the config to not have nodes, links and agents and still be parsed
This commit is contained in:
@@ -222,8 +222,12 @@ class PrimaiteGame:
|
|||||||
sim = game.simulation
|
sim = game.simulation
|
||||||
net = sim.network
|
net = sim.network
|
||||||
|
|
||||||
nodes_cfg = cfg["simulation"]["network"]["nodes"]
|
simulation_config = cfg.get("simulation", {})
|
||||||
links_cfg = cfg["simulation"]["network"]["links"]
|
network_config = simulation_config.get("network", {})
|
||||||
|
|
||||||
|
nodes_cfg = network_config.get("nodes", [])
|
||||||
|
links_cfg = network_config.get("links", [])
|
||||||
|
|
||||||
for node_cfg in nodes_cfg:
|
for node_cfg in nodes_cfg:
|
||||||
node_ref = node_cfg["ref"]
|
node_ref = node_cfg["ref"]
|
||||||
n_type = node_cfg["type"]
|
n_type = node_cfg["type"]
|
||||||
@@ -390,7 +394,7 @@ class PrimaiteGame:
|
|||||||
game.ref_map_links[link_cfg["ref"]] = new_link.uuid
|
game.ref_map_links[link_cfg["ref"]] = new_link.uuid
|
||||||
|
|
||||||
# 3. create agents
|
# 3. create agents
|
||||||
agents_cfg = cfg["agents"]
|
agents_cfg = cfg.get("agents", [])
|
||||||
|
|
||||||
for agent_cfg in agents_cfg:
|
for agent_cfg in agents_cfg:
|
||||||
agent_ref = agent_cfg["ref"] # noqa: F841
|
agent_ref = agent_cfg["ref"] # noqa: F841
|
||||||
@@ -439,12 +443,12 @@ class PrimaiteGame:
|
|||||||
agent_settings=agent_settings,
|
agent_settings=agent_settings,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
msg(f"Configuration error: {agent_type} is not a valid agent type.")
|
msg = f"Configuration error: {agent_type} is not a valid agent type."
|
||||||
_LOGGER.error(msg)
|
_LOGGER.error(msg)
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
game.agents[agent_cfg["ref"]] = new_agent
|
game.agents[agent_cfg["ref"]] = new_agent
|
||||||
|
|
||||||
# Set the NMNE capture config
|
# Set the NMNE capture config
|
||||||
set_nmne_config(cfg["simulation"]["network"].get("nmne_config", {}))
|
set_nmne_config(network_config.get("nmne_config", {}))
|
||||||
|
|
||||||
return game
|
return game
|
||||||
|
|||||||
31
tests/assets/configs/no_nodes_links_agents_network.yaml
Normal file
31
tests/assets/configs/no_nodes_links_agents_network.yaml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
training_config:
|
||||||
|
rl_framework: SB3
|
||||||
|
rl_algorithm: PPO
|
||||||
|
seed: 333
|
||||||
|
n_learn_episodes: 1
|
||||||
|
n_eval_episodes: 5
|
||||||
|
max_steps_per_episode: 128
|
||||||
|
deterministic_eval: false
|
||||||
|
n_agents: 1
|
||||||
|
agent_references:
|
||||||
|
- defender
|
||||||
|
|
||||||
|
io_settings:
|
||||||
|
save_checkpoints: true
|
||||||
|
checkpoint_interval: 5
|
||||||
|
save_step_metadata: false
|
||||||
|
save_pcap_logs: true
|
||||||
|
save_sys_logs: true
|
||||||
|
|
||||||
|
|
||||||
|
game:
|
||||||
|
max_episode_length: 256
|
||||||
|
ports:
|
||||||
|
- ARP
|
||||||
|
- DNS
|
||||||
|
- HTTP
|
||||||
|
- POSTGRES_SERVER
|
||||||
|
protocols:
|
||||||
|
- ICMP
|
||||||
|
- TCP
|
||||||
|
- UDP
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import yaml
|
||||||
|
|
||||||
|
from primaite.game.game import PrimaiteGame
|
||||||
|
from tests import TEST_ASSETS_ROOT
|
||||||
|
|
||||||
|
CONFIG_FILE = TEST_ASSETS_ROOT / "configs" / "no_nodes_links_agents_network.yaml"
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_nodes_links_agents_config():
|
||||||
|
"""Tests PrimaiteGame can be created from config file where there are no nodes, links, agents in the config file."""
|
||||||
|
with open(CONFIG_FILE, "r") as f:
|
||||||
|
cfg = yaml.safe_load(f)
|
||||||
|
|
||||||
|
game = PrimaiteGame.from_config(cfg)
|
||||||
|
|
||||||
|
network = game.simulation.network
|
||||||
|
|
||||||
|
assert len(network.nodes) == 0
|
||||||
|
assert len(network.links) == 0
|
||||||
Reference in New Issue
Block a user