summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroki Shirokura <slank.dev@gmail.com>2020-12-18 22:11:19 +0900
committerMark Stapp <mjs@voltanet.io>2021-06-02 10:24:48 -0400
commitc5a044e0551fc607fdfe950ddefcc351d8a4f15d (patch)
treed565af7eb37a50e8d98847bfdd87912aa1139ea7
parentaf31f6c05c26192d4e2ea18845bef2617b919631 (diff)
topotests: for zapi's seg6 route configuration (step3)
This commit checks seg6 route configuration via ZAPI is working fine. Signed-off-by: Hiroki Shirokura <slank.dev@gmail.com>
-rw-r--r--tests/topotests/zebra_seg6_route/r1/routes.json25
-rw-r--r--tests/topotests/zebra_seg6_route/r1/setup.sh5
-rw-r--r--tests/topotests/zebra_seg6_route/r1/sharpd.conf0
-rw-r--r--tests/topotests/zebra_seg6_route/r1/zebra.conf13
-rwxr-xr-xtests/topotests/zebra_seg6_route/test_zebra_seg6_route.py109
5 files changed, 152 insertions, 0 deletions
diff --git a/tests/topotests/zebra_seg6_route/r1/routes.json b/tests/topotests/zebra_seg6_route/r1/routes.json
new file mode 100644
index 0000000000..a0c15b8fe4
--- /dev/null
+++ b/tests/topotests/zebra_seg6_route/r1/routes.json
@@ -0,0 +1,25 @@
+[
+ {
+ "in": {
+ "dest": "1::1",
+ "nh": "2001::1",
+ "sid": "a::"
+ },
+ "out":[{
+ "prefix":"1::1/128",
+ "protocol":"sharp",
+ "selected":true,
+ "destSelected":true,
+ "distance":150,
+ "metric":0,
+ "installed":true,
+ "table":254,
+ "nexthops":[{
+ "flags":3,
+ "fib":true,
+ "active":true,
+ "seg6": { "segs": "a::" }
+ }]
+ }]
+ }
+]
diff --git a/tests/topotests/zebra_seg6_route/r1/setup.sh b/tests/topotests/zebra_seg6_route/r1/setup.sh
new file mode 100644
index 0000000000..2cb5c4a4ec
--- /dev/null
+++ b/tests/topotests/zebra_seg6_route/r1/setup.sh
@@ -0,0 +1,5 @@
+ip link add vrf10 type vrf table 10
+ip link set vrf10 up
+ip link add dum0 type dummy
+ip link set dum0 up
+sysctl -w net.ipv6.conf.dum0.disable_ipv6=0
diff --git a/tests/topotests/zebra_seg6_route/r1/sharpd.conf b/tests/topotests/zebra_seg6_route/r1/sharpd.conf
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/topotests/zebra_seg6_route/r1/sharpd.conf
diff --git a/tests/topotests/zebra_seg6_route/r1/zebra.conf b/tests/topotests/zebra_seg6_route/r1/zebra.conf
new file mode 100644
index 0000000000..ad661e116b
--- /dev/null
+++ b/tests/topotests/zebra_seg6_route/r1/zebra.conf
@@ -0,0 +1,13 @@
+log file zebra.log
+!
+log stdout notifications
+log monitor notifications
+log commands
+!
+debug zebra packet
+debug zebra dplane
+debug zebra kernel msgdump
+!
+interface dum0
+ ipv6 address 2001::1/64
+!
diff --git a/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py b/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py
new file mode 100755
index 0000000000..e14d9690c1
--- /dev/null
+++ b/tests/topotests/zebra_seg6_route/test_zebra_seg6_route.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+
+#
+# test_zebra_seg6_route.py
+#
+# Copyright (c) 2020 by
+# LINE Corporation, Hiroki Shirokura <slank.dev@gmail.com>
+#
+# 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_seg6_route.py: Test seg6 route addition with zapi.
+"""
+
+import os
+import re
+import sys
+import pytest
+import json
+import platform
+from functools import partial
+
+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
+from lib.common_config import shutdown_bringup_interface
+from mininet.topo import Topo
+
+
+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)
+
+
+class TemplateTopo(Topo):
+ def build(self, **_opts):
+ tgen = get_topogen(self)
+ tgen.add_router("r1")
+
+
+def setup_module(mod):
+ tgen = Topogen(TemplateTopo, mod.__name__)
+ tgen.start_topology()
+ router_list = tgen.routers()
+ for rname, router in tgen.routers().items():
+ router.run("/bin/bash {}".format(os.path.join(CWD, "{}/setup.sh".format(rname))))
+ router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.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_zebra_seg6local_routes():
+ tgen = get_topogen()
+ if tgen.routers_have_failure():
+ pytest.skip(tgen.errors)
+ logger.info("Test for seg6local route install via ZAPI was start.")
+ r1 = tgen.gears["r1"]
+
+ def check(router, dest, nh, sid, expected):
+ router.vtysh_cmd("sharp install routes {} "\
+ "nexthop-seg6 {} encap {} 1".format(dest, nh, sid))
+ output = json.loads(router.vtysh_cmd("show ipv6 route {} json".format(dest)))
+ output = output.get('{}/128'.format(dest))
+ if output is None:
+ return False
+ return topotest.json_cmp(output, expected)
+
+ manifests = open_json_file(os.path.join(CWD, "{}/routes.json".format("r1")))
+ for manifest in manifests:
+ logger.info("CHECK {} {} {}".format(manifest['in']['dest'],
+ manifest['in']['nh'],
+ manifest['in']['sid']))
+ test_func = partial(check, r1,
+ manifest['in']['dest'],
+ manifest['in']['nh'],
+ manifest['in']['sid'],
+ manifest['out'])
+ success, result = topotest.run_and_expect(test_func, None, count=5, wait=1)
+ assert result is None, 'Failed'
+
+
+if __name__ == "__main__":
+ args = ["-s"] + sys.argv[1:]
+ sys.exit(pytest.main(args))