Пример #1
0
def get_dut_port_id(dut_hostname, dut_port, conn_data, fanout_data):
    snappi_fanout = get_peer_snappi_chassis(conn_data=conn_data,
                                            dut_hostname=dut_hostname)

    if snappi_fanout is None:
        return None

    snappi_fanout_id = list(fanout_data.keys()).index(snappi_fanout)
    snappi_fanout_list = SnappiFanoutManager(fanout_data)
    snappi_fanout_list.get_fanout_device_details(
        device_number=snappi_fanout_id)

    snappi_ports = snappi_fanout_list.get_ports(peer_device=dut_hostname)

    for i in range(len(snappi_ports)):
        if snappi_ports[i]['peer_port'] == dut_port:
            return i

    return None
Пример #2
0
def snappi_testbed_config(conn_graph_facts, fanout_graph_facts, duthosts,
                          rand_one_dut_hostname, snappi_api):
    """
    Geenrate snappi API config and port config information for the testbed
    Args:
        conn_graph_facts (pytest fixture)
        fanout_graph_facts (pytest fixture)
        duthosts (pytest fixture): list of DUTs
        rand_one_dut_hostname (pytest fixture): DUT hostname
        snappi_api(pytest fixture): Snappi API fixture
    Returns:
        - config (obj): Snappi API config of the testbed
        - port_config_list (list): list of port configuration information
    """
    duthost = duthosts[rand_one_dut_hostname]
    """ Generate L1 config """
    snappi_fanout = get_peer_snappi_chassis(conn_data=conn_graph_facts,
                                            dut_hostname=duthost.hostname)

    pytest_assert(snappi_fanout is not None, 'Fail to get snappi_fanout')

    snappi_fanout_id = list(fanout_graph_facts.keys()).index(snappi_fanout)
    snappi_fanout_list = SnappiFanoutManager(fanout_graph_facts)
    snappi_fanout_list.get_fanout_device_details(
        device_number=snappi_fanout_id)

    snappi_ports = snappi_fanout_list.get_ports(peer_device=duthost.hostname)

    port_speed = None
    """ L1 config """
    config = snappi_api.config()
    for i in range(len(snappi_ports)):
        config.ports.port(name='Port {}'.format(i),
                          location=get_snappi_port_location(snappi_ports[i]))

        if port_speed is None:
            port_speed = int(snappi_ports[i]['speed'])

        pytest_assert(port_speed == int(snappi_ports[i]['speed']),
                      'Ports have different link speeds')

    speed_gbps = int(port_speed / 1000)

    config.options.port_options.location_preemption = True
    l1_config = config.layer1.layer1()[-1]
    l1_config.name = 'L1 config'
    l1_config.port_names = [port.name for port in config.ports]
    l1_config.speed = 'speed_{}_gbps'.format(speed_gbps)
    l1_config.ieee_media_defaults = False
    l1_config.auto_negotiate = False
    l1_config.auto_negotiation.link_training = True
    l1_config.auto_negotiation.rs_fec = True

    pfc = l1_config.flow_control.ieee_802_1qbb
    pfc.pfc_delay = 0
    pfc.pfc_class_0 = 0
    pfc.pfc_class_1 = 1
    pfc.pfc_class_2 = 2
    pfc.pfc_class_3 = 3
    pfc.pfc_class_4 = 4
    pfc.pfc_class_5 = 5
    pfc.pfc_class_6 = 6
    pfc.pfc_class_7 = 7

    port_config_list = []

    config_result = __vlan_intf_config(config=config,
                                       port_config_list=port_config_list,
                                       duthost=duthost,
                                       snappi_ports=snappi_ports)
    pytest_assert(config_result is True, 'Fail to configure Vlan interfaces')

    config_result = __portchannel_intf_config(
        config=config,
        port_config_list=port_config_list,
        duthost=duthost,
        snappi_ports=snappi_ports)
    pytest_assert(config_result is True,
                  'Fail to configure portchannel interfaces')

    config_result = __l3_intf_config(config=config,
                                     port_config_list=port_config_list,
                                     duthost=duthost,
                                     snappi_ports=snappi_ports)
    pytest_assert(config_result is True, 'Fail to configure L3 interfaces')

    return config, port_config_list
Пример #3
0
def tgen_ports(duthost, conn_graph_facts, fanout_graph_facts):
    """
    Populate tgen ports info of T0 testbed and returns as a list
    Args:
        duthost (pytest fixture): duthost fixture
        conn_graph_facts (pytest fixture): connection graph
        fanout_graph_facts (pytest fixture): fanout graph
    Return:
        [{'card_id': '1',
        'ip': '22.1.1.2',
        'ipv6': '3001::2',
        'ipv6_prefix': u'64',
        'location': '10.36.78.238;1;2',
        'peer_device': 'sonic-s6100-dut',
        'peer_ip': u'22.1.1.1',
        'peer_ipv6': u'3001::1',
        'peer_port': 'Ethernet8',
        'port_id': '2',
        'prefix': u'24',
        'speed': 'speed_400_gbps'},
        {'card_id': '1',
        'ip': '21.1.1.2',
        'ipv6': '2001::2',
        'ipv6_prefix': u'64',
        'location': '10.36.78.238;1;1',
        'peer_device': 'sonic-s6100-dut',
        'peer_ip': u'21.1.1.1',
        'peer_ipv6': u'2001::1',
        'peer_port': 'Ethernet0',
        'port_id': '1',
        'prefix': u'24',
        'speed': 'speed_400_gbps'}]
    """

    speed_type = {
        '50000': 'speed_50_gbps',
        '100000': 'speed_100_gbps',
        '200000': 'speed_200_gbps',
        '400000': 'speed_400_gbps'
    }

    snappi_fanout = get_peer_snappi_chassis(conn_data=conn_graph_facts,
                                            dut_hostname=duthost.hostname)
    snappi_fanout_id = list(fanout_graph_facts.keys()).index(snappi_fanout)
    snappi_fanout_list = SnappiFanoutManager(fanout_graph_facts)
    snappi_fanout_list.get_fanout_device_details(
        device_number=snappi_fanout_id)
    snappi_ports = snappi_fanout_list.get_ports(peer_device=duthost.hostname)
    port_speed = None

    for i in range(len(snappi_ports)):
        if port_speed is None:
            port_speed = int(snappi_ports[i]['speed'])

        elif port_speed != int(snappi_ports[i]['speed']):
            """ All the ports should have the same bandwidth """
            return None

    config_facts = duthost.config_facts(host=duthost.hostname,
                                        source="running")['ansible_facts']
    for port in snappi_ports:
        port['location'] = get_snappi_port_location(port)
        port['speed'] = speed_type[port['speed']]
    try:
        for port in snappi_ports:
            peer_port = port['peer_port']
            int_addrs = config_facts['INTERFACE'][peer_port].keys()
            ipv4_subnet = [ele for ele in int_addrs if "." in ele][0]
            if not ipv4_subnet:
                raise Exception(
                    "IPv4 is not configured on the interface {}".format(
                        peer_port))
            port['peer_ip'], port['prefix'] = ipv4_subnet.split("/")
            port['ip'] = get_addrs_in_subnet(ipv4_subnet, 1)[0]
            ipv6_subnet = [ele for ele in int_addrs if ":" in ele][0]
            if not ipv6_subnet:
                raise Exception(
                    "IPv6 is not configured on the interface {}".format(
                        peer_port))
            port['peer_ipv6'], port['ipv6_prefix'] = ipv6_subnet.split("/")
            port['ipv6'] = get_ipv6_addrs_in_subnet(ipv6_subnet, 1)[0]
    except:
        raise Exception('Configure IPv4 and IPv6 on DUT interfaces')

    return snappi_ports