Commit d12a3eaa04 for frr

commit d12a3eaa04706be005b8ed84d2ab1e90548e62a6
Author: Yukie Kawamata <y-kawamata@sakura.ad.jp>
Date:   Wed Nov 11 22:49:58 2026 +0900

    tests: Add topotest for addpath-tx-best-selected on dynamic peers

    Add a regression test that verifies that a peer-group configured with
    'addpath-tx-best-selected N' propagates the count to dynamic peers created
    through 'bgp listen range'.  Without the fix the receiving peer only gets
    the single best path; with the fix it receives best + N paths.

    Fixes: #24318
    Signed-off-by: Yukie Kawamata <y-kawamata@sakura.ad.jp>

diff --git a/tests/topotests/bgp_addpath_best_selected_dynamic_peers/__init__.py b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r1/frr.conf b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r1/frr.conf
new file mode 100644
index 0000000000..4d6966c474
--- /dev/null
+++ b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r1/frr.conf
@@ -0,0 +1,16 @@
+!
+interface r1-eth0
+ ip address 192.0.2.1/24
+!
+router bgp 65001
+ no bgp ebgp-requires-policy
+ bgp bestpath compare-routerid
+ neighbor PG peer-group
+ neighbor PG remote-as external
+ bgp listen range 192.0.2.0/24 peer-group PG
+ !
+ address-family ipv4 unicast
+  neighbor PG addpath-tx-best-selected 1
+  neighbor PG activate
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r2/frr.conf b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r2/frr.conf
new file mode 100644
index 0000000000..0dd7d3e96f
--- /dev/null
+++ b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r2/frr.conf
@@ -0,0 +1,14 @@
+!
+interface r2-eth0
+ ip address 192.0.2.2/24
+!
+ip route 172.16.16.254/32 Null0
+!
+router bgp 65002
+ no bgp ebgp-requires-policy
+ neighbor 192.0.2.1 remote-as external
+ !
+ address-family ipv4 unicast
+  network 172.16.16.254/32
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r3/frr.conf b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r3/frr.conf
new file mode 100644
index 0000000000..c550201174
--- /dev/null
+++ b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r3/frr.conf
@@ -0,0 +1,14 @@
+!
+interface r3-eth0
+ ip address 192.0.2.3/24
+!
+ip route 172.16.16.254/32 Null0
+!
+router bgp 65003
+ no bgp ebgp-requires-policy
+ neighbor 192.0.2.1 remote-as external
+ !
+ address-family ipv4 unicast
+  network 172.16.16.254/32
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r4/frr.conf b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r4/frr.conf
new file mode 100644
index 0000000000..fa447ca4bc
--- /dev/null
+++ b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r4/frr.conf
@@ -0,0 +1,14 @@
+!
+interface r4-eth0
+ ip address 192.0.2.4/24
+!
+ip route 172.16.16.254/32 Null0
+!
+router bgp 65004
+ no bgp ebgp-requires-policy
+ neighbor 192.0.2.1 remote-as external
+ !
+ address-family ipv4 unicast
+  network 172.16.16.254/32
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r5/frr.conf b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r5/frr.conf
new file mode 100644
index 0000000000..177943c0a8
--- /dev/null
+++ b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/r5/frr.conf
@@ -0,0 +1,8 @@
+!
+interface r5-eth0
+ ip address 192.0.2.5/24
+!
+router bgp 65005
+ no bgp ebgp-requires-policy
+ neighbor 192.0.2.1 remote-as external
+!
diff --git a/tests/topotests/bgp_addpath_best_selected_dynamic_peers/test_bgp_addpath_best_selected_dynamic_peers.py b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/test_bgp_addpath_best_selected_dynamic_peers.py
new file mode 100644
index 0000000000..b78e577c18
--- /dev/null
+++ b/tests/topotests/bgp_addpath_best_selected_dynamic_peers/test_bgp_addpath_best_selected_dynamic_peers.py
@@ -0,0 +1,120 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+#
+# Copyright (c) 2026 by
+# Yukie Kawamata <y-kawamata@sakura.ad.jp>
+#
+
+"""
+Test that addpath-tx-best-selected count is inherited by dynamic peers
+created through bgp listen range + peer-group.
+
+Topology: a single switch connects r1 (listener/reflector) with r2-r5.
+r1 accepts dynamic peers from 192.0.2.0/24 into peer-group PG, which has
+`addpath-tx-best-selected 1`.  r2-r4 each advertise 172.16.16.254/32, so
+r1 has three paths.  r5 (also a dynamic peer in PG) must receive the
+best path plus one more selected path (two paths total).
+"""
+
+import os
+import sys
+import json
+import pytest
+import functools
+
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+from lib import topotest
+from lib.topogen import Topogen, get_topogen
+
+pytestmark = [pytest.mark.bgpd]
+
+
+def build_topo(tgen):
+    for routern in range(1, 6):
+        tgen.add_router("r{}".format(routern))
+
+    switch = tgen.add_switch("s1")
+    switch.add_link(tgen.gears["r1"])
+    switch.add_link(tgen.gears["r2"])
+    switch.add_link(tgen.gears["r3"])
+    switch.add_link(tgen.gears["r4"])
+    switch.add_link(tgen.gears["r5"])
+
+
+def setup_module(mod):
+    tgen = Topogen(build_topo, mod.__name__)
+    tgen.start_topology()
+
+    for router in tgen.routers().values():
+        router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(router.name)))
+
+    tgen.start_router()
+
+
+def teardown_module(mod):
+    tgen = get_topogen()
+    tgen.stop_topology()
+
+
+def test_bgp_addpath_best_selected_dynamic_peers():
+    tgen = get_topogen()
+
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    r1 = tgen.gears["r1"]
+    r5 = tgen.gears["r5"]
+
+    def _bgp_converge():
+        output = json.loads(r1.vtysh_cmd("show bgp ipv4 unicast 172.16.16.254/32 json"))
+        expected = {
+            "paths": [
+                {"aspath": {"string": "65002"}},
+                {"aspath": {"string": "65003"}},
+                {"aspath": {"string": "65004"}},
+            ]
+        }
+        return topotest.json_cmp(output, expected)
+
+    test_func = functools.partial(_bgp_converge)
+    _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
+    assert result is None, "r1 did not converge with three paths"
+
+    def _r5_session_established():
+        output = json.loads(r5.vtysh_cmd("show bgp neighbor 192.0.2.1 json"))
+        expected = {"192.0.2.1": {"bgpState": "Established"}}
+        return topotest.json_cmp(output, expected)
+
+    test_func = functools.partial(_r5_session_established)
+    _, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
+    assert result is None, "r5 did not establish dynamic session with r1"
+
+    def _r5_received_addpath_routes():
+        output = json.loads(
+            r5.vtysh_cmd("show bgp ipv4 neighbors 192.0.2.1 routes json")
+        )
+        expected = {
+            "routes": {
+                "172.16.16.254/32": [
+                    {"valid": True, "path": "65001 65002"},
+                    {"valid": True, "path": "65001 65003"},
+                ]
+            },
+            "totalRoutes": 1,
+            "totalPaths": 2,
+        }
+        return topotest.json_cmp(output, expected)
+
+    test_func = functools.partial(_r5_received_addpath_routes)
+    _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
+    assert (
+        result is None
+    ), "r5 received wrong number of Add-Path best selected routes (expected best + 1)"
+
+
+if __name__ == "__main__":
+    args = ["-s"] + sys.argv[1:]
+    sys.exit(pytest.main(args))