Giter VIP home page Giter VIP logo

iperf3-python's Introduction

iperf3-python: Python wrapper around iperf3

PyPi Status Build Status Coverage Status Documentation Status

Detailed documentation at iperf3-python.readthedocs.org

iperf3 for python provides a wrapper around the excellent iperf3 utility. iperf3 is a complete rewrite of the original iperf implementation. more information on the official iperf3 site

iperf3 introduced an API called libiperf that allows you to easily interact with iperf3 from other languages. This library provides a python wrapper around libiperf for easy integration into your own python scripts in a pythonic way

Installation

First you have to make sure the iperf3 utility is present on your system as the python module wraps around the libiperf API provided by it.

The common linux distributions offer installations from their own repositories. These might be out of date so installation from the official iperf3 website is preferred.

note The libiperf API was only introduced in 3.0.6 so make sure you have an updated version of iperf3 installation.

note The libiperf API added a feature to programmatically retrieve the json output from the library. This enables us to retrieve the results without having to scrape the output from stdout. Effectively this means that if you want to redirect your script's stdout/stderr to something else you need at least iperf3 version 3.1

  • Install from source (preferred)
wget http://downloads.es.net/pub/iperf/iperf-3-current.tar.gz
tar xvf iperf-3-current.tar.gz
cd iperf-3.3/                # Or whatever the latest version is
./configure && make && sudo make install
  • Ubuntu:
sudo apt-get install iperf3
  • CenOS/RedHat
sudo yum install iperf3

Once the iperf3 utility is installed the simplest way to install the python wrapper is through PyPi

pip install iperf3

You can also install directly from the github repository:

git clone https://github.com/thiezn/iperf3-python.git
cd iperf3-python
python3 setup.py install

Quickstart

For detailed examples check out the examples page or the detailed documentation at iperf3-python.readthedocs.org

Server

>>> import iperf3

>>> server = iperf3.Server()
>>> result = server.run()
>>> result.remote_host
"10.10.10.10"

Client

>>> import iperf3

>>> client = iperf3.Client()
>>> client.duration = 1
>>> client.server_hostname = '127.0.0.1'
>>> client.port = 5201
>>> result = client.run()
>>> result.sent_Mbps
32583.293914794922

External Dependencies

  • iperf3
  • libiperf.so.0 (Comes with iperf3 >= 3.0.6)

Testing

  • Tested against the following iperf3 versions on Linux:
    • 3.0.6
    • 3.0.7
    • 3.0.8
    • 3.0.9
    • 3.0.10
    • 3.0.11
    • 3.0.12
    • 3.1
    • 3.1.1
    • 3.1.2
    • 3.1.3
    • 3.1.4
    • 3.1.5
    • 3.1.6
    • 3.1.7
    • 3.2
    • 3.3
    • 3.4
    • 3.5
    • 3.6
  • Test coverage reporting through coveralls.io
  • Tested against the following Python versions:
    • 2.7
    • 3.6

iperf3-python's People

Contributors

austinpayne avatar christofkaufmann avatar gleichda avatar m-mortimer avatar p0intr avatar rustyhowell avatar thiezn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

iperf3-python's Issues

iperf3 segmentation fault in python

I am trying to write a python code for iperf3 on a virtual machine with ubuntu 14.04 installed. Anytime i run this command "client = iperf3.Client()" i get a segmentation fault(core dumped) error.
Any help with how to solve this problem.

client.run hangs when client.duration over 130 seconds

Anyone know if there is any fix or workaround on this (other than running in a loop heh)?

I am encountering same issue on rhel7 and Ubuntu 16.04. When i use iperf3 module with python3 it hangs for interval > 130...

When I run iperf3 tool itself command line it works just fine with long test duration.

Details below. Any insight appreciated, thanks! :)

(iperf3env) # python3
Python 3.6.8 (default, Jun 11 2019, 15:15:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.

import iperf3
client = iperf3.Client()
client.duration = 10
client.server_hostname = '10.0.0.2'
client.bandwidth = 50000000
result = client.run()
result.sent_Mbps
49.561612938104
del client
client = iperf3.Client()
client.duration = 131
client.server_hostname = '10.0.0.2'
client.bandwidth = 50000000
result = client.run()
^CTraceback (most recent call last):
File "", line 1, in
File "/home/nick/iperf3env/lib/python3.6/site-packages/iperf3/iperf3.py", line 616, in run
error = self.lib.iperf_run_client(self._test)
KeyboardInterrupt
quit()
(iperf3env) #

(iperf3env) # iperf3 -c 10.0.0.2 -b 50000000 -t 180
Connecting to host 10.0.0.2, port 5201
[ 4] local 10.0.0.1 port 38590 connected to 10.0.0.2 port 5201
[ ID] Interval Transfer Bandwidth Retr Cwnd
[ 4] 0.00-1.00 sec 5.46 MBytes 45.8 Mbits/sec 29 417 KBytes
[ 4] 1.00-2.00 sec 5.88 MBytes 49.3 Mbits/sec 0 427 KBytes
[ 4] 2.00-3.00 sec 6.00 MBytes 50.3 Mbits/sec 0 436 KBytes
...
[ 4] 177.00-178.00 sec 6.00 MBytes 50.3 Mbits/sec 0 622 KBytes
[ 4] 178.00-179.00 sec 5.88 MBytes 49.3 Mbits/sec 0 625 KBytes
[ 4] 179.00-180.00 sec 6.00 MBytes 50.3 Mbits/sec 0 625 KBytes

[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-180.00 sec 1.05 GBytes 50.0 Mbits/sec 82 sender
[ 4] 0.00-180.00 sec 1.05 GBytes 50.0 Mbits/sec receiver

iperf Done.
(iperf3env) #

I can't take several measures

I would like to repeat the tests several times to relieve the bandwidth of an entire room. but when I repeat the test it gives me an error that I suppose is to rewrite the variable result = client.run ()

Traceback (most recent call last):
File "/home/pi/Desktop/test1.py", line 19, in
test = client.run()
File "/usr/local/lib/python3.5/dist-packages/iperf3-0.1.10-py3.5.egg/iperf3/iperf3.py", line 612, in run
output_to_screen(self._stdout_fd, self.stderr_fd) # enable stdout
File "/usr/local/lib/python3.5/dist-packages/iperf3-0.1.10-py3.5.egg/iperf3/iperf3.py", line 80, in output_to_screen
os.dup2(stdout_fd, 1)
OSError: [Errno 9] Bad file descriptor**

any help??

Unable to run Iperf with parallel streams for more than 20 seconds

Running Iperf with 5 parallel streams(TCP) does not work while running the same code with a single connection works fine.

CODE SNIPPET:

class IperfClient(object):
    def __init__(self):
         self.run()

    def run(self):
         print('1')
         client = iperf3.Client()
         client.server_hostname = 0.0.0.0
         client.duration = 60
         client.num_streams = 5
         print('2')
         response = client.run()
         print('3')

class IperfAgent(object):
    def startAgent(self):
        protocol = 'tcp'
        p1 = Process(target=IperfClient).start()

OUTPUT:

1

2

It does not reach "print('3')" line. I pressed Ctrl+C after waiting for several minutes and only this was printed:

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/multiprocessing/popen_fork.py", line 31, in poll
pid, sts = os.waitpid(self.pid, flag)

KeyboardInterrupt

Please add the ability to override the library name as find_library is broken!

utils.find_library does not work on Python 2.7.14 in my testing:

$ ./find.py
Finding path for library [libiperf] = None

$ cat find.py
#!/usr/bin/python
from ctypes import util

lib = "libiperf"

print "Finding path for library [{}] = {}".format(lib, util.find_library(lib))

$ /usr/bin/python --version
Python 2.7.14

$ ldconfig -p |grep libiperf
        libiperf.so.0 (libc6,x86-64) => /lib64/libiperf.so.0
        libiperf.so (libc6,x86-64) => /lib64/libiperf.so

And actually this seems to work:

% ./find.py
Finding path for library [iperf] = libiperf.so.0

So we need to be able to specify the library name it looks for at the very least, and override the lib_name itself would also be ideal.

Also it does seem that it gets set to libiperf.so.0 via the None check, however it fails to load the library still?

OSError: Couldn't find shared library libiperf.so.0, is iperf3 installed?
Exception AttributeError: "'Client' object has no attribute '_stdout_fd'" in <bound method Client.__del__ of <iperf3.iperf3.Client object at 0x7f5152cc8850>> ignored

Or is my library too old?

If I assign output to variable there is a JSON decode error.

When running the code below if I don't assign the client.run() to a variable it will print to screen like normal. If I assign to a variable to parse it/print later I get the below error.

import iperf3, time, threading

def client():
    
    print("starting client")
    client = iperf3.Client()
    client.Duration = 4
    client.bind_address="192.168.200.10"
    client.server_hostname='192.168.200.20'
    client.port=6969
    time.sleep(2) #used to make sure server is up and ready
    result = client.run()
    #print(type(result))

    return result

    


def server():
	server = iperf3.Server()
	server.bind_address='192.168.200.20'
	server.port=6969
	print("starting server")
	server.run()
	print("server done")
    #if you see the server stating and ending quickly. the ip/port is already bound?


c = threading.Thread(target=client)
t = threading.Thread(target=server)
t.setDaemon=True

t.start()
c.start()

Error:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "iperf3Client.py", line 12, in client
    result = client.run()
  File "/usr/local/lib/python3.5/dist-packages/iperf3/iperf3.py", line 617, in run
    return TestResult(data)
  File "/usr/local/lib/python3.5/dist-packages/iperf3/iperf3.py", line 768, in __init__
    self.json = json.loads(result)
  File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.5/json/decoder.py", line 342, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 310 column 1 (char 6530)

Could it be it's seeing an extra character at the start of the list when it does the JSON formatting and it errors out? I know just enough about the JSON to get myself in trouble.

I also changed my json_output=False like in #38 but that causes it to hang. Was hoping for the NoneType, or for something different, but it wasn't the different I was expecting.

Linux machoog546-virtual-machine 4.10.0-38-generic #42~16.04.1-Ubuntu SMP Tue Oct 10 16:32:20 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

UDP bandwidth low limit always 5Mbps.

My iperf3 is latest version 3.1.3, I found BW for UDP is always set to 5Mbps by iperf3-python when bw setting is < 5Mbps. This problem does not see on CLI mode of iperf3.

DSCP Tos

This tool is very helpful. How to enable DSCP or TOS mark?

Cannot build using bazel due to `extra_require` referencing `iperf3`

This looks like a fantastic library that I'd like to use, however, I am unable to build this with bazel due to the extra_require at https://github.com/thiezn/iperf3-python/blob/master/setup.py#L65 that references iperf3.
https://github.com/bazelbuild/rules_python#using-the-packaging-rules
bazel installs iperf3, but then tries to add that dependency which breaks the build.
Will have to resort to using subprocess to parse the output, but please let me know if you fix this, or have a workaround!

"bandwidth" attribute

I'm using iperf3 for testing VoIP quality, and would like to use iperf-lib, but can't set bandwidth in udp mode, script tests at the maximum speed that it can send.
for example:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import iperf3

client = iperf3.Client()
client.protocol = 'udp'
client.bandwidth = 1
client.duration = 5
client.server_hostname = '127.0.0.1'
client.port = 6969

result = client.run()

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('  Megabits per second  (Mbps)  {0}'.format(result.Mbps))

where out are:


Test completed:
  started at         Sun, 25 Jun 2017 04:26:54 GMT
  bytes transmitted  21561039487
  jitter (ms)        0.00436181
  avg cpu load       87.6748%

  Megabits per second  (Mbps)  32899.4750977

In CLI version iperf work is fine

Debian GNU/Linux 8.8 (jessie)
Python 2.7.9

Can I use 'interval fanction'??

Hello,Author!!! I'm using iperf3 funcion.
I'd like to use 'interval function' to check measure speed every few seconds,but I don`t know how to use this function. If I'm able to use 'interval function' or there is 'interval module' to be used iperf3,please tell me how to use them.

Also,I want to ask you one order. If there isn't 'interval function' and I can't use them now, can you add the function to measure speed every few seconds??

Parse the JSON results into a python object

At the moment the server and client returns the raw json output. It could be handy to parse this output into a python object for easy access. an example could be something like this:

>>TestResult.duration
10
>>TestResult.sender_bps
1234

How to set number of bytes to transmit (-n)

Different from getting available bandwidth, I'd like to find how much time it used to transfer specific volume of data.

Is there any way to set the parameter as the cli command of '-n'?

json_output = False, always will output "None"

There is my function

def start_test(hostname, port):
    client = iperf3.Client()
    client.duration = 1
    client.reverse = True
    client.num_streams = 16
    client.server_hostname = hostname
    client.port = port
    client.json_output = False
    return client.run()

If I set client.json_output = False, I will get "None". If I set output as json, everything work like a charm.

iperf version:

iperf 3.1.3
Linux vasiliyrusin 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64
Optional features available: CPU affinity setting, IPv6 flow label, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing

Raise exception when port given to server is already occupied

I am trying to implement an iperf3 server that is capable of doing multiple simultaneous tests. I am planning on doing the handling of multiple tests using Twisted. Unfortunately I've run into an issue with finding a port to give the iperf3.Server: if I give it a port that is already being used by another process, no error information is returned until the call to Server.run() returns. Until this point there is no way of telling if the port was good or not.

It seems to me that the pythonic way to do this would be to define an exception ("PortTakenError" or something similar) that is raised before the call to Server.run() returns. That way, people can encapsulate the Server.run() call in a try-except statement and handle a "PortTakenError" gracefully.

Is this doable? I can probably figure out how to implement this; if I submit a pull request with these changes would you accept it?

Client connection resilience on busy

Im trying to add some resilience to my clients such that if they attempt to connect to a port on the server that is busy, they automatically increment the port number within the range of open server ports. This is what I am trying. The problem is it seems never to trigger the exception. If I make port 5200 busy with another client, the test seems just to fail silently. Surely I can't be the first person to attempt this. Any ideas how I can force a retry?

client = iperf3.Client()
client.duration = 15
client.server_hostname = 'x.x.x.x'
client.verbose = True
client.reverse = True
print('a')
i = 0
while i < 9:
        print('b')
        try:
                client.port = 5200 + i
                print('c')
                result = client.run()
                print(result.received_Mbps)
                i = 10
                print(str(client.port))
        except:
                i = i + 1

Reverse Mode not working

When reverse mode is set, IPERF3 does not work correctly and there are errors in returning.

CODE:

import iperf3
client = iperf3.Client()
client.server_hostname = '192.168.1.1'
client.port = 5201
client.protocol = 'udp'
client.duration = 10
client.num_streams = 10
client.reverse = True

#RUN!
result = client.run()

print('BW {:0.3f}'.format(result.Mbps))
print('LOST {:0.3f}%'.format(result.lost_percent))
print('JITTER {:0.3f}'.format(result.jitter_ms))

RETURN WITH REVERSE MODE:

Traceback (most recent call last):
File "teste.py", line 54, in
result = client.run()
File "/usr/local/lib/python2.7/dist-packages/iperf3/iperf3.py", line 512, in run
return TestResult(data)
File "/usr/local/lib/python2.7/dist-packages/iperf3/iperf3.py", line 659, in init
self.json = json.loads(result)
File "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

SERVER RETURN WITH IPERF3-PYTHON:
[SUM] 0.00-10.08 sec 537 MBytes 447 Mbits/sec 1.442 ms 5087/5193 (98%)

SERVER RETURN WITHOUT IPERF3-PYTHON ( iperf3 -c 192.168.1.1 -p 5201 -P 10 -t 10 -u -R):
[SUM] 0.00-10.01 sec 12.5 MBytes 10.5 Mbits/sec 3.296 ms 0/1599 (0%)

The BW are diferent! The interfaces are Fast-Ethernet (100Mbps).

TCP protocol produces error in output

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))

Simple run on local network produces json key error

On linux/raspi/bullseye with latest python

in python, i set server_hostname to a local IP and then client.run()

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/dist-packages/IPython/core/interactiveshell.py", line 3398, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-44-be7fe9e82b4a>", line 1, in <cell line: 1>
    client.run()
  File "/usr/local/lib/python3.9/dist-packages/iperf3/iperf3.py", line 634, in run
    return TestResult(data)
  File "/usr/local/lib/python3.9/dist-packages/iperf3/iperf3.py", line 793, in __init__
    self.time = self.json['start']['timestamp']['time']
KeyError: 'timestamp'

How disable Neagle's algorithm: -N, --no-delay

Currently it doesn't look like the --no-delay parameter has been passed through as a modification variable.
Setting the MSS (trying to use tcp_mss_default, not sure if it is the correct one) does not seem to take affect if the Neagle algorithm is in play.

Cannot run from Cron

I just discovered that a script using this library cannot run under Cron. I get:

File "/usr/local/lib/python2.7/dist-packages/iperf_graphite/iperf_graphite.py", line 58, in run_iperf
    r = client.run()
  File "/usr/local/lib/python2.7/dist-packages/iperf3/iperf3.py", line 465, in run
    return TestResult(data)
  File "/usr/local/lib/python2.7/dist-packages/iperf3/iperf3.py", line 590, in __init__
    self.json = json.loads(result)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

It seems to be related to how iperf3-python handles stdout/stderr via pipes. I'm not sure how to fix this. Any pointers appreciated.

Not using the get_server_output api call

want to run UDP tests, but throughput/bandwidth measured at server side

if i run iperf3 from the CLI i get both what i sent and the servers received data results.

also found there are issues with 'end' results when running reversed to get around the issue

Client is not responding with num_streams > 22

Tested with iperf 3.9, 3.6, 3.0.11 client is not responding with num_streams > 22

Working scenario:

import iperf3
import os

remote_site = os.getenv('REMOTE_SITE_IP')

client = iperf3.Client()
client.server_hostname = remote_site
client.zerocopy = True
client.verbose = False
client.reverse = False
client.port = 5201
client.num_streams = 22
client.protocol = 'tcp'

result = client.run()

sent_mbps = int(result.sent_Mbps)
received_mbps = int(result.received_Mbps)

print('sent speed:%',sent_mbps)
print('received speed:%',received_mbps)

Non-working scenario:

import iperf3
import os

remote_site = os.getenv('REMOTE_SITE_IP')

client = iperf3.Client()
client.server_hostname = remote_site
client.zerocopy = True
client.verbose = False
client.reverse = False
client.port = 5201
client.num_streams = 23
client.protocol = 'tcp'

result = client.run()

sent_mbps = int(result.sent_Mbps)
received_mbps = int(result.received_Mbps)

print('sent speed:%',sent_mbps)
print('received speed:%',received_mbps)

client hangs while running

I'm using Python 2.7.12, iperf 3.0.11 on a Ubuntu 16.04.1 x86_64 machine.

I configured the client to run as follows:

>>> import iperf3
>>> client = iperf3.Client()
>>> client.duration = 125
>>> client.bind_address = '127.0.0.1'
>>> client.server_hostname = '127.0.0.1'
>>> client.port = 9923
>>> client.bandwidth = (5096 * 1024)
>>> client.num_streams = 3
>>> client.protocol = "tcp"
>>> client.bulksize = (client.bandwidth * client.duration)/8
>>> client.run()

The bandwidth parameter is configured that way since I need 5096 kbps. The Bulksize parameter is kept as it is to ensure that the total throughput (total bits sent/total duration) matches the bandwidth value of (5096*1024). I've run the same code with smaller throughput and smaller duration values and it works great.

There are two problems:

  1. When running this client, the client stalls. It does not terminate on my machine. For lower throughput/duration values, it works like a charm. Whats the problem here? I always have to kill it for this specific test!

  2. I've noticed that the traffic is bursty in nature i.e. it attempts to send most of the data within the 1st second itself rather than evenly distributing the data over the entire test duration. Is there a way where I can achieve my expected throughput but have evenly distributed traffic as well?

Set MSS value

Hi everyone,

I was wandering if it's possible to set MSS value for TCP streams?
Tried tcp_mss_default, but doesn't look to have any impact.

Thank you!
Kr,
Dan

Timeout in server

Hi,

Is there a way to use a timeout on the server? For example, the server automatically closes when X seconds have passed without a client request.

Thanks!

Any support planned for windows?

Is there support for windows planned? Perhaps this is something I could assist with.

Attempting run this python wrapper on windows (with iperf3 installed through chocolatey) results in a missing library. See the below error.

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import iperf3
>>> client = iperf3.Client()
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\iperf3\iperf3.py", line 102, in __init__
    self.lib = cdll.LoadLibrary(lib_name)
  File "C:\Python36\lib\ctypes\__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python36\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36\lib\site-packages\iperf3\iperf3.py", line 410, in __init__
    super(Client, self).__init__(role='c', *args, **kwargs)
  File "C:\Python36\lib\site-packages\iperf3\iperf3.py", line 106, in __init__
    lib_name
OSError: Couldn't find shared library libiperf.so.0, is iperf3 installed?

Which TestResult property has meaning bandwidth like iperf3 cli shows?

I see many derivatives of bits total amount is sent and received:

    class TestResult(object):

    :param sent_bytes: Sent bytes
    :param sent_bps: Sent bits per second
    :param sent_kbps: sent kilobits per second
    :param sent_Mbps: Sent Megabits per second
    :param sent_kB_s: Sent kiloBytes per second
    :param sent_MB_s: Sent MegaBytes per second

    :param received_bytes:  Received bytes
    :param received_bps: Received bits per second
    :param received_kbps: Received kilobits per second
    :param received_Mbps: Received Megabits per second
    :param received_kB_s: Received kiloBytes per second
    :param received_MB_s: Received MegaBytes per second

But i'm interested in bandwidth speed:
bw

Could you help me to find it or explain how to compute it up?

Segfault on Ubuntu 16.10

Kernel: 4.8
Python 3.5.2+ (default, Sep 22 2016, 12:18:14)
iperf 3.1.3

Stacktrace:
ThreadStacktrace:

Thread 1 (Thread 0x7f2e69160700 (LWP 19792)):
#0 0x00007f2e65db2164 in iperf_defaults () from /usr/lib/x86_64-linux-gnu/libiperf.so.0
No symbol table info available.
#1 0x00007f2e67199a08 in ffi_call_unix64 () from /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so
No symbol table info available.
#2 0x00007f2e6719946a in ffi_call () from /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so
No symbol table info available.
#3 0x00007f2e67192c14 in _ctypes_callproc () from /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so
No symbol table info available.
#4 0x00007f2e671913c1 in ?? () from /usr/lib/python3.5/lib-dynload/_ctypes.cpython-35m-x86_64-linux-gnu.so
No symbol table info available.
#5 0x00005636e05f72f7 in PyObject_Call ()
No symbol table info available.
#6 0x00005636e0562f01 in PyEval_EvalFrameEx ()
No symbol table info available.
#7 0x00005636e0562b0f in PyEval_EvalFrameEx ()
No symbol table info available.
#8 0x00005636e05681ef in PyEval_EvalCodeEx ()
No symbol table info available.
#9 0x00005636e051139f in ?? ()
No symbol table info available.
#10 0x00005636e05f72f7 in PyObject_Call ()
No symbol table info available.
#11 0x00005636e0560356 in PyEval_EvalFrameEx ()
No symbol table info available.
#12 0x00005636e0568927 in PyEval_EvalCodeEx ()
No symbol table info available.
#13 0x00005636e05111b3 in ?? ()
No symbol table info available.
#14 0x00005636e05f72f7 in PyObject_Call ()
No symbol table info available.
#15 0x00005636e052cc0e in ?? ()
No symbol table info available.
#16 0x00005636e05f72f7 in PyObject_Call ()
No symbol table info available.
#17 0x00005636e05b71e9 in ?? ()
No symbol table info available.
#18 0x00005636e05be6b4 in ?? ()
No symbol table info available.
#19 0x00005636e05f72f7 in PyObject_Call ()
No symbol table info available.
#20 0x00005636e0562f01 in PyEval_EvalFrameEx ()
No symbol table info available.
#21 0x00005636e05673f6 in ?? ()
No symbol table info available.
#22 0x00005636e05680af in PyEval_EvalCode ()
No symbol table info available.
#23 0x00005636e0641532 in ?? ()
No symbol table info available.
#24 0x00005636e0495956 in PyRun_InteractiveOneObject ()
No symbol table info available.
#25 0x00005636e0495aff in PyRun_InteractiveLoopFlags ()
No symbol table info available.
#26 0x00005636e06442f4 in PyRun_AnyFileExFlags ()
No symbol table info available.
#27 0x00005636e0503bff in ?? ()
No symbol table info available.
#28 0x00005636e05047e1 in main ()
No symbol table info available.

Ctrl+C doesn't terminate the Server()

It seems that during the C library call to iperf_run_server(self._test) KeyboardInterrupt (aka Ctrl+C) isn't being passed onto the library. This causes the call to block indefinitely until either the server gets a client connection or the server process is killed.

A solution using threading has been proposed here but for the moment could not get it to work:
http://stackoverflow.com/questions/14271697/ctrlc-doesnt-interrupt-call-to-shared-library-using-ctypes-in-python

segmentationfault on debian 9

Hi,
i just tried to run iperf3-python on Debian Stetch. (iperf3 (and libiperf) installed from Debian apt repository. iperf3-python installed using pip.)

following code fails

>>> import iperf3
>>> i = iperf3.Server()
Speicherzugriffsfehler

I had a look at the code and found that it fails at line self.lib.iperf_defaults(self._test) in method defaults of class IPerf3. If i try to use libiperf in the same way iperf3-python does, it fails too. Problem seems to be, that the code is not defining restype and argtype properties for the used library functions.

OSError: [Errno 9] Bad file descriptor

Running following code, based mostly on this example produces error:

#!/usr/bin/env python3

import iperf3

client = iperf3.Client()
client.duration = 1
client.server_hostname = '127.0.0.1'
client.port = 5201

while True:
    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.sent_bytes))
        print('  retransmits        {0}'.format(result.retransmits))
        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.sent_bps))
        print('  Kilobits per second  (kbps)  {0}'.format(result.sent_kbps))
        print('  Megabits per second  (Mbps)  {0}'.format(result.sent_Mbps))
        print('  KiloBytes per second (kB/s)  {0}'.format(result.sent_kB_s))
        print('  MegaBytes per second (MB/s)  {0}'.format(result.sent_MB_s))
$ python3 iperf_client_test.py 
Connecting to 127.0.0.1:5201

Test completed:
  started at         Fri, 27 Sep 2019 07:42:40 GMT
  bytes transmitted  3696230400
  retransmits        28
  avg cpu load       61.11677%

Average transmitted data in all sorts of networky formats:
  bits per second      (bps)   29553560000.0
  Kilobits per second  (kbps)  29553560.0
  Megabits per second  (Mbps)  29553.56
  KiloBytes per second (kB/s)  3607612.3046875
  MegaBytes per second (MB/s)  3523.0588912963867
Connecting to 127.0.0.1:5201
Traceback (most recent call last):
  File "iperf_client_test.py", line 12, in <module>
    result = client.run()
  File "/usr/local/lib/python3.6/site-packages/iperf3/iperf3.py", line 629, in run
    output_to_screen(self._stdout_fd, self._stderr_fd)  # enable stdout
  File "/usr/local/lib/python3.6/site-packages/iperf3/iperf3.py", line 80, in output_to_screen
    os.dup2(stdout_fd, 1)
OSError: [Errno 9] Bad file descriptor
Exception ignored in: <bound method IPerf3.__del__ of <iperf3.iperf3.Client object at 0x7f2a943b27f0>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/iperf3/iperf3.py", line 213, in __del__
OSError: [Errno 9] Bad file descriptor

Same issue experienced with UDP client example. It always fails on second iteration of the test.
Additional details about test environment:

$ cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)

$ pip3 list
attrs (19.1.0)
Automat (0.7.0)
constantly (15.1.0)
filelock (3.0.12)
hyperlink (19.0.0)
idna (2.8)
incremental (17.5.0)
iperf3 (0.1.11)
pip (9.0.3)
prometheus-client (0.7.1)
PyHamcrest (1.9.0)
setuptools (39.2.0)
six (1.12.0)
Twisted (19.7.0)
zope.interface (4.6.0)

$ iperf3 -v 
iperf 3.1.7
Linux hostname 3.10.0-1062.1.1.el7.x86_64 #1 SMP Fri Sep 13 22:55:44 UTC 2019 x86_64
Optional features available: CPU affinity setting, IPv6 flow label, TCP congestion algorithm setting, sendfile / zerocopy, socket pacing

$ ps aux | grep iperf
nobody     1092  0.4  0.0   9616   992 ?        Ss   06:17   0:25 /usr/bin/iperf3 -s -f m -p 5201

Any ideas why it fails?

python3.10 support?

python3.10 is the python version included with the Ubuntu 22.04 LTS release. I'm finding that the iperf3 python module fails with this version. Example output:
File "/usr/local/share/lcwa-speed/lib/python3.10/site-packages/iperf3/iperf3.py", line 100, in __init__ lib_name = util.find_library('libiperf') File "/usr/lib/python3.10/ctypes/util.py", line 341, in find_library _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name)) File "/usr/lib/python3.10/ctypes/util.py", line 147, in _findLib_gcc if not _is_elf(file): File "/usr/lib/python3.10/ctypes/util.py", line 99, in _is_elf with open(filename, 'br') as thefile: FileNotFoundError: [Errno 2] No such file or directory: b'liblibiperf.a' Exception ignored in: <function IPerf3.__del__ at 0x7f07db2cb0a0> Traceback (most recent call last): File "/usr/local/share/lcwa-speed/lib/python3.10/site-packages/iperf3/iperf3.py", line 213, in __del__ os.close(self._stdout_fd) AttributeError: 'Client' object has no attribute '_stdout_fd'

Is support for this version contemplated to be released any time soon?

IPv6 Function

Hi , we are using 'iperf3-python' , but we don't know how to change IP address mode from 'IPv4' to 'IPv6' .
If we can change and use ''IPv6 function'' , please tell me how to use the function.

Issue When using UDP on OS X

Running the client/server locally on Mac OS X

I get a JSONDecodeError Expecting value: line 1 column 1 (char 0)

this is how the result looks like, there is Increasing socket buffer size to 66531 at the beginning, so when the TestResult object gets initialized I get that error

Increasing socket buffer size to 66531
{
	"start":	{
		"connected":	[{
				"socket":	9,
				"local_host":	"127.0.0.1",
				"local_port":	5201,
				"remote_host":	"127.0.0.1",
				"remote_port":	53766

Cannot run iperf on client with bind address

I'm trying to run server on 1 vm and client on other vm. so , i have to set client.bind_address which throws "unable to connect to server: Can't assign requested address".
So basically any client.bind_address with localhost throws the above error

iperf3 stops working after a while

Hello,

Let me explain the situation. I have a server that periodically sends commands to a bunch of clients (I have written the client and the server code), when the command is sent, the clients perform an iperf test.
The server runs iperf3 servers is separate processes (no python here, just plain terminal window). So the server is fine.
The client is using asyncio to run the code that accepts commands and then runs iper3 test. This works find for a while, but after a week or so, iper3 no longer runs any test. Here is the code for running the iper3 test:

MyFunction(protocol,duration,port):
client=iperf3.Client()
client.duration=int(duration)
client.port=port
client.bind_port=17801
client.server_hostname='IP address of the server machine'
client.protocol=protocol
client.reverse=True
a=client.run()
return a

The current parameter, with which the software runs fine for a while, are - protocol TCP, duration 10.
What happens is after a while, this code does not initiate a test. I can see whether a test is being run on the iperf server, and nothing happens. Not even an initiation of a connection. I can verify the code is running on the client as I have remote access to these client boxes. I use as px and I see the process running. On the same client box, where the script is failing, if I run the iperf3 test from the terminal it works fine, and I can see the test on the server as well.
I used strace on the process, and I get the following exception:

image

This is inline with client.run() not running the test for some reason.
The function above is run by asyncio that is run in the main thread.
I am going to continue troubleshooting, but it would be great if you can help me.

OS-CentOS Linux 7 (Core)
Python3 version Python 3.6.8

cpu_utilization_percent key not found at TestResult

Traceback (most recent call last):
File "/site-packages/iperf3/iperf3.py", line 701, in run
return TestResult(data_queue.get())
File "/site-packages/iperf3/iperf3.py", line 816, in init
cpu_utilization_perc = self.json['end']['cpu_utilization_percent']
KeyError: 'cpu_utilization_percent'

list index out of range

File "/script/iperf.py", line 30, in my_iperf3
return client.run()
File "/usr/local/lib/python3.7/dist-packages/iperf3/iperf3.py", line 621, in run
data = '{' + data.split('{', 1)[1]
IndexError: list index out of range

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.