Commit e8c9c3c0cc for frr
commit e8c9c3c0cc4f2b734f4c07b3c4d3a40c8fe8d5fe
Author: Nageswara Soma <nsoma@cisco.com>
Date: Sun Nov 22 13:10:50 2026 -0800
tests: cover restored routes during refresh
Exercise A-to-B-to-A and withdraw-to-A processing
while replies are held. Wait for outbound versions
and verify the route exists without stale state at
EoRR.
Handle wrapped queue output and describe the log check
by test name.
Signed-off-by: Nageswara Soma <nsoma@cisco.com>
diff --git a/tests/topotests/bgp_enhanced_route_refresh/test_bgp_enhanced_route_refresh.py b/tests/topotests/bgp_enhanced_route_refresh/test_bgp_enhanced_route_refresh.py
index c7cbf0d9f6..2a1bfc3ebb 100644
--- a/tests/topotests/bgp_enhanced_route_refresh/test_bgp_enhanced_route_refresh.py
+++ b/tests/topotests/bgp_enhanced_route_refresh/test_bgp_enhanced_route_refresh.py
@@ -15,10 +15,11 @@ at the same time.
An unchanged eBGP advertisement must also survive normal route reprocessing
while its forced refresh reply is queued. After EoRR, r2 must retain the
-refreshed path without a stale flag.
+refreshed path without a stale flag, including when attributes change and
+return to their original values or a route is withdrawn and restored.
Which markers were ignored or rejected is not visible in any show command,
-so the second test reads r2's bgpd.log, written under
+so the dual-AF refresh test reads r2's bgpd.log, written under
`debug bgp neighbor-events`.
"""
@@ -224,7 +225,8 @@ def test_bgp_dual_af_refresh():
assert False, "the two refreshes did not overlap in {} attempts".format(attempts)
-def test_refresh_survives_unchanged_egress_attributes():
+@pytest.mark.parametrize("change", ["local_preference", "metric", "withdraw"])
+def test_refresh_survives_unchanged_egress_attributes(change):
"""A normal reprocess must not cancel a queued route-refresh reply."""
tgen = get_topogen()
if tgen.routers_have_failure():
@@ -237,48 +239,91 @@ def test_refresh_survives_unchanged_egress_attributes():
prefix = "10.0.0.1/32"
r1.vtysh_cmd(
"configure terminal\nbgp route-map delay-timer 1\n"
- "route-map REFRESH_TEST permit 10\nset local-preference 100\n"
+ "route-map REFRESH_TEST permit 10\nset local-preference 100\nset metric 100\n"
"router bgp 65001\naddress-family ipv4 unicast\n"
"network {} route-map REFRESH_TEST\nend".format(prefix)
)
- # Local preference changes best-path state but is not sent over eBGP.
- def local_pref(expected):
- route = r1.vtysh_cmd(
+ def route_matches(router, expected):
+ route = router.vtysh_cmd(
"show bgp ipv4 unicast {} json".format(prefix), isjson=True
)
paths = route.get("paths", [])
- return bool(paths) and paths[0].get("locPrf") == expected
+ if expected is None:
+ return not paths
+ return bool(paths) and all(paths[0].get(k) == v for k, v in expected.items())
+
+ def queued_metric():
+ output = r1.vtysh_cmd("show bgp ipv4 unicast update-groups advertise-queue")
+ # A long prefix can put its next hop and metric on the following line.
+ fields = output.split()
+ if prefix in fields:
+ return int(fields[fields.index(prefix) + 2])
+ return None
+
+ def reprocess(config, expected):
+ version = r1.vtysh_cmd("show bgp ipv4 unicast json", isjson=True)[
+ "tableVersion"
+ ]
+ r1.vtysh_cmd("configure terminal\n{}\nend".format(config))
+
+ def processed():
+ if not route_matches(r1, expected):
+ return False
+ current = r1.vtysh_cmd("show bgp ipv4 unicast json", isjson=True)[
+ "tableVersion"
+ ]
+ groups = r1.vtysh_cmd(
+ "show bgp ipv4 unicast update-groups json", isjson=True
+ )["default"]
+ # Wait for outbound processing, not just the local attribute change.
+ return current > version and any(
+ R2 in subgroup.get("peers", []) and subgroup["version"] >= current
+ for group in groups.values()
+ for subgroup in group["subGroup"]
+ )
+
+ ok, _ = topotest.run_and_expect(processed, True, count=30, wait=1)
+ assert ok, "The route change was not processed for r2"
- ok, _ = topotest.run_and_expect(lambda: local_pref(100), True, count=30, wait=1)
- assert ok, "Initial local preference was not applied"
+ for router in [r1, r2]:
+ ok, _ = topotest.run_and_expect(
+ lambda: route_matches(router, {"metric": 100}), True, count=30, wait=1
+ )
+ assert ok, "Initial metric was not applied on {}".format(router.name)
before = _stats_towards_r1(r2)["routeRefreshRecv"]
try:
r1.vtysh_cmd("bgp test updates disable neighbor {}".format(R2))
r2.vtysh_cmd("clear bgp ipv4 unicast {} soft in".format(R1))
_wait_refresh_received(r2, before + 1)
- def queued():
- return prefix in r1.vtysh_cmd(
- "show bgp ipv4 unicast update-groups advertise-queue"
- )
-
- ok, _ = topotest.run_and_expect(queued, True, count=30, wait=1)
+ ok, _ = topotest.run_and_expect(queued_metric, 100, count=30, wait=1)
assert ok, "The forced refresh reply was not queued"
- version = r1.vtysh_cmd("show bgp ipv4 unicast json", isjson=True)[
- "tableVersion"
- ]
- r1.vtysh_cmd(
- "configure terminal\nroute-map REFRESH_TEST permit 10\n"
- "set local-preference 200\nend"
- )
-
- def reprocessed():
- output = r1.vtysh_cmd("show bgp ipv4 unicast json", isjson=True)
- return local_pref(200) and output["tableVersion"] > version
+ network = "router bgp 65001\naddress-family ipv4 unicast\n"
+ network += "network {} route-map REFRESH_TEST".format(prefix)
+ if change == "local_preference":
+ # Local preference changes best-path state but is not sent over eBGP.
+ reprocess(
+ "route-map REFRESH_TEST permit 10\nset local-preference 200",
+ {"locPrf": 200, "metric": 100},
+ )
+ elif change == "metric":
+ reprocess(
+ "route-map REFRESH_TEST permit 10\nset metric 200", {"metric": 200}
+ )
+ assert queued_metric() == 200, "The changed advertisement was not queued"
+ reprocess(
+ "route-map REFRESH_TEST permit 10\nset metric 100", {"metric": 100}
+ )
+ else:
+ reprocess(
+ "router bgp 65001\naddress-family ipv4 unicast\n"
+ "no network {}".format(prefix),
+ None,
+ )
+ assert queued_metric() is None, "The refresh reply was not withdrawn"
+ reprocess(network, {"metric": 100})
- ok, _ = topotest.run_and_expect(reprocessed, True, count=30, wait=1)
- assert ok, "The route was not reprocessed with its new local preference"
r1.vtysh_cmd("no bgp test updates disable neighbor {}".format(R2))
_wait_refresh_received(r2, before + 2)
route = r2.vtysh_cmd(
@@ -289,6 +334,7 @@ def test_refresh_survives_unchanged_egress_attributes():
assert not any(
path.get("stale", False) for path in paths
), "Refresh left a route stale with unchanged egress attributes"
+ assert all(path.get("metric") == 100 for path in paths), "Incorrect metric"
finally:
r1.vtysh_cmd("no bgp test updates disable neighbor {}".format(R2))
r1.vtysh_cmd(