Closed linuxyoda closed 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
Thanks @MarkusFreitag, you are correct. I'm trying to closely follow the iperf3 library implementation which produces different attributes for UDP and TCP tests.
esnet/iperf#584 is kind of relevant to this issue. I don't have a particular fix in mind.
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))