From 74514e977d5d3ceed422d819381ce93a4cd9c355 Mon Sep 17 00:00:00 2001 From: Charlie Crane Date: Tue, 14 May 2024 11:05:37 +0100 Subject: [PATCH] #2457 - Syncing changes made. Updates to documentation and tests --- docs/source/configuration/simulation.rst | 6 ++++++ src/primaite/simulator/network/container.py | 2 +- src/primaite/simulator/network/creation.py | 15 ++++++++++----- src/primaite/simulator/network/hardware/base.py | 4 ++-- tests/assets/configs/basic_switched_network.yaml | 2 ++ .../nodes/test_node_config.py | 3 +++ 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/docs/source/configuration/simulation.rst b/docs/source/configuration/simulation.rst index 9da2b6a3..b2c2bcd6 100644 --- a/docs/source/configuration/simulation.rst +++ b/docs/source/configuration/simulation.rst @@ -64,10 +64,12 @@ this results in: endpoint_a_port: 1 # port 1 on computer_1 endpoint_b_hostname: switch endpoint_b_port: 1 # port 1 on switch + bandwidth: 100 - endpoint_a_hostname: computer_2 endpoint_a_port: 1 # port 1 on computer_2 endpoint_b_hostname: switch endpoint_b_port: 2 # port 2 on switch + bandwidth: 100 ``ref`` ^^^^^^^ @@ -95,3 +97,7 @@ The ``hostname`` of the node which must be connected. The port on ``endpoint_b_hostname`` which is to be connected to ``endpoint_a_port``. This accepts an integer value e.g. if port 1 is to be connected, the configuration should be ``endpoint_b_port: 1`` + +``bandwidth`` + +This is an integer value specifying the allowed bandwidth across the connection. diff --git a/src/primaite/simulator/network/container.py b/src/primaite/simulator/network/container.py index e175b04f..91ea3c71 100644 --- a/src/primaite/simulator/network/container.py +++ b/src/primaite/simulator/network/container.py @@ -321,7 +321,7 @@ class Network(SimComponent): :type endpoint_a: WiredNetworkInterface :param endpoint_b: The second endpoint to connect. :type endpoint_b: WiredNetworkInterface - :param bandwidth: bandwidth of new link + :param bandwidth: bandwidth of new link, default of 100mbps :type bandwidth: int :raises RuntimeError: If any validation or runtime checks fail. """ diff --git a/src/primaite/simulator/network/creation.py b/src/primaite/simulator/network/creation.py index 8bda626a..f4475bec 100644 --- a/src/primaite/simulator/network/creation.py +++ b/src/primaite/simulator/network/creation.py @@ -50,6 +50,7 @@ def create_office_lan( num_pcs: int, network: Optional[Network] = None, include_router: bool = True, + bandwidth: int = 100, ) -> Network: """ Creates a 2-Tier or 3-Tier office local area network (LAN). @@ -109,9 +110,11 @@ def create_office_lan( switch.power_on() network.add_node(switch) if num_of_switches > 1: - network.connect(core_switch.network_interface[core_switch_port], switch.network_interface[24]) + network.connect( + core_switch.network_interface[core_switch_port], switch.network_interface[24], bandwidth=bandwidth + ) else: - network.connect(router.network_interface[1], switch.network_interface[24]) + network.connect(router.network_interface[1], switch.network_interface[24], bandwidth=bandwidth) # Add PCs to the LAN and connect them to switches for i in range(1, num_pcs + 1): @@ -125,9 +128,11 @@ def create_office_lan( # Connect the new switch to the router or core switch if num_of_switches > 1: core_switch_port += 1 - network.connect(core_switch.network_interface[core_switch_port], switch.network_interface[24]) + network.connect( + core_switch.network_interface[core_switch_port], switch.network_interface[24], bandwidth=bandwidth + ) else: - network.connect(router.network_interface[1], switch.network_interface[24]) + network.connect(router.network_interface[1], switch.network_interface[24], bandwidth=bandwidth) # Create and add a PC to the network pc = Computer( @@ -142,7 +147,7 @@ def create_office_lan( # Connect the PC to the switch switch_port += 1 - network.connect(switch.network_interface[switch_port], pc.network_interface[1]) + network.connect(switch.network_interface[switch_port], pc.network_interface[1], bandwidth=bandwidth) switch.network_interface[switch_port].enable() return network diff --git a/src/primaite/simulator/network/hardware/base.py b/src/primaite/simulator/network/hardware/base.py index d88a688e..99cc00a3 100644 --- a/src/primaite/simulator/network/hardware/base.py +++ b/src/primaite/simulator/network/hardware/base.py @@ -547,7 +547,7 @@ class Link(SimComponent): :param endpoint_a: The first NIC or SwitchPort connected to the Link. :param endpoint_b: The second NIC or SwitchPort connected to the Link. - :param bandwidth: The bandwidth of the Link in Mbps (default is 100 Mbps). + :param bandwidth: The bandwidth of the Link in Mbps. """ endpoint_a: WiredNetworkInterface @@ -555,7 +555,7 @@ class Link(SimComponent): endpoint_b: WiredNetworkInterface "The second WiredNetworkInterface connected to the Link." bandwidth: float - "The bandwidth of the Link in Mbps (default is 100 Mbps)." + "The bandwidth of the Link in Mbps." current_load: float = 0.0 "The current load on the link in Mbps." diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 37505f6e..0cbaefdb 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -234,7 +234,9 @@ simulation: endpoint_a_port: 1 endpoint_b_hostname: client_1 endpoint_b_port: 1 + bandwidth: 200 - endpoint_a_hostname: switch_1 endpoint_a_port: 2 endpoint_b_hostname: client_2 endpoint_b_port: 1 + bandwidth: 200 diff --git a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py index 174bd0c0..b71c0c9c 100644 --- a/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py +++ b/tests/integration_tests/configuration_file_parsing/nodes/test_node_config.py @@ -43,3 +43,6 @@ def test_basic_config(): # client 3 should not be online client_3: Computer = network.get_node_by_hostname("client_3") assert client_3.operating_state == NodeOperatingState.OFF + + for link in network.links: + assert network.links[link].bandwidth == 200