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

View file

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

View file

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

View file

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

View file

@ -157,25 +157,27 @@ class PhysicalNode(CoreNodeBase):
self.ifindex += 1
return ifindex
def newnetif(self, net: CoreNetworkBase, interface: InterfaceData) -> CoreInterface:
def newnetif(
self, net: CoreNetworkBase, interface_data: InterfaceData
) -> CoreInterface:
logging.info("creating interface")
addresses = interface.get_addresses()
ifindex = interface.id
addresses = interface_data.get_addresses()
ifindex = interface_data.id
if ifindex is None:
ifindex = self.newifindex()
name = interface.name
name = interface_data.name
if name is None:
name = f"gt{ifindex}"
if self.up:
# 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
_, 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
else:
# this is reached when configuring services (self.up=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
def privatedir(self, path: str) -> None:
@ -297,19 +299,21 @@ class Rj45Node(CoreNodeBase):
self.up = False
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
represents an interface, we do not create another object here,
but attach ourselves to the given network.
:param net: new network instance
:param interface: interface data for new interface
:param interface_data: interface data for new interface
:return: interface index
:raises ValueError: when an interface has already been created, one max
"""
with self.lock:
ifindex = interface.id
ifindex = interface_data.id
if ifindex is None:
ifindex = 0
if self.interface.net is not None:
@ -318,7 +322,7 @@ class Rj45Node(CoreNodeBase):
self.ifindex = ifindex
if net is not None:
self.interface.attachnet(net)
for addr in interface.get_addresses():
for addr in interface_data.get_addresses():
self.addaddr(addr)
return self.interface