Optional MAC address and other changes 02/73802/1
authorLuc Provoost <luc.provoost@gmail.com>
Mon, 9 Jan 2023 14:07:59 +0000 (15:07 +0100)
committerLuc Provoost <luc.provoost@gmail.com>
Mon, 9 Jan 2023 14:07:59 +0000 (15:07 +0100)
The MAC address of the dataplane interfaces in the environment file is
now optional. If not specified, the HW MAC address of that interface
will be used. When using l2 tests, the parameter will be needed anyway
and the test will fail if the MAC address is not specified.
Starting from DPDK 20.11, the EAL --pci-whitelist parameter changed into
--allow. We are now checking the DPDK version of the PROX instance to
determine which parameter to use.
For pods using cgroup v2, we are now using a different file to determine
the cpuset available to the pod.

Signed-off-by: Luc Provoost <luc.provoost@gmail.com>
Change-Id: I7a88458406b9ae3c8cae9c583cc37121d40c5073

VNFs/DPPD-PROX/helper-scripts/rapid/rapid_defaults.py
VNFs/DPPD-PROX/helper-scripts/rapid/rapid_machine.py
VNFs/DPPD-PROX/helper-scripts/rapid/rapid_parser.py

index b56fbe1..6fe8684 100644 (file)
@@ -21,7 +21,7 @@ class RapidDefaults(object):
     Class to define the test defaults
     """
     test_params = {
-        'version' : '2021.03.15', # Please do NOT change, used for debugging
+        'version' : '2023.01.09', # Please do NOT change, used for debugging
         'environment_file' : 'rapid.env', #Default string for environment
         'test_file' : 'tests/basicrapid.test', #Default string for test
         'machine_map_file' : 'machine.map', #Default string for machine map file
index f7871dc..352561d 100644 (file)
@@ -41,8 +41,12 @@ class RapidMachine(object):
         while True:
             ip_key = 'dp_ip{}'.format(index)
             mac_key = 'dp_mac{}'.format(index)
-            if ip_key in machine_params.keys() and mac_key in machine_params.keys():
-                dp_port = {'ip': machine_params[ip_key], 'mac' : machine_params[mac_key]}
+            if ip_key in machine_params.keys():
+                if mac_key in machine_params.keys():
+                    dp_port = {'ip': machine_params[ip_key],
+                            'mac' : machine_params[mac_key]}
+                else:
+                    dp_port = {'ip': machine_params[ip_key], 'mac' : None}
                 self.dp_ports.append(dict(dp_port))
                 self.dpdk_port_index.append(index - 1)
                 index += 1
@@ -55,7 +59,8 @@ class RapidMachine(object):
             PROXConfigfile =  open (self.machine_params['config_file'], 'r')
             PROXConfig = PROXConfigfile.read()
             PROXConfigfile.close()
-            self.all_tasks_for_this_cfg = set(re.findall("task\s*=\s*(\d+)",PROXConfig))
+            self.all_tasks_for_this_cfg = set(re.findall("task\s*=\s*(\d+)",
+                PROXConfig))
 
     def get_cores(self):
         return (self.machine_params['cores'])
@@ -77,18 +82,31 @@ class RapidMachine(object):
     def read_cpuset(self):
         """Read list of cpus on which we allowed to execute
         """
-        cmd = 'cat /sys/fs/cgroup/cpuset/cpuset.cpus'
+        cpu_set_file = '/sys/fs/cgroup/cpuset.cpus'
+        cmd = 'test -e {0} && echo exists'.format(cpu_set_file)
+        if (self._client.run_cmd(cmd).decode().rstrip()):
+            cmd = 'cat {}'.format(cpu_set_file)
+        else:
+            cpu_set_file = '/sys/fs/cgroup/cpuset/cpuset.cpus'
+            cmd = 'test -e {0} && echo exists'.format(cpu_set_file)
+            if (self._client.run_cmd(cmd).decode().rstrip()):
+                cmd = 'cat {}'.format(cpu_set_file)
+            else:
+                RapidLog.critical('{Cannot determine cpuset')
         cpuset_cpus = self._client.run_cmd(cmd).decode().rstrip()
-        RapidLog.debug('{} ({}): Allocated cpuset: {}'.format(self.name, self.ip, cpuset_cpus))
+        RapidLog.debug('{} ({}): Allocated cpuset: {}'.format(self.name,
+            self.ip, cpuset_cpus))
         self.cpu_mapping = self.expand_list_format(cpuset_cpus)
-        RapidLog.debug('{} ({}): Expanded cpuset: {}'.format(self.name, self.ip, self.cpu_mapping))
+        RapidLog.debug('{} ({}): Expanded cpuset: {}'.format(self.name,
+            self.ip, self.cpu_mapping))
 
         # Log CPU core mapping for user information
         cpu_mapping_str = ''
         for i in range(len(self.cpu_mapping)):
             cpu_mapping_str = cpu_mapping_str + '[' + str(i) + '->' + str(self.cpu_mapping[i]) + '], '
         cpu_mapping_str = cpu_mapping_str[:-2]
-        RapidLog.debug('{} ({}): CPU mapping: {}'.format(self.name, self.ip, cpu_mapping_str))
+        RapidLog.debug('{} ({}): CPU mapping: {}'.format(self.name, self.ip,
+            cpu_mapping_str))
 
     def remap_cpus(self, cpus):
         """Convert relative cpu ids provided as function parameter to match
@@ -108,12 +126,14 @@ class RapidMachine(object):
 
         if 'mcore' in self.machine_params.keys():
             cpus_remapped = self.remap_cpus(self.machine_params['mcore'])
-            RapidLog.debug('{} ({}): mcore {} remapped to {}'.format(self.name, self.ip, self.machine_params['mcore'], cpus_remapped))
+            RapidLog.debug('{} ({}): mcore {} remapped to {}'.format(self.name,
+                self.ip, self.machine_params['mcore'], cpus_remapped))
             self.machine_params['mcore'] = cpus_remapped
 
         if 'cores' in self.machine_params.keys():
             cpus_remapped = self.remap_cpus(self.machine_params['cores'])
-            RapidLog.debug('{} ({}): cores {} remapped to {}'.format(self.name, self.ip, self.machine_params['cores'], cpus_remapped))
+            RapidLog.debug('{} ({}): cores {} remapped to {}'.format(self.name,
+                self.ip, self.machine_params['cores'], cpus_remapped))
             self.machine_params['cores'] = cpus_remapped
 
     def devbind(self):
@@ -137,7 +157,16 @@ class RapidMachine(object):
                 LuaFile.write('local_ip{}="{}"\n'.format(index, dp_port['ip']))
                 LuaFile.write('local_hex_ip{}=convertIPToHex(local_ip{})\n'.format(index, index))
             if self.vim in ['kubernetes']:
-                LuaFile.write("eal=\"--file-prefix %s --pci-whitelist %s\"\n" % (self.name, self.machine_params['dp_pci_dev']))
+                cmd = 'pkg-config --modversion libdpdk'
+                dpdk_version = self._client.run_cmd(cmd).decode().rstrip()
+                if (dpdk_version >= '20.11.0'):
+                    allow_parameter = 'allow'
+                else:
+                    allow_parameter = 'pci-whitelist'
+                eal_line = 'eal=\"--file-prefix {} --{} {}\"\n'.format(
+                        self.name, allow_parameter,
+                        self.machine_params['dp_pci_dev'])
+                LuaFile.write(eal_line)
             else:
                 LuaFile.write("eal=\"\"\n")
             if 'mcore' in self.machine_params.keys():
@@ -150,7 +179,9 @@ class RapidMachine(object):
                 for index, dest_port in enumerate(self.machine_params['dest_ports'], start = 1):
                     LuaFile.write('dest_ip{}="{}"\n'.format(index, dest_port['ip']))
                     LuaFile.write('dest_hex_ip{}=convertIPToHex(dest_ip{})\n'.format(index, index))
-                    LuaFile.write('dest_hex_mac{}="{}"\n'.format(index , dest_port['mac'].replace(':',' ')))
+                    if dest_port['mac']:
+                        LuaFile.write('dest_hex_mac{}="{}"\n'.format(index,
+                            dest_port['mac'].replace(':',' ')))
             if 'gw_vm' in self.machine_params.keys():
                 for index, gw_ip in enumerate(self.machine_params['gw_ips'],
                         start = 1):
index ee8fa67..1a82671 100644 (file)
@@ -170,10 +170,13 @@ class RapidConfigParser(object):
                 while True: 
                     dp_ip_key = 'dp_ip{}'.format(index)
                     dp_mac_key = 'dp_mac{}'.format(index)
-                    if dp_ip_key in machines[int(machine['dest_vm'])-1].keys() and \
-                            dp_mac_key in machines[int(machine['dest_vm'])-1].keys():
-                        dp_port = {'ip': machines[int(machine['dest_vm'])-1][dp_ip_key],
-                                'mac' : machines[int(machine['dest_vm'])-1][dp_mac_key]}
+                    if dp_ip_key in machines[int(machine['dest_vm'])-1].keys():
+                        if dp_mac_key in machines[int(machine['dest_vm'])-1].keys():
+                            dp_port = {'ip': machines[int(machine['dest_vm'])-1][dp_ip_key],
+                                    'mac' : machines[int(machine['dest_vm'])-1][dp_mac_key]}
+                        else:
+                            dp_port = {'ip': machines[int(machine['dest_vm'])-1][dp_ip_key],
+                                    'mac' : None}
                         dp_ports.append(dict(dp_port))
                         index += 1
                     else: