Commit 932f6275a1 for frr

commit 932f6275a160be929c235052bcc3d12977dd8cde
Author: Donald Sharp <sharpd@nvidia.com>
Date:   Wed Dec 2 20:03:57 2026 -0500

    tests: Create a generate_neighbor helper function

    Create a generic generate_neighbor helper function
    that we can replace the usage of a direct call
    into ping with, even if this function is just
    calling ping.  Let's name what we are looking
    to happen not what we are doing.

    Signed-off-by: Donald Sharp <sharpd@nvidia.com>

diff --git a/tests/topotests/lib/checkping.py b/tests/topotests/lib/checkping.py
index 25cf91d2da..4fdf231e31 100644
--- a/tests/topotests/lib/checkping.py
+++ b/tests/topotests/lib/checkping.py
@@ -9,6 +9,55 @@ from lib.topolog import logger
 from lib import topotest


+def _ping_command(gear, dest_addr, source_addr=None, vrf=None, ipv6=False):
+    """
+    Build a ping command for gear.
+
+    A VRF that `ip vrf show` knows is entered with `ip vrf exec`. Anything
+    else is treated as a netns, matching check_ping. ipv6 selects `ping -6`.
+    source_addr is passed to ping -I and may be an address or an interface.
+    """
+    ping = "ping -6" if ipv6 else "ping"
+    if vrf:
+        vrf_check = gear.run("ip vrf show {}".format(vrf))
+        if vrf in vrf_check:
+            cmd = "ip vrf exec {} {} {}".format(vrf, ping, dest_addr)
+        else:
+            cmd = "ip netns exec {} {} {}".format(vrf, ping, dest_addr)
+    else:
+        cmd = "{} {}".format(ping, dest_addr)
+    if source_addr:
+        cmd += " -I {}".format(source_addr)
+    return cmd
+
+
+def generate_neighbor(name, dest_addr, source_addr=None, vrf=None, count=1):
+    """
+    Send echo requests so the kernel installs a neighbor entry for dest_addr.
+
+    An on-link destination is resolved with ARP or Neighbor Discovery before
+    any reply arrives, so the ping does not have to succeed. Use this to
+    populate a neighbor cache or to trigger MAC learning. Use check_ping to
+    test reachability.
+
+    * 'name': the router or host to send from
+    * 'dest_addr': address to resolve. An address containing ':' is IPv6
+    * 'source_addr': source address or interface name passed to ping -I
+    * 'vrf': VRF or netns name, or None for the default
+    * 'count': number of echo requests to send
+    """
+    tgen = get_topogen()
+    gear = tgen.gears[name]
+    cmd = _ping_command(gear, dest_addr, source_addr, vrf, ipv6=":" in str(dest_addr))
+    cmd += " -c {} -W 1".format(count)
+    if count > 1:
+        cmd += " -i 0.2"
+    logger.info("[+] generate neighbor {} -> {}".format(name, dest_addr))
+    output = gear.run(cmd)
+    logger.info(output)
+    return output
+
+
 def check_ping(
     name, dest_addr, expect_connected, count, wait, source_addr=None, vrf=None
 ):
@@ -24,18 +73,10 @@ def check_ping(

     def _check(name, dest_addr, source_addr, vrf, expect_connected):
         tgen = get_topogen()
-        if vrf:
-            vrf_check = tgen.gears[name].run(f"ip vrf show {vrf}")
-            if vrf in vrf_check:
-                cmd = f"ip vrf exec {vrf} ping {dest_addr}"
-            else:
-                cmd = f"ip netns exec {vrf} ping {dest_addr}"
-        else:
-            cmd = "ping {}".format(dest_addr)
-        if source_addr:
-            cmd += " -I {}".format(source_addr)
+        gear = tgen.gears[name]
+        cmd = _ping_command(gear, dest_addr, source_addr, vrf)
         cmd += " -c 1 -w 1"
-        output = tgen.gears[name].run(cmd)
+        output = gear.run(cmd)
         logger.info(output)

         # Extract packet loss percentage from ping output