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 ()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue