#2457 - Initial commit removing the hardcoding of bandwidth values within links. Now pull it from configuration files, defaulting to 100 if not implemented

This commit is contained in:
Charlie Crane
2024-05-13 14:42:15 +01:00
parent 4cd15a39aa
commit 71684dc5f0
6 changed files with 12 additions and 13 deletions

View File

@@ -406,15 +406,10 @@ class PrimaiteGame:
new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3))
# 2. create links between nodes
# TODO: Pull from link_cfg the 'bandwidth' of that link
for link_cfg in links_cfg:
node_a = net.get_node_by_hostname(link_cfg["endpoint_a_hostname"])
node_b = net.get_node_by_hostname(link_cfg["endpoint_b_hostname"])
print(link_cfg)
try:
bandwidth = link_cfg["bandwidth"]
except Exception:
bandwidth = 100
bandwidth = link_cfg.get("bandwidth", 100) # default value if not configured
if isinstance(node_a, Switch):
endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]]

View File

@@ -110,7 +110,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.11"
}
},
"nbformat": 4,

View File

@@ -57,7 +57,7 @@ class EpisodeListScheduler(EpisodeScheduler):
if episode_num >= len(self.schedule):
if not self._exceeded_episode_list:
self._exceeded_episode_list = True
_LOGGER.warn(
_LOGGER.warning(
f"Running episode {episode_num} but the schedule only defines "
f"{len(self.schedule)} episodes. Looping back to the beginning"
)

View File

@@ -309,7 +309,9 @@ class Network(SimComponent):
self._node_request_manager.remove_request(name=node.hostname)
_LOGGER.info(f"Removed node {node.hostname} from network {self.uuid}")
def connect(self, endpoint_a: WiredNetworkInterface, endpoint_b: WiredNetworkInterface, **kwargs) -> Optional[Link]:
def connect(
self, endpoint_a: WiredNetworkInterface, endpoint_b: WiredNetworkInterface, bandwidth: int = 100, **kwargs
) -> Optional[Link]:
"""
Connect two endpoints on the network by creating a link between their NICs/SwitchPorts.
@@ -319,6 +321,8 @@ 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
:type bandwidth: int
:raises RuntimeError: If any validation or runtime checks fail.
"""
node_a: Node = endpoint_a.parent
@@ -330,7 +334,7 @@ class Network(SimComponent):
if node_a is node_b:
_LOGGER.warning(f"Cannot link endpoint {endpoint_a} to {endpoint_b} because they belong to the same node.")
return
link = Link(endpoint_a=endpoint_a, endpoint_b=endpoint_b, **kwargs)
link = Link(endpoint_a=endpoint_a, endpoint_b=endpoint_b, bandwidth=bandwidth, **kwargs)
self.links[link.uuid] = link
self._link_id_map[len(self.links)] = link
self._nx_graph.add_edge(endpoint_a.parent.hostname, endpoint_b.parent.hostname)

View File

@@ -554,7 +554,7 @@ class Link(SimComponent):
"The first WiredNetworkInterface connected to the Link."
endpoint_b: WiredNetworkInterface
"The second WiredNetworkInterface connected to the Link."
bandwidth: float = 100.0
bandwidth: float
"The bandwidth of the Link in Mbps (default is 100 Mbps)."
current_load: float = 0.0
"The current load on the link in Mbps."

View File

@@ -49,12 +49,12 @@ def web_client_web_server_database(example_network) -> Tuple[Network, Computer,
db_server_nic = db_server.network_interfaces[next(iter(db_server.network_interfaces))]
# Connect Computer and Server
link_computer_server = Link(endpoint_a=computer_nic, endpoint_b=server_nic)
link_computer_server = Link(endpoint_a=computer_nic, endpoint_b=server_nic, bandwidth=100)
# Should be linked
assert link_computer_server.is_up
# Connect database server and web server
link_server_db = Link(endpoint_a=server_nic, endpoint_b=db_server_nic)
link_server_db = Link(endpoint_a=server_nic, endpoint_b=db_server_nic, bandwidth=100)
# Should be linked
assert link_computer_server.is_up
assert link_server_db.is_up