Exemplo n.º 1
0
def check_local_neighbor_asicdb(asic, neighbor_ip, neighbor_mac):
    """
    Verifies the neighbor information of a sonic host in the asicdb for a locally attached neighbor.

    Args:
        asic: The SonicAsic instance to be checked.
        neighbor_ip: The IP address of the neighbor.
        neighbor_mac: The MAC address of the neighbor.

    Returns:
        A dictionary with the encap ID from the ASIC neighbor table.

    Raises:
        Pytest Failed exception when assertions fail.

    """
    asicdb = AsicDbCli(asic)
    neighbor_key = asicdb.get_neighbor_key_by_ip(neighbor_ip)
    pytest_assert(
        neighbor_key is not None,
        "Did not find neighbor in asictable for IP: %s" % neighbor_ip)
    asic_mac = asicdb.get_neighbor_value(
        neighbor_key, 'SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS')
    pytest_assert(
        asic_mac.lower() == neighbor_mac.lower(),
        "MAC does not match in asicDB, asic %s, device %s" %
        (asic_mac.lower(), neighbor_mac.lower()))
    encap_idx = asicdb.get_neighbor_value(
        neighbor_key, 'SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX')
    return {"encap_index": encap_idx}
Exemplo n.º 2
0
def check_voq_remote_neighbor(host, asic, neighbor_ip, neighbor_mac, interface, encap_idx, inband_mac):
    """
    Verifies the neighbor information of a neighbor learned on a different host.

    The ASIC DB, APP DB, and host ARP table are checked. The host kernal route is verified.  The encap ID from the
    local neighbor is provided as a parameter and verified that it is imposed.

    Args:
        host: Instance of SonicHost to check.
        asic: Instance of SonicAsic to check.
        neighbor_ip: IP address if the neighbor to check.
        neighbor_mac: Expected ethernet MAC address of the neighbor.
        interface: Expected interface the neighbor was learned on.
        encap_idx: The encap index from the SONIC host the neighbor is directly attached to.
        inband_mac: The MAC of the inband port of the remote host.

    Raises:
        Pytest Failed exception when assertions fail.
    """
    logger.info("Check remote neighbor on host %s, asic: %s for %s/%s via port: %s", host.hostname,
                str(asic.asic_index), neighbor_ip, neighbor_mac, interface)

    # asic db
    asicdb = AsicDbCli(asic)
    neighbor_key = asicdb.get_neighbor_key_by_ip(neighbor_ip)
    pytest_assert(neighbor_key is not None, "Did not find neighbor in asic table for IP: %s" % neighbor_ip)
    pytest_assert(asicdb.get_neighbor_value(neighbor_key,
                                            'SAI_NEIGHBOR_ENTRY_ATTR_DST_MAC_ADDRESS').lower() == neighbor_mac.lower(),
                  "MAC does not match in asicDB")
    pytest_assert(asicdb.get_neighbor_value(neighbor_key,
                                            'SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_INDEX') == encap_idx,
                  "Encap index does not match in asicDB")
    pytest_assert(asicdb.get_neighbor_value(neighbor_key,
                                            'SAI_NEIGHBOR_ENTRY_ATTR_ENCAP_IMPOSE_INDEX') == "true",
                  "Encap impose is not true in asicDB")
    pytest_assert(asicdb.get_neighbor_value(neighbor_key,
                                            'SAI_NEIGHBOR_ENTRY_ATTR_IS_LOCAL') == "false",
                  "is local is not false in asicDB")

    # LC app db
    appdb = AppDbCli(asic)
    neighbor_key = appdb.get_neighbor_key_by_ip(neighbor_ip)
    pytest_assert(":{}:".format(interface) in neighbor_key, "Port for %s does not match" % neighbor_key)
    appdb.get_and_check_key_value(neighbor_key, inband_mac, field="neigh")

    # verify linux arp table
    check_host_arp_table(host, neighbor_ip, inband_mac, interface, 'PERMANENT')

    # verify linux route entry
    check_neighbor_kernel_route(host, asic.asic_index, neighbor_ip, interface)