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)

View file

@ -11,7 +11,7 @@ if __name__ == "__main__":
# setup basic network
prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16")
options = NodeOptions(model="nothing")
options = NodeOptions(model=None)
coreemu = CoreEmu()
session = coreemu.create_session()
session.set_state(EventTypes.CONFIGURATION_STATE)
@ -19,14 +19,14 @@ if __name__ == "__main__":
# node one
options.config_services = ["DefaultRoute", "IPForward"]
node_one = session.add_node(CoreNode, options=options)
interface = prefixes.create_interface(node_one)
session.add_link(node_one.id, switch.id, interface_one=interface)
node1 = session.add_node(CoreNode, options=options)
interface = prefixes.create_interface(node1)
session.add_link(node1.id, switch.id, interface1_data=interface)
# node two
node_two = session.add_node(CoreNode, options=options)
interface = prefixes.create_interface(node_two)
session.add_link(node_two.id, switch.id, interface_one=interface)
node2 = session.add_node(CoreNode, options=options)
interface = prefixes.create_interface(node2)
session.add_link(node2.id, switch.id, interface1_data=interface)
# start session and run services
session.instantiate()

View file

@ -17,15 +17,15 @@ if __name__ == "__main__":
options = NodeOptions(model=None, image="ubuntu")
# create node one
node_one = session.add_node(DockerNode, options=options)
interface_one = prefixes.create_interface(node_one)
node1 = session.add_node(DockerNode, options=options)
interface1_data = prefixes.create_interface(node1)
# create node two
node_two = session.add_node(CoreNode)
interface_two = prefixes.create_interface(node_two)
node2 = session.add_node(CoreNode)
interface2_data = prefixes.create_interface(node2)
# add link
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
# instantiate
session.instantiate()

View file

@ -18,15 +18,15 @@ if __name__ == "__main__":
options = NodeOptions(model=None, image="ubuntu")
# create node one
node_one = session.add_node(DockerNode, options=options)
interface_one = prefixes.create_interface(node_one)
node1 = session.add_node(DockerNode, options=options)
interface1_data = prefixes.create_interface(node1)
# create node two
node_two = session.add_node(DockerNode, options=options)
interface_two = prefixes.create_interface(node_two)
node2 = session.add_node(DockerNode, options=options)
interface2_data = prefixes.create_interface(node2)
# add link
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
# instantiate
session.instantiate()

View file

@ -22,20 +22,20 @@ if __name__ == "__main__":
switch = session.add_node(SwitchNode)
# node one
node_one = session.add_node(DockerNode, options=options)
interface_one = prefixes.create_interface(node_one)
node1 = session.add_node(DockerNode, options=options)
interface1_data = prefixes.create_interface(node1)
# node two
node_two = session.add_node(DockerNode, options=options)
interface_two = prefixes.create_interface(node_two)
node2 = session.add_node(DockerNode, options=options)
interface2_data = prefixes.create_interface(node2)
# node three
node_three = session.add_node(CoreNode)
interface_three = prefixes.create_interface(node_three)
# add links
session.add_link(node_one.id, switch.id, interface_one)
session.add_link(node_two.id, switch.id, interface_two)
session.add_link(node1.id, switch.id, interface1_data)
session.add_link(node2.id, switch.id, interface2_data)
session.add_link(node_three.id, switch.id, interface_three)
# instantiate

View file

@ -44,11 +44,11 @@ def main(args):
node = Node(position=position)
response = core.add_node(session_id, node)
logging.info("created node one: %s", response)
node_one_id = response.node_id
node1_id = response.node_id
# create link
interface_one = interface_helper.create_interface(node_one_id, 0)
response = core.add_link(session_id, node_one_id, switch_id, interface_one)
interface1 = interface_helper.create_interface(node1_id, 0)
response = core.add_link(session_id, node1_id, switch_id, interface1)
logging.info("created link from node one to switch: %s", response)
# create node two
@ -56,11 +56,11 @@ def main(args):
node = Node(position=position, server=server_name)
response = core.add_node(session_id, node)
logging.info("created node two: %s", response)
node_two_id = response.node_id
node2_id = response.node_id
# create link
interface_one = interface_helper.create_interface(node_two_id, 0)
response = core.add_link(session_id, node_two_id, switch_id, interface_one)
interface1 = interface_helper.create_interface(node2_id, 0)
response = core.add_link(session_id, node2_id, switch_id, interface1)
logging.info("created link from node two to switch: %s", response)
# change session state

View file

@ -57,11 +57,11 @@ def main():
node2_id = response.node_id
# links nodes to switch
interface_one = interface_helper.create_interface(node1_id, 0)
response = core.add_link(session_id, node1_id, emane_id, interface_one)
interface1 = interface_helper.create_interface(node1_id, 0)
response = core.add_link(session_id, node1_id, emane_id, interface1)
logging.info("created link: %s", response)
interface_one = interface_helper.create_interface(node2_id, 0)
response = core.add_link(session_id, node2_id, emane_id, interface_one)
interface1 = interface_helper.create_interface(node2_id, 0)
response = core.add_link(session_id, node2_id, emane_id, interface1)
logging.info("created link: %s", response)
# change session state

View file

@ -53,11 +53,11 @@ def main():
node2_id = response.node_id
# links nodes to switch
interface_one = interface_helper.create_interface(node1_id, 0)
response = core.add_link(session_id, node1_id, switch_id, interface_one)
interface1 = interface_helper.create_interface(node1_id, 0)
response = core.add_link(session_id, node1_id, switch_id, interface1)
logging.info("created link: %s", response)
interface_one = interface_helper.create_interface(node2_id, 0)
response = core.add_link(session_id, node2_id, switch_id, interface_one)
interface1 = interface_helper.create_interface(node2_id, 0)
response = core.add_link(session_id, node2_id, switch_id, interface1)
logging.info("created link: %s", response)
# change session state

View file

@ -65,11 +65,11 @@ def main():
node2_id = response.node_id
# links nodes to switch
interface_one = interface_helper.create_interface(node1_id, 0)
response = core.add_link(session_id, node1_id, wlan_id, interface_one)
interface1 = interface_helper.create_interface(node1_id, 0)
response = core.add_link(session_id, node1_id, wlan_id, interface1)
logging.info("created link: %s", response)
interface_one = interface_helper.create_interface(node2_id, 0)
response = core.add_link(session_id, node2_id, wlan_id, interface_one)
interface1 = interface_helper.create_interface(node2_id, 0)
response = core.add_link(session_id, node2_id, wlan_id, interface1)
logging.info("created link: %s", response)
# change session state

View file

@ -17,15 +17,15 @@ if __name__ == "__main__":
options = NodeOptions(image="ubuntu")
# create node one
node_one = session.add_node(LxcNode, options=options)
interface_one = prefixes.create_interface(node_one)
node1 = session.add_node(LxcNode, options=options)
interface1_data = prefixes.create_interface(node1)
# create node two
node_two = session.add_node(CoreNode)
interface_two = prefixes.create_interface(node_two)
node2 = session.add_node(CoreNode)
interface2_data = prefixes.create_interface(node2)
# add link
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
# instantiate
session.instantiate()

View file

@ -18,15 +18,15 @@ if __name__ == "__main__":
options = NodeOptions(image="ubuntu:18.04")
# create node one
node_one = session.add_node(LxcNode, options=options)
interface_one = prefixes.create_interface(node_one)
node1 = session.add_node(LxcNode, options=options)
interface1_data = prefixes.create_interface(node1)
# create node two
node_two = session.add_node(LxcNode, options=options)
interface_two = prefixes.create_interface(node_two)
node2 = session.add_node(LxcNode, options=options)
interface2_data = prefixes.create_interface(node2)
# add link
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
# instantiate
session.instantiate()

View file

@ -22,21 +22,21 @@ if __name__ == "__main__":
switch = session.add_node(SwitchNode)
# node one
node_one = session.add_node(LxcNode, options=options)
interface_one = prefixes.create_interface(node_one)
node1 = session.add_node(LxcNode, options=options)
interface1_data = prefixes.create_interface(node1)
# node two
node_two = session.add_node(LxcNode, options=options)
interface_two = prefixes.create_interface(node_two)
node2 = session.add_node(LxcNode, options=options)
interface2_data = prefixes.create_interface(node2)
# node three
node_three = session.add_node(CoreNode)
interface_three = prefixes.create_interface(node_three)
node3 = session.add_node(CoreNode)
interface3_data = prefixes.create_interface(node3)
# add links
session.add_link(node_one.id, switch.id, interface_one)
session.add_link(node_two.id, switch.id, interface_two)
session.add_link(node_three.id, switch.id, interface_three)
session.add_link(node1.id, switch.id, interface1_data)
session.add_link(node2.id, switch.id, interface2_data)
session.add_link(node3.id, switch.id, interface3_data)
# instantiate
session.instantiate()

View file

@ -52,17 +52,17 @@ def main(args):
# create local node, switch, and remote nodes
options = NodeOptions(model="mdr")
options.set_position(0, 0)
node_one = session.add_node(CoreNode, options=options)
node1 = session.add_node(CoreNode, options=options)
emane_net = session.add_node(EmaneNet)
session.emane.set_model(emane_net, EmaneIeee80211abgModel)
options.server = server_name
node_two = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode, options=options)
# create node interfaces and link
interface_one = prefixes.create_interface(node_one)
interface_two = prefixes.create_interface(node_two)
session.add_link(node_one.id, emane_net.id, interface_one=interface_one)
session.add_link(node_two.id, emane_net.id, interface_one=interface_two)
interface1_data = prefixes.create_interface(node1)
interface2_data = prefixes.create_interface(node2)
session.add_link(node1.id, emane_net.id, interface1_data=interface1_data)
session.add_link(node2.id, emane_net.id, interface1_data=interface2_data)
# instantiate session
session.instantiate()

View file

@ -43,14 +43,14 @@ def main(args):
# create local node, switch, and remote nodes
options = NodeOptions(image="ubuntu:18.04")
node_one = session.add_node(LxcNode, options=options)
node1 = session.add_node(LxcNode, options=options)
options.server = server_name
node_two = session.add_node(LxcNode, options=options)
node2 = session.add_node(LxcNode, options=options)
# create node interfaces and link
interface_one = prefixes.create_interface(node_one)
interface_two = prefixes.create_interface(node_two)
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
interface1_data = prefixes.create_interface(node1)
interface2_data = prefixes.create_interface(node2)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
# instantiate session
session.instantiate()

View file

@ -43,14 +43,14 @@ def main(args):
# create local node, switch, and remote nodes
options = NodeOptions()
node_one = session.add_node(CoreNode, options=options)
node1 = session.add_node(CoreNode, options=options)
options.server = server_name
node_two = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode, options=options)
# create node interfaces and link
interface_one = prefixes.create_interface(node_one)
interface_two = prefixes.create_interface(node_two)
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
interface1_data = prefixes.create_interface(node1)
interface2_data = prefixes.create_interface(node2)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
# instantiate session
session.instantiate()

View file

@ -45,17 +45,17 @@ def main(args):
session.set_state(EventTypes.CONFIGURATION_STATE)
# create local node, switch, and remote nodes
node_one = session.add_node(CoreNode)
node1 = session.add_node(CoreNode)
switch = session.add_node(SwitchNode)
options = NodeOptions()
options.server = server_name
node_two = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode, options=options)
# create node interfaces and link
interface_one = prefixes.create_interface(node_one)
interface_two = prefixes.create_interface(node_two)
session.add_link(node_one.id, switch.id, interface_one=interface_one)
session.add_link(node_two.id, switch.id, interface_one=interface_two)
interface1_data = prefixes.create_interface(node1)
interface2_data = prefixes.create_interface(node2)
session.add_link(node1.id, switch.id, interface1_data=interface1_data)
session.add_link(node2.id, switch.id, interface1_data=interface2_data)
# instantiate session
session.instantiate()

View file

@ -43,7 +43,7 @@ def main():
node = session.add_node(CoreNode, options=options)
node.setposition(x=150 * (i + 1), y=150)
interface = prefixes.create_interface(node)
session.add_link(node.id, emane_network.id, interface_one=interface)
session.add_link(node.id, emane_network.id, interface1_data=interface)
# instantiate session
session.instantiate()

View file

@ -32,7 +32,7 @@ def main():
for _ in range(NODES):
node = session.add_node(CoreNode)
interface = prefixes.create_interface(node)
session.add_link(node.id, switch.id, interface_one=interface)
session.add_link(node.id, switch.id, interface1_data=interface)
# instantiate session
session.instantiate()

View file

@ -34,7 +34,7 @@ def main():
for _ in range(NODES):
node = session.add_node(CoreNode)
interface = prefixes.create_interface(node)
session.add_link(node.id, switch.id, interface_one=interface)
session.add_link(node.id, switch.id, interface1_data=interface)
# instantiate session
session.instantiate()

View file

@ -36,7 +36,7 @@ def main():
for _ in range(NODES):
node = session.add_node(CoreNode, options=options)
interface = prefixes.create_interface(node)
session.add_link(node.id, wlan.id, interface_one=interface)
session.add_link(node.id, wlan.id, interface1_data=interface)
# instantiate session
session.instantiate()

View file

@ -492,16 +492,16 @@ message AddLinkRequest {
message AddLinkResponse {
bool result = 1;
Interface interface_one = 2;
Interface interface_two = 3;
Interface interface1 = 2;
Interface interface2 = 3;
}
message EditLinkRequest {
int32 session_id = 1;
int32 node_one_id = 2;
int32 node_two_id = 3;
int32 interface_one_id = 4;
int32 interface_two_id = 5;
int32 node1_id = 2;
int32 node2_id = 3;
int32 interface1_id = 4;
int32 interface2_id = 5;
LinkOptions options = 6;
}
@ -511,10 +511,10 @@ message EditLinkResponse {
message DeleteLinkRequest {
int32 session_id = 1;
int32 node_one_id = 2;
int32 node_two_id = 3;
int32 interface_one_id = 4;
int32 interface_two_id = 5;
int32 node1_id = 2;
int32 node2_id = 3;
int32 interface1_id = 4;
int32 interface2_id = 5;
}
message DeleteLinkResponse {
@ -702,11 +702,11 @@ message Node {
}
message Link {
int32 node_one_id = 1;
int32 node_two_id = 2;
int32 node1_id = 1;
int32 node2_id = 2;
LinkType.Enum type = 3;
Interface interface_one = 4;
Interface interface_two = 5;
Interface interface1 = 4;
Interface interface2 = 5;
LinkOptions options = 6;
int32 network_id = 7;
string label = 8;

View file

@ -75,8 +75,8 @@ message GetEmaneEventChannelResponse {
message EmaneLinkRequest {
int32 session_id = 1;
int32 nem_one = 2;
int32 nem_two = 3;
int32 nem1 = 2;
int32 nem2 = 3;
bool linked = 4;
}
@ -93,12 +93,12 @@ message EmaneModelConfig {
message EmanePathlossesRequest {
int32 session_id = 1;
int32 node_one = 2;
float rx_one = 3;
int32 interface_one_id = 4;
int32 node_two = 5;
float rx_two = 6;
int32 interface_two_id = 7;
int32 node1_id = 2;
float rx1 = 3;
int32 interface1_id = 4;
int32 node2_id = 5;
float rx2 = 6;
int32 interface2_id = 7;
}
message EmanePathlossesResponse {

View file

@ -38,8 +38,8 @@ message SetWlanConfigResponse {
message WlanLinkRequest {
int32 session_id = 1;
int32 wlan = 2;
int32 node_one = 3;
int32 node_two = 4;
int32 node1_id = 3;
int32 node2_id = 4;
bool linked = 5;
}

View file

@ -3,6 +3,7 @@ Unit tests for testing CORE EMANE networks.
"""
import os
from tempfile import TemporaryFile
from typing import Type
from xml.etree import ElementTree
import pytest
@ -43,7 +44,9 @@ def ping(
class TestEmane:
@pytest.mark.parametrize("model", _EMANE_MODELS)
def test_models(self, session: Session, model: EmaneModel, ip_prefixes: IpPrefixes):
def test_models(
self, session: Session, model: Type[EmaneModel], ip_prefixes: IpPrefixes
):
"""
Test emane models within a basic network.
@ -70,20 +73,20 @@ class TestEmane:
# create nodes
options = NodeOptions(model="mdr")
options.set_position(150, 150)
node_one = session.add_node(CoreNode, options=options)
node1 = session.add_node(CoreNode, options=options)
options.set_position(300, 150)
node_two = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode, options=options)
for i, node in enumerate([node_one, node_two]):
for i, node in enumerate([node1, node2]):
node.setposition(x=150 * (i + 1), y=150)
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, emane_network.id, interface_one=interface)
session.add_link(node.id, emane_network.id, interface1_data=interface)
# instantiate session
session.instantiate()
# ping n2 from n1 and assert success
status = ping(node_one, node_two, ip_prefixes, count=5)
# ping node2 from node1 and assert success
status = ping(node1, node2, ip_prefixes, count=5)
assert not status
def test_xml_emane(
@ -110,22 +113,22 @@ class TestEmane:
# create nodes
options = NodeOptions(model="mdr")
options.set_position(150, 150)
node_one = session.add_node(CoreNode, options=options)
node1 = session.add_node(CoreNode, options=options)
options.set_position(300, 150)
node_two = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode, options=options)
for i, node in enumerate([node_one, node_two]):
for i, node in enumerate([node1, node2]):
node.setposition(x=150 * (i + 1), y=150)
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, emane_network.id, interface_one=interface)
session.add_link(node.id, emane_network.id, interface1_data=interface)
# instantiate session
session.instantiate()
# get ids for nodes
emane_id = emane_network.id
n1_id = node_one.id
n2_id = node_two.id
node1_id = node1.id
node2_id = node2.id
# save xml
xml_file = tmpdir.join("session.xml")
@ -141,9 +144,9 @@ class TestEmane:
# verify nodes have been removed from session
with pytest.raises(CoreError):
assert not session.get_node(n1_id, CoreNode)
assert not session.get_node(node1_id, CoreNode)
with pytest.raises(CoreError):
assert not session.get_node(n2_id, CoreNode)
assert not session.get_node(node2_id, CoreNode)
# load saved xml
session.open_xml(file_path, start=True)
@ -154,7 +157,7 @@ class TestEmane:
)
# verify nodes and configuration were restored
assert session.get_node(n1_id, CoreNode)
assert session.get_node(n2_id, CoreNode)
assert session.get_node(node1_id, CoreNode)
assert session.get_node(node2_id, CoreNode)
assert session.get_node(emane_id, EmaneNet)
assert value == config_value

View file

@ -14,11 +14,11 @@ from core.nodes.network import WlanNode
class TestConfigurableOptions(ConfigurableOptions):
name_one = "value1"
name_two = "value2"
name1 = "value1"
name2 = "value2"
options = [
Configuration(_id=name_one, _type=ConfigDataTypes.STRING, label=name_one),
Configuration(_id=name_two, _type=ConfigDataTypes.STRING, label=name_two),
Configuration(_id=name1, _type=ConfigDataTypes.STRING, label=name1),
Configuration(_id=name2, _type=ConfigDataTypes.STRING, label=name2),
]
@ -33,11 +33,11 @@ class TestConf:
# then
assert len(default_values) == 2
assert TestConfigurableOptions.name_one in default_values
assert TestConfigurableOptions.name_two in default_values
assert TestConfigurableOptions.name1 in default_values
assert TestConfigurableOptions.name2 in default_values
assert len(instance_default_values) == 2
assert TestConfigurableOptions.name_one in instance_default_values
assert TestConfigurableOptions.name_two in instance_default_values
assert TestConfigurableOptions.name1 in instance_default_values
assert TestConfigurableOptions.name2 in instance_default_values
def test_nodes(self):
# given

View file

@ -48,19 +48,19 @@ class TestCore:
net_node = session.add_node(net_type)
# create nodes
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
# link nodes to net node
for node in [node_one, node_two]:
for node in [node1, node2]:
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, net_node.id, interface_one=interface)
session.add_link(node.id, net_node.id, interface1_data=interface)
# instantiate session
session.instantiate()
# ping n2 from n1 and assert success
status = ping(node_one, node_two, ip_prefixes)
# ping node2 from node1 and assert success
status = ping(node1, node2, ip_prefixes)
assert not status
def test_vnode_client(self, request, session: Session, ip_prefixes: IpPrefixes):
@ -75,16 +75,16 @@ class TestCore:
ptp_node = session.add_node(PtpNet)
# create nodes
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
# link nodes to ptp net
for node in [node_one, node_two]:
for node in [node1, node2]:
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, ptp_node.id, interface_one=interface)
session.add_link(node.id, ptp_node.id, interface1_data=interface)
# get node client for testing
client = node_one.client
client = node1.client
# instantiate session
session.instantiate()
@ -108,13 +108,13 @@ class TestCore:
ptp_node = session.add_node(PtpNet)
# create nodes
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
# link nodes to ptp net
for node in [node_one, node_two]:
for node in [node1, node2]:
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, ptp_node.id, interface_one=interface)
session.add_link(node.id, ptp_node.id, interface1_data=interface)
# instantiate session
session.instantiate()
@ -123,22 +123,22 @@ class TestCore:
assert ptp_node.all_link_data(MessageFlags.ADD)
# check common nets exist between linked nodes
assert node_one.commonnets(node_two)
assert node_two.commonnets(node_one)
assert node1.commonnets(node2)
assert node2.commonnets(node1)
# check we can retrieve netif index
assert node_one.ifname(0)
assert node_two.ifname(0)
assert node1.ifname(0)
assert node2.ifname(0)
# check interface parameters
interface = node_one.netif(0)
interface = node1.netif(0)
interface.setparam("test", 1)
assert interface.getparam("test") == 1
assert interface.getparams()
# delete netif and test that if no longer exists
node_one.delnetif(0)
assert not node_one.netif(0)
node1.delnetif(0)
assert not node1.netif(0)
def test_wlan_ping(self, session: Session, ip_prefixes: IpPrefixes):
"""
@ -155,19 +155,19 @@ class TestCore:
# create nodes
options = NodeOptions(model="mdr")
options.set_position(0, 0)
node_one = session.add_node(CoreNode, options=options)
node_two = session.add_node(CoreNode, options=options)
node1 = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode, options=options)
# link nodes
for node in [node_one, node_two]:
for node in [node1, node2]:
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, wlan_node.id, interface_one=interface)
session.add_link(node.id, wlan_node.id, interface1_data=interface)
# instantiate session
session.instantiate()
# ping n2 from n1 and assert success
status = ping(node_one, node_two, ip_prefixes)
# ping node2 from node1 and assert success
status = ping(node1, node2, ip_prefixes)
assert not status
def test_mobility(self, session: Session, ip_prefixes: IpPrefixes):
@ -185,13 +185,13 @@ class TestCore:
# create nodes
options = NodeOptions(model="mdr")
options.set_position(0, 0)
node_one = session.add_node(CoreNode, options=options)
node_two = session.add_node(CoreNode, options=options)
node1 = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode, options=options)
# link nodes
for node in [node_one, node_two]:
for node in [node1, node2]:
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, wlan_node.id, interface_one=interface)
session.add_link(node.id, wlan_node.id, interface1_data=interface)
# configure mobility script for session
config = {

View file

@ -34,23 +34,23 @@ class TestGrpc:
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
position = core_pb2.Position(x=50, y=100)
node_one = core_pb2.Node(id=1, position=position, model="PC")
node1 = core_pb2.Node(id=1, position=position, model="PC")
position = core_pb2.Position(x=100, y=100)
node_two = core_pb2.Node(id=2, position=position, model="PC")
node2 = core_pb2.Node(id=2, position=position, model="PC")
position = core_pb2.Position(x=200, y=200)
wlan_node = core_pb2.Node(
id=3, type=NodeTypes.WIRELESS_LAN.value, position=position
)
nodes = [node_one, node_two, wlan_node]
nodes = [node1, node2, wlan_node]
interface_helper = InterfaceHelper(ip4_prefix="10.83.0.0/16")
interface_one = interface_helper.create_interface(node_one.id, 0)
interface_two = interface_helper.create_interface(node_two.id, 0)
interface1 = interface_helper.create_interface(node1.id, 0)
interface2 = interface_helper.create_interface(node2.id, 0)
link = core_pb2.Link(
type=core_pb2.LinkType.WIRED,
node_one_id=node_one.id,
node_two_id=node_two.id,
interface_one=interface_one,
interface_two=interface_two,
node1_id=node1.id,
node2_id=node2.id,
interface1=interface1,
interface2=interface2,
)
links = [link]
hook = core_pb2.Hook(
@ -99,11 +99,11 @@ class TestGrpc:
)
mobility_configs = [mobility_config]
service_config = ServiceConfig(
node_id=node_one.id, service="DefaultRoute", validate=["echo hello"]
node_id=node1.id, service="DefaultRoute", validate=["echo hello"]
)
service_configs = [service_config]
service_file_config = ServiceFileConfig(
node_id=node_one.id,
node_id=node1.id,
service="DefaultRoute",
file="defaultroute.sh",
data="echo hello",
@ -128,11 +128,11 @@ class TestGrpc:
)
# then
assert node_one.id in session.nodes
assert node_two.id in session.nodes
assert node1.id in session.nodes
assert node2.id in session.nodes
assert wlan_node.id in session.nodes
assert session.nodes[node_one.id].netif(0) is not None
assert session.nodes[node_two.id].netif(0) is not None
assert session.nodes[node1.id].netif(0) is not None
assert session.nodes[node2.id].netif(0) is not None
hook_file, hook_data = session._hooks[EventTypes.RUNTIME_STATE][0]
assert hook_file == hook.file
assert hook_data == hook.data
@ -153,11 +153,11 @@ class TestGrpc:
)
assert set_model_config[model_config_key] == model_config_value
service = session.services.get_service(
node_one.id, service_config.service, default_service=True
node1.id, service_config.service, default_service=True
)
assert service.validate == tuple(service_config.validate)
service_file = session.services.get_service_file(
node_one, service_file_config.service, service_file_config.file
node1, service_file_config.service, service_file_config.file
)
assert service_file.data == service_file_config.data
@ -596,7 +596,7 @@ class TestGrpc:
# then
with client.context_connect():
response = client.edit_link(
session.id, node.id, switch.id, options, interface_one_id=interface.id
session.id, node.id, switch.id, options, interface1_id=interface.id
)
# then
@ -608,28 +608,28 @@ class TestGrpc:
# given
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
node_one = session.add_node(CoreNode)
interface_one = ip_prefixes.create_interface(node_one)
node_two = session.add_node(CoreNode)
interface_two = ip_prefixes.create_interface(node_two)
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
node1 = session.add_node(CoreNode)
interface1 = ip_prefixes.create_interface(node1)
node2 = session.add_node(CoreNode)
interface2 = ip_prefixes.create_interface(node2)
session.add_link(node1.id, node2.id, interface1, interface2)
link_node = None
for node_id in session.nodes:
node = session.nodes[node_id]
if node.id not in {node_one.id, node_two.id}:
if node.id not in {node1.id, node2.id}:
link_node = node
break
assert len(link_node.all_link_data(0)) == 1
assert len(link_node.all_link_data()) == 1
# then
with client.context_connect():
response = client.delete_link(
session.id, node_one.id, node_two.id, interface_one.id, interface_two.id
session.id, node1.id, node2.id, interface1.id, interface2.id
)
# then
assert response.result is True
assert len(link_node.all_link_data(0)) == 0
assert len(link_node.all_link_data()) == 0
def test_get_wlan_config(self, grpc_server: CoreGrpcServer):
# given

View file

@ -50,12 +50,13 @@ class TestGui:
self, coretlv: CoreHandler, node_type: NodeTypes, model: Optional[str]
):
node_id = 1
name = "node1"
message = coreapi.CoreNodeMessage.create(
MessageFlags.ADD.value,
[
(NodeTlvs.NUMBER, node_id),
(NodeTlvs.TYPE, node_type.value),
(NodeTlvs.NAME, "n1"),
(NodeTlvs.NAME, name),
(NodeTlvs.X_POSITION, 0),
(NodeTlvs.Y_POSITION, 0),
(NodeTlvs.MODEL, model),
@ -63,7 +64,9 @@ class TestGui:
)
coretlv.handle_message(message)
assert coretlv.session.get_node(node_id, NodeBase) is not None
node = coretlv.session.get_node(node_id, NodeBase)
assert node
assert node.name == name
def test_node_update(self, coretlv: CoreHandler):
node_id = 1
@ -99,71 +102,71 @@ class TestGui:
coretlv.session.get_node(node_id, NodeBase)
def test_link_add_node_to_net(self, coretlv: CoreHandler):
node_one = 1
coretlv.session.add_node(CoreNode, _id=node_one)
switch = 2
coretlv.session.add_node(SwitchNode, _id=switch)
node1_id = 1
coretlv.session.add_node(CoreNode, _id=node1_id)
switch_id = 2
coretlv.session.add_node(SwitchNode, _id=switch_id)
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
interface_one = str(ip_prefix[node_one])
interface1_ip4 = str(ip_prefix[node1_id])
message = coreapi.CoreLinkMessage.create(
MessageFlags.ADD.value,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, switch),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, switch_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
(LinkTlvs.INTERFACE1_IP4, interface_one),
(LinkTlvs.INTERFACE1_IP4, interface1_ip4),
(LinkTlvs.INTERFACE1_IP4_MASK, 24),
],
)
coretlv.handle_message(message)
switch_node = coretlv.session.get_node(switch, SwitchNode)
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
all_links = switch_node.all_link_data()
assert len(all_links) == 1
def test_link_add_net_to_node(self, coretlv: CoreHandler):
node_one = 1
coretlv.session.add_node(CoreNode, _id=node_one)
switch = 2
coretlv.session.add_node(SwitchNode, _id=switch)
node1_id = 1
coretlv.session.add_node(CoreNode, _id=node1_id)
switch_id = 2
coretlv.session.add_node(SwitchNode, _id=switch_id)
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
interface_one = str(ip_prefix[node_one])
interface2_ip4 = str(ip_prefix[node1_id])
message = coreapi.CoreLinkMessage.create(
MessageFlags.ADD.value,
[
(LinkTlvs.N1_NUMBER, switch),
(LinkTlvs.N2_NUMBER, node_one),
(LinkTlvs.N1_NUMBER, switch_id),
(LinkTlvs.N2_NUMBER, node1_id),
(LinkTlvs.INTERFACE2_NUMBER, 0),
(LinkTlvs.INTERFACE2_IP4, interface_one),
(LinkTlvs.INTERFACE2_IP4, interface2_ip4),
(LinkTlvs.INTERFACE2_IP4_MASK, 24),
],
)
coretlv.handle_message(message)
switch_node = coretlv.session.get_node(switch, SwitchNode)
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
all_links = switch_node.all_link_data()
assert len(all_links) == 1
def test_link_add_node_to_node(self, coretlv: CoreHandler):
node_one = 1
coretlv.session.add_node(CoreNode, _id=node_one)
node_two = 2
coretlv.session.add_node(CoreNode, _id=node_two)
node1_id = 1
coretlv.session.add_node(CoreNode, _id=node1_id)
node2_id = 2
coretlv.session.add_node(CoreNode, _id=node2_id)
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
interface_one = str(ip_prefix[node_one])
interface_two = str(ip_prefix[node_two])
interface1_ip4 = str(ip_prefix[node1_id])
interface2_ip4 = str(ip_prefix[node2_id])
message = coreapi.CoreLinkMessage.create(
MessageFlags.ADD.value,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, node_two),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, node2_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
(LinkTlvs.INTERFACE1_IP4, interface_one),
(LinkTlvs.INTERFACE1_IP4, interface1_ip4),
(LinkTlvs.INTERFACE1_IP4_MASK, 24),
(LinkTlvs.INTERFACE2_NUMBER, 0),
(LinkTlvs.INTERFACE2_IP4, interface_two),
(LinkTlvs.INTERFACE2_IP4, interface2_ip4),
(LinkTlvs.INTERFACE2_IP4_MASK, 24),
],
)
@ -177,24 +180,24 @@ class TestGui:
assert len(all_links) == 1
def test_link_update(self, coretlv: CoreHandler):
node_one = 1
coretlv.session.add_node(CoreNode, _id=node_one)
switch = 2
coretlv.session.add_node(SwitchNode, _id=switch)
node1_id = 1
coretlv.session.add_node(CoreNode, _id=node1_id)
switch_id = 2
coretlv.session.add_node(SwitchNode, _id=switch_id)
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
interface_one = str(ip_prefix[node_one])
interface1_ip4 = str(ip_prefix[node1_id])
message = coreapi.CoreLinkMessage.create(
MessageFlags.ADD.value,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, switch),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, switch_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
(LinkTlvs.INTERFACE1_IP4, interface_one),
(LinkTlvs.INTERFACE1_IP4, interface1_ip4),
(LinkTlvs.INTERFACE1_IP4_MASK, 24),
],
)
coretlv.handle_message(message)
switch_node = coretlv.session.get_node(switch, SwitchNode)
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
all_links = switch_node.all_link_data()
assert len(all_links) == 1
link = all_links[0]
@ -204,37 +207,37 @@ class TestGui:
message = coreapi.CoreLinkMessage.create(
0,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, switch),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, switch_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
(LinkTlvs.BANDWIDTH, bandwidth),
],
)
coretlv.handle_message(message)
switch_node = coretlv.session.get_node(switch, SwitchNode)
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
all_links = switch_node.all_link_data()
assert len(all_links) == 1
link = all_links[0]
assert link.bandwidth == bandwidth
def test_link_delete_node_to_node(self, coretlv: CoreHandler):
node_one = 1
coretlv.session.add_node(CoreNode, _id=node_one)
node_two = 2
coretlv.session.add_node(CoreNode, _id=node_two)
node1_id = 1
coretlv.session.add_node(CoreNode, _id=node1_id)
node2_id = 2
coretlv.session.add_node(CoreNode, _id=node2_id)
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
interface_one = str(ip_prefix[node_one])
interface_two = str(ip_prefix[node_two])
interface1_ip4 = str(ip_prefix[node1_id])
interface2_ip4 = str(ip_prefix[node2_id])
message = coreapi.CoreLinkMessage.create(
MessageFlags.ADD.value,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, node_two),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, node2_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
(LinkTlvs.INTERFACE1_IP4, interface_one),
(LinkTlvs.INTERFACE1_IP4, interface1_ip4),
(LinkTlvs.INTERFACE1_IP4_MASK, 24),
(LinkTlvs.INTERFACE2_IP4, interface_two),
(LinkTlvs.INTERFACE2_IP4, interface2_ip4),
(LinkTlvs.INTERFACE2_IP4_MASK, 24),
],
)
@ -248,8 +251,8 @@ class TestGui:
message = coreapi.CoreLinkMessage.create(
MessageFlags.DELETE.value,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, node_two),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, node2_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
(LinkTlvs.INTERFACE2_NUMBER, 0),
],
@ -263,74 +266,74 @@ class TestGui:
assert len(all_links) == 0
def test_link_delete_node_to_net(self, coretlv: CoreHandler):
node_one = 1
coretlv.session.add_node(CoreNode, _id=node_one)
switch = 2
coretlv.session.add_node(SwitchNode, _id=switch)
node1_id = 1
coretlv.session.add_node(CoreNode, _id=node1_id)
switch_id = 2
coretlv.session.add_node(SwitchNode, _id=switch_id)
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
interface_one = str(ip_prefix[node_one])
interface1_ip4 = str(ip_prefix[node1_id])
message = coreapi.CoreLinkMessage.create(
MessageFlags.ADD.value,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, switch),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, switch_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
(LinkTlvs.INTERFACE1_IP4, interface_one),
(LinkTlvs.INTERFACE1_IP4, interface1_ip4),
(LinkTlvs.INTERFACE1_IP4_MASK, 24),
],
)
coretlv.handle_message(message)
switch_node = coretlv.session.get_node(switch, SwitchNode)
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
all_links = switch_node.all_link_data()
assert len(all_links) == 1
message = coreapi.CoreLinkMessage.create(
MessageFlags.DELETE.value,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, switch),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, switch_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
],
)
coretlv.handle_message(message)
switch_node = coretlv.session.get_node(switch, SwitchNode)
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
all_links = switch_node.all_link_data()
assert len(all_links) == 0
def test_link_delete_net_to_node(self, coretlv: CoreHandler):
node_one = 1
coretlv.session.add_node(CoreNode, _id=node_one)
switch = 2
coretlv.session.add_node(SwitchNode, _id=switch)
node1_id = 1
coretlv.session.add_node(CoreNode, _id=node1_id)
switch_id = 2
coretlv.session.add_node(SwitchNode, _id=switch_id)
ip_prefix = netaddr.IPNetwork("10.0.0.0/24")
interface_one = str(ip_prefix[node_one])
interface1_ip4 = str(ip_prefix[node1_id])
message = coreapi.CoreLinkMessage.create(
MessageFlags.ADD.value,
[
(LinkTlvs.N1_NUMBER, node_one),
(LinkTlvs.N2_NUMBER, switch),
(LinkTlvs.N1_NUMBER, node1_id),
(LinkTlvs.N2_NUMBER, switch_id),
(LinkTlvs.INTERFACE1_NUMBER, 0),
(LinkTlvs.INTERFACE1_IP4, interface_one),
(LinkTlvs.INTERFACE1_IP4, interface1_ip4),
(LinkTlvs.INTERFACE1_IP4_MASK, 24),
],
)
coretlv.handle_message(message)
switch_node = coretlv.session.get_node(switch, SwitchNode)
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
all_links = switch_node.all_link_data()
assert len(all_links) == 1
message = coreapi.CoreLinkMessage.create(
MessageFlags.DELETE.value,
[
(LinkTlvs.N1_NUMBER, switch),
(LinkTlvs.N2_NUMBER, node_one),
(LinkTlvs.N1_NUMBER, switch_id),
(LinkTlvs.N2_NUMBER, node1_id),
(LinkTlvs.INTERFACE2_NUMBER, 0),
],
)
coretlv.handle_message(message)
switch_node = coretlv.session.get_node(switch, SwitchNode)
switch_node = coretlv.session.get_node(switch_id, SwitchNode)
all_links = switch_node.all_link_data()
assert len(all_links) == 0

View file

@ -10,71 +10,71 @@ def create_ptp_network(
session: Session, ip_prefixes: IpPrefixes
) -> Tuple[CoreNode, CoreNode]:
# create nodes
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
# link nodes to net node
interface_one = ip_prefixes.create_interface(node_one)
interface_two = ip_prefixes.create_interface(node_two)
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
interface1_data = ip_prefixes.create_interface(node1)
interface2_data = ip_prefixes.create_interface(node2)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
# instantiate session
session.instantiate()
return node_one, node_two
return node1, node2
class TestLinks:
def test_add_ptp(self, session: Session, ip_prefixes: IpPrefixes):
# given
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
interface_one = ip_prefixes.create_interface(node_one)
interface_two = ip_prefixes.create_interface(node_two)
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
interface1_data = ip_prefixes.create_interface(node1)
interface2_data = ip_prefixes.create_interface(node2)
# when
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
# then
assert node_one.netif(interface_one.id)
assert node_two.netif(interface_two.id)
assert node1.netif(interface1_data.id)
assert node2.netif(interface2_data.id)
def test_add_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
# given
node_one = session.add_node(CoreNode)
node_two = session.add_node(SwitchNode)
interface_one = ip_prefixes.create_interface(node_one)
node1 = session.add_node(CoreNode)
node2 = session.add_node(SwitchNode)
interface1_data = ip_prefixes.create_interface(node1)
# when
session.add_link(node_one.id, node_two.id, interface_one=interface_one)
session.add_link(node1.id, node2.id, interface1_data=interface1_data)
# then
assert node_two.all_link_data()
assert node_one.netif(interface_one.id)
assert node2.all_link_data()
assert node1.netif(interface1_data.id)
def test_add_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
# given
node_one = session.add_node(SwitchNode)
node_two = session.add_node(CoreNode)
interface_two = ip_prefixes.create_interface(node_two)
node1 = session.add_node(SwitchNode)
node2 = session.add_node(CoreNode)
interface2_data = ip_prefixes.create_interface(node2)
# when
session.add_link(node_one.id, node_two.id, interface_two=interface_two)
session.add_link(node1.id, node2.id, interface2_data=interface2_data)
# then
assert node_one.all_link_data()
assert node_two.netif(interface_two.id)
assert node1.all_link_data()
assert node2.netif(interface2_data.id)
def test_add_net_to_net(self, session):
# given
node_one = session.add_node(SwitchNode)
node_two = session.add_node(SwitchNode)
node1 = session.add_node(SwitchNode)
node2 = session.add_node(SwitchNode)
# when
session.add_link(node_one.id, node_two.id)
session.add_link(node1.id, node2.id)
# then
assert node_one.all_link_data()
assert node1.all_link_data()
def test_update_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
# given
@ -83,34 +83,31 @@ class TestLinks:
per = 25
dup = 25
jitter = 10
node_one = session.add_node(CoreNode)
node_two = session.add_node(SwitchNode)
interface_one_data = ip_prefixes.create_interface(node_one)
session.add_link(node_one.id, node_two.id, interface_one_data)
interface_one = node_one.netif(interface_one_data.id)
assert interface_one.getparam("delay") != delay
assert interface_one.getparam("bw") != bandwidth
assert interface_one.getparam("loss") != per
assert interface_one.getparam("duplicate") != dup
assert interface_one.getparam("jitter") != jitter
node1 = session.add_node(CoreNode)
node2 = session.add_node(SwitchNode)
interface1_data = ip_prefixes.create_interface(node1)
session.add_link(node1.id, node2.id, interface1_data)
interface1 = node1.netif(interface1_data.id)
assert interface1.getparam("delay") != delay
assert interface1.getparam("bw") != bandwidth
assert interface1.getparam("loss") != per
assert interface1.getparam("duplicate") != dup
assert interface1.getparam("jitter") != jitter
# when
link_options = LinkOptions(
options = LinkOptions(
delay=delay, bandwidth=bandwidth, per=per, dup=dup, jitter=jitter
)
session.update_link(
node_one.id,
node_two.id,
interface_one_id=interface_one_data.id,
options=link_options,
node1.id, node2.id, interface1_id=interface1_data.id, options=options
)
# then
assert interface_one.getparam("delay") == delay
assert interface_one.getparam("bw") == bandwidth
assert interface_one.getparam("loss") == per
assert interface_one.getparam("duplicate") == dup
assert interface_one.getparam("jitter") == jitter
assert interface1.getparam("delay") == delay
assert interface1.getparam("bw") == bandwidth
assert interface1.getparam("loss") == per
assert interface1.getparam("duplicate") == dup
assert interface1.getparam("jitter") == jitter
def test_update_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
# given
@ -119,34 +116,31 @@ class TestLinks:
per = 25
dup = 25
jitter = 10
node_one = session.add_node(SwitchNode)
node_two = session.add_node(CoreNode)
interface_two_data = ip_prefixes.create_interface(node_two)
session.add_link(node_one.id, node_two.id, interface_two=interface_two_data)
interface_two = node_two.netif(interface_two_data.id)
assert interface_two.getparam("delay") != delay
assert interface_two.getparam("bw") != bandwidth
assert interface_two.getparam("loss") != per
assert interface_two.getparam("duplicate") != dup
assert interface_two.getparam("jitter") != jitter
node1 = session.add_node(SwitchNode)
node2 = session.add_node(CoreNode)
interface2_data = ip_prefixes.create_interface(node2)
session.add_link(node1.id, node2.id, interface2_data=interface2_data)
interface2 = node2.netif(interface2_data.id)
assert interface2.getparam("delay") != delay
assert interface2.getparam("bw") != bandwidth
assert interface2.getparam("loss") != per
assert interface2.getparam("duplicate") != dup
assert interface2.getparam("jitter") != jitter
# when
link_options = LinkOptions(
options = LinkOptions(
delay=delay, bandwidth=bandwidth, per=per, dup=dup, jitter=jitter
)
session.update_link(
node_one.id,
node_two.id,
interface_two_id=interface_two_data.id,
options=link_options,
node1.id, node2.id, interface2_id=interface2_data.id, options=options
)
# then
assert interface_two.getparam("delay") == delay
assert interface_two.getparam("bw") == bandwidth
assert interface_two.getparam("loss") == per
assert interface_two.getparam("duplicate") == dup
assert interface_two.getparam("jitter") == jitter
assert interface2.getparam("delay") == delay
assert interface2.getparam("bw") == bandwidth
assert interface2.getparam("loss") == per
assert interface2.getparam("duplicate") == dup
assert interface2.getparam("jitter") == jitter
def test_update_ptp(self, session: Session, ip_prefixes: IpPrefixes):
# given
@ -155,93 +149,85 @@ class TestLinks:
per = 25
dup = 25
jitter = 10
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
interface_one_data = ip_prefixes.create_interface(node_one)
interface_two_data = ip_prefixes.create_interface(node_two)
session.add_link(
node_one.id, node_two.id, interface_one_data, interface_two_data
)
interface_one = node_one.netif(interface_one_data.id)
interface_two = node_two.netif(interface_two_data.id)
assert interface_one.getparam("delay") != delay
assert interface_one.getparam("bw") != bandwidth
assert interface_one.getparam("loss") != per
assert interface_one.getparam("duplicate") != dup
assert interface_one.getparam("jitter") != jitter
assert interface_two.getparam("delay") != delay
assert interface_two.getparam("bw") != bandwidth
assert interface_two.getparam("loss") != per
assert interface_two.getparam("duplicate") != dup
assert interface_two.getparam("jitter") != jitter
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
interface1_data = ip_prefixes.create_interface(node1)
interface2_data = ip_prefixes.create_interface(node2)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
interface1 = node1.netif(interface1_data.id)
interface2 = node2.netif(interface2_data.id)
assert interface1.getparam("delay") != delay
assert interface1.getparam("bw") != bandwidth
assert interface1.getparam("loss") != per
assert interface1.getparam("duplicate") != dup
assert interface1.getparam("jitter") != jitter
assert interface2.getparam("delay") != delay
assert interface2.getparam("bw") != bandwidth
assert interface2.getparam("loss") != per
assert interface2.getparam("duplicate") != dup
assert interface2.getparam("jitter") != jitter
# when
link_options = LinkOptions(
options = LinkOptions(
delay=delay, bandwidth=bandwidth, per=per, dup=dup, jitter=jitter
)
session.update_link(
node_one.id,
node_two.id,
interface_one_data.id,
interface_two_data.id,
link_options,
node1.id, node2.id, interface1_data.id, interface2_data.id, options
)
# then
assert interface_one.getparam("delay") == delay
assert interface_one.getparam("bw") == bandwidth
assert interface_one.getparam("loss") == per
assert interface_one.getparam("duplicate") == dup
assert interface_one.getparam("jitter") == jitter
assert interface_two.getparam("delay") == delay
assert interface_two.getparam("bw") == bandwidth
assert interface_two.getparam("loss") == per
assert interface_two.getparam("duplicate") == dup
assert interface_two.getparam("jitter") == jitter
assert interface1.getparam("delay") == delay
assert interface1.getparam("bw") == bandwidth
assert interface1.getparam("loss") == per
assert interface1.getparam("duplicate") == dup
assert interface1.getparam("jitter") == jitter
assert interface2.getparam("delay") == delay
assert interface2.getparam("bw") == bandwidth
assert interface2.getparam("loss") == per
assert interface2.getparam("duplicate") == dup
assert interface2.getparam("jitter") == jitter
def test_delete_ptp(self, session: Session, ip_prefixes: IpPrefixes):
# given
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
interface_one = ip_prefixes.create_interface(node_one)
interface_two = ip_prefixes.create_interface(node_two)
session.add_link(node_one.id, node_two.id, interface_one, interface_two)
assert node_one.netif(interface_one.id)
assert node_two.netif(interface_two.id)
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
interface1_data = ip_prefixes.create_interface(node1)
interface2_data = ip_prefixes.create_interface(node2)
session.add_link(node1.id, node2.id, interface1_data, interface2_data)
assert node1.netif(interface1_data.id)
assert node2.netif(interface2_data.id)
# when
session.delete_link(
node_one.id, node_two.id, interface_one.id, interface_two.id
)
session.delete_link(node1.id, node2.id, interface1_data.id, interface2_data.id)
# then
assert not node_one.netif(interface_one.id)
assert not node_two.netif(interface_two.id)
assert not node1.netif(interface1_data.id)
assert not node2.netif(interface2_data.id)
def test_delete_node_to_net(self, session: Session, ip_prefixes: IpPrefixes):
# given
node_one = session.add_node(CoreNode)
node_two = session.add_node(SwitchNode)
interface_one = ip_prefixes.create_interface(node_one)
session.add_link(node_one.id, node_two.id, interface_one)
assert node_one.netif(interface_one.id)
node1 = session.add_node(CoreNode)
node2 = session.add_node(SwitchNode)
interface1_data = ip_prefixes.create_interface(node1)
session.add_link(node1.id, node2.id, interface1_data)
assert node1.netif(interface1_data.id)
# when
session.delete_link(node_one.id, node_two.id, interface_one_id=interface_one.id)
session.delete_link(node1.id, node2.id, interface1_id=interface1_data.id)
# then
assert not node_one.netif(interface_one.id)
assert not node1.netif(interface1_data.id)
def test_delete_net_to_node(self, session: Session, ip_prefixes: IpPrefixes):
# given
node_one = session.add_node(SwitchNode)
node_two = session.add_node(CoreNode)
interface_two = ip_prefixes.create_interface(node_two)
session.add_link(node_one.id, node_two.id, interface_two=interface_two)
assert node_two.netif(interface_two.id)
node1 = session.add_node(SwitchNode)
node2 = session.add_node(CoreNode)
interface2_data = ip_prefixes.create_interface(node2)
session.add_link(node1.id, node2.id, interface2_data=interface2_data)
assert node2.netif(interface2_data.id)
# when
session.delete_link(node_one.id, node_two.id, interface_two_id=interface_two.id)
session.delete_link(node1.id, node2.id, interface2_id=interface2_data.id)
# then
assert not node_two.netif(interface_two.id)
assert not node2.netif(interface2_data.id)

View file

@ -206,23 +206,23 @@ class TestServices:
# given
ServiceManager.add_services(_SERVICES_PATH)
my_service = ServiceManager.get(SERVICE_ONE)
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
file_name = my_service.configs[0]
file_data_one = "# custom file one"
file_data_two = "# custom file two"
file_data1 = "# custom file one"
file_data2 = "# custom file two"
session.services.set_service_file(
node_one.id, my_service.name, file_name, file_data_one
node1.id, my_service.name, file_name, file_data1
)
session.services.set_service_file(
node_two.id, my_service.name, file_name, file_data_two
node2.id, my_service.name, file_name, file_data2
)
# when
custom_service_one = session.services.get_service(node_one.id, my_service.name)
session.services.create_service_files(node_one, custom_service_one)
custom_service_two = session.services.get_service(node_two.id, my_service.name)
session.services.create_service_files(node_two, custom_service_two)
custom_service1 = session.services.get_service(node1.id, my_service.name)
session.services.create_service_files(node1, custom_service1)
custom_service2 = session.services.get_service(node2.id, my_service.name)
session.services.create_service_files(node2, custom_service2)
def test_service_import(self):
"""

View file

@ -68,20 +68,20 @@ class TestXml:
ptp_node = session.add_node(PtpNet)
# create nodes
node_one = session.add_node(CoreNode)
node_two = session.add_node(CoreNode)
node1 = session.add_node(CoreNode)
node2 = session.add_node(CoreNode)
# link nodes to ptp net
for node in [node_one, node_two]:
for node in [node1, node2]:
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, ptp_node.id, interface_one=interface)
session.add_link(node.id, ptp_node.id, interface1_data=interface)
# instantiate session
session.instantiate()
# get ids for nodes
n1_id = node_one.id
n2_id = node_two.id
node1_id = node1.id
node2_id = node2.id
# save xml
xml_file = tmpdir.join("session.xml")
@ -97,16 +97,16 @@ class TestXml:
# verify nodes have been removed from session
with pytest.raises(CoreError):
assert not session.get_node(n1_id, CoreNode)
assert not session.get_node(node1_id, CoreNode)
with pytest.raises(CoreError):
assert not session.get_node(n2_id, CoreNode)
assert not session.get_node(node2_id, CoreNode)
# load saved xml
session.open_xml(file_path, start=True)
# verify nodes have been recreated
assert session.get_node(n1_id, CoreNode)
assert session.get_node(n2_id, CoreNode)
assert session.get_node(node1_id, CoreNode)
assert session.get_node(node2_id, CoreNode)
def test_xml_ptp_services(
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
@ -123,28 +123,28 @@ class TestXml:
# create nodes
options = NodeOptions(model="host")
node_one = session.add_node(CoreNode, options=options)
node_two = session.add_node(CoreNode)
node1 = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode)
# link nodes to ptp net
for node in [node_one, node_two]:
for node in [node1, node2]:
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, ptp_node.id, interface_one=interface)
session.add_link(node.id, ptp_node.id, interface1_data=interface)
# set custom values for node service
session.services.set_service(node_one.id, SshService.name)
session.services.set_service(node1.id, SshService.name)
service_file = SshService.configs[0]
file_data = "# test"
session.services.set_service_file(
node_one.id, SshService.name, service_file, file_data
node1.id, SshService.name, service_file, file_data
)
# instantiate session
session.instantiate()
# get ids for nodes
n1_id = node_one.id
n2_id = node_two.id
node1_id = node1.id
node2_id = node2.id
# save xml
xml_file = tmpdir.join("session.xml")
@ -160,19 +160,19 @@ class TestXml:
# verify nodes have been removed from session
with pytest.raises(CoreError):
assert not session.get_node(n1_id, CoreNode)
assert not session.get_node(node1_id, CoreNode)
with pytest.raises(CoreError):
assert not session.get_node(n2_id, CoreNode)
assert not session.get_node(node2_id, CoreNode)
# load saved xml
session.open_xml(file_path, start=True)
# retrieve custom service
service = session.services.get_service(node_one.id, SshService.name)
service = session.services.get_service(node1.id, SshService.name)
# verify nodes have been recreated
assert session.get_node(n1_id, CoreNode)
assert session.get_node(n2_id, CoreNode)
assert session.get_node(node1_id, CoreNode)
assert session.get_node(node2_id, CoreNode)
assert service.config_data.get(service_file) == file_data
def test_xml_mobility(
@ -192,21 +192,21 @@ class TestXml:
# create nodes
options = NodeOptions(model="mdr")
options.set_position(0, 0)
node_one = session.add_node(CoreNode, options=options)
node_two = session.add_node(CoreNode, options=options)
node1 = session.add_node(CoreNode, options=options)
node2 = session.add_node(CoreNode, options=options)
# link nodes
for node in [node_one, node_two]:
for node in [node1, node2]:
interface = ip_prefixes.create_interface(node)
session.add_link(node.id, wlan_node.id, interface_one=interface)
session.add_link(node.id, wlan_node.id, interface1_data=interface)
# instantiate session
session.instantiate()
# get ids for nodes
wlan_id = wlan_node.id
n1_id = node_one.id
n2_id = node_two.id
node1_id = node1.id
node2_id = node2.id
# save xml
xml_file = tmpdir.join("session.xml")
@ -222,9 +222,9 @@ class TestXml:
# verify nodes have been removed from session
with pytest.raises(CoreError):
assert not session.get_node(n1_id, CoreNode)
assert not session.get_node(node1_id, CoreNode)
with pytest.raises(CoreError):
assert not session.get_node(n2_id, CoreNode)
assert not session.get_node(node2_id, CoreNode)
# load saved xml
session.open_xml(file_path, start=True)
@ -233,8 +233,8 @@ class TestXml:
value = str(session.mobility.get_config("test", wlan_id, BasicRangeModel.name))
# verify nodes and configuration were restored
assert session.get_node(n1_id, CoreNode)
assert session.get_node(n2_id, CoreNode)
assert session.get_node(node1_id, CoreNode)
assert session.get_node(node2_id, CoreNode)
assert session.get_node(wlan_id, WlanNode)
assert value == "1"
@ -246,18 +246,18 @@ class TestXml:
:param tmpdir: tmpdir to create data in
"""
# create nodes
switch_one = session.add_node(SwitchNode)
switch_two = session.add_node(SwitchNode)
switch1 = session.add_node(SwitchNode)
switch2 = session.add_node(SwitchNode)
# link nodes
session.add_link(switch_one.id, switch_two.id)
session.add_link(switch1.id, switch2.id)
# instantiate session
session.instantiate()
# get ids for nodes
n1_id = switch_one.id
n2_id = switch_two.id
node1_id = switch1.id
node2_id = switch2.id
# save xml
xml_file = tmpdir.join("session.xml")
@ -273,19 +273,19 @@ class TestXml:
# verify nodes have been removed from session
with pytest.raises(CoreError):
assert not session.get_node(n1_id, SwitchNode)
assert not session.get_node(node1_id, SwitchNode)
with pytest.raises(CoreError):
assert not session.get_node(n2_id, SwitchNode)
assert not session.get_node(node2_id, SwitchNode)
# load saved xml
session.open_xml(file_path, start=True)
# verify nodes have been recreated
switch_one = session.get_node(n1_id, SwitchNode)
switch_two = session.get_node(n2_id, SwitchNode)
assert switch_one
assert switch_two
assert len(switch_one.all_link_data() + switch_two.all_link_data()) == 1
switch1 = session.get_node(node1_id, SwitchNode)
switch2 = session.get_node(node2_id, SwitchNode)
assert switch1
assert switch2
assert len(switch1.all_link_data() + switch2.all_link_data()) == 1
def test_link_options(
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
@ -298,25 +298,25 @@ class TestXml:
:param ip_prefixes: generates ip addresses for nodes
"""
# create nodes
node_one = session.add_node(CoreNode)
interface_one = ip_prefixes.create_interface(node_one)
node1 = session.add_node(CoreNode)
interface1_data = ip_prefixes.create_interface(node1)
switch = session.add_node(SwitchNode)
# create link
link_options = LinkOptions()
link_options.per = 10.5
link_options.bandwidth = 50000
link_options.jitter = 10
link_options.delay = 30
link_options.dup = 5
session.add_link(node_one.id, switch.id, interface_one, options=link_options)
options = LinkOptions()
options.per = 10.5
options.bandwidth = 50000
options.jitter = 10
options.delay = 30
options.dup = 5
session.add_link(node1.id, switch.id, interface1_data, options=options)
# instantiate session
session.instantiate()
# get ids for nodes
n1_id = node_one.id
n2_id = switch.id
node1_id = node1.id
node2_id = switch.id
# save xml
xml_file = tmpdir.join("session.xml")
@ -332,26 +332,26 @@ class TestXml:
# verify nodes have been removed from session
with pytest.raises(CoreError):
assert not session.get_node(n1_id, CoreNode)
assert not session.get_node(node1_id, CoreNode)
with pytest.raises(CoreError):
assert not session.get_node(n2_id, SwitchNode)
assert not session.get_node(node2_id, SwitchNode)
# load saved xml
session.open_xml(file_path, start=True)
# verify nodes have been recreated
assert session.get_node(n1_id, CoreNode)
assert session.get_node(n2_id, SwitchNode)
assert session.get_node(node1_id, CoreNode)
assert session.get_node(node2_id, SwitchNode)
links = []
for node_id in session.nodes:
node = session.nodes[node_id]
links += node.all_link_data()
link = links[0]
assert link_options.per == link.per
assert link_options.bandwidth == link.bandwidth
assert link_options.jitter == link.jitter
assert link_options.delay == link.delay
assert link_options.dup == link.dup
assert options.per == link.per
assert options.bandwidth == link.bandwidth
assert options.jitter == link.jitter
assert options.delay == link.delay
assert options.dup == link.dup
def test_link_options_ptp(
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
@ -364,28 +364,26 @@ class TestXml:
:param ip_prefixes: generates ip addresses for nodes
"""
# create nodes
node_one = session.add_node(CoreNode)
interface_one = ip_prefixes.create_interface(node_one)
node_two = session.add_node(CoreNode)
interface_two = ip_prefixes.create_interface(node_two)
node1 = session.add_node(CoreNode)
interface1_data = ip_prefixes.create_interface(node1)
node2 = session.add_node(CoreNode)
interface2_data = ip_prefixes.create_interface(node2)
# create link
link_options = LinkOptions()
link_options.per = 10.5
link_options.bandwidth = 50000
link_options.jitter = 10
link_options.delay = 30
link_options.dup = 5
session.add_link(
node_one.id, node_two.id, interface_one, interface_two, link_options
)
options = LinkOptions()
options.per = 10.5
options.bandwidth = 50000
options.jitter = 10
options.delay = 30
options.dup = 5
session.add_link(node1.id, node2.id, interface1_data, interface2_data, options)
# instantiate session
session.instantiate()
# get ids for nodes
n1_id = node_one.id
n2_id = node_two.id
node1_id = node1.id
node2_id = node2.id
# save xml
xml_file = tmpdir.join("session.xml")
@ -401,26 +399,26 @@ class TestXml:
# verify nodes have been removed from session
with pytest.raises(CoreError):
assert not session.get_node(n1_id, CoreNode)
assert not session.get_node(node1_id, CoreNode)
with pytest.raises(CoreError):
assert not session.get_node(n2_id, CoreNode)
assert not session.get_node(node2_id, CoreNode)
# load saved xml
session.open_xml(file_path, start=True)
# verify nodes have been recreated
assert session.get_node(n1_id, CoreNode)
assert session.get_node(n2_id, CoreNode)
assert session.get_node(node1_id, CoreNode)
assert session.get_node(node2_id, CoreNode)
links = []
for node_id in session.nodes:
node = session.nodes[node_id]
links += node.all_link_data()
link = links[0]
assert link_options.per == link.per
assert link_options.bandwidth == link.bandwidth
assert link_options.jitter == link.jitter
assert link_options.delay == link.delay
assert link_options.dup == link.dup
assert options.per == link.per
assert options.bandwidth == link.bandwidth
assert options.jitter == link.jitter
assert options.delay == link.delay
assert options.dup == link.dup
def test_link_options_bidirectional(
self, session: Session, tmpdir: TemporaryFile, ip_prefixes: IpPrefixes
@ -433,43 +431,37 @@ class TestXml:
:param ip_prefixes: generates ip addresses for nodes
"""
# create nodes
node_one = session.add_node(CoreNode)
interface_one = ip_prefixes.create_interface(node_one)
node_two = session.add_node(CoreNode)
interface_two = ip_prefixes.create_interface(node_two)
node1 = session.add_node(CoreNode)
interface1_data = ip_prefixes.create_interface(node1)
node2 = session.add_node(CoreNode)
interface2_data = ip_prefixes.create_interface(node2)
# create link
link_options_one = LinkOptions()
link_options_one.unidirectional = 1
link_options_one.bandwidth = 5000
link_options_one.delay = 10
link_options_one.per = 10.5
link_options_one.dup = 5
link_options_one.jitter = 5
session.add_link(
node_one.id, node_two.id, interface_one, interface_two, link_options_one
)
link_options_two = LinkOptions()
link_options_two.unidirectional = 1
link_options_two.bandwidth = 10000
link_options_two.delay = 20
link_options_two.per = 10
link_options_two.dup = 10
link_options_two.jitter = 10
options1 = LinkOptions()
options1.unidirectional = 1
options1.bandwidth = 5000
options1.delay = 10
options1.per = 10.5
options1.dup = 5
options1.jitter = 5
session.add_link(node1.id, node2.id, interface1_data, interface2_data, options1)
options2 = LinkOptions()
options2.unidirectional = 1
options2.bandwidth = 10000
options2.delay = 20
options2.per = 10
options2.dup = 10
options2.jitter = 10
session.update_link(
node_two.id,
node_one.id,
interface_two.id,
interface_one.id,
link_options_two,
node2.id, node1.id, interface2_data.id, interface1_data.id, options2
)
# instantiate session
session.instantiate()
# get ids for nodes
n1_id = node_one.id
n2_id = node_two.id
node1_id = node1.id
node2_id = node2.id
# save xml
xml_file = tmpdir.join("session.xml")
@ -485,30 +477,30 @@ class TestXml:
# verify nodes have been removed from session
with pytest.raises(CoreError):
assert not session.get_node(n1_id, CoreNode)
assert not session.get_node(node1_id, CoreNode)
with pytest.raises(CoreError):
assert not session.get_node(n2_id, CoreNode)
assert not session.get_node(node2_id, CoreNode)
# load saved xml
session.open_xml(file_path, start=True)
# verify nodes have been recreated
assert session.get_node(n1_id, CoreNode)
assert session.get_node(n2_id, CoreNode)
assert session.get_node(node1_id, CoreNode)
assert session.get_node(node2_id, CoreNode)
links = []
for node_id in session.nodes:
node = session.nodes[node_id]
links += node.all_link_data()
assert len(links) == 2
link_one = links[0]
link_two = links[1]
assert link_options_one.bandwidth == link_one.bandwidth
assert link_options_one.delay == link_one.delay
assert link_options_one.per == link_one.per
assert link_options_one.dup == link_one.dup
assert link_options_one.jitter == link_one.jitter
assert link_options_two.bandwidth == link_two.bandwidth
assert link_options_two.delay == link_two.delay
assert link_options_two.per == link_two.per
assert link_options_two.dup == link_two.dup
assert link_options_two.jitter == link_two.jitter
link1 = links[0]
link2 = links[1]
assert options1.bandwidth == link1.bandwidth
assert options1.delay == link1.delay
assert options1.per == link1.per
assert options1.dup == link1.dup
assert options1.jitter == link1.jitter
assert options2.bandwidth == link2.bandwidth
assert options2.delay == link2.delay
assert options2.per == link2.per
assert options2.dup == link2.dup
assert options2.jitter == link2.jitter

View file

@ -62,7 +62,7 @@ def main():
for _ in range(NODES):
node = session.add_node(CoreNode)
interface = prefixes.create_interface(node)
session.add_link(node.id, switch.id, interface_one=interface)
session.add_link(node.id, switch.id, interface1_data=interface)
# instantiate session
session.instantiate()