]> git.proxmox.com Git - mirror_frr.git/blobdiff - tests/topotests/zebra_rib/test_zebra_rib.py
Merge pull request #13455 from sri-mohan1/srib-ldpd
[mirror_frr.git] / tests / topotests / zebra_rib / test_zebra_rib.py
index ae891d90677a4d8b578db2f2f90e54a17b33b765..e2863218b0c1546f49e5d3e045c15d293f82e126 100644 (file)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# SPDX-License-Identifier: ISC
 #
 # test_zebra_rib.py
 #
@@ -6,20 +7,6 @@
 # Cumulus Networks, Inc
 # Donald Sharp
 #
-# 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_zebra_rib.py: Test some basic zebra <-> kernel interactions
@@ -31,6 +18,7 @@ import sys
 from functools import partial
 import pytest
 import json
+import platform
 
 # Save the Current Working Directory to find configuration files.
 CWD = os.path.dirname(os.path.realpath(__file__))
@@ -45,11 +33,26 @@ from time import sleep
 
 
 pytestmark = [pytest.mark.sharpd]
+krel = platform.release()
+
+
+def config_macvlan(tgen, r_str, device, macvlan):
+    "Creates specified macvlan interace on physical device"
+
+    if topotest.version_cmp(krel, "5.1") < 0:
+        return
+
+    router = tgen.gears[r_str]
+    router.run(
+        "ip link add {} link {} type macvlan mode bridge".format(macvlan, device)
+    )
+    router.run("ip link set {} up".format(macvlan))
 
 
 def setup_module(mod):
     "Sets up the pytest environment"
-    topodef = {"s1": ("r1", "r1", "r1", "r1", "r1", "r1", "r1", "r1")}
+    # 8 links to 8 switches on r1
+    topodef = {"s{}".format(x): ("r1",) for x in range(1, 9)}
     tgen = Topogen(topodef, mod.__name__)
     tgen.start_topology()
 
@@ -62,6 +65,8 @@ def setup_module(mod):
             TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname))
         )
 
+    # Macvlan interface for protodown func test */
+    config_macvlan(tgen, "r1", "r1-eth0", "r1-eth0-macvlan")
     # Initialize all routers.
     tgen.start_router()
 
@@ -186,7 +191,16 @@ def test_route_map_usage():
     r1.vtysh_cmd("conf\nip route 10.100.100.100/32 192.168.216.3")
     r1.vtysh_cmd("conf\nip route 10.100.100.101/32 10.0.0.44")
     r1.vtysh_cmd("sharp install route 10.0.0.0 nexthop 192.168.216.3 500")
-    sleep(4)
+
+    def check_initial_routes_installed(router):
+        output = json.loads(router.vtysh_cmd("show ip route summ json"))
+        expected = {
+            "routes": [{"type": "static", "rib": 2}, {"type": "sharp", "rib": 500}]
+        }
+        return topotest.json_cmp(output, expected)
+
+    test_func = partial(check_initial_routes_installed, r1)
+    success, result = topotest.run_and_expect(test_func, None, count=40, wait=1)
 
     static_rmapfile = "%s/r1/static_rmap.ref" % (thisDir)
     expected = open(static_rmapfile).read().rstrip()
@@ -269,6 +283,46 @@ def test_route_map_usage():
     assert ok, result
 
 
+def test_protodown():
+    "Run protodown basic functionality test and report results."
+    pdown = False
+    count = 0
+    tgen = get_topogen()
+    if topotest.version_cmp(krel, "5.1") < 0:
+        tgen.errors = "kernel 5.1 needed for protodown tests"
+        pytest.skip(tgen.errors)
+
+    r1 = tgen.gears["r1"]
+
+    # Set interface protodown on
+    r1.vtysh_cmd("sharp interface r1-eth0-macvlan protodown")
+
+    # Timeout to wait for dplane to handle it
+    while count < 10:
+        count += 1
+        output = r1.vtysh_cmd("show interface r1-eth0-macvlan")
+        if re.search(r"protodown reasons:.*sharp", output):
+            pdown = True
+            break
+        sleep(1)
+
+    assert pdown is True, "Interface r1-eth0-macvlan not set protodown"
+
+    # Set interface protodown off
+    r1.vtysh_cmd("no sharp interface r1-eth0-macvlan protodown")
+
+    # Timeout to wait for dplane to handle it
+    while count < 10:
+        count += 1
+        output = r1.vtysh_cmd("show interface r1-eth0-macvlan")
+        if not re.search(r"protodown reasons:.*sharp", output):
+            pdown = False
+            break
+        sleep(1)
+
+    assert pdown is False, "Interface r1-eth0-macvlan not set protodown off"
+
+
 def test_memory_leak():
     "Run the memory leak test and report results."
     tgen = get_topogen()