mal-simulator 2.0.1__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. {mal_simulator-2.0.1/mal_simulator.egg-info → mal_simulator-2.2.0}/PKG-INFO +1 -1
  2. {mal_simulator-2.0.1 → mal_simulator-2.2.0/mal_simulator.egg-info}/PKG-INFO +1 -1
  3. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/__init__.py +9 -3
  4. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/attacker_step.py +1 -1
  5. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/defender_step.py +1 -1
  6. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/run_simulation.py +0 -1
  7. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/simulator.py +80 -47
  8. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/simulator_state.py +3 -2
  9. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/keyboard_input.py +0 -1
  10. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/pyproject.toml +1 -1
  11. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/tests/test_mal_simulator.py +26 -0
  12. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/AUTHORS +0 -0
  13. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/LICENSE +0 -0
  14. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/README.md +0 -0
  15. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/mal_simulator.egg-info/SOURCES.txt +0 -0
  16. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/mal_simulator.egg-info/dependency_links.txt +0 -0
  17. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/mal_simulator.egg-info/entry_points.txt +0 -0
  18. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/mal_simulator.egg-info/requires.txt +0 -0
  19. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/mal_simulator.egg-info/top_level.txt +0 -0
  20. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/__main__.py +0 -0
  21. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/config/__init__.py +0 -0
  22. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/config/agent_settings.py +0 -0
  23. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/config/agent_settings_factories.py +0 -0
  24. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/config/node_property_rule.py +0 -0
  25. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/config/sim_settings.py +0 -0
  26. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/__init__.py +0 -0
  27. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/base_classes.py +0 -0
  28. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/graph/__init__.py +0 -0
  29. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/graph/graph_env.py +0 -0
  30. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/graph/mal_spaces.py +0 -0
  31. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/graph/serialization.py +0 -0
  32. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/graph/utils.py +0 -0
  33. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/graph/wrapper.py +0 -0
  34. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/legacy/__init__.py +0 -0
  35. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/legacy/gym_envs.py +0 -0
  36. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/envs/legacy/malsim_vectorized_obs_env.py +0 -0
  37. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/__init__.py +0 -0
  38. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/agent_state.py +0 -0
  39. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/attack_surface.py +0 -0
  40. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/attacker_state.py +0 -0
  41. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/attacker_state_factories.py +0 -0
  42. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/defender_state.py +0 -0
  43. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/defender_state_factories.py +0 -0
  44. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/defense_surface.py +0 -0
  45. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/false_alerts.py +0 -0
  46. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/graph_processing.py +0 -0
  47. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/graph_state.py +0 -0
  48. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/graph_utils.py +0 -0
  49. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/node_getters.py +0 -0
  50. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/observability.py +0 -0
  51. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/register_agent.py +0 -0
  52. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/reset_agent.py +0 -0
  53. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/rewards.py +0 -0
  54. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/state_query.py +0 -0
  55. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/mal_simulator/ttc_utils.py +0 -0
  56. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/__init__.py +0 -0
  57. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/attackers/__init__.py +0 -0
  58. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/attackers/searchers.py +0 -0
  59. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/attackers/shortest_path.py +0 -0
  60. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/attackers/ttc_soft_min.py +0 -0
  61. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/decision_agent.py +0 -0
  62. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/defenders/__init__.py +0 -0
  63. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/defenders/heuristic_agent.py +0 -0
  64. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/passive_agent.py +0 -0
  65. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/random_agent.py +0 -0
  66. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/policies/utils/path_finding.py +0 -0
  67. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/scenario/__init__.py +0 -0
  68. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/scenario/scenario.py +0 -0
  69. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/types.py +0 -0
  70. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/malsim/visualization/malsim_gui_client.py +0 -0
  71. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/setup.cfg +0 -0
  72. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/tests/test_graph_processing.py +0 -0
  73. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/tests/test_main.py +0 -0
  74. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/tests/test_scenario.py +0 -0
  75. {mal_simulator-2.0.1 → mal_simulator-2.2.0}/tests/test_ttc_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mal-simulator
3
- Version: 2.0.1
3
+ Version: 2.2.0
4
4
  Summary: A MAL compliant simulator.
5
5
  Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Sandor Berglund <sandorb@kth.se>
6
6
  License: Apache Software License
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mal-simulator
3
- Version: 2.0.1
3
+ Version: 2.2.0
4
4
  Summary: A MAL compliant simulator.
5
5
  Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Sandor Berglund <sandorb@kth.se>
6
6
  License: Apache Software License
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Simulator v2.0.1
2
+ # MAL Simulator v2.2.0
3
3
  # Copyright 2025, Andrei Buhaiu.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,8 +27,14 @@ from malsim.scenario import Scenario
27
27
  from malsim.config import AttackerSettings, DefenderSettings
28
28
 
29
29
  __title__ = 'malsim'
30
- __version__ = '2.0.1'
31
- __authors__ = ['Andrei Buhaiu', 'Joakim Loxdal', 'Jakob Nyberg', 'Nikolaos Kakouros', 'Sandor Berglund']
30
+ __version__ = '2.2.0'
31
+ __authors__ = [
32
+ 'Andrei Buhaiu',
33
+ 'Joakim Loxdal',
34
+ 'Jakob Nyberg',
35
+ 'Nikolaos Kakouros',
36
+ 'Sandor Berglund',
37
+ ]
32
38
  __license__ = 'Apache 2.0'
33
39
  __docformat__ = 'restructuredtext en'
34
40
 
@@ -129,7 +129,7 @@ def attacker_step(
129
129
  Returns: two lists with compromised, attempted nodes
130
130
  """
131
131
 
132
- logger.info('Stepping with agent %s', agent.name)
132
+ logger.debug('Stepping with agent %s', agent.name)
133
133
  successful_compromises: list[AttackGraphNode] = []
134
134
  attempted_compromises: list[AttackGraphNode] = []
135
135
 
@@ -42,7 +42,7 @@ def defender_step(
42
42
  and `attack_steps_made_unviable`.
43
43
  """
44
44
 
45
- logger.info('Stepping with %s', agent.name)
45
+ logger.debug('Stepping with %s', agent.name)
46
46
  enabled_defenses: list[AttackGraphNode] = []
47
47
  attack_steps_made_unviable: set[AttackGraphNode] = set()
48
48
 
@@ -39,7 +39,6 @@ def run_simulation(
39
39
 
40
40
  if agent_action:
41
41
  actions[agent_name] = [agent_action]
42
- print(f'Agent {agent_name} chose action: {agent_action.full_name}')
43
42
 
44
43
  # Store agent action
45
44
  agent_actions.setdefault(agent_name, []).append(agent_action)
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from collections import defaultdict
4
4
  import logging
5
- from typing import Any, Optional
5
+ from typing import Any, NamedTuple, Optional
6
6
  from collections.abc import Callable, Mapping, Set
7
7
 
8
8
  import numpy as np
@@ -20,6 +20,7 @@ from malsim.mal_simulator.defender_step import (
20
20
  defender_is_terminated,
21
21
  defender_step,
22
22
  )
23
+ from malsim.mal_simulator.graph_state import compute_initial_graph_state
23
24
  from malsim.mal_simulator.node_getters import (
24
25
  full_names_or_nodes_to_nodes,
25
26
  get_node,
@@ -103,6 +104,20 @@ ENABLED_ATTACKS_FUNCS: Mapping[
103
104
  BASE_SETTINGS = MalSimulatorSettings()
104
105
 
105
106
 
107
+ class MALSimulatorStaticData(NamedTuple):
108
+ attack_graph: AttackGraph
109
+ sim_settings: MalSimulatorSettings
110
+ rewards: Optional[dict[str, float] | dict[AttackGraphNode, float]] = None
111
+ false_positive_rates: Optional[dict[str, float] | dict[AttackGraphNode, float]] = (
112
+ None
113
+ )
114
+ false_negative_rates: Optional[dict[str, float] | dict[AttackGraphNode, float]] = (
115
+ None
116
+ )
117
+ node_actionabilities: Optional[dict[str, bool] | dict[AttackGraphNode, bool]] = None
118
+ node_observabilities: Optional[dict[str, bool] | dict[AttackGraphNode, bool]] = None
119
+
120
+
106
121
  class MalSimulator:
107
122
  """A MAL Simulator that works on the AttackGraph
108
123
 
@@ -115,6 +130,7 @@ class MalSimulator:
115
130
  self,
116
131
  attack_graph: AttackGraph,
117
132
  sim_settings: MalSimulatorSettings = BASE_SETTINGS,
133
+ agent_settings: Optional[AgentSettings] = None,
118
134
  rewards: Optional[dict[str, float] | dict[AttackGraphNode, float]] = None,
119
135
  false_positive_rates: Optional[
120
136
  dict[str, float] | dict[AttackGraphNode, float]
@@ -132,45 +148,61 @@ class MalSimulator:
132
148
  ):
133
149
  """
134
150
  Args:
135
- attack_graph - The attack graph to use
136
- sim_settings - Settings for simulator
151
+ attack_graph - The attack graph to use
152
+ sim_settings - Settings for simulator
153
+ agent_settings - The agents to pre-register
154
+ rewards - Global rewards per node
155
+ false_positive_rates - global fpr per node
156
+ false_negative_rates - global fnr per node
157
+ node_actionabilities - global actionabilities per node
158
+ node_observabilities - global obserabilities per node
159
+ send_to_api - Enable to send data to malsim-gui rest api
137
160
  """
138
- logger.info('Creating Base MAL Simulator.')
139
- self.sim_settings = sim_settings
140
- self.rng = default_rng(self.sim_settings.seed)
161
+ rng = default_rng(sim_settings.seed)
162
+ rest_api_client = MalSimGUIClient() if send_to_api else None
141
163
 
142
- # Initialize the REST API client
143
- self.rest_api_client = None
144
- if send_to_api:
145
- self.rest_api_client = MalSimGUIClient()
146
-
147
- # Initialize all values
148
- self.recording: Recording = defaultdict(dict)
149
- self._agent_settings: dict[str, AttackerSettings | DefenderSettings] = {}
150
- self._agent_states: AgentStates = {}
151
- self._alive_agents: set[str] = set()
152
- self._agent_rewards: AgentRewards = {}
153
-
154
- self.sim_state = create_simulator_state(
164
+ static_sim_data = MALSimulatorStaticData(
155
165
  attack_graph,
156
166
  sim_settings,
157
- self.rng,
158
167
  rewards,
159
168
  false_positive_rates,
160
169
  false_negative_rates,
161
170
  node_actionabilities,
162
171
  node_observabilities,
163
172
  )
164
-
165
- self.performed_attacks_func = PERFORMED_ATTACKS_FUNCS[
173
+ performed_attacks_func = PERFORMED_ATTACKS_FUNCS[
166
174
  sim_settings.attacker_reward_mode
167
175
  ]
168
- self.enabled_defenses_func = ENABLED_DEFENSES_FUNCS[
169
- sim_settings.defender_reward_mode
170
- ]
171
- self.enabled_attacks_func = ENABLED_ATTACKS_FUNCS[
176
+ enabled_defenses_func = ENABLED_DEFENSES_FUNCS[
172
177
  sim_settings.defender_reward_mode
173
178
  ]
179
+ enabled_attacks_func = ENABLED_ATTACKS_FUNCS[sim_settings.defender_reward_mode]
180
+ agent_settings = agent_settings or {}
181
+
182
+ agent_states, alive_agents, sim_state, agent_rewards, recording = reset(
183
+ static_sim_data,
184
+ agent_settings,
185
+ rng,
186
+ rest_api_client,
187
+ performed_attacks_func,
188
+ enabled_defenses_func,
189
+ enabled_attacks_func,
190
+ )
191
+
192
+ # Set all instance variables
193
+ self.rng = rng
194
+ self._agent_states = agent_states
195
+ self._alive_agents = alive_agents
196
+ self._agent_rewards = agent_rewards
197
+ self.sim_state = sim_state
198
+ self.recording = recording
199
+ self.enabled_attacks_func = enabled_attacks_func
200
+ self.enabled_defenses_func = enabled_defenses_func
201
+ self.performed_attacks_func = performed_attacks_func
202
+ self.sim_settings = sim_settings
203
+ self._agent_settings = agent_settings
204
+ self.rest_api_client = rest_api_client
205
+ self._static_data = static_sim_data
174
206
 
175
207
  def __getstate__(self) -> dict[str, Any]:
176
208
  """This just ensures a pickled simulator doesn't contain some data structures"""
@@ -324,8 +356,14 @@ class MalSimulator:
324
356
  return agent_is_terminated(self._agent_states, self._alive_agents, agent_name)
325
357
 
326
358
  def reset(self) -> dict[str, MalSimAttackerState | MalSimDefenderState]:
327
- agent_states, alive_agents, sim_state, agent_rewards, recording = reset(
359
+ (
360
+ self._agent_states,
361
+ self._alive_agents,
328
362
  self.sim_state,
363
+ self._agent_rewards,
364
+ self.recording,
365
+ ) = reset(
366
+ self._static_data,
329
367
  self._agent_settings,
330
368
  self.rng,
331
369
  self.rest_api_client,
@@ -333,11 +371,6 @@ class MalSimulator:
333
371
  self.enabled_defenses_func,
334
372
  self.enabled_attacks_func,
335
373
  )
336
- self._agent_states = agent_states
337
- self._alive_agents = alive_agents
338
- self._agent_rewards = agent_rewards
339
- self.recording = recording
340
- self.sim_state = sim_state
341
374
  return self._agent_states
342
375
 
343
376
  def register_attacker(
@@ -533,7 +566,7 @@ def agent_is_terminated(
533
566
 
534
567
 
535
568
  def reset(
536
- sim_state: MalSimulatorState,
569
+ static_data: MALSimulatorStaticData,
537
570
  agent_settings: AgentSettings,
538
571
  rng: np.random.Generator,
539
572
  rest_api_client: Optional[MalSimGUIClient],
@@ -544,28 +577,28 @@ def reset(
544
577
  AgentStates,
545
578
  set[str],
546
579
  MalSimulatorState,
547
- dict[str, float],
580
+ AgentRewards,
548
581
  Recording,
549
582
  ]:
550
583
  """Reset attack graph and reinitialize agents"""
551
584
  logger.info('Resetting MAL Simulator.')
585
+ attack_graph = static_data.attack_graph
586
+ settings = static_data.sim_settings
552
587
 
553
588
  # Re-calculate initial simulator state
589
+ graph_state = compute_initial_graph_state(attack_graph, settings, rng)
554
590
  sim_state = create_simulator_state(
555
- sim_state.attack_graph,
556
- sim_state.settings,
591
+ attack_graph,
592
+ graph_state,
593
+ settings,
557
594
  rng,
558
- sim_state.global_rewards,
559
- sim_state.global_false_positive_rates,
560
- sim_state.global_false_negative_rates,
561
- sim_state.global_actionability,
562
- sim_state.global_observability,
595
+ static_data.rewards,
596
+ static_data.false_positive_rates,
597
+ static_data.false_negative_rates,
598
+ static_data.node_actionabilities,
599
+ static_data.node_observabilities,
563
600
  )
564
601
 
565
- # Reset rewards and recording
566
- agent_rewards: dict[str, float] = {}
567
- recording: Recording = defaultdict(dict)
568
-
569
602
  agent_states, alive_agents, agent_rewards = reset_agents(
570
603
  sim_state,
571
604
  agent_settings,
@@ -576,9 +609,9 @@ def reset(
576
609
  )
577
610
  # Upload initial state to the REST API
578
611
  if rest_api_client:
579
- rest_api_client.upload_initial_state(sim_state.attack_graph)
612
+ rest_api_client.upload_initial_state(attack_graph)
580
613
 
581
- return agent_states, alive_agents, sim_state, agent_rewards, recording
614
+ return agent_states, alive_agents, sim_state, agent_rewards, defaultdict(dict)
582
615
 
583
616
 
584
617
  def _pre_step_check(
@@ -5,7 +5,7 @@ from maltoolbox.attackgraph import AttackGraph, AttackGraphNode
5
5
  import numpy as np
6
6
 
7
7
  from malsim.config.sim_settings import MalSimulatorSettings
8
- from malsim.mal_simulator.graph_state import GraphState, compute_initial_graph_state
8
+ from malsim.mal_simulator.graph_state import GraphState
9
9
  from malsim.mal_simulator.node_getters import full_name_dict_to_node_dict
10
10
 
11
11
 
@@ -23,6 +23,7 @@ class MalSimulatorState:
23
23
 
24
24
  def create_simulator_state(
25
25
  attack_graph: AttackGraph,
26
+ graph_state: GraphState,
26
27
  sim_settings: MalSimulatorSettings,
27
28
  rng: np.random.Generator,
28
29
  rewards: Optional[dict[str, float] | dict[AttackGraphNode, float]] = None,
@@ -42,7 +43,7 @@ def create_simulator_state(
42
43
  return MalSimulatorState(
43
44
  attack_graph,
44
45
  sim_settings,
45
- compute_initial_graph_state(attack_graph, sim_settings, rng),
46
+ graph_state,
46
47
  full_name_dict_to_node_dict(attack_graph, rewards or {}),
47
48
  full_name_dict_to_node_dict(attack_graph, false_positive_rates or {}),
48
49
  full_name_dict_to_node_dict(attack_graph, false_negative_rates or {}),
@@ -16,7 +16,6 @@ class KeyboardAgent(DecisionAgent):
16
16
 
17
17
  def __init__(self, _: Any, **kwargs: Any):
18
18
  super().__init__(**kwargs)
19
- logger.info('Creating KeyboardAgent')
20
19
 
21
20
  def get_next_action(
22
21
  self, agent_state: MalSimAgentState, **kwargs: Any
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mal-simulator"
3
- version = "2.0.1"
3
+ version = "2.2.0"
4
4
  authors = [
5
5
  { name="Andrei Buhaiu", email="buhaiu@kth.se" },
6
6
  { name="Joakim Loxdal", email="loxdal@kth.se" },
@@ -25,6 +25,9 @@ from malsim.config.agent_settings import AttackerSettings, DefenderSettings
25
25
  from dataclasses import asdict
26
26
  import numpy as np
27
27
  import pytest
28
+
29
+ from malsim.policies.random_agent import RandomAgent
30
+ from malsim.types import AgentSettings
28
31
  from .conftest import get_node
29
32
 
30
33
  if TYPE_CHECKING:
@@ -37,6 +40,29 @@ def test_init(corelang_lang_graph: LanguageGraph, model: Model) -> None:
37
40
  MalSimulator(attack_graph)
38
41
 
39
42
 
43
+ def test_init_with_agent_settings(
44
+ corelang_lang_graph: LanguageGraph, model: Model
45
+ ) -> None:
46
+ attack_graph = AttackGraph(corelang_lang_graph, model)
47
+ entry_points = {'OS App:localConnect'}
48
+ goals = {'OS App:fullAccess'}
49
+
50
+ agent_settings: AgentSettings = {
51
+ 'Attacker1': AttackerSettings(
52
+ name='Attacker1', entry_points=entry_points, goals=goals, policy=RandomAgent
53
+ ),
54
+ 'Defender1': DefenderSettings(name='Defender1', policy=RandomAgent),
55
+ }
56
+ attack_graph = AttackGraph(corelang_lang_graph, model)
57
+ sim = MalSimulator(attack_graph, agent_settings=agent_settings)
58
+
59
+ # Make sure the agents were registered
60
+ assert sim.agent_states.keys() == {'Attacker1', 'Defender1'}
61
+ assert sim.agent_reward('Attacker1') == 0.0
62
+ assert sim.agent_reward('Defender1') == 0.0
63
+ assert sim._alive_agents == {'Attacker1', 'Defender1'}
64
+
65
+
40
66
  def test_reset(corelang_lang_graph: LanguageGraph, model: Model) -> None:
41
67
  """Make sure attack graph is reset"""
42
68
  attack_graph = AttackGraph(corelang_lang_graph, model)
File without changes
File without changes
File without changes
File without changes