Added ability to choose the version of iperf to test for multi-threading

The QA engineer can choose now the utility (version) of the iperf tool
to verify the multiple threads test cases.
Set 'iperf' to use 'iperf' tool (v2).
Set 'iperf3' to use iperf v3 tool.

Change-Id: Ie11fb6d148779b53183f362b27847e9880af3542
diff --git a/README.md b/README.md
index 51de507..bfc8fde 100644
--- a/README.md
+++ b/README.md
@@ -48,6 +48,8 @@
 | internet_at_vms | 'true' | In case True, the Internet is present at VMs, and the tests are able to install iperf3 by _apt update; apt install iperf3_. In case VMs have no Internet, set 'false' and the iperf3 will be installed from offline *.deb packages. |
 | iperf_deb_package_dir_path | /opt/packages/ | Path to the local directory where the iperf3 *.deb packages are present. In the toolset offline images they are located at /opt/packages. Or you can download iperf3 deb package and its dependencies and put them at some custom folder. |
 | iperf_time | 60 | iperf3 -t option value: time in seconds to transmit for (iperf -t option). |
+| multiple_threads_number | 10 | Number of iperf/iperf3 parallel client threads to run (iperf3/iperf -P option value) |
+| multiple_threads_iperf_utility | 'iperf3' | The tool for bandwidth measurements. Options to set: 'iperf' to use v2 and 'iperf3' to use v3. Eventually, this is the name of the utility that is installed at Ubuntu VMs from apt. |
 
  In case _internet_at_vms=false_, please make sure that _iperf_deb_package_dir_path_ is set correctly and has iperf3 deb package and its dependencies.
 
diff --git a/global_config.yaml b/global_config.yaml
index d47e11b..7e2105a 100644
--- a/global_config.yaml
+++ b/global_config.yaml
@@ -17,5 +17,6 @@
 iperf_deb_package_dir_path: '/opt/packages/'
 iperf_time: 60 # time in seconds to transmit for (iperf -t option)
 multiple_threads_number: 10
+multiple_threads_iperf_utility: "iperf3" # set "iperf" for v2, "iperf3" for v3
 ssh_timeout: 500
 skipped_nodes: []
diff --git a/tests/test_vm2vm.py b/tests/test_vm2vm.py
index 9c6d107..1b81268 100644
--- a/tests/test_vm2vm.py
+++ b/tests/test_vm2vm.py
@@ -35,6 +35,8 @@
     private_key = os_resources['keypair'].private_key
     ssh_timeout = int(config.get('ssh_timeout', 500))
     threads = int(config.get('multiple_threads_number', 10))
+    iperf_utility = config.get('multiple_threads_iperf_utility', 'iperf3')
+    utils.check_iperf_utility(iperf_utility)
     result_table = Texttable(max_width=120)
 
     try:
@@ -142,13 +144,22 @@
         logger.info("Doing 'VM to VM in same tenant on different HW nodes "
                     "via Private IP, {} threads' measurement..."
                     "".format(threads))
-        result3 = transport1.exec_command(
-            'iperf -c {} -P {} -t {} | tail -n 1'.format(
-                vm_info[2]['private_address'], threads, iperf_time))
-        res3 = (b" ".join(result3.split()[-2::])).decode('utf-8')
+        if iperf_utility == "iperf3":
+            result3 = transport1.exec_command(
+                '{} -c {} -P {} -t {} | grep sender | tail -n 1'
+                ''.format(iperf_utility, vm_info[2]['private_address'],
+                          threads, iperf_time))
+            res3 = (b" ".join(result3.split()[-4:-2:])).decode('utf-8')
+        else:
+            iperf_utility = "iperf"
+            result3 = transport1.exec_command(
+                '{} -c {} -P {} -t {} | tail -n 1'.format(iperf_utility,
+                    vm_info[2]['private_address'], threads, iperf_time))
+            res3 = (b" ".join(result3.split()[-2::])).decode('utf-8')
         logger.info("Result #3 is {}".format(res3))
         table_rows.append(['VM to VM in same tenant on different HW nodes '
-                           'via Private IP, {} threads; iperf (v2)'.format(threads),
+                           'via Private IP, {} threads; {}'
+                           ''.format(threads, iperf_utility),
                            "{}".format(pair[0]),
                            "{}".format(pair[1]),
                            "{}, {}".format(mtus[0], mtus[2]),
diff --git a/utils/__init__.py b/utils/__init__.py
index 8b04bab..8cfe897 100644
--- a/utils/__init__.py
+++ b/utils/__init__.py
@@ -72,3 +72,13 @@
                 global_config[param] = os.environ[param]
 
     return global_config
+
+
+def check_iperf_utility(actual_iperf_utility):
+    valid_values = ["iperf", "iperf3"]
+    if actual_iperf_utility not in valid_values:
+        raise BaseException("The iperf utility for multiple threads test case "
+                            "is not correct. Valid value is one of {}. Actual "
+                            "value is {}. Please set the correct value in "
+                            "global_config.yaml:multiple_threads_iperf_utility"
+                            "".format(valid_values, actual_iperf_utility))