def test_red_accuracy(request, snappi_api, snappi_testbed_config,
                      conn_graph_facts, fanout_graph_facts, duthosts,
                      rand_one_dut_hostname, rand_one_dut_portname_oper_up,
                      rand_one_dut_lossless_prio, prio_dscp_map):
    """
    Measure RED/ECN marking accuracy of the device under test (DUT).
    Dump queue length vs. ECN marking probability results into a file.

    Args:
        request (pytest fixture): pytest request object
        snappi_api (pytest fixture): SNAPPI session
        snappi_testbed_config (pytest fixture): testbed configuration information
        conn_graph_facts (pytest fixture): connection graph
        fanout_graph_facts (pytest fixture): fanout graph
        duthosts (pytest fixture): list of DUTs
        rand_one_dut_hostname (str): hostname of DUT
        rand_one_dut_portname_oper_up (str): name of port to test, e.g., 's6100-1|Ethernet0'
        rand_one_dut_lossless_prio (str): name of lossless priority to test, e.g., 's6100-1|3'
        prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority).

    Returns:
        N/A
    """
    disable_test = request.config.getoption("--disable_ecn_snappi_test")
    if disable_test:
        pytest.skip("test_red_accuracy is disabled")

    dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|')
    dut_hostname2, lossless_prio = rand_one_dut_lossless_prio.split('|')
    pytest_require(rand_one_dut_hostname == dut_hostname == dut_hostname2,
                   "Priority and port are not mapped to the expected DUT")

    testbed_config, port_config_list = snappi_testbed_config
    duthost = duthosts[rand_one_dut_hostname]
    lossless_prio = int(lossless_prio)

    kmin = 500000
    kmax = 2000000
    pmax = 5
    pkt_size = 1024
    pkt_cnt = 2100
    iters = 100
    result_file_name = 'result.txt'

    ip_pkts_list = run_ecn_test(api=snappi_api,
                                testbed_config=testbed_config,
                                port_config_list=port_config_list,
                                conn_data=conn_graph_facts,
                                fanout_data=fanout_graph_facts,
                                duthost=duthost,
                                dut_port=dut_port,
                                kmin=kmin,
                                kmax=kmax,
                                pmax=pmax,
                                pkt_size=pkt_size,
                                pkt_cnt=pkt_cnt,
                                lossless_prio=lossless_prio,
                                prio_dscp_map=prio_dscp_map,
                                iters=iters)
    """ Check if we capture packets of all the rounds """
    pytest_assert(
        len(ip_pkts_list) == iters,
        'Only capture {}/{} rounds of packets'.format(len(ip_pkts_list),
                                                      iters))

    queue_mark_cnt = {}
    for i in range(pkt_cnt):
        queue_len = (pkt_cnt - i) * pkt_size
        queue_mark_cnt[queue_len] = 0

    for i in range(iters):
        ip_pkts = ip_pkts_list[i]
        """ Check if we capture all the packets in each round """
        pytest_assert(
            len(ip_pkts) == pkt_cnt,
            'Only capture {}/{} packets in round {}'.format(
                len(ip_pkts), pkt_cnt, i))

        for j in range(pkt_cnt):
            ip_pkt = ip_pkts[j]
            queue_len = (pkt_cnt - j) * pkt_size

            if is_ecn_marked(ip_pkt):
                queue_mark_cnt[queue_len] += 1
    """ Dump queue length vs. ECN marking probability into a file """
    queue_mark_cnt = collections.OrderedDict(sorted(queue_mark_cnt.items()))
    f = open(result_file_name, 'w')
    for queue, mark_cnt in queue_mark_cnt.iteritems():
        f.write('{} {}\n'.format(queue, float(mark_cnt) / iters))
    f.close()
Example #2
0
def test_dequeue_ecn(request, ixia_api, ixia_testbed_config, conn_graph_facts,
                     fanout_graph_facts, duthosts, rand_one_dut_hostname,
                     rand_one_dut_portname_oper_up, rand_one_dut_lossless_prio,
                     prio_dscp_map):
    """
    Test if the device under test (DUT) performs ECN marking at the egress

    Args:
        request (pytest fixture): pytest request object
        ixia_api (pytest fixture): IXIA session
        ixia_testbed_config (pytest fixture): testbed configuration information
        conn_graph_facts (pytest fixture): connection graph
        fanout_graph_facts (pytest fixture): fanout graph
        duthosts (pytest fixture): list of DUTs
        rand_one_dut_hostname (str): hostname of DUT
        rand_one_dut_portname_oper_up (str): name of port to test, e.g., 's6100-1|Ethernet0'
        rand_one_dut_lossless_prio (str): name of lossless priority to test, e.g., 's6100-1|3'
        prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority).

    Returns:
        N/A
    """
    disable_test = request.config.getoption("--disable_ecn_test")
    if disable_test:
        pytest.skip("test_dequeue_ecn is disabled")

    dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|')
    dut_hostname2, lossless_prio = rand_one_dut_lossless_prio.split('|')
    pytest_require(rand_one_dut_hostname == dut_hostname == dut_hostname2,
                   "Priority and port are not mapped to the expected DUT")

    testbed_config, port_config_list = ixia_testbed_config
    duthost = duthosts[rand_one_dut_hostname]
    lossless_prio = int(lossless_prio)

    kmin = 50000
    kmax = 51000
    pmax = 100
    pkt_size = 1024
    pkt_cnt = 100

    ip_pkts = run_ecn_test(api=ixia_api,
                           testbed_config=testbed_config,
                           port_config_list=port_config_list,
                           conn_data=conn_graph_facts,
                           fanout_data=fanout_graph_facts,
                           duthost=duthost,
                           dut_port=dut_port,
                           kmin=kmin,
                           kmax=kmax,
                           pmax=pmax,
                           pkt_size=pkt_size,
                           pkt_cnt=pkt_cnt,
                           lossless_prio=lossless_prio,
                           prio_dscp_map=prio_dscp_map,
                           iters=1)[0]
    """ Check if we capture all the packets """
    pytest_assert(
        len(ip_pkts) == pkt_cnt,
        'Only capture {}/{} IP packets'.format(len(ip_pkts), pkt_cnt))
    """ Check if the first packet is marked """
    pytest_assert(is_ecn_marked(ip_pkts[0]),
                  "The first packet should be marked")
    """ Check if the last packet is not marked """
    pytest_assert(not is_ecn_marked(ip_pkts[-1]),
                  "The last packet should not be marked")