Repository: nokia/moler

Issue:
wrong units recalculation in iperf
iperf `_normalise_units()` assumes that `MBits/sec` means `1024*1024` bits

In reality Mega means here `1000*1000`

Discussion:

Patch:
diff --git a/moler/cmd/__init__.py b/moler/cmd/__init__.py
index 13cbf39d..7784a9a0 100644
--- a/moler/cmd/__init__.py
+++ b/moler/cmd/__init__.py
@@ -37,5 +37,8 @@ class RegexHelper(object):
     def group(self, number):
         return self._match.group(number)
 
+    def groups(self):
+        return self._match.groups()
+
     def groupdict(self):
         return self._match.groupdict()
diff --git a/moler/cmd/unix/iperf.py b/moler/cmd/unix/iperf.py
index 67c7cdea..2741ad0c 100644
--- a/moler/cmd/unix/iperf.py
+++ b/moler/cmd/unix/iperf.py
@@ -16,6 +16,28 @@ import re
 
 
 class Iperf(GenericUnixCommand):
+    """
+    Run iperf command and return its statistics
+
+    Statistics are given as list of dicts like::
+
+      {'Interval':                 '0.0- 1.0 sec',
+       'Transfer Raw':             '1.17 MBytes',
+       'Transfer':                 1226833,
+       'Bandwidth Raw':            '9.84 Mbits/sec',
+       'Bandwidth':                1230000,
+       'Jitter':                   '1.830 ms',
+       'Lost_vs_Total_Datagrams': '0/ 837   (0%)'}
+
+    Above dict represents iperf output like::
+
+      [ ID]   Interval         Transfer        Bandwidth         Jitter        Lost/Total Datagrams
+      [904]   0.0- 1.0 sec   1.17 MBytes   9.84 Mbits/sec   1.830 ms   0/ 837   (0%)
+
+    Please note that numeric values are normalized to Bytes:
+    - Transfer is in Bytes
+    - Bandwith is in Bytes/sec
+    """
     def __init__(self, connection, options, prompt=None, newline_chars=None, runner=None):
         super(Iperf, self).__init__(connection=connection, prompt=prompt, newline_chars=newline_chars, runner=runner)
         self.options = options
@@ -24,13 +46,18 @@ class Iperf(GenericUnixCommand):
 
         # private values
         self._connection_dict = dict()
-        self._list_of_connections = dict()
         self._converter_helper = ConverterHelper()
 
     def build_command_string(self):
         cmd = 'iperf ' + str(self.options)
         return cmd
 
+    @property
+    def protocol(self):
+        if self.options.startswith('-u') or (' -u' in self.options) or ('--udp' in self.options):
+            return 'udp'
+        return 'tcp'
+
     def on_new_line(self, line, is_full_line):
         if is_full_line:
             try:
@@ -50,6 +77,7 @@ class Iperf(GenericUnixCommand):
             self.set_exception(CommandFailure(self, "ERROR: {}".format(self._regex_helper.group("FAILURE_MSG"))))
             raise ParsingDone
 
+    # [904] local 10.1.1.1 port 5001 connected with 10.6.2.5 port 32781
     _re_connection_name_and_id = re.compile(r"(?P<ID>\[\s*\d*\])\s*(?P<ID_NAME>.*port\s*\d*\s*connected with.*)")
 
     def _parse_connection_name_and_id(self, line):
@@ -60,25 +88,39 @@ class Iperf(GenericUnixCommand):
             self._connection_dict.update(connection_dict)
             raise ParsingDone
 
-    _re_headers = re.compile(r"(?P<HEADERS>\[\s+ID\].*)")
+    # iperf output for: udp client, tcp client, tcp server
+    # [ ID] Interval       Transfer     Bandwidth
+
+    # iperf output for: udp server
+    # [ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
+    _re_headers = re.compile(r"\[\s+ID\]\s+Interval\s+Transfer\s+Bandwidth")
 
     def _parse_headers(self, line):
         if self._regex_helper.search_compiled(Iperf._re_headers, line):
-            matched = line.split()[2:]
-            self._list_of_connections = [header.strip() for header in matched]
+            # ignore headers
             raise ParsingDone
 
+    # udp:
+    # [ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
+    # [  3]  0.0- 1.0 sec   612 KBytes  5010 Kbits/sec   0.022 ms    0/  426 (0%)
+    #
+    # tcp:
+    # [ ID] Interval       Transfer     Bandwidth
+    # [  4]  0.0- 1.0 sec   979 KBytes  8020 Kbits/sec
     _re_connection_info = re.compile(r"(?P<CONNECTION_ID>\[\s*\d*\])\s*(?P<CONNECTION_REPORT>.*)")
+    _re_ci = r"(?P<ID>\[\s*\d*\])\s+(?P<Interval>\d+.+sec)\s+(?P<Transfer>[\d\.]+\s+\w+)\s+(?P<Bandwidth>[\d\.]+\s+\w+/sec)"
+    _re_ci_udp_svr = _re_ci + r"\s+(?P<Jitter>\d+\.\d+\s\w+)\s+(?P<Lost_vs_Total_Datagrams>\d+/\s*\d+\s*\([\d\.]+\%\))"
+    _re_iperf_record = re.compile(_re_ci)
+    _re_iperf_record_udp_svr = re.compile(_re_ci_udp_svr)
 
     def _parse_connection_info(self, line):
-        if self._regex_helper.search_compiled(Iperf._re_connection_info, line):
-            connection_id = self._regex_helper.group("CONNECTION_ID")
-            connection_report = self._regex_helper.group("CONNECTION_REPORT").split('  ')
-            connection_report = [report.strip() for report in connection_report]
+        regex_found = self._regex_helper.search_compiled
+        if regex_found(Iperf._re_iperf_record_udp_svr, line) or regex_found(Iperf._re_iperf_record, line):
+            iperf_record = self._regex_helper.groupdict()
+            connection_id = iperf_record.pop("ID")
             connection_name = self._connection_dict[connection_id]
-            info_dict = dict(zip(self._list_of_connections, connection_report))
-            self._normalise_units(connection_report, info_dict)
-            self._update_current_ret(connection_name, info_dict)
+            normalized_iperf_record = self._normalize_to_bytes(iperf_record)
+            self._update_current_ret(connection_name, normalized_iperf_record)
             raise ParsingDone
 
     def _update_current_ret(self, connection_name, info_dict):
@@ -88,6 +130,9 @@ class Iperf(GenericUnixCommand):
             connection_dict = {connection_name: [info_dict]}
             self.current_ret['CONNECTIONS'].update(connection_dict)
 
+    # [  5] Sent 2552 datagrams
+    # [  5] Server Report:
+    # ------------------------------------------------------------
     _re_ornaments = re.compile(r"(?P<ORNAMENTS>----*|\[\s*ID\].*)", re.IGNORECASE)
 
     def _parse_connection_headers(self, line):
@@ -95,15 +140,21 @@ class Iperf(GenericUnixCommand):
             self.current_ret['INFO'].append(line.strip())
             raise ParsingDone
 
-    def _normalise_units(self, report, dictionary_to_update):
-        for (index, item) in enumerate(report):
-            if 'Bytes' in item or 'bits' in item:
-                header = self._list_of_connections[index]
-                raw_bites = self._converter_helper.to_bytes(item)[0]
-                new_column_title = header + " Raw"
-                read_bites = dictionary_to_update[header]
-                dictionary_to_update[header] = raw_bites
-                dictionary_to_update.update({new_column_title: read_bites})
+    def _normalize_to_bytes(self, input_dict):
+        new_dict = {}
+        for (key, raw_value) in input_dict.items():
+            if 'Bytes' in raw_value:  # iperf MBytes means 1024 * 1024 Bytes - see iperf.fr/iperf-doc.php
+                new_dict[key + " Raw"] = raw_value
+                value_in_bytes, _, _ = self._converter_helper.to_bytes(raw_value)
+                new_dict[key] = value_in_bytes
+            elif 'bits' in raw_value:  # iperf Mbits means 1000 * 1000 bits - see iperf.fr/iperf-doc.php
+                new_dict[key + " Raw"] = raw_value
+                value_in_bits, _, _ = self._converter_helper.to_bytes(raw_value, binary_multipliers=False)
+                value_in_bytes = value_in_bits // 8
+                new_dict[key] = value_in_bytes
+            else:
+                new_dict[key] = raw_value
+        return new_dict
 
 
 COMMAND_OUTPUT_basic_client = """
@@ -134,27 +185,27 @@ COMMAND_KWARGS_basic_client = {
 COMMAND_RESULT_basic_client = {
     'CONNECTIONS':
         {'local 192.168.0.102 port 49597 connected with 192.168.0.100 port 5001': [
-            {'Bandwidth Raw': '240 Mbits/sec', 'Bandwidth': 251658240, 'Transfer Raw': '28.6 MBytes',
+            {'Bandwidth Raw': '240 Mbits/sec', 'Bandwidth': 30000000, 'Transfer Raw': '28.6 MBytes',
              'Transfer': 29989273, 'Interval': '0.0- 1.0 sec'},
-            {'Bandwidth Raw': '217 Mbits/sec', 'Bandwidth': 227540992, 'Transfer Raw': '25.9 MBytes',
+            {'Bandwidth Raw': '217 Mbits/sec', 'Bandwidth': 27125000, 'Transfer Raw': '25.9 MBytes',
              'Transfer': 27158118, 'Interval': '1.0- 2.0 sec'},
-            {'Bandwidth Raw': '222 Mbits/sec', 'Bandwidth': 232783872, 'Transfer Raw': '26.5 MBytes',
+            {'Bandwidth Raw': '222 Mbits/sec', 'Bandwidth': 27750000, 'Transfer Raw': '26.5 MBytes',
              'Transfer': 27787264, 'Interval': '2.0- 3.0 sec'},
-            {'Bandwidth Raw': '223 Mbits/sec', 'Bandwidth': 233832448, 'Transfer Raw': '26.6 MBytes',
+            {'Bandwidth Raw': '223 Mbits/sec', 'Bandwidth': 27875000, 'Transfer Raw': '26.6 MBytes',
              'Transfer': 27892121, 'Interval': '3.0- 4.0 sec'},
-            {'Bandwidth Raw': '218 Mbits/sec', 'Bandwidth': 228589568, 'Transfer Raw': '26.0 MBytes',
+            {'Bandwidth Raw': '218 Mbits/sec', 'Bandwidth': 27250000, 'Transfer Raw': '26.0 MBytes',
              'Transfer': 27262976, 'Interval': '4.0- 5.0 sec'},
-            {'Bandwidth Raw': '220 Mbits/sec', 'Bandwidth': 230686720, 'Transfer Raw': '26.2 MBytes',
+            {'Bandwidth Raw': '220 Mbits/sec', 'Bandwidth': 27500000, 'Transfer Raw': '26.2 MBytes',
              'Transfer': 27472691, 'Interval': '5.0- 6.0 sec'},
-            {'Bandwidth Raw': '224 Mbits/sec', 'Bandwidth': 234881024, 'Transfer Raw': '26.8 MBytes',
+            {'Bandwidth Raw': '224 Mbits/sec', 'Bandwidth': 28000000, 'Transfer Raw': '26.8 MBytes',
              'Transfer': 28101836, 'Interval': '6.0- 7.0 sec'},
-            {'Bandwidth Raw': '218 Mbits/sec', 'Bandwidth': 228589568, 'Transfer Raw': '26.0 MBytes',
+            {'Bandwidth Raw': '218 Mbits/sec', 'Bandwidth': 27250000, 'Transfer Raw': '26.0 MBytes',
              'Transfer': 27262976, 'Interval': '7.0- 8.0 sec'},
-            {'Bandwidth Raw': '216 Mbits/sec', 'Bandwidth': 226492416, 'Transfer Raw': '25.8 MBytes',
+            {'Bandwidth Raw': '216 Mbits/sec', 'Bandwidth': 27000000, 'Transfer Raw': '25.8 MBytes',
              'Transfer': 27053260, 'Interval': '8.0- 9.0 sec'},
-            {'Bandwidth Raw': '221 Mbits/sec', 'Bandwidth': 231735296, 'Transfer Raw': '26.4 MBytes',
+            {'Bandwidth Raw': '221 Mbits/sec', 'Bandwidth': 27625000, 'Transfer Raw': '26.4 MBytes',
              'Transfer': 27682406, 'Interval': '9.0-10.0 sec'},
-            {'Bandwidth Raw': '222 Mbits/sec', 'Bandwidth': 232783872, 'Transfer Raw': '265 MBytes',
+            {'Bandwidth Raw': '222 Mbits/sec', 'Bandwidth': 27750000, 'Transfer Raw': '265 MBytes',
              'Transfer': 277872640, 'Interval': '0.0-10.0 sec'}]},
     'INFO': ['Client connecting to 10.1.1.1, TCP port 5001', 'TCP window size: 16384 Byte (default)']
 }
@@ -189,96 +240,371 @@ COMMAND_KWARGS_basic_server = {
 COMMAND_RESULT_basic_server = {
     'CONNECTIONS': {
         'local 10.1.1.1 port 5001 connected with 10.6.2.5 port 32781': [{'Bandwidth Raw': '9.84 Mbits/sec',
-                                                                         'Bandwidth': 10317987,
-                                                                         'Datagrams': '(0%)',
+                                                                         'Bandwidth': 1230000,
                                                                          'Interval': '0.0- 1.0 sec',
                                                                          'Jitter': '1.830 ms',
-                                                                         'Lost/Total': '0/ 837',
+                                                                         'Lost_vs_Total_Datagrams': '0/ 837   (0%)',
                                                                          'Transfer Raw': '1.17 MBytes',
                                                                          'Transfer': 1226833},
                                                                         {'Bandwidth Raw': '9.94 Mbits/sec',
-                                                                         'Bandwidth': 10422845,
-                                                                         'Datagrams': '(0.59%)',
+                                                                         'Bandwidth': 1242500,
                                                                          'Interval': '1.0- 2.0 sec',
                                                                          'Jitter': '1.846 ms',
-                                                                         'Lost/Total': '5/ 850',
+                                                                         'Lost_vs_Total_Datagrams': '5/ 850   (0.59%)',
                                                                          'Transfer Raw': '1.18 MBytes',
                                                                          'Transfer': 1237319},
                                                                         {'Bandwidth Raw': '9.98 Mbits/sec',
-                                                                         'Bandwidth': 10464788,
-                                                                         'Datagrams': '(0.24%)',
+                                                                         'Bandwidth': 1247500,
                                                                          'Interval': '2.0- 3.0 sec',
                                                                          'Jitter': '1.802 ms',
-                                                                         'Lost/Total': '2/ 851',
+                                                                         'Lost_vs_Total_Datagrams': '2/ 851   (0.24%)',
                                                                          'Transfer Raw': '1.19 MBytes',
                                                                          'Transfer': 1247805},
                                                                         {'Bandwidth Raw': '10.0 Mbits/sec',
-                                                                         'Bandwidth': 10485760,
-                                                                         'Datagrams': '(0%)',
+                                                                         'Bandwidth': 1250000,
                                                                          'Interval': '3.0- 4.0 sec',
                                                                          'Jitter': '1.830 ms',
-                                                                         'Lost/Total': '0/ 850',
+                                                                         'Lost_vs_Total_Datagrams': '0/ 850   (0%)',
                                                                          'Transfer Raw': '1.19 MBytes',
                                                                          'Transfer': 1247805},
                                                                         {'Bandwidth Raw': '9.98 Mbits/sec',
-                                                                         'Bandwidth': 10464788,
-                                                                         'Datagrams': '(0.12%)',
+                                                                         'Bandwidth': 1247500,
                                                                          'Interval': '4.0- 5.0 sec',
                                                                          'Jitter': '1.846 ms',
-                                                                         'Lost/Total': '1/ 850',
+                                                                         'Lost_vs_Total_Datagrams': '1/ 850   (0.12%)',
                                                                          'Transfer Raw': '1.19 MBytes',
                                                                          'Transfer': 1247805},
                                                                         {'Bandwidth Raw': '10.0 Mbits/sec',
-                                                                         'Bandwidth': 10485760,
-                                                                         'Datagrams': '(0%)',
+                                                                         'Bandwidth': 1250000,
                                                                          'Interval': '5.0- 6.0 sec',
                                                                          'Jitter': '1.806 ms',
-                                                                         'Lost/Total': '0/ 851',
+                                                                         'Lost_vs_Total_Datagrams': '0/ 851   (0%)',
                                                                          'Transfer Raw': '1.19 MBytes',
                                                                          'Transfer': 1247805},
                                                                         {'Bandwidth Raw': '8.87 Mbits/sec',
-                                                                         'Bandwidth': 9300869,
-                                                                         'Datagrams': '(0.13%)',
+                                                                         'Bandwidth': 1108750,
                                                                          'Interval': '6.0- 7.0 sec',
                                                                          'Jitter': '1.803 ms',
-                                                                         'Lost/Total': '1/ 755',
+                                                                         'Lost_vs_Total_Datagrams': '1/ 755   (0.13%)',
                                                                          'Transfer Raw': '1.06 MBytes',
                                                                          'Transfer': 1111490},
                                                                         {'Bandwidth Raw': '10.0 Mbits/sec',
-                                                                         'Bandwidth': 10485760,
-                                                                         'Datagrams': '(0%)',
+                                                                         'Bandwidth': 1250000,
                                                                          'Interval': '7.0- 8.0 sec',
                                                                          'Jitter': '1.831 ms',
-                                                                         'Lost/Total': '0/ 850',
+                                                                         'Lost_vs_Total_Datagrams': '0/ 850   (0%)',
                                                                          'Transfer Raw': '1.19 MBytes',
                                                                          'Transfer': 1247805},
                                                                         {'Bandwidth Raw': '10.0 Mbits/sec',
-                                                                         'Bandwidth': 10485760,
-                                                                         'Datagrams': '(0%)',
+                                                                         'Bandwidth': 1250000,
                                                                          'Interval': '8.0- 9.0 sec',
                                                                          'Jitter': '1.841 ms',
-                                                                         'Lost/Total': '0/ 850',
+                                                                         'Lost_vs_Total_Datagrams': '0/ 850   (0%)',
                                                                          'Transfer Raw': '1.19 MBytes',
                                                                          'Transfer': 1247805},
                                                                         {'Bandwidth Raw': '10.0 Mbits/sec',
-                                                                         'Bandwidth': 10485760,
-                                                                         'Datagrams': '(0%)',
+                                                                         'Bandwidth': 1250000,
                                                                          'Interval': '9.0-10.0 sec',
                                                                          'Jitter': '1.801 ms',
-                                                                         'Lost/Total': '0/ 851',
+                                                                         'Lost_vs_Total_Datagrams': '0/ 851   (0%)',
                                                                          'Transfer Raw': '1.19 MBytes',
                                                                          'Transfer': 1247805},
                                                                         {'Bandwidth Raw': '9.86 Mbits/sec',
-                                                                         'Bandwidth': 10338959,
-                                                                         'Datagrams': '(0.11%)',
+                                                                         'Bandwidth': 1232500,
                                                                          'Interval': '0.0-10.0 sec',
                                                                          'Jitter': '2.618 ms',
-                                                                         'Lost/Total': '9/ 8409',
+                                                                         'Lost_vs_Total_Datagrams': '9/ 8409  (0.11%)',
                                                                          'Transfer Raw': '11.8 MBytes',
                                                                          'Transfer': 12373196}]},
     'INFO': ['Server listening on UDP port 5001', 'Receiving 1470 byte datagrams',
              'UDP buffer size: 8.00 KByte (default)']}
 
+
+COMMAND_OUTPUT_bidirectional_udp_client = """
+ute@IAV-KRA-TL160:~$ iperf -c 10.89.47.191 -u -p 5016 -f k -i 1.0 -t 6.0 --dualtest -b 5000.0k
+------------------------------------------------------------
+Server listening on UDP port 5016
+Receiving 1470 byte datagrams
+UDP buffer size: 1024 KByte (default)
+------------------------------------------------------------
+------------------------------------------------------------
+Client connecting to 10.89.47.191, UDP port 5016
+Sending 1470 byte datagrams, IPG target: 2352.00 us (kalman adjust)
+UDP buffer size: 1024 KByte (default)
+------------------------------------------------------------
+[  4] local 10.89.47.150 port 56262 connected with 10.89.47.191 port 5016
+[  3] local 10.89.47.150 port 5016 connected with 10.89.47.191 port 47384
+[ ID] Interval       Transfer     Bandwidth
+[  4]  0.0- 1.0 sec   613 KBytes  5022 Kbits/sec
+[  3]  0.0- 1.0 sec   612 KBytes  5010 Kbits/sec   0.011 ms    0/  426 (0%)
+[  4]  1.0- 2.0 sec   610 KBytes  4998 Kbits/sec
+[  3]  1.0- 2.0 sec   610 KBytes  4998 Kbits/sec   0.012 ms    0/  425 (0%)
+[  4]  2.0- 3.0 sec   610 KBytes  4998 Kbits/sec
+[  3]  2.0- 3.0 sec   610 KBytes  4998 Kbits/sec   0.017 ms    0/  425 (0%)
+[  4]  3.0- 4.0 sec   610 KBytes  4998 Kbits/sec
+[  3]  3.0- 4.0 sec   610 KBytes  4998 Kbits/sec   0.019 ms    0/  425 (0%)
+[  4]  4.0- 5.0 sec   610 KBytes  4998 Kbits/sec
+[  3]  4.0- 5.0 sec   610 KBytes  4998 Kbits/sec   0.014 ms    0/  425 (0%)
+[  4]  5.0- 6.0 sec   610 KBytes  4998 Kbits/sec
+[  4]  0.0- 6.0 sec  3664 KBytes  5000 Kbits/sec
+[  4] Sent 2552 datagrams
+[  3]  5.0- 6.0 sec   612 KBytes  5010 Kbits/sec   0.017 ms    0/  426 (0%)
+[  3]  0.0- 6.0 sec  3664 KBytes  5000 Kbits/sec   0.017 ms    0/ 2552 (0%)
+[  4] Server Report:
+[  4]  0.0- 6.0 sec  3664 KBytes  5000 Kbits/sec   0.017 ms    0/ 2552 (0%)
+ute@IAV-KRA-TL160:~$"""
+
+
+COMMAND_KWARGS_bidirectional_udp_client = {
+    'options': '-c 10.89.47.191 -u -p 5016 -f k -i 1.0 -t 6.0 --dualtest -b 5000.0k'
+}
+
+
+COMMAND_RESULT_bidirectional_udp_client = {
+    'CONNECTIONS': {
+        'local 10.89.47.150 port 56262 connected with 10.89.47.191 port 5016': [{'Transfer': 627712,
+                                                                                 'Bandwidth': 627750,
+                                                                                 'Transfer Raw': '613 KBytes',
+                                                                                 'Bandwidth Raw': '5022 Kbits/sec',
+                                                                                 'Interval': '0.0- 1.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '1.0- 2.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '2.0- 3.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '3.0- 4.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '4.0- 5.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '5.0- 6.0 sec'},
+                                                                                {'Transfer': 3751936,
+                                                                                 'Bandwidth': 625000,
+                                                                                 'Transfer Raw': '3664 KBytes',
+                                                                                 'Bandwidth Raw': '5000 Kbits/sec',
+                                                                                 'Interval': '0.0- 6.0 sec'},
+                                                                                {'Transfer Raw': '3664 KBytes',
+                                                                                 'Jitter': '0.017 ms',
+                                                                                 'Transfer': 3751936,
+                                                                                 'Interval': '0.0- 6.0 sec',
+                                                                                 'Bandwidth': 625000,
+                                                                                 'Lost_vs_Total_Datagrams': '0/ 2552 (0%)',
+                                                                                 'Bandwidth Raw': '5000 Kbits/sec'}],
+        'local 10.89.47.150 port 5016 connected with 10.89.47.191 port 47384': [{'Transfer Raw': '612 KBytes',
+                                                                                 'Jitter': '0.011 ms',
+                                                                                 'Transfer': 626688,
+                                                                                 'Interval': '0.0- 1.0 sec',
+                                                                                 'Bandwidth': 626250,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  426 (0%)',
+                                                                                 'Bandwidth Raw': '5010 Kbits/sec'},
+                                                                                {'Transfer Raw': '610 KBytes',
+                                                                                 'Jitter': '0.012 ms',
+                                                                                 'Transfer': 624640,
+                                                                                 'Interval': '1.0- 2.0 sec',
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  425 (0%)',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec'},
+                                                                                {'Transfer Raw': '610 KBytes',
+                                                                                 'Jitter': '0.017 ms',
+                                                                                 'Transfer': 624640,
+                                                                                 'Interval': '2.0- 3.0 sec',
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  425 (0%)',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec'},
+                                                                                {'Transfer Raw': '610 KBytes',
+                                                                                 'Jitter': '0.019 ms',
+                                                                                 'Transfer': 624640,
+                                                                                 'Interval': '3.0- 4.0 sec',
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  425 (0%)',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec'},
+                                                                                {'Transfer Raw': '610 KBytes',
+                                                                                 'Jitter': '0.014 ms',
+                                                                                 'Transfer': 624640,
+                                                                                 'Interval': '4.0- 5.0 sec',
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  425 (0%)',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec'},
+                                                                                {'Transfer Raw': '612 KBytes',
+                                                                                 'Jitter': '0.017 ms',
+                                                                                 'Transfer': 626688,
+                                                                                 'Interval': '5.0- 6.0 sec',
+                                                                                 'Bandwidth': 626250,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  426 (0%)',
+                                                                                 'Bandwidth Raw': '5010 Kbits/sec'},
+                                                                                {'Transfer Raw': '3664 KBytes',
+                                                                                 'Jitter': '0.017 ms',
+                                                                                 'Transfer': 3751936,
+                                                                                 'Interval': '0.0- 6.0 sec',
+                                                                                 'Bandwidth': 625000,
+                                                                                 'Lost_vs_Total_Datagrams': '0/ 2552 (0%)',
+                                                                                 'Bandwidth Raw': '5000 Kbits/sec'}]},
+    'INFO': ['Server listening on UDP port 5016', 'Receiving 1470 byte datagrams',
+             'UDP buffer size: 1024 KByte (default)',
+             'Client connecting to 10.89.47.191, UDP port 5016',
+             'Sending 1470 byte datagrams, IPG target: 2352.00 us (kalman adjust)',
+             'UDP buffer size: 1024 KByte (default)',
+             '[  4] Sent 2552 datagrams',
+             '[  4] Server Report:']}
+
+
+COMMAND_OUTPUT_bidirectional_udp_server = """
+ute@2-7-TL166:~$ iperf -s -u -p 5016 -f k -i 1.0
+------------------------------------------------------------
+Server listening on UDP port 5016
+Receiving 1470 byte datagrams
+UDP buffer size: 1024 KByte (default)
+------------------------------------------------------------
+[  3] local 10.89.47.191 port 5016 connected with 10.89.47.150 port 56262
+------------------------------------------------------------
+Client connecting to 10.89.47.150, UDP port 5016
+Sending 1470 byte datagrams, IPG target: 2352.00 us (kalman adjust)
+UDP buffer size: 1024 KByte (default)
+------------------------------------------------------------
+[  5] local 10.89.47.191 port 47384 connected with 10.89.47.150 port 5016
+[ ID] Interval       Transfer     Bandwidth        Jitter   Lost/Total Datagrams
+[  3]  0.0- 1.0 sec   612 KBytes  5010 Kbits/sec   0.022 ms    0/  426 (0%)
+[  5]  0.0- 1.0 sec   613 KBytes  5022 Kbits/sec
+[  3]  1.0- 2.0 sec   610 KBytes  4998 Kbits/sec   0.016 ms    0/  425 (0%)
+[  5]  1.0- 2.0 sec   610 KBytes  4998 Kbits/sec
+[  3]  2.0- 3.0 sec   610 KBytes  4998 Kbits/sec   0.021 ms    0/  425 (0%)
+[  5]  2.0- 3.0 sec   610 KBytes  4998 Kbits/sec
+[  3]  3.0- 4.0 sec   610 KBytes  4998 Kbits/sec   0.009 ms    0/  425 (0%)
+[  5]  3.0- 4.0 sec   610 KBytes  4998 Kbits/sec
+[  3]  4.0- 5.0 sec   612 KBytes  5010 Kbits/sec   0.014 ms    0/  426 (0%)
+[  5]  4.0- 5.0 sec   610 KBytes  4998 Kbits/sec
+[  3]  5.0- 6.0 sec   610 KBytes  4998 Kbits/sec   0.018 ms    0/  425 (0%)
+[  3]  0.0- 6.0 sec  3664 KBytes  5000 Kbits/sec   0.018 ms    0/ 2552 (0%)
+[  5]  5.0- 6.0 sec   610 KBytes  4998 Kbits/sec
+[  5]  0.0- 6.0 sec  3664 KBytes  5000 Kbits/sec
+[  5] Sent 2552 datagrams
+[  5] Server Report:
+[  5]  0.0- 6.0 sec  3664 KBytes  5000 Kbits/sec   0.017 ms    0/ 2552 (0%)
+ute@2-7-TL166:~$"""
+
+
+COMMAND_KWARGS_bidirectional_udp_server = {
+    'options': '-u -p 5016 -f k -i 1.0'
+}
+
+
+COMMAND_RESULT_bidirectional_udp_server = {
+    'CONNECTIONS': {
+        'local 10.89.47.191 port 47384 connected with 10.89.47.150 port 5016': [{'Transfer': 627712,
+                                                                                 'Bandwidth': 627750,
+                                                                                 'Transfer Raw': '613 KBytes',
+                                                                                 'Bandwidth Raw': '5022 Kbits/sec',
+                                                                                 'Interval': '0.0- 1.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '1.0- 2.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '2.0- 3.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '3.0- 4.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '4.0- 5.0 sec'},
+                                                                                {'Transfer': 624640,
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Transfer Raw': '610 KBytes',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec',
+                                                                                 'Interval': '5.0- 6.0 sec'},
+                                                                                {'Transfer': 3751936,
+                                                                                 'Bandwidth': 625000,
+                                                                                 'Transfer Raw': '3664 KBytes',
+                                                                                 'Bandwidth Raw': '5000 Kbits/sec',
+                                                                                 'Interval': '0.0- 6.0 sec'},
+                                                                                {'Transfer Raw': '3664 KBytes',
+                                                                                 'Jitter': '0.017 ms',
+                                                                                 'Transfer': 3751936,
+                                                                                 'Interval': '0.0- 6.0 sec',
+                                                                                 'Bandwidth': 625000,
+                                                                                 'Lost_vs_Total_Datagrams': '0/ 2552 (0%)',
+                                                                                 'Bandwidth Raw': '5000 Kbits/sec'}],
+        'local 10.89.47.191 port 5016 connected with 10.89.47.150 port 56262': [{'Transfer Raw': '612 KBytes',
+                                                                                 'Jitter': '0.022 ms',
+                                                                                 'Transfer': 626688,
+                                                                                 'Interval': '0.0- 1.0 sec',
+                                                                                 'Bandwidth': 626250,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  426 (0%)',
+                                                                                 'Bandwidth Raw': '5010 Kbits/sec'},
+                                                                                {'Transfer Raw': '610 KBytes',
+                                                                                 'Jitter': '0.016 ms',
+                                                                                 'Transfer': 624640,
+                                                                                 'Interval': '1.0- 2.0 sec',
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  425 (0%)',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec'},
+                                                                                {'Transfer Raw': '610 KBytes',
+                                                                                 'Jitter': '0.021 ms',
+                                                                                 'Transfer': 624640,
+                                                                                 'Interval': '2.0- 3.0 sec',
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  425 (0%)',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec'},
+                                                                                {'Transfer Raw': '610 KBytes',
+                                                                                 'Jitter': '0.009 ms',
+                                                                                 'Transfer': 624640,
+                                                                                 'Interval': '3.0- 4.0 sec',
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  425 (0%)',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec'},
+                                                                                {'Transfer Raw': '612 KBytes',
+                                                                                 'Jitter': '0.014 ms',
+                                                                                 'Transfer': 626688,
+                                                                                 'Interval': '4.0- 5.0 sec',
+                                                                                 'Bandwidth': 626250,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  426 (0%)',
+                                                                                 'Bandwidth Raw': '5010 Kbits/sec'},
+                                                                                {'Transfer Raw': '610 KBytes',
+                                                                                 'Jitter': '0.018 ms',
+                                                                                 'Transfer': 624640,
+                                                                                 'Interval': '5.0- 6.0 sec',
+                                                                                 'Bandwidth': 624750,
+                                                                                 'Lost_vs_Total_Datagrams': '0/  425 (0%)',
+                                                                                 'Bandwidth Raw': '4998 Kbits/sec'},
+                                                                                {'Transfer Raw': '3664 KBytes',
+                                                                                 'Jitter': '0.018 ms',
+                                                                                 'Transfer': 3751936,
+                                                                                 'Interval': '0.0- 6.0 sec',
+                                                                                 'Bandwidth': 625000,
+                                                                                 'Lost_vs_Total_Datagrams': '0/ 2552 (0%)',
+                                                                                 'Bandwidth Raw': '5000 Kbits/sec'}]},
+    'INFO': ['Server listening on UDP port 5016',
+             'Receiving 1470 byte datagrams',
+             'UDP buffer size: 1024 KByte (default)',
+             'Client connecting to 10.89.47.150, UDP port 5016',
+             'Sending 1470 byte datagrams, IPG target: 2352.00 us (kalman adjust)',
+             'UDP buffer size: 1024 KByte (default)',
+             '[  5] Sent 2552 datagrams',
+             '[  5] Server Report:']}
+
+
 COMMAND_OUTPUT_multiple_connections = """
 xyz@debian:~$ iperf -c 192.168.0.100 -P 20
 ------------------------------------------------------------
@@ -336,102 +662,102 @@ COMMAND_KWARGS_multiple_connections = {
 COMMAND_RESULT_multiple_connections = {
     'CONNECTIONS': {
         'local 192.168.0.102 port 57246 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '14.5 Mbits/sec',
-                                                                                   'Bandwidth': 15204352,
+                                                                                   'Bandwidth': 1812500,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '18.5 MBytes',
                                                                                    'Transfer': 19398656}],
         'local 192.168.0.102 port 57247 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '14.1 Mbits/sec',
-                                                                                   'Bandwidth': 14784921,
+                                                                                   'Bandwidth': 1762500,
                                                                                    'Interval': '0.0-10.8 sec',
                                                                                    'Transfer Raw': '18.1 MBytes',
                                                                                    'Transfer': 18979225}],
         'local 192.168.0.102 port 57248 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.9 Mbits/sec',
-                                                                                   'Bandwidth': 14575206,
+                                                                                   'Bandwidth': 1737500,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '17.6 MBytes',
                                                                                    'Transfer': 18454937}],
         'local 192.168.0.102 port 57249 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.2 Mbits/sec',
-                                                                                   'Bandwidth': 13841203,
+                                                                                   'Bandwidth': 1650000,
                                                                                    'Interval': '0.0-10.8 sec',
                                                                                    'Transfer Raw': '17.0 MBytes',
                                                                                    'Transfer': 17825792}],
         'local 192.168.0.102 port 57250 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '14.3 Mbits/sec',
-                                                                                   'Bandwidth': 14994636,
+                                                                                   'Bandwidth': 1787500,
                                                                                    'Interval': '0.0-10.8 sec',
                                                                                    'Transfer Raw': '18.4 MBytes',
                                                                                    'Transfer': 19293798}],
         'local 192.168.0.102 port 57251 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.1 Mbits/sec',
-                                                                                   'Bandwidth': 13736345,
+                                                                                   'Bandwidth': 1637500,
                                                                                    'Interval': '0.0-10.6 sec',
                                                                                    'Transfer Raw': '16.6 MBytes',
                                                                                    'Transfer': 17406361}],
         'local 192.168.0.102 port 57252 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.0 Mbits/sec',
-                                                                                   'Bandwidth': 13631488,
+                                                                                   'Bandwidth': 1625000,
                                                                                    'Interval': '0.0-10.8 sec',
                                                                                    'Transfer Raw': '16.8 MBytes',
                                                                                    'Transfer': 17616076}],
         'local 192.168.0.102 port 57253 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.1 Mbits/sec',
-                                                                                   'Bandwidth': 13736345,
+                                                                                   'Bandwidth': 1637500,
                                                                                    'Interval': '0.0-10.8 sec',
                                                                                    'Transfer Raw': '16.8 MBytes',
                                                                                    'Transfer': 17616076}],
         'local 192.168.0.102 port 57254 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '14.0 Mbits/sec',
-                                                                                   'Bandwidth': 14680064,
+                                                                                   'Bandwidth': 1750000,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '18.0 MBytes',
                                                                                    'Transfer': 18874368}],
         'local 192.168.0.102 port 57255 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.7 Mbits/sec',
-                                                                                   'Bandwidth': 14365491,
+                                                                                   'Bandwidth': 1712500,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '17.5 MBytes',
                                                                                    'Transfer': 18350080}],
         'local 192.168.0.102 port 57256 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.9 Mbits/sec',
-                                                                                   'Bandwidth': 14575206,
+                                                                                   'Bandwidth': 1737500,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '17.8 MBytes',
                                                                                    'Transfer': 18664652}],
         'local 192.168.0.102 port 57257 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '14.1 Mbits/sec',
-                                                                                   'Bandwidth': 14784921,
+                                                                                   'Bandwidth': 1762500,
                                                                                    'Interval': '0.0-10.8 sec',
                                                                                    'Transfer Raw': '18.2 MBytes',
                                                                                    'Transfer': 19084083}],
         'local 192.168.0.102 port 57258 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.8 Mbits/sec',
-                                                                                   'Bandwidth': 14470348,
+                                                                                   'Bandwidth': 1725000,
                                                                                    'Interval': '0.0-10.8 sec',
                                                                                    'Transfer Raw': '17.8 MBytes',
                                                                                    'Transfer': 18664652}],
         'local 192.168.0.102 port 57259 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.1 Mbits/sec',
-                                                                                   'Bandwidth': 13736345,
+                                                                                   'Bandwidth': 1637500,
                                                                                    'Interval': '0.0-10.6 sec',
                                                                                    'Transfer Raw': '16.6 MBytes',
                                                                                    'Transfer': 17406361}],
         'local 192.168.0.102 port 57260 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.1 Mbits/sec',
-                                                                                   'Bandwidth': 13736345,
+                                                                                   'Bandwidth': 1637500,
                                                                                    'Interval': '0.0-10.6 sec',
                                                                                    'Transfer Raw': '16.5 MBytes',
                                                                                    'Transfer': 17301504}],
         'local 192.168.0.102 port 57261 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.0 Mbits/sec',
-                                                                                   'Bandwidth': 13631488,
+                                                                                   'Bandwidth': 1625000,
                                                                                    'Interval': '0.0-10.6 sec',
                                                                                    'Transfer Raw': '16.5 MBytes',
                                                                                    'Transfer': 17301504}],
         'local 192.168.0.102 port 57262 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '12.9 Mbits/sec',
-                                                                                   'Bandwidth': 13526630,
+                                                                                   'Bandwidth': 1612500,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '16.5 MBytes',
                                                                                    'Transfer': 17301504}],
         'local 192.168.0.102 port 57263 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.0 Mbits/sec',
-                                                                                   'Bandwidth': 13631488,
+                                                                                   'Bandwidth': 1625000,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '16.6 MBytes',
                                                                                    'Transfer': 17406361}],
         'local 192.168.0.102 port 57264 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '12.3 Mbits/sec',
-                                                                                   'Bandwidth': 12897484,
+                                                                                   'Bandwidth': 1537500,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '15.6 MBytes',
                                                                                    'Transfer': 16357785}],
         'local 192.168.0.102 port 57265 connected with 192.168.0.100 port 5001': [{'Bandwidth Raw': '13.0 Mbits/sec',
-                                                                                   'Bandwidth': 13631488,
+                                                                                   'Bandwidth': 1625000,
                                                                                    'Interval': '0.0-10.7 sec',
                                                                                    'Transfer Raw': '16.6 MBytes',
                                                                                    'Transfer': 17406361}]},


Test patch:
diff --git a/test/cmd/unix/test_cmd_iperf.py b/test/cmd/unix/test_cmd_iperf.py
index 0ee81a01..e66b78e0 100644
--- a/test/cmd/unix/test_cmd_iperf.py
+++ b/test/cmd/unix/test_cmd_iperf.py
@@ -44,6 +44,51 @@ def test_iperf_raise_error_on_iperf_problem(buffer_connection, command_output_an
         iperf_cmd()
 
 
+def test_iperf_correctly_parses_bidirectional_udp_client_output(buffer_connection):
+    from moler.cmd.unix import iperf
+    buffer_connection.remote_inject_response([iperf.COMMAND_OUTPUT_bidirectional_udp_client])
+    iperf_cmd = iperf.Iperf(connection=buffer_connection.moler_connection,
+                            **iperf.COMMAND_KWARGS_bidirectional_udp_client)
+    res = iperf_cmd()
+    assert res == iperf.COMMAND_RESULT_bidirectional_udp_client
+
+
+def test_iperf_correctly_parses_bidirectional_udp_server_output(buffer_connection):
+    from moler.cmd.unix import iperf
+    buffer_connection.remote_inject_response([iperf.COMMAND_OUTPUT_bidirectional_udp_server])
+    iperf_cmd = iperf.Iperf(connection=buffer_connection.moler_connection,
+                            **iperf.COMMAND_KWARGS_bidirectional_udp_server)
+    res = iperf_cmd()
+    assert res == iperf.COMMAND_RESULT_bidirectional_udp_server
+
+
+def test_iperf_correctly_parses_basic_udp_server_output(buffer_connection):
+    from moler.cmd.unix import iperf
+    buffer_connection.remote_inject_response([iperf.COMMAND_OUTPUT_basic_server])
+    iperf_cmd = iperf.Iperf(connection=buffer_connection.moler_connection,
+                            **iperf.COMMAND_KWARGS_basic_server)
+
+    assert iperf_cmd() == iperf.COMMAND_RESULT_basic_server
+
+
+def test_iperf_correctly_parses_basic_tcp_client_output(buffer_connection):
+    from moler.cmd.unix import iperf
+    buffer_connection.remote_inject_response([iperf.COMMAND_OUTPUT_basic_client])
+    iperf_cmd = iperf.Iperf(connection=buffer_connection.moler_connection,
+                            **iperf.COMMAND_KWARGS_basic_client)
+
+    assert iperf_cmd() == iperf.COMMAND_RESULT_basic_client
+
+
+def test_iperf_correctly_parses_multiconnection_tcp_client_output(buffer_connection):
+    from moler.cmd.unix import iperf
+    buffer_connection.remote_inject_response([iperf.COMMAND_OUTPUT_multiple_connections])
+    iperf_cmd = iperf.Iperf(connection=buffer_connection.moler_connection,
+                            **iperf.COMMAND_KWARGS_multiple_connections)
+
+    assert iperf_cmd() == iperf.COMMAND_RESULT_multiple_connections
+
+
 @pytest.fixture
 def command_output_and_expected_result_on_bind_failed():
     output = """xyz@debian>iperf -s