#2887 - Node class changes to address some test failures. Addressed some inconsistencies around operating_state, amended instantiation of some Nodes in test environments
This commit is contained in:
@@ -119,13 +119,13 @@ def application_class():
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def file_system() -> FileSystem:
|
||||
# computer = Computer(hostname="fs_node", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
computer_cfg = {"type": "computer",
|
||||
"hostname": "fs_node",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "fs_node",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
computer = Computer.from_config(config=computer_cfg)
|
||||
computer.power_on()
|
||||
return computer.file_system
|
||||
@@ -136,23 +136,29 @@ def client_server() -> Tuple[Computer, Server]:
|
||||
network = Network()
|
||||
|
||||
# Create Computer
|
||||
computer = Computer(
|
||||
hostname="computer",
|
||||
ip_address="192.168.1.2",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "computer",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
computer: Computer = Computer.from_config(config=computer_cfg)
|
||||
computer.power_on()
|
||||
|
||||
# Create Server
|
||||
server = Server(
|
||||
hostname="server",
|
||||
ip_address="192.168.1.3",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
server_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "server",
|
||||
"ip_address": "192.168.1.3",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
server: Server = Server.from_config(config=server_cfg)
|
||||
server.power_on()
|
||||
|
||||
# Connect Computer and Server
|
||||
@@ -169,26 +175,33 @@ def client_switch_server() -> Tuple[Computer, Switch, Server]:
|
||||
network = Network()
|
||||
|
||||
# Create Computer
|
||||
computer = Computer(
|
||||
hostname="computer",
|
||||
ip_address="192.168.1.2",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "computer",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
computer: Computer = Computer.from_config(config=computer_cfg)
|
||||
computer.power_on()
|
||||
|
||||
# Create Server
|
||||
server = Server(
|
||||
hostname="server",
|
||||
ip_address="192.168.1.3",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
server_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "server",
|
||||
"ip_address": "192.168.1.3",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
server: Server = Server.from_config(config=server_cfg)
|
||||
server.power_on()
|
||||
|
||||
switch = Switch(hostname="switch", start_up_duration=0)
|
||||
# Create Switch
|
||||
switch: Switch = Switch.from_config(config={"type": "switch", "hostname": "switch", "start_up_duration": 0})
|
||||
switch.power_on()
|
||||
|
||||
network.connect(endpoint_a=computer.network_interface[1], endpoint_b=switch.network_interface[1])
|
||||
@@ -219,7 +232,7 @@ def example_network() -> Network:
|
||||
|
||||
# Router 1
|
||||
|
||||
router_1_cfg = {"hostname": "router_1", "type": "router"}
|
||||
router_1_cfg = {"hostname": "router_1", "type": "router", "start_up_duration":0}
|
||||
|
||||
# router_1 = Router(hostname="router_1", start_up_duration=0)
|
||||
router_1 = Router.from_config(config=router_1_cfg)
|
||||
@@ -229,7 +242,7 @@ def example_network() -> Network:
|
||||
|
||||
# Switch 1
|
||||
|
||||
switch_1_cfg = {"hostname": "switch_1", "type": "switch"}
|
||||
switch_1_cfg = {"hostname": "switch_1", "type": "switch", "start_up_duration": 0}
|
||||
|
||||
switch_1 = Switch.from_config(config=switch_1_cfg)
|
||||
|
||||
@@ -240,7 +253,7 @@ def example_network() -> Network:
|
||||
router_1.enable_port(1)
|
||||
|
||||
# Switch 2
|
||||
switch_2_config = {"hostname": "switch_2", "type": "switch", "num_ports": 8}
|
||||
switch_2_config = {"hostname": "switch_2", "type": "switch", "num_ports": 8, "start_up_duration":0}
|
||||
# switch_2 = Switch(hostname="switch_2", num_ports=8, start_up_duration=0)
|
||||
switch_2 = Switch.from_config(config=switch_2_config)
|
||||
switch_2.power_on()
|
||||
@@ -348,28 +361,34 @@ def install_stuff_to_sim(sim: Simulation):
|
||||
|
||||
# 1: Set up network hardware
|
||||
# 1.1: Configure the router
|
||||
router = Router.from_config(config={"type":"router", "hostname":"router", "num_ports":3, "start_up_duration":0})
|
||||
router = Router.from_config(config={"type": "router", "hostname": "router", "num_ports": 3, "start_up_duration": 0})
|
||||
router.power_on()
|
||||
router.configure_port(port=1, ip_address="10.0.1.1", subnet_mask="255.255.255.0")
|
||||
router.configure_port(port=2, ip_address="10.0.2.1", subnet_mask="255.255.255.0")
|
||||
|
||||
# 1.2: Create and connect switches
|
||||
switch_1 = Switch.from_config(config={"type":"switch", "hostname":"switch_1", "num_ports":6, "start_up_duration":0})
|
||||
switch_1 = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch_1", "num_ports": 6, "start_up_duration": 0}
|
||||
)
|
||||
switch_1.power_on()
|
||||
network.connect(endpoint_a=router.network_interface[1], endpoint_b=switch_1.network_interface[6])
|
||||
router.enable_port(1)
|
||||
switch_2 = Switch.from_config(config={"type":"switch", "hostname":"switch_2", "num_ports":6, "start_up_duration":0})
|
||||
switch_2 = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch_2", "num_ports": 6, "start_up_duration": 0}
|
||||
)
|
||||
switch_2.power_on()
|
||||
network.connect(endpoint_a=router.network_interface[2], endpoint_b=switch_2.network_interface[6])
|
||||
router.enable_port(2)
|
||||
|
||||
# 1.3: Create and connect computer
|
||||
client_1_cfg = {"type": "computer",
|
||||
"hostname": "client_1",
|
||||
"ip_address":"10.0.1.2",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"default_gateway": "10.0.1.1",
|
||||
"start_up_duration":0}
|
||||
client_1_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "client_1",
|
||||
"ip_address": "10.0.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "10.0.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
client_1: Computer = Computer.from_config(config=client_1_cfg)
|
||||
client_1.power_on()
|
||||
network.connect(
|
||||
@@ -378,24 +397,26 @@ def install_stuff_to_sim(sim: Simulation):
|
||||
)
|
||||
|
||||
# 1.4: Create and connect servers
|
||||
server_1_cfg = {"type": "server",
|
||||
"hostname":"server_1",
|
||||
"ip_address": "10.0.2.2",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"default_gateway":"10.0.2.1",
|
||||
"start_up_duration": 0}
|
||||
|
||||
server_1_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "server_1",
|
||||
"ip_address": "10.0.2.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "10.0.2.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
server_1: Server = Server.from_config(config=server_1_cfg)
|
||||
server_1.power_on()
|
||||
network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_2.network_interface[1])
|
||||
server_2_cfg = {"type": "server",
|
||||
"hostname":"server_2",
|
||||
"ip_address": "10.0.2.3",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"default_gateway":"10.0.2.1",
|
||||
"start_up_duration": 0}
|
||||
|
||||
server_2_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "server_2",
|
||||
"ip_address": "10.0.2.3",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "10.0.2.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
server_2: Server = Server.from_config(config=server_2_cfg)
|
||||
server_2.power_on()
|
||||
|
||||
@@ -12,12 +12,18 @@ def test_passing_actions_down(monkeypatch) -> None:
|
||||
|
||||
sim = Simulation()
|
||||
|
||||
pc1 = Computer.from_config(config={"type":"computer", "hostname":"PC-1", "ip_address":"10.10.1.1", "subnet_mask":"255.255.255.0"})
|
||||
pc1 = Computer.from_config(
|
||||
config={"type": "computer", "hostname": "PC-1", "ip_address": "10.10.1.1", "subnet_mask": "255.255.255.0"}
|
||||
)
|
||||
pc1.start_up_duration = 0
|
||||
pc1.power_on()
|
||||
pc2 = Computer.from_config(config={"type":"computer", "hostname":"PC-2", "ip_address":"10.10.1.2", "subnet_mask":"255.255.255.0"})
|
||||
srv = Server.from_config(config={"type":"server", "hostname":"WEBSERVER", "ip_address":"10.10.1.100", "subnet_mask":"255.255.255.0"})
|
||||
s1 = Switch.from_config(config={"type":"switch", "hostname":"switch1"})
|
||||
pc2 = Computer.from_config(
|
||||
config={"type": "computer", "hostname": "PC-2", "ip_address": "10.10.1.2", "subnet_mask": "255.255.255.0"}
|
||||
)
|
||||
srv = Server.from_config(
|
||||
config={"type": "server", "hostname": "WEBSERVER", "ip_address": "10.10.1.100", "subnet_mask": "255.255.255.0"}
|
||||
)
|
||||
s1 = Switch.from_config(config={"type": "switch", "hostname": "switch1"})
|
||||
|
||||
for n in [pc1, pc2, srv, s1]:
|
||||
sim.network.add_node(n)
|
||||
|
||||
@@ -5,8 +5,8 @@ from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router
|
||||
from primaite.simulator.network.hardware.nodes.network.firewall import Firewall
|
||||
from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router
|
||||
from primaite.utils.validation.ip_protocol import PROTOCOL_LOOKUP
|
||||
from primaite.utils.validation.port import PORT_LOOKUP
|
||||
from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config
|
||||
|
||||
@@ -3,6 +3,8 @@ from primaite.config.load import data_manipulation_config_path
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter
|
||||
from primaite.simulator.network.hardware.nodes.network.firewall import Firewall
|
||||
from tests.integration_tests.configuration_file_parsing import BASIC_CONFIG, DMZ_NETWORK, load_config
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import yaml
|
||||
|
||||
from primaite.session.environment import PrimaiteGymEnv
|
||||
from primaite.session.ray_envs import PrimaiteRayEnv, PrimaiteRayMARLEnv
|
||||
from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter
|
||||
from tests.conftest import TEST_ASSETS_ROOT
|
||||
|
||||
folder_path = TEST_ASSETS_ROOT / "configs" / "scenario_with_placeholders"
|
||||
|
||||
@@ -35,7 +35,7 @@ def test_node_startup_shutdown(game_and_agent_fixture: Tuple[PrimaiteGame, Proxy
|
||||
|
||||
assert client_1.operating_state == NodeOperatingState.SHUTTING_DOWN
|
||||
|
||||
for i in range(client_1.shut_down_duration + 1):
|
||||
for i in range(client_1.config.shut_down_duration + 1):
|
||||
action = ("do_nothing", {})
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
@@ -49,7 +49,7 @@ def test_node_startup_shutdown(game_and_agent_fixture: Tuple[PrimaiteGame, Proxy
|
||||
|
||||
assert client_1.operating_state == NodeOperatingState.BOOTING
|
||||
|
||||
for i in range(client_1.start_up_duration + 1):
|
||||
for i in range(client_1.config.start_up_duration + 1):
|
||||
action = ("do_nothing", {})
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
@@ -79,7 +79,7 @@ def test_node_cannot_be_shut_down_if_node_is_already_off(game_and_agent_fixture:
|
||||
client_1 = game.simulation.network.get_node_by_hostname("client_1")
|
||||
client_1.power_off()
|
||||
|
||||
for i in range(client_1.shut_down_duration + 1):
|
||||
for i in range(client_1.config.shut_down_duration + 1):
|
||||
action = ("do_nothing", {})
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
@@ -117,7 +117,9 @@ def test_firewall_observation():
|
||||
assert all(observation["PORTS"][i]["operating_status"] == 2 for i in range(1, 4))
|
||||
|
||||
# connect a switch to the firewall and check that only the correct port is updated
|
||||
switch: Switch = Switch.from_config(config={"type": "switch", "hostname":"switch", "num_ports":1, "operating_state":NodeOperatingState.ON})
|
||||
switch: Switch = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch", "num_ports": 1, "operating_state": NodeOperatingState.ON}
|
||||
)
|
||||
link = net.connect(firewall.network_interface[1], switch.network_interface[1])
|
||||
assert firewall.network_interface[1].enabled
|
||||
observation = firewall_observation.observe(firewall.describe_state())
|
||||
|
||||
@@ -56,12 +56,26 @@ def test_link_observation():
|
||||
"""Check the shape and contents of the link observation."""
|
||||
net = Network()
|
||||
sim = Simulation(network=net)
|
||||
switch: Switch = Switch.from_config(config={"type":"switch", "hostname":"switch", "num_ports":5, "operating_state":NodeOperatingState.ON})
|
||||
computer_1: Computer = Computer.from_config(config={"type": "computer",
|
||||
"hostname":"computer_1", "ip_address":"10.0.0.1", "subnet_mask":"255.255.255.0", "start_up_duration":0}
|
||||
switch: Switch = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch", "num_ports": 5, "operating_state": NodeOperatingState.ON}
|
||||
)
|
||||
computer_2: Computer = Computer.from_config(config={"type":"computer",
|
||||
"hostname":"computer_2", "ip_address":"10.0.0.2", "subnet_mask":"255.255.255.0", "start_up_duration":0}
|
||||
computer_1: Computer = Computer.from_config(
|
||||
config={
|
||||
"type": "computer",
|
||||
"hostname": "computer_1",
|
||||
"ip_address": "10.0.0.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
)
|
||||
computer_2: Computer = Computer.from_config(
|
||||
config={
|
||||
"type": "computer",
|
||||
"hostname": "computer_2",
|
||||
"ip_address": "10.0.0.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
)
|
||||
computer_1.power_on()
|
||||
computer_2.power_on()
|
||||
|
||||
@@ -163,7 +163,9 @@ def test_nic_monitored_traffic(simulation):
|
||||
pc2: Computer = simulation.network.get_node_by_hostname("client_2")
|
||||
|
||||
nic_obs = NICObservation(
|
||||
where=["network", "nodes", pc.config.hostname, "NICs", 1], include_nmne=False, monitored_traffic=monitored_traffic
|
||||
where=["network", "nodes", pc.config.hostname, "NICs", 1],
|
||||
include_nmne=False,
|
||||
monitored_traffic=monitored_traffic,
|
||||
)
|
||||
|
||||
simulation.pre_timestep(0) # apply timestep to whole sim
|
||||
|
||||
@@ -16,7 +16,9 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
def test_router_observation():
|
||||
"""Test adding/removing acl rules and enabling/disabling ports."""
|
||||
net = Network()
|
||||
router = Router.from_config(config={"type": "router", "hostname":"router", "num_ports":5, "operating_state":NodeOperatingState.ON})
|
||||
router = Router.from_config(
|
||||
config={"type": "router", "hostname": "router", "num_ports": 5, "operating_state": NodeOperatingState.ON}
|
||||
)
|
||||
|
||||
ports = [PortObservation(where=["NICs", i]) for i in range(1, 6)]
|
||||
acl = ACLObservation(
|
||||
@@ -89,7 +91,9 @@ def test_router_observation():
|
||||
assert all(observed_output["PORTS"][i]["operating_status"] == 2 for i in range(1, 6))
|
||||
|
||||
# connect a switch to the router and check that only the correct port is updated
|
||||
switch: Switch = Switch.from_config(config={"type": "switch", "hostname":"switch", "num_ports":1, "operating_state":NodeOperatingState.ON})
|
||||
switch: Switch = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch", "num_ports": 1, "operating_state": NodeOperatingState.ON}
|
||||
)
|
||||
link = net.connect(router.network_interface[1], switch.network_interface[1])
|
||||
assert router.network_interface[1].enabled
|
||||
observed_output = router_observation.observe(router.describe_state())
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
from primaite.session.environment import PrimaiteGymEnv
|
||||
from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState
|
||||
from primaite.simulator.network.hardware.nodes.host.host_node import HostNode
|
||||
from primaite.simulator.system.services.service import ServiceOperatingState
|
||||
from primaite.simulator.network.hardware.nodes.network.wireless_router import WirelessRouter
|
||||
from primaite.simulator.system.services.service import ServiceOperatingState
|
||||
from tests.conftest import TEST_ASSETS_ROOT
|
||||
|
||||
CFG_PATH = TEST_ASSETS_ROOT / "configs/test_primaite_session.yaml"
|
||||
|
||||
@@ -17,11 +17,11 @@ from typing import Tuple
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from primaite.simulator.network.hardware.nodes.network.firewall import Firewall
|
||||
from primaite.game.agent.interface import ProxyAgent
|
||||
from primaite.game.game import PrimaiteGame
|
||||
from primaite.session.environment import PrimaiteGymEnv
|
||||
from primaite.simulator.file_system.file_system_item_abc import FileSystemItemHealthStatus
|
||||
from primaite.simulator.network.hardware.nodes.network.firewall import Firewall
|
||||
from primaite.simulator.system.applications.application import ApplicationOperatingState
|
||||
from primaite.simulator.system.applications.web_browser import WebBrowser
|
||||
from primaite.simulator.system.software import SoftwareHealthState
|
||||
|
||||
@@ -8,14 +8,17 @@ from primaite.simulator.sim_container import Simulation
|
||||
|
||||
def test_file_observation():
|
||||
sim = Simulation()
|
||||
pc = Computer(hostname="beep", ip_address="123.123.123.123", subnet_mask="255.255.255.0")
|
||||
pc: Computer = Computer.from_config(config={"type":"computer",
|
||||
"hostname":"beep",
|
||||
"ip_address":"123.123.123.123",
|
||||
"subnet_mask":"255.255.255.0"})
|
||||
sim.network.add_node(pc)
|
||||
f = pc.file_system.create_file(file_name="dog.png")
|
||||
|
||||
state = sim.describe_state()
|
||||
|
||||
dog_file_obs = FileObservation(
|
||||
where=["network", "nodes", pc.hostname, "file_system", "folders", "root", "files", "dog.png"],
|
||||
where=["network", "nodes", pc.config.hostname, "file_system", "folders", "root", "files", "dog.png"],
|
||||
include_num_access=False,
|
||||
file_system_requires_scan=False,
|
||||
)
|
||||
|
||||
@@ -84,24 +84,28 @@ class BroadcastTestClient(Application, identifier="BroadcastTestClient"):
|
||||
def broadcast_network() -> Network:
|
||||
network = Network()
|
||||
|
||||
client_1_cfg = {"type": "computer",
|
||||
"hostname": "client_1",
|
||||
"ip_address":"192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration":0}
|
||||
client_1_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "client_1",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
client_1: Computer = Computer.from_config(config=client_1_cfg)
|
||||
client_1.power_on()
|
||||
client_1.software_manager.install(BroadcastTestClient)
|
||||
application_1 = client_1.software_manager.software["BroadcastTestClient"]
|
||||
application_1.run()
|
||||
client_2_cfg = {"type": "computer",
|
||||
"hostname": "client_2",
|
||||
"ip_address":"192.168.1.3",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration":0}
|
||||
client_2_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "client_2",
|
||||
"ip_address": "192.168.1.3",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
client_2: Computer = Computer.from_config(config=client_2_cfg)
|
||||
client_2.power_on()
|
||||
@@ -109,14 +113,16 @@ def broadcast_network() -> Network:
|
||||
application_2 = client_2.software_manager.software["BroadcastTestClient"]
|
||||
application_2.run()
|
||||
|
||||
server_1_cfg = {"type": "server",
|
||||
"hostname": "server_1",
|
||||
"ip_address":"192.168.1.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway":"192.168.1.1",
|
||||
"start_up_duration": 0}
|
||||
server_1_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "server_1",
|
||||
"ip_address": "192.168.1.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
server_1 :Server = Server.from_config(config=server_1_cfg)
|
||||
server_1: Server = Server.from_config(config=server_1_cfg)
|
||||
|
||||
server_1.power_on()
|
||||
|
||||
@@ -124,7 +130,9 @@ def broadcast_network() -> Network:
|
||||
service: BroadcastTestService = server_1.software_manager.software["BroadcastService"]
|
||||
service.start()
|
||||
|
||||
switch_1: Switch = Switch.from_config(config={"type": "switch", "hostname":"switch_1", "num_ports":6, "start_up_duration":0})
|
||||
switch_1: Switch = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch_1", "num_ports": 6, "start_up_duration": 0}
|
||||
)
|
||||
switch_1.power_on()
|
||||
|
||||
network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.network_interface[1])
|
||||
|
||||
@@ -41,7 +41,9 @@ def dmz_external_internal_network() -> Network:
|
||||
"""
|
||||
network = Network()
|
||||
|
||||
firewall_node: Firewall = Firewall(hostname="firewall_1", start_up_duration=0)
|
||||
firewall_node: Firewall = Firewall.from_config(
|
||||
config={"type": "firewall", "hostname": "firewall_1", "start_up_duration": 0}
|
||||
)
|
||||
firewall_node.power_on()
|
||||
# configure firewall ports
|
||||
firewall_node.configure_external_port(
|
||||
|
||||
@@ -34,54 +34,64 @@ def basic_network() -> Network:
|
||||
|
||||
# Creating two generic nodes for the C2 Server and the C2 Beacon.
|
||||
|
||||
node_a_cfg = {"type": "computer",
|
||||
"hostname": "node_a",
|
||||
"ip_address": "192.168.0.2",
|
||||
"subnet_mask": "255.255.255.252",
|
||||
"default_gateway": "192.168.0.1",
|
||||
"start_up_duration": 0}
|
||||
|
||||
node_a_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "node_a",
|
||||
"ip_address": "192.168.0.2",
|
||||
"subnet_mask": "255.255.255.252",
|
||||
"default_gateway": "192.168.0.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
node_a: Computer = Computer.from_config(config=node_a_cfg)
|
||||
node_a.power_on()
|
||||
node_a.software_manager.get_open_ports()
|
||||
node_a.software_manager.install(software_class=C2Server)
|
||||
|
||||
node_b_cfg = {"type": "computer",
|
||||
"hostname": "node_b",
|
||||
"ip_address": "192.168.255.2",
|
||||
"subnet_mask": "255.255.255.248",
|
||||
"default_gateway": "192.168.255.1",
|
||||
"start_up_duration": 0}
|
||||
|
||||
node_b_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "node_b",
|
||||
"ip_address": "192.168.255.2",
|
||||
"subnet_mask": "255.255.255.248",
|
||||
"default_gateway": "192.168.255.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
node_b: Computer = Computer.from_config(config=node_b_cfg)
|
||||
node_b.power_on()
|
||||
node_b.software_manager.install(software_class=C2Beacon)
|
||||
|
||||
# Creating a generic computer for testing remote terminal connections.
|
||||
node_c_cfg = {"type": "computer",
|
||||
"hostname": "node_c",
|
||||
"ip_address": "192.168.255.3",
|
||||
"subnet_mask": "255.255.255.248",
|
||||
"default_gateway": "192.168.255.1",
|
||||
"start_up_duration": 0}
|
||||
|
||||
node_c_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "node_c",
|
||||
"ip_address": "192.168.255.3",
|
||||
"subnet_mask": "255.255.255.248",
|
||||
"default_gateway": "192.168.255.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
node_c: Computer = Computer.from_config(config=node_c_cfg)
|
||||
node_c.power_on()
|
||||
|
||||
# Creating a router to sit between node 1 and node 2.
|
||||
router = Router.from_config(config={"type":"router", "hostname":"router", "num_ports":3, "start_up_duration":0})
|
||||
router = Router.from_config(config={"type": "router", "hostname": "router", "num_ports": 3, "start_up_duration": 0})
|
||||
# Default allow all.
|
||||
router.acl.add_rule(action=ACLAction.PERMIT)
|
||||
router.power_on()
|
||||
# Creating switches for each client.
|
||||
switch_1 = Switch.from_config(config={"type":"switch", "hostname":"switch_1", "num_ports":6, "start_up_duration":0})
|
||||
switch_1 = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch_1", "num_ports": 6, "start_up_duration": 0}
|
||||
)
|
||||
switch_1.power_on()
|
||||
|
||||
# Connecting the switches to the router.
|
||||
router.configure_port(port=1, ip_address="192.168.0.1", subnet_mask="255.255.255.252")
|
||||
network.connect(endpoint_a=router.network_interface[1], endpoint_b=switch_1.network_interface[6])
|
||||
|
||||
switch_2 = Switch.from_config(config={"type":"switch", "hostname":"switch_2", "num_ports":6, "start_up_duration":0})
|
||||
switch_2 = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch_2", "num_ports": 6, "start_up_duration": 0}
|
||||
)
|
||||
switch_2.power_on()
|
||||
|
||||
network.connect(endpoint_a=router.network_interface[2], endpoint_b=switch_2.network_interface[6])
|
||||
|
||||
@@ -72,7 +72,7 @@ def test_dns_client_requests_offline_dns_server(dns_client_and_dns_server):
|
||||
|
||||
server.power_off()
|
||||
|
||||
for i in range(server.shut_down_duration + 1):
|
||||
for i in range(server.config.shut_down_duration + 1):
|
||||
server.apply_timestep(timestep=i)
|
||||
|
||||
assert server.operating_state == NodeOperatingState.OFF
|
||||
|
||||
@@ -13,13 +13,15 @@ from primaite.simulator.system.services.service import Service, ServiceOperating
|
||||
def populated_node(
|
||||
service_class,
|
||||
) -> Tuple[Server, Service]:
|
||||
server = Server(
|
||||
hostname="server",
|
||||
ip_address="192.168.0.1",
|
||||
subnet_mask="255.255.255.0",
|
||||
start_up_duration=0,
|
||||
shut_down_duration=0,
|
||||
)
|
||||
server_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "server",
|
||||
"ip_address": "192.168.0.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
"shut_down_duration": 0,
|
||||
}
|
||||
server: Server = Server.from_config(config=server_cfg)
|
||||
server.power_on()
|
||||
server.software_manager.install(service_class)
|
||||
|
||||
@@ -31,14 +33,16 @@ def populated_node(
|
||||
|
||||
def test_service_on_offline_node(service_class):
|
||||
"""Test to check that the service cannot be interacted with when node it is on is off."""
|
||||
computer: Computer = Computer(
|
||||
hostname="test_computer",
|
||||
ip_address="192.168.1.2",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
shut_down_duration=0,
|
||||
)
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "test_computer",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
"shut_down_duration": 0,
|
||||
}
|
||||
computer: Computer = Computer.from_config(config=computer_cfg)
|
||||
computer.power_on()
|
||||
computer.software_manager.install(service_class)
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ def test_web_page_request_from_shut_down_server(web_client_and_web_server):
|
||||
|
||||
server.power_off()
|
||||
|
||||
for i in range(server.shut_down_duration + 1):
|
||||
for i in range(server.config.shut_down_duration + 1):
|
||||
server.apply_timestep(timestep=i)
|
||||
|
||||
# node should be off
|
||||
|
||||
@@ -7,10 +7,7 @@ from primaite.simulator.network.hardware.nodes.network.switch import Switch
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def switch() -> Switch:
|
||||
switch_cfg = {"type": "switch",
|
||||
"hostname": "switch_1",
|
||||
"num_ports": 8,
|
||||
"start_up_duration": 0}
|
||||
switch_cfg = {"type": "switch", "hostname": "switch_1", "num_ports": 8, "start_up_duration": 0}
|
||||
switch: Switch = Switch.from_config(config=switch_cfg)
|
||||
switch.power_on()
|
||||
switch.show()
|
||||
|
||||
@@ -7,10 +7,7 @@ from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
|
||||
@pytest.fixture
|
||||
def node() -> Node:
|
||||
computer_cfg = {"type": "computer",
|
||||
"hostname": "test",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0"}
|
||||
computer_cfg = {"type": "computer", "hostname": "test", "ip_address": "192.168.1.2", "subnet_mask": "255.255.255.0"}
|
||||
computer = Computer.from_config(config=computer_cfg)
|
||||
|
||||
return computer
|
||||
|
||||
@@ -12,13 +12,12 @@ from tests.conftest import DummyApplication, DummyService
|
||||
|
||||
@pytest.fixture
|
||||
def node() -> Node:
|
||||
computer_cfg = {"type": "computer",
|
||||
"hostname": "test",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"shut_down_duration": 3,
|
||||
"operating_state": "OFF",
|
||||
}
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "test",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
}
|
||||
computer = Computer.from_config(config=computer_cfg)
|
||||
|
||||
return computer
|
||||
|
||||
@@ -74,7 +74,16 @@ def test_removing_node_that_does_not_exist(network):
|
||||
"""Node that does not exist on network should not affect existing nodes."""
|
||||
assert len(network.nodes) is 7
|
||||
|
||||
network.remove_node(Computer.from_config(config = {"type":"computer","hostname":"new_node", "ip_address":"192.168.1.2", "subnet_mask":"255.255.255.0"}))
|
||||
network.remove_node(
|
||||
Computer.from_config(
|
||||
config={
|
||||
"type": "computer",
|
||||
"hostname": "new_node",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
}
|
||||
)
|
||||
)
|
||||
assert len(network.nodes) is 7
|
||||
|
||||
|
||||
|
||||
@@ -16,23 +16,25 @@ def basic_c2_network() -> Network:
|
||||
network = Network()
|
||||
|
||||
# Creating two generic nodes for the C2 Server and the C2 Beacon.
|
||||
computer_a_cfg = {"type": "computer",
|
||||
"hostname": "computer_a",
|
||||
"ip_address": "192.168.0.1",
|
||||
"subnet_mask": "255.255.255.252",
|
||||
"start_up_duration": 0}
|
||||
computer_a = Computer.from_config(config = computer_a_cfg)
|
||||
computer_a_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "computer_a",
|
||||
"ip_address": "192.168.0.1",
|
||||
"subnet_mask": "255.255.255.252",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
computer_a = Computer.from_config(config=computer_a_cfg)
|
||||
|
||||
computer_a.power_on()
|
||||
computer_a.software_manager.install(software_class=C2Server)
|
||||
|
||||
|
||||
computer_b_cfg = {"type": "computer",
|
||||
"hostname": "computer_b",
|
||||
"ip_address": "192.168.0.2",
|
||||
"subnet_mask": "255.255.255.252",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
computer_b_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "computer_b",
|
||||
"ip_address": "192.168.0.2",
|
||||
"subnet_mask": "255.255.255.252",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
computer_b = Computer.from_config(config=computer_b_cfg)
|
||||
|
||||
|
||||
@@ -12,12 +12,13 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def dos_bot() -> DoSBot:
|
||||
computer_cfg = {"type":"computer",
|
||||
"hostname": "compromised_pc",
|
||||
"ip_address": "192.168.0.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "compromised_pc",
|
||||
"ip_address": "192.168.0.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
computer: Computer = Computer.from_config(config=computer_cfg)
|
||||
|
||||
computer.power_on()
|
||||
@@ -39,7 +40,7 @@ def test_dos_bot_cannot_run_when_node_offline(dos_bot):
|
||||
|
||||
dos_bot_node.power_off()
|
||||
|
||||
for i in range(dos_bot_node.shut_down_duration + 1):
|
||||
for i in range(dos_bot_node.config.shut_down_duration + 1):
|
||||
dos_bot_node.apply_timestep(timestep=i)
|
||||
|
||||
assert dos_bot_node.operating_state is NodeOperatingState.OFF
|
||||
|
||||
@@ -17,14 +17,28 @@ from primaite.simulator.system.services.database.database_service import Databas
|
||||
def database_client_on_computer() -> Tuple[DatabaseClient, Computer]:
|
||||
network = Network()
|
||||
|
||||
db_server: Server = Server.from_config(config={"type": "server", "hostname":"db_server", "ip_address":"192.168.0.1", "subnet_mask":"255.255.255.0", "start_up_duration":0})
|
||||
db_server: Server = Server.from_config(
|
||||
config={
|
||||
"type": "server",
|
||||
"hostname": "db_server",
|
||||
"ip_address": "192.168.0.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
)
|
||||
db_server.power_on()
|
||||
db_server.software_manager.install(DatabaseService)
|
||||
db_server.software_manager.software["DatabaseService"].start()
|
||||
|
||||
db_client: Computer = Computer.from_config(config = {"type":"computer",
|
||||
"hostname":"db_client", "ip_address":"192.168.0.2", "subnet_mask":"255.255.255.0", "start_up_duration":0
|
||||
})
|
||||
db_client: Computer = Computer.from_config(
|
||||
config={
|
||||
"type": "computer",
|
||||
"hostname": "db_client",
|
||||
"ip_address": "192.168.0.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
)
|
||||
db_client.power_on()
|
||||
db_client.software_manager.install(DatabaseClient)
|
||||
|
||||
|
||||
@@ -12,8 +12,15 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def web_browser() -> WebBrowser:
|
||||
computer_cfg = {"type": "computer", "hostname": "web_client", "ip_address": "192.168.1.11", "subnet_mask": "255.255.255.0", "default_gateway": "192.168.1.1", "start_up_duration": 0}
|
||||
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "web_client",
|
||||
"ip_address": "192.168.1.11",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
computer: Computer = Computer.from_config(config=computer_cfg)
|
||||
|
||||
computer.power_on()
|
||||
@@ -25,8 +32,15 @@ def web_browser() -> WebBrowser:
|
||||
|
||||
|
||||
def test_create_web_client():
|
||||
computer_cfg = {"type": "computer", "hostname": "web_client", "ip_address": "192.168.1.11", "subnet_mask": "255.255.255.0", "default_gateway": "192.168.1.1", "start_up_duration": 0}
|
||||
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "web_client",
|
||||
"ip_address": "192.168.1.11",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
computer: Computer = Computer.from_config(config=computer_cfg)
|
||||
|
||||
computer.power_on()
|
||||
|
||||
@@ -8,12 +8,13 @@ from primaite.simulator.system.services.database.database_service import Databas
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def database_server() -> Node:
|
||||
node_cfg = {"type": "computer",
|
||||
"hostname": "db_node",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
node_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "db_node",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
node = Computer.from_config(config=node_cfg)
|
||||
node.power_on()
|
||||
|
||||
@@ -14,21 +14,15 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def dns_client() -> Computer:
|
||||
|
||||
node_cfg = {"type": "computer",
|
||||
"hostname": "dns_client",
|
||||
"ip_address": "192.168.1.11",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"dns_server": IPv4Address("192.168.1.10")}
|
||||
node_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "dns_client",
|
||||
"ip_address": "192.168.1.11",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"dns_server": IPv4Address("192.168.1.10"),
|
||||
}
|
||||
node = Computer.from_config(config=node_cfg)
|
||||
# node = Computer(
|
||||
# hostname="dns_client",
|
||||
# ip_address="192.168.1.11",
|
||||
# subnet_mask="255.255.255.0",
|
||||
# default_gateway="192.168.1.1",
|
||||
# dns_server=IPv4Address("192.168.1.10"),
|
||||
# )
|
||||
return node
|
||||
|
||||
|
||||
@@ -69,7 +63,7 @@ def test_dns_client_check_domain_exists_when_not_running(dns_client):
|
||||
|
||||
dns_client.power_off()
|
||||
|
||||
for i in range(dns_client.shut_down_duration + 1):
|
||||
for i in range(dns_client.config.shut_down_duration + 1):
|
||||
dns_client.apply_timestep(timestep=i)
|
||||
|
||||
assert dns_client.operating_state is NodeOperatingState.OFF
|
||||
|
||||
@@ -16,12 +16,14 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def dns_server() -> Node:
|
||||
node_cfg = {"type": "server",
|
||||
"hostname": "dns_server",
|
||||
"ip_address": "192.168.1.10",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration":0}
|
||||
node_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "dns_server",
|
||||
"ip_address": "192.168.1.10",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
node = Server.from_config(config=node_cfg)
|
||||
node.power_on()
|
||||
node.software_manager.install(software_class=DNSServer)
|
||||
@@ -55,12 +57,13 @@ def test_dns_server_receive(dns_server):
|
||||
# register the web server in the domain controller
|
||||
dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12"))
|
||||
|
||||
client_cfg = {"type": "computer",
|
||||
"hostname": "client",
|
||||
"ip_address": "192.168.1.11",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
client_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "client",
|
||||
"ip_address": "192.168.1.11",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
client = Computer.from_config(config=client_cfg)
|
||||
client.power_on()
|
||||
client.dns_server = IPv4Address("192.168.1.10")
|
||||
|
||||
@@ -16,13 +16,14 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def ftp_client() -> Node:
|
||||
node_cfg = {"type": "computer",
|
||||
"hostname": "ftp_client",
|
||||
"ip_address":"192.168.1.11",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"default_gateway":"192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
node_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "ftp_client",
|
||||
"ip_address": "192.168.1.11",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
node = Computer.from_config(config=node_cfg)
|
||||
node.power_on()
|
||||
return node
|
||||
|
||||
@@ -14,12 +14,14 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def ftp_server() -> Node:
|
||||
node_cfg = {"type": "server",
|
||||
"hostname":"ftp_server",
|
||||
"ip_address":"192.168.1.10",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration":0}
|
||||
node_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "ftp_server",
|
||||
"ip_address": "192.168.1.10",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
node = Server.from_config(config=node_cfg)
|
||||
node.power_on()
|
||||
node.software_manager.install(software_class=FTPServer)
|
||||
|
||||
@@ -29,8 +29,8 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def terminal_on_computer() -> Tuple[Terminal, Computer]:
|
||||
computer: Computer = Computer(
|
||||
hostname="node_a", ip_address="192.168.0.10", subnet_mask="255.255.255.0", start_up_duration=0
|
||||
computer: Computer = Computer.from_config(config={"type":"computer",
|
||||
"hostname":"node_a", "ip_address":"192.168.0.10", "subnet_mask":"255.255.255.0", "start_up_duration":0}
|
||||
)
|
||||
computer.power_on()
|
||||
terminal: Terminal = computer.software_manager.software.get("Terminal")
|
||||
@@ -41,11 +41,19 @@ def terminal_on_computer() -> Tuple[Terminal, Computer]:
|
||||
@pytest.fixture(scope="function")
|
||||
def basic_network() -> Network:
|
||||
network = Network()
|
||||
node_a = Computer(hostname="node_a", ip_address="192.168.0.10", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
node_a = Computer.from_config(config={"type":"computer",
|
||||
"hostname":"node_a",
|
||||
"ip_address":"192.168.0.10",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"start_up_duration":0})
|
||||
node_a.power_on()
|
||||
node_a.software_manager.get_open_ports()
|
||||
|
||||
node_b = Computer(hostname="node_b", ip_address="192.168.0.11", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
node_b = Computer.from_config(config={"type":"computer",
|
||||
"hostname":"node_b",
|
||||
"ip_address":"192.168.0.11",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"start_up_duration":0})
|
||||
node_b.power_on()
|
||||
network.connect(node_a.network_interface[1], node_b.network_interface[1])
|
||||
|
||||
@@ -57,18 +65,20 @@ def wireless_wan_network():
|
||||
network = Network()
|
||||
|
||||
# Configure PC A
|
||||
pc_a = Computer(
|
||||
hostname="pc_a",
|
||||
ip_address="192.168.0.2",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.0.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
pc_a_cfg = {"type": "computer",
|
||||
"hostname":"pc_a",
|
||||
"ip_address":"192.168.0.2",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"default_gateway":"192.168.0.1",
|
||||
"start_up_duration":0,
|
||||
}
|
||||
|
||||
pc_a = Computer.from_config(config=pc_a_cfg)
|
||||
pc_a.power_on()
|
||||
network.add_node(pc_a)
|
||||
|
||||
# Configure Router 1
|
||||
router_1 = WirelessRouter(hostname="router_1", start_up_duration=0, airspace=network.airspace)
|
||||
router_1 = WirelessRouter.from_config(config={"type":"wireless_router", "hostname":"router_1", "start_up_duration":0, "airspace":network.airspace})
|
||||
router_1.power_on()
|
||||
network.add_node(router_1)
|
||||
|
||||
@@ -88,18 +98,21 @@ def wireless_wan_network():
|
||||
)
|
||||
|
||||
# Configure PC B
|
||||
pc_b = Computer(
|
||||
hostname="pc_b",
|
||||
ip_address="192.168.2.2",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.2.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
|
||||
pc_b_cfg = {"type": "computer",
|
||||
"hostname":"pc_b",
|
||||
"ip_address":"192.168.2.2",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"default_gateway":"192.168.2.1",
|
||||
"start_up_duration":0,
|
||||
}
|
||||
|
||||
pc_b = Computer.from_config(config=pc_b_cfg)
|
||||
pc_b.power_on()
|
||||
network.add_node(pc_b)
|
||||
|
||||
# Configure Router 2
|
||||
router_2 = WirelessRouter(hostname="router_2", start_up_duration=0, airspace=network.airspace)
|
||||
router_2 = WirelessRouter.from_config(config={"type":"wireless_router", "hostname":"router_2", "start_up_duration":0, "airspace":network.airspace})
|
||||
router_2.power_on()
|
||||
network.add_node(router_2)
|
||||
|
||||
@@ -131,7 +144,7 @@ def game_and_agent_fixture(game_and_agent):
|
||||
game, agent = game_and_agent
|
||||
|
||||
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
|
||||
client_1.start_up_duration = 3
|
||||
client_1.config.start_up_duration = 3
|
||||
|
||||
return game, agent
|
||||
|
||||
@@ -143,7 +156,11 @@ def test_terminal_creation(terminal_on_computer):
|
||||
|
||||
def test_terminal_install_default():
|
||||
"""Terminal should be auto installed onto Nodes"""
|
||||
computer = Computer(hostname="node_a", ip_address="192.168.0.10", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
computer: Computer = Computer.from_config(config={"type":"computer",
|
||||
"hostname":"node_a",
|
||||
"ip_address":"192.168.0.10",
|
||||
"subnet_mask":"255.255.255.0",
|
||||
"start_up_duration":0})
|
||||
computer.power_on()
|
||||
|
||||
assert computer.software_manager.software.get("Terminal")
|
||||
@@ -151,7 +168,7 @@ def test_terminal_install_default():
|
||||
|
||||
def test_terminal_not_on_switch():
|
||||
"""Ensure terminal does not auto-install to switch"""
|
||||
test_switch = Switch(hostname="Test")
|
||||
test_switch = Switch.from_config(config={"type":"switch", "hostname":"Test"})
|
||||
|
||||
assert not test_switch.software_manager.software.get("Terminal")
|
||||
|
||||
@@ -357,8 +374,6 @@ def test_multiple_remote_terminals_same_node(basic_network):
|
||||
for attempt in range(3):
|
||||
remote_connection = terminal_a.login(username="admin", password="admin", ip_address="192.168.0.11")
|
||||
|
||||
terminal_a.show()
|
||||
|
||||
assert len(terminal_a._connections) == 3
|
||||
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def web_server() -> Server:
|
||||
node_cfg = {"type": "server",
|
||||
"hostname":"web_server",
|
||||
"ip_address": "192.168.1.10",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway":"192.168.1.1",
|
||||
"start_up_duration":0 }
|
||||
node_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "web_server",
|
||||
"ip_address": "192.168.1.10",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
node = Server.from_config(config=node_cfg)
|
||||
node.power_on()
|
||||
node.software_manager.install(WebServer)
|
||||
|
||||
Reference in New Issue
Block a user