daemon: refactored all_link_data to links
This commit is contained in:
parent
b2ea8cbbf6
commit
ca2b1c9e4c
13 changed files with 49 additions and 49 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue