Path: blob/main/cyberbattle/samples/simple/simpleenv.py
597 views
# Copyright (c) Microsoft Corporation.1# Licensed under the MIT License.23"""A simple test sandbox to play with creation of simulation environments"""45import networkx as nx6import yaml78from cyberbattle.simulation import model, model_test, actions_test91011def main() -> None:12"""Simple environment sandbox"""1314# Create a toy graph15graph = nx.DiGraph()16graph.add_edges_from([("a", "b"), ("b", "c")])17print(graph)1819# create a random graph20graph = nx.cubical_graph()2122graph = model.assign_random_labels(graph)2324vulnerabilities = actions_test.SAMPLE_VULNERABILITIES2526model.setup_yaml_serializer()2728# Define an environment from this graph29env = model.Environment(network=graph, vulnerability_library=vulnerabilities, identifiers=actions_test.ENV_IDENTIFIERS)3031model_test.check_reserializing(env)3233model_test.check_reserializing(vulnerabilities)3435# Save the environment to file as Yaml36with open("./simpleenv.yaml", "w") as file:37yaml.dump(env, file)38print(yaml.dump(env))394041if __name__ == "__main__":42main()434445