]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: add one test to bgp_set_aspath_replace.py
authorFrancois Dumontet <francois.dumontet@6wind.com>
Mon, 17 Jul 2023 15:48:49 +0000 (17:48 +0200)
committerFrancois Dumontet <francois.dumontet@6wind.com>
Mon, 7 Aug 2023 10:30:34 +0000 (12:30 +0200)
add support of  set as-path replace as-path-access-list

Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
tests/topotests/bgp_set_aspath_replace/test_bgp_set_aspath_replace.py

index 0433c15e0a1ebf589d34fef14c5726b1f6762618..c0e19fa35690ed7ab9ceca80a9507ce8722d7afc 100644 (file)
@@ -120,6 +120,82 @@ def test_bgp_set_aspath_replace_test2():
     ), "Failed overriding incoming AS-PATH with route-map replace with configured ASN"
 
 
+def test_bgp_set_aspath_replace_access_list():
+    tgen = get_topogen()
+
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    rname = "r1"
+    r1 = tgen.gears[rname]
+
+    r1.vtysh_cmd(
+        """
+conf
+ bgp as-path access-list FIRST permit ^65
+ route-map r2 permit 20
+  set as-path replace as-path-access-list FIRST 65002
+    """
+    )
+
+    expected = {
+        "routes": {
+            "172.16.255.31/32": [{"path": "65002 65500"}],
+            "172.16.255.32/32": [{"path": "65002 65002"}],
+        }
+    }
+
+    def _bgp_regexp_1(router):
+        output = json.loads(router.vtysh_cmd("show bgp ipv4 unicast json"))
+
+        return topotest.json_cmp(output, expected)
+
+    test_func = functools.partial(_bgp_regexp_1, tgen.gears["r1"])
+    _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
+
+    assert result is None, "Failed overriding incoming AS-PATH with regex 1 route-map"
+    r1.vtysh_cmd(
+        """
+conf
+ bgp as-path access-list SECOND permit 2
+ route-map r2 permit 10
+  set as-path replace as-path-access-list SECOND 65001
+    """
+    )
+
+    expected = {
+        "routes": {
+            "172.16.255.31/32": [{"path": "65001 65003"}],
+            "172.16.255.32/32": [{"path": "65002 65002"}],
+        }
+    }
+
+    test_func = functools.partial(_bgp_regexp_1, tgen.gears["r1"])
+    _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
+
+    assert result is None, "Failed overriding incoming AS-PATH with regex 2 route-map"
+
+    r1.vtysh_cmd(
+        """
+conf
+ bgp as-path access-list TER permit 3
+ route-map r2 permit 10
+  set as-path replace as-path-access-list TER
+    """
+    )
+    expected = {
+        "routes": {
+            "172.16.255.31/32": [{"path": "65002 65001"}],
+            "172.16.255.32/32": [{"path": "65002 65002"}],
+        }
+    }
+
+    test_func = functools.partial(_bgp_regexp_1, tgen.gears["r1"])
+    _, result = topotest.run_and_expect(test_func, None, count=30, wait=0.5)
+
+    assert result is None, "Failed overriding incoming AS-PATH with regex 3 route-map"
+
+
 if __name__ == "__main__":
     args = ["-s"] + sys.argv[1:]
     sys.exit(pytest.main(args))