Files
PrimAITE/sandbox.ipynb
2023-09-21 10:42:26 +01:00

154 lines
3.6 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from primaite.simulator.network.networks import arcd_uc2_network\n",
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"net = arcd_uc2_network()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"random_node = list(net.nodes.keys())[0]\n",
"f = net.nodes[random_node].file_system.create_file(file_name=\"testfile\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f.describe_state()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def test_file_observation():\n",
" from primaite.simulator.sim_container import Simulation\n",
" from primaite.simulator.network.hardware.nodes.computer import Computer\n",
" from primaite.game.actor.observations import FileObservation\n",
"\n",
" sim = Simulation()\n",
" pc = Computer(hostname=\"beep\", ip_address=\"123.123.123.123\", subnet_mask=\"255.255.255.0\")\n",
" sim.network.add_node(pc)\n",
" f = pc.file_system.create_file(file_name=\"dog.png\")\n",
"\n",
" dog_file_obs = FileObservation(where=['network','nodes',pc.uuid,'file_system'])\n",
" print(sim.describe_state())\n",
"test_file_observation()"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2023-09-21 10:41:35,339: Added node f03fec1b-927d-4d5a-8de9-1ef426052932 to Network f7400348-31e5-440e-8eb5-42366326d9d1\n"
]
},
{
"data": {
"text/plain": [
"{'health_status': 1}"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from primaite.simulator.sim_container import Simulation\n",
"from primaite.simulator.network.hardware.nodes.computer import Computer\n",
"from primaite.game.actor.observations import FileObservation\n",
"\n",
"sim = Simulation()\n",
"pc = Computer(hostname=\"beep\", ip_address=\"123.123.123.123\", subnet_mask=\"255.255.255.0\")\n",
"sim.network.add_node(pc)\n",
"f = pc.file_system.create_file(file_name=\"dog.png\")\n",
"\n",
"state = sim.describe_state()\n",
"\n",
"dog_file_obs = FileObservation(where=['network','nodes',pc.uuid,'file_system', 'folders','root','files','dog.png'])\n",
"o = dog_file_obs(state)\n",
"o"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Dict(health_status:Discrete(6))"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dog_file_obs.space"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}