daemon: updated variables for InterfaceData to be denote data to make it more clear

This commit is contained in:
Blake Harnden 2020-06-12 17:32:55 -07:00
parent 876699e8ef
commit 178d12b327
4 changed files with 30 additions and 26 deletions
daemon/core

View file

@ -59,13 +59,13 @@ def link_interface(interface_proto: core_pb2.Interface) -> InterfaceData:
:param interface_proto: interface proto :param interface_proto: interface proto
:return: interface data :return: interface data
""" """
interface = None interface_data = None
if interface_proto: if interface_proto:
name = interface_proto.name if interface_proto.name else None name = interface_proto.name if interface_proto.name else None
mac = interface_proto.mac if interface_proto.mac else None mac = interface_proto.mac if interface_proto.mac else None
ip4 = interface_proto.ip4 if interface_proto.ip4 else None ip4 = interface_proto.ip4 if interface_proto.ip4 else None
ip6 = interface_proto.ip6 if interface_proto.ip6 else None ip6 = interface_proto.ip6 if interface_proto.ip6 else None
interface = InterfaceData( interface_data = InterfaceData(
id=interface_proto.id, id=interface_proto.id,
name=name, name=name,
mac=mac, mac=mac,
@ -74,7 +74,7 @@ def link_interface(interface_proto: core_pb2.Interface) -> InterfaceData:
ip6=ip6, ip6=ip6,
ip6_mask=interface_proto.ip6mask, ip6_mask=interface_proto.ip6mask,
) )
return interface return interface_data
def add_link_data( def add_link_data(

View file

@ -201,6 +201,6 @@ class IpPrefixes:
generation generation
:return: new interface data for the provided node :return: new interface data for the provided node
""" """
interface = self.gen_interface(node.id, name, mac) interface_data = self.gen_interface(node.id, name, mac)
interface.id = node.newifindex() interface_data.id = node.newifindex()
return interface return interface_data

View file

@ -475,13 +475,13 @@ class CoreNodeBase(NodeBase):
raise NotImplementedError raise NotImplementedError
def newnetif( def newnetif(
self, net: "CoreNetworkBase", interface: InterfaceData self, net: "CoreNetworkBase", interface_data: InterfaceData
) -> CoreInterface: ) -> CoreInterface:
""" """
Create a new network interface. Create a new network interface.
:param net: network to associate with :param net: network to associate with
:param interface: interface data for new interface :param interface_data: interface data for new interface
:return: interface index :return: interface index
""" """
raise NotImplementedError raise NotImplementedError
@ -860,34 +860,34 @@ class CoreNode(CoreNodeBase):
self.node_net_client.device_up(interface_name) self.node_net_client.device_up(interface_name)
def newnetif( def newnetif(
self, net: "CoreNetworkBase", interface: InterfaceData self, net: "CoreNetworkBase", interface_data: InterfaceData
) -> CoreInterface: ) -> CoreInterface:
""" """
Create a new network interface. Create a new network interface.
:param net: network to associate with :param net: network to associate with
:param interface: interface data for new interface :param interface_data: interface data for new interface
:return: interface index :return: interface index
""" """
addresses = interface.get_addresses() addresses = interface_data.get_addresses()
with self.lock: with self.lock:
# TODO: emane specific code # TODO: emane specific code
if net.is_emane is True: if net.is_emane is True:
ifindex = self.newtuntap(interface.id, interface.name) ifindex = self.newtuntap(interface_data.id, interface_data.name)
# TUN/TAP is not ready for addressing yet; the device may # TUN/TAP is not ready for addressing yet; the device may
# take some time to appear, and installing it into a # take some time to appear, and installing it into a
# namespace after it has been bound removes addressing; # namespace after it has been bound removes addressing;
# save addresses with the interface now # save addresses with the interface now
self.attachnet(ifindex, net) self.attachnet(ifindex, net)
netif = self.netif(ifindex) netif = self.netif(ifindex)
netif.sethwaddr(interface.mac) netif.sethwaddr(interface_data.mac)
for address in addresses: for address in addresses:
netif.addaddr(address) netif.addaddr(address)
else: else:
ifindex = self.newveth(interface.id, interface.name) ifindex = self.newveth(interface_data.id, interface_data.name)
self.attachnet(ifindex, net) self.attachnet(ifindex, net)
if interface.mac: if interface_data.mac:
self.sethwaddr(ifindex, interface.mac) self.sethwaddr(ifindex, interface_data.mac)
for address in addresses: for address in addresses:
self.addaddr(ifindex, address) self.addaddr(ifindex, address)
self.ifup(ifindex) self.ifup(ifindex)

View file

@ -157,25 +157,27 @@ class PhysicalNode(CoreNodeBase):
self.ifindex += 1 self.ifindex += 1
return ifindex return ifindex
def newnetif(self, net: CoreNetworkBase, interface: InterfaceData) -> CoreInterface: def newnetif(
self, net: CoreNetworkBase, interface_data: InterfaceData
) -> CoreInterface:
logging.info("creating interface") logging.info("creating interface")
addresses = interface.get_addresses() addresses = interface_data.get_addresses()
ifindex = interface.id ifindex = interface_data.id
if ifindex is None: if ifindex is None:
ifindex = self.newifindex() ifindex = self.newifindex()
name = interface.name name = interface_data.name
if name is None: if name is None:
name = f"gt{ifindex}" name = f"gt{ifindex}"
if self.up: if self.up:
# this is reached when this node is linked to a network node # this is reached when this node is linked to a network node
# tunnel to net not built yet, so build it now and adopt it # tunnel to net not built yet, so build it now and adopt it
_, remote_tap = self.session.distributed.create_gre_tunnel(net, self.server) _, remote_tap = self.session.distributed.create_gre_tunnel(net, self.server)
self.adoptnetif(remote_tap, ifindex, interface.mac, addresses) self.adoptnetif(remote_tap, ifindex, interface_data.mac, addresses)
return remote_tap return remote_tap
else: else:
# this is reached when configuring services (self.up=False) # this is reached when configuring services (self.up=False)
netif = GreTap(node=self, name=name, session=self.session, start=False) netif = GreTap(node=self, name=name, session=self.session, start=False)
self.adoptnetif(netif, ifindex, interface.mac, addresses) self.adoptnetif(netif, ifindex, interface_data.mac, addresses)
return netif return netif
def privatedir(self, path: str) -> None: def privatedir(self, path: str) -> None:
@ -297,19 +299,21 @@ class Rj45Node(CoreNodeBase):
self.up = False self.up = False
self.restorestate() self.restorestate()
def newnetif(self, net: CoreNetworkBase, interface: InterfaceData) -> CoreInterface: def newnetif(
self, net: CoreNetworkBase, interface_data: InterfaceData
) -> CoreInterface:
""" """
This is called when linking with another node. Since this node This is called when linking with another node. Since this node
represents an interface, we do not create another object here, represents an interface, we do not create another object here,
but attach ourselves to the given network. but attach ourselves to the given network.
:param net: new network instance :param net: new network instance
:param interface: interface data for new interface :param interface_data: interface data for new interface
:return: interface index :return: interface index
:raises ValueError: when an interface has already been created, one max :raises ValueError: when an interface has already been created, one max
""" """
with self.lock: with self.lock:
ifindex = interface.id ifindex = interface_data.id
if ifindex is None: if ifindex is None:
ifindex = 0 ifindex = 0
if self.interface.net is not None: if self.interface.net is not None:
@ -318,7 +322,7 @@ class Rj45Node(CoreNodeBase):
self.ifindex = ifindex self.ifindex = ifindex
if net is not None: if net is not None:
self.interface.attachnet(net) self.interface.attachnet(net)
for addr in interface.get_addresses(): for addr in interface_data.get_addresses():
self.addaddr(addr) self.addaddr(addr)
return self.interface return self.interface