def test_vf_number_found(self, mock_iglob, mock_readlink): mock_iglob.return_value = [ '/sys/bus/pci/devices/0000:00:00.1/physfn/virtfn3', ] mock_readlink.return_value = '../../0000:00:00.1' vf_num = linux_net.get_vf_num_by_pci_address('0000:00:00.1') self.assertEqual(vf_num, '3')
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 _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 _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)