def _get_representor(self, vif): if isinstance(vif, obj.vif.VIFHostDevice): pci_addr = vif.dev_address elif 'datapath_offload' in vif.port_profile \ and hasattr(vif.port_profile, 'datapath_offload') \ and isinstance(vif.port_profile.datapath_offload, obj.vif.DatapathOffloadRepresentor): pci_addr = vif.port_profile.datapath_offload.representor_address elif 'representor_address' in vif.port_profile \ and hasattr(vif.port_profile, 'representor_address'): pci_addr = vif.port_profile.representor_address else: # TODO(jangutter): New exception is needed raise exception.WrongPortProfile( profile=vif.port_profile.__class__.__name__) vf_num = linux_net.get_vf_num_by_pci_address(pci_addr) pf_ifname = linux_net.get_ifname_by_pci_address(pci_addr, pf_interface=True, switchdev=True) representor = linux_net.get_representor_port(pf_ifname, vf_num) return { 'address': pci_addr, 'name': representor, 'pfname': pf_ifname, 'vfno': vf_num }
def test_physical_function_interface_name_with_switchdev( self, mock__get_phys_port_name, mock__get_phys_switch_id, mock_listdir): mock_listdir.return_value = ['foo', 'bar'] mock__get_phys_switch_id.side_effect = (['', 'valid_switch']) mock__get_phys_port_name.side_effect = (["p1s0"]) ifname = linux_net.get_ifname_by_pci_address('0000:00:00.1', pf_interface=True, switchdev=True) self.assertEqual(ifname, 'bar')
def test_physical_function_inferface_name_with_switchdev( self, mock_listdir, mock_isfile, mock_open): mock_listdir.return_value = ['foo', 'bar'] mock_isfile.side_effect = [True, True] mock_open.return_value.__enter__ = lambda s: s readline_mock = mock_open.return_value.readline readline_mock.side_effect = ( ['', 'valid_switch']) ifname = linux_net.get_ifname_by_pci_address( '0000:00:00.1', pf_interface=True, switchdev=True) self.assertEqual(ifname, 'bar')
def _plug_vf_passthrough(self, vif, instance_info): linux_net.ensure_ovs_bridge(vif.network.bridge, constants.OVS_DATAPATH_SYSTEM) pci_slot = vif.dev_address pf_ifname = linux_net.get_ifname_by_pci_address(pci_slot, pf_interface=True, switchdev=True) vf_num = linux_net.get_vf_num_by_pci_address(pci_slot) representor = linux_net.get_representor_port(pf_ifname, vf_num) linux_net.set_interface_state(representor, 'up') self._create_vif_port(vif, representor, instance_info)
def test_physical_function_interface_name_with_representors( self, mock__get_phys_port_name, mock__get_phys_switch_id, mock_listdir): # Get the PF that matches the phys_port_name regex mock_listdir.return_value = ['enp2s0f0_0', 'enp2s0f0_1', 'enp2s0f0'] mock__get_phys_switch_id.side_effect = ([ 'valid_switch', 'valid_switch', 'valid_switch' ]) mock__get_phys_port_name.side_effect = (["pf0vf0", "pf0vf1", "p0"]) ifname = linux_net.get_ifname_by_pci_address('0000:00:00.1', pf_interface=True, switchdev=True) self.assertEqual(ifname, 'enp2s0f0')
def test_physical_function_interface_name_with_fallback_To_first_netdev( self, mock__get_phys_port_name, mock__get_phys_switch_id, mock_listdir): # Try with switchdev mode to get PF but fail because there is no match # for the phys_port_name then fallback to first interface found mock_listdir.return_value = ['enp2s0f0_0', 'enp2s0f0_1', 'enp2s0f0'] mock__get_phys_switch_id.side_effect = ([ 'valid_switch', 'valid_switch', 'valid_switch' ]) mock__get_phys_port_name.side_effect = (["pf0vf0", "pf0vf1", "pf0vf2"]) ifname = linux_net.get_ifname_by_pci_address('0000:00:00.1', pf_interface=True, switchdev=True) self.assertEqual(ifname, 'enp2s0f0_0')
def _unplug_vf_passthrough(self, vif, instance_info): """Remove port from OVS.""" pci_slot = vif.dev_address pf_ifname = linux_net.get_ifname_by_pci_address(pci_slot, pf_interface=True, switchdev=True) vf_num = linux_net.get_vf_num_by_pci_address(pci_slot) representor = linux_net.get_representor_port(pf_ifname, vf_num) # The representor interface can't be deleted because it bind the # SR-IOV VF, therefore we just need to remove it from the ovs bridge # and set the status to down linux_net.delete_ovs_vif_port(vif.network.bridge, representor, delete_netdev=False) linux_net.set_interface_state(representor, 'down')
def _unplug_vf(self, vif): """Remove port from OVS.""" datapath = self._get_vif_datapath_type(vif) if datapath == constants.OVS_DATAPATH_SYSTEM: pci_slot = vif.dev_address pf_ifname = linux_net.get_ifname_by_pci_address( pci_slot, pf_interface=True, switchdev=True) vf_num = linux_net.get_vf_num_by_pci_address(pci_slot) representor = linux_net.get_representor_port(pf_ifname, vf_num) else: representor = linux_net.get_dpdk_representor_port_name( vif.id) # The representor interface can't be deleted because it bind the # SR-IOV VF, therefore we just need to remove it from the ovs bridge # and set the status to down self.ovsdb.delete_ovs_vif_port( vif.network.bridge, representor, delete_netdev=False) if datapath == constants.OVS_DATAPATH_SYSTEM: linux_net.set_interface_state(representor, 'down')
def _plug_vf(self, vif, instance_info): datapath = self._get_vif_datapath_type(vif) self.ovsdb.ensure_ovs_bridge(vif.network.bridge, datapath) pci_slot = vif.dev_address vf_num = linux_net.get_vf_num_by_pci_address(pci_slot) args = [] kwargs = {} if datapath == constants.OVS_DATAPATH_SYSTEM: pf_ifname = linux_net.get_ifname_by_pci_address( pci_slot, pf_interface=True, switchdev=True) representor = linux_net.get_representor_port(pf_ifname, vf_num) linux_net.set_interface_state(representor, 'up') args = [vif, representor, instance_info] else: representor = linux_net.get_dpdk_representor_port_name( vif.id) pf_pci = linux_net.get_pf_pci_from_vf(pci_slot) args = [vif, representor, instance_info] kwargs = {'interface_type': constants.OVS_DPDK_INTERFACE_TYPE, 'pf_pci': pf_pci, 'vf_num': vf_num} self._create_vif_port(*args, **kwargs)