diff --git a/daemon/core/api/grpc/grpcutils.py b/daemon/core/api/grpc/grpcutils.py index d95b7555..2c13315c 100644 --- a/daemon/core/api/grpc/grpcutils.py +++ b/daemon/core/api/grpc/grpcutils.py @@ -270,9 +270,9 @@ def get_links(node: NodeBase): :return: protobuf links """ links = [] - for link_data in node.all_link_data(): - link = convert_link(link_data) - links.append(link) + for link in node.links(): + link_proto = convert_link(link) + links.append(link_proto) return links diff --git a/daemon/core/api/tlv/corehandlers.py b/daemon/core/api/tlv/corehandlers.py index d01f15a3..bb4f2ecd 100644 --- a/daemon/core/api/tlv/corehandlers.py +++ b/daemon/core/api/tlv/corehandlers.py @@ -1824,16 +1824,16 @@ class CoreHandler(socketserver.BaseRequestHandler): Return API messages that describe the current session. """ # find all nodes and links - links_data = [] + all_links = [] with self.session.nodes_lock: for node_id in self.session.nodes: node = self.session.nodes[node_id] self.session.broadcast_node(node, MessageFlags.ADD) - node_links = node.all_link_data(flags=MessageFlags.ADD) - links_data.extend(node_links) + links = node.links(flags=MessageFlags.ADD) + all_links.extend(links) - for link_data in links_data: - self.session.broadcast_link(link_data) + for link in all_links: + self.session.broadcast_link(link) # send mobility model info for node_id in self.session.mobility.nodes(): @@ -1940,7 +1940,7 @@ class CoreHandler(socketserver.BaseRequestHandler): node_count = self.session.get_node_count() logging.info( - "informed GUI about %d nodes and %d links", node_count, len(links_data) + "informed GUI about %d nodes and %d links", node_count, len(all_links) ) diff --git a/daemon/core/emane/nodes.py b/daemon/core/emane/nodes.py index c28f1382..9173fbfc 100644 --- a/daemon/core/emane/nodes.py +++ b/daemon/core/emane/nodes.py @@ -241,8 +241,8 @@ class EmaneNet(CoreNetworkBase): event.append(nemid, latitude=lat, longitude=lon, altitude=alt) self.session.emane.service.publish(0, event) - def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: - links = super().all_link_data(flags) + def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + links = super().links(flags) # gather current emane links nem_ids = set(self.nemidmap.values()) emane_manager = self.session.emane diff --git a/daemon/core/location/mobility.py b/daemon/core/location/mobility.py index 9bb2966e..f2e0f470 100644 --- a/daemon/core/location/mobility.py +++ b/daemon/core/location/mobility.py @@ -217,7 +217,7 @@ class WirelessModel(ConfigurableOptions): self.session: "Session" = session self.id: int = _id - def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: """ May be used if the model can populate the GUI with wireless (green) link lines. @@ -509,7 +509,7 @@ class BasicRangeModel(WirelessModel): link_data = self.create_link_data(iface, iface2, message_type) self.session.broadcast_link(link_data) - def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: """ Return a list of wireless link messages for when the GUI reconnects. diff --git a/daemon/core/nodes/base.py b/daemon/core/nodes/base.py index 4fc6b873..2c8ca06c 100644 --- a/daemon/core/nodes/base.py +++ b/daemon/core/nodes/base.py @@ -182,7 +182,7 @@ class NodeBase(abc.ABC): self.iface_id += 1 return iface_id - def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: """ Build link data for this node. @@ -1021,7 +1021,7 @@ class CoreNetworkBase(NodeBase): with self._linked_lock: del self._linked[iface] - def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: """ Build link data objects for this network. Each link object describes a link between this network and a node. diff --git a/daemon/core/nodes/network.py b/daemon/core/nodes/network.py index f20b6dfb..62443fb8 100644 --- a/daemon/core/nodes/network.py +++ b/daemon/core/nodes/network.py @@ -831,7 +831,7 @@ class CtrlNet(CoreNetwork): super().shutdown() - def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: """ Do not include CtrlNet in link messages describing this session. @@ -859,7 +859,7 @@ class PtpNet(CoreNetwork): raise CoreError("ptp links support at most 2 network interfaces") super().attach(iface) - def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: """ Build CORE API TLVs for a point-to-point link. One Link message describes this network. @@ -1054,17 +1054,17 @@ class WlanNode(CoreNetwork): for iface in self.get_ifaces(): iface.setposition() - def all_link_data(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: + def links(self, flags: MessageFlags = MessageFlags.NONE) -> List[LinkData]: """ Retrieve all link data. :param flags: message flags :return: list of link data """ - all_links = super().all_link_data(flags) + links = super().links(flags) if self.model: - all_links.extend(self.model.all_link_data(flags)) - return all_links + links.extend(self.model.links(flags)) + return links class TunnelNode(GreTapBridge): diff --git a/daemon/core/plugins/sdt.py b/daemon/core/plugins/sdt.py index 84c90730..ef36b0a4 100644 --- a/daemon/core/plugins/sdt.py +++ b/daemon/core/plugins/sdt.py @@ -225,7 +225,7 @@ class Sdt: self.add_node(node) for net in nets: - all_links = net.all_link_data(flags=MessageFlags.ADD) + all_links = net.links(flags=MessageFlags.ADD) for link_data in all_links: is_wireless = isinstance(net, (WlanNode, EmaneNet)) if is_wireless and link_data.node1_id == net.id: diff --git a/daemon/core/xml/corexml.py b/daemon/core/xml/corexml.py index 190cf8f7..d3cc85d8 100644 --- a/daemon/core/xml/corexml.py +++ b/daemon/core/xml/corexml.py @@ -465,7 +465,7 @@ class CoreXmlWriter: self.write_device(node) # add known links - links.extend(node.all_link_data()) + links.extend(node.links()) return links def write_network(self, node: NodeBase) -> None: diff --git a/daemon/tests/test_core.py b/daemon/tests/test_core.py index 2623b0df..c4465863 100644 --- a/daemon/tests/test_core.py +++ b/daemon/tests/test_core.py @@ -120,7 +120,7 @@ class TestCore: session.instantiate() # check link data gets generated - assert ptp_node.all_link_data(MessageFlags.ADD) + assert ptp_node.links(MessageFlags.ADD) # check common nets exist between linked nodes assert node1.commonnets(node2) diff --git a/daemon/tests/test_grpc.py b/daemon/tests/test_grpc.py index 8abf33aa..a4efd6d9 100644 --- a/daemon/tests/test_grpc.py +++ b/daemon/tests/test_grpc.py @@ -555,7 +555,7 @@ class TestGrpc: session = grpc_server.coreemu.create_session() switch = session.add_node(SwitchNode) node = session.add_node(CoreNode) - assert len(switch.all_link_data()) == 0 + assert len(switch.links()) == 0 # then iface = iface_helper.create_iface(node.id, 0) @@ -564,7 +564,7 @@ class TestGrpc: # then assert response.result is True - assert len(switch.all_link_data()) == 1 + assert len(switch.links()) == 1 def test_add_link_exception( self, grpc_server: CoreGrpcServer, iface_helper: InterfaceHelper @@ -589,7 +589,7 @@ class TestGrpc: iface = ip_prefixes.create_iface(node) session.add_link(node.id, switch.id, iface) options = core_pb2.LinkOptions(bandwidth=30000) - link = switch.all_link_data()[0] + link = switch.links()[0] assert options.bandwidth != link.options.bandwidth # then @@ -600,7 +600,7 @@ class TestGrpc: # then assert response.result is True - link = switch.all_link_data()[0] + link = switch.links()[0] assert options.bandwidth == link.options.bandwidth def test_delete_link(self, grpc_server: CoreGrpcServer, ip_prefixes: IpPrefixes): @@ -618,7 +618,7 @@ class TestGrpc: if node.id not in {node1.id, node2.id}: link_node = node break - assert len(link_node.all_link_data()) == 1 + assert len(link_node.links()) == 1 # then with client.context_connect(): @@ -628,7 +628,7 @@ class TestGrpc: # then assert response.result is True - assert len(link_node.all_link_data()) == 0 + assert len(link_node.links()) == 0 def test_get_wlan_config(self, grpc_server: CoreGrpcServer): # given @@ -1029,7 +1029,7 @@ class TestGrpc: node = session.add_node(CoreNode) iface = ip_prefixes.create_iface(node) session.add_link(node.id, wlan.id, iface) - link_data = wlan.all_link_data()[0] + link_data = wlan.links()[0] queue = Queue() def handle_event(event_data): diff --git a/daemon/tests/test_gui.py b/daemon/tests/test_gui.py index 8f01a2bf..a0b3bd8a 100644 --- a/daemon/tests/test_gui.py +++ b/daemon/tests/test_gui.py @@ -122,7 +122,7 @@ class TestGui: coretlv.handle_message(message) switch_node = coretlv.session.get_node(switch_id, SwitchNode) - all_links = switch_node.all_link_data() + all_links = switch_node.links() assert len(all_links) == 1 def test_link_add_net_to_node(self, coretlv: CoreHandler): @@ -146,7 +146,7 @@ class TestGui: coretlv.handle_message(message) switch_node = coretlv.session.get_node(switch_id, SwitchNode) - all_links = switch_node.all_link_data() + all_links = switch_node.links() assert len(all_links) == 1 def test_link_add_node_to_node(self, coretlv: CoreHandler): @@ -176,7 +176,7 @@ class TestGui: all_links = [] for node_id in coretlv.session.nodes: node = coretlv.session.nodes[node_id] - all_links += node.all_link_data() + all_links += node.links() assert len(all_links) == 1 def test_link_update(self, coretlv: CoreHandler): @@ -198,7 +198,7 @@ class TestGui: ) coretlv.handle_message(message) switch_node = coretlv.session.get_node(switch_id, SwitchNode) - all_links = switch_node.all_link_data() + all_links = switch_node.links() assert len(all_links) == 1 link = all_links[0] assert link.options.bandwidth is None @@ -216,7 +216,7 @@ class TestGui: coretlv.handle_message(message) switch_node = coretlv.session.get_node(switch_id, SwitchNode) - all_links = switch_node.all_link_data() + all_links = switch_node.links() assert len(all_links) == 1 link = all_links[0] assert link.options.bandwidth == bandwidth @@ -245,7 +245,7 @@ class TestGui: all_links = [] for node_id in coretlv.session.nodes: node = coretlv.session.nodes[node_id] - all_links += node.all_link_data() + all_links += node.links() assert len(all_links) == 1 message = coreapi.CoreLinkMessage.create( @@ -262,7 +262,7 @@ class TestGui: all_links = [] for node_id in coretlv.session.nodes: node = coretlv.session.nodes[node_id] - all_links += node.all_link_data() + all_links += node.links() assert len(all_links) == 0 def test_link_delete_node_to_net(self, coretlv: CoreHandler): @@ -284,7 +284,7 @@ class TestGui: ) coretlv.handle_message(message) switch_node = coretlv.session.get_node(switch_id, SwitchNode) - all_links = switch_node.all_link_data() + all_links = switch_node.links() assert len(all_links) == 1 message = coreapi.CoreLinkMessage.create( @@ -298,7 +298,7 @@ class TestGui: coretlv.handle_message(message) switch_node = coretlv.session.get_node(switch_id, SwitchNode) - all_links = switch_node.all_link_data() + all_links = switch_node.links() assert len(all_links) == 0 def test_link_delete_net_to_node(self, coretlv: CoreHandler): @@ -320,7 +320,7 @@ class TestGui: ) coretlv.handle_message(message) switch_node = coretlv.session.get_node(switch_id, SwitchNode) - all_links = switch_node.all_link_data() + all_links = switch_node.links() assert len(all_links) == 1 message = coreapi.CoreLinkMessage.create( @@ -334,7 +334,7 @@ class TestGui: coretlv.handle_message(message) switch_node = coretlv.session.get_node(switch_id, SwitchNode) - all_links = switch_node.all_link_data() + all_links = switch_node.links() assert len(all_links) == 0 def test_session_update(self, coretlv: CoreHandler): diff --git a/daemon/tests/test_links.py b/daemon/tests/test_links.py index 4078d8bc..535ad837 100644 --- a/daemon/tests/test_links.py +++ b/daemon/tests/test_links.py @@ -49,7 +49,7 @@ class TestLinks: session.add_link(node1.id, node2.id, iface1_data=iface1_data) # then - assert node2.all_link_data() + assert node2.links() assert node1.get_iface(iface1_data.id) def test_add_net_to_node(self, session: Session, ip_prefixes: IpPrefixes): @@ -62,7 +62,7 @@ class TestLinks: session.add_link(node1.id, node2.id, iface2_data=iface2_data) # then - assert node1.all_link_data() + assert node1.links() assert node2.get_iface(iface2_data.id) def test_add_net_to_net(self, session): @@ -74,7 +74,7 @@ class TestLinks: session.add_link(node1.id, node2.id) # then - assert node1.all_link_data() + assert node1.links() def test_update_node_to_net(self, session: Session, ip_prefixes: IpPrefixes): # given diff --git a/daemon/tests/test_xml.py b/daemon/tests/test_xml.py index 91b598f3..fb8bc4d9 100644 --- a/daemon/tests/test_xml.py +++ b/daemon/tests/test_xml.py @@ -285,7 +285,7 @@ class TestXml: switch2 = session.get_node(node2_id, SwitchNode) assert switch1 assert switch2 - assert len(switch1.all_link_data() + switch2.all_link_data()) == 1 + assert len(switch1.links() + switch2.links()) == 1 def test_link_options( self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes @@ -345,7 +345,7 @@ class TestXml: links = [] for node_id in session.nodes: node = session.nodes[node_id] - links += node.all_link_data() + links += node.links() link = links[0] assert options.loss == link.options.loss assert options.bandwidth == link.options.bandwidth @@ -412,7 +412,7 @@ class TestXml: links = [] for node_id in session.nodes: node = session.nodes[node_id] - links += node.all_link_data() + links += node.links() link = links[0] assert options.loss == link.options.loss assert options.bandwidth == link.options.bandwidth @@ -490,7 +490,7 @@ class TestXml: links = [] for node_id in session.nodes: node = session.nodes[node_id] - links += node.all_link_data() + links += node.links() assert len(links) == 2 link1 = links[0] link2 = links[1]