]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: Check if `route-map vpn import` basic funtionality works fine
authorDonatas Abraitis <donatas@opensourcerouting.org>
Mon, 6 Feb 2023 16:38:52 +0000 (18:38 +0200)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Mon, 6 Feb 2023 16:44:10 +0000 (18:44 +0200)
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
tests/topotests/bgp_route_map_vpn_import/__init__.py [new file with mode: 0644]
tests/topotests/bgp_route_map_vpn_import/r1/bgpd.conf [new file with mode: 0644]
tests/topotests/bgp_route_map_vpn_import/r1/zebra.conf [new file with mode: 0644]
tests/topotests/bgp_route_map_vpn_import/test_bgp_route_map_vpn_import.py [new file with mode: 0644]

diff --git a/tests/topotests/bgp_route_map_vpn_import/__init__.py b/tests/topotests/bgp_route_map_vpn_import/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/topotests/bgp_route_map_vpn_import/r1/bgpd.conf b/tests/topotests/bgp_route_map_vpn_import/r1/bgpd.conf
new file mode 100644 (file)
index 0000000..c9ad0b1
--- /dev/null
@@ -0,0 +1,46 @@
+!
+debug bgp updates
+debug bgp vpn leak-from-vrf
+debug bgp vpn leak-to-vrf
+debug bgp nht
+debug route-map
+!
+router bgp 65001
+ bgp router-id 10.10.10.10
+ no bgp ebgp-requires-policy
+!
+router bgp 65001 vrf Customer
+ bgp router-id 192.168.1.2
+ no bgp ebgp-requires-policy
+ address-family ipv4 unicast
+  redistribute connected
+  rd vpn export 192.168.1.2:2
+  rt vpn import 192.168.1.2:2
+  rt vpn export 192.168.1.2:2
+  export vpn
+  import vpn
+ exit-address-family
+!
+router bgp 65001 vrf Service
+ bgp router-id 192.168.2.2
+ no bgp ebgp-requires-policy
+ address-family ipv4 unicast
+  redistribute connected
+  rd vpn export 192.168.2.2:2
+  rt vpn import 192.168.2.2:2 192.168.1.2:2
+  rt vpn export 192.168.2.2:2
+  route-map vpn import from-customer
+  export vpn
+  import vpn
+ exit-address-family
+!
+bgp extcommunity-list standard from-customer seq 5 permit rt 192.168.1.2:2
+!
+ip prefix-list p1 seq 5 permit 192.0.2.0/24
+!
+route-map from-customer permit 10
+ match extcommunity from-customer
+ match ip address prefix-list p1
+ set local-preference 123
+route-map from-customer permit 20
+!
diff --git a/tests/topotests/bgp_route_map_vpn_import/r1/zebra.conf b/tests/topotests/bgp_route_map_vpn_import/r1/zebra.conf
new file mode 100644 (file)
index 0000000..51966b2
--- /dev/null
@@ -0,0 +1,16 @@
+!
+interface lo
+ ip address 10.10.10.10/32
+!
+interface r1-eth0 vrf Customer
+ ip address 192.168.1.2/24
+!
+interface r1-eth1 vrf Service
+ ip address 192.168.2.2/24
+!
+interface r1-eth2
+ ip address 10.0.1.1/24
+!
+interface r1-eth3 vrf Customer
+ ip address 192.0.2.1/24
+!
diff --git a/tests/topotests/bgp_route_map_vpn_import/test_bgp_route_map_vpn_import.py b/tests/topotests/bgp_route_map_vpn_import/test_bgp_route_map_vpn_import.py
new file mode 100644 (file)
index 0000000..9de1b1a
--- /dev/null
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+
+#
+# Copyright (c) 2022 by
+# Donatas Abraitis <donatas@opensourcerouting.org>
+#
+# Permission to use, copy, modify, and/or distribute this software
+# for any purpose with or without fee is hereby granted, provided
+# that the above copyright notice and this permission notice appear
+# in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+# OF THIS SOFTWARE.
+#
+
+"""
+Test if `route-map vpn import NAME` works by setting/matching via route-maps.
+Routes from VRF Customer to VRF Service MUST be leaked and modified later
+with `route-map vpn import`.
+"""
+
+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, TopoRouter, get_topogen
+from lib.common_config import step
+
+pytestmark = [pytest.mark.bgpd]
+
+
+def build_topo(tgen):
+    tgen.add_router("r1")
+
+    switch = tgen.add_switch("s1")
+    switch.add_link(tgen.gears["r1"])
+
+    switch = tgen.add_switch("s2")
+    switch.add_link(tgen.gears["r1"])
+
+    switch = tgen.add_switch("s3")
+    switch.add_link(tgen.gears["r1"])
+
+    switch = tgen.add_switch("s4")
+    switch.add_link(tgen.gears["r1"])
+
+
+def setup_module(mod):
+    tgen = Topogen(build_topo, mod.__name__)
+    tgen.start_topology()
+
+    r1 = tgen.gears["r1"]
+
+    r1.run("ip link add Customer type vrf table 1001")
+    r1.run("ip link set up dev Customer")
+    r1.run("ip link set r1-eth0 master Customer")
+    r1.run("ip link add Service type vrf table 1002")
+    r1.run("ip link set up dev Service")
+    r1.run("ip link set r1-eth1 master Service")
+    r1.run("ip link set r1-eth3 master Customer")
+
+    router_list = tgen.routers()
+
+    for i, (rname, router) in enumerate(router_list.items(), 1):
+        router.load_config(
+            TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
+        )
+        router.load_config(
+            TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname))
+        )
+
+    tgen.start_router()
+
+
+def teardown_module(mod):
+    tgen = get_topogen()
+    tgen.stop_topology()
+
+
+def test_bgp_route_map_vpn_import():
+    tgen = get_topogen()
+
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    r1 = tgen.gears["r1"]
+
+    def _bgp_check_received_leaked_with_vpn_import():
+        output = json.loads(r1.vtysh_cmd("show bgp vrf Service ipv4 unicast json"))
+        expected = {
+            "routes": {
+                "192.0.2.0/24": [
+                    {
+                        "locPrf": 123,
+                    },
+                ],
+                "192.168.1.0/24": [
+                    {
+                        "locPrf": None,
+                    }
+                ],
+            }
+        }
+        return topotest.json_cmp(output, expected)
+
+    test_func = functools.partial(_bgp_check_received_leaked_with_vpn_import)
+    _, result = topotest.run_and_expect(test_func, None, count=60, wait=1)
+    assert result is None, "Failed, imported routes are not modified"
+
+
+if __name__ == "__main__":
+    args = ["-s"] + sys.argv[1:]
+    sys.exit(pytest.main(args))