Пример #1
0
def __run_traffic(api, config, data_flow_names, all_flow_names, exp_dur_sec):
    """
    Run traffic and dump per-flow statistics

    Args:
        api (obj): IXIA session
        config (obj): experiment config (testbed config + flow config)
        data_flow_names (list): list of names of data (test and background) flows
        all_flow_names (list): list of names of all the flows
        exp_dur_sec (int): experiment duration in second

    Returns:
        per-flow statistics (list)
    """
    api.set_state(State(ConfigState(config=config, state='set')))
    api.set_state(State(FlowTransmitState(state='start')))
    time.sleep(exp_dur_sec)

    while True:
        rows = api.get_flow_results(FlowRequest(flow_names=data_flow_names))
        """ If all the data flows have stopped """
        transmit_states = [row['transmit'] for row in rows]
        if len(rows) == len(data_flow_names) and\
           list(set(transmit_states)) == ['stopped']:
            time.sleep(IXIA_POLL_DELAY_SEC)
            break
        else:
            time.sleep(1)
    """ Dump per-flow statistics """
    rows = api.get_flow_results(FlowRequest(flow_names=all_flow_names))
    api.set_state(State(FlowTransmitState(state='stop')))

    return rows
Пример #2
0
def __run_traffic(api,
                  config,
                  all_flow_names,
                  exp_dur_sec,
                  capture_port_name,
                  pcap_file_name):
    """
    Run traffic and capture packets

    Args:
        api (obj): IXIA session
        config (obj): experiment config
        all_flow_names (list): names of all the flows
        capture_port_name (str): name of the port to capture packets
        pcap_file_name (str): name of the pcap file to store captured packets

    Returns:
        N/A
    """
    api.set_state(State(ConfigState(config=config, state='set')))

    api.set_state(State(PortCaptureState(port_names=[capture_port_name],
                                         state='start')))

    api.set_state(State(FlowTransmitState(state='start')))
    time.sleep(exp_dur_sec)

    attempts = 0
    max_attempts = 20

    while attempts < max_attempts:
        rows = api.get_flow_results(FlowRequest(flow_names=all_flow_names))
        """ If all the flows have stopped """
        transmit_states = [row['transmit'] for row in rows]
        if len(rows) == len(all_flow_names) and\
           list(set(transmit_states)) == ['stopped']:
            time.sleep(IXIA_POLL_DELAY_SEC)
            break
        else:
            time.sleep(1)
            attempts += 1

    """ Dump captured packets """
    pcap_bytes = api.get_capture_results(CaptureRequest(port_name=capture_port_name))
    with open(pcap_file_name, 'wb') as fid:
        fid.write(pcap_bytes)

    """ Stop all the flows """
    api.set_state(State(FlowTransmitState(state='stop')))
def __run_traffic(api, config, duthost, all_flow_names, pfcwd_start_delay_sec,
                  exp_dur_sec):
    """
    Start traffic at time 0 and enable PFC watchdog at pfcwd_start_delay_sec

    Args:
        api (obj): IXIA session
        config (obj): experiment config (testbed config + flow config)
        duthost (Ansible host instance): device under test
        all_flow_names (list): list of names of all the flows
        pfcwd_start_delay_sec (int): PFC watchdog start delay in second
        exp_dur_sec (int): experiment duration in second

    Returns:
        per-flow statistics (list)
    """

    api.set_state(State(ConfigState(config=config, state='set')))
    api.set_state(State(FlowTransmitState(state='start')))

    time.sleep(pfcwd_start_delay_sec)
    start_pfcwd(duthost)
    time.sleep(exp_dur_sec - pfcwd_start_delay_sec)

    attempts = 0
    max_attempts = 20

    while attempts < max_attempts:
        rows = api.get_flow_results(FlowRequest(flow_names=all_flow_names))
        """ If all the flows have stopped """
        transmit_states = [row['transmit'] for row in rows]
        if len(rows) == len(all_flow_names) and\
           list(set(transmit_states)) == ['stopped']:
            time.sleep(IXIA_POLL_DELAY_SEC)
            break
        else:
            time.sleep(1)
            attempts += 1

    pytest_assert(attempts < max_attempts,
                  "Flows do not stop in {} seconds".format(max_attempts))
    """ Dump per-flow statistics """
    rows = api.get_flow_results(FlowRequest(flow_names=all_flow_names))
    api.set_state(State(FlowTransmitState(state='stop')))

    return rows
Пример #4
0
def __run_traffic(api, config, all_flow_names, exp_dur_sec):
    """
    Run traffic and dump per-flow statistics

    Args:
        api (obj): IXIA session
        config (obj): experiment config (testbed config + flow config)
        all_flow_names (list): list of names of all the flows
        exp_dur_sec (float): experiment duration in second

    Returns:
        per-flow statistics (list)
    """
    api.set_state(State(ConfigState(config=config, state='set')))
    api.set_state(State(FlowTransmitState(state='start')))
    time.sleep(exp_dur_sec)

    attempts = 0
    max_attempts = 20

    while attempts < max_attempts:
        rows = api.get_flow_results(FlowRequest(flow_names=all_flow_names))
        """ If all the flows have stopped """
        transmit_states = [row['transmit'] for row in rows]
        if len(rows) == len(all_flow_names) and\
           list(set(transmit_states)) == ['stopped']:
            time.sleep(IXIA_POLL_DELAY_SEC)
            break
        else:
            time.sleep(1)
            attempts += 1

    pytest_assert(attempts < max_attempts,
                  "Flows do not stop in {} seconds".format(max_attempts))

    """ Dump per-flow statistics """
    rows = api.get_flow_results(FlowRequest(flow_names=all_flow_names))
    api.set_state(State(FlowTransmitState(state='stop')))

    return rows
Пример #5
0
def test_pfc_pause_config(api, tx_port, rx_port):
    """Configure only a pfc pause frame
    """
    tx_rx_map = PortTxRx(tx_port_name=tx_port.name,
                         rx_port_names=[rx_port.name])
    pause = PfcPause()
    flow = Flow(name='Pause',
                tx_rx=TxRx(tx_rx_map),
                packet=[Header(pause)],
                size=Size(64),
                rate=Rate('pps', value=1000000),
                duration=Duration(
                    FixedPackets(packets=1024,
                                 delay=120,
                                 delay_unit='nanoseconds')))
    config = Config(ports=[tx_port, rx_port], flows=[flow])
    api.set_state(State(ConfigState(config=config, state='set')))
Пример #6
0
def test_tgen(traffic_config, ixia_api):
    config = traffic_config

    flow_name = config.flows[0].name
    pkt_size = config.flows[0].size.fixed
    rate_percent = config.flows[0].rate.value
    duration_sec = config.flows[0].duration.seconds.seconds

    port_speed = config.layer1[0].speed
    words = port_speed.split('_')
    pytest_assert(
        len(words) == 3 and words[1].isdigit(),
        'Fail to get port speed from {}'.format(port_speed))

    port_speed_gbps = int(words[1])
    """ Apply configuration """
    ixia_api.set_state(State(ConfigState(config=config, state='set')))
    """ Start traffic """
    ixia_api.set_state(State(FlowTransmitState(state='start')))
    """ Wait for traffic to finish """
    time.sleep(duration_sec)

    while True:
        rows = ixia_api.get_flow_results(FlowRequest(flow_names=[flow_name]))
        if len(rows) == 1 and \
           rows[0]['name'] == flow_name and \
           rows[0]['transmit'] == 'stopped':
            """ Wait for counters to fully propagate """
            time.sleep(2)
            break
        else:
            time.sleep(1)
    """ Dump per-flow statistics """
    rows = ixia_api.get_flow_results(FlowRequest(flow_names=[flow_name]))
    """ Stop traffic """
    ixia_api.set_state(State(FlowTransmitState(state='stop')))
    """ Analyze traffic results """
    pytest_assert(
        len(rows) == 1 and rows[0]['name'] == flow_name,
        'Fail to get results of flow {}'.format(flow_name))

    row = rows[0]
    rx_frames = row['frames_rx']
    tx_frames = row['frames_tx']

    pytest_assert(
        rx_frames == tx_frames,
        'Unexpected packet losses (Tx: {}, Rx: {})'.format(
            tx_frames, rx_frames))

    tput_bps = port_speed_gbps * 1e9 * rate_percent / 100.0
    exp_rx_frames = tput_bps * duration_sec / 8 / pkt_size

    deviation_thresh = 0.05
    ratio = float(exp_rx_frames) / rx_frames
    deviation = abs(ratio - 1)

    pytest_assert(
        deviation <= deviation_thresh,
        'Expected / Actual # of pkts: {} / {}'.format(exp_rx_frames,
                                                      rx_frames))
Пример #7
0
def test_tgen(conn_graph_facts, fanout_graph_facts, ixia_api, ixia_testbed,
              enum_dut_portname_oper_up):
    """
    Test if we can use Tgen API generate traffic in a testbed

    Args:
        conn_graph_facts (pytest fixture): connection graph
        fanout_graph_facts (pytest fixture): fanout graph
        ixia_api (pytest fixture): IXIA session
        ixia_testbed (pytest fixture): L2/L3 config of a T0 testbed
        enum_dut_portname_oper_up (str): name of port to test, e.g., 's6100-1|Ethernet0'

    Returns:
        None
    """

    words = enum_dut_portname_oper_up.split('|')
    pytest_require(len(words) == 2, "Fail to parse port name")

    dut_hostname = words[0]
    dut_port = words[1]

    config = ixia_testbed
    config.flows = __gen_traffic(testbed_config=config,
                                 dut_hostname=dut_hostname,
                                 dut_port=dut_port,
                                 conn_data=conn_graph_facts,
                                 fanout_data=fanout_graph_facts)

    flow_name = config.flows[0].name
    pkt_size = config.flows[0].size.fixed
    rate_percent = config.flows[0].rate.value
    duration_sec = config.flows[0].duration.seconds.seconds

    port_speed = config.layer1[0].speed
    words = port_speed.split('_')
    pytest_assert(
        len(words) == 3 and words[1].isdigit(),
        'Fail to get port speed from {}'.format(port_speed))

    port_speed_gbps = int(words[1])
    """ Apply configuration """
    ixia_api.set_state(State(ConfigState(config=config, state='set')))
    """ Start traffic """
    ixia_api.set_state(State(FlowTransmitState(state='start')))
    """ Wait for traffic to finish """
    time.sleep(duration_sec)

    while True:
        rows = ixia_api.get_flow_results(FlowRequest(flow_names=[flow_name]))
        if len(rows) == 1 and \
           rows[0]['name'] == flow_name and \
           rows[0]['transmit'] == 'stopped':
            """ Wait for counters to fully propagate """
            time.sleep(2)
            break
        else:
            time.sleep(1)
    """ Dump per-flow statistics """
    rows = ixia_api.get_flow_results(FlowRequest(flow_names=[flow_name]))
    """ Stop traffic """
    ixia_api.set_state(State(FlowTransmitState(state='stop')))
    """ Analyze traffic results """
    pytest_assert(
        len(rows) == 1 and rows[0]['name'] == flow_name,
        'Fail to get results of flow {}'.format(flow_name))

    row = rows[0]
    rx_frames = row['frames_rx']
    tx_frames = row['frames_tx']

    pytest_assert(
        rx_frames == tx_frames,
        'Unexpected packet losses (Tx: {}, Rx: {})'.format(
            tx_frames, rx_frames))

    tput_bps = port_speed_gbps * 1e9 * rate_percent / 100.0
    exp_rx_frames = tput_bps * duration_sec / 8 / pkt_size

    deviation_thresh = 0.05
    ratio = float(exp_rx_frames) / rx_frames
    deviation = abs(ratio - 1)

    pytest_assert(
        deviation <= deviation_thresh,
        'Expected / Actual # of pkts: {} / {}'.format(exp_rx_frames,
                                                      rx_frames))
Пример #8
0
def test_tgen(ixia_api,
              ixia_testbed_config,
              conn_graph_facts,
              fanout_graph_facts,
              rand_one_dut_lossless_prio,
              prio_dscp_map):
    """
    Test if we can use Tgen API generate traffic in a testbed

    Args:
        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
        rand_one_dut_lossless_prio (str): name of lossless priority to test
        prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority)

    Returns:
        N/A
    """

    testbed_config, port_config_list = ixia_testbed_config
    dut_hostname, lossless_prio = rand_one_dut_lossless_prio.split('|')

    pytest_require(len(port_config_list) >= 2, "This test requires at least 2 ports")

    config = testbed_config
    config.flows = __gen_all_to_all_traffic(testbed_config=testbed_config,
                                            port_config_list=port_config_list,
                                            dut_hostname=dut_hostname,
                                            conn_data=conn_graph_facts,
                                            fanout_data=fanout_graph_facts,
                                            priority=int(lossless_prio),
                                            prio_dscp_map=prio_dscp_map)

    pkt_size = config.flows[0].size.fixed
    rate_percent = config.flows[0].rate.value
    duration_sec = config.flows[0].duration.seconds.seconds

    port_speed = config.layer1[0].speed
    words = port_speed.split('_')
    pytest_assert(len(words) == 3 and words[1].isdigit(),
                  'Fail to get port speed from {}'.format(port_speed))

    port_speed_gbps = int(words[1])

    """ Apply configuration """
    ixia_api.set_state(State(ConfigState(config=config, state='set')))

    """ Start traffic """
    ixia_api.set_state(State(FlowTransmitState(state='start')))

    """ Wait for traffic to finish """
    time.sleep(duration_sec)

    attempts = 0
    max_attempts = 20
    all_flow_names = [flow.name for flow in config.flows]

    while attempts < max_attempts:
        rows = ixia_api.get_flow_results(FlowRequest(flow_names=all_flow_names))

        """ If all the data flows have stopped """
        transmit_states = [row['transmit'] for row in rows]
        if len(rows) == len(all_flow_names) and\
           list(set(transmit_states)) == ['stopped']:
            time.sleep(2)
            break
        else:
            time.sleep(1)
            attempts += 1

    pytest_assert(attempts < max_attempts,
                  "Flows do not stop in {} seconds".format(max_attempts))

    """ Dump per-flow statistics """
    rows = ixia_api.get_flow_results(FlowRequest(flow_names=all_flow_names))
    ixia_api.set_state(State(FlowTransmitState(state='stop')))

    """ Analyze traffic results """
    for row in rows:
        flow_name = row['name']
        rx_frames = row['frames_rx']
        tx_frames = row['frames_tx']

        pytest_assert(rx_frames == tx_frames,
                      'packet losses for {} (Tx: {}, Rx: {})'.\
                      format(flow_name, tx_frames, rx_frames))

        tput_bps = port_speed_gbps * 1e9 * rate_percent / 100.0
        exp_rx_frames = tput_bps * duration_sec / 8 / pkt_size

        deviation_thresh = 0.05
        ratio = float(exp_rx_frames) / rx_frames
        deviation = abs(ratio - 1)

        pytest_assert(deviation <= deviation_thresh,
                      'Expected / Actual # of pkts for flow {}: {} / {}'.\
                      format(flow_name, exp_rx_frames, rx_frames))