From 54347452dbaef46216fe81bd805e153bac72f17d Mon Sep 17 00:00:00 2001 From: Jakub Libosvar Date: Fri, 29 Nov 2024 00:04:46 +0000 Subject: [PATCH] Use BFD sessions for local OVN This patch needs bump of ovsdbapp to >=2.10.0 Depends-On: https://review.opendev.org/c/openstack/ovsdbapp/+/936877 Change-Id: I77294a9077e230efbb182cb6590e2ca135449b73 --- ovn_bgp_agent/drivers/openstack/utils/wire.py | 38 +++++++++++++++++-- .../unit/drivers/openstack/utils/test_wire.py | 5 ++- requirements.txt | 2 +- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/ovn_bgp_agent/drivers/openstack/utils/wire.py b/ovn_bgp_agent/drivers/openstack/utils/wire.py index c0c3dcce..b364d0e0 100644 --- a/ovn_bgp_agent/drivers/openstack/utils/wire.py +++ b/ovn_bgp_agent/drivers/openstack/utils/wire.py @@ -233,7 +233,16 @@ def _ensure_base_wiring_config_ovn(ovs_idl, ovn_idl): _execute_commands(ovn_idl, cmds) cmds = [] cmds.extend(_ensure_ovn_policies(ovn_idl, CONF.local_ovn_cluster.peer_ips)) - cmds.extend(_ensure_ovn_routes(ovn_idl, CONF.local_ovn_cluster.peer_ips)) + + ovs_idl.get_ovn_bridge_mappings( + bridge=CONF.local_ovn_cluster.bgp_chassis_id) + + bfds = _ensure_bfds(ovn_idl, zip( + CONF.local_ovn_cluster.peer_ips, + ovs_idl.get_ovn_bridge_mappings( + bridge=CONF.local_ovn_cluster.bgp_chassis_id))) + cmds.extend( + _ensure_ovn_routes(ovn_idl, CONF.local_ovn_cluster.peer_ips, bfds)) # Creation of all router related cmds in a single transaction _execute_commands(ovn_idl, cmds) @@ -261,6 +270,21 @@ def _ensure_base_wiring_config_ovn(ovs_idl, ovn_idl): return ovn_bridge_mappings, flows_info +def _ensure_bfds(ovn_idl, nic_infos): + bfds = [] + for peer_ip, bm in nic_infos: + network, bridge = helpers.parse_bridge_mapping(bm) + # the port name is hardcoded + r_port_name = "{}-{}".format( + constants.OVN_CLUSTER_ROUTER, network) + bfds.append( + ovn_idl.bfd_add( + logical_port=r_port_name, dst_ip=peer_ip, + may_exist=True).execute(check_error=True)) + + return bfds + + def _ensure_ovn_router(ovn_idl): return [ovn_idl.lr_add(constants.OVN_CLUSTER_ROUTER, may_exist=True)] @@ -374,6 +398,11 @@ def _ensure_ovn_network_link_external(ovn_idl, switch_name, ip, mac): cmds.extend(_ensure_lsp_cmds(ovn_idl, s_port_name, switch_name, 'router', 'router', **options)) + # bind to local chassis + # ovn-nbctl lrp-set-gateway-chassis bgp-router-public bgp 1 + cmds.append(ovn_idl.lrp_set_gateway_chassis( + r_port_name, CONF.local_ovn_cluster.bgp_chassis_id, 1)) + _execute_commands(ovn_idl, cmds) @@ -402,12 +431,13 @@ def _ensure_ovn_policies(ovn_idl, next_hops): match, action, may_exist=True, **columns)] -def _ensure_ovn_routes(ovn_idl, peer_ips): +def _ensure_ovn_routes(ovn_idl, peer_ips, bfds): prefix = '0.0.0.0/0' cmds = [] - for ip in peer_ips: + for bfd, ip in zip(bfds, peer_ips): cmds.append(ovn_idl.lr_route_add(constants.OVN_CLUSTER_ROUTER, prefix, - ip, ecmp=True, may_exist=True)) + ip, ecmp=True, may_exist=True, + bfd=bfd.uuid)) return cmds diff --git a/ovn_bgp_agent/tests/unit/drivers/openstack/utils/test_wire.py b/ovn_bgp_agent/tests/unit/drivers/openstack/utils/test_wire.py index e4d0acba..5a77b108 100644 --- a/ovn_bgp_agent/tests/unit/drivers/openstack/utils/test_wire.py +++ b/ovn_bgp_agent/tests/unit/drivers/openstack/utils/test_wire.py @@ -249,10 +249,11 @@ class TestWire(test_base.TestCase): @mock.patch.object(wire, '_execute_commands') def test_ensure_ovn_routes(self, m_cmds): peer_ips = ['1.1.1.1'] - wire._ensure_ovn_routes(self.nb_idl, peer_ips) + bfds = [test_utils.create_row(uuid='bfd')] + wire._ensure_ovn_routes(self.nb_idl, peer_ips, bfds) self.nb_idl.lr_route_add.assert_called_once_with( constants.OVN_CLUSTER_ROUTER, '0.0.0.0/0', peer_ips[0], - ecmp=True, may_exist=True) + ecmp=True, may_exist=True, bfd=bfds[0].uuid) @mock.patch.object(ovs_utils, 'ensure_flow') @mock.patch.object(linux_net, 'get_ip_version') diff --git a/requirements.txt b/requirements.txt index 7eb1a12a..1f100c13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ oslo.privsep>=2.3.0 # Apache-2.0 oslo.rootwrap>=5.15.0 # Apache-2.0 oslo.service>=1.40.2 # Apache-2.0 ovs>=2.8.0 # Apache-2.0 -ovsdbapp>=2.8.0 # Apache-2.0 +ovsdbapp>=2.10.0 # Apache-2.0 pyroute2>=0.6.6;sys_platform!='win32' # Apache-2.0 (+ dual licensed GPL2) stevedore>=1.20.0 # Apache-2.0 tenacity>=6.0.0 # Apache-2.0