Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the option of fetching the server output on the client side. #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions iperf3/iperf3.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ def __init__(self,
self.lib.iperf_get_test_reverse.argtypes = (c_void_p,)
self.lib.iperf_set_test_reverse.restype = None
self.lib.iperf_set_test_reverse.argtypes = (c_void_p, c_int,)
self.lib.iperf_get_test_get_server_output.restype = c_int
self.lib.iperf_get_test_get_server_output.argtypes = (c_void_p,)
self.lib.iperf_set_test_get_server_output.restype = None
self.lib.iperf_set_test_get_server_output.argtypes = (c_void_p, c_int,)
self.lib.iperf_run_client.restype = c_int
self.lib.iperf_run_client.argtypes = (c_void_p,)
self.lib.iperf_run_server.restype = c_int
Expand Down Expand Up @@ -605,6 +609,21 @@ def reverse(self, enabled):
self.lib.iperf_set_test_reverse(self._test, 0)

self._reverse = enabled

@property
def get_server_output(self):
"""The server output."""
self._server_output = self.lib.iperf_get_test_get_server_output(self._test)
return self._server_output

@get_server_output.setter
def get_server_output(self, enabled):
if enabled:
self.lib.iperf_set_test_get_server_output(self._test, 1)
else:
self.lib.iperf_set_test_get_server_output(self._test, 0)

self._get_server_output = enabled

def run(self):
"""Run the current test client.
Expand Down Expand Up @@ -773,6 +792,10 @@ class TestResult(object):
:param lost_packets:
:param lost_percent:
:param seconds:

Server information

:param server_output: The server output (Only returned from client)
"""

def __init__(self, result):
Expand Down Expand Up @@ -864,6 +887,10 @@ def __init__(self, result):
self.lost_packets = self.json['end']['sum']['lost_packets']
self.lost_percent = self.json['end']['sum']['lost_percent']
self.seconds = self.json['end']['sum']['seconds']

# Server information (Only returned from client)
self.server_output = self.json.get('server_output_text') or self.json.get('server_output_json')


@property
def reverse(self):
Expand Down
70 changes: 70 additions & 0 deletions tests/test_iperf3.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ def test_reverse_disabled(self):
client = iperf3.Client()
client.reverse = False
assert not client.reverse

def test_get_server_output_enabled(self):
client = iperf3.Client()
client.get_server_output = True
assert client.get_server_output

def test_get_server_output__disabled(self):
client = iperf3.Client()
client.get_server_output = False
assert not client.get_server_output

def test_get_last_error(self):
client = iperf3.Client()
Expand Down Expand Up @@ -206,6 +216,66 @@ def test_client_succesful_run_reverse(self):
assert response.reverse
assert response.type == 'client'
assert response.__repr__()

def test_client_succesful_get_server_output(self):
client = iperf3.Client()
client.server_hostname = '127.0.0.1'
client.port = 5203
client.duration = 1
client.get_server_output = True

server = subprocess.Popen(["iperf3", "-s", "-p", "5203"])
sleep(.3) # give the server some time to start
response = client.run()
server.kill()

assert response.remote_host == '127.0.0.1'
assert response.remote_port == 5203

# These are added to check some of the TestResult variables
assert response.server_output
assert response.type == 'client'
assert response.__repr__()

def test_client_succesful_get_server_output_json(self):
client = iperf3.Client()
client.server_hostname = '127.0.0.1'
client.port = 5203
client.duration = 1
client.get_server_output = True

server = subprocess.Popen(["iperf3", "-s", "-J", "-p", "5203"])
sleep(.3) # give the server some time to start
response = client.run()
server.kill()

assert response.remote_host == '127.0.0.1'
assert response.remote_port == 5203

# These are added to check some of the TestResult variables
assert response.server_output
assert response.type == 'client'
assert response.__repr__()

def test_client_unsuccesful_get_server_output(self):
client = iperf3.Client()
client.server_hostname = '127.0.0.1'
client.port = 5203
client.duration = 1
client.get_server_output = False

server = subprocess.Popen(["iperf3", "-s", "-p", "5203"])
sleep(.3) # give the server some time to start
response = client.run()
server.kill()

assert response.remote_host == '127.0.0.1'
assert response.remote_port == 5203

# These are added to check some of the TestResult variables
assert not response.server_output
assert response.type == 'client'
assert response.__repr__()

def test_client_succesful_run_udp(self):
client = iperf3.Client()
Expand Down