daemon: renamed LinkData.link_type to LinkData.type and removed LinkOptions.type to remove redundant information, link_type param added to session.add_link, delete_link, and update_link functions
This commit is contained in:
parent
a29a7a5582
commit
351b99aae0
10 changed files with 37 additions and 28 deletions
|
@ -78,7 +78,7 @@ def link_iface(iface_proto: core_pb2.Interface) -> InterfaceData:
|
|||
|
||||
def add_link_data(
|
||||
link_proto: core_pb2.Link
|
||||
) -> Tuple[InterfaceData, InterfaceData, LinkOptions]:
|
||||
) -> Tuple[InterfaceData, InterfaceData, LinkOptions, LinkTypes]:
|
||||
"""
|
||||
Convert link proto to link interfaces and options data.
|
||||
|
||||
|
@ -88,7 +88,7 @@ def add_link_data(
|
|||
iface1_data = link_iface(link_proto.iface1)
|
||||
iface2_data = link_iface(link_proto.iface2)
|
||||
link_type = LinkTypes(link_proto.type)
|
||||
options = LinkOptions(type=link_type)
|
||||
options = LinkOptions()
|
||||
options_data = link_proto.options
|
||||
if options_data:
|
||||
options.delay = options_data.delay
|
||||
|
@ -102,7 +102,7 @@ def add_link_data(
|
|||
options.unidirectional = options_data.unidirectional
|
||||
options.key = options_data.key
|
||||
options.opaque = options_data.opaque
|
||||
return iface1_data, iface2_data, options
|
||||
return iface1_data, iface2_data, options, link_type
|
||||
|
||||
|
||||
def create_nodes(
|
||||
|
@ -142,8 +142,8 @@ def create_links(
|
|||
for link_proto in link_protos:
|
||||
node1_id = link_proto.node1_id
|
||||
node2_id = link_proto.node2_id
|
||||
iface1, iface2, options = add_link_data(link_proto)
|
||||
args = (node1_id, node2_id, iface1, iface2, options)
|
||||
iface1, iface2, options, link_type = add_link_data(link_proto)
|
||||
args = (node1_id, node2_id, iface1, iface2, options, link_type)
|
||||
funcs.append((session.add_link, args, {}))
|
||||
start = time.monotonic()
|
||||
results, exceptions = utils.threadpool(funcs)
|
||||
|
@ -166,8 +166,8 @@ def edit_links(
|
|||
for link_proto in link_protos:
|
||||
node1_id = link_proto.node1_id
|
||||
node2_id = link_proto.node2_id
|
||||
iface1, iface2, options = add_link_data(link_proto)
|
||||
args = (node1_id, node2_id, iface1.id, iface2.id, options)
|
||||
iface1, iface2, options, link_type = add_link_data(link_proto)
|
||||
args = (node1_id, node2_id, iface1.id, iface2.id, options, link_type)
|
||||
funcs.append((session.update_link, args, {}))
|
||||
start = time.monotonic()
|
||||
results, exceptions = utils.threadpool(funcs)
|
||||
|
@ -350,7 +350,7 @@ def convert_link(link_data: LinkData) -> core_pb2.Link:
|
|||
iface2 = convert_iface(link_data.iface2)
|
||||
options = convert_link_options(link_data.options)
|
||||
return core_pb2.Link(
|
||||
type=link_data.link_type.value,
|
||||
type=link_data.type.value,
|
||||
node1_id=link_data.node1_id,
|
||||
node2_id=link_data.node2_id,
|
||||
iface1=iface1,
|
||||
|
|
|
@ -847,9 +847,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
node2_id = request.link.node2_id
|
||||
self.get_node(session, node1_id, context, NodeBase)
|
||||
self.get_node(session, node2_id, context, NodeBase)
|
||||
iface1_data, iface2_data, options = grpcutils.add_link_data(request.link)
|
||||
iface1_data, iface2_data, options, link_type = grpcutils.add_link_data(
|
||||
request.link
|
||||
)
|
||||
node1_iface, node2_iface = session.add_link(
|
||||
node1_id, node2_id, iface1_data, iface2_data, options=options
|
||||
node1_id, node2_id, iface1_data, iface2_data, options, link_type
|
||||
)
|
||||
iface1_proto = None
|
||||
iface2_proto = None
|
||||
|
@ -1522,7 +1524,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
|||
color = session.get_link_color(emane1.id)
|
||||
link = LinkData(
|
||||
message_type=flag,
|
||||
link_type=LinkTypes.WIRELESS,
|
||||
type=LinkTypes.WIRELESS,
|
||||
node1_id=node1.id,
|
||||
node2_id=node2.id,
|
||||
network_id=emane1.id,
|
||||
|
|
|
@ -370,7 +370,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
(LinkTlvs.MER, options_data.mer),
|
||||
(LinkTlvs.BURST, options_data.burst),
|
||||
(LinkTlvs.MBURST, options_data.mburst),
|
||||
(LinkTlvs.TYPE, link_data.link_type.value),
|
||||
(LinkTlvs.TYPE, link_data.type.value),
|
||||
(LinkTlvs.GUI_ATTRIBUTES, options_data.gui_attributes),
|
||||
(LinkTlvs.UNIDIRECTIONAL, options_data.unidirectional),
|
||||
(LinkTlvs.EMULATION_ID, options_data.emulation_id),
|
||||
|
@ -784,7 +784,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
link_type_value = message.get_tlv(LinkTlvs.TYPE.value)
|
||||
if link_type_value is not None:
|
||||
link_type = LinkTypes(link_type_value)
|
||||
options = LinkOptions(type=link_type)
|
||||
options = LinkOptions()
|
||||
options.delay = message.get_tlv(LinkTlvs.DELAY.value)
|
||||
options.bandwidth = message.get_tlv(LinkTlvs.BANDWIDTH.value)
|
||||
options.loss = message.get_tlv(LinkTlvs.LOSS.value)
|
||||
|
@ -801,12 +801,16 @@ class CoreHandler(socketserver.BaseRequestHandler):
|
|||
options.opaque = message.get_tlv(LinkTlvs.OPAQUE.value)
|
||||
|
||||
if message.flags & MessageFlags.ADD.value:
|
||||
self.session.add_link(node1_id, node2_id, iface1_data, iface2_data, options)
|
||||
self.session.add_link(
|
||||
node1_id, node2_id, iface1_data, iface2_data, options, link_type
|
||||
)
|
||||
elif message.flags & MessageFlags.DELETE.value:
|
||||
self.session.delete_link(node1_id, node2_id, iface1_data.id, iface2_data.id)
|
||||
self.session.delete_link(
|
||||
node1_id, node2_id, iface1_data.id, iface2_data.id, link_type
|
||||
)
|
||||
else:
|
||||
self.session.update_link(
|
||||
node1_id, node2_id, iface1_data.id, iface2_data.id, options
|
||||
node1_id, node2_id, iface1_data.id, iface2_data.id, options, link_type
|
||||
)
|
||||
return ()
|
||||
|
||||
|
|
|
@ -500,10 +500,10 @@ class EmaneManager(ModelManager):
|
|||
color = self.session.get_link_color(emane1.id)
|
||||
return LinkData(
|
||||
message_type=flags,
|
||||
type=LinkTypes.WIRELESS,
|
||||
node1_id=node1.id,
|
||||
node2_id=node2.id,
|
||||
network_id=emane1.id,
|
||||
link_type=LinkTypes.WIRELESS,
|
||||
color=color,
|
||||
)
|
||||
|
||||
|
|
|
@ -305,11 +305,11 @@ class EmaneLinkMonitor:
|
|||
color = self.emane_manager.session.get_link_color(emane_id)
|
||||
link_data = LinkData(
|
||||
message_type=message_type,
|
||||
type=LinkTypes.WIRELESS,
|
||||
label=label,
|
||||
node1_id=node1,
|
||||
node2_id=node2,
|
||||
network_id=emane_id,
|
||||
link_type=LinkTypes.WIRELESS,
|
||||
color=color,
|
||||
)
|
||||
self.emane_manager.session.broadcast_link(link_data)
|
||||
|
|
|
@ -132,7 +132,6 @@ class LinkOptions:
|
|||
Options for creating and updating links within core.
|
||||
"""
|
||||
|
||||
type: LinkTypes = LinkTypes.WIRED
|
||||
delay: int = None
|
||||
bandwidth: int = None
|
||||
loss: float = None
|
||||
|
@ -155,7 +154,7 @@ class LinkData:
|
|||
"""
|
||||
|
||||
message_type: MessageFlags = None
|
||||
link_type: LinkTypes = None
|
||||
type: LinkTypes = LinkTypes.WIRED
|
||||
label: str = None
|
||||
node1_id: int = None
|
||||
node2_id: int = None
|
||||
|
|
|
@ -224,6 +224,7 @@ class Session:
|
|||
iface1_data: InterfaceData = None,
|
||||
iface2_data: InterfaceData = None,
|
||||
options: LinkOptions = None,
|
||||
link_type: LinkTypes = LinkTypes.WIRED,
|
||||
) -> Tuple[CoreInterface, CoreInterface]:
|
||||
"""
|
||||
Add a link between nodes.
|
||||
|
@ -236,6 +237,7 @@ class Session:
|
|||
data, defaults to none
|
||||
:param options: data for creating link,
|
||||
defaults to no options
|
||||
:param link_type: type of link to add
|
||||
:return: tuple of created core interfaces, depending on link
|
||||
"""
|
||||
if not options:
|
||||
|
@ -246,7 +248,7 @@ class Session:
|
|||
iface2 = None
|
||||
|
||||
# wireless link
|
||||
if options.type == LinkTypes.WIRELESS:
|
||||
if link_type == LinkTypes.WIRELESS:
|
||||
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):
|
||||
self._link_wireless(node1, node2, connect=True)
|
||||
else:
|
||||
|
@ -371,6 +373,7 @@ class Session:
|
|||
iface1_id: int = None,
|
||||
iface2_id: int = None,
|
||||
options: LinkOptions = None,
|
||||
link_type: LinkTypes = LinkTypes.WIRED,
|
||||
) -> None:
|
||||
"""
|
||||
Update link information between nodes.
|
||||
|
@ -380,6 +383,7 @@ class Session:
|
|||
:param iface1_id: interface id for node one
|
||||
:param iface2_id: interface id for node two
|
||||
:param options: data to update link with
|
||||
:param link_type: type of link to update
|
||||
:return: nothing
|
||||
:raises core.CoreError: when updating a wireless type link, when there is a
|
||||
unknown link between networks
|
||||
|
@ -390,7 +394,7 @@ class Session:
|
|||
node2 = self.get_node(node2_id, NodeBase)
|
||||
logging.info(
|
||||
"update link(%s) node(%s):interface(%s) node(%s):interface(%s)",
|
||||
options.type.name,
|
||||
link_type.name,
|
||||
node1.name,
|
||||
iface1_id,
|
||||
node2.name,
|
||||
|
@ -398,7 +402,7 @@ class Session:
|
|||
)
|
||||
|
||||
# wireless link
|
||||
if options.type == LinkTypes.WIRELESS:
|
||||
if link_type == LinkTypes.WIRELESS:
|
||||
raise CoreError("cannot update wireless link")
|
||||
else:
|
||||
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):
|
||||
|
|
|
@ -487,10 +487,10 @@ class BasicRangeModel(WirelessModel):
|
|||
color = self.session.get_link_color(self.wlan.id)
|
||||
return LinkData(
|
||||
message_type=message_type,
|
||||
type=LinkTypes.WIRELESS,
|
||||
node1_id=iface1.node.id,
|
||||
node2_id=iface2.node.id,
|
||||
network_id=self.wlan.id,
|
||||
link_type=LinkTypes.WIRELESS,
|
||||
color=color,
|
||||
)
|
||||
|
||||
|
|
|
@ -1109,9 +1109,9 @@ class CoreNetworkBase(NodeBase):
|
|||
options_data = iface.get_link_options(unidirectional)
|
||||
link_data = LinkData(
|
||||
message_type=flags,
|
||||
type=self.linktype,
|
||||
node1_id=self.id,
|
||||
node2_id=linked_node.id,
|
||||
link_type=self.linktype,
|
||||
iface2=iface2,
|
||||
options=options_data,
|
||||
)
|
||||
|
@ -1123,9 +1123,9 @@ class CoreNetworkBase(NodeBase):
|
|||
options_data = iface.get_link_options(unidirectional)
|
||||
link_data = LinkData(
|
||||
message_type=MessageFlags.NONE,
|
||||
type=self.linktype,
|
||||
node1_id=linked_node.id,
|
||||
node2_id=self.id,
|
||||
link_type=self.linktype,
|
||||
options=options_data,
|
||||
)
|
||||
iface.swapparams("_params_up")
|
||||
|
|
|
@ -923,9 +923,9 @@ class PtpNet(CoreNetwork):
|
|||
options_data = iface1.get_link_options(unidirectional)
|
||||
link_data = LinkData(
|
||||
message_type=flags,
|
||||
type=self.linktype,
|
||||
node1_id=iface1.node.id,
|
||||
node2_id=iface2.node.id,
|
||||
link_type=self.linktype,
|
||||
iface1=iface1_data,
|
||||
iface2=iface2_data,
|
||||
options=options_data,
|
||||
|
@ -940,7 +940,7 @@ class PtpNet(CoreNetwork):
|
|||
options_data = iface2.get_link_options(unidirectional)
|
||||
link_data = LinkData(
|
||||
message_type=MessageFlags.NONE,
|
||||
link_type=self.linktype,
|
||||
type=self.linktype,
|
||||
node1_id=iface2.node.id,
|
||||
node2_id=iface1.node.id,
|
||||
iface1=iface1_data,
|
||||
|
|
Loading…
Reference in a new issue