def test_throughput_with_different_CFP(CFP_list=[0.2, 0.5, 1, 2, 4]): print("start the test: throughput with different contention-free period") throughput_with_different_CFP = [] for CFP in CFP_list: ws_line = 0 test_times = 500 for times in range(test_times): pFHMAC_throughput = [] for num_stations in numOfstations_list: stations_pos = np.array( genToplogy.rnd_top_square(num_node=num_stations)) matSIR = genMatSIR(stations_pos) traffic_amount = 0 for j in range(20000): upstream, downstream = trafficHandler.generateUDtraffic( len(matSIR), 1, 1, True) traffic_amount += np.sum(np.array(upstream)) + np.sum( np.array(downstream)) # start the contention free period if j == 0: [curr_down_time, curr_up_time ] = pFHMAC.contention_free_inital_stage_sim(matSIR) [ curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay ] = pFHMAC.greedyPolling( matSIR, upstream, downstream, curr_up_time, curr_down_time, [-1, -1], np.zeros((len(matSIR), ), dtype=np.int32), np.zeros((len(matSIR), ), dtype=np.int32)) else: [ curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay ] = pFHMAC.greedyPolling(matSIR, upstream, downstream, curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay) # checkout whether the contention free period is over, period = 100ms, that is 10**5 us if max(curr_down_time, curr_up_time) > CFP * 10**5: break # record the throughput pFHMAC_throughput.append(traffic_amount * 8 / max(curr_down_time, curr_up_time)) write2xls(pFHMAC_throughput, ws_line, CFP_list.index(CFP) + 1) ws_line += 1 if times == 0: array_pFDMAC_throughput = np.array(pFHMAC_throughput) else: array_pFDMAC_throughput += np.array(pFHMAC_throughput) throughput_with_different_CFP.append(array_pFDMAC_throughput / test_times) ws_line += 2 write2xls(array_pFDMAC_throughput / test_times, ws_line, CFP_list.index(CFP) + 1) throughput_with_different_CFP = np.array(throughput_with_different_CFP) print( "throghtput(different protocols) with different Contetion-free period:" ) print(throughput_with_different_CFP.tolist()) print("End the test: throughput with different contention-free period") print( "####################################################################################################" )
def test_APPower_with_saturated_traffic(): deltaPower = [-20, -10, 0, 10, 20, 30] throughput = [] delay = [] for numStation in numOfstations_list: throughput_deltaP = [] delay_deltaP = [] stations_pos = np.array(genToplogy.rnd_top_square(num_node=numStation)) for dp in deltaPower: # matSIR = genMatSIR(stations_pos,dp) matSIR = genMatSIR_directional(stations_pos, AP_pos, dp) # print(matSIR) traffic_amount = 0 count_round = 0 for j in range(20000): # saturated traffic with different packet length upstream, downstream = trafficHandler.generateUDtraffic( len(matSIR), 1, 1, True, 1024) traffic_amount += np.sum(np.array(upstream)) + np.sum( np.array(downstream)) # start the contention free period if j == 0: [curr_down_time, curr_up_time ] = pFHMAC.contention_free_inital_stage_sim(matSIR) [ curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay ] = pFHMAC.greedyPolling( matSIR, upstream, downstream, curr_up_time, curr_down_time, [-1, -1], np.zeros((len(matSIR), ), dtype=np.int32), np.zeros((len(matSIR), ), dtype=np.int32)) else: [ curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay ] = pFHMAC.greedyPolling(matSIR, upstream, downstream, curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay) count_round += 1 # checkout whether the contention free period is over, period = 100ms, that is 10**5 us if max(curr_down_time, curr_up_time) > 10**5: # print('time out!') break # record the throughput throughput_deltaP.append(traffic_amount * 8 / max(curr_down_time, curr_up_time)) delay_deltaP.append( max(curr_down_time, curr_up_time) / count_round) throughput.append(throughput_deltaP) delay.append(delay_deltaP) delay = list(np.array(delay) / 1000) # print(throughput, delay) throughput = np.transpose(np.array(throughput)).tolist() delay = np.transpose(np.array(delay)).tolist() return throughput, delay
def test_different_trafficType(): throughput = [] delay = [] for i in range(5): throughput_t = [] delay_t = [] for numStation in numOfstations_list: stations_pos = np.array( genToplogy.rnd_top_square(num_node=numStation)) matSIR = genMatSIR(stations_pos) # matSIR = makeAllFullDuplex(matSIR) # matSIR = genMatSIR_directional(stations_pos,AP_pos) # print(matSIR) traffic_amount = 0 count_round = 0 for j in range(20000): # saturated traffic with different packet length if i == 0: # saturated traffic with the same packet length upstream, downstream = trafficHandler.generateUDtraffic( len(matSIR), 1, 1, True) elif i == 1: # only upstream, nothing to download upstream, downstream = trafficHandler.generateUDtraffic( len(matSIR), 1, 0, True) elif i == 2: # only downstream, nothing to upload upstream, downstream = trafficHandler.generateUDtraffic( len(matSIR), 0, 1, True) elif i == 3: # typical asymmetric traffic upstream, downstream = trafficHandler.genAsymmetricTraffic( len(matSIR), True) elif i == 4: # random traffic upstream, downstream = trafficHandler.generateUDtraffic( len(matSIR), 0.5, 0.5, True) traffic_amount += np.sum(np.array(upstream)) + np.sum( np.array(downstream)) # start the contention free period if j == 0: [curr_down_time, curr_up_time ] = pFHMAC.contention_free_inital_stage_sim(matSIR) [ curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay ] = pFHMAC.greedyPolling( matSIR, upstream, downstream, curr_up_time, curr_down_time, [-1, -1], np.zeros((len(matSIR), ), dtype=np.int32), np.zeros((len(matSIR), ), dtype=np.int32)) else: [ curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay ] = pFHMAC.greedyPolling(matSIR, upstream, downstream, curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay) count_round += 1 # checkout whether the contention free period is over, period = 100ms, that is 10**5 us if max(curr_down_time, curr_up_time) > 10**5: # print('time out!') break # record the throughput throughput_t.append(traffic_amount * 8 / max(curr_down_time, curr_up_time)) delay_t.append(max(curr_down_time, curr_up_time) / count_round) throughput.append(throughput_t) delay.append(delay_t) tmp1 = np.array(delay) / 1000 delay = tmp1.tolist() # print(throughput, delay) return throughput, delay
def test_performance_with_saturated_traffic(): throughput = [] delay = [] ALL_throughput = [] ALL_delay = [] PCF_throughput = [] PCF_delay = [] for numStation in numOfstations_list: stations_pos = np.array(genToplogy.rnd_top_square(num_node=numStation)) matSIR = genMatSIR(stations_pos) all_matSIR = genMatSIR_directional(stations_pos) # print(matSIR.tolist()) # print(all_matSIR.tolist()) traffic_amount = 0 count_round = 0 for j in range(20000): # saturated traffic with different packet length upstream, downstream = trafficHandler.generateUDtraffic( len(matSIR), 1, 1, True, 1024) traffic_amount += np.sum(np.array(upstream)) + np.sum( np.array(downstream)) # start the contention free period if j == 0: [curr_down_time, curr_up_time ] = pFHMAC.contention_free_inital_stage_sim(matSIR) [ curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay ] = pFHMAC.greedyPolling( matSIR, upstream, downstream, curr_up_time, curr_down_time, [-1, -1], np.zeros((len(matSIR), ), dtype=np.int32), np.zeros((len(matSIR), ), dtype=np.int32)) [curr_down_time1, curr_up_time1 ] = pFHMAC.contention_free_inital_stage_sim(all_matSIR) [ curr_up_time1, curr_down_time1, last_station1, ACK_up1, ACK_down1, oRateL, LDpay ] = pFHMAC.greedyPolling( all_matSIR, upstream, downstream, curr_up_time1, curr_down_time1, [-1, -1], np.zeros((len(all_matSIR), ), dtype=np.int32), np.zeros((len(all_matSIR), ), dtype=np.int32), oRateL, LDpay) [PCF_timer, PCF_ACK] = PCF.PCF_sim(upstream, downstream, current_time=0, need_ACK=False, Vt=18) else: [ curr_up_time, curr_down_time, last_station, ACK_up, ACK_down, oRateL, LDpay ] = pFHMAC.greedyPolling(matSIR, upstream, downstream, curr_up_time, curr_down_time, last_station, ACK_up, ACK_down) [ curr_up_time1, curr_down_time1, last_station1, ACK_up1, ACK_down1, oRateL, LDpay ] = pFHMAC.greedyPolling(all_matSIR, upstream, downstream, curr_up_time1, curr_down_time1, last_station1, ACK_up1, ACK_down1, oRateL, LDpay) [PCF_timer, PCF_ACK] = PCF.PCF_sim(upstream, downstream, PCF_timer, PCF_ACK, Vt=18) count_round += 1 # checkout whether the contention free period is over, period = 100ms, that is 10**5 us if max(curr_down_time, curr_up_time) > 10**5: # print('time out!') break # record the throughput throughput.append(traffic_amount * 8 / max(curr_down_time, curr_up_time)) PCF_throughput.append(traffic_amount * 8 / PCF_timer) ALL_throughput.append(traffic_amount * 8 / max(curr_down_time1, curr_up_time1)) delay.append(max(curr_down_time, curr_up_time) / count_round) PCF_delay.append(PCF_timer / count_round) ALL_delay.append(max(curr_up_time1, curr_down_time1) / count_round) delay = list(np.array(delay) / 1000) PCF_delay = list(np.array(PCF_delay) / 1000) ALL_delay = list(np.array(ALL_delay) / 1000) global ws_line write2xls(ALL_throughput, ws_line, 1) write2xls(ALL_delay, ws_line, 2) write2xls(throughput, ws_line, 3) write2xls(delay, ws_line, 4) write2xls(PCF_throughput, ws_line, 5) write2xls(PCF_delay, ws_line, 6) ws_line += 1 return [ALL_throughput, throughput, PCF_throughput], [ALL_delay, delay, PCF_delay]