]> git.puffer.fish Git - mirror/frr.git/commitdiff
topotests: bmp, test syncro for pre/post-policy of imported bgps
authorPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 12 Nov 2024 08:41:46 +0000 (09:41 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 7 Jan 2025 14:35:32 +0000 (15:35 +0100)
Add a test that controls that the configuration of an imported
BGP instance triggers a re-syncronisation.
Ensure that changing an attribute like route distinguisher
triggers also a re-syncronisation.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
tests/topotests/bgp_bmp/bmp1import/bmp-update-loc-rib-step2.json [new file with mode: 0644]
tests/topotests/bgp_bmp/bmp1import/bmp-update-post-policy-step2.json [new file with mode: 0644]
tests/topotests/bgp_bmp/bmp1import/bmp-update-pre-policy-step2.json [new file with mode: 0644]
tests/topotests/bgp_bmp/bmp1import/bmp-withdraw-post-policy-step2.json [deleted file]
tests/topotests/bgp_bmp/test_bgp_bmp_3.py

diff --git a/tests/topotests/bgp_bmp/bmp1import/bmp-update-loc-rib-step2.json b/tests/topotests/bgp_bmp/bmp1import/bmp-update-loc-rib-step2.json
new file mode 100644 (file)
index 0000000..60066d5
--- /dev/null
@@ -0,0 +1,34 @@
+{
+    "loc-rib": {
+        "update": {
+            "172.31.0.77/32": {
+                "as_path": "",
+                "bgp_nexthop": "192.168.1.3",
+                "bmp_log_type": "update",
+                "ip_prefix": "172.31.0.77/32",
+                "is_filtered": false,
+                "origin": "IGP",
+                "peer_asn": 65501,
+                "peer_bgp_id": "192.168.0.1",
+                "peer_distinguisher": "666:22",
+                "peer_type": "loc-rib instance",
+                "policy": "loc-rib"
+            },
+            "2001::1125/128": {
+                "afi": 2,
+                "as_path": "",
+                "bmp_log_type": "update",
+                "ip_prefix": "2001::1125/128",
+                "is_filtered": false,
+                "nxhp_ip": "192:167::3",
+                "origin": "IGP",
+                "peer_asn": 65501,
+                "peer_bgp_id": "192.168.0.1",
+                "peer_distinguisher": "666:22",
+                "peer_type": "loc-rib instance",
+                "policy": "loc-rib",
+                "safi": 1
+            }
+        }
+    }
+}
diff --git a/tests/topotests/bgp_bmp/bmp1import/bmp-update-post-policy-step2.json b/tests/topotests/bgp_bmp/bmp1import/bmp-update-post-policy-step2.json
new file mode 100644 (file)
index 0000000..b555c2a
--- /dev/null
@@ -0,0 +1,36 @@
+{
+    "post-policy": {
+        "update": {
+            "172.31.0.77/32": {
+                "as_path": "",
+                "bgp_nexthop": "192.168.1.3",
+                "bmp_log_type": "update",
+                "ip_prefix": "172.31.0.77/32",
+                "ipv6": false,
+                "origin": "IGP",
+                "peer_asn": 65501,
+                "peer_bgp_id": "192.168.1.3",
+                "peer_distinguisher": "666:22",
+                "peer_ip": "192.168.1.3",
+                "peer_type": "route distinguisher instance",
+                "policy": "post-policy"
+            },
+            "2001::1125/128": {
+                "afi": 2,
+                "as_path": "",
+                "bmp_log_type": "update",
+                "ip_prefix": "2001::1125/128",
+                "ipv6": true,
+                "nxhp_ip": "192:167::3",
+                "origin": "IGP",
+                "peer_asn": 65501,
+                "peer_bgp_id": "192.168.1.3",
+                "peer_distinguisher": "666:22",
+                "peer_ip": "192:167::3",
+                "peer_type": "route distinguisher instance",
+                "policy": "post-policy",
+                "safi": 1
+            }
+        }
+    }
+}
diff --git a/tests/topotests/bgp_bmp/bmp1import/bmp-update-pre-policy-step2.json b/tests/topotests/bgp_bmp/bmp1import/bmp-update-pre-policy-step2.json
new file mode 100644 (file)
index 0000000..2054992
--- /dev/null
@@ -0,0 +1,36 @@
+{
+    "pre-policy": {
+        "update": {
+            "172.31.0.77/32": {
+                "as_path": "",
+                "bgp_nexthop": "192.168.1.3",
+                "bmp_log_type": "update",
+                "ip_prefix": "172.31.0.77/32",
+                "ipv6": false,
+                "origin": "IGP",
+                "peer_asn": 65501,
+                "peer_bgp_id": "192.168.1.3",
+                "peer_distinguisher": "666:22",
+                "peer_ip": "192.168.1.3",
+                "peer_type": "route distinguisher instance",
+                "policy": "pre-policy"
+            },
+            "2001::1125/128": {
+                "afi": 2,
+                "as_path": "",
+                "bmp_log_type": "update",
+                "ip_prefix": "2001::1125/128",
+                "ipv6": true,
+                "nxhp_ip": "192:167::3",
+                "origin": "IGP",
+                "peer_asn": 65501,
+                "peer_bgp_id": "192.168.1.3",
+                "peer_distinguisher": "666:22",
+                "peer_ip": "192:167::3",
+                "peer_type": "route distinguisher instance",
+                "policy": "pre-policy",
+                "safi": 1
+            }
+        }
+    }
+}
diff --git a/tests/topotests/bgp_bmp/bmp1import/bmp-withdraw-post-policy-step2.json b/tests/topotests/bgp_bmp/bmp1import/bmp-withdraw-post-policy-step2.json
deleted file mode 100644 (file)
index 9eb221d..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-{
-    "post-policy": {
-        "withdraw": {
-            "2001::1111/128": {
-                "afi": 2,
-                "bmp_log_type": "withdraw",
-                "ip_prefix": "2001::1111/128",
-                "ipv6": true,
-                "label": 0,
-                "peer_asn": 65502,
-                "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
-                "peer_ip": "192:168::2",
-                "peer_type": "global instance",
-                "policy": "post-policy",
-                "rd": "555:2",
-                "safi": 128
-            },
-            "172.31.0.15/32": {
-                "afi": 1,
-                "bmp_log_type": "withdraw",
-                "ip_prefix": "172.31.0.15/32",
-                "ipv6": false,
-                "label": 0,
-                "peer_asn": 65502,
-                "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
-                "peer_ip": "192.168.0.2",
-                "peer_type": "global instance",
-                "policy": "post-policy",
-                "rd": "444:2",
-                "safi": 128
-            }
-        }
-    }
-}
index a108774821aabdb9934a35f942003dbf1c06bde2..212cf9e69675d01f838dd9e8497c21f8094bc514 100644 (file)
@@ -124,6 +124,32 @@ def test_bgp_convergence():
     assert result is True, "BGP is not converging"
 
 
+def _test_prefixes_syncro(policy, vrf=None, step=1):
+    """
+    Check that the given policy has syncronised the previously received BGP
+    updates.
+    """
+    tgen = get_topogen()
+
+    prefixes = ["172.31.0.77/32", "2001::1125/128"]
+    # check
+    test_func = partial(
+        bmp_check_for_prefixes,
+        prefixes,
+        "update",
+        policy,
+        step,
+        tgen.gears["bmp1import"],
+        os.path.join(tgen.logdir, "bmp1import"),
+        tgen.gears["r1import"],
+        f"{CWD}/bmp1import",
+        UPDATE_EXPECTED_JSON,
+        LOC_RIB,
+    )
+    success, res = topotest.run_and_expect(test_func, None, count=30, wait=1)
+    assert success, "Checking the updated prefixes has failed ! %s" % res
+
+
 def _test_prefixes(policy, vrf=None, step=0):
     """
     Setup the BMP  monitor policy, Add and withdraw ipv4/v6 prefixes.
@@ -270,6 +296,63 @@ def test_peer_down():
     assert success, "Checking the updated prefixes has been failed !."
 
 
+def test_reconfigure_prefixes():
+    """
+    Reconfigured BGP networks from R3. Check for BGP VRF update messages
+    """
+
+    tgen = get_topogen()
+
+    prefixes = ["172.31.0.77/32", "2001::1125/128"]
+    bgp_configure_prefixes(
+        tgen.gears["r3"],
+        65501,
+        "unicast",
+        prefixes,
+        vrf=None,
+        update=True,
+    )
+
+    for ipver in [4, 6]:
+        ref_file = "{}/r1import/show-bgp-{}-ipv{}-{}-step{}.json".format(
+            CWD, "vrf1", ipver, "update", 1
+        )
+        expected = json.loads(open(ref_file).read())
+
+        test_func = partial(
+            topotest.router_json_cmp,
+            tgen.gears["r1import"],
+            f"show bgp vrf vrf1 ipv{ipver} json",
+            expected,
+        )
+        _, res = topotest.run_and_expect(test_func, None, count=30, wait=1)
+        assertmsg = f"r1: BGP IPv{ipver} convergence failed"
+        assert res is None, assertmsg
+
+
+def test_monitor_syncro():
+    """
+    Checking for BMP peers down messages
+    """
+    tgen = get_topogen()
+
+    tgen.gears["r1import"].vtysh_cmd(
+        """
+        configure terminal
+        router bgp 65501
+        bmp targets bmp1
+        bmp import-vrf-view vrf1
+        """
+    )
+
+    logger.info("*** Unicast prefixes pre-policy logging ***")
+    _test_prefixes_syncro(PRE_POLICY, vrf="vrf1")
+    logger.info("*** Unicast prefixes post-policy logging ***")
+    _test_prefixes_syncro(POST_POLICY, vrf="vrf1")
+    logger.info("*** Unicast prefixes loc-rib logging ***")
+    _test_prefixes_syncro(LOC_RIB, vrf="vrf1")
+
+
 def test_reconfigure_route_distinguisher_vrf1():
     """
     Checking for BMP peers down messages
@@ -293,7 +376,7 @@ def test_reconfigure_route_distinguisher_vrf1():
         """
     )
     logger.info(
-        "checking for BMP peer down LOC-RIB message with route-distinguisher set to 444:1"
+        "Checking for BMP peer down LOC-RIB message with route-distinguisher set to 444:1"
     )
     test_func = partial(
         bmp_check_for_peer_message,
@@ -310,7 +393,7 @@ def test_reconfigure_route_distinguisher_vrf1():
     ), "Checking the BMP peer down LOC-RIB message with route-distinguisher set to 444:1 failed !."
 
     logger.info(
-        "checking for BMP peer up LOC-RIB messages with route-distinguisher set to 666:22"
+        "Checking for BMP peer up LOC-RIB messages with route-distinguisher set to 666:22"
     )
     test_func = partial(
         bmp_check_for_peer_message,
@@ -327,7 +410,7 @@ def test_reconfigure_route_distinguisher_vrf1():
     ), "Checking the BMP peer up LOC-RIB message with route-distinguisher set to 666:22 failed !."
 
     logger.info(
-        "checking for BMP peer up messages with route-distinguisher set to 666:22"
+        "Checking for BMP peer up messages with route-distinguisher set to 666:22"
     )
     peers = ["192.168.1.3", "192:167::3"]
     test_func = partial(
@@ -344,6 +427,13 @@ def test_reconfigure_route_distinguisher_vrf1():
         success
     ), "Checking the BMP peer up messages with route-distinguisher set to 666:22 failed !."
 
+    logger.info("*** Unicast prefixes pre-policy logging ***")
+    _test_prefixes_syncro(PRE_POLICY, vrf="vrf1", step=2)
+    logger.info("*** Unicast prefixes post-policy logging ***")
+    _test_prefixes_syncro(POST_POLICY, vrf="vrf1", step=2)
+    logger.info("*** Unicast prefixes loc-rib logging ***")
+    _test_prefixes_syncro(LOC_RIB, vrf="vrf1", step=2)
+
 
 def test_bgp_routerid_changed():
     """