예제 #1
0
def single_pass_server():
    import iperf3
    server = iperf3.Server()
    server.bind_address = serv
    server.port = 5201
    server.verbose = False
    server.run()
예제 #2
0
 def start_iperf_server(self, iperf_server):
     logging.debug(iperf_server.__str__())
     server = iperf3.Server()
     server.bind_address = iperf_server.address
     server.port = iperf_server.port
     #server.verbose = False
     print("Server listening on " + str(server.port))
     result = server.run()
예제 #3
0
 def start_iperf3_server(self):
     #creates an iperf3 server. only lasts for one measurement. putting in a while 1 causes udp problems
     print("Starting iperf server for throughput")
     server = iperf3.Server()
     server.bind_address = self.ip 
     server.port = 6969
     server.verbose = False
     server.run()
def create_server():
    if request.headers['Content-Type'] == 'application/json':
        name = str(request.json['name'])
    else:
        return make_response(jsonify(_error("Server creation Failed : Please provide Server 'name'!"))), 500
    server = iperf3.Server()
    server.json_output = False
    _servers.register(server, name)
    return make_response(jsonify(_success(request.data)), 201)
예제 #5
0
def start_bw_stats_server():
    import iperf3

    server = iperf3.Server()
    server.port = 6969
    server.verbose = False
    server.json_output = False
    while True:
        server.run()
예제 #6
0
def iperfServer():
    server = iperf3.Server()
    server.bind_address = '10.221.109.28'
    server.port = '5201'
    server.verbose = False
    while True:
        print('#################################\n')
        print('##### Iperf3 Server Running #####\n')
        print('#################################\n')
        server.run()
    def test_server_failed_run(self):
        """This test will launch two server instances on the same ip:port
        to generate an error"""
        server = iperf3.Server()
        server.bind_address = '127.0.0.1'
        server.port = 5201

        server2 = subprocess.Popen(["iperf3", "-s"])
        sleep(.3)  # give the server some time to start

        response = server.run()
        server2.kill()

        assert "unable to start listener for connections: " in response.error
예제 #8
0
파일: main.py 프로젝트: lvillis/Dockerfiles
def main():
    server = iperf3.Server()
    server.bind_address = SERVER
    server.port = PORT
    server.verbose = VERBOSE
    logger.info(f"iperf3 server: {SERVER} port: {PORT} verbose: {VERBOSE}")
    while True:
        try:
            res = server.run()
            logger.info(
                f"server:{get_local_ip()} sender:{res.sent_Mbps} receiver:{res.received_Mbps} "
                f"From client:{res.remote_host} {res.receiver_tcp_congestion}")
        except Exception as e:
            logger.error(e)
    def test_server_run_output_to_screen(self):
        server = iperf3.Server()
        server.bind_address = '127.0.0.1'
        server.port = 5206
        server.json_output = False

        # Launching the client with a sleep timer to give our server some time to start
        client = subprocess.Popen(
            'sleep .5 && iperf3 -c 127.0.0.1 -p 5206 -t 1',
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        response = server.run()
        client.kill()

        assert not response
예제 #10
0
    def test_server_run(self):
        server = iperf3.Server()
        server.bind_address = '127.0.0.1'
        server.port = 5201

        # Launching the client with a sleep timer to give our server some time to start
        client = subprocess.Popen('sleep .5 && iperf3 -c 127.0.0.1 5201 -t 1',
                                  shell=True,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
        response = server.run()
        client.kill()

        assert not response.error
        assert response.local_host == '127.0.0.1'
        assert response.local_port == 5201
def launchIperf3Server(**kwargs):
    print(f"iperf server, kwargs: {kwargs}")
    iperfServer = iperf3.Server()
    iperfServer.bind_address = kwargs['iperf3BindAddress']
    iperfServer.port = kwargs['iperf3ServerPort']
    iperfServer.verbose = False
    res = None
    try:
        res = iperfServer.run()
        res = res.json
    except:
        print('it fails!')
    print("writing results")
    global testResults
    #global awaitingResults
    print(type(testResults))
    testResults = res
예제 #12
0
def main(args):
    server = iperf3.Server()
    server.port = int(os.environ.get("PORT"))
    result = server.run()
    data = {}
    edge_ip = result.json['start']['connected'][0]['remote_host']
    data[edge_ip] = {}
    # data[edge_ip]['bandwidth'] = result.json['end']['sum_received']['bits_per_second']

    # Get individual readings throughout the iperf test
    intervals = result.json['intervals']

    last = intervals.pop()['sum']['bytes'] * 8 # remove last reading, get bits transmitted
    count = len(intervals)
    
    readings = [ ] # store bandwidth for all readings
    for reading in intervals:
        # readings.append(reading['sum']['bits_per_second']) # old

        # Combine last bytes into the other readings (that's what iperf does)
        readings.append(reading['sum']['bytes']*8 + last/count)

    data[edge_ip]['readings'] = readings
    data[edge_ip]['bandwidth'] = sum(readings)/90 # len(readings)
    # ^ len(readings) can be 92 or 93, we discard the last results later and
    # combine them into the readings later.

    #print(result.text)
    #print(json.dumps(result.json, indent=3))
    #print(result.json['end']['sum_received']['bits_per_second'])

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        while True:
            print("Attempting to connect to bandwidth server", file=sys.stderr)
            try:
                s.connect(("127.0.0.1", 20000))
                break
            except BaseException:
                print(("Error connecting to bandwidth server"),
        file=sys.stderr)

        print("Successfully connected to bandwidth server", file=sys.stderr)

        print("Sending json data")
        s.sendall(json.dumps(data).encode())
        print("Successfully sent json data")
예제 #13
0
 def _setup_iperf3(self):
     ''' Set up the iperf3 servers for the test instances. Must be run on a
     main thread '''
     self._iperfs = ()
     for instance in self._instances:
         if instance.is_uplink:
             iperf = iperf3.Server()
             iperf.bind_address = '192.168.129.42'
             iperf.port = TrafficTestDriver._get_port()
         else:
             iperf = iperf3.Client()
             iperf.bandwidth = 10 ** 7  # 10 Mbps
             iperf.bind_address = '192.168.129.42'
             iperf.duration = instance.duration
             iperf.port = instance.port
             iperf.protocol = 'udp' if instance.is_udp else 'tcp'
             iperf.server_hostname = instance.ip.exploded
         self._iperfs += (iperf,)
예제 #14
0
def IPERF3_nonXLSX():
    if 'client' in Modeq.lower():
        iperf3test = iperf3.Client()
        iperf3test.server_hostname = Serverq
        iperf3test.duration = Durationq
        iperf3test.protocol = Protocolq
        iperf3test.bandwidth = int(Bandwidthq)
        if 'true' in Reversemodeq.lower():
            iperf3test.reverse = 1
    if 'server' in Modeq.lower():
        iperf3test = iperf3.Server()
        iperf3test.bind_address = Serverq
    iperf3test.port = Portq
    if 'True' in QuietModeq:
        iperf3test.json_output = True
        iperf3test.verbose = False
    # Client Portion
    if 'client' in Modeq.lower():
        print('Connecting to {0}:{1}'.format(iperf3test.server_hostname,
                                             iperf3test.port))
        result = iperf3test.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))
    # Server Portion
    if 'server' in Modeq.lower():
        while True:
            iperf3test.run()
예제 #15
0
    def test_server_run(self):
        server = iperf3.Server()
        server.bind_address = '127.0.0.1'
        server.port = 5205

        # Launching the client with a sleep timer to give our server some time to start
        client = subprocess.Popen(
            'sleep .5 && iperf3 -c 127.0.0.1 -p 5205 -t 1',
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        response = server.run()

        if server.iperf_version.startswith(
                'iperf 3.0') or server.iperf_version.startswith('iperf 3.1'):
            assert not response.error
            assert response.local_host == '127.0.0.1'
            assert response.local_port == 5205
            assert response.type == 'server'
        else:
            assert response.error == 'the client has unexpectedly closed the connection'
예제 #16
0
 def _setup_iperf3(self):
     ''' Set up the iperf3 servers for the test instances. Must be run on a
     main thread '''
     self._iperfs = ()
     for instance in self._instances:
         if instance.is_uplink:
             iperf = iperf3.Server()
             ip_str = ipaddress.ip_address(instance.ip)
             if ip_str.version == 4:
                 print("Running ipv4")
                 iperf.bind_address = self._trfserver_ipv4
             else:
                 print("Running ipv6")
                 iperf.bind_address = self._trfserver_ipv6
                 os.system('sudo /sbin/ip -6 route add %s/%d dev eth3' %
                           (self._agw_ipv6, self._agw_ip_sub))
                 os.system('sudo /sbin/ip -6 route add %s via %s dev eth3' %
                           (instance.ip.exploded, self._agw_ipv6))
             iperf.port = TrafficTestDriver._get_port()
         else:
             iperf = iperf3.Client()
             iperf.bandwidth = 10**7  # 10 Mbps
             ip_str = ipaddress.ip_address(instance.ip)
             if ip_str.version == 4:
                 iperf.bind_address = self._trfserver_ipv4
             else:
                 iperf.bind_address = self._trfserver_ipv6
                 os.system('sudo /sbin/ip -6 route add %s/%d dev eth3' %
                           (self._agw_ipv6, self._agw_ip_sub))
                 os.system('sudo /sbin/ip -6 route add %s via %s dev eth3' %
                           (instance.ip.exploded, self._agw_ipv6))
             iperf.duration = instance.duration
             iperf.port = instance.port
             iperf.protocol = 'udp' if instance.is_udp else 'tcp'
             iperf.server_hostname = instance.ip.exploded
         self._iperfs += (iperf, )
예제 #17
0
 def test_init_server(self):
     server = iperf3.Server()
     assert server._test
예제 #18
0
#!/usr/bin/env python

import sys
import iperf3

server = iperf3.Server()

while True:
    server.run()
예제 #19
0
 def __init__(self):
     super().__init__()
     self.server = iperf3.Server()
     self.stop_iperf = threading.Event()
     self.daemon = True
     threading.Thread.__init__(self)
예제 #20
0
def IPERF3_XLSX(rowdata):
    t = threading.currentThread()
    while getattr(t, "do_run", True) and runtime < maxruntime:
        sshdevicetype = 'linux'
        # Device Configuration
        try:
            remotedevice = rowdata.get('Remote Device').encode('utf-8')
        except:
            remotedevice = rowdata.get('Remote Device')
            remotedevice = str(remotedevice)
        try:
            Modeq = rowdata.get('Mode').encode('utf-8')
        except:
            Modeq = rowdata.get('Mode')
            Modeq = str(Modeq)
        try:
            Durationq = rowdata.get('Duration').encode('utf-8')
        except:
            Durationq = rowdata.get('Duration')
            Durationq = str(Durationq)
        try:
            Serverq = rowdata.get('Server').encode('utf-8')
        except:
            Serverq = rowdata.get('Server')
            Serverq = str(Serverq)
        try:
            Portq = rowdata.get('Port').encode('utf-8')
        except:
            Portq = rowdata.get('Port')
            Portq = str(Portq)
        try:
            Protocolq = rowdata.get('Protocol').encode('utf-8')
        except:
            Protocolq = rowdata.get('Protocol')
            Protocolq = str(Protocolq)
        try:
            Bandwidthq = rowdata.get('Target Bandwidth').encode('utf-8')
        except:
            Bandwidthq = rowdata.get('Target Bandwidth')
            Bandwidthq = str(Bandwidthq)
        try:
            Reversemodeq = rowdata.get('Reverse Mode').encode('utf-8')
        except:
            Reversemodeq = rowdata.get('Reverse Mode')
            Reversemodeq = str(Reversemodeq)
        #Start Connection
        try:
            sshnet_connect = ConnectHandler(device_type=sshdevicetype,
                                            ip=remotedevice,
                                            username=sshusername,
                                            password=sshpassword)
            sshdevicehostname = sshnet_connect.find_prompt()
            print 'Successfully connected to ' + remotedevice
            if 'client' in Modeq.lower():
                iperf3test = iperf3.Client()
                iperf3test.server_hostname = Serverq
                iperf3test.duration = Durationq
                iperf3test.protocol = Protocolq
                iperf3test.bandwidth = int(Bandwidthq)
                if 'true' in Reversemodeq.lower():
                    iperf3test.reverse = 1
            if 'server' in Modeq.lower():
                iperf3test = iperf3.Server()
                iperf3test.bind_address = Serverq
            iperf3test.port = Portq
            # Client Portion
            if 'client' in Modeq.lower():
                print('Connecting to {0}:{1}'.format(
                    iperf3test.server_hostname, iperf3test.port))
                result = iperf3test.run()
                writer.writerow({
                    'Device IP': remotedevice,
                    'Start Time': iperf3test.time,
                    'Average CPU Load': iperf3test.local_cpu_total,
                    'Total Bytes Transmitted': iperf3test.bytes,
                    'Mbps': iperf3test.Mbps,
                    'Average Jitter': iperf3test.jitter_ms
                })
            # Server Portion
            if 'server' in Modeq.lower():
                while True:
                    iperf3test.run()
            sshnet_connect.disconnect()
        except:
            print "Failure in connecting to device " + sshdevicename + ". Please confirm that the IP address is correct"
            sshnet_connect.disconnect()
    print("Stopping as you wish.")
    try:
        sshnet_connect.disconnect()
    except:
        ''' Skip '''
def iperf():
    server = iperf3.Server()
    result = server.run()
    return (result.remote_host)
예제 #22
0
 def test_port(self):
     server = iperf3.Server()
     server.port = 666
     assert server.port == 666
예제 #23
0
 def server(self):
     print("The Iperf server is running...")
     server = iperf3.Server()
     result = server.run()
예제 #24
0
 def test_server_hostname(self):
     client = iperf3.Server()
     client.server_hostname = '127.0.0.1'
     assert client.server_hostname == '127.0.0.1'
예제 #25
0
import requests
import socket
import iperf3 as iperf
from iperf_utils import show, dump, get_config
hostname = socket.gethostname()

conf = get_config()

server = iperf.Server()

for section in conf:
    if section.startswith('server'):
        c = conf[section]
        if c.get('skip'):
            continue
        port = int(c.get('port', 5001))
        host = c['host']  # host IP or name
        label = c.get('label', section)
        if c.get('hostname') == hostname:
            server.port = port
            break
else:
    raise ValueError(
        f'Hostname `{hostname}` needs to be registered in pearu-sandbox/iperf-bench/config.conf'
    )

fn = f'server-{hostname}.txt'
print(f'output: {fn}. Press Ctrl-C to stop the server.')
f = open(fn, 'a+')
while 1:
    try: