Ejemplo n.º 1
0
 def do_return_to_linux(self):
     if not self.m_devices:
         self.run_dpdk_lspci()
     dpdk_interfaces = []
     for device in self.m_devices.values():
         if device.get('Driver_str') in dpdk_nic_bind.dpdk_drivers:
             dpdk_interfaces.append(device['Slot'])
     if not dpdk_interfaces:
         print('No DPDK bound interfaces.')
         return
     if dpdk_nic_bind.get_igb_uio_usage():
         pid = dpdk_nic_bind.get_pid_using_pci(dpdk_interfaces)
         if pid:
             cmdline = dpdk_nic_bind.read_pid_cmdline(pid)
             print('DPDK interfaces are in use. Unbinding them might cause following process to hang:\npid: %s, cmd: %s' % (pid, cmdline))
             if not dpdk_nic_bind.confirm('Confirm (y/N):'):
                 return
     drivers_table = {
         'rte_ixgbe_pmd': 'ixgbe',
         'rte_igb_pmd': 'igb',
         'rte_i40e_pmd': 'i40e',
         'rte_em_pmd': 'e1000',
         'rte_vmxnet3_pmd': 'vmxnet3',
         'rte_virtio_pmd': 'virtio-pci',
         'rte_enic_pmd': 'enic',
     }
     for pci, info in dpdk_nic_bind.get_info_from_trex(dpdk_interfaces).items():
         if pci not in self.m_devices:
             raise DpdkSetup('Internal error: PCI %s is not found among devices' % pci)
         dev = self.m_devices[pci]
         if info['TRex_Driver'] not in drivers_table:
             print('Got unknown driver %s, description: %s' % (info['TRex_Driver'], dev['Device_str']))
         else:
             print('Returning to Linux %s' % pci)
             dpdk_nic_bind.bind_one(pci, drivers_table[info['TRex_Driver']], False)
Ejemplo n.º 2
0
 def do_return_to_linux(self):
     if not self.m_devices:
         self.run_dpdk_lspci()
     dpdk_interfaces = []
     for device in self.m_devices.values():
         if device.get('Driver_str') in dpdk_nic_bind.dpdk_drivers:
             dpdk_interfaces.append(device['Slot'])
     if not dpdk_interfaces:
         print('No DPDK bound interfaces.')
         return
     if dpdk_nic_bind.get_igb_uio_usage():
         pid = dpdk_nic_bind.get_pid_using_pci(dpdk_interfaces)
         if pid:
             cmdline = dpdk_nic_bind.read_pid_cmdline(pid)
             print('DPDK interfaces are in use. Unbinding them might cause following process to hang:\n%s' % cmdline)
             if not dpdk_nic_bind.confirm('Confirm (y/N):'):
                 return
     drivers_table = {
         'rte_ixgbe_pmd': 'ixgbe',
         'rte_igb_pmd': 'igb',
         'rte_i40e_pmd': 'i40e',
         'rte_em_pmd': 'e1000',
         'rte_vmxnet3_pmd': 'vmxnet3',
         'rte_virtio_pmd': 'virtio',
         'rte_enic_pmd': 'enic',
     }
     for pci, info in dpdk_nic_bind.get_info_from_trex(dpdk_interfaces).items():
         if pci not in self.m_devices:
             raise DpdkSetup('Internal error: PCI %s is not found among devices' % pci)
         dev = self.m_devices[pci]
         if info['TRex_Driver'] not in drivers_table:
             print('Got unknown driver %s, description: %s' % (info['TRex_Driver'], dev['Device_str']))
         else:
             print('Returning to Linux %s' % pci)
             dpdk_nic_bind.bind_one(pci, drivers_table[info['TRex_Driver']], False)
Ejemplo n.º 3
0
    def _get_wanted_interfaces(self, input_interfaces):
        if type(input_interfaces) is not list:
            raise DpdkSetup('type of input interfaces should be list')
        if not len(input_interfaces):
            raise DpdkSetup('Please specify interfaces to use in the config')
        if len(input_interfaces) % 2:
            raise DpdkSetup('Please specify even number of interfaces')
        wanted_interfaces = []
        sorted_pci = sorted(self.m_devices.keys())
        for interface in input_interfaces:
            dev = None
            try:
                interface = int(interface)
                if interface < 0 or interface >= len(sorted_pci):
                    raise DpdkSetup(
                        'Index of an interfaces should be in range 0:%s' %
                        (len(sorted_pci) - 1))
                dev = self.m_devices[sorted_pci[interface]]
            except ValueError:
                for d in self.m_devices.values():
                    if interface in (d['Interface'], d['Slot'], d['Slot_str']):
                        dev = d
                        break
            if not dev:
                raise DpdkSetup(
                    'Could not find information about this interface: %s' %
                    interface)
            if dev in wanted_interfaces:
                raise DpdkSetup('Interface %s is specified twice' % interface)
            dev['Interface_argv'] = interface
            wanted_interfaces.append(dev)

        unbound = []
        for interface in wanted_interfaces:
            if 'Driver_str' not in interface:
                unbound.append(interface['Slot'])
        if unbound:
            for pci, info in dpdk_nic_bind.get_info_from_trex(unbound).items():
                if pci not in self.m_devices:
                    raise DpdkSetup(
                        'Internal error: PCI %s is not found among devices' %
                        pci)
                self.m_devices[pci].update(info)

        return wanted_interfaces
    def _get_wanted_interfaces(self, input_interfaces, get_macs = True):
        if type(input_interfaces) is not list:
            raise DpdkSetup('type of input interfaces should be list')
        if not len(input_interfaces):
            raise DpdkSetup('Please specify interfaces to use in the config')
        if len(input_interfaces) % 2:
            raise DpdkSetup('Please specify even number of interfaces')
        wanted_interfaces = []
        sorted_pci = sorted(self.m_devices.keys())
        for interface in input_interfaces:
            dev = None
            try:
                interface = int(interface)
                if interface < 0 or interface >= len(sorted_pci):
                    raise DpdkSetup('Index of an interfaces should be in range 0:%s' % (len(sorted_pci) - 1))
                dev = self.m_devices[sorted_pci[interface]]
            except ValueError:
                for d in self.m_devices.values():
                    if interface in (d['Interface'], d['Slot'], d['Slot_str']):
                        dev = d
                        break
            if not dev:
                raise DpdkSetup('Could not find information about this interface: %s' % interface)
            if dev in wanted_interfaces:
                raise DpdkSetup('Interface %s is specified twice' % interface)
            dev['Interface_argv'] = interface
            wanted_interfaces.append(dev)

        if get_macs:
            unbound = []
            dpdk_bound = []
            for interface in wanted_interfaces:
                if 'Driver_str' not in interface:
                    unbound.append(interface['Slot'])
                elif interface.get('Driver_str') in dpdk_nic_bind.dpdk_drivers:
                    dpdk_bound.append(interface['Slot'])
            if unbound or dpdk_bound:
                for pci, info in dpdk_nic_bind.get_info_from_trex(unbound + dpdk_bound).items():
                    if pci not in self.m_devices:
                        raise DpdkSetup('Internal error: PCI %s is not found among devices' % pci)
                    self.m_devices[pci].update(info)

        return wanted_interfaces