def ftp(): if FTP_TIMETABLE_FILE != "": running_time_list = get_random_running_time(FTP_TIMETABLE_FILE) if running_time_list == None: print("no time interval matched current time") return print(running_time_list) for running_time in running_time_list: # Get the current time current_time = time_process.get_current_time() while (not time_process.compare_t2t(current_time, running_time)): sleep(1) current_time = time_process.get_current_time() # Get a random from the first three ones in users list # The new created users (for some reason) cannot login ftp server yet username, passwd = get_random_user(users) print(username, passwd) if ftp_actions.connect(FTP_SERVER, username, passwd) == 0: ftp_actions.get_file(download_dir) ftp_actions.clean_download_dir(download_dir) ftp_actions.quit_session() else: for i in range(0, NUM_CON): now = time.time() username, passwd = get_random_user(users) if ftp_actions.connect(FTP_SERVER, username, passwd) == 0: ftp_actions.get_file(download_dir) ftp_actions.clean_download_dir(download_dir) ftp_actions.quit_session() then = time.time() print(then - now)
def intranet(): count = 0 count_https = 0 tmp = "" if INTRANET_TIMETABLE_FILE != "": running_time_list, running_time_list_random = get_running_time( INTRANET_TIMETABLE_FILE) print(running_time_list) if (len(running_time_list) == 0): print("no time interval matched current time") return # Calculate http and https connection total_cnx = len(running_time_list) https_cnx = int(total_cnx * RATIO_HTTPS) current_time = time_process.get_current_time() # If current time is earlier than the interval while (not time_process.compare_t2t(current_time, running_time_list[0])): sleep(1) current_time = time_process.get_current_time() # If current time is in the interval already, then only excuse connections # which are later than the current time while True: # Get current time current_time = time_process.get_current_time() #print("current_time:" + current_time) # If the current time is out of interval, break if (time_process.compare_t2t(current_time, running_time_list[-1])): break # If current time is in the running_time_list, run if current_time in running_time_list and current_time != tmp: tmp = current_time count += 1 # Get http or https connection randomly if count_https < https_cnx: k = random.randint(0, 1) if k == 0: # HTTP connection #http_actions.read_event("http", intranet_http_site_list, intranet_https_site_list) #http_actions.read_event("http", intranet_http_site_list, intranet_https_site_list) http_actions.read_event("http") http_actions.read_event("http") else: # HTTPS connection http_actions.read_event("https") http_actions.read_event("https") count_https += 1 else: http_actions.read_event("http") http_actions.read_event("http") # If not, sleep one sec and check again else: sleep(1) print(count) else: for i in range(0, NUM_CXN): http_actions.read_event("https")
def smtp(): send_type = ["group", "random", "broadcast"] if SENDMAIL_TIMETABLE_FILE != "": running_time_list = get_random_running_time(SENDMAIL_TIMETABLE_FILE) if running_time_list == None: print("no time interval matched current time") return for running_time in running_time_list: print(running_time) num_cxn = len(running_time_list) num_conn_group = rand_funcs.float_to_int(num_cxn * 0.6) num_conn_rand = rand_funcs.float_to_int(num_cxn * 0.3) num_conn_brc = rand_funcs.float_to_int(num_cxn * 0.1) num_group_temp = num_conn_group num_rand_temp = num_conn_rand num_brc_temp = num_conn_brc for running_time in running_time_list: # Get the current time current_time = time_process.get_current_time() while (not time_process.compare_t2t(current_time, running_time)): sleep(1) current_time = time_process.get_current_time() num_group_temp, num_rand_temp, num_brc_temp = one_send_email( send_type, num_group_temp, num_rand_temp, num_brc_temp) else: num_conn_group = rand_funcs.float_to_int(NUM_CXN * 0.6) num_conn_rand = rand_funcs.float_to_int(NUM_CXN * 0.3) num_conn_brc = rand_funcs.float_to_int(NUM_CXN * 0.1) num_group_temp = num_conn_group num_rand_temp = num_conn_rand num_brc_temp = num_conn_brc num_try = 0 for i in range(0, NUM_CXN): num_group_temp, num_rand_temp, num_brc_temp = one_send_email( send_type, num_group_temp, num_rand_temp, num_brc_temp)
def livestream(): count = 0 tmp = "" if LIVESTR_TIMETABLE_FILE != "": running_time_list, running_time_list_random = get_running_time( LIVESTR_TIMETABLE_FILE) if (len(running_time_list) == 0): print("no time interval matched current time") return current_time = time_process.get_current_time() # If current time is earlier than the interval while (not time_process.compare_t2t(current_time, running_time_list[0])): sleep(1) current_time = time_process.get_current_time() # If current time is in the interval already, then only excuse connections # which are later than the current time while True: # Get current time current_time = time_process.get_current_time() #print("current_time:" + current_time) # If the current time is out of interval, break if (time_process.compare_t2t(current_time, running_time_list[-1])): break # If current time is in the running_time_list, run if current_time in running_time_list and current_time != tmp: tmp = current_time count += 1 http_actions.live_stream(livestr_site_list, tapas_dir) # If not, sleep one sec and check again else: sleep(1) print(count) else: for i in range(0, NUM_CXN): http_actions.live_stream(livestr_site_list, tapas_dir)
def get_random_running_time(timetable): # List of running time running_time_list = [] # Get the current time current_time = time_process.get_current_time() # Get the corresponding time_interval and numsession from the mail_timetable file interval_numsession_dict = timetable_process.get_time_interval( current_time, timetable) if interval_numsession_dict == None: return else: running_time_list = time_process.generate_random_running_time( interval_numsession_dict) return running_time_list
def imap(): if READMAIL_TIMETABLE_FILE != "": running_time_list = get_random_running_time(READMAIL_TIMETABLE_FILE) if running_time_list == None: print("no time interval matched current time") return #for running_time in running_time_list: # print(running_time) num_cxn = len(running_time_list) num_readmail_mean = rand_funcs.float_to_int(num_cxn * 0.5) num_reply_mean = rand_funcs.float_to_int(num_readmail_mean * 0.3) print("num_conn, num_readmail_mean, num_reply_mean", num_cxn, num_readmail_mean, num_reply_mean) for running_time in running_time_list: # Get the current time current_time = time_process.get_current_time() while (not time_process.compare_t2t(current_time, running_time)): sleep(1) current_time = time_process.get_current_time() one_read_email(num_readmail_mean, num_reply_mean) else: num_readmail_mean = rand_funcs.float_to_int(NUM_CXN * 0.5) num_reply_mean = rand_funcs.float_to_int(num_readmail_mean * 0.3) print("num_conn, num_readmail_mean, num_reply_mean", NUM_CXN, num_readmail_mean, num_reply_mean) for i in range(0, NUM_CXN): now = time.time() one_read_email(num_readmail_mean, num_reply_mean) then = time.time() print(then - now)