]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: Check if labeled-unicast works correctly with addpath capability
authorDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 6 Dec 2022 16:24:13 +0000 (18:24 +0200)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 6 Dec 2022 16:24:13 +0000 (18:24 +0200)
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
tests/topotests/bgp_labeled_unicast_addpath/__init__.py [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/r1/bgpd.conf [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/r1/zebra.conf [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/r2/bgpd.conf [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/r2/zebra.conf [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/r3/bgpd.conf [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/r3/zebra.conf [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/r4/bgpd.conf [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/r4/zebra.conf [new file with mode: 0644]
tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py [new file with mode: 0644]

diff --git a/tests/topotests/bgp_labeled_unicast_addpath/__init__.py b/tests/topotests/bgp_labeled_unicast_addpath/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r1/bgpd.conf b/tests/topotests/bgp_labeled_unicast_addpath/r1/bgpd.conf
new file mode 100644 (file)
index 0000000..ae3812a
--- /dev/null
@@ -0,0 +1,14 @@
+router bgp 65001
+ no bgp ebgp-requires-policy
+ no bgp default ipv4-unicast
+ neighbor 192.168.31.3 remote-as external
+ neighbor 192.168.31.3 timers 1 3
+ neighbor 192.168.31.3 timers connect 1
+ address-family ipv4 unicast
+  redistribute connected
+ exit-address-family
+ !
+ address-family ipv4 labeled-unicast
+  neighbor 192.168.31.3 activate
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r1/zebra.conf b/tests/topotests/bgp_labeled_unicast_addpath/r1/zebra.conf
new file mode 100644 (file)
index 0000000..fbaccda
--- /dev/null
@@ -0,0 +1,7 @@
+!
+interface lo
+ ip address 10.0.0.1/32
+!
+interface r1-eth0
+ ip address 192.168.31.1/24
+!
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r2/bgpd.conf b/tests/topotests/bgp_labeled_unicast_addpath/r2/bgpd.conf
new file mode 100644 (file)
index 0000000..16dc1f3
--- /dev/null
@@ -0,0 +1,14 @@
+router bgp 65002
+ no bgp ebgp-requires-policy
+ no bgp default ipv4-unicast
+ neighbor 192.168.32.3 remote-as external
+ neighbor 192.168.32.3 timers 1 3
+ neighbor 192.168.32.3 timers connect 1
+ address-family ipv4 unicast
+  redistribute connected
+ exit-address-family
+ !
+ address-family ipv4 labeled-unicast
+  neighbor 192.168.32.3 activate
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r2/zebra.conf b/tests/topotests/bgp_labeled_unicast_addpath/r2/zebra.conf
new file mode 100644 (file)
index 0000000..8118d56
--- /dev/null
@@ -0,0 +1,7 @@
+!
+interface lo
+ ip address 10.0.0.1/32
+!
+interface r2-eth0
+ ip address 192.168.32.2/24
+!
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r3/bgpd.conf b/tests/topotests/bgp_labeled_unicast_addpath/r3/bgpd.conf
new file mode 100644 (file)
index 0000000..c38ed7e
--- /dev/null
@@ -0,0 +1,30 @@
+!
+router bgp 65003
+ no bgp default ipv4-unicast
+ no bgp ebgp-requires-policy
+ no bgp suppress-duplicates
+ bgp bestpath as-path multipath-relax
+ neighbor 192.168.31.1 remote-as external
+ neighbor 192.168.31.1 timers 1 3
+ neighbor 192.168.31.1 timers connect 1
+ neighbor 192.168.32.2 remote-as external
+ neighbor 192.168.32.2 timers 1 3
+ neighbor 192.168.32.2 timers connect 1
+ neighbor 192.168.34.4 remote-as external
+ neighbor 192.168.34.4 timers 1 3
+ neighbor 192.168.34.4 timers connect 1
+ address-family ipv4 labeled-unicast
+  neighbor 192.168.31.1 activate
+  neighbor 192.168.32.2 activate
+  neighbor 192.168.34.4 activate
+  neighbor 192.168.34.4 route-map r4 out
+  neighbor 192.168.34.4 addpath-tx-all-paths
+ exit-address-family
+ !
+!
+ip prefix-list r4 seq 5 permit 10.0.0.1/32
+!
+route-map r4 permit 10
+ match ip address prefix-list r4
+exit
+!
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r3/zebra.conf b/tests/topotests/bgp_labeled_unicast_addpath/r3/zebra.conf
new file mode 100644 (file)
index 0000000..1cc2ca2
--- /dev/null
@@ -0,0 +1,10 @@
+!
+interface r3-eth0
+ ip address 192.168.31.3/24
+!
+interface r3-eth1
+ ip address 192.168.32.3/24
+!
+interface r3-eth2
+ ip address 192.168.34.3/24
+!
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r4/bgpd.conf b/tests/topotests/bgp_labeled_unicast_addpath/r4/bgpd.conf
new file mode 100644 (file)
index 0000000..e137156
--- /dev/null
@@ -0,0 +1,10 @@
+router bgp 65004
+ no bgp ebgp-requires-policy
+ no bgp default ipv4-unicast
+ neighbor 192.168.34.3 remote-as external
+ neighbor 192.168.34.3 timers 1 3
+ neighbor 192.168.34.3 timers connect 1
+ address-family ipv4 labeled-unicast
+  neighbor 192.168.34.3 activate
+ exit-address-family
+!
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/r4/zebra.conf b/tests/topotests/bgp_labeled_unicast_addpath/r4/zebra.conf
new file mode 100644 (file)
index 0000000..2ec426a
--- /dev/null
@@ -0,0 +1,4 @@
+!
+interface r4-eth0
+ ip address 192.168.34.4/24
+!
diff --git a/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py b/tests/topotests/bgp_labeled_unicast_addpath/test_bgp_labeled_unicast_addpath.py
new file mode 100644 (file)
index 0000000..9e7dd40
--- /dev/null
@@ -0,0 +1,142 @@
+#!/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.
+#
+
+"""
+Check if labeled-unicast works correctly with addpath capability.
+"""
+
+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):
+    for routern in range(1, 5):
+        tgen.add_router("r{}".format(routern))
+
+    switch = tgen.add_switch("s1")
+    switch.add_link(tgen.gears["r1"])
+    switch.add_link(tgen.gears["r3"])
+
+    switch = tgen.add_switch("s2")
+    switch.add_link(tgen.gears["r2"])
+    switch.add_link(tgen.gears["r3"])
+
+    switch = tgen.add_switch("s3")
+    switch.add_link(tgen.gears["r3"])
+    switch.add_link(tgen.gears["r4"])
+
+
+def setup_module(mod):
+    tgen = Topogen(build_topo, mod.__name__)
+    tgen.start_topology()
+
+    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_addpath_labeled_unicast():
+    tgen = get_topogen()
+
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    r3 = tgen.gears["r3"]
+    r4 = tgen.gears["r4"]
+
+    def _bgp_check_advertised_routes():
+        output = json.loads(
+            r3.vtysh_cmd(
+                "show bgp ipv4 labeled-unicast neighbors 192.168.34.4 advertised-routes json"
+            )
+        )
+        expected = {
+            "advertisedRoutes": {
+                "10.0.0.1/32": {
+                    "appliedStatusSymbols": {
+                        "*": True,
+                        ">": True,
+                        "=": True,
+                    }
+                }
+            },
+            "totalPrefixCounter": 2,
+        }
+        return topotest.json_cmp(output, expected)
+
+    test_func = functools.partial(_bgp_check_advertised_routes)
+    _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+    assert (
+        result is None
+    ), "Failed to advertise labeled-unicast with addpath (multipath)"
+
+    def _bgp_check_received_routes():
+        output = json.loads(r4.vtysh_cmd("show bgp ipv4 labeled-unicast json"))
+        expected = {
+            "routes": {
+                "10.0.0.1/32": [
+                    {
+                        "valid": True,
+                        "path": "65003 65001",
+                    },
+                    {
+                        "valid": True,
+                        "path": "65003 65002",
+                    },
+                ]
+            }
+        }
+        return topotest.json_cmp(output, expected)
+
+    test_func = functools.partial(_bgp_check_received_routes)
+    _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5)
+    assert result is None, "Failed to receive labeled-unicast with addpath (multipath)"
+
+
+if __name__ == "__main__":
+    args = ["-s"] + sys.argv[1:]
+    sys.exit(pytest.main(args))