initial sweeping changes to call all usages of various interface related variables and functions (netif, interface, if, ifc, etc) to use a consistent name iface

This commit is contained in:
Blake Harnden 2020-06-16 09:30:16 -07:00
parent 0462c1b084
commit 0725199d6d
93 changed files with 1955 additions and 2156 deletions

View file

@ -13,33 +13,33 @@ from core.nodes.network import WlanNode
GROUP = "FRR"
def has_mtu_mismatch(ifc: CoreInterface) -> bool:
def has_mtu_mismatch(iface: CoreInterface) -> bool:
"""
Helper to detect MTU mismatch and add the appropriate FRR
mtu-ignore command. This is needed when e.g. a node is linked via a
GreTap device.
"""
if ifc.mtu != 1500:
if iface.mtu != 1500:
return True
if not ifc.net:
if not iface.net:
return False
for i in ifc.net.netifs():
if i.mtu != ifc.mtu:
for iface in iface.net.get_ifaces():
if iface.mtu != iface.mtu:
return True
return False
def get_min_mtu(ifc):
def get_min_mtu(iface):
"""
Helper to discover the minimum MTU of interfaces linked with the
given interface.
"""
mtu = ifc.mtu
if not ifc.net:
mtu = iface.mtu
if not iface.net:
return mtu
for i in ifc.net.netifs():
if i.mtu < mtu:
mtu = i.mtu
for iface in iface.net.get_ifaces():
if iface.mtu < mtu:
mtu = iface.mtu
return mtu
@ -47,10 +47,8 @@ def get_router_id(node: CoreNodeBase) -> str:
"""
Helper to return the first IPv4 address of a node as its router ID.
"""
for ifc in node.netifs():
if getattr(ifc, "control", False):
continue
for a in ifc.addrlist:
for iface in node.get_ifaces(control=False):
for a in iface.addrlist:
a = a.split("/")[0]
if netaddr.valid_ipv4(a):
return a
@ -97,25 +95,25 @@ class FRRZebra(ConfigService):
want_ip6 = True
services.append(service)
interfaces = []
for ifc in self.node.netifs():
ifaces = []
for iface in self.node.get_ifaces():
ip4s = []
ip6s = []
for x in ifc.addrlist:
for x in iface.addrlist:
addr = x.split("/")[0]
if netaddr.valid_ipv4(addr):
ip4s.append(x)
else:
ip6s.append(x)
is_control = getattr(ifc, "control", False)
interfaces.append((ifc, ip4s, ip6s, is_control))
is_control = getattr(iface, "control", False)
ifaces.append((iface, ip4s, ip6s, is_control))
return dict(
frr_conf=frr_conf,
frr_sbin_search=frr_sbin_search,
frr_bin_search=frr_bin_search,
frr_state_dir=constants.FRR_STATE_DIR,
interfaces=interfaces,
ifaces=ifaces,
want_ip4=want_ip4,
want_ip6=want_ip6,
services=services,
@ -138,7 +136,7 @@ class FrrService(abc.ABC):
ipv6_routing = False
@abc.abstractmethod
def frr_interface_config(self, ifc: CoreInterface) -> str:
def frr_iface_config(self, iface: CoreInterface) -> str:
raise NotImplementedError
@abc.abstractmethod
@ -162,10 +160,8 @@ class FRROspfv2(FrrService, ConfigService):
def frr_config(self) -> str:
router_id = get_router_id(self.node)
addresses = []
for ifc in self.node.netifs():
if getattr(ifc, "control", False):
continue
for a in ifc.addrlist:
for iface in self.node.get_ifaces(control=False):
for a in iface.addrlist:
addr = a.split("/")[0]
if netaddr.valid_ipv4(addr):
addresses.append(a)
@ -180,8 +176,8 @@ class FRROspfv2(FrrService, ConfigService):
"""
return self.render_text(text, data)
def frr_interface_config(self, ifc: CoreInterface) -> str:
if has_mtu_mismatch(ifc):
def frr_iface_config(self, iface: CoreInterface) -> str:
if has_mtu_mismatch(iface):
return "ip ospf mtu-ignore"
else:
return ""
@ -203,10 +199,8 @@ class FRROspfv3(FrrService, ConfigService):
def frr_config(self) -> str:
router_id = get_router_id(self.node)
ifnames = []
for ifc in self.node.netifs():
if getattr(ifc, "control", False):
continue
ifnames.append(ifc.name)
for iface in self.node.get_ifaces(control=False):
ifnames.append(iface.name)
data = dict(router_id=router_id, ifnames=ifnames)
text = """
router ospf6
@ -218,9 +212,9 @@ class FRROspfv3(FrrService, ConfigService):
"""
return self.render_text(text, data)
def frr_interface_config(self, ifc: CoreInterface) -> str:
mtu = get_min_mtu(ifc)
if mtu < ifc.mtu:
def frr_iface_config(self, iface: CoreInterface) -> str:
mtu = get_min_mtu(iface)
if mtu < iface.mtu:
return f"ipv6 ospf6 ifmtu {mtu}"
else:
return ""
@ -254,7 +248,7 @@ class FRRBgp(FrrService, ConfigService):
"""
return self.clean_text(text)
def frr_interface_config(self, ifc: CoreInterface) -> str:
def frr_iface_config(self, iface: CoreInterface) -> str:
return ""
@ -279,7 +273,7 @@ class FRRRip(FrrService, ConfigService):
"""
return self.clean_text(text)
def frr_interface_config(self, ifc: CoreInterface) -> str:
def frr_iface_config(self, iface: CoreInterface) -> str:
return ""
@ -304,7 +298,7 @@ class FRRRipng(FrrService, ConfigService):
"""
return self.clean_text(text)
def frr_interface_config(self, ifc: CoreInterface) -> str:
def frr_iface_config(self, iface: CoreInterface) -> str:
return ""
@ -321,10 +315,8 @@ class FRRBabel(FrrService, ConfigService):
def frr_config(self) -> str:
ifnames = []
for ifc in self.node.netifs():
if getattr(ifc, "control", False):
continue
ifnames.append(ifc.name)
for iface in self.node.get_ifaces(control=False):
ifnames.append(iface.name)
text = """
router babel
% for ifname in ifnames:
@ -337,8 +329,8 @@ class FRRBabel(FrrService, ConfigService):
data = dict(ifnames=ifnames)
return self.render_text(text, data)
def frr_interface_config(self, ifc: CoreInterface) -> str:
if isinstance(ifc.net, (WlanNode, EmaneNet)):
def frr_iface_config(self, iface: CoreInterface) -> str:
if isinstance(iface.net, (WlanNode, EmaneNet)):
text = """
babel wireless
no babel split-horizon
@ -363,9 +355,9 @@ class FRRpimd(FrrService, ConfigService):
def frr_config(self) -> str:
ifname = "eth0"
for ifc in self.node.netifs():
if ifc.name != "lo":
ifname = ifc.name
for iface in self.node.get_ifaces():
if iface.name != "lo":
ifname = iface.name
break
text = f"""
@ -382,7 +374,7 @@ class FRRpimd(FrrService, ConfigService):
"""
return self.clean_text(text)
def frr_interface_config(self, ifc: CoreInterface) -> str:
def frr_iface_config(self, iface: CoreInterface) -> str:
text = """
ip mfea
ip igmp