thiezn / iperf3-python

Python wrapper around iperf3
https://iperf3-python.readthedocs.org/
MIT License
110 stars 51 forks source link

TCP protocol produces error in output #15

Closed linuxyoda closed 7 years ago

linuxyoda commented 7 years ago

When I use tcp as the protocol, I get the following error:

Test completed: started at Mon, 05 Jun 2017 14:30:00 GMT Traceback (most recent call last): File "./run-iperf3.py", line 31, in print(' bytes transmitted {0}'.format(result.bytes)) AttributeError: 'TestResult' object has no attribute 'bytes'

If I change the protocol to udp, I get the expected output.

The following is my script:

!/usr/bin/python

import iperf3 import socket

hostname = socket.gethostname()

client = iperf3.Client() client.duration = 5 client.bandwidth = '10M' client.server_hostname = '10.255.2.1' client.port = 5201 client.protocol = 'tcp'

print('Running on {0}'.format(hostname)) print('Connecting to {0}:{1}'.format(client.server_hostname, client.port)) result = client.run()

if result.error: print(result.error) else: print('') print('Test completed:') print(' started at {0}'.format(result.time)) print(' bytes transmitted {0}'.format(result.bytes)) print(' jitter (ms) {0}'.format(result.jitter_ms)) print(' avg cpu load {0}%\n'.format(result.local_cpu_total))

print('Average transmitted data in all sorts of networky formats:')
print('  bits per second      (bps)   {0}'.format(result.bps))
print('  Kilobits per second  (kbps)  {0}'.format(result.kbps))
print('  Megabits per second  (Mbps)  {0}'.format(result.Mbps))
print('  KiloBytes per second (kB/s)  {0}'.format(result.kB_s))
print('  MegaBytes per second (MB/s)  {0}'.format(result.MB_s))
MarkusFreitag commented 7 years ago

Please have a look at the documentation about the TestResult class. If you have performed a tcp-based test, the result object has separated attributes like "sent_bytes" and "received_bytes". https://iperf3-python.readthedocs.io/en/latest/modules.html#testresult

thiezn commented 7 years ago

Thanks @MarkusFreitag, you are correct. I'm trying to closely follow the iperf3 library implementation which produces different attributes for UDP and TCP tests.

bmah888 commented 7 years ago

esnet/iperf#584 is kind of relevant to this issue. I don't have a particular fix in mind.