Commit 8978dffda5 for frr

commit 8978dffda543645d0d5e61713985341dffa3038b
Author: Nageswara Soma <nsoma@cisco.com>
Date:   Sun Nov 29 22:06:04 2026 -0800

    tests: fix flaky bfd strict dynamic peer drop check

    R2 drops a held dynamic neighbor after the 10 second
    BFD strict hold time, but R1 reconnects after its
    1 second connect timer. R2 then creates a new dynamic
    peer for the same address, so a poll can miss the
    short gap and see the neighbor present every time.

    Record the held peer's creation time from its reset
    age and pass when the neighbor is absent or has been
    recreated. A held dynamic peer is deleted on stop and
    never Established, so its reset time is set only at
    creation. A 5 second margin absorbs reset-age
    rounding and vtysh latency; a recreated peer is at
    least 11 seconds newer. Keep the 45 second window.

    Signed-off-by: Nageswara Soma <nsoma@cisco.com>

diff --git a/tests/topotests/bgp_bfd_strict_dynamic_neighbor/test_bgp_bfd_strict_dynamic_neighbor.py b/tests/topotests/bgp_bfd_strict_dynamic_neighbor/test_bgp_bfd_strict_dynamic_neighbor.py
index b983642c87..b16dfce70b 100644
--- a/tests/topotests/bgp_bfd_strict_dynamic_neighbor/test_bgp_bfd_strict_dynamic_neighbor.py
+++ b/tests/topotests/bgp_bfd_strict_dynamic_neighbor/test_bgp_bfd_strict_dynamic_neighbor.py
@@ -18,6 +18,7 @@ import sys
 import json
 import pytest
 import functools
+import time

 CWD = os.path.dirname(os.path.realpath(__file__))
 sys.path.append(os.path.join(CWD, "../"))
@@ -29,6 +30,9 @@ from lib.common_config import step

 pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd]

+# Allow for whole-second reset-age rounding and vtysh command latency.
+DYNAMIC_NEIGHBOR_RECREATE_TOLERANCE_MS = 5000
+

 def build_topo(tgen):
     for routern in range(1, 3):
@@ -79,15 +83,45 @@ def _bfd_session_source_resolved(r2):
     return "no BFD session to 192.0.2.1"


-def _bgp_dynamic_neighbor_gone(r2):
+def _bgp_dynamic_neighbor_creation_time(r2):
+    now_ms = time.monotonic() * 1000
+    raw_output = r2.vtysh_cmd("show bgp neighbors 192.0.2.1 json brief")
     try:
-        output = json.loads(r2.vtysh_cmd("show bgp neighbor 192.0.2.1 json"))
-    except ValueError:
-        # No such neighbor, the reply is not JSON.
+        output = json.loads(raw_output)
+    except ValueError as error:
+        assert False, "invalid JSON from neighbor query: {} ({})".format(
+            raw_output.strip(), error
+        )
+
+    assert isinstance(output, dict), "unexpected neighbor query response: {}".format(
+        output
+    )
+    if "bgpNoSuchNeighbor" in output:
+        return None
+
+    neighbor = output.get("192.0.2.1")
+    assert isinstance(neighbor, dict), "unexpected neighbor query response: {}".format(
+        output
+    )
+
+    reset_age_ms = neighbor.get("lastResetTimerMsecs")
+    assert reset_age_ms is not None, "neighbor response is missing lastResetTimerMsecs"
+
+    # While held, the unestablished dynamic peer's reset time is its creation time.
+    return now_ms - reset_age_ms
+
+
+def _bgp_dynamic_neighbor_gone(r2, original_creation_time):
+    current_creation_time = _bgp_dynamic_neighbor_creation_time(r2)
+    if current_creation_time is None:
         return None
-    if "192.0.2.1" in output:
-        return "dynamic neighbor 192.0.2.1 is still present"
-    return None
+    if (
+        current_creation_time
+        > original_creation_time + DYNAMIC_NEIGHBOR_RECREATE_TOLERANCE_MS
+    ):
+        return None
+
+    return "dynamic neighbor 192.0.2.1 is still present"


 def _bgp_established(router, neighbor):
@@ -147,9 +181,19 @@ def test_bgp_bfd_strict_dynamic_neighbor_hold_time():
     assert result is None, "R2 did not hold the dynamic neighbor connection"

     step("Check that R2 drops the held dynamic neighbor once the hold time expires")
-    test_func = functools.partial(_bgp_dynamic_neighbor_gone, r2)
+    original_creation_time = _bgp_dynamic_neighbor_creation_time(r2)
+    if original_creation_time is None:
+        return
+
+    test_func = functools.partial(
+        _bgp_dynamic_neighbor_gone, r2, original_creation_time
+    )
     _, result = topotest.run_and_expect(test_func, None, count=45, wait=1)
-    assert result is None, "R2 did not drop the held dynamic neighbor"
+    assert (
+        result is None
+    ), "R2 did not drop or reset the held dynamic neighbor; last poll: {}".format(
+        result
+    )


 def test_bgp_bfd_strict_dynamic_neighbor_established():