Skip to content

Commit

Permalink
tests: Add topotests for SRv6 encap source address
Browse files Browse the repository at this point in the history
Add a new topotest `srv6_encap_src_addr` which verifies that the
`source-address` command works properly.

Signed-off-by: Carmine Scarpitta <[email protected]>
  • Loading branch information
cscarpitta committed Dec 1, 2023
1 parent 550c47c commit ec7e9ef
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parameters": {
"encapsulation":{
"sourceAddress": {
"configured": "fc00:0:1::1"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parameters": {
"encapsulation":{
"sourceAddress": {
"configured": "fc00:0:1::1"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parameters": {
"encapsulation":{
"sourceAddress": {
"configured": "::"
}
}
}
}
2 changes: 2 additions & 0 deletions tests/topotests/srv6_encap_src_addr/r1/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ip link add dummy0 type dummy
ip link set dummy0 up
17 changes: 17 additions & 0 deletions tests/topotests/srv6_encap_src_addr/r1/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
encapsulation
source-address fc00:0:1::1
!
!
!
142 changes: 142 additions & 0 deletions tests/topotests/srv6_encap_src_addr/test_srv6_encap_src_addr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/usr/bin/env python
# SPDX-License-Identifier: ISC

#
# test_srv6_encap_src_addr.py
# Part of NetDEF Topology Tests
#
# Copyright (c) 2022 by
# University of Rome Tor Vergata, Carmine Scarpitta <[email protected]>
#

"""
test_srv6_encap_src_addr.py:
Test for SRv6 encap source address 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_zebra_srv6_encap_src_addr(tgen):
"Test SRv6 encapsulation source address."
logger.info(
"Test SRv6 encapsulation source address."
)
r1 = tgen.gears["r1"]

# Generate expected results
json_file = "{}/r1/expected_srv6_encap_src_addr.json".format(CWD)
expected = json.loads(open(json_file).read())

ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected)
assert ok, '"r1" JSON output mismatches'

output = r1.cmd("ip sr tunsrc show")
assert output == "tunsrc addr fc00:0:1::1\n"


def test_zebra_srv6_encap_src_addr_unset(tgen):
"Test SRv6 encapsulation source address unset."
logger.info(
"Test SRv6 encapsulation source address unset."
)
r1 = tgen.gears["r1"]

# Unset SRv6 encapsulation source address
r1.vtysh_cmd(
"""
configure terminal
segment-routing
srv6
encapsulation
no source-address
"""
)

# Generate expected results
json_file = "{}/r1/expected_srv6_encap_src_addr_unset.json".format(CWD)
expected = json.loads(open(json_file).read())

ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected)
assert ok, '"r1" JSON output mismatches'

output = r1.cmd("ip sr tunsrc show")
assert output == "tunsrc addr ::\n"


def test_zebra_srv6_encap_src_addr_set(tgen):
"Test SRv6 encapsulation source address set."
logger.info(
"Test SRv6 encapsulation source address set."
)
r1 = tgen.gears["r1"]

# Set SRv6 encapsulation source address
r1.vtysh_cmd(
"""
configure terminal
segment-routing
srv6
encapsulation
source-address fc00:0:1::1
"""
)

# Generate expected results
json_file = "{}/r1/expected_srv6_encap_src_addr_set.json".format(CWD)
expected = json.loads(open(json_file).read())

ok = topotest.router_json_cmp_retry(r1, "show segment-routing srv6 manager json", expected)
assert ok, '"r1" JSON output mismatches'

output = r1.cmd("ip sr tunsrc show")
assert output == "tunsrc addr fc00:0:1::1\n"


if __name__ == "__main__":
args = ["-s"] + sys.argv[1:]
sys.exit(pytest.main(args))

0 comments on commit ec7e9ef

Please sign in to comment.