def test_bandwidth(self): client = iperf3.Client() client.bandwidth = 1 assert client.bandwidth == 1
def test_reverse_disabled(self): client = iperf3.Client() client.reverse = False assert not client.reverse
def test_error_to_string(self): client = iperf3.Client() assert client._error_to_string(1) == 'cannot be both server and client'
def test_verbose_disabled(self): client = iperf3.Client() client.verbose = False assert not client.verbose
def test_zerocopy_disabled(self): client = iperf3.Client() client.zerocopy = False assert not client.zerocopy
def test_json_output_enabled(self): client = iperf3.Client() client.json_output = True assert client.json_output
def test_json_output_disabled(self): client = iperf3.Client() client.json_output = False assert not client.json_output
def test_bind_address(self): """Test setting of the bind address is properly passed on to the iperf3 API""" client = iperf3.Client() client.bind_address = '127.0.0.1' assert client.bind_address == '127.0.0.1'
def test_server_hostname_empty(self): client = iperf3.Client() client.server_hostname = '' assert client.server_hostname == None
def test_role_property(self): client = iperf3.Client() assert client.role == 'c'
def test_bind_address_empty(self): """Test if we bind to any/all address when empty bind_address is passed""" client = iperf3.Client() client.bind_address = '' assert client.bind_address == '*'
def test_get_last_error(self): client = iperf3.Client() assert client._errno == 0
###End commands to submit changes### channel.send('end\n') time.sleep(1) ###Close Connections### channel.close ssh.close original_stdout = sys.stdout ###File to write perfomance output to### with open('FortiVPNbaseline.txt', 'w') as f: sys.stdout = f ###Call IPERF3### client = iperf3.Client() client.duration = 5 ###IPERF3 Server hostname or address### client.server_hostname = '192.168.1.10' ###IPERF3 Server Port### client.port = 4444 ###IPERF3 test protocol### client.protocol = 'tcp' ###IPERF3 test 1#### print('Connecting to {0}:{1} over {2} for baseline test 1'.format( client.server_hostname, client.port, client.protocol)) result = client.run() if result.error: print(result.error)
def main(argv): parser = argparse.ArgumentParser() bosdyn.client.util.add_common_arguments(parser) parser.add_argument('--protocol', default='tcp', type=str, choices=['tcp', 'udp'], help='IP Protocel to use, either tcp or udp.') parser.add_argument('--server-port', default=5201, type=int, help='Port number of iperf3 server') parser.add_argument('--server-hostname', default='127.0.0.1', type=str, help='IP address of ieprf3 server') options = parser.parse_args(argv) sdk = bosdyn.client.create_standard_sdk('CommsTestingClient', [MissionClient]) robot = sdk.create_robot(options.hostname) #ROBOT_IP robot.authenticate(options.username, options.password) robot.sync_with_directory() _robot_state_client = robot.ensure_client( RobotStateClient.default_service_name) _mission_client = robot.ensure_client(MissionClient.default_service_name) _robot_state_task = AsyncRobotState(_robot_state_client) _mission_state_task = AsyncMissionState(_mission_client) _task_list = [_robot_state_task, _mission_state_task] _async_tasks = AsyncTasks(_task_list) print('Connected.') update_thread = threading.Thread(target=_update_thread, args=[_async_tasks]) update_thread.daemon = True update_thread.start() # Wait for the first responses. while any(task.proto is None for task in _task_list): time.sleep(0.1) # list to hold all the data data_list = [] curr_fname = '' try: while True: if _mission_state_task.proto.status != mission_proto.State.STATUS_RUNNING: # Write out data if it exists if len(data_list) > 0: print( f'Finished a mission, data can be found in {curr_fname}' ) data_list.clear() print(_mission_state_task.proto) time.sleep(1) else: if _robot_state_task.proto: # This script currently uses odometry positioning, which is based on the robot's # position at boot time. Runs across boots will not be easily comparable odom_tform_body = get_odom_tform_body( _robot_state_task.proto.kinematic_state. transforms_snapshot).to_proto() helper_se3 = SE3Pose.from_obj(odom_tform_body) #check latency ping_ret = check_ping(options.server_hostname) ping = -1 if ping_ret is None else ping_ret['avg'] # Run iperf3 client client = iperf3.Client() client.duration = 1 client.server_hostname = options.server_hostname client.protocol = options.protocol client.port = options.server_port result = client.run() # update list of data points if result.error: print(result.error) else: data_entry = { 'loc_x': helper_se3.x, 'loc_y': helper_se3.y, 'loc_z': helper_se3.z, 'time': datetime.datetime.now(), 'latency(ms)': ping } if options.protocol == 'udp': data_entry.update({ 'send throughput(Mbps)': result.Mbps, 'recv throughput(Mbps)': -1, 'jitter(ms)': result.jitter_ms, 'lost(%)': result.lost_percent, 'retransmits': -1 }) elif options.protocol == 'tcp': data_entry.update({ 'send throughput(Mbps)': result.sent_Mbps, 'recv throughput(Mbps)': result.received_Mbps, 'jitter(ms)': -1, 'lost(%)': -1, 'retransmits': result.retransmits }) data_list.append(data_entry) print(data_list[-1]) # Create csv with header if it doesn't exist, then write latest row keys = data_list[0].keys() if curr_fname == '': curr_fname = create_csv_filename(options.protocol) with open(curr_fname, 'w') as output_file: header_writer = csv.DictWriter( output_file, keys) header_writer.writeheader() with open(curr_fname, 'a') as output_file: dict_writer = csv.DictWriter(output_file, keys) dict_writer.writerow(data_list[-1]) del client except KeyboardInterrupt: print("Caught KeyboardInterrupt, exiting") return True
sockH = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sockH.bind(("", HOST_PORT)) sockC = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sockC.sendto(b'req', (CLIENT_IP, CLIENT_PORT)) while True: data, addr = sockH.recvfrom(1024) dl_str = data.decode() DL = float(dl_str) / 1000 print(DL) if (dl_str == ''): continue else: break client = iperf3.Client() client.duration = 1 client.server_hostname = '192.168.1.43' client.port = 5201 client.protocol = 'udp' result = client.run() if result.error: print(result.error) else: bandwidth = result.Mbps total = bandwidth + DL print(result.Mbps) print('') print(total)
def test_duration(self): client = iperf3.Client() client.duration = 666 assert client.duration == 666
def test_num_streams(self): client = iperf3.Client() client.num_streams = 666 assert client.num_streams == 666
def test_iperf3_version(self): client = iperf3.Client() assert 'iperf' in client.iperf_version
def test_init_client(self): client = iperf3.Client() assert client._test
def test_bulksize(self): client = iperf3.Client() client.bulksize = 666 assert client.bulksize == 666
def test_verbose_enabled(self): client = iperf3.Client() client.verbose = True assert client.verbose
def test_protocol(self): client = iperf3.Client() client.protocol = SOCK_DGRAM assert client.protocol == SOCK_DGRAM
def test_zerocopy_enabled(self): client = iperf3.Client() client.zerocopy = True assert client.zerocopy
def test_wrong_bulksize_for_udp(self): client = iperf3.Client() client.protocol = SOCK_DGRAM client.bulksize = MAX_UDP_BULKSIZE + 1 assert client.bulksize <= MAX_UDP_BULKSIZE
def test_reverse_enabled(self): client = iperf3.Client() client.reverse = True assert client.reverse
def test_unavailable_library(self): with pytest.raises(OSError): client = iperf3.Client(lib_name='bla')
def test_get_last_error(self): client = iperf3.Client() print(client._error_to_string(client._errno)) assert client._errno == 111
def run_module(): # define available arguments/parameters a user can pass to the module argument_spec= (host=dict(type='str', required=True), duration=dict(type='int', defailt 1), bind_address=dict(type='str'), port=dict(type='int', default=5001), blksize=dict(type='int'), streams=dict(type='int', default=1), zerocopy=dict(type=True), verbose=dict(type='bool'), reverse=dict(type='bool', default=True), protocol=dict(type='str', choices=['tcp', 'udp'], default='tcp') ) # seed the result dict in the object # we primarily care about changed and state # change is if this module effectively modified the target # state will include any data that you want your module to pass back # for consumption, for example, in a subsequent task result = dict( changed=False, original_message='', message='' ) # the AnsibleModule object will be our abstraction working with Ansible # this includes instantiation, a couple of common attr would be the # args/params passed to the execution, as well as if the module # supports check mode module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, ) client = iperf3.Client() client.server_hostname = module.params['host'] if module.params['duration']: client.duration = module.params['duration'] if module.params['port']: client.port = module.params['port'] if module.params['protocol']: client.protocol = module.params['protocol'] if module.params['bind_address']: client.bind_address = module.params['bind_address'] if module.params['blksize']: client.blksize = module.params['blksize'] if module.params['streams']: client.num_streams = module.params['streams'] if module.params['zerocopy']: client.zerocopy = module.params['zerocopy'] if module.params['reverse']: client.reverse = module.params['reverse'] result['stats'] = client.run() # if the user is working with this module in only check mode we do not # want to make any changes to the environment, just return the current # state with no modifications if module.check_mode: return result # if the user is working with this module in only check mode we do not # want to make any changes to the environment, just return the current # state with no modifications # FIXME: Work with iperf3 so they can implement a check mode if module.check_mode: module.exit_json(**iperf3.result) # execute checks for argument completeness # manipulate or modify the state as needed (this is going to be the # part where your module will do what it needs to do) # in the event of a successful module execution, you will want to # simple AnsibleModule.exit_json(), passing the key/value results module.exit_json(**iperf3.result)
def test_lib_name(self): client = iperf3.Client(lib_name='libiperf.so.0') assert client._test
def _make_client(self): cl = iperf3.Client() cl.server_hostname = self.server cl.port = self.port cl.duration = self.duration return cl