def run_iperf_multi(self, obj, packet_type, update_interval, test_time, address): """ TODO :param obj: :param packet_type: :param update_interval: :return: """ self.pool = ThreadPool(1000) self.printing(True) if obj is not None: self.run_packet_script(obj, packet_type) result = TestResult(update_interval=update_interval, test_time=test_time, address=address) result.run_multi_test() Terminal.clear_line() self.printing(True) return result
def run_test_tcp(self, obj, packet_type): """ TODO This will run packet loss and return values of TCP retransmissions :param obj: :param packet_type: :return: """ self.pool = ThreadPool(1000) self.printing(False) self.run_packet_script(obj, packet_type) with self.time_limit(self.MAX_TEST_TIME): try: self.tcp_requests() except Exception: # If the request timed out os.system('rm -rf *.tmp') self.force_print( '## Timeout occurred! - Accuracy may be compromised') Terminal.clear_line() self.printing(True)
def printing(printing_on): """Used to stop printing when it isn't needed""" Terminal.clear_line() if printing_on: sys.stdout = sys.__stdout__ else: sys.stdout = open(os.devnull, 'w')
def user_input_thread(graph_active): """This thread is a listener for users input""" def reset_cursor(msg): """Used to stop input from messing up terminal format and displays what command was entered""" Terminal.clear_line() print('[{}]'.format(msg), end='\r', flush=True) while True: # HACK: Stops this from looping too fast and soaking up to much performance # A better solution would be to introduce events time.sleep(0.01) try: if keyboard.is_pressed('g'): # Waits until the key is released while keyboard.is_pressed('g'): pass if graph_active: # Clears any fragments from the screen including the button pressed Terminal.clear_line() affect_all_objects('graph') reset_cursor('Show graph') # More degradation elif keyboard.is_pressed('e'): # Waits until the key is released while keyboard.is_pressed('e'): pass affect_all_objects('increase') reset_cursor('Increase Effect') # Less degradation elif keyboard.is_pressed('q'): # Waits until the key is released while keyboard.is_pressed('q'): pass affect_all_objects('decrease') reset_cursor('Decrease Effect') except RuntimeError: pass
def start(self): # Test with a new packet value for effect_value in range(self.START_EFFECT_VALUE, self.MAX_EFFECT_VALUE + 1, self.EFFECT_STEP): test_data = [] # Repeats for that percentage values for x in range(0, self.REPEAT_TESTS): Terminal.clear_line() print('\n## Starting test {}'.format(x)) # CUSTOM BEHAVIOUR self.custom_test_behavior(effect_value, test_data) self.stop_pool() if test_data is not None: test_data.insert(0, effect_value) self.save_csv(test_data) print('## Tests done!') Terminal.clear_line()
def run_iperf_local(self, obj, packet_type): """ Runs a iperf test on the localhost. Iperf sends a huge amount of TCP packets and measures transfer rate :param update_interval: The amount of updates the iperf script gives per time, default 0 is off :param obj: - The script object :param packet_type: - The target packet :return: """ self.pool = ThreadPool(1000) self.printing(False) self.run_packet_script(obj, packet_type) result = TestResult() result.run_single_test() self.pool.close() Terminal.clear_line() self.printing(True) return result
def print_speeds(): Terminal.clear_line() print("[!] Download: {:.2f}Mbps - Upload: {:.2f}Mbps".format(DOWNLOAD, UPLOAD))
def print_clear(): """Method that is used to clear the output line, this is so no fragments are left after a stat print refresh""" Terminal.clear_line()
def reset_cursor(msg): """Used to stop input from messing up terminal format and displays what command was entered""" Terminal.clear_line() print('[{}]'.format(msg), end='\r', flush=True)