def gen_stf(): trex = CTRexClient('127.0.0.1') print("Before Running, TRex status is: %s", trex.is_running()) print("Before Running, TRex status is: %s", trex.get_running_status()) ret = trex.start_trex(c=1, m=0.1, d=int(args.duration), f='mydns_traffic.yaml', nc=True) print("After Starting, TRex status is: %s %s", trex.is_running(), trex.get_running_status()) time.sleep(int(args.duration)) while trex.is_running(): time.sleep(5) print("Is TRex running? %s %s", trex.is_running(), trex.get_running_status())
def restart_stl_mode(ip): try: trex = CTRexClient(ip) if trex.get_running_status()['state'] == TRexStatus.Idle: # print('trex server process is not running') return False else: trex.force_kill(confirm=False) time.sleep(1) # 4 if trex.get_running_status()['state'] == TRexStatus.Idle: print("Success killed server, ip:" + ip) return True except Exception as e: print( 'Error occurred when automatically resetting up trex stateless server at: ' + ip) print(e) return False
def start_stl_mode(ip): try: trex = CTRexClient(ip) if trex.get_running_status()['state'] == TRexStatus.Running: # print('server has already running') print('ip: ' + ip + ' server has started!') else: trex.start_stateless() time.sleep(1) # 4 if trex.get_running_status()['state'] == TRexStatus.Running: print("Success start, ip:" + ip) return True except Exception as e: print( '\nError occurs when automatically starting up trex stateless server at: ' + ip + '\n') print(e) return False