#2502 add more info about config placeholders

This commit is contained in:
Marek Wolan
2024-05-28 15:45:26 +01:00
parent 85f03570f7
commit 4d1f84dc27
6 changed files with 202 additions and 1 deletions

View File

@@ -352,6 +352,101 @@
"source": [
"env.reset(); # semicolon suppresses jupyter outputting the observation space.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Other uses\n",
"\n",
"Since the episode schedules make use of yaml aliases and anchors, it's possible to use them in any part of the config, not just agent definitions. For instance, we can vary the simulation setup by changing what software is installed on hosts, how that software is configured, or even change the nodes themselves.\n",
"\n",
"As an example, we will vary what software is installed on nodes in a basic test network."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mini_scenario_path = PRIMAITE_PATHS.user_config_path / \"example_config/mini_scenario_with_simulation_variation\"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's open the base scenario to see the placeholders. client_1 and server both have placeholders in the software installed on them. The server has a placeholder called `*server_services` and the client has `*client_applications`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(mini_scenario_path/\"base_scenario.yaml\") as f:\n",
" print(f.read())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the 0th episode, simulation_variant_1.yaml is loaded in and the server gets a `DatabaseService`, while client_1 gets `DatabaseClient`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(mini_scenario_path/\"simulation_variant_1.yaml\") as f:\n",
" print(f.read())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"env = PrimaiteGymEnv(env_config=mini_scenario_path)\n",
"print(f\"Episode: {env.episode_counter}\")\n",
"env.game.simulation.network.get_node_by_hostname('server').software_manager.show()\n",
"env.game.simulation.network.get_node_by_hostname('client_1').software_manager.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the 1st episode, `simulation_variant_2.yaml` is loaded in, therefore the server gets a `FTPServer` and client_1 gets a `RansomwareScript`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(mini_scenario_path/\"simulation_variant_2.yaml\") as f:\n",
" print(f.read())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"env.reset()\n",
"print(f\"Episode: {env.episode_counter}\")\n",
"env.game.simulation.network.get_node_by_hostname('server').software_manager.show()\n",
"env.game.simulation.network.get_node_by_hostname('client_1').software_manager.show()"
]
}
],
"metadata": {