Rename connect_nodes to connect and fix minor bug
This commit is contained in:
@@ -72,7 +72,7 @@ class Network(SimComponent):
|
|||||||
del self.nodes[node.uuid]
|
del self.nodes[node.uuid]
|
||||||
del node.parent # misleading?
|
del node.parent # misleading?
|
||||||
|
|
||||||
def connect_nodes(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None:
|
def connect(self, endpoint_a: Union[NIC, SwitchPort], endpoint_b: Union[NIC, SwitchPort], **kwargs) -> None:
|
||||||
"""Connect two nodes on the network by creating a link between an NIC/SwitchPort of each one.
|
"""Connect two nodes on the network by creating a link between an NIC/SwitchPort of each one.
|
||||||
|
|
||||||
:param endpoint_a: The endpoint to which to connect the link on the first node
|
:param endpoint_a: The endpoint to which to connect the link on the first node
|
||||||
|
|||||||
@@ -1011,6 +1011,7 @@ class Switch(Node):
|
|||||||
self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)}
|
self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)}
|
||||||
for port_num, port in self.switch_ports.items():
|
for port_num, port in self.switch_ports.items():
|
||||||
port.connected_node = self
|
port.connected_node = self
|
||||||
|
port.parent = self
|
||||||
port.port_num = port_num
|
port.port_num = port_num
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ def test_connecting_nodes():
|
|||||||
net.add_node(n1)
|
net.add_node(n1)
|
||||||
net.add_node(n2)
|
net.add_node(n2)
|
||||||
|
|
||||||
net.connect_nodes(n1.nics[n1_nic.uuid], n2.nics[n2_nic.uuid], bandwidth=30)
|
net.connect(n1.nics[n1_nic.uuid], n2.nics[n2_nic.uuid], bandwidth=30)
|
||||||
|
|
||||||
assert len(net.links) == 1
|
assert len(net.links) == 1
|
||||||
link = list(net.links.values())[0]
|
link = list(net.links.values())[0]
|
||||||
@@ -70,7 +70,7 @@ def test_connecting_node_to_itself():
|
|||||||
net.add_node(node)
|
net.add_node(node)
|
||||||
|
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
net.connect_nodes(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30)
|
net.connect(node.nics[nic1.uuid], node.nics[nic2.uuid], bandwidth=30)
|
||||||
|
|
||||||
assert node in net
|
assert node in net
|
||||||
assert nic1.connected_link is None
|
assert nic1.connected_link is None
|
||||||
|
|||||||
Reference in New Issue
Block a user