Merged PR 354: Network focussed dev config documentation
## Summary Built three networks, one is the minimal network, one is a basic LAN, and another is a nice beefy multi-LAN setup with ISP and DNS along with applications, services. Documented the process when building the config files. Included the config files as example configs for use. ## Test process Tested the shit out of the big multi-lan network. ## Checklist - [ ] PR is linked to a **work item** - [ ] **acceptance criteria** of linked ticket are met - [ ] performed **self-review** of the code - [ ] written **tests** for any new functionality added with this PR - [ ] updated the **documentation** if this PR changes or adds functionality - [ ] written/updated **design docs** if this PR implements new functionality - [ ] updated the **change log** - [ ] ran **pre-commit** checks for code style - [ ] attended to any **TO-DOs** left in the code Related work items: #2266
This commit is contained in:
@@ -330,7 +330,7 @@ class Firewall(Router):
|
||||
# check if External Inbound ACL Rules permit frame
|
||||
permitted, rule = self.external_inbound_acl.is_permitted(frame)
|
||||
if not permitted:
|
||||
self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}")
|
||||
self.sys_log.info(f"Frame blocked at external inbound by rule {rule}")
|
||||
return
|
||||
self.software_manager.arp.add_arp_cache_entry(
|
||||
ip_address=frame.ip.src_ip_address,
|
||||
@@ -360,7 +360,7 @@ class Firewall(Router):
|
||||
# check if External Outbound ACL Rules permit frame
|
||||
permitted, rule = self.external_outbound_acl.is_permitted(frame=frame)
|
||||
if not permitted:
|
||||
self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}")
|
||||
self.sys_log.info(f"Frame blocked at external outbound by rule {rule}")
|
||||
return
|
||||
|
||||
self.process_frame(frame=frame, from_network_interface=from_network_interface)
|
||||
@@ -380,7 +380,7 @@ class Firewall(Router):
|
||||
# check if Internal Inbound ACL Rules permit frame
|
||||
permitted, rule = self.internal_inbound_acl.is_permitted(frame=frame)
|
||||
if not permitted:
|
||||
self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}")
|
||||
self.sys_log.info(f"Frame blocked at internal inbound by rule {rule}")
|
||||
return
|
||||
|
||||
self.process_frame(frame=frame, from_network_interface=from_network_interface)
|
||||
@@ -398,7 +398,7 @@ class Firewall(Router):
|
||||
"""
|
||||
permitted, rule = self.internal_outbound_acl.is_permitted(frame)
|
||||
if not permitted:
|
||||
self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}")
|
||||
self.sys_log.info(f"Frame blocked at internal outbound by rule {rule}")
|
||||
return
|
||||
self.software_manager.arp.add_arp_cache_entry(
|
||||
ip_address=frame.ip.src_ip_address,
|
||||
@@ -432,7 +432,7 @@ class Firewall(Router):
|
||||
# check if DMZ Inbound ACL Rules permit frame
|
||||
permitted, rule = self.dmz_inbound_acl.is_permitted(frame=frame)
|
||||
if not permitted:
|
||||
self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}")
|
||||
self.sys_log.info(f"Frame blocked at DMZ inbound by rule {rule}")
|
||||
return
|
||||
|
||||
self.process_frame(frame=frame, from_network_interface=from_network_interface)
|
||||
@@ -452,7 +452,7 @@ class Firewall(Router):
|
||||
"""
|
||||
permitted, rule = self.dmz_outbound_acl.is_permitted(frame)
|
||||
if not permitted:
|
||||
self.sys_log.info(f"Frame blocked at interface {from_network_interface} by rule {rule}")
|
||||
self.sys_log.info(f"Frame blocked at DMZ outbound by rule {rule}")
|
||||
return
|
||||
self.software_manager.arp.add_arp_cache_entry(
|
||||
ip_address=frame.ip.src_ip_address,
|
||||
@@ -688,4 +688,9 @@ class Firewall(Router):
|
||||
next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")),
|
||||
metric=float(route.get("metric", 0)),
|
||||
)
|
||||
if "default_route" in cfg:
|
||||
next_hop_ip_address = cfg["default_route"].get("next_hop_ip_address", None)
|
||||
if next_hop_ip_address:
|
||||
firewall.route_table.set_default_route_next_hop_ip_address(next_hop_ip_address)
|
||||
|
||||
return firewall
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
from ipaddress import IPv4Address
|
||||
|
||||
import yaml
|
||||
|
||||
from primaite import getLogger, PRIMAITE_PATHS
|
||||
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.host_node import NIC
|
||||
@@ -15,6 +19,8 @@ from primaite.simulator.system.services.dns.dns_server import DNSServer
|
||||
from primaite.simulator.system.services.ftp.ftp_server import FTPServer
|
||||
from primaite.simulator.system.services.web_server.web_server import WebServer
|
||||
|
||||
_LOGGER = getLogger(__name__)
|
||||
|
||||
|
||||
def client_server_routed() -> Network:
|
||||
"""
|
||||
@@ -279,3 +285,34 @@ def arcd_uc2_network() -> Network:
|
||||
router_1.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.HTTP, dst_port=Port.HTTP, position=3)
|
||||
|
||||
return network
|
||||
|
||||
|
||||
def _get_example_network(path: str) -> Network:
|
||||
try:
|
||||
with open(path, "r") as file:
|
||||
cfg = yaml.safe_load(file)
|
||||
except FileNotFoundError:
|
||||
msg = f"Failed to locate example network config {path}. Run `primaite setup` to load the example config files."
|
||||
_LOGGER.error(msg)
|
||||
raise FileNotFoundError(msg)
|
||||
game = PrimaiteGame.from_config(cfg)
|
||||
|
||||
return game.simulation.network
|
||||
|
||||
|
||||
def client_server_p2p_network_example() -> Network:
|
||||
"""Get the Client-Server P2P example network."""
|
||||
path = PRIMAITE_PATHS.user_config_path / "example_config" / "client_server_p2p_network_example.yaml"
|
||||
return _get_example_network(path)
|
||||
|
||||
|
||||
def basic_lan_network_example() -> Network:
|
||||
"""Get the basic LAN example network."""
|
||||
path = PRIMAITE_PATHS.user_config_path / "example_config" / "basic_network_network_example.yaml"
|
||||
return _get_example_network(path)
|
||||
|
||||
|
||||
def multi_lan_internet_network_example() -> Network:
|
||||
"""Get Multi-LAN with Internet example network."""
|
||||
path = PRIMAITE_PATHS.user_config_path / "example_config" / "multi_lan_internet_network_example.yaml"
|
||||
return _get_example_network(path)
|
||||
|
||||
Reference in New Issue
Block a user