#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:
@@ -406,15 +406,10 @@ class PrimaiteGame:
|
|||||||
new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3))
|
new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3))
|
||||||
|
|
||||||
# 2. create links between nodes
|
# 2. create links between nodes
|
||||||
# TODO: Pull from link_cfg the 'bandwidth' of that link
|
|
||||||
for link_cfg in links_cfg:
|
for link_cfg in links_cfg:
|
||||||
node_a = net.get_node_by_hostname(link_cfg["endpoint_a_hostname"])
|
node_a = net.get_node_by_hostname(link_cfg["endpoint_a_hostname"])
|
||||||
node_b = net.get_node_by_hostname(link_cfg["endpoint_b_hostname"])
|
node_b = net.get_node_by_hostname(link_cfg["endpoint_b_hostname"])
|
||||||
print(link_cfg)
|
bandwidth = link_cfg.get("bandwidth", 100) # default value if not configured
|
||||||
try:
|
|
||||||
bandwidth = link_cfg["bandwidth"]
|
|
||||||
except Exception:
|
|
||||||
bandwidth = 100
|
|
||||||
|
|
||||||
if isinstance(node_a, Switch):
|
if isinstance(node_a, Switch):
|
||||||
endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]]
|
endpoint_a = node_a.network_interface[link_cfg["endpoint_a_port"]]
|
||||||
|
|||||||
@@ -110,7 +110,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.10.12"
|
"version": "3.10.11"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class EpisodeListScheduler(EpisodeScheduler):
|
|||||||
if episode_num >= len(self.schedule):
|
if episode_num >= len(self.schedule):
|
||||||
if not self._exceeded_episode_list:
|
if not self._exceeded_episode_list:
|
||||||
self._exceeded_episode_list = True
|
self._exceeded_episode_list = True
|
||||||
_LOGGER.warn(
|
_LOGGER.warning(
|
||||||
f"Running episode {episode_num} but the schedule only defines "
|
f"Running episode {episode_num} but the schedule only defines "
|
||||||
f"{len(self.schedule)} episodes. Looping back to the beginning"
|
f"{len(self.schedule)} episodes. Looping back to the beginning"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -309,7 +309,9 @@ class Network(SimComponent):
|
|||||||
self._node_request_manager.remove_request(name=node.hostname)
|
self._node_request_manager.remove_request(name=node.hostname)
|
||||||
_LOGGER.info(f"Removed node {node.hostname} from network {self.uuid}")
|
_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.
|
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
|
:type endpoint_a: WiredNetworkInterface
|
||||||
:param endpoint_b: The second endpoint to connect.
|
:param endpoint_b: The second endpoint to connect.
|
||||||
:type endpoint_b: WiredNetworkInterface
|
:type endpoint_b: WiredNetworkInterface
|
||||||
|
:param bandwidth: bandwidth of new link
|
||||||
|
:type bandwidth: int
|
||||||
:raises RuntimeError: If any validation or runtime checks fail.
|
:raises RuntimeError: If any validation or runtime checks fail.
|
||||||
"""
|
"""
|
||||||
node_a: Node = endpoint_a.parent
|
node_a: Node = endpoint_a.parent
|
||||||
@@ -330,7 +334,7 @@ class Network(SimComponent):
|
|||||||
if node_a is node_b:
|
if node_a is node_b:
|
||||||
_LOGGER.warning(f"Cannot link endpoint {endpoint_a} to {endpoint_b} because they belong to the same node.")
|
_LOGGER.warning(f"Cannot link endpoint {endpoint_a} to {endpoint_b} because they belong to the same node.")
|
||||||
return
|
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.links[link.uuid] = link
|
||||||
self._link_id_map[len(self.links)] = link
|
self._link_id_map[len(self.links)] = link
|
||||||
self._nx_graph.add_edge(endpoint_a.parent.hostname, endpoint_b.parent.hostname)
|
self._nx_graph.add_edge(endpoint_a.parent.hostname, endpoint_b.parent.hostname)
|
||||||
|
|||||||
@@ -554,7 +554,7 @@ class Link(SimComponent):
|
|||||||
"The first WiredNetworkInterface connected to the Link."
|
"The first WiredNetworkInterface connected to the Link."
|
||||||
endpoint_b: WiredNetworkInterface
|
endpoint_b: WiredNetworkInterface
|
||||||
"The second WiredNetworkInterface connected to the Link."
|
"The second WiredNetworkInterface connected to the Link."
|
||||||
bandwidth: float = 100.0
|
bandwidth: float
|
||||||
"The bandwidth of the Link in Mbps (default is 100 Mbps)."
|
"The bandwidth of the Link in Mbps (default is 100 Mbps)."
|
||||||
current_load: float = 0.0
|
current_load: float = 0.0
|
||||||
"The current load on the link in Mbps."
|
"The current load on the link in Mbps."
|
||||||
|
|||||||
@@ -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))]
|
db_server_nic = db_server.network_interfaces[next(iter(db_server.network_interfaces))]
|
||||||
|
|
||||||
# Connect Computer and Server
|
# 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
|
# Should be linked
|
||||||
assert link_computer_server.is_up
|
assert link_computer_server.is_up
|
||||||
|
|
||||||
# Connect database server and web server
|
# 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
|
# Should be linked
|
||||||
assert link_computer_server.is_up
|
assert link_computer_server.is_up
|
||||||
assert link_server_db.is_up
|
assert link_server_db.is_up
|
||||||
|
|||||||
Reference in New Issue
Block a user