Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/CyberBattleSim
Path: blob/main/cyberbattle/samples/simple/simpleenv.py
597 views
1
# Copyright (c) Microsoft Corporation.
2
# Licensed under the MIT License.
3
4
"""A simple test sandbox to play with creation of simulation environments"""
5
6
import networkx as nx
7
import yaml
8
9
from cyberbattle.simulation import model, model_test, actions_test
10
11
12
def main() -> None:
13
"""Simple environment sandbox"""
14
15
# Create a toy graph
16
graph = nx.DiGraph()
17
graph.add_edges_from([("a", "b"), ("b", "c")])
18
print(graph)
19
20
# create a random graph
21
graph = nx.cubical_graph()
22
23
graph = model.assign_random_labels(graph)
24
25
vulnerabilities = actions_test.SAMPLE_VULNERABILITIES
26
27
model.setup_yaml_serializer()
28
29
# Define an environment from this graph
30
env = model.Environment(network=graph, vulnerability_library=vulnerabilities, identifiers=actions_test.ENV_IDENTIFIERS)
31
32
model_test.check_reserializing(env)
33
34
model_test.check_reserializing(vulnerabilities)
35
36
# Save the environment to file as Yaml
37
with open("./simpleenv.yaml", "w") as file:
38
yaml.dump(env, file)
39
print(yaml.dump(env))
40
41
42
if __name__ == "__main__":
43
main()
44
45