Commit b675c81cf2 for frr

commit b675c81cf20c82ae1bd382cb5229d842dde56e56
Author: Brad House <bhouse@nexthop.ai>
Date:   Fri Oct 9 10:33:22 2026 +0000

    tests: check sticky MAC with a MAC mobility seq

    Add topotest bgp_evpn_sticky_mac_mobility. Two VTEPs, one L2-VNI:

    - r1 adds a static sticky MAC that was never remote. r2 must receive
      it with "MM:0, sticky MAC" and install it as a sticky remote MAC.
    - r2 advertises a MAC, r1 learns it as remote, and the MAC is then
      configured on r1 as static sticky. r1's local sequence number is 1.
      r2 must receive the route with "MM:1, sticky MAC" and install it as
      a sticky remote MAC.

    Signed-off-by: Brad House <bhouse@nexthop.ai>

diff --git a/tests/topotests/bgp_evpn_sticky_mac_mobility/__init__.py b/tests/topotests/bgp_evpn_sticky_mac_mobility/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/topotests/bgp_evpn_sticky_mac_mobility/r1/frr.conf b/tests/topotests/bgp_evpn_sticky_mac_mobility/r1/frr.conf
new file mode 100644
index 0000000000..5264f0e0c2
--- /dev/null
+++ b/tests/topotests/bgp_evpn_sticky_mac_mobility/r1/frr.conf
@@ -0,0 +1,17 @@
+!
+interface r1-eth0
+ ip address 192.168.1.1/24
+!
+ip route 10.0.0.2/32 192.168.1.2
+!
+router bgp 65000
+ bgp router-id 10.0.0.1
+ no bgp default ipv4-unicast
+ neighbor 192.168.1.2 remote-as internal
+ neighbor 192.168.1.2 timers 3 10
+ !
+ address-family l2vpn evpn
+  neighbor 192.168.1.2 activate
+  advertise-all-vni
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_evpn_sticky_mac_mobility/r2/frr.conf b/tests/topotests/bgp_evpn_sticky_mac_mobility/r2/frr.conf
new file mode 100644
index 0000000000..7da1478476
--- /dev/null
+++ b/tests/topotests/bgp_evpn_sticky_mac_mobility/r2/frr.conf
@@ -0,0 +1,17 @@
+!
+interface r2-eth0
+ ip address 192.168.1.2/24
+!
+ip route 10.0.0.1/32 192.168.1.1
+!
+router bgp 65000
+ bgp router-id 10.0.0.2
+ no bgp default ipv4-unicast
+ neighbor 192.168.1.1 remote-as internal
+ neighbor 192.168.1.1 timers 3 10
+ !
+ address-family l2vpn evpn
+  neighbor 192.168.1.1 activate
+  advertise-all-vni
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_evpn_sticky_mac_mobility/setup.sh b/tests/topotests/bgp_evpn_sticky_mac_mobility/setup.sh
new file mode 100644
index 0000000000..7e9cd94e5f
--- /dev/null
+++ b/tests/topotests/bgp_evpn_sticky_mac_mobility/setup.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+# SPDX-License-Identifier: ISC
+#
+# setup.sh <vtep-ip>: L2-VNI 100 bridged to a local access port.
+
+set -e
+
+vtep=$1
+
+ip addr add "$vtep/32" dev lo
+
+ip link add br100 type bridge stp_state 0
+ip link set br100 up
+ip link add vxlan100 type vxlan id 100 local "$vtep" dstport 4789 nolearning
+ip link set vxlan100 master br100
+ip link set vxlan100 up
+ip link add acc100 type dummy
+ip link set acc100 master br100
+ip link set acc100 up
diff --git a/tests/topotests/bgp_evpn_sticky_mac_mobility/test_bgp_evpn_sticky_mac_mobility.py b/tests/topotests/bgp_evpn_sticky_mac_mobility/test_bgp_evpn_sticky_mac_mobility.py
new file mode 100644
index 0000000000..62383de241
--- /dev/null
+++ b/tests/topotests/bgp_evpn_sticky_mac_mobility/test_bgp_evpn_sticky_mac_mobility.py
@@ -0,0 +1,205 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+#
+# Copyright (C) 2026 Nexthop Systems
+#
+
+"""
+A MAC learned from a remote VTEP and then configured locally as sticky (static)
+is advertised with a MAC Mobility sequence number above 0. The route must still
+carry the sticky flag (RFC 7432 section 7.7), and the remote VTEP must install
+the MAC as sticky.
+"""
+
+import os
+import re
+import sys
+import functools
+import pytest
+
+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, pytest.mark.evpn]
+
+VNI = 100
+R1_VTEP = "10.0.0.1"
+R2_VTEP = "10.0.0.2"
+FRESH_MAC = "00:00:5e:00:53:01"
+MOVED_MAC = "00:00:5e:00:53:02"
+
+
+def setup_module(mod):
+    topodef = {"s1": ("r1", "r2")}
+    tgen = Topogen(topodef, mod.__name__)
+    tgen.start_topology()
+
+    for rname, vtep in (("r1", R1_VTEP), ("r2", R2_VTEP)):
+        router = tgen.gears[rname]
+        router.cmd_raises(f"/bin/bash {CWD}/setup.sh {vtep}")
+        router.load_frr_config(os.path.join(CWD, f"{rname}/frr.conf"))
+
+    tgen.start_router()
+
+
+def teardown_module(mod):
+    tgen = get_topogen()
+    tgen.stop_topology()
+
+
+def _check_mac(router, mac, expected):
+    cmd = f"show evpn mac vni {VNI} mac {mac} json"
+    return topotest.router_json_cmp(router, cmd, {mac: expected})
+
+
+def _wait_mac(router, mac, expected, what):
+    test_func = functools.partial(_check_mac, router, mac, expected)
+    _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
+    assert result is None, f"{router.name}: {what}: {result}"
+
+
+def _bgp_paths(output):
+    if not isinstance(output, dict):
+        return
+    if "paths" in output:
+        for path in output["paths"]:
+            yield from path if isinstance(path, list) else [path]
+        return
+    for value in output.values():
+        yield from _bgp_paths(value)
+
+
+def _bgp_mac_mm(router, mac, nexthop):
+    """
+    MAC Mobility values of the global table paths for mac from nexthop, as
+    (seq, sticky) tuples.
+    """
+    output = router.vtysh_cmd(
+        f"show bgp l2vpn evpn route rd all mac {mac} json", isjson=True
+    )
+    mm = []
+    for p in _bgp_paths(output):
+        if not any(nh.get("ip") == nexthop for nh in p.get("nexthops", [])):
+            continue
+        ecomm = p.get("extendedCommunity", {}).get("string", "")
+        match = re.search(r"MM:(\d+)(, sticky MAC)?", ecomm)
+        mm.append((int(match.group(1)), bool(match.group(2))) if match else None)
+    return mm
+
+
+def _wait_bgp_mac_mm(router, mac, nexthop, seq, what):
+    test_func = functools.partial(_bgp_mac_mm, router, mac, nexthop)
+    _, result = topotest.run_and_expect(test_func, [(seq, True)], count=30, wait=1)
+    assert result == [(seq, True)], (
+        f"{router.name}: {what}: MAC Mobility (seq, sticky) from {nexthop} is {result}, "
+        f"want [({seq}, True)]"
+    )
+
+
+def test_evpn_converge():
+    tgen = get_topogen()
+
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    for rname, peer in (("r1", R2_VTEP), ("r2", R1_VTEP)):
+        router = tgen.gears[rname]
+        expected = {"numRemoteVteps": 1, "remoteVteps": [{"ip": peer}]}
+        test_func = functools.partial(
+            topotest.router_json_cmp, router, f"show evpn vni {VNI} json", expected
+        )
+        _, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
+        assert result is None, f"{rname}: VNI {VNI} has no remote VTEP {peer}: {result}"
+
+
+def test_evpn_sticky_mac_seq0():
+    """A sticky MAC that was never remote is advertised with sequence 0."""
+    tgen = get_topogen()
+
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    r1 = tgen.gears["r1"]
+    r2 = tgen.gears["r2"]
+
+    r1.cmd_raises(f"bridge fdb add {FRESH_MAC} dev acc100 master static sticky")
+    _wait_mac(
+        r1,
+        FRESH_MAC,
+        {"type": "local", "stickyMac": True, "localSequence": 0},
+        "sticky MAC is not local",
+    )
+
+    _wait_bgp_mac_mm(r2, FRESH_MAC, R1_VTEP, 0, "sticky MAC with sequence 0")
+    _wait_mac(
+        r2,
+        FRESH_MAC,
+        {
+            "type": "remote",
+            "remoteVtep": R1_VTEP,
+            "stickyMac": True,
+            "remoteSequence": 0,
+        },
+        "sticky MAC with sequence 0 is not remote sticky",
+    )
+
+
+def test_evpn_sticky_mac_after_move():
+    """
+    A MAC learned from r2, then configured on r1 as sticky, is advertised by r1
+    with sequence 1 and the sticky flag.
+    """
+    tgen = get_topogen()
+
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    r1 = tgen.gears["r1"]
+    r2 = tgen.gears["r2"]
+
+    r2.cmd_raises(f"bridge fdb add {MOVED_MAC} dev acc100 master dynamic")
+    _wait_mac(
+        r1,
+        MOVED_MAC,
+        {"type": "remote", "remoteVtep": R2_VTEP, "remoteSequence": 0},
+        "MAC from r2 is not remote",
+    )
+
+    r1.cmd_raises(f"bridge fdb replace {MOVED_MAC} dev acc100 master static sticky")
+    _wait_mac(
+        r1,
+        MOVED_MAC,
+        {"type": "local", "stickyMac": True, "localSequence": 1},
+        "MAC moved from r2 is not local sticky with sequence 1",
+    )
+
+    _wait_bgp_mac_mm(r2, MOVED_MAC, R1_VTEP, 1, "sticky MAC with sequence 1")
+    _wait_mac(
+        r2,
+        MOVED_MAC,
+        {
+            "type": "remote",
+            "remoteVtep": R1_VTEP,
+            "stickyMac": True,
+            "remoteSequence": 1,
+        },
+        "sticky MAC with sequence 1 is not remote sticky",
+    )
+
+
+def test_memory_leak():
+    tgen = get_topogen()
+    if not tgen.is_memleak_enabled():
+        pytest.skip("Memory leak test/report is disabled")
+
+    tgen.report_memory_leaks()
+
+
+if __name__ == "__main__":
+    args = ["-s"] + sys.argv[1:]
+    sys.exit(pytest.main(args))