]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: Check if BGP conditional advertisement works fine with static routes 14650/head
authorDonatas Abraitis <donatas@opensourcerouting.org>
Thu, 19 Oct 2023 17:25:23 +0000 (20:25 +0300)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Wed, 25 Oct 2023 04:51:36 +0000 (04:51 +0000)
If we modify the prefix-list that is used to define the routes to be
advertised, all of them MUST be advertised.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 3c9415125818b54416bd89b9f703f987ff91746c)

tests/topotests/bgp_conditional_advertisement_static_route/__init__.py [new file with mode: 0644]
tests/topotests/bgp_conditional_advertisement_static_route/r1/frr.conf [new file with mode: 0644]
tests/topotests/bgp_conditional_advertisement_static_route/r2/frr.conf [new file with mode: 0644]
tests/topotests/bgp_conditional_advertisement_static_route/r3/frr.conf [new file with mode: 0644]
tests/topotests/bgp_conditional_advertisement_static_route/test_bgp_conditional_advertisement_static_route.py [new file with mode: 0644]

diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/__init__.py b/tests/topotests/bgp_conditional_advertisement_static_route/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/r1/frr.conf b/tests/topotests/bgp_conditional_advertisement_static_route/r1/frr.conf
new file mode 100644 (file)
index 0000000..3e51337
--- /dev/null
@@ -0,0 +1,10 @@
+!
+int r1-eth0
+ ip address 192.168.1.1/24
+!
+router bgp 65000
+ no bgp ebgp-requires-policy
+ neighbor 192.168.1.2 remote-as internal
+ neighbor 192.168.1.2 timers 1 3
+ neighbor 192.168.1.2 timers connect 1
+!
diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/r2/frr.conf b/tests/topotests/bgp_conditional_advertisement_static_route/r2/frr.conf
new file mode 100644 (file)
index 0000000..9dc4099
--- /dev/null
@@ -0,0 +1,39 @@
+!
+!debug bgp conditional-advertisement
+!debug bgp updates
+!
+int r2-eth0
+ ip address 192.168.1.2/24
+!
+int r2-eth1
+ ip address 192.168.2.2/24
+!
+router bgp 65000
+ no bgp ebgp-requires-policy
+ bgp conditional-advertisement timer 5
+ neighbor 192.168.1.1 remote-as internal
+ neighbor 192.168.1.1 timers 1 3
+ neighbor 192.168.1.1 timers connect 1
+ neighbor 192.168.2.1 remote-as internal
+ neighbor 192.168.2.1 timers 1 3
+ neighbor 192.168.2.1 timers connect 1
+ address-family ipv4 unicast
+  redistribute static
+  neighbor 192.168.1.1 advertise-map advertise-map exist-map exist-map
+  neighbor 192.168.1.1 route-map deny-all out
+ exit-address-family
+!
+ip route 10.10.10.1/32 r2-eth0
+ip route 10.10.10.2/32 r2-eth0
+!
+ip prefix-list default seq 5 permit 0.0.0.0/0
+ip prefix-list advertise seq 5 permit 10.10.10.1/32
+!
+route-map deny-all deny 10
+!
+route-map exist-map permit 10
+ match ip address prefix-list default
+!
+route-map advertise-map permit 10
+ match ip address prefix-list advertise
+!
diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/r3/frr.conf b/tests/topotests/bgp_conditional_advertisement_static_route/r3/frr.conf
new file mode 100644 (file)
index 0000000..a24a2cb
--- /dev/null
@@ -0,0 +1,19 @@
+!
+int lo
+ ip address 10.10.10.1/32
+ ip address 10.10.10.2/32
+!
+int r3-eth0
+ ip address 192.168.2.1/24
+!
+router bgp 65000
+ no bgp ebgp-requires-policy
+ no bgp network import-check
+ neighbor 192.168.2.2 remote-as internal
+ neighbor 192.168.2.2 timers 1 3
+ neighbor 192.168.2.2 timers connect 1
+ !
+ address-family ipv4 unicast
+  neighbor 192.168.2.2 default-originate
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_conditional_advertisement_static_route/test_bgp_conditional_advertisement_static_route.py b/tests/topotests/bgp_conditional_advertisement_static_route/test_bgp_conditional_advertisement_static_route.py
new file mode 100644 (file)
index 0000000..9d61bbd
--- /dev/null
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+# SPDX-License-Identifier: ISC
+
+# Copyright (c) 2023 by
+# Donatas Abraitis <donatas@opensourcerouting.org>
+#
+
+"""
+Test if static route with BGP conditional advertisement works correctly
+if we modify the prefix-lists.
+"""
+
+import os
+import re
+import sys
+import json
+import pytest
+import functools
+
+pytestmark = pytest.mark.bgpd
+
+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 setup_module(mod):
+    topodef = {"s1": ("r1", "r2"), "s2": ("r2", "r3")}
+    tgen = Topogen(topodef, mod.__name__)
+    tgen.start_topology()
+
+    router_list = tgen.routers()
+
+    for _, (rname, router) in enumerate(router_list.items(), 1):
+        router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname)))
+
+    tgen.start_router()
+
+
+def teardown_module(mod):
+    tgen = get_topogen()
+    tgen.stop_topology()
+
+
+def test_bgp_conditional_advertisements_static_route():
+    tgen = get_topogen()
+
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    r2 = tgen.gears["r2"]
+
+    def _bgp_converge():
+        output = json.loads(
+            r2.vtysh_cmd(
+                "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
+            )
+        )
+        expected = {
+            "advertisedRoutes": {
+                "10.10.10.1/32": {
+                    "valid": True,
+                }
+            },
+            "totalPrefixCounter": 1,
+        }
+        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, "Can't converge"
+
+    step("Append prefix-list to advertise 10.10.10.2/32")
+
+    r2.vtysh_cmd(
+        """
+    configure terminal
+        ip prefix-list advertise seq 10 permit 10.10.10.2/32
+    """
+    )
+
+    def _bgp_check_advertised_after_update():
+        output = json.loads(
+            r2.vtysh_cmd(
+                "show bgp ipv4 unicast neighbor 192.168.1.1 advertised-routes json"
+            )
+        )
+        expected = {
+            "advertisedRoutes": {
+                "10.10.10.1/32": {
+                    "valid": True,
+                },
+                "10.10.10.2/32": {
+                    "valid": True,
+                },
+            },
+            "totalPrefixCounter": 2,
+        }
+        return topotest.json_cmp(output, expected)
+
+    test_func = functools.partial(
+        _bgp_check_advertised_after_update,
+    )
+    _, result = topotest.run_and_expect(test_func, None, count=30, wait=1)
+    assert result is None, "10.10.10.2/32 is not advertised after prefix-list update"
+
+
+if __name__ == "__main__":
+    args = ["-s"] + sys.argv[1:]
+    sys.exit(pytest.main(args))