Exemple #1
0
def test_Janus_scheduler():
    # in this test program, the Janus exchange period will be discussed and test the throughput under different traffic.
    throughput = []
    for i in range(5):
        throughput_t = []
        for numStation in numOfstations_list:
            stations_pos = np.array(
                genToplogy.rnd_top_square(num_node=numStation))
            matSIR = genMatSIR(stations_pos)
            matSIR = makeAllFullDuplex(matSIR)
            traffic_amount = 0
            for j in range(200):
                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, last_dSta, last_uSta, last_op_rate, last_packet_length] \
                        = Janus.Janus_sim_exchange_period(upstream, downstream,matSIR)
                    # print(curr_down_time, curr_up_time)
                else:
                    [curr_down_time, curr_up_time, last_dSta, last_uSta, last_op_rate, last_packet_length] \
                        = Janus.Janus_sim_exchange_period(upstream, downstream, matSIR,curr_down_time, curr_up_time,
                                                          last_dSta, last_uSta, last_op_rate, last_packet_length)

                # 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))
        throughput.append(throughput_t)
    # print(throughput, delay)
    return throughput
Exemple #2
0
def test_PCF_traffic():
    throughput = []
    delay = []
    for i in range(5):
        throughput_tmp = []
        delay_tmp = []
        for Station_num in numOfstations_list:
            traffic_amount = 0
            for j in range(100):
                # saturated traffic with different packet length
                if i == 0:  # saturated traffic with the same packet length
                    upstream, downstream = trafficHandler.generateUDtraffic(
                        Station_num, 1, 1, True)
                elif i == 1:  # only upstream, nothing to download
                    upstream, downstream = trafficHandler.generateUDtraffic(
                        Station_num, 1, 0, True)
                elif i == 2:  # only downstream, nothing to upload
                    upstream, downstream = trafficHandler.generateUDtraffic(
                        Station_num, 0, 1, True)
                elif i == 3:  # typical asymmetric traffic
                    upstream, downstream = trafficHandler.genAsymmetricTraffic(
                        Station_num, True)
                elif i == 4:  # random traffic
                    upstream, downstream = trafficHandler.generateUDtraffic(
                        Station_num, 0.5, 0.5, True)
                traffic_amount += np.sum(np.array(upstream)) + np.sum(
                    np.array(downstream))

                if not j:
                    [PCF_timer, PCF_ACK] = PCF.PCF_sim(upstream,
                                                       downstream,
                                                       current_time=0,
                                                       need_ACK=False,
                                                       Vt=18)
                else:
                    [PCF_timer, PCF_ACK] = PCF.PCF_sim(upstream,
                                                       downstream,
                                                       current_time=PCF_timer,
                                                       need_ACK=PCF_ACK,
                                                       Vt=18)

            throughput_tmp.append(traffic_amount * 8 / PCF_timer)
            delay_tmp.append(PCF_timer / 100 / 1000)

        throughput.append(throughput_tmp.copy())
        delay.append(delay_tmp.copy())

    write2excel(throughput, delay)
Exemple #3
0
def calculate_delay(throughput):
    delay_list = []

    for node_num in numOfstations_list:
        tmpT = np.zeros(5)
        for i in range(50):
            upstream, downstream = trafficHandler.generateUDtraffic(node_num, 1, 1, True,Plength=1024)
            traffic_amount = np.sum(np.array(upstream)) + np.sum(np.array(downstream))

            for j in range(5):
                tmpT[j] += traffic_amount*8/throughput_under_saturatedTraffic_with_different_networksize[j][numOfstations_list.tolist().index(node_num)]
        delay_list.append((tmpT/50/1000).tolist())
    return delay_list
Exemple #4
0
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(
        "####################################################################################################"
    )
Exemple #5
0
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
Exemple #6
0
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
Exemple #7
0
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]
Exemple #8
0
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:
        for times in range(10):
            pFDMAC_throughput = []
            for num_stations in [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]:
                top_rnd = genToplogy.getRandomTopology([300, 300],
                                                       num_stations)
                matSIR = np.array(genToplogy.calc_SIR(top_rnd, [150, 150],
                                                      100))
                for k in range(len(matSIR)):
                    matSIR[k][k] = 30
                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
                         ] = pFDMAC.contention_free_inital_stage_sim(matSIR)
                        [
                            curr_up_time, curr_down_time, last_station, ACK_up,
                            ACK_down, V_curr
                        ] = pFDMAC.greedyPolling(matSIR,
                                                 upstream,
                                                 downstream,
                                                 curr_up_time,
                                                 curr_down_time,
                                                 -1,
                                                 ACK_up=False,
                                                 ACK_down=False,
                                                 current_rate=18)
                    else:
                        [
                            curr_up_time, curr_down_time, last_station, ACK_up,
                            ACK_down, V_curr
                        ] = pFDMAC.greedyPolling(matSIR,
                                                 upstream,
                                                 downstream,
                                                 curr_up_time,
                                                 curr_down_time,
                                                 last_station,
                                                 ACK_up,
                                                 ACK_down,
                                                 current_rate=V_curr)
                    # 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
                pFDMAC_throughput.append(traffic_amount * 8 /
                                         max(curr_down_time, curr_up_time))
            if times == 0:
                array_pFDMAC_throughput = np.array(pFDMAC_throughput)
            else:
                array_pFDMAC_throughput += np.array(pFDMAC_throughput)
        throughput_with_different_CFP.append(array_pFDMAC_throughput / 10)
    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(
        "####################################################################################################"
    )
Exemple #9
0
def test_scheduler_gain():
    throughput = []
    for times in range(10):
        throughput_w = []
        throughput_wo = []
        for i in range(5):
            throughput_each_traffic_type = []
            throughput_each_traffic_type_wo = []
            for num_stations in [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]:
                top_rnd = genToplogy.getRandomTopology([300, 300],
                                                       num_stations)
                matSIR = np.array(genToplogy.calc_SIR(top_rnd, [150, 150],
                                                      100))
                for k in range(len(matSIR)):
                    matSIR[k][k] = 30
                traffic_amount = 0
                for j in range(20000):
                    if i == 0:  # saturated traffic with the same packet length
                        upstream, downstream = trafficHandler.generateUDtraffic(
                            len(matSIR), 1, 1, True)
                    elif i == 1:  # only downstream, nothing to upload
                        upstream, downstream = trafficHandler.generateUDtraffic(
                            len(matSIR), 1, 0, True)
                    elif i == 2:  # only upstream, nothing to download
                        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
                         ] = pFDMAC.contention_free_inital_stage_sim(matSIR)
                        [
                            curr_up_time1, curr_down_time1, last_station1,
                            ACK_up1, ACK_down1, V_curr1
                        ] = pFDMAC.greedyPollingWithoutScheduler(
                            matSIR,
                            upstream,
                            downstream,
                            curr_up_time,
                            curr_down_time,
                            -1,
                            ACK_up=False,
                            ACK_down=False,
                            current_rate=18)

                        [
                            curr_up_time, curr_down_time, last_station, ACK_up,
                            ACK_down, V_curr
                        ] = pFDMAC.greedyPolling(matSIR,
                                                 upstream,
                                                 downstream,
                                                 curr_up_time,
                                                 curr_down_time,
                                                 -1,
                                                 ACK_up=False,
                                                 ACK_down=False,
                                                 current_rate=18)

                    else:
                        [
                            curr_up_time1, curr_down_time1, last_station1,
                            ACK_up1, ACK_down1, V_curr1
                        ] = pFDMAC.greedyPollingWithoutScheduler(
                            matSIR,
                            upstream,
                            downstream,
                            curr_up_time1,
                            curr_down_time1,
                            last_station1,
                            ACK_up1,
                            ACK_down1,
                            current_rate=V_curr1)
                        [
                            curr_up_time, curr_down_time, last_station, ACK_up,
                            ACK_down, V_curr
                        ] = pFDMAC.greedyPolling(matSIR,
                                                 upstream,
                                                 downstream,
                                                 curr_up_time,
                                                 curr_down_time,
                                                 last_station,
                                                 ACK_up,
                                                 ACK_down,
                                                 current_rate=V_curr)

                    # 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_each_traffic_type.append(
                    traffic_amount * 8 / max(curr_down_time, curr_up_time))
                throughput_each_traffic_type_wo.append(
                    traffic_amount * 8 / max(curr_down_time1, curr_up_time1))

            throughput_w.append(throughput_each_traffic_type)
            throughput_wo.append(throughput_each_traffic_type_wo)
        throughput.append([throughput_w, throughput_wo])
    print("throghtput(with/without scheduler) of greedy polling:")
    print(throughput)
    print(
        "####################################################################################################"
    )
Exemple #10
0
def test_performance_betweend_different_protocols_different_packet_length():
    throughputOfDifferentTrafficType = []
    delaOfDifferentTrafficType = []
    for i in range(6):
        throughput = []
        delay = []
        Janus_throughput = []
        Janus_delay = []
        PCF_throughput = []
        PCF_delay = []

        for Plength in [64, 128, 256, 512, 1024, 1500]:
            traffic_amount = 0
            count_round = 0
            PCF_timer = 0
            Janus_flag = True
            for j in range(20000):
                if i == 0:  # saturated traffic with the same packet length
                    upstream, downstream = trafficHandler.generateUDtraffic(
                        len(matSIR), 1, 1, False, Plength)
                elif i == 1:  # only upstream, nothing to download
                    upstream, downstream = trafficHandler.generateUDtraffic(
                        len(matSIR), 1, 0, False, Plength)
                elif i == 2:  # only downstream, nothing to upload
                    upstream, downstream = trafficHandler.generateUDtraffic(
                        len(matSIR), 0, 1, False, Plength)
                elif i == 3:  # typical asymmetric traffic
                    upstream, downstream = trafficHandler.genAsymmetricTraffic(
                        len(matSIR), False, Plength)
                elif i == 4:  # random traffic
                    upstream, downstream = trafficHandler.generateUDtraffic(
                        len(matSIR), 0.5, 0.5, False, Plength)
                elif i == 5:  # 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 Janus simulator
                if Janus_flag:
                    Janus_time = Janus.Janus_sim(upstream, downstream, matSIR,
                                                 True)
                    Janus_delay.append(Janus_time)
                    Janus_throughput.append(traffic_amount * 16 / Janus_time)
                    Janus_flag = False
                # start the contention free period
                if j == 0:
                    [curr_down_time, curr_up_time
                     ] = pFDMAC.contention_free_inital_stage_sim(matSIR)
                    [
                        curr_up_time, curr_down_time, last_station, ACK_up,
                        ACK_down, V_curr
                    ] = pFDMAC.greedyPolling(matSIR,
                                             upstream,
                                             downstream,
                                             curr_up_time,
                                             curr_down_time,
                                             -1,
                                             ACK_up=False,
                                             ACK_down=False,
                                             current_rate=18)
                    [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, V_curr
                    ] = pFDMAC.greedyPolling(matSIR,
                                             upstream,
                                             downstream,
                                             curr_up_time,
                                             curr_down_time,
                                             last_station,
                                             ACK_up,
                                             ACK_down,
                                             current_rate=V_curr)
                    [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))
            delay.append(max(curr_down_time, curr_up_time) / count_round)

            PCF_throughput.append(traffic_amount * 8 / PCF_timer)
            PCF_delay.append(PCF_timer / count_round)
            # if i == 5:
            #     break
        print("Type " + str(i + 1) +
              " throghtput and delay of greedy polling:")
        print(throughput)
        print(Janus_throughput)
        print(PCF_throughput)
        delay = list(np.array(delay) / 1000)
        Janus_delay = list(np.array(Janus_delay) / 1000)
        PCF_delay = list(np.array(PCF_delay) / 1000)
        print(delay)
        print(Janus_delay)
        print(PCF_delay)

        throughputOfDifferentTrafficType.append(
            [throughput, Janus_throughput, PCF_throughput])
        delaOfDifferentTrafficType.append([delay, Janus_delay, PCF_delay])
    print(throughputOfDifferentTrafficType)
    print(delaOfDifferentTrafficType)
    print(
        "####################################################################################################"
    )
Exemple #11
0
def test_performance_betweend_different_protocols_different_saturated_distributed_traffic(
):
    throughput_with_different_networksizes = []
    delay_with_different_networksizes = []
    for times in range(10):
        pFDMAC_throughput = []
        Janus_throughput = []
        PCF_throughput = []
        pFDMAC_delay = []
        Janus_delay = []
        PCF_delay = []
        for num_stations in [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]:
            top_rnd = genToplogy.getRandomTopology([300, 300], num_stations)
            matSIR = np.array(genToplogy.calc_SIR(top_rnd, [150, 150], 100))
            for k in range(len(matSIR)):
                matSIR[k][k] = 30
            traffic_amount = 0
            Janus_flag = True
            count_round = 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))

                if Janus_flag:
                    if True:
                        Janus_time = Janus.Janus_sim(upstream, downstream,
                                                     matSIR, False)
                        Janus_throughput.append(traffic_amount * 8 /
                                                Janus_time)
                        Janus_delay.append(Janus_time / 1000)
                    else:
                        Janus_time = Janus.Janus_sim(upstream, downstream,
                                                     matSIR, True)
                        Janus_throughput.append(traffic_amount * 16 /
                                                Janus_time)
                        Janus_delay.append(Janus_time / 1000)
                    Janus_flag = False
                # start the contention free period
                if j == 0:
                    [curr_down_time, curr_up_time
                     ] = pFDMAC.contention_free_inital_stage_sim(matSIR)
                    [
                        curr_up_time, curr_down_time, last_station, ACK_up,
                        ACK_down, V_curr
                    ] = pFDMAC.greedyPolling(matSIR,
                                             upstream,
                                             downstream,
                                             curr_up_time,
                                             curr_down_time,
                                             -1,
                                             ACK_up=False,
                                             ACK_down=False,
                                             current_rate=18)
                    [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, V_curr
                    ] = pFDMAC.greedyPolling(matSIR,
                                             upstream,
                                             downstream,
                                             curr_up_time,
                                             curr_down_time,
                                             last_station,
                                             ACK_up,
                                             ACK_down,
                                             current_rate=V_curr)
                    [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:
                    break
            # record the throughput
            pFDMAC_throughput.append(traffic_amount * 8 /
                                     max(curr_down_time, curr_up_time))
            PCF_throughput.append(traffic_amount * 8 / PCF_timer)
            pFDMAC_delay.append(
                max(curr_down_time, curr_up_time) / count_round / 1000)
            PCF_delay.append(PCF_timer / count_round / 1000)
        throughput_with_different_networksizes.append(
            [pFDMAC_throughput, Janus_throughput, PCF_throughput])
        delay_with_different_networksizes.append(
            [pFDMAC_delay, Janus_delay, PCF_delay])

    print("throghtput(different protocols) with different network sizes:")
    print(throughput_with_different_networksizes)
    print(delay_with_different_networksizes)