Example #1
0
    def test_front_panel_admindown_port(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_asic_index,
                                        all_cfg_facts, setup, nbrhosts, nbr_macs, established_arp):
        """
        Verify tables, databases, and kernel routes are correctly deleted when the DUT port is admin down/up.

        Test Steps

        * Admin down interface on DUT.
        * On local linecard:
            * Verify ARP/NDP entries are removed from CLI for neighbors on down port.
            * Verify table entries in ASIC, AppDb are removed for addresses on down port.
        * On Supervisor card:
            * Verify Chassis App DB entry are removed for only the cleared address.  Entries for addresses on other
            line cards should still be present.
        * On remote linecards:
            * Verify table entries in ASICDB, APPDB, and host ARP table are removed for cleared addresses.
            * Verify kernel routes for cleared address are deleted.
        * Admin interface up, verify recreation after restarting traffic.

        Args:
            duthosts: duthosts fixture.
            enum_rand_one_per_hwsku_frontend_hostname: frontend iteration fixture.
            enum_asic_index: asic iteration fixture.
            all_cfg_facts: all_cfg_facts fixture from voq/conftest.py
            setup: setup fixture for this module.
            nbrhosts: nbrhosts fixture.
            established_arp: Fixture to establish ARP to all neighbors.

        """

        per_host = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
        asic = per_host.asics[enum_asic_index if enum_asic_index is not None else 0]
        cfg_facts = all_cfg_facts[per_host.hostname][asic.asic_index]['ansible_facts']

        neighs = cfg_facts['BGP_NEIGHBOR']

        intfs, intfs_to_test = pick_ports(cfg_facts)

        logger.info("Will test interfaces: %s", intfs_to_test)

        for intf in intfs_to_test:
            local_ips = [i.split("/")[0] for i in intfs[intf].keys()]  # [u'2064:100::2/64', u'100.0.0.2/24']
            neighbors = [n for n in neighs if neighs[n]['local_addr'] in local_ips]

            logger.info("Testing neighbors: %s on intf: %s", neighbors, intf)

            self.localport_admindown(per_host, intf)
            try:
                check_neighbors_are_gone(duthosts, all_cfg_facts, per_host, asic, neighbors)
            finally:
                self.localport_adminup(per_host, intf)

            for neighbor in neighbors:
                sonic_ping(asic, neighbor)

            for neighbor in neighbors:
                pytest_assert(wait_until(60, 2, check_arptable_state, per_host, neighbor, "REACHABLE"),
                              "STATE for neighbor {} did not change to reachable".format(neighbor))

            dump_and_verify_neighbors_on_asic(duthosts, per_host, asic, neighbors, nbrhosts, all_cfg_facts, nbr_macs)
Example #2
0
def ping_all_neighbors(duthosts, neighbors):
    """
    Pings all neighbors in the neighbor list from all frontend hosts on the DUT..

    Args:
        duthosts: An instance of the duthosts fixture.
        neighbors: A list of neighbor IP addresses.

    """
    for per_host in duthosts.frontend_nodes:
        for asic in per_host.asics:
            for neighbor in neighbors:
                logger.info("Ping %s from %s/%s", neighbor, per_host.hostname, asic.asic_index)
                sonic_ping(asic, neighbor)
def ping_all_neighbors(duthosts, all_cfg_facts, neighbors):
    """
    Pings all neighbors in the neighbor list from all frontend hosts on the DUT..

    Args:
        duthosts: An instance of the duthosts fixture.
        all_cfg_facts: Fixture from voq/conftest.py
        neighbors: A list of neighbor IP addresses.

    """
    for per_host in duthosts.frontend_nodes:
        for asic in per_host.asics:
            cfg_facts = all_cfg_facts[per_host.hostname][asic.asic_index]['ansible_facts']
            inband = get_inband_info(cfg_facts)
            if inband == {}:
                continue

            for neighbor in neighbors:
                logger.info("Ping %s from %s/%s", neighbor, per_host.hostname, asic.asic_index)
                sonic_ping(asic, neighbor, verbose=True)
Example #4
0
    def _ping_all_local_nbrs(node=None, results=None):
        if node is None or results is None:
            logger.error('Missing kwarg "node" or "results"')
            return

        node_results = []
        logger.info("Pinging neighbors to establish ARP on node: %s", node.hostname)

        for asic in node.asics:
            cfg_facts = asic.config_facts(source="persistent")['ansible_facts']
            neighs = cfg_facts['BGP_NEIGHBOR']
            for neighbor in neighs:
                node_results.append(sonic_ping(asic, neighbor))
        results[node.hostname] = node_results
    def _ping_all_local_nbrs(node=None, results=None):
        if node is None or results is None:
            logger.error('Missing kwarg "node" or "results"')
            return

        node_results = []
        logger.info("Pinging neighbors to establish ARP on node: %s", node.hostname)

        for asic in node.asics:
            cfg_facts = asic.config_facts(source="persistent")['ansible_facts']
            if 'BGP_NEIGHBOR' in cfg_facts:
                neighs = cfg_facts['BGP_NEIGHBOR']
            else:
                logger.info("No local neighbors for host: %s/%s, skipping", node.hostname, asic.asic_index)
                continue

            for neighbor in neighs:
                node_results.append(sonic_ping(asic, neighbor, verbose=True))
        results[node.hostname] = node_results
def test_neighbor_hw_mac_change(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_asic_index,
                                setup, teardown, nbrhosts, all_cfg_facts, nbr_macs, established_arp):
    """
    Verify tables, databases, and kernel routes are correctly updated when the MAC address of a neighbor changes
    and is updated via request/reply exchange.

    Test Steps

    * Change the MAC address on a remote host that is already present in the ARP table.
    * Without clearing the entry in the DUT, allow the existing entry to time out and the new reply to have the new MAC
      address.
    * On local linecard:
        * Verify table entries in local ASIC, APP, and host ARP table are updated with new MAC.
    * On supervisor card:
        * Verify Chassis App DB entry is correct for with the updated MAC address.
    * On remote linecards:
        * Verify table entries in remote hosts/ASICs in APPDB, and host ARP table are still present with inband MAC
          address
        * Verify ASIC DB is updated with new MAC.
        * Verify kernel route in remote hosts are still present to inband port.
    * Verify that packets can be sent from local and remote linecards to the learned address.

    Args:
        duthosts: duthosts fixture.
        enum_rand_one_per_hwsku_frontend_hostname: frontend iteration fixture.
        enum_asic_index: asic iteration fixture.
        setup: setup fixture for this module.
        nbrhosts: nbrhosts fixture.
        established_arp: Fixture to establish arp on all nodes
        all_cfg_facts: all_cfg_facts fixture from voq/conftest.py
    """

    per_host = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
    asic = per_host.asics[enum_asic_index if enum_asic_index is not None else 0]
    cfg_facts = all_cfg_facts[per_host.hostname][asic.asic_index]['ansible_facts']

    if 'BGP_NEIGHBOR' in cfg_facts:
        neighs = cfg_facts['BGP_NEIGHBOR']
    else:
        logger.info("No local neighbors for host: %s/%s, skipping", per_host.hostname, asic.asic_index)
        return

    eth_cfg = cfg_facts['INTERFACE'] if 'INTERFACE' in cfg_facts else {}
    if eth_cfg == {}:
        pytest.skip("Can't run this test without any IP interfaces on ethernet ports")
    eth_ports = [intf for intf in eth_cfg]
    local_port = random.choice(eth_ports)

    logger.info("We will test port: %s on host %s, asic %s", local_port, per_host.hostname, asic.asic_index)

    nbr_to_test = []
    for neighbor in neighs:
        local_ip = neighs[neighbor]['local_addr']
        nbr_port = get_port_by_ip(cfg_facts, local_ip)
        if local_port == nbr_port:
            nbr_to_test.append(neighbor)

    logger.info("We will test neighbors: %s", nbr_to_test)
    nbrinfo = get_neighbor_info(nbr_to_test[0], nbrhosts)
    original_mac = nbrinfo['mac']

    for neighbor in nbr_to_test:
        # Check neighbor on local linecard
        logger.info("*" * 60)
        logger.info("Verify initial neighbor: %s, port %s", neighbor, local_port)
        pytest_assert(wait_until(60, 2, check_arptable_mac, per_host, asic, neighbor, original_mac, checkstate=False),
                      "MAC {} didn't change in ARP table".format(original_mac))
        sonic_ping(asic, neighbor, verbose=True)
        pytest_assert(wait_until(60, 2, check_arptable_mac, per_host, asic, neighbor, original_mac),
                      "MAC {} didn't change in ARP table".format(original_mac))

    dump_and_verify_neighbors_on_asic(duthosts, per_host, asic, nbr_to_test, nbrhosts, all_cfg_facts, nbr_macs)

    try:
        logger.info("Changing ethernet mac on port %s, vm %s", nbrinfo['shell_intf'], nbrinfo['vm'])

        change_mac(nbrhosts[nbrinfo['vm']], nbrinfo['shell_intf'], NEW_MAC)

        for neighbor in nbr_to_test:
            if ":" in neighbor:
                logger.info("Force neighbor solicitation to workaround long IPV6 timer.")
                asic_cmd(asic, "ndisc6 %s %s" % (neighbor, local_port))
            pytest_assert(wait_until(60, 2, check_arptable_mac, per_host, asic, neighbor, NEW_MAC, checkstate=False),
                          "MAC {} didn't change in ARP table".format(NEW_MAC))

            sonic_ping(asic, neighbor, verbose=True)
            pytest_assert(wait_until(60, 2, check_arptable_mac, per_host, asic, neighbor, NEW_MAC),
                          "MAC {} didn't change in ARP table".format(NEW_MAC))
            logger.info("Verify neighbor after mac change: %s, port %s", neighbor, local_port)
            check_one_neighbor_present(duthosts, per_host, asic, neighbor, nbrhosts, all_cfg_facts)

        logger.info("Ping neighbors: %s from all line cards", nbr_to_test)

        ping_all_neighbors(duthosts, all_cfg_facts, nbr_to_test)

    finally:
        logger.info("-" * 60)
        logger.info("Will Restore ethernet mac on port %s, vm %s", nbrinfo['shell_intf'], nbrinfo['vm'])
        change_mac(nbrhosts[nbrinfo['vm']], nbrinfo['shell_intf'], original_mac)
        for neighbor in nbr_to_test:
            if ":" in neighbor:
                logger.info("Force neighbor solicitation to workaround long IPV6 timer.")
                asic_cmd(asic, "ndisc6 %s %s" % (neighbor, local_port))
            pytest_assert(
                wait_until(60, 2, check_arptable_mac, per_host, asic, neighbor, original_mac, checkstate=False),
                "MAC {} didn't change in ARP table".format(original_mac))
            sonic_ping(asic, neighbor, verbose=True)
            pytest_assert(wait_until(60, 2, check_arptable_mac, per_host, asic, neighbor, original_mac),
                          "MAC {} didn't change in ARP table".format(original_mac))

        dump_and_verify_neighbors_on_asic(duthosts, per_host, asic, nbr_to_test, nbrhosts, all_cfg_facts, nbr_macs)

    ping_all_neighbors(duthosts, all_cfg_facts, nbr_to_test)
    def test_gratarp_macchange(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_asic_index,
                               ptfhost, tbinfo, nbrhosts, setup, teardown, all_cfg_facts, established_arp):
        """
        Verify tables, databases, and kernel routes are correctly updated when a unsolicited ARP packet changes
        the MAC address of learned neighbor.

        Test Steps

        * Send unsolicited ARP packet into DUT for an IP known by DUT with a different MAC address for the neighbor.
        * Change the MAC address of the neighbor VM.
        * On local linecard:
            * Verify table entries in local ASIC, APP, and host ARP table are updated with new MAC.
        * On supervisor card:
            * Verify Chassis App DB entry is correct for with the updated MAC address.
        * On remote linecards:
            * Verify table entries in remote hosts/ASICs in APPDB, and host ARP table are still present with inband MAC
              address
            * Verify ASIC DB is updated with new MAC.
            * Verify kernel route in remote hosts are still present to inband port.
        * Verify that packets can be sent from local and remote linecards to learned address.

        Args:
            duthosts: The duthosts fixture
            enum_rand_one_per_hwsku_frontend_hostname: frontend enumeration fixture
            enum_asic_index: asic enumeration fixture
            ptfhost: The ptfhost fixure.
            tbinfo: The tbinfo fixture
            nbrhosts: The nbrhosts fixture.
            setup: The setup fixture from this module.
            established_arp: The established_arp fixture from this module.
            all_cfg_facts: The all_cfg_facts fixture from voq/contest.py


        """
        self.ptfhost = ptfhost

        duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]

        asic = duthost.asics[enum_asic_index if enum_asic_index is not None else 0]
        cfg_facts = all_cfg_facts[duthost.hostname][asic.asic_index]['ansible_facts']

        if 'BGP_NEIGHBOR' in cfg_facts:
            neighs = cfg_facts['BGP_NEIGHBOR']
        else:
            logger.info("No local neighbors for host: %s/%s, skipping", duthost.hostname, asic.asic_index)
            return

        eth_cfg = cfg_facts['INTERFACE'] if 'INTERFACE' in cfg_facts else {}
        if eth_cfg == {}:
            pytest.skip("Can't run this test without any IP interfaces on ethernet ports")
        eth_ports = [intf for intf in eth_cfg]
        local_port = random.choice(eth_ports)

        logger.info("We will test port: %s on host %s, asic %s", local_port, duthost.hostname, asic.asic_index)

        nbr_to_test = []
        for neighbor in neighs:
            local_ip = neighs[neighbor]['local_addr']
            nbr_port = get_port_by_ip(cfg_facts, local_ip)
            if local_port == nbr_port:
                nbr_to_test.append(neighbor)

        logger.info("We will test neighbors: %s", nbr_to_test)

        for neighbor in nbr_to_test:

            nbrinfo = get_neighbor_info(neighbor, nbrhosts)

            tb_port = get_ptf_port(duthosts,
                                   all_cfg_facts[duthost.hostname][asic.asic_index]['ansible_facts'],
                                   tbinfo, duthost, local_port)[0]
            original_mac = nbrinfo['mac']

            logger.info("*" * 60)
            logger.info("Verify initial neighbor: %s, port %s", neighbor, local_port)
            logger.info("%s port %s is on ptf port: %s", duthost.hostname, local_port, tb_port)
            logger.info("-" * 60)
            sonic_ping(asic, neighbor)
            pytest_assert(wait_until(60, 2, check_arptable_mac, duthost, asic, neighbor, original_mac),
                          "MAC {} didn't change in ARP table".format(original_mac))

            check_one_neighbor_present(duthosts, duthost, asic, neighbor, nbrhosts, all_cfg_facts)

            try:
                change_mac(nbrhosts[nbrinfo['vm']], nbrinfo['shell_intf'], NEW_MAC)
                self.send_grat_pkt(NEW_MAC, neighbor, int(tb_port))

                pytest_assert(wait_until(60, 2, check_arptable_mac, duthost, asic, neighbor, NEW_MAC, checkstate=False),
                              "MAC {} didn't change in ARP table of neighbor {}".format(NEW_MAC, neighbor))
                try:
                    sonic_ping(asic, neighbor)
                except AssertionError:
                    logging.info("No initial response from ping, begin poll to see if ARP table responds.")
                pytest_assert(wait_until(60, 2, check_arptable_mac, duthost, asic, neighbor, NEW_MAC, checkstate=True),
                              "MAC {} didn't change in ARP table of neighbor {}".format(NEW_MAC, neighbor))
                check_one_neighbor_present(duthosts, duthost, asic, neighbor, nbrhosts, all_cfg_facts)
                ping_all_neighbors(duthosts, all_cfg_facts, [neighbor])
            finally:
                logger.info("Will Restore ethernet mac on neighbor: %s, port %s, vm %s", neighbor,
                            nbrinfo['shell_intf'], nbrinfo['vm'])
                change_mac(nbrhosts[nbrinfo['vm']], nbrinfo['shell_intf'], original_mac)

                if ":" in neighbor:
                    logger.info("Force neighbor solicitation to workaround long IPV6 timer.")
                    asic_cmd(asic, "ndisc6 %s %s" % (neighbor, local_port))
                pytest_assert(
                    wait_until(60, 2, check_arptable_mac, duthost, asic, neighbor, original_mac, checkstate=False),
                    "MAC {} didn't change in ARP table".format(original_mac))
                sonic_ping(asic, neighbor, verbose=True)
                pytest_assert(wait_until(60, 2, check_arptable_mac, duthost, asic, neighbor, original_mac),
                              "MAC {} didn't change in ARP table".format(original_mac))

            check_one_neighbor_present(duthosts, duthost, asic, neighbor, nbrhosts, all_cfg_facts)
            ping_all_neighbors(duthosts, all_cfg_facts, [neighbor])