NFVBENCH-190: Add a 'i40e_mixed' option, trex accepts other i40e driven ports to...
[nfvbench.git] / nfvbench / traffic_server.py
index 52ec2f1..629cb3d 100644 (file)
@@ -34,12 +34,27 @@ class TRexTrafficServer(TrafficServer):
         assert len(contents) == 1
         self.trex_dir = os.path.join(trex_base_dir, contents[0])
 
+    def __apply_trex_patches(self):
+        parent_dir = os.path.dirname(os.path.realpath(__file__))
+        patches_dir = os.path.join(parent_dir, "trex_patches")
+        patches = os.listdir(patches_dir)
+        for patch in patches:
+            patch = os.path.join(patches_dir, patch)
+            command = (
+                "patch --directory=" + self.trex_dir + " --strip=0"
+                " --forward --no-backup-if-mismatch --reject-file=-"
+                " --force --input=" + patch + " >&-")
+            os.system(command)
+
     def run_server(self, generator_config, filename='/etc/trex_cfg.yaml'):
         """Run TRex server for specified traffic profile.
 
         :param traffic_profile: traffic profile object based on config file
         :param filename: path where to save TRex config file
         """
+        # in order to allow for customized behaviors, let's apply some patches
+        # this scheme keeps acceptable since we have only simple modifications
+        self.__apply_trex_patches()
         cfg = self.__save_config(generator_config, filename)
         cores = generator_config.cores
         vtep_vlan = generator_config.gen_config.get('vtep_vlan')
@@ -53,10 +68,21 @@ class TRexTrafficServer(TrafficServer):
         # --unbind-unused-ports: for NIC that have more than 2 ports such as Intel X710
         # this will instruct trex to unbind all ports that are unused instead of
         # erroring out with an exception (i40e only)
+        # Try: --ignore-528-issue -> neither unbind nor exit with error,
+        #                            just proceed cause it might work!
+        # Note that force unbinding is probably a bad choice:
+        # we can't assume for sure that other ports are "unused".
+        # The default TRex behaviour - exit - is indeed a safer option;
+        # a message informs about the ports that should be unbound.
+        i40e_opt = ("--ignore-528-issue" if
+                    generator_config.config.i40e_mixed == 'ignore' else
+                    "--unbind-unused-ports" if
+                    generator_config.config.i40e_mixed == 'unbind' else "")
         cmd = ['nohup', '/bin/bash', '-c',
                './t-rex-64 -i -c {} --iom 0 --no-scapy-server '
-               '--unbind-unused-ports --close-at-end {} {} '
+               '--close-at-end {} {} {} '
                '{} {} --cfg {} &> /tmp/trex.log & disown'.format(cores, sw_mode,
+                                                                 i40e_opt,
                                                                  vlan_opt,
                                                                  hdrh_opt,
                                                                  mbuf_opt, cfg)]
@@ -91,7 +117,7 @@ class TRexTrafficServer(TrafficServer):
         # parameter, specified as one of the starting command line
         # arguments, has been modified since the last launch.
         # Hence we add some extra fields to the config file
-        # (nb_cores, use_vlan, mbuf_factor, hdrh)
+        # (nb_cores, use_vlan, mbuf_factor, i40e_mixed, hdrh)
         # which will serve as a memory between runs -
         # while being actually ignored by the T-Rex server.
 
@@ -108,6 +134,7 @@ class TRexTrafficServer(TrafficServer):
             hdrh       : {hdrh}
             nb_cores   : {nb_cores}
             use_vlan   : {use_vlan}
+            i40e_mixed : {i40e_mixed}
           interfaces   : [{ifs}]""".format(
             zmq_pub_port=generator_config.zmq_pub_port,
             zmq_rpc_port=generator_config.zmq_rpc_port,
@@ -119,6 +146,7 @@ class TRexTrafficServer(TrafficServer):
             nb_cores=generator_config.cores,
             use_vlan=generator_config.gen_config.get('vtep_vlan') or
             generator_config.vlan_tagging,
+            i40e_mixed=generator_config.config.i40e_mixed,
             ifs=ifs)
 
         if hasattr(generator_config, 'mbuf_64') and generator_config.mbuf_64: