]> git.puffer.fish Git - mirror/frr.git/commitdiff
tests: add new topotest to verify SRv6 locators
authorCarmine Scarpitta <carmine.scarpitta@uniroma2.it>
Sat, 23 Jul 2022 16:30:03 +0000 (18:30 +0200)
committerCarmine Scarpitta <carmine.scarpitta@uniroma2.it>
Tue, 18 Oct 2022 14:08:23 +0000 (16:08 +0200)
This commit adds a new topotest to verify the functionality of SRv6
locators with custom bits length parameters.

Signed-off-by: Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
17 files changed:
tests/topotests/srv6_locator_custom_bits_length/__init__.py [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_chunks1.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_chunks2.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_chunks3.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_chunks4.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_chunks5.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_chunks6.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_locators1.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_locators2.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_locators3.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_locators4.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_locators5.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/expected_locators6.json [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/r1/setup.sh [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/r1/sharpd.conf [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/r1/zebra.conf [new file with mode: 0644]
tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator.py [new file with mode: 0755]

diff --git a/tests/topotests/srv6_locator_custom_bits_length/__init__.py b/tests/topotests/srv6_locator_custom_bits_length/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_chunks1.json b/tests/topotests/srv6_locator_custom_bits_length/expected_chunks1.json
new file mode 100644 (file)
index 0000000..fe51488
--- /dev/null
@@ -0,0 +1 @@
+[]
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_chunks2.json b/tests/topotests/srv6_locator_custom_bits_length/expected_chunks2.json
new file mode 100644 (file)
index 0000000..9f34c58
--- /dev/null
@@ -0,0 +1,8 @@
+[
+  {
+    "name": "loc1",
+    "chunks": [
+      "2001:db8:1::/64"
+    ]
+  }
+]
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_chunks3.json b/tests/topotests/srv6_locator_custom_bits_length/expected_chunks3.json
new file mode 100644 (file)
index 0000000..fe51488
--- /dev/null
@@ -0,0 +1 @@
+[]
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_chunks4.json b/tests/topotests/srv6_locator_custom_bits_length/expected_chunks4.json
new file mode 100644 (file)
index 0000000..0d4f101
--- /dev/null
@@ -0,0 +1,2 @@
+[
+]
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_chunks5.json b/tests/topotests/srv6_locator_custom_bits_length/expected_chunks5.json
new file mode 100644 (file)
index 0000000..0d4f101
--- /dev/null
@@ -0,0 +1,2 @@
+[
+]
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_chunks6.json b/tests/topotests/srv6_locator_custom_bits_length/expected_chunks6.json
new file mode 100644 (file)
index 0000000..0d4f101
--- /dev/null
@@ -0,0 +1,2 @@
+[
+]
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_locators1.json b/tests/topotests/srv6_locator_custom_bits_length/expected_locators1.json
new file mode 100644 (file)
index 0000000..e89a56a
--- /dev/null
@@ -0,0 +1,34 @@
+{
+  "locators":[
+    {
+      "name": "loc1",
+      "prefix": "2001:db8:1::/64",
+      "blockBitsLength": 40,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:1::/64",
+          "proto": "system"
+        }
+      ]
+    },
+    {
+      "name": "loc2",
+      "prefix": "2001:db8:2::/48",
+      "blockBitsLength": 24,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:2::/48",
+          "proto": "system"
+        }
+      ]
+    }
+  ]
+}
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_locators2.json b/tests/topotests/srv6_locator_custom_bits_length/expected_locators2.json
new file mode 100644 (file)
index 0000000..f2ca09a
--- /dev/null
@@ -0,0 +1,34 @@
+{
+  "locators":[
+    {
+      "name": "loc1",
+      "prefix": "2001:db8:1::/64",
+      "blockBitsLength": 40,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:1::/64",
+          "proto": "sharp"
+        }
+      ]
+    },
+    {
+      "name": "loc2",
+      "prefix": "2001:db8:2::/48",
+      "blockBitsLength": 24,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:2::/48",
+          "proto": "system"
+        }
+      ]
+    }
+  ]
+}
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_locators3.json b/tests/topotests/srv6_locator_custom_bits_length/expected_locators3.json
new file mode 100644 (file)
index 0000000..e89a56a
--- /dev/null
@@ -0,0 +1,34 @@
+{
+  "locators":[
+    {
+      "name": "loc1",
+      "prefix": "2001:db8:1::/64",
+      "blockBitsLength": 40,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:1::/64",
+          "proto": "system"
+        }
+      ]
+    },
+    {
+      "name": "loc2",
+      "prefix": "2001:db8:2::/48",
+      "blockBitsLength": 24,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:2::/48",
+          "proto": "system"
+        }
+      ]
+    }
+  ]
+}
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_locators4.json b/tests/topotests/srv6_locator_custom_bits_length/expected_locators4.json
new file mode 100644 (file)
index 0000000..4c75d7f
--- /dev/null
@@ -0,0 +1,49 @@
+{
+  "locators":[
+    {
+      "name": "loc1",
+      "prefix": "2001:db8:1::/64",
+      "blockBitsLength": 40,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:1::/64",
+          "proto": "system"
+        }
+      ]
+    },
+    {
+      "name": "loc2",
+      "prefix": "2001:db8:2::/48",
+      "blockBitsLength": 24,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:2::/48",
+          "proto": "system"
+        }
+      ]
+    },
+    {
+      "name": "loc3",
+      "prefix": "2001:db8:3::/48",
+      "blockBitsLength": 32,
+      "nodeBitsLength": 16,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:3::/48",
+          "proto": "system"
+        }
+      ]
+    }
+  ]
+}
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_locators5.json b/tests/topotests/srv6_locator_custom_bits_length/expected_locators5.json
new file mode 100644 (file)
index 0000000..a01d313
--- /dev/null
@@ -0,0 +1,34 @@
+{
+  "locators":[
+    {
+      "name": "loc2",
+      "prefix": "2001:db8:2::/48",
+      "blockBitsLength": 24,
+      "nodeBitsLength": 24,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "statusUp": true,
+      "chunks": [
+        {
+          "prefix": "2001:db8:2::/48",
+          "proto": "system"
+        }
+      ]
+    },
+    {
+      "name": "loc3",
+      "prefix": "2001:db8:3::/48",
+      "statusUp": true,
+      "blockBitsLength": 32,
+      "nodeBitsLength": 16,
+      "functionBitsLength": 16,
+      "argumentBitsLength": 0,
+      "chunks":[
+        {
+          "prefix": "2001:db8:3::/48",
+          "proto": "system"
+        }
+      ]
+    }
+  ]
+}
diff --git a/tests/topotests/srv6_locator_custom_bits_length/expected_locators6.json b/tests/topotests/srv6_locator_custom_bits_length/expected_locators6.json
new file mode 100644 (file)
index 0000000..6e1b993
--- /dev/null
@@ -0,0 +1,4 @@
+{
+  "locators":[
+  ]
+}
diff --git a/tests/topotests/srv6_locator_custom_bits_length/r1/setup.sh b/tests/topotests/srv6_locator_custom_bits_length/r1/setup.sh
new file mode 100644 (file)
index 0000000..36ed713
--- /dev/null
@@ -0,0 +1,2 @@
+ip link add dummy0 type dummy
+ip link set dummy0 up
diff --git a/tests/topotests/srv6_locator_custom_bits_length/r1/sharpd.conf b/tests/topotests/srv6_locator_custom_bits_length/r1/sharpd.conf
new file mode 100644 (file)
index 0000000..d460859
--- /dev/null
@@ -0,0 +1,7 @@
+hostname r1
+!
+log stdout notifications
+log monitor notifications
+log commands
+log file sharpd.log debugging
+!
diff --git a/tests/topotests/srv6_locator_custom_bits_length/r1/zebra.conf b/tests/topotests/srv6_locator_custom_bits_length/r1/zebra.conf
new file mode 100644 (file)
index 0000000..30a520b
--- /dev/null
@@ -0,0 +1,22 @@
+hostname r1
+!
+! debug zebra events
+! debug zebra rib detailed
+!
+log stdout notifications
+log monitor notifications
+log commands
+log file zebra.log debugging
+!
+segment-routing
+ srv6
+  locators
+   locator loc1
+    prefix 2001:db8:1::/64
+   !
+   locator loc2
+    prefix 2001:db8:2::/48
+   !
+  !
+ !
+!
diff --git a/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator.py b/tests/topotests/srv6_locator_custom_bits_length/test_srv6_locator.py
new file mode 100755 (executable)
index 0000000..ecc0856
--- /dev/null
@@ -0,0 +1,160 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2022, University of Rome Tor Vergata
+# Authored by Carmine Scarpitta <carmine.scarpitta@uniroma2.it>
+#
+# 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_srv6_manager.py:
+Test for SRv6 manager on zebra
+"""
+
+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.topolog import logger
+
+pytestmark = [pytest.mark.bgpd, pytest.mark.sharpd]
+
+
+def open_json_file(filename):
+    try:
+        with open(filename, "r") as f:
+            return json.load(f)
+    except IOError:
+        assert False, "Could not read file {}".format(filename)
+
+
+def setup_module(mod):
+    tgen = Topogen({None: "r1"}, mod.__name__)
+    tgen.start_topology()
+    for rname, router in tgen.routers().items():
+        router.run("/bin/bash {}/{}/setup.sh".format(CWD, rname))
+        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))
+        )
+        router.load_config(
+            TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname))
+        )
+    tgen.start_router()
+
+
+def teardown_module(mod):
+    tgen = get_topogen()
+    tgen.stop_topology()
+
+
+def test_srv6():
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+    router = tgen.gears["r1"]
+
+    def _check_srv6_locator(router, expected_locator_file):
+        logger.info("checking zebra locator status")
+        output = json.loads(router.vtysh_cmd("show segment-routing srv6 locator json"))
+        expected = open_json_file("{}/{}".format(CWD, expected_locator_file))
+        return topotest.json_cmp(output, expected)
+
+    def _check_sharpd_chunk(router, expected_chunk_file):
+        logger.info("checking sharpd locator chunk status")
+        output = json.loads(router.vtysh_cmd("show sharp segment-routing srv6 json"))
+        expected = open_json_file("{}/{}".format(CWD, expected_chunk_file))
+        return topotest.json_cmp(output, expected)
+
+    def check_srv6_locator(router, expected_file):
+        func = functools.partial(_check_srv6_locator, router, expected_file)
+        success, result = topotest.run_and_expect(func, None, count=5, wait=0.5)
+        assert result is None, "Failed"
+
+    def check_sharpd_chunk(router, expected_file):
+        func = functools.partial(_check_sharpd_chunk, router, expected_file)
+        success, result = topotest.run_and_expect(func, None, count=5, wait=0.5)
+        assert result is None, "Failed"
+
+    # FOR DEVELOPER:
+    # If you want to stop some specific line and start interactive shell,
+    # please use tgen.mininet_cli() to start it.
+
+    logger.info("Test1 for Locator Configuration")
+    check_srv6_locator(router, "expected_locators1.json")
+    check_sharpd_chunk(router, "expected_chunks1.json")
+
+    logger.info("Test2 get chunk for locator loc1")
+    router.vtysh_cmd("sharp srv6-manager get-locator-chunk loc1")
+    check_srv6_locator(router, "expected_locators2.json")
+    check_sharpd_chunk(router, "expected_chunks2.json")
+
+    logger.info("Test3 release chunk for locator loc1")
+    router.vtysh_cmd("sharp srv6-manager release-locator-chunk loc1")
+    check_srv6_locator(router, "expected_locators3.json")
+    check_sharpd_chunk(router, "expected_chunks3.json")
+
+    logger.info("Test4 additional locator loc3")
+    router.vtysh_cmd(
+        """
+        configure terminal
+         segment-routing
+          srv6
+           locators
+            locator loc3
+             prefix 2001:db8:3::/48 func-bits 16 block-len 32 node-len 16
+        """
+    )
+    check_srv6_locator(router, "expected_locators4.json")
+    check_sharpd_chunk(router, "expected_chunks4.json")
+
+    logger.info("Test5 delete locator and chunk is released automatically")
+    router.vtysh_cmd(
+        """
+        configure terminal
+         segment-routing
+          srv6
+           locators
+            no locator loc1
+        """
+    )
+    check_srv6_locator(router, "expected_locators5.json")
+    check_sharpd_chunk(router, "expected_chunks5.json")
+
+    logger.info("Test6 delete srv6 all configuration")
+    router.vtysh_cmd(
+        """
+        configure terminal
+         segment-routing
+          no srv6
+        """
+    )
+    check_srv6_locator(router, "expected_locators6.json")
+    check_sharpd_chunk(router, "expected_chunks6.json")
+
+
+if __name__ == "__main__":
+    args = ["-s"] + sys.argv[1:]
+    sys.exit(pytest.main(args))