From c40fb2b15db10f7e067629b88567ecfb39db61be Mon Sep 17 00:00:00 2001 From: Blake Harnden <32446120+bharnden@users.noreply.github.com> Date: Mon, 11 Apr 2022 10:54:27 -0700 Subject: [PATCH] daemon: updated frr services to use consistent configuration for iface config for ospfv2, enabled opaque lsa support for ospf by default --- .../configservices/frrservices/services.py | 43 ++++++++++++++++--- .../frrservices/templates/frrboot.sh | 4 ++ daemon/core/services/frr.py | 31 +++++++------ 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/daemon/core/configservices/frrservices/services.py b/daemon/core/configservices/frrservices/services.py index dd2d1f9d..7ed965be 100644 --- a/daemon/core/configservices/frrservices/services.py +++ b/daemon/core/configservices/frrservices/services.py @@ -6,7 +6,8 @@ from core.configservice.base import ConfigService, ConfigServiceMode from core.emane.nodes import EmaneNet from core.nodes.base import CoreNodeBase, NodeBase from core.nodes.interface import DEFAULT_MTU, CoreInterface -from core.nodes.network import WlanNode +from core.nodes.network import PtpNet, WlanNode +from core.nodes.physical import Rj45Node from core.nodes.wireless import WirelessNode GROUP: str = "FRR" @@ -64,6 +65,20 @@ def get_router_id(node: CoreNodeBase) -> str: return "0.0.0.0" +def rj45_check(iface: CoreInterface) -> bool: + """ + Helper to detect whether interface is connected an external RJ45 + link. + """ + if iface.net: + for peer_iface in iface.net.get_ifaces(): + if peer_iface == iface: + continue + if isinstance(peer_iface.node, Rj45Node): + return True + return False + + class FRRZebra(ConfigService): name: str = "FRRzebra" group: str = GROUP @@ -169,7 +184,7 @@ class FRROspfv2(FrrService, ConfigService): addresses = [] for iface in self.node.get_ifaces(control=False): for ip4 in iface.ip4s: - addresses.append(str(ip4.ip)) + addresses.append(str(ip4)) data = dict(router_id=router_id, addresses=addresses) text = """ router ospf @@ -177,15 +192,31 @@ class FRROspfv2(FrrService, ConfigService): % for addr in addresses: network ${addr} area 0 % endfor + ospf opaque-lsa ! """ return self.render_text(text, data) def frr_iface_config(self, iface: CoreInterface) -> str: - if has_mtu_mismatch(iface): - return "ip ospf mtu-ignore" - else: - return "" + has_mtu = has_mtu_mismatch(iface) + has_rj45 = rj45_check(iface) + is_ptp = isinstance(iface.net, PtpNet) + data = dict(has_mtu=has_mtu, is_ptp=is_ptp, has_rj45=has_rj45) + text = """ + % if has_mtu: + ip ospf mtu-ignore + % endif + % if has_rj45: + <% return STOP_RENDERING %> + % endif + % if is_ptp: + ip ospf network point-to-point + % endif + ip ospf hello-interval 2 + ip ospf dead-interval 6 + ip ospf retransmit-interval 5 + """ + return self.render_text(text, data) class FRROspfv3(FrrService, ConfigService): diff --git a/daemon/core/configservices/frrservices/templates/frrboot.sh b/daemon/core/configservices/frrservices/templates/frrboot.sh index db47b6d1..c1c11d28 100644 --- a/daemon/core/configservices/frrservices/templates/frrboot.sh +++ b/daemon/core/configservices/frrservices/templates/frrboot.sh @@ -48,6 +48,10 @@ bootdaemon() flags="$flags -6" fi + if [ "$1" = "ospfd" ]; then + flags="$flags --apiserver" + fi + #force FRR to use CORE generated conf file flags="$flags -d -f $FRR_CONF" $FRR_SBIN_DIR/$1 $flags diff --git a/daemon/core/services/frr.py b/daemon/core/services/frr.py index 87145d37..5fbacf42 100644 --- a/daemon/core/services/frr.py +++ b/daemon/core/services/frr.py @@ -195,6 +195,10 @@ bootdaemon() flags="$flags -6" fi + if [ "$1" = "ospfd" ]; then + flags="$flags --apiserver" + fi + #force FRR to use CORE generated conf file flags="$flags -d -f $FRR_CONF" $FRR_SBIN_DIR/$1 $flags @@ -425,12 +429,25 @@ class FRROspfv2(FrrService): for iface in node.get_ifaces(control=False): for ip4 in iface.ip4s: cfg += f" network {ip4} area 0\n" + cfg += " ospf opaque-lsa\n" cfg += "!\n" return cfg @classmethod def generate_frr_iface_config(cls, node: CoreNode, iface: CoreInterface) -> str: - return cls.mtu_check(iface) + cfg = cls.mtu_check(iface) + # external RJ45 connections will use default OSPF timers + if cls.rj45check(iface): + return cfg + cfg += cls.ptp_check(iface) + return ( + cfg + + """\ + ip ospf hello-interval 2 + ip ospf dead-interval 6 + ip ospf retransmit-interval 5 +""" + ) class FRROspfv3(FrrService): @@ -496,18 +513,6 @@ class FRROspfv3(FrrService): @classmethod def generate_frr_iface_config(cls, node: CoreNode, iface: CoreInterface) -> str: return cls.mtu_check(iface) - # cfg = cls.mtucheck(ifc) - # external RJ45 connections will use default OSPF timers - # if cls.rj45check(ifc): - # return cfg - # cfg += cls.ptpcheck(ifc) - # return cfg + """\ - - -# ipv6 ospf6 hello-interval 2 -# ipv6 ospf6 dead-interval 6 -# ipv6 ospf6 retransmit-interval 5 -# """ class FRRBgp(FrrService):