From 3cf4899cf0d6a4868f7ac6ac86451b06360abcef Mon Sep 17 00:00:00 2001 From: Yifan Li Date: Thu, 8 Sep 2022 16:45:46 +0800 Subject: [PATCH] [OVN] Adding support for VNIC type virtio-forwarder. The virtio-forwarder related code has already been written in other neutron components except OVN. Added logic solving virtio-forwarder in OVN plugin.Add unit tests of virtio-forwarder VNIC type. Test cases include test_create_port_with_vnic_virtio_forwarder, test_bind_virtio_forwarder_port_geneve, test_bind_virtio_forwarder_port_vxlan. Closes-Bug: #1988542 Change-Id: I80f32db761f5813409c6f789177b2fdebf643305 --- neutron/common/ovn/constants.py | 1 + .../drivers/ovn/mech_driver/mech_driver.py | 15 +++++++ .../ovn/mech_driver/test_mech_driver.py | 44 +++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/neutron/common/ovn/constants.py b/neutron/common/ovn/constants.py index 6aacbbee022..eed3063ed18 100644 --- a/neutron/common/ovn/constants.py +++ b/neutron/common/ovn/constants.py @@ -431,4 +431,5 @@ OVN_SUPPORTED_VNIC_TYPES = [portbindings.VNIC_NORMAL, portbindings.VNIC_VHOST_VDPA, portbindings.VNIC_REMOTE_MANAGED, portbindings.VNIC_BAREMETAL, + portbindings.VNIC_VIRTIO_FORWARDER, ] diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py index 02778bae34e..3286d74354e 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py @@ -213,6 +213,10 @@ class OVNMechanismDriver(api.MechanismDriver): portbindings.CAP_PORT_FILTER: self.sg_enabled, portbindings.VIF_DETAILS_CONNECTIVITY: self.connectivity, }, + portbindings.VIF_TYPE_AGILIO_OVS: { + portbindings.CAP_PORT_FILTER: self.sg_enabled, + portbindings.VIF_DETAILS_CONNECTIVITY: self.connectivity, + }, portbindings.VIF_TYPE_VHOST_USER: { portbindings.CAP_PORT_FILTER: False, portbindings.VHOST_USER_MODE: @@ -1021,6 +1025,17 @@ class OVNMechanismDriver(api.MechanismDriver): vif_details = dict(self.vif_details[vif_type]) vif_details[portbindings.VHOST_USER_SOCKET] = ( vhost_user_socket) + elif (vnic_type == portbindings.VNIC_VIRTIO_FORWARDER): + vhost_user_socket = ovn_utils.ovn_vhu_sockpath( + ovn_conf.get_ovn_vhost_sock_dir(), port['id']) + vif_type = portbindings.VIF_TYPE_AGILIO_OVS + port[portbindings.VIF_DETAILS].update({ + portbindings.VHOST_USER_SOCKET: vhost_user_socket}) + vif_details = dict(self.vif_details[vif_type]) + vif_details[portbindings.VHOST_USER_SOCKET] = ( + vhost_user_socket) + vif_details[portbindings.VHOST_USER_MODE] = ( + portbindings.VHOST_USER_MODE_CLIENT) else: vif_type = portbindings.VIF_TYPE_OVS vif_details = self.vif_details[vif_type] diff --git a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py index f768bf7635a..e7822c7488b 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py @@ -1250,6 +1250,28 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase): portbindings.VIF_TYPE_OVS, self.mech_driver.vif_details[portbindings.VIF_TYPE_OVS]) + def _test_bind_port_virtio_forwarder(self, fake_segments): + fake_port = fakes.FakePort.create_one_port( + attrs={'binding:vnic_type': 'virtio-forwarder'}).info() + fake_host = 'host' + fake_port_context = fakes.FakePortContext( + fake_port, fake_host, fake_segments) + self.mech_driver.bind_port(fake_port_context) + + vif_details = self.mech_driver.\ + vif_details[portbindings.VIF_TYPE_AGILIO_OVS] + vif_details.update({"vhostuser_socket": ovn_utils.ovn_vhu_sockpath( + ovn_conf.get_ovn_vhost_sock_dir(), fake_port['id'])}) + vif_details.update({"vhostuser_mode": "client"}) + + neutron_agent.AgentCache().get_agents.assert_called_once_with( + {'host': fake_host, + 'agent_type': ovn_const.OVN_CONTROLLER_TYPES}) + fake_port_context.set_binding.assert_called_once_with( + fake_segments[0]['id'], + portbindings.VIF_TYPE_AGILIO_OVS, + vif_details) + def _test_bind_port_remote_managed(self, fake_segments): fake_serial = 'fake-serial' fake_port = fakes.FakePort.create_one_port( @@ -1329,6 +1351,15 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase): [fakes.FakeSegment.create_one_segment(attrs=segment_attrs).info()] self._test_bind_port_remote_managed(fake_segments) + def test_bind_virtio_forwarder_port_geneve(self): + """Test binding a VIRTIO_FORWARDER port to a geneve segment.""" + segment_attrs = {'network_type': 'geneve', + 'physical_network': None, + 'segmentation_id': 1023} + fake_segments = \ + [fakes.FakeSegment.create_one_segment(attrs=segment_attrs).info()] + self._test_bind_port_virtio_forwarder(fake_segments) + def test_bind_remote_managed_port_vlan(self): """Test binding a REMOTE_MANAGED port to a geneve segment.""" segment_attrs = {'network_type': 'vlan', @@ -1362,6 +1393,15 @@ class TestOVNMechanismDriver(TestOVNMechanismDriverBase): [fakes.FakeSegment.create_one_segment(attrs=segment_attrs).info()] self._test_bind_port(fake_segments) + def test_bind_virtio_forwarder_port_vxlan(self): + """Test binding a VIRTIO_FORWARDER port to a vxlan segment.""" + segment_attrs = {'network_type': 'vxlan', + 'physical_network': None, + 'segmentation_id': 1024} + fake_segments = \ + [fakes.FakeSegment.create_one_segment(attrs=segment_attrs).info()] + self._test_bind_port_virtio_forwarder(fake_segments) + def test__is_port_provisioning_required(self): fake_port = fakes.FakePort.create_one_port( attrs={'binding:vnic_type': 'normal', @@ -3929,6 +3969,10 @@ class TestOVNMechanismDriverSecurityGroup(MechDriverSetupBase, self._test_create_port_with_vnic_type( portbindings.VNIC_BAREMETAL) + def test_create_port_with_vnic_virtio_forwarder(self): + self._test_create_port_with_vnic_type( + portbindings.VNIC_VIRTIO_FORWARDER) + def test_update_port_with_sgs(self): with self.network() as n, self.subnet(n): sg1 = self._create_empty_sg('sg1')