variable/grpc cleanup to rename everything using spelt out numbers instead of actual numbers

This commit is contained in:
Blake Harnden 2020-06-12 16:52:41 -07:00
parent b28ef76d65
commit 876699e8ef
45 changed files with 932 additions and 966 deletions

View file

@ -609,30 +609,30 @@ class CoreGrpcClient:
def add_link(
self,
session_id: int,
node_one_id: int,
node_two_id: int,
interface_one: core_pb2.Interface = None,
interface_two: core_pb2.Interface = None,
node1_id: int,
node2_id: int,
interface1: core_pb2.Interface = None,
interface2: core_pb2.Interface = None,
options: core_pb2.LinkOptions = None,
) -> core_pb2.AddLinkResponse:
"""
Add a link between nodes.
:param session_id: session id
:param node_one_id: node one id
:param node_two_id: node two id
:param interface_one: node one interface data
:param interface_two: node two interface data
:param node1_id: node one id
:param node2_id: node two id
:param interface1: node one interface data
:param interface2: node two interface data
:param options: options for link (jitter, bandwidth, etc)
:return: response with result of success or failure
:raises grpc.RpcError: when session or one of the nodes don't exist
"""
link = core_pb2.Link(
node_one_id=node_one_id,
node_two_id=node_two_id,
node1_id=node1_id,
node2_id=node2_id,
type=core_pb2.LinkType.WIRED,
interface_one=interface_one,
interface_two=interface_two,
interface1=interface1,
interface2=interface2,
options=options,
)
request = core_pb2.AddLinkRequest(session_id=session_id, link=link)
@ -641,59 +641,59 @@ class CoreGrpcClient:
def edit_link(
self,
session_id: int,
node_one_id: int,
node_two_id: int,
node1_id: int,
node2_id: int,
options: core_pb2.LinkOptions,
interface_one_id: int = None,
interface_two_id: int = None,
interface1_id: int = None,
interface2_id: int = None,
) -> core_pb2.EditLinkResponse:
"""
Edit a link between nodes.
:param session_id: session id
:param node_one_id: node one id
:param node_two_id: node two id
:param node1_id: node one id
:param node2_id: node two id
:param options: options for link (jitter, bandwidth, etc)
:param interface_one_id: node one interface id
:param interface_two_id: node two interface id
:param interface1_id: node one interface id
:param interface2_id: node two interface id
:return: response with result of success or failure
:raises grpc.RpcError: when session or one of the nodes don't exist
"""
request = core_pb2.EditLinkRequest(
session_id=session_id,
node_one_id=node_one_id,
node_two_id=node_two_id,
node1_id=node1_id,
node2_id=node2_id,
options=options,
interface_one_id=interface_one_id,
interface_two_id=interface_two_id,
interface1_id=interface1_id,
interface2_id=interface2_id,
)
return self.stub.EditLink(request)
def delete_link(
self,
session_id: int,
node_one_id: int,
node_two_id: int,
interface_one_id: int = None,
interface_two_id: int = None,
node1_id: int,
node2_id: int,
interface1_id: int = None,
interface2_id: int = None,
) -> core_pb2.DeleteLinkResponse:
"""
Delete a link between nodes.
:param session_id: session id
:param node_one_id: node one id
:param node_two_id: node two id
:param interface_one_id: node one interface id
:param interface_two_id: node two interface id
:param node1_id: node one id
:param node2_id: node two id
:param interface1_id: node one interface id
:param interface2_id: node two interface id
:return: response with result of success or failure
:raises grpc.RpcError: when session doesn't exist
"""
request = core_pb2.DeleteLinkRequest(
session_id=session_id,
node_one_id=node_one_id,
node_two_id=node_two_id,
interface_one_id=interface_one_id,
interface_two_id=interface_two_id,
node1_id=node1_id,
node2_id=node2_id,
interface1_id=interface1_id,
interface2_id=interface2_id,
)
return self.stub.DeleteLink(request)
@ -1111,20 +1111,20 @@ class CoreGrpcClient:
return self.stub.OpenXml(request)
def emane_link(
self, session_id: int, nem_one: int, nem_two: int, linked: bool
self, session_id: int, nem1: int, nem2: int, linked: bool
) -> EmaneLinkResponse:
"""
Helps broadcast wireless link/unlink between EMANE nodes.
:param session_id: session to emane link
:param nem_one: first nem for emane link
:param nem_two: second nem for emane link
:param nem1: first nem for emane link
:param nem2: second nem for emane link
:param linked: True to link, False to unlink
:return: get emane link response
:raises grpc.RpcError: when session or nodes related to nems do not exist
"""
request = EmaneLinkRequest(
session_id=session_id, nem_one=nem_one, nem_two=nem_two, linked=linked
session_id=session_id, nem1=nem1, nem2=nem2, linked=linked
)
return self.stub.EmaneLink(request)
@ -1243,24 +1243,24 @@ class CoreGrpcClient:
return self.stub.ExecuteScript(request)
def wlan_link(
self, session_id: int, wlan: int, node_one: int, node_two: int, linked: bool
self, session_id: int, wlan_id: int, node1_id: int, node2_id: int, linked: bool
) -> WlanLinkResponse:
"""
Links/unlinks nodes on the same WLAN.
:param session_id: session id containing wlan and nodes
:param wlan: wlan nodes must belong to
:param node_one: first node of pair to link/unlink
:param node_two: second node of pair to link/unlin
:param wlan_id: wlan nodes must belong to
:param node1_id: first node of pair to link/unlink
:param node2_id: second node of pair to link/unlin
:param linked: True to link, False to unlink
:return: wlan link response
:raises grpc.RpcError: when session or one of the nodes do not exist
"""
request = WlanLinkRequest(
session_id=session_id,
wlan=wlan,
node_one=node_one,
node_two=node_two,
wlan=wlan_id,
node1_id=node1_id,
node2_id=node2_id,
linked=linked,
)
return self.stub.WlanLink(request)

View file

@ -86,8 +86,8 @@ def add_link_data(
:param link_proto: link proto
:return: link interfaces and options
"""
interface_one = link_interface(link_proto.interface_one)
interface_two = link_interface(link_proto.interface_two)
interface1_data = link_interface(link_proto.interface1)
interface2_data = link_interface(link_proto.interface2)
link_type = LinkTypes(link_proto.type)
options = LinkOptions(type=link_type)
options_data = link_proto.options
@ -103,7 +103,7 @@ def add_link_data(
options.unidirectional = options_data.unidirectional
options.key = options_data.key
options.opaque = options_data.opaque
return interface_one, interface_two, options
return interface1_data, interface2_data, options
def create_nodes(
@ -141,10 +141,10 @@ def create_links(
"""
funcs = []
for link_proto in link_protos:
node_one_id = link_proto.node_one_id
node_two_id = link_proto.node_two_id
interface_one, interface_two, options = add_link_data(link_proto)
args = (node_one_id, node_two_id, interface_one, interface_two, options)
node1_id = link_proto.node1_id
node2_id = link_proto.node2_id
interface1, interface2, options = add_link_data(link_proto)
args = (node1_id, node2_id, interface1, interface2, options)
funcs.append((session.add_link, args, {}))
start = time.monotonic()
results, exceptions = utils.threadpool(funcs)
@ -165,10 +165,10 @@ def edit_links(
"""
funcs = []
for link_proto in link_protos:
node_one_id = link_proto.node_one_id
node_two_id = link_proto.node_two_id
interface_one, interface_two, options = add_link_data(link_proto)
args = (node_one_id, node_two_id, interface_one.id, interface_two.id, options)
node1_id = link_proto.node1_id
node2_id = link_proto.node2_id
interface1, interface2, options = add_link_data(link_proto)
args = (node1_id, node2_id, interface1.id, interface2.id, options)
funcs.append((session.update_link, args, {}))
start = time.monotonic()
results, exceptions = utils.threadpool(funcs)
@ -315,9 +315,9 @@ def convert_link(link_data: LinkData) -> core_pb2.Link:
:param link_data: link to convert
:return: core protobuf Link
"""
interface_one = None
interface1 = None
if link_data.interface1_id is not None:
interface_one = core_pb2.Interface(
interface1 = core_pb2.Interface(
id=link_data.interface1_id,
name=link_data.interface1_name,
mac=convert_value(link_data.interface1_mac),
@ -326,9 +326,9 @@ def convert_link(link_data: LinkData) -> core_pb2.Link:
ip6=convert_value(link_data.interface1_ip6),
ip6mask=link_data.interface1_ip6_mask,
)
interface_two = None
interface2 = None
if link_data.interface2_id is not None:
interface_two = core_pb2.Interface(
interface2 = core_pb2.Interface(
id=link_data.interface2_id,
name=link_data.interface2_name,
mac=convert_value(link_data.interface2_mac),
@ -352,10 +352,10 @@ def convert_link(link_data: LinkData) -> core_pb2.Link:
)
return core_pb2.Link(
type=link_data.link_type.value,
node_one_id=link_data.node1_id,
node_two_id=link_data.node2_id,
interface_one=interface_one,
interface_two=interface_two,
node1_id=link_data.node1_id,
node2_id=link_data.node2_id,
interface1=interface1,
interface2=interface2,
options=options,
network_id=link_data.network_id,
label=link_data.label,

View file

@ -845,27 +845,23 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
:return: add-link response
"""
logging.debug("add link: %s", request)
# validate session and nodes
session = self.get_session(request.session_id, context)
self.get_node(session, request.link.node_one_id, context, NodeBase)
self.get_node(session, request.link.node_two_id, context, NodeBase)
node_one_id = request.link.node_one_id
node_two_id = request.link.node_two_id
interface_one, interface_two, options = grpcutils.add_link_data(request.link)
node_one_interface, node_two_interface = session.add_link(
node_one_id, node_two_id, interface_one, interface_two, options=options
node1_id = request.link.node1_id
node2_id = request.link.node2_id
self.get_node(session, node1_id, context, NodeBase)
self.get_node(session, node2_id, context, NodeBase)
interface1, interface2, options = grpcutils.add_link_data(request.link)
node1_interface, node2_interface = session.add_link(
node1_id, node2_id, interface1, interface2, options=options
)
interface_one_proto = None
interface_two_proto = None
if node_one_interface:
interface_one_proto = grpcutils.interface_to_proto(node_one_interface)
if node_two_interface:
interface_two_proto = grpcutils.interface_to_proto(node_two_interface)
interface1_proto = None
interface2_proto = None
if node1_interface:
interface1_proto = grpcutils.interface_to_proto(node1_interface)
if node2_interface:
interface2_proto = grpcutils.interface_to_proto(node2_interface)
return core_pb2.AddLinkResponse(
result=True,
interface_one=interface_one_proto,
interface_two=interface_two_proto,
result=True, interface1=interface1_proto, interface2=interface2_proto
)
def EditLink(
@ -880,10 +876,10 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
"""
logging.debug("edit link: %s", request)
session = self.get_session(request.session_id, context)
node_one_id = request.node_one_id
node_two_id = request.node_two_id
interface_one_id = request.interface_one_id
interface_two_id = request.interface_two_id
node1_id = request.node1_id
node2_id = request.node2_id
interface1_id = request.interface1_id
interface2_id = request.interface2_id
options_data = request.options
link_options = LinkOptions()
link_options.delay = options_data.delay
@ -898,7 +894,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
link_options.key = options_data.key
link_options.opaque = options_data.opaque
session.update_link(
node_one_id, node_two_id, interface_one_id, interface_two_id, link_options
node1_id, node2_id, interface1_id, interface2_id, link_options
)
return core_pb2.EditLinkResponse(result=True)
@ -914,13 +910,11 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
"""
logging.debug("delete link: %s", request)
session = self.get_session(request.session_id, context)
node_one_id = request.node_one_id
node_two_id = request.node_two_id
interface_one_id = request.interface_one_id
interface_two_id = request.interface_two_id
session.delete_link(
node_one_id, node_two_id, interface_one_id, interface_two_id
)
node1_id = request.node1_id
node2_id = request.node2_id
interface1_id = request.interface1_id
interface2_id = request.interface2_id
session.delete_link(node1_id, node2_id, interface1_id, interface2_id)
return core_pb2.DeleteLinkResponse(result=True)
def GetHooks(
@ -1519,30 +1513,30 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
"""
logging.debug("emane link: %s", request)
session = self.get_session(request.session_id, context)
nem_one = request.nem_one
emane_one, netif = session.emane.nemlookup(nem_one)
if not emane_one or not netif:
context.abort(grpc.StatusCode.NOT_FOUND, f"nem one {nem_one} not found")
node_one = netif.node
nem1 = request.nem1
emane1, netif = session.emane.nemlookup(nem1)
if not emane1 or not netif:
context.abort(grpc.StatusCode.NOT_FOUND, f"nem one {nem1} not found")
node1 = netif.node
nem_two = request.nem_two
emane_two, netif = session.emane.nemlookup(nem_two)
if not emane_two or not netif:
context.abort(grpc.StatusCode.NOT_FOUND, f"nem two {nem_two} not found")
node_two = netif.node
nem2 = request.nem2
emane2, netif = session.emane.nemlookup(nem2)
if not emane2 or not netif:
context.abort(grpc.StatusCode.NOT_FOUND, f"nem two {nem2} not found")
node2 = netif.node
if emane_one.id == emane_two.id:
if emane1.id == emane2.id:
if request.linked:
flag = MessageFlags.ADD
else:
flag = MessageFlags.DELETE
color = session.get_link_color(emane_one.id)
color = session.get_link_color(emane1.id)
link = LinkData(
message_type=flag,
link_type=LinkTypes.WIRELESS,
node1_id=node_one.id,
node2_id=node_two.id,
network_id=emane_one.id,
node1_id=node1.id,
node2_id=node2.id,
network_id=emane1.id,
color=color,
)
session.broadcast_link(link)
@ -1739,21 +1733,23 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
grpc.StatusCode.NOT_FOUND,
f"wlan node {request.wlan} does not using BasicRangeModel",
)
n1 = self.get_node(session, request.node_one, context, CoreNode)
n2 = self.get_node(session, request.node_two, context, CoreNode)
n1_netif, n2_netif = None, None
for net, netif1, netif2 in n1.commonnets(n2):
node1 = self.get_node(session, request.node1_id, context, CoreNode)
node2 = self.get_node(session, request.node2_id, context, CoreNode)
node1_interface, node2_interface = None, None
for net, interface1, interface2 in node1.commonnets(node2):
if net == wlan:
n1_netif = netif1
n2_netif = netif2
node1_interface = interface1
node2_interface = interface2
break
result = False
if n1_netif and n2_netif:
if node1_interface and node2_interface:
if request.linked:
wlan.link(n1_netif, n2_netif)
wlan.link(node1_interface, node2_interface)
else:
wlan.unlink(n1_netif, n2_netif)
wlan.model.sendlinkmsg(n1_netif, n2_netif, unlink=not request.linked)
wlan.unlink(node1_interface, node2_interface)
wlan.model.sendlinkmsg(
node1_interface, node2_interface, unlink=not request.linked
)
result = True
return WlanLinkResponse(result=result)
@ -1764,9 +1760,9 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
) -> EmanePathlossesResponse:
for request in request_iterator:
session = self.get_session(request.session_id, context)
n1 = self.get_node(session, request.node_one, context, CoreNode)
nem1 = grpcutils.get_nem_id(n1, request.interface_one_id, context)
n2 = self.get_node(session, request.node_two, context, CoreNode)
nem2 = grpcutils.get_nem_id(n2, request.interface_two_id, context)
session.emane.publish_pathloss(nem1, nem2, request.rx_one, request.rx_two)
node1 = self.get_node(session, request.node1_id, context, CoreNode)
nem1 = grpcutils.get_nem_id(node1, request.interface1_id, context)
node2 = self.get_node(session, request.node2_id, context, CoreNode)
nem2 = grpcutils.get_nem_id(node2, request.interface2_id, context)
session.emane.publish_pathloss(nem1, nem2, request.rx1, request.rx2)
return EmanePathlossesResponse()

View file

@ -745,10 +745,9 @@ class CoreHandler(socketserver.BaseRequestHandler):
:param core.api.tlv.coreapi.CoreLinkMessage message: link message to handle
:return: link message replies
"""
node_one_id = message.get_tlv(LinkTlvs.N1_NUMBER.value)
node_two_id = message.get_tlv(LinkTlvs.N2_NUMBER.value)
interface_one = InterfaceData(
node1_id = message.get_tlv(LinkTlvs.N1_NUMBER.value)
node2_id = message.get_tlv(LinkTlvs.N2_NUMBER.value)
interface1_data = InterfaceData(
id=message.get_tlv(LinkTlvs.INTERFACE1_NUMBER.value),
name=message.get_tlv(LinkTlvs.INTERFACE1_NAME.value),
mac=message.get_tlv(LinkTlvs.INTERFACE1_MAC.value),
@ -757,7 +756,7 @@ class CoreHandler(socketserver.BaseRequestHandler):
ip6=message.get_tlv(LinkTlvs.INTERFACE1_IP6.value),
ip6_mask=message.get_tlv(LinkTlvs.INTERFACE1_IP6_MASK.value),
)
interface_two = InterfaceData(
interface2_data = InterfaceData(
id=message.get_tlv(LinkTlvs.INTERFACE2_NUMBER.value),
name=message.get_tlv(LinkTlvs.INTERFACE2_NAME.value),
mac=message.get_tlv(LinkTlvs.INTERFACE2_MAC.value),
@ -766,45 +765,38 @@ class CoreHandler(socketserver.BaseRequestHandler):
ip6=message.get_tlv(LinkTlvs.INTERFACE2_IP6.value),
ip6_mask=message.get_tlv(LinkTlvs.INTERFACE2_IP6_MASK.value),
)
link_type = LinkTypes.WIRED
link_type_value = message.get_tlv(LinkTlvs.TYPE.value)
if link_type_value is not None:
link_type = LinkTypes(link_type_value)
link_options = LinkOptions(type=link_type)
link_options.delay = message.get_tlv(LinkTlvs.DELAY.value)
link_options.bandwidth = message.get_tlv(LinkTlvs.BANDWIDTH.value)
link_options.session = message.get_tlv(LinkTlvs.SESSION.value)
link_options.per = message.get_tlv(LinkTlvs.PER.value)
link_options.dup = message.get_tlv(LinkTlvs.DUP.value)
link_options.jitter = message.get_tlv(LinkTlvs.JITTER.value)
link_options.mer = message.get_tlv(LinkTlvs.MER.value)
link_options.burst = message.get_tlv(LinkTlvs.BURST.value)
link_options.mburst = message.get_tlv(LinkTlvs.MBURST.value)
link_options.gui_attributes = message.get_tlv(LinkTlvs.GUI_ATTRIBUTES.value)
link_options.unidirectional = message.get_tlv(LinkTlvs.UNIDIRECTIONAL.value)
link_options.emulation_id = message.get_tlv(LinkTlvs.EMULATION_ID.value)
link_options.network_id = message.get_tlv(LinkTlvs.NETWORK_ID.value)
link_options.key = message.get_tlv(LinkTlvs.KEY.value)
link_options.opaque = message.get_tlv(LinkTlvs.OPAQUE.value)
options = LinkOptions(type=link_type)
options.delay = message.get_tlv(LinkTlvs.DELAY.value)
options.bandwidth = message.get_tlv(LinkTlvs.BANDWIDTH.value)
options.session = message.get_tlv(LinkTlvs.SESSION.value)
options.per = message.get_tlv(LinkTlvs.PER.value)
options.dup = message.get_tlv(LinkTlvs.DUP.value)
options.jitter = message.get_tlv(LinkTlvs.JITTER.value)
options.mer = message.get_tlv(LinkTlvs.MER.value)
options.burst = message.get_tlv(LinkTlvs.BURST.value)
options.mburst = message.get_tlv(LinkTlvs.MBURST.value)
options.gui_attributes = message.get_tlv(LinkTlvs.GUI_ATTRIBUTES.value)
options.unidirectional = message.get_tlv(LinkTlvs.UNIDIRECTIONAL.value)
options.emulation_id = message.get_tlv(LinkTlvs.EMULATION_ID.value)
options.network_id = message.get_tlv(LinkTlvs.NETWORK_ID.value)
options.key = message.get_tlv(LinkTlvs.KEY.value)
options.opaque = message.get_tlv(LinkTlvs.OPAQUE.value)
if message.flags & MessageFlags.ADD.value:
self.session.add_link(
node_one_id, node_two_id, interface_one, interface_two, link_options
node1_id, node2_id, interface1_data, interface2_data, options
)
elif message.flags & MessageFlags.DELETE.value:
self.session.delete_link(
node_one_id, node_two_id, interface_one.id, interface_two.id
node1_id, node2_id, interface1_data.id, interface2_data.id
)
else:
self.session.update_link(
node_one_id,
node_two_id,
interface_one.id,
interface_two.id,
link_options,
node1_id, node2_id, interface1_data.id, interface2_data.id, options
)
return ()
def handle_execute_message(self, message):

View file

@ -269,11 +269,11 @@ class EmaneLinkMonitor:
self.scheduler.enter(self.link_interval, 0, self.check_links)
def get_complete_id(self, link_id: Tuple[int, int]) -> Tuple[int, int]:
value_one, value_two = link_id
if value_one < value_two:
return value_one, value_two
value1, value2 = link_id
if value1 < value2:
return value1, value2
else:
return value_two, value_one
return value2, value1
def is_complete_link(self, link_id: Tuple[int, int]) -> bool:
reverse_id = link_id[1], link_id[0]
@ -287,8 +287,8 @@ class EmaneLinkMonitor:
return f"{source_link.sinr:.1f} / {dest_link.sinr:.1f}"
def send_link(self, message_type: MessageFlags, link_id: Tuple[int, int]) -> None:
nem_one, nem_two = link_id
link = self.emane_manager.get_nem_link(nem_one, nem_two, message_type)
nem1, nem2 = link_id
link = self.emane_manager.get_nem_link(nem1, nem2, message_type)
if link:
label = self.get_link_label(link_id)
link.label = label
@ -298,16 +298,16 @@ class EmaneLinkMonitor:
self,
message_type: MessageFlags,
label: str,
node_one: int,
node_two: int,
node1: int,
node2: int,
emane_id: int,
) -> None:
color = self.emane_manager.session.get_link_color(emane_id)
link_data = LinkData(
message_type=message_type,
label=label,
node1_id=node_one,
node2_id=node_two,
node1_id=node1,
node2_id=node2,
network_id=emane_id,
link_type=LinkTypes.WIRELESS,
color=color,

View file

@ -224,18 +224,20 @@ class DistributedController:
self.tunnels[key] = tunnel
return tunnel
def tunnel_key(self, n1_id: int, n2_id: int) -> int:
def tunnel_key(self, node1_id: int, node2_id: int) -> int:
"""
Compute a 32-bit key used to uniquely identify a GRE tunnel.
The hash(n1num), hash(n2num) values are used, so node numbers may be
None or string values (used for e.g. "ctrlnet").
:param n1_id: node one id
:param n2_id: node two id
:param node1_id: node one id
:param node2_id: node two id
:return: tunnel key for the node pair
"""
logging.debug("creating tunnel key for: %s, %s", n1_id, n2_id)
logging.debug("creating tunnel key for: %s, %s", node1_id, node2_id)
key = (
(self.session.id << 16) ^ utils.hashkey(n1_id) ^ (utils.hashkey(n2_id) << 8)
(self.session.id << 16)
^ utils.hashkey(node1_id)
^ (utils.hashkey(node2_id) << 8)
)
return key & 0xFFFFFFFF

View file

@ -194,13 +194,13 @@ class Session:
return node_type
def _link_wireless(
self, node_one: CoreNodeBase, node_two: CoreNodeBase, connect: bool
self, node1: CoreNodeBase, node2: CoreNodeBase, connect: bool
) -> None:
"""
Objects to deal with when connecting/disconnecting wireless links.
:param node_one: node one for wireless link
:param node_two: node two for wireless link
:param node1: node one for wireless link
:param node2: node two for wireless link
:param connect: link interfaces if True, unlink otherwise
:return: nothing
:raises core.CoreError: when objects to link is less than 2, or no common
@ -208,14 +208,14 @@ class Session:
"""
logging.info(
"handling wireless linking node1(%s) node2(%s): %s",
node_one.name,
node_two.name,
node1.name,
node2.name,
connect,
)
common_networks = node_one.commonnets(node_one)
common_networks = node1.commonnets(node1)
if not common_networks:
raise CoreError("no common network found for wireless link/unlink")
for common_network, interface_one, interface_two in common_networks:
for common_network, interface1, interface2 in common_networks:
if not isinstance(common_network, (WlanNode, EmaneNet)):
logging.info(
"skipping common network that is not wireless/emane: %s",
@ -223,26 +223,26 @@ class Session:
)
continue
if connect:
common_network.link(interface_one, interface_two)
common_network.link(interface1, interface2)
else:
common_network.unlink(interface_one, interface_two)
common_network.unlink(interface1, interface2)
def add_link(
self,
node_one_id: int,
node_two_id: int,
interface_one: InterfaceData = None,
interface_two: InterfaceData = None,
node1_id: int,
node2_id: int,
interface1_data: InterfaceData = None,
interface2_data: InterfaceData = None,
options: LinkOptions = None,
) -> Tuple[CoreInterface, CoreInterface]:
"""
Add a link between nodes.
:param node_one_id: node one id
:param node_two_id: node two id
:param interface_one: node one interface
:param node1_id: node one id
:param node2_id: node two id
:param interface1_data: node one interface
data, defaults to none
:param interface_two: node two interface
:param interface2_data: node two interface
data, defaults to none
:param options: data for creating link,
defaults to no options
@ -250,10 +250,10 @@ class Session:
"""
if not options:
options = LinkOptions()
node1 = self.get_node(node_one_id, NodeBase)
node2 = self.get_node(node_two_id, NodeBase)
node1_interface = None
node2_interface = None
node1 = self.get_node(node1_id, NodeBase)
node2 = self.get_node(node2_id, NodeBase)
interface1 = None
interface2 = None
# wireless link
if options.type == LinkTypes.WIRELESS:
@ -270,22 +270,22 @@ class Session:
logging.info("linking ptp: %s - %s", node1.name, node2.name)
start = self.state.should_start()
ptp = self.create_node(PtpNet, start=start)
node1_interface = node1.newnetif(ptp, interface_one)
node2_interface = node2.newnetif(ptp, interface_two)
ptp.linkconfig(node1_interface, options)
interface1 = node1.newnetif(ptp, interface1_data)
interface2 = node2.newnetif(ptp, interface2_data)
ptp.linkconfig(interface1, options)
if not options.unidirectional:
ptp.linkconfig(node2_interface, options)
ptp.linkconfig(interface2, options)
# link node to net
elif isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNetworkBase):
node1_interface = node1.newnetif(node2, interface_one)
interface1 = node1.newnetif(node2, interface1_data)
if not isinstance(node2, (EmaneNet, WlanNode)):
node2.linkconfig(node1_interface, options)
node2.linkconfig(interface1, options)
# link net to node
elif isinstance(node2, CoreNodeBase) and isinstance(node1, CoreNetworkBase):
node2_interface = node2.newnetif(node1, interface_two)
interface2 = node2.newnetif(node1, interface2_data)
wireless_net = isinstance(node1, (EmaneNet, WlanNode))
if not options.unidirectional and not wireless_net:
node1.linkconfig(node2_interface, options)
node1.linkconfig(interface2, options)
# network to network
elif isinstance(node1, CoreNetworkBase) and isinstance(
node2, CoreNetworkBase
@ -293,12 +293,12 @@ class Session:
logging.info(
"linking network to network: %s - %s", node1.name, node2.name
)
node1_interface = node1.linknet(node2)
node1.linkconfig(node1_interface, options)
interface1 = node1.linknet(node2)
node1.linkconfig(interface1, options)
if not options.unidirectional:
node1_interface.swapparams("_params_up")
node2.linkconfig(node1_interface, options)
node1_interface.swapparams("_params_up")
interface1.swapparams("_params_up")
node2.linkconfig(interface1, options)
interface1.swapparams("_params_up")
else:
raise CoreError(
f"cannot link node1({type(node1)}) node2({type(node2)})"
@ -308,41 +308,41 @@ class Session:
key = options.key
if isinstance(node1, TunnelNode):
logging.info("setting tunnel key for: %s", node1.name)
node1.setkey(key, interface_one)
node1.setkey(key, interface1_data)
if isinstance(node2, TunnelNode):
logging.info("setting tunnel key for: %s", node2.name)
node2.setkey(key, interface_two)
self.sdt.add_link(node_one_id, node_two_id)
return node1_interface, node2_interface
node2.setkey(key, interface2_data)
self.sdt.add_link(node1_id, node2_id)
return interface1, interface2
def delete_link(
self,
node_one_id: int,
node_two_id: int,
interface_one_id: int = None,
interface_two_id: int = None,
node1_id: int,
node2_id: int,
interface1_id: int = None,
interface2_id: int = None,
link_type: LinkTypes = LinkTypes.WIRED,
) -> None:
"""
Delete a link between nodes.
:param node_one_id: node one id
:param node_two_id: node two id
:param interface_one_id: interface id for node one
:param interface_two_id: interface id for node two
:param node1_id: node one id
:param node2_id: node two id
:param interface1_id: interface id for node one
:param interface2_id: interface id for node two
:param link_type: link type to delete
:return: nothing
:raises core.CoreError: when no common network is found for link being deleted
"""
node1 = self.get_node(node_one_id, NodeBase)
node2 = self.get_node(node_two_id, NodeBase)
node1 = self.get_node(node1_id, NodeBase)
node2 = self.get_node(node2_id, NodeBase)
logging.info(
"deleting link(%s) node(%s):interface(%s) node(%s):interface(%s)",
link_type.name,
node1.name,
interface_one_id,
interface1_id,
node2.name,
interface_two_id,
interface2_id,
)
# wireless link
@ -357,15 +357,15 @@ class Session:
# wired link
else:
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):
interface1 = node1.netif(interface_one_id)
interface2 = node2.netif(interface_two_id)
interface1 = node1.netif(interface1_id)
interface2 = node2.netif(interface2_id)
if not interface1:
raise CoreError(
f"node({node1.name}) missing interface({interface_one_id})"
f"node({node1.name}) missing interface({interface1_id})"
)
if not interface2:
raise CoreError(
f"node({node2.name}) missing interface({interface_two_id})"
f"node({node2.name}) missing interface({interface2_id})"
)
if interface1.net != interface2.net:
raise CoreError(
@ -373,30 +373,30 @@ class Session:
"not connected to same net"
)
ptp = interface1.net
node1.delnetif(interface_one_id)
node2.delnetif(interface_two_id)
node1.delnetif(interface1_id)
node2.delnetif(interface2_id)
self.delete_node(ptp.id)
elif isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNetworkBase):
node1.delnetif(interface_one_id)
node1.delnetif(interface1_id)
elif isinstance(node2, CoreNodeBase) and isinstance(node1, CoreNetworkBase):
node2.delnetif(interface_two_id)
self.sdt.delete_link(node_one_id, node_two_id)
node2.delnetif(interface2_id)
self.sdt.delete_link(node1_id, node2_id)
def update_link(
self,
node_one_id: int,
node_two_id: int,
interface_one_id: int = None,
interface_two_id: int = None,
node1_id: int,
node2_id: int,
interface1_id: int = None,
interface2_id: int = None,
options: LinkOptions = None,
) -> None:
"""
Update link information between nodes.
:param node_one_id: node one id
:param node_two_id: node two id
:param interface_one_id: interface id for node one
:param interface_two_id: interface id for node two
:param node1_id: node one id
:param node2_id: node two id
:param interface1_id: interface id for node one
:param interface2_id: interface id for node two
:param options: data to update link with
:return: nothing
:raises core.CoreError: when updating a wireless type link, when there is a
@ -404,15 +404,15 @@ class Session:
"""
if not options:
options = LinkOptions()
node1 = self.get_node(node_one_id, NodeBase)
node2 = self.get_node(node_two_id, NodeBase)
node1 = self.get_node(node1_id, NodeBase)
node2 = self.get_node(node2_id, NodeBase)
logging.info(
"update link(%s) node(%s):interface(%s) node(%s):interface(%s)",
options.type.name,
node1.name,
interface_one_id,
interface1_id,
node2.name,
interface_two_id,
interface2_id,
)
# wireless link
@ -420,15 +420,15 @@ class Session:
raise CoreError("cannot update wireless link")
else:
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):
interface1 = node1.netif(interface_one_id)
interface2 = node2.netif(interface_two_id)
interface1 = node1.netif(interface1_id)
interface2 = node2.netif(interface2_id)
if not interface1:
raise CoreError(
f"node({node1.name}) missing interface({interface_one_id})"
f"node({node1.name}) missing interface({interface1_id})"
)
if not interface2:
raise CoreError(
f"node({node2.name}) missing interface({interface_two_id})"
f"node({node2.name}) missing interface({interface2_id})"
)
if interface1.net != interface2.net:
raise CoreError(
@ -440,10 +440,10 @@ class Session:
if not options.unidirectional:
ptp.linkconfig(interface2, options, interface1)
elif isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNetworkBase):
interface = node1.netif(interface_one_id)
interface = node1.netif(interface1_id)
node2.linkconfig(interface, options)
elif isinstance(node2, CoreNodeBase) and isinstance(node1, CoreNetworkBase):
interface = node2.netif(interface_two_id)
interface = node2.netif(interface2_id)
node1.linkconfig(interface, options)
elif isinstance(node1, CoreNetworkBase) and isinstance(
node2, CoreNetworkBase

View file

@ -164,25 +164,19 @@ class CoreClient:
def handle_link_event(self, event: core_pb2.LinkEvent):
logging.debug("Link event: %s", event)
node_one_id = event.link.node_one_id
node_two_id = event.link.node_two_id
if node_one_id == node_two_id:
node1_id = event.link.node1_id
node2_id = event.link.node2_id
if node1_id == node2_id:
logging.warning("ignoring links with loops: %s", event)
return
canvas_node_one = self.canvas_nodes[node_one_id]
canvas_node_two = self.canvas_nodes[node_two_id]
canvas_node1 = self.canvas_nodes[node1_id]
canvas_node2 = self.canvas_nodes[node2_id]
if event.message_type == core_pb2.MessageType.ADD:
self.app.canvas.add_wireless_edge(
canvas_node_one, canvas_node_two, event.link
)
self.app.canvas.add_wireless_edge(canvas_node1, canvas_node2, event.link)
elif event.message_type == core_pb2.MessageType.DELETE:
self.app.canvas.delete_wireless_edge(
canvas_node_one, canvas_node_two, event.link
)
self.app.canvas.delete_wireless_edge(canvas_node1, canvas_node2, event.link)
elif event.message_type == core_pb2.MessageType.NONE:
self.app.canvas.update_wireless_edge(
canvas_node_one, canvas_node_two, event.link
)
self.app.canvas.update_wireless_edge(canvas_node1, canvas_node2, event.link)
else:
logging.warning("unknown link event: %s", event)
@ -472,10 +466,10 @@ class CoreClient:
for edge in self.links.values():
link = core_pb2.Link()
link.CopyFrom(edge.link)
if link.HasField("interface_one") and not link.interface_one.mac:
link.interface_one.mac = self.interfaces_manager.next_mac()
if link.HasField("interface_two") and not link.interface_two.mac:
link.interface_two.mac = self.interfaces_manager.next_mac()
if link.HasField("interface1") and not link.interface1.mac:
link.interface1.mac = self.interfaces_manager.next_mac()
if link.HasField("interface2") and not link.interface2.mac:
link.interface2.mac = self.interfaces_manager.next_mac()
links.append(link)
wlan_configs = self.get_wlan_configs_proto()
mobility_configs = self.get_mobility_configs_proto()
@ -693,10 +687,10 @@ class CoreClient:
for link_proto in link_protos:
response = self.client.add_link(
self.session_id,
link_proto.node_one_id,
link_proto.node_two_id,
link_proto.interface_one,
link_proto.interface_two,
link_proto.node1_id,
link_proto.node2_id,
link_proto.interface1,
link_proto.interface2,
link_proto.options,
)
logging.debug("create link: %s", response)
@ -881,20 +875,20 @@ class CoreClient:
link = core_pb2.Link(
type=core_pb2.LinkType.WIRED,
node_one_id=src_node.id,
node_two_id=dst_node.id,
interface_one=src_interface,
interface_two=dst_interface,
node1_id=src_node.id,
node2_id=dst_node.id,
interface1=src_interface,
interface2=dst_interface,
)
# assign after creating link proto, since interfaces are copied
if src_interface:
interface_one = link.interface_one
edge.src_interface = interface_one
canvas_src_node.interfaces[interface_one.id] = interface_one
interface1 = link.interface1
edge.src_interface = interface1
canvas_src_node.interfaces[interface1.id] = interface1
if dst_interface:
interface_two = link.interface_two
edge.dst_interface = interface_two
canvas_dst_node.interfaces[interface_two.id] = interface_two
interface2 = link.interface2
edge.dst_interface = interface2
canvas_dst_node.interfaces[interface2.id] = interface2
edge.set_link(link)
self.links[edge.token] = edge
logging.info("Add link between %s and %s", src_node.name, dst_node.name)

View file

@ -227,21 +227,21 @@ class LinkConfigurationDialog(Dialog):
)
link.options.CopyFrom(options)
interface_one = None
if link.HasField("interface_one"):
interface_one = link.interface_one.id
interface_two = None
if link.HasField("interface_two"):
interface_two = link.interface_two.id
interface1_id = None
if link.HasField("interface1"):
interface1_id = link.interface1.id
interface2_id = None
if link.HasField("interface2"):
interface2_id = link.interface2.id
if not self.is_symmetric:
link.options.unidirectional = True
asym_interface_one = None
if interface_one:
asym_interface_one = core_pb2.Interface(id=interface_one)
asym_interface_two = None
if interface_two:
asym_interface_two = core_pb2.Interface(id=interface_two)
asym_interface1 = None
if interface1_id:
asym_interface1 = core_pb2.Interface(id=interface1_id)
asym_interface2 = None
if interface2_id:
asym_interface2 = core_pb2.Interface(id=interface2_id)
down_bandwidth = get_int(self.down_bandwidth)
down_jitter = get_int(self.down_jitter)
down_delay = get_int(self.down_delay)
@ -256,10 +256,10 @@ class LinkConfigurationDialog(Dialog):
unidirectional=True,
)
self.edge.asymmetric_link = core_pb2.Link(
node_one_id=link.node_two_id,
node_two_id=link.node_one_id,
interface_one=asym_interface_one,
interface_two=asym_interface_two,
node1_id=link.node2_id,
node2_id=link.node1_id,
interface1=asym_interface1,
interface2=asym_interface2,
options=options,
)
else:
@ -270,20 +270,20 @@ class LinkConfigurationDialog(Dialog):
session_id = self.app.core.session_id
self.app.core.client.edit_link(
session_id,
link.node_one_id,
link.node_two_id,
link.node1_id,
link.node2_id,
link.options,
interface_one,
interface_two,
interface1_id,
interface2_id,
)
if self.edge.asymmetric_link:
self.app.core.client.edit_link(
session_id,
link.node_two_id,
link.node_one_id,
link.node2_id,
link.node1_id,
self.edge.asymmetric_link.options,
interface_one,
interface_two,
interface1_id,
interface2_id,
)
self.destroy()

View file

@ -296,13 +296,13 @@ class CanvasEdge(Edge):
return label
def create_node_labels(self) -> Tuple[str, str]:
label_one = None
if self.link.HasField("interface_one"):
label_one = self.interface_label(self.link.interface_one)
label_two = None
if self.link.HasField("interface_two"):
label_two = self.interface_label(self.link.interface_two)
return label_one, label_two
label1 = None
if self.link.HasField("interface1"):
label1 = self.interface_label(self.link.interface1)
label2 = None
if self.link.HasField("interface2"):
label2 = self.interface_label(self.link.interface2)
return label1, label2
def draw_labels(self) -> None:
src_text, dst_text = self.create_node_labels()

View file

@ -300,41 +300,39 @@ class CanvasGraph(tk.Canvas):
# draw existing links
for link in session.links:
logging.debug("drawing link: %s", link)
canvas_node_one = self.core.canvas_nodes[link.node_one_id]
node_one = canvas_node_one.core_node
canvas_node_two = self.core.canvas_nodes[link.node_two_id]
node_two = canvas_node_two.core_node
token = create_edge_token(canvas_node_one.id, canvas_node_two.id)
canvas_node1 = self.core.canvas_nodes[link.node1_id]
node1 = canvas_node1.core_node
canvas_node2 = self.core.canvas_nodes[link.node2_id]
node2 = canvas_node2.core_node
token = create_edge_token(canvas_node1.id, canvas_node2.id)
if link.type == core_pb2.LinkType.WIRELESS:
self.add_wireless_edge(canvas_node_one, canvas_node_two, link)
self.add_wireless_edge(canvas_node1, canvas_node2, link)
else:
if token not in self.edges:
src_pos = (node_one.position.x, node_one.position.y)
dst_pos = (node_two.position.x, node_two.position.y)
edge = CanvasEdge(self, canvas_node_one.id, src_pos, dst_pos)
src_pos = (node1.position.x, node1.position.y)
dst_pos = (node2.position.x, node2.position.y)
edge = CanvasEdge(self, canvas_node1.id, src_pos, dst_pos)
edge.token = token
edge.dst = canvas_node_two.id
edge.dst = canvas_node2.id
edge.set_link(link)
edge.check_wireless()
canvas_node_one.edges.add(edge)
canvas_node_two.edges.add(edge)
canvas_node1.edges.add(edge)
canvas_node2.edges.add(edge)
self.edges[edge.token] = edge
self.core.links[edge.token] = edge
if link.HasField("interface_one"):
interface_one = link.interface_one
if link.HasField("interface1"):
interface1 = link.interface1
self.core.interface_to_edge[(node1.id, interface1.id)] = token
canvas_node1.interfaces[interface1.id] = interface1
edge.src_interface = interface1
if link.HasField("interface2"):
interface2 = link.interface2
self.core.interface_to_edge[
(node_one.id, interface_one.id)
] = token
canvas_node_one.interfaces[interface_one.id] = interface_one
edge.src_interface = interface_one
if link.HasField("interface_two"):
interface_two = link.interface_two
self.core.interface_to_edge[
(node_two.id, interface_two.id)
(node2.id, interface2.id)
] = edge.token
canvas_node_two.interfaces[interface_two.id] = interface_two
edge.dst_interface = interface_two
canvas_node2.interfaces[interface2.id] = interface2
edge.dst_interface = interface2
elif link.options.unidirectional:
edge = self.edges[token]
edge.asymmetric_link = link
@ -965,26 +963,26 @@ class CanvasGraph(tk.Canvas):
copy_link = copy_edge.link
options = edge.link.options
copy_link.options.CopyFrom(options)
interface_one = None
if copy_link.HasField("interface_one"):
interface_one = copy_link.interface_one.id
interface_two = None
if copy_link.HasField("interface_two"):
interface_two = copy_link.interface_two.id
interface1_id = None
if copy_link.HasField("interface1"):
interface1_id = copy_link.interface1.id
interface2_id = None
if copy_link.HasField("interface2"):
interface2_id = copy_link.interface2.id
if not options.unidirectional:
copy_edge.asymmetric_link = None
else:
asym_interface_one = None
if interface_one:
asym_interface_one = core_pb2.Interface(id=interface_one)
asym_interface_two = None
if interface_two:
asym_interface_two = core_pb2.Interface(id=interface_two)
asym_interface1 = None
if interface1_id:
asym_interface1 = core_pb2.Interface(id=interface1_id)
asym_interface2 = None
if interface2_id:
asym_interface2 = core_pb2.Interface(id=interface2_id)
copy_edge.asymmetric_link = core_pb2.Link(
node_one_id=copy_link.node_two_id,
node_two_id=copy_link.node_one_id,
interface_one=asym_interface_one,
interface_two=asym_interface_two,
node1_id=copy_link.node2_id,
node2_id=copy_link.node1_id,
interface1=asym_interface1,
interface2=asym_interface2,
options=edge.asymmetric_link.options,
)
self.itemconfig(

View file

@ -89,21 +89,21 @@ class InterfaceManager:
remaining_subnets = set()
for edge in self.app.core.links.values():
link = edge.link
if link.HasField("interface_one"):
subnets = self.get_subnets(link.interface_one)
if link.HasField("interface1"):
subnets = self.get_subnets(link.interface1)
remaining_subnets.add(subnets)
if link.HasField("interface_two"):
subnets = self.get_subnets(link.interface_two)
if link.HasField("interface2"):
subnets = self.get_subnets(link.interface2)
remaining_subnets.add(subnets)
# remove all subnets from used subnets when no longer present
# or remove used indexes from subnet
interfaces = []
for link in links:
if link.HasField("interface_one"):
interfaces.append(link.interface_one)
if link.HasField("interface_two"):
interfaces.append(link.interface_two)
if link.HasField("interface1"):
interfaces.append(link.interface1)
if link.HasField("interface2"):
interfaces.append(link.interface2)
for interface in interfaces:
subnets = self.get_subnets(interface)
if subnets not in remaining_subnets:
@ -117,10 +117,10 @@ class InterfaceManager:
def joined(self, links: List["core_pb2.Link"]) -> None:
interfaces = []
for link in links:
if link.HasField("interface_one"):
interfaces.append(link.interface_one)
if link.HasField("interface_two"):
interfaces.append(link.interface_two)
if link.HasField("interface1"):
interfaces.append(link.interface1)
if link.HasField("interface2"):
interfaces.append(link.interface2)
# add to used subnets and mark used indexes
for interface in interfaces:

View file

@ -21,8 +21,8 @@ if TYPE_CHECKING:
from core.emulator.session import Session
def get_link_id(node_one: int, node_two: int, network_id: int) -> str:
link_id = f"{node_one}-{node_two}"
def get_link_id(node1_id: int, node2_id: int, network_id: int) -> str:
link_id = f"{node1_id}-{node2_id}"
if network_id is not None:
link_id = f"{link_id}-{network_id}"
return link_id
@ -351,27 +351,27 @@ class Sdt:
return result
def add_link(
self, node_one: int, node_two: int, network_id: int = None, label: str = None
self, node1_id: int, node2_id: int, network_id: int = None, label: str = None
) -> None:
"""
Handle adding a link in SDT.
:param node_one: node one id
:param node_two: node two id
:param node1_id: node one id
:param node2_id: node two id
:param network_id: network link is associated with, None otherwise
:param label: label for link
:return: nothing
"""
logging.debug("sdt add link: %s, %s, %s", node_one, node_two, network_id)
logging.debug("sdt add link: %s, %s, %s", node1_id, node2_id, network_id)
if not self.connect():
return
if self.wireless_net_check(node_one) or self.wireless_net_check(node_two):
if self.wireless_net_check(node1_id) or self.wireless_net_check(node2_id):
return
color = DEFAULT_LINK_COLOR
if network_id:
color = self.session.get_link_color(network_id)
line = f"{color},2"
link_id = get_link_id(node_one, node_two, network_id)
link_id = get_link_id(node1_id, node2_id, network_id)
layer = LINK_LAYER
if network_id:
node = self.session.nodes.get(network_id)
@ -383,47 +383,47 @@ class Sdt:
if label:
link_label = f'linklabel on,"{label}"'
self.cmd(
f"link {node_one},{node_two},{link_id} linkLayer {layer} line {line} "
f"link {node1_id},{node2_id},{link_id} linkLayer {layer} line {line} "
f"{link_label}"
)
def delete_link(self, node_one: int, node_two: int, network_id: int = None) -> None:
def delete_link(self, node1_id: int, node2_id: int, network_id: int = None) -> None:
"""
Handle deleting a link in SDT.
:param node_one: node one id
:param node_two: node two id
:param node1_id: node one id
:param node2_id: node two id
:param network_id: network link is associated with, None otherwise
:return: nothing
"""
logging.debug("sdt delete link: %s, %s, %s", node_one, node_two, network_id)
logging.debug("sdt delete link: %s, %s, %s", node1_id, node2_id, network_id)
if not self.connect():
return
if self.wireless_net_check(node_one) or self.wireless_net_check(node_two):
if self.wireless_net_check(node1_id) or self.wireless_net_check(node2_id):
return
link_id = get_link_id(node_one, node_two, network_id)
self.cmd(f"delete link,{node_one},{node_two},{link_id}")
link_id = get_link_id(node1_id, node2_id, network_id)
self.cmd(f"delete link,{node1_id},{node2_id},{link_id}")
def edit_link(
self, node_one: int, node_two: int, network_id: int, label: str
self, node1_id: int, node2_id: int, network_id: int, label: str
) -> None:
"""
Handle editing a link in SDT.
:param node_one: node one id
:param node_two: node two id
:param node1_id: node one id
:param node2_id: node two id
:param network_id: network link is associated with, None otherwise
:param label: label to update
:return: nothing
"""
logging.debug("sdt edit link: %s, %s, %s", node_one, node_two, network_id)
logging.debug("sdt edit link: %s, %s, %s", node1_id, node2_id, network_id)
if not self.connect():
return
if self.wireless_net_check(node_one) or self.wireless_net_check(node_two):
if self.wireless_net_check(node1_id) or self.wireless_net_check(node2_id):
return
link_id = get_link_id(node_one, node_two, network_id)
link_id = get_link_id(node1_id, node2_id, network_id)
link_label = f'linklabel on,"{label}"'
self.cmd(f"link {node_one},{node_two},{link_id} {link_label}")
self.cmd(f"link {node1_id},{node2_id},{link_id} {link_label}")
def handle_link_update(self, link_data: LinkData) -> None:
"""
@ -432,13 +432,13 @@ class Sdt:
:param link_data: link data to handle
:return: nothing
"""
node_one = link_data.node1_id
node_two = link_data.node2_id
node1_id = link_data.node1_id
node2_id = link_data.node2_id
network_id = link_data.network_id
label = link_data.label
if link_data.message_type == MessageFlags.ADD:
self.add_link(node_one, node_two, network_id, label)
self.add_link(node1_id, node2_id, network_id, label)
elif link_data.message_type == MessageFlags.DELETE:
self.delete_link(node_one, node_two, network_id)
self.delete_link(node1_id, node2_id, network_id)
elif link_data.message_type == MessageFlags.NONE and label:
self.edit_link(node_one, node_two, network_id, label)
self.edit_link(node1_id, node2_id, network_id, label)

View file

@ -534,7 +534,7 @@ class CoreXmlWriter:
# check for interface one
if link_data.interface1_id is not None:
interface_one = self.create_interface_element(
interface1 = self.create_interface_element(
"interface_one",
link_data.node1_id,
link_data.interface1_id,
@ -544,11 +544,11 @@ class CoreXmlWriter:
link_data.interface1_ip6,
link_data.interface1_ip6_mask,
)
link_element.append(interface_one)
link_element.append(interface1)
# check for interface two
if link_data.interface2_id is not None:
interface_two = self.create_interface_element(
interface2 = self.create_interface_element(
"interface_two",
link_data.node2_id,
link_data.interface2_id,
@ -558,14 +558,14 @@ class CoreXmlWriter:
link_data.interface2_ip6,
link_data.interface2_ip6_mask,
)
link_element.append(interface_two)
link_element.append(interface2)
# check for options, don't write for emane/wlan links
node_one = self.session.get_node(link_data.node1_id, NodeBase)
node_two = self.session.get_node(link_data.node2_id, NodeBase)
is_node_one_wireless = isinstance(node_one, (WlanNode, EmaneNet))
is_node_two_wireless = isinstance(node_two, (WlanNode, EmaneNet))
if not any([is_node_one_wireless, is_node_two_wireless]):
node1 = self.session.get_node(link_data.node1_id, NodeBase)
node2 = self.session.get_node(link_data.node2_id, NodeBase)
is_node1_wireless = isinstance(node1, (WlanNode, EmaneNet))
is_node2_wireless = isinstance(node2, (WlanNode, EmaneNet))
if not any([is_node1_wireless, is_node2_wireless]):
options = etree.Element("options")
add_attribute(options, "delay", link_data.delay)
add_attribute(options, "bandwidth", link_data.bandwidth)
@ -932,19 +932,19 @@ class CoreXmlReader:
node_sets = set()
for link_element in link_elements.iterchildren():
node_one = get_int(link_element, "node_one")
node_two = get_int(link_element, "node_two")
node_set = frozenset((node_one, node_two))
node1_id = get_int(link_element, "node_one")
node2_id = get_int(link_element, "node_two")
node_set = frozenset((node1_id, node2_id))
interface_one_element = link_element.find("interface_one")
interface_one = None
if interface_one_element is not None:
interface_one = create_interface_data(interface_one_element)
interface1_element = link_element.find("interface_one")
interface1_data = None
if interface1_element is not None:
interface1_data = create_interface_data(interface1_element)
interface_two_element = link_element.find("interface_two")
interface_two = None
if interface_two_element is not None:
interface_two = create_interface_data(interface_two_element)
interface2_element = link_element.find("interface_two")
interface2_data = None
if interface2_element is not None:
interface2_data = create_interface_data(interface2_element)
options_element = link_element.find("options")
link_options = LinkOptions()
@ -966,18 +966,18 @@ class CoreXmlReader:
link_options.gui_attributes = options_element.get("gui_attributes")
if link_options.unidirectional == 1 and node_set in node_sets:
logging.info(
"updating link node_one(%s) node_two(%s)", node_one, node_two
)
logging.info("updating link node1(%s) node2(%s)", node1_id, node2_id)
self.session.update_link(
node_one, node_two, interface_one.id, interface_two.id, link_options
node1_id,
node2_id,
interface1_data.id,
interface2_data.id,
link_options,
)
else:
logging.info(
"adding link node_one(%s) node_two(%s)", node_one, node_two
)
logging.info("adding link node1(%s) node2(%s)", node1_id, node2_id)
self.session.add_link(
node_one, node_two, interface_one, interface_two, link_options
node1_id, node2_id, interface1_data, interface2_data, link_options
)
node_sets.add(node_set)