Rename networkcontainer to network
This commit is contained in:
@@ -7,7 +7,7 @@ from primaite.simulator.network.hardware.base import Link, NIC, Node, SwitchPort
|
|||||||
_LOGGER = getLogger(__name__)
|
_LOGGER = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class NetworkContainer(SimComponent):
|
class Network(SimComponent):
|
||||||
"""Top level container object representing the physical network."""
|
"""Top level container object representing the physical network."""
|
||||||
|
|
||||||
nodes: Dict[str, Node] = {}
|
nodes: Dict[str, Node] = {}
|
||||||
|
|||||||
@@ -2,19 +2,19 @@ from typing import Dict
|
|||||||
|
|
||||||
from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent
|
from primaite.simulator.core import Action, ActionManager, AllowAllValidator, SimComponent
|
||||||
from primaite.simulator.domain.controller import DomainController
|
from primaite.simulator.domain.controller import DomainController
|
||||||
from primaite.simulator.network.container import NetworkContainer
|
from primaite.simulator.network.container import Network
|
||||||
|
|
||||||
|
|
||||||
class Simulation(SimComponent):
|
class Simulation(SimComponent):
|
||||||
"""Top-level simulation object which holds a reference to all other parts of the simulation."""
|
"""Top-level simulation object which holds a reference to all other parts of the simulation."""
|
||||||
|
|
||||||
network: NetworkContainer
|
network: Network
|
||||||
domain: DomainController
|
domain: DomainController
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
"""Initialise the Simulation."""
|
"""Initialise the Simulation."""
|
||||||
if not kwargs.get("network"):
|
if not kwargs.get("network"):
|
||||||
kwargs["network"] = NetworkContainer()
|
kwargs["network"] = Network()
|
||||||
|
|
||||||
if not kwargs.get("domain"):
|
if not kwargs.get("domain"):
|
||||||
kwargs["domain"] = DomainController()
|
kwargs["domain"] = DomainController()
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from primaite.simulator.network.container import NetworkContainer
|
from primaite.simulator.network.container import Network
|
||||||
from primaite.simulator.network.hardware.base import NIC, Node
|
from primaite.simulator.network.hardware.base import NIC, Node
|
||||||
|
|
||||||
|
|
||||||
def test_adding_removing_nodes():
|
def test_adding_removing_nodes():
|
||||||
"""Check that we can create and add a node to a network."""
|
"""Check that we can create and add a node to a network."""
|
||||||
net = NetworkContainer()
|
net = Network()
|
||||||
n1 = Node(hostname="computer")
|
n1 = Node(hostname="computer")
|
||||||
net.add_node(n1)
|
net.add_node(n1)
|
||||||
assert n1.parent is net
|
assert n1.parent is net
|
||||||
@@ -19,7 +19,7 @@ def test_adding_removing_nodes():
|
|||||||
|
|
||||||
def test_readding_node():
|
def test_readding_node():
|
||||||
"""Check that warning is raised when readding a node."""
|
"""Check that warning is raised when readding a node."""
|
||||||
net = NetworkContainer()
|
net = Network()
|
||||||
n1 = Node(hostname="computer")
|
n1 = Node(hostname="computer")
|
||||||
net.add_node(n1)
|
net.add_node(n1)
|
||||||
with pytest.raises(RuntimeWarning):
|
with pytest.raises(RuntimeWarning):
|
||||||
@@ -30,7 +30,7 @@ def test_readding_node():
|
|||||||
|
|
||||||
def test_removing_nonexistent_node():
|
def test_removing_nonexistent_node():
|
||||||
"""Check that warning is raised when trying to remove a node that is not in the network."""
|
"""Check that warning is raised when trying to remove a node that is not in the network."""
|
||||||
net = NetworkContainer()
|
net = Network()
|
||||||
n1 = Node(hostname="computer")
|
n1 = Node(hostname="computer")
|
||||||
with pytest.raises(RuntimeWarning):
|
with pytest.raises(RuntimeWarning):
|
||||||
net.remove_node(n1)
|
net.remove_node(n1)
|
||||||
@@ -40,7 +40,7 @@ def test_removing_nonexistent_node():
|
|||||||
|
|
||||||
def test_connecting_nodes():
|
def test_connecting_nodes():
|
||||||
"""Check that two nodes on the network can be connected."""
|
"""Check that two nodes on the network can be connected."""
|
||||||
net = NetworkContainer()
|
net = Network()
|
||||||
n1 = Node(hostname="computer")
|
n1 = Node(hostname="computer")
|
||||||
n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
||||||
n1.connect_nic(n1_nic)
|
n1.connect_nic(n1_nic)
|
||||||
@@ -60,7 +60,7 @@ def test_connecting_nodes():
|
|||||||
|
|
||||||
|
|
||||||
def test_connecting_node_to_itself():
|
def test_connecting_node_to_itself():
|
||||||
net = NetworkContainer()
|
net = Network()
|
||||||
node = Node(hostname="computer")
|
node = Node(hostname="computer")
|
||||||
nic1 = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
nic1 = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
||||||
node.connect_nic(nic1)
|
node.connect_nic(nic1)
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from primaite.simulator.network.container import NetworkContainer
|
from primaite.simulator.network.container import Network
|
||||||
|
|
||||||
|
|
||||||
def test_creating_container():
|
def test_creating_container():
|
||||||
"""Check that we can create a network container"""
|
"""Check that we can create a network container"""
|
||||||
net = NetworkContainer()
|
net = Network()
|
||||||
assert net.nodes and net.links
|
assert net.nodes and net.links
|
||||||
|
|
||||||
|
|
||||||
def test_describe_state():
|
def test_describe_state():
|
||||||
"""Check that we can describe network state without raising errors, and that the result is JSON serialisable."""
|
"""Check that we can describe network state without raising errors, and that the result is JSON serialisable."""
|
||||||
net = NetworkContainer()
|
net = Network()
|
||||||
state = net.describe_state()
|
state = net.describe_state()
|
||||||
json.dumps(state) # if this function call raises an error, the test fails, state was not JSON-serialisable
|
json.dumps(state) # if this function call raises an error, the test fails, state was not JSON-serialisable
|
||||||
|
|||||||
Reference in New Issue
Block a user