daemon: renamed link_options to options in both session.add_link and session.update_link

This commit is contained in:
Blake Harnden 2020-06-09 13:46:26 -07:00
parent 2965273f58
commit 21da670698
4 changed files with 32 additions and 36 deletions

View file

@ -854,7 +854,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
node_two_id = request.link.node_two_id node_two_id = request.link.node_two_id
interface_one, interface_two, options = grpcutils.add_link_data(request.link) interface_one, interface_two, options = grpcutils.add_link_data(request.link)
node_one_interface, node_two_interface = session.add_link( node_one_interface, node_two_interface = session.add_link(
node_one_id, node_two_id, interface_one, interface_two, link_options=options node_one_id, node_two_id, interface_one, interface_two, options=options
) )
interface_one_proto = None interface_one_proto = None
interface_two_proto = None interface_two_proto = None

View file

@ -299,7 +299,7 @@ class Session:
node_two_id: int, node_two_id: int,
interface_one: InterfaceData = None, interface_one: InterfaceData = None,
interface_two: InterfaceData = None, interface_two: InterfaceData = None,
link_options: LinkOptions = None, options: LinkOptions = None,
) -> Tuple[CoreInterface, CoreInterface]: ) -> Tuple[CoreInterface, CoreInterface]:
""" """
Add a link between nodes. Add a link between nodes.
@ -310,12 +310,12 @@ class Session:
data, defaults to none data, defaults to none
:param interface_two: node two interface :param interface_two: node two interface
data, defaults to none data, defaults to none
:param link_options: data for creating link, :param options: data for creating link,
defaults to no options defaults to no options
:return: tuple of created core interfaces, depending on link :return: tuple of created core interfaces, depending on link
""" """
if not link_options: if not options:
link_options = LinkOptions() options = LinkOptions()
# get node objects identified by link data # get node objects identified by link data
node_one, node_two, net_one, net_two, tunnel = self._link_nodes( node_one, node_two, net_one, net_two, tunnel = self._link_nodes(
@ -332,7 +332,7 @@ class Session:
try: try:
# wireless link # wireless link
if link_options.type == LinkTypes.WIRELESS: if options.type == LinkTypes.WIRELESS:
objects = [node_one, node_two, net_one, net_two] objects = [node_one, node_two, net_one, net_two]
self._link_wireless(objects, connect=True) self._link_wireless(objects, connect=True)
# wired link # wired link
@ -358,7 +358,7 @@ class Session:
node_one_interface = node_one.netif(ifindex) node_one_interface = node_one.netif(ifindex)
wireless_net = isinstance(net_one, (EmaneNet, WlanNode)) wireless_net = isinstance(net_one, (EmaneNet, WlanNode))
if not wireless_net: if not wireless_net:
net_one.linkconfig(node_one_interface, link_options) net_one.linkconfig(node_one_interface, options)
# network to node # network to node
if node_two and net_one: if node_two and net_one:
@ -370,8 +370,8 @@ class Session:
ifindex = node_two.newnetif(net_one, interface_two) ifindex = node_two.newnetif(net_one, interface_two)
node_two_interface = node_two.netif(ifindex) node_two_interface = node_two.netif(ifindex)
wireless_net = isinstance(net_one, (EmaneNet, WlanNode)) wireless_net = isinstance(net_one, (EmaneNet, WlanNode))
if not link_options.unidirectional and not wireless_net: if not options.unidirectional and not wireless_net:
net_one.linkconfig(node_two_interface, link_options) net_one.linkconfig(node_two_interface, options)
# network to network # network to network
if net_one and net_two: if net_one and net_two:
@ -382,10 +382,10 @@ class Session:
) )
interface = net_one.linknet(net_two) interface = net_one.linknet(net_two)
node_one_interface = interface node_one_interface = interface
net_one.linkconfig(interface, link_options) net_one.linkconfig(interface, options)
if not link_options.unidirectional: if not options.unidirectional:
interface.swapparams("_params_up") interface.swapparams("_params_up")
net_two.linkconfig(interface, link_options) net_two.linkconfig(interface, options)
interface.swapparams("_params_up") interface.swapparams("_params_up")
# a tunnel node was found for the nodes # a tunnel node was found for the nodes
@ -396,7 +396,7 @@ class Session:
addresses.extend(interface_two.get_addresses()) addresses.extend(interface_two.get_addresses())
# tunnel node logic # tunnel node logic
key = link_options.key key = options.key
if key and isinstance(net_one, TunnelNode): if key and isinstance(net_one, TunnelNode):
logging.info("setting tunnel key for: %s", net_one.name) logging.info("setting tunnel key for: %s", net_one.name)
net_one.setkey(key) net_one.setkey(key)
@ -416,14 +416,14 @@ class Session:
node_one.adoptnetif( node_one.adoptnetif(
tunnel, interface_one.id, interface_one.mac, addresses tunnel, interface_one.id, interface_one.mac, addresses
) )
node_one.linkconfig(tunnel, link_options) node_one.linkconfig(tunnel, options)
elif node_two and isinstance(node_two, PhysicalNode): elif node_two and isinstance(node_two, PhysicalNode):
logging.info("adding link for physical node: %s", node_two.name) logging.info("adding link for physical node: %s", node_two.name)
addresses = interface_two.get_addresses() addresses = interface_two.get_addresses()
node_two.adoptnetif( node_two.adoptnetif(
tunnel, interface_two.id, interface_two.mac, addresses tunnel, interface_two.id, interface_two.mac, addresses
) )
node_two.linkconfig(tunnel, link_options) node_two.linkconfig(tunnel, options)
finally: finally:
if node_one: if node_one:
node_one.lock.release() node_one.lock.release()
@ -547,7 +547,7 @@ class Session:
node_two_id: int, node_two_id: int,
interface_one_id: int = None, interface_one_id: int = None,
interface_two_id: int = None, interface_two_id: int = None,
link_options: LinkOptions = None, options: LinkOptions = None,
) -> None: ) -> None:
""" """
Update link information between nodes. Update link information between nodes.
@ -556,13 +556,13 @@ class Session:
:param node_two_id: node two id :param node_two_id: node two id
:param interface_one_id: interface id for node one :param interface_one_id: interface id for node one
:param interface_two_id: interface id for node two :param interface_two_id: interface id for node two
:param link_options: data to update link with :param options: data to update link with
:return: nothing :return: nothing
:raises core.CoreError: when updating a wireless type link, when there is a unknown :raises core.CoreError: when updating a wireless type link, when there is a unknown
link between networks link between networks
""" """
if not link_options: if not options:
link_options = LinkOptions() options = LinkOptions()
# get node objects identified by link data # get node objects identified by link data
node_one, node_two, net_one, net_two, _tunnel = self._link_nodes( node_one, node_two, net_one, net_two, _tunnel = self._link_nodes(
@ -576,7 +576,7 @@ class Session:
try: try:
# wireless link # wireless link
if link_options.type == LinkTypes.WIRELESS: if options.type == LinkTypes.WIRELESS:
raise CoreError("cannot update wireless link") raise CoreError("cannot update wireless link")
else: else:
if not node_one and not node_two: if not node_one and not node_two:
@ -594,28 +594,28 @@ class Session:
if upstream: if upstream:
interface.swapparams("_params_up") interface.swapparams("_params_up")
net_one.linkconfig(interface, link_options) net_one.linkconfig(interface, options)
interface.swapparams("_params_up") interface.swapparams("_params_up")
else: else:
net_one.linkconfig(interface, link_options) net_one.linkconfig(interface, options)
if not link_options.unidirectional: if not options.unidirectional:
if upstream: if upstream:
net_two.linkconfig(interface, link_options) net_two.linkconfig(interface, options)
else: else:
interface.swapparams("_params_up") interface.swapparams("_params_up")
net_two.linkconfig(interface, link_options) net_two.linkconfig(interface, options)
interface.swapparams("_params_up") interface.swapparams("_params_up")
else: else:
raise CoreError("modify link for unknown nodes") raise CoreError("modify link for unknown nodes")
elif not node_one: elif not node_one:
# node1 = layer 2node, node2 = layer3 node # node1 = layer 2node, node2 = layer3 node
interface = node_two.netif(interface_two_id) interface = node_two.netif(interface_two_id)
net_one.linkconfig(interface, link_options) net_one.linkconfig(interface, options)
elif not node_two: elif not node_two:
# node2 = layer 2node, node1 = layer3 node # node2 = layer 2node, node1 = layer3 node
interface = node_one.netif(interface_one_id) interface = node_one.netif(interface_one_id)
net_one.linkconfig(interface, link_options) net_one.linkconfig(interface, options)
else: else:
common_networks = node_one.commonnets(node_two) common_networks = node_one.commonnets(node_two)
if not common_networks: if not common_networks:
@ -628,11 +628,9 @@ class Session:
): ):
continue continue
net_one.linkconfig(interface_one, link_options, interface_two) net_one.linkconfig(interface_one, options, interface_two)
if not link_options.unidirectional: if not options.unidirectional:
net_one.linkconfig( net_one.linkconfig(interface_two, options, interface_one)
interface_two, link_options, interface_one
)
finally: finally:
if node_one: if node_one:
node_one.lock.release() node_one.lock.release()

View file

@ -105,7 +105,7 @@ class TestLinks:
node_one.id, node_one.id,
node_two.id, node_two.id,
interface_one_id=interface_one_data.id, interface_one_id=interface_one_data.id,
link_options=link_options, options=link_options,
) )
# then # then

View file

@ -309,9 +309,7 @@ class TestXml:
link_options.jitter = 10 link_options.jitter = 10
link_options.delay = 30 link_options.delay = 30
link_options.dup = 5 link_options.dup = 5
session.add_link( session.add_link(node_one.id, switch.id, interface_one, options=link_options)
node_one.id, switch.id, interface_one, link_options=link_options
)
# instantiate session # instantiate session
session.instantiate() session.instantiate()