#2257: temporarily commit changes - added startup and shut down durations to node config + adding routes
This commit is contained in:
@@ -266,6 +266,10 @@ class PrimaiteGame:
|
||||
game.ref_map_services[service_ref] = new_service.uuid
|
||||
else:
|
||||
_LOGGER.warning(f"service type not found {service_type}")
|
||||
|
||||
# start the service
|
||||
new_service.start()
|
||||
|
||||
# service-dependent options
|
||||
if service_type == "DNSClient":
|
||||
if "options" in service_cfg:
|
||||
@@ -282,17 +286,14 @@ class PrimaiteGame:
|
||||
if "options" in service_cfg:
|
||||
opt = service_cfg["options"]
|
||||
new_service.configure_backup(backup_server=IPv4Address(opt.get("backup_server_ip")))
|
||||
new_service.start()
|
||||
if service_type == "FTPServer":
|
||||
if "options" in service_cfg:
|
||||
opt = service_cfg["options"]
|
||||
new_service.server_password = opt.get("server_password")
|
||||
new_service.start()
|
||||
if service_type == "NTPClient":
|
||||
if "options" in service_cfg:
|
||||
opt = service_cfg["options"]
|
||||
new_service.ntp_server = IPv4Address(opt.get("ntp_server_ip"))
|
||||
new_service.start()
|
||||
if "applications" in node_cfg:
|
||||
for application_cfg in node_cfg["applications"]:
|
||||
new_application = None
|
||||
@@ -306,6 +307,9 @@ class PrimaiteGame:
|
||||
else:
|
||||
_LOGGER.warning(f"application type not found {application_type}")
|
||||
|
||||
# run the application
|
||||
new_application.run()
|
||||
|
||||
if application_type == "DataManipulationBot":
|
||||
if "options" in application_cfg:
|
||||
opt = application_cfg["options"]
|
||||
@@ -327,7 +331,6 @@ class PrimaiteGame:
|
||||
if "options" in application_cfg:
|
||||
opt = application_cfg["options"]
|
||||
new_application.target_url = opt.get("target_url")
|
||||
|
||||
elif application_type == "DoSBot":
|
||||
if "options" in application_cfg:
|
||||
opt = application_cfg["options"]
|
||||
@@ -344,6 +347,9 @@ class PrimaiteGame:
|
||||
for nic_num, nic_cfg in node_cfg["network_interfaces"].items():
|
||||
new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"]))
|
||||
|
||||
new_node.start_up_duration = int(node_cfg.get("start_up_duration", 3))
|
||||
new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3))
|
||||
|
||||
net.add_node(new_node)
|
||||
new_node.power_on()
|
||||
game.ref_map_nodes[node_ref] = new_node.uuid
|
||||
|
||||
@@ -1276,4 +1276,12 @@ class Router(NetworkNode):
|
||||
if "acl" in cfg:
|
||||
new.acl._default_config = cfg["acl"] # save the config to allow resetting
|
||||
new.acl._reset_rules_to_default() # read the config and apply rules
|
||||
if "routes" in cfg:
|
||||
for route in cfg.get("routes"):
|
||||
new.route_table.add_route(
|
||||
address=IPv4Address(route.get("address")),
|
||||
subnet_mask=IPv4Address(route.get("subnet_mask")),
|
||||
next_hop_ip_address=IPv4Address(route.get("subnet_mask")),
|
||||
metric=float(route.get("metric")),
|
||||
)
|
||||
return new
|
||||
|
||||
@@ -9,26 +9,26 @@
|
||||
# . -------------- -------------- -------------- .
|
||||
# . | client_1 |------| switch_1 |------| router_1 | .
|
||||
# . -------------- -------------- -------------- .
|
||||
# . (Computer) | .
|
||||
# ......................................................|.....................
|
||||
# |
|
||||
# |
|
||||
# ......................................................|.....................
|
||||
# . | .
|
||||
# . DMZ Network | .
|
||||
# . | .
|
||||
# . -------------- -------------- -------------- .
|
||||
# . | client_2 |------| switch_2 |------| router_2 | .
|
||||
# . -------------- -------------- -------------- .
|
||||
# . (Computer) | .
|
||||
# ......................................................|.....................
|
||||
# |
|
||||
# External Network |
|
||||
# |
|
||||
# |
|
||||
# ----------------------- -------------- ---------------------
|
||||
# | external_computer |------| switch_3 |------| external_server |
|
||||
# ----------------------- -------------- ---------------------
|
||||
# . (Computer) | .
|
||||
# ........................................................|.....................
|
||||
# |
|
||||
# |
|
||||
# ........................................................|.....................
|
||||
# . | .
|
||||
# . DMZ Network | .
|
||||
# . | .
|
||||
# . ---------------- -------------- -------------- .
|
||||
# . | dmz_server |------| switch_2 |------| router_2 | .
|
||||
# . ---------------- -------------- -------------- .
|
||||
# . (Computer) | .
|
||||
# ........................................................|...................
|
||||
# |
|
||||
# External Network |
|
||||
# |
|
||||
# |
|
||||
# ----------------------- -------------- ---------------------
|
||||
# | external_computer |------| switch_3 |------| external_server |
|
||||
# ----------------------- -------------- ---------------------
|
||||
#
|
||||
training_config:
|
||||
rl_framework: SB3
|
||||
@@ -63,7 +63,7 @@ game:
|
||||
- UDP
|
||||
|
||||
agents:
|
||||
- ref: client_2_green_user
|
||||
- ref: client_1_green_user
|
||||
team: GREEN
|
||||
type: GreenWebBrowsingAgent
|
||||
observation_space:
|
||||
@@ -74,7 +74,7 @@ agents:
|
||||
- type: NODE_APPLICATION_EXECUTE
|
||||
options:
|
||||
nodes:
|
||||
- node_name: client_2
|
||||
- node_name: client_1
|
||||
applications:
|
||||
- application_name: WebBrowser
|
||||
max_folders_per_node: 1
|
||||
@@ -102,17 +102,23 @@ simulation:
|
||||
ip_address: 192.168.0.10
|
||||
subnet_mask: 255.255.255.0
|
||||
default_gateway: 192.168.0.1
|
||||
dns_server: 192.168.20.10
|
||||
dns_server: 192.168.20.11
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
|
||||
- ref: switch_1
|
||||
type: switch
|
||||
hostname: switch_1
|
||||
num_ports: 8
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
|
||||
- ref: router_1
|
||||
type: router
|
||||
hostname: router_1
|
||||
num_ports: 5
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
ports:
|
||||
1:
|
||||
ip_address: 192.168.0.1
|
||||
@@ -128,24 +134,43 @@ simulation:
|
||||
23:
|
||||
action: PERMIT
|
||||
protocol: ICMP
|
||||
routes:
|
||||
- address: 192.168.10.10
|
||||
subnet_mask: 255.255.255.0
|
||||
next_hop_ip_address: 192.168.11.1
|
||||
metric: 0
|
||||
- address: 192.168.20.10
|
||||
subnet_mask: 255.255.255.0
|
||||
next_hop_ip_address: 192.168.11.1
|
||||
metric: 0
|
||||
- address: 192.168.20.11
|
||||
subnet_mask: 255.255.255.0
|
||||
next_hop_ip_address: 192.168.11.1
|
||||
metric: 0
|
||||
|
||||
- ref: client_2
|
||||
type: computer
|
||||
hostname: client_2
|
||||
- ref: dmz_server
|
||||
type: server
|
||||
hostname: dmz_server
|
||||
ip_address: 192.168.10.10
|
||||
subnet_mask: 255.255.255.0
|
||||
default_gateway: 192.168.10.1
|
||||
dns_server: 192.168.20.10
|
||||
dns_server: 192.168.20.11
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
|
||||
- ref: switch_2
|
||||
type: switch
|
||||
hostname: switch_2
|
||||
num_ports: 8
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
|
||||
- ref: router_2
|
||||
type: router
|
||||
hostname: router_2
|
||||
num_ports: 5
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
ports:
|
||||
1:
|
||||
ip_address: 192.168.10.1
|
||||
@@ -164,11 +189,18 @@ simulation:
|
||||
23:
|
||||
action: PERMIT
|
||||
protocol: ICMP
|
||||
routes:
|
||||
- address: 192.168.0.10
|
||||
subnet_mask: 255.255.255.0
|
||||
next_hop_ip_address: 192.168.1.1
|
||||
metric: 0
|
||||
|
||||
- ref: switch_3
|
||||
type: switch
|
||||
hostname: switch_3
|
||||
num_ports: 8
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
|
||||
- ref: external_computer
|
||||
type: computer
|
||||
@@ -176,14 +208,18 @@ simulation:
|
||||
ip_address: 192.168.20.10
|
||||
subnet_mask: 255.255.255.0
|
||||
default_gateway: 192.168.20.1
|
||||
dns_server: 192.168.20.10
|
||||
dns_server: 192.168.20.11
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
|
||||
- ref: external_server
|
||||
type: server
|
||||
hostname: external_server
|
||||
ip_address: 192.168.20.10
|
||||
ip_address: 192.168.20.11
|
||||
subnet_mask: 255.255.255.0
|
||||
default_gateway: 192.168.20.1
|
||||
start_up_duration: 0
|
||||
shut_down_duration: 0
|
||||
services:
|
||||
- ref: domain_controller_dns_server
|
||||
type: DNSServer
|
||||
@@ -208,8 +244,8 @@ simulation:
|
||||
endpoint_a_port: 1
|
||||
endpoint_b_ref: switch_2
|
||||
endpoint_b_port: 8
|
||||
- ref: client_2___switch_2
|
||||
endpoint_a_ref: client_2
|
||||
- ref: dmz_server___switch_2
|
||||
endpoint_a_ref: dmz_server
|
||||
endpoint_a_port: 1
|
||||
endpoint_b_ref: switch_2
|
||||
endpoint_b_port: 1
|
||||
|
||||
@@ -5,6 +5,9 @@ import yaml
|
||||
|
||||
from primaite.game.game import PrimaiteGame
|
||||
from primaite.simulator.network.container import Network
|
||||
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 Router
|
||||
from tests import TEST_ASSETS_ROOT
|
||||
|
||||
DMZ_NETWORK = TEST_ASSETS_ROOT / "configs/dmz_network.yaml"
|
||||
@@ -27,12 +30,27 @@ def test_dmz_config():
|
||||
assert len(network.nodes) == 9 # 9 nodes in network
|
||||
assert len(network.routers) == 2 # 2 routers in network
|
||||
assert len(network.switches) == 3 # 3 switches in network
|
||||
assert len(network.servers) == 1 # 1 server in network
|
||||
assert len(network.servers) == 2 # 2 servers in network
|
||||
|
||||
|
||||
def test_router_routes_are_correctly_added():
|
||||
"""Test that makes sure that router routes have been added from the configuration file."""
|
||||
pass
|
||||
game = load_config(DMZ_NETWORK)
|
||||
|
||||
network: Network = game.simulation.network
|
||||
|
||||
router_1: Router = network.get_node_by_hostname("router_1")
|
||||
client_1: Computer = network.get_node_by_hostname("client_1")
|
||||
dmz_server: Server = network.get_node_by_hostname("dmz_server")
|
||||
external_computer: Computer = network.get_node_by_hostname("external_computer")
|
||||
external_server: Server = network.get_node_by_hostname("external_server")
|
||||
|
||||
# test that client_1 has a route to the DMZ and external nodes - they are on a second router
|
||||
|
||||
# there should be a route to the dmz server
|
||||
assert router_1.route_table.find_best_route(dmz_server.network_interface[1].ip_address)
|
||||
# ping DMZ server
|
||||
# assert client_1.ping(dmz_server.network_interface[1].ip_address)
|
||||
|
||||
|
||||
def test_firewall_node_added_to_network():
|
||||
|
||||
Reference in New Issue
Block a user