dpdk_setup_ports.py: config creation - don't run TRex if IP config is wanted
authorYaroslav Brustinov <[email protected]>
Thu, 3 Nov 2016 13:17:49 +0000 (15:17 +0200)
committerYaroslav Brustinov <[email protected]>
Thu, 3 Nov 2016 13:18:00 +0000 (15:18 +0200)
Signed-off-by: Yaroslav Brustinov <[email protected]>
scripts/dpdk_nic_bind.py
scripts/dpdk_setup_ports.py

index a85ecb7..36d123f 100755 (executable)
@@ -609,7 +609,7 @@ def get_info_from_trex(pci_addr_list):
             pci_info_dict[pci]['TRex_Driver'] = match.group(3)
     return pci_info_dict
 
-def show_table():
+def show_table(get_macs = True):
     '''Function called when the script is passed the "--table" option.
     Similar to show_status() function, but shows more info: NUMA etc.'''
     global dpdk_drivers
@@ -620,12 +620,13 @@ def show_table():
         if devices[d].get("Driver_str") in dpdk_drivers:
             dpdk_drv.append(d)
 
-    for pci, info in get_info_from_trex(dpdk_drv).items():
-        if pci not in dpdk_drv: # sanity check, should not happen
-            print('Internal error while getting MACs of DPDK bound interfaces, unknown PCI: %s' % pci)
-            return
-        devices[pci].update(info)
-        
+    if get_macs:
+        for pci, info in get_info_from_trex(dpdk_drv).items():
+            if pci not in dpdk_drv: # sanity check, should not happen
+                print('Internal error while getting MACs of DPDK bound interfaces, unknown PCI: %s' % pci)
+                return
+            devices[pci].update(info)
+
     table = texttable.Texttable(max_width=-1)
     table.header(['ID', 'NUMA', 'PCI', 'MAC', 'Name', 'Driver', 'Linux IF', 'Active'])
     for id, pci in enumerate(sorted(devices.keys())):
index 61875cc..f85dae5 100755 (executable)
@@ -431,7 +431,7 @@ Other network devices
     # input: list of different descriptions of interfaces: index, pci, name etc.
     # Binds to dpdk wanted interfaces, not bound to any driver.
     # output: list of maps of devices in dpdk_* format (self.m_devices.values())
-    def _get_wanted_interfaces(self, input_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):
@@ -459,26 +459,23 @@ Other network devices
             dev['Interface_argv'] = interface
             wanted_interfaces.append(dev)
 
-        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)
+        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
 
     def do_create(self):
-        # gather info about NICS from dpdk_nic_bind.py
-        if not self.m_devices:
-            self.run_dpdk_lspci()
-        wanted_interfaces = self._get_wanted_interfaces(map_driver.args.create_interfaces)
 
         ips = map_driver.args.ips
         def_gws = map_driver.args.def_gws
@@ -495,7 +492,7 @@ Other network devices
                 raise DpdkSetup("If specifying ips, must specify also def-gws")
             if dest_macs:
                 raise DpdkSetup("If specifying ips, should not specify dest--macs")
-            if len(ips) != len(def_gws) or len(ips) != len(wanted_interfaces):
+            if len(ips) != len(def_gws) or len(ips) != len(map_driver.args.create_interfaces):
                 raise DpdkSetup("Number of given IPs should equal number of given def-gws and number of interfaces")
         else:
             if dest_macs:
@@ -503,6 +500,11 @@ Other network devices
             else:
                 ip_config = True
 
+        # gather info about NICS from dpdk_nic_bind.py
+        if not self.m_devices:
+            self.run_dpdk_lspci()
+        wanted_interfaces = self._get_wanted_interfaces(map_driver.args.create_interfaces, get_macs = not ip_config)
+
         for i, interface in enumerate(wanted_interfaces):
             dual_index = i + 1 - (i % 2) * 2
             if ip_config:
@@ -548,9 +550,18 @@ Other network devices
                 ignore_numa = True
             else:
                 sys.exit(1)
+
+        if map_driver.args.force_macs:
+            ip_based = False
+        elif dpdk_nic_bind.confirm("By default, IP based configuration file will be created. Do you want to use MAC based config? (y/N)"):
+            ip_based = False
+        else:
+            ip_based = True
+            ip_addr_digit = 1
+
         if not self.m_devices:
             self.run_dpdk_lspci()
-        dpdk_nic_bind.show_table()
+        dpdk_nic_bind.show_table(get_macs = not ip_based)
         print('Please choose even number of interfaces from the list above, either by ID , PCI or Linux IF')
         print('Stateful will use order of interfaces: Client1 Server1 Client2 Server2 etc. for flows.')
         print('Stateless can be in any order.')
@@ -579,14 +590,6 @@ Other network devices
                 if not dpdk_nic_bind.confirm('Ignore and continue? (y/N): '):
                     sys.exit(1)
 
-        if map_driver.args.force_macs:
-            ip_based = False
-        elif dpdk_nic_bind.confirm("By default, IP based configuration file will be created. Do you want to change to MAC based config? (y/N)"):
-            ip_based = False
-        else:
-            ip_based = True
-            ip_addr_digit = 1
-
         for i, interface in enumerate(wanted_interfaces):
             if not ip_based:
                 if 'MAC' not in interface: