Skip to content

Commit

Permalink
Add SRv6 test cases
Browse files Browse the repository at this point in the history
Signed-off-by: carmine <[email protected]>
  • Loading branch information
cscarpitta committed Nov 13, 2024
1 parent 1690f53 commit 8a496ac
Showing 1 changed file with 176 additions and 0 deletions.
176 changes: 176 additions & 0 deletions tests/srv6/test_srv6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
import pytest
import logging
from tests.common.helpers.assertions import pytest_assert as py_assert

pytestmark = [
pytest.mark.topology('t0'),
pytest.mark.device_type('vs')
]

Logger = logging.getLogger(__name__)

V6_PREFIX_NBR = "2001:db8::"
V6_MASK_NBR = "64"

V6_PREFIX_DUT = "2001:db8:1::"
V6_MASK_DUT = "64"


@pytest.fixture(name="setUp", scope="module")
def fixture_setUp(nbrhosts, duthosts, enum_frontend_dut_hostname):

# pick dut
duthost = duthosts[enum_frontend_dut_hostname]

# pick one neighbor
nbr = None
nbrnames = list(nbrhosts.keys())
for name in nbrnames:
if 'T1' in name:
nbr = nbrhosts[name]
break
py_assert(nbr is not None, "No T1 neighbors")

yield nbr, duthost

Logger.info("Performing cleanup")

# cleanup neighbor
cmd = "config interface vrf unbind Loopback1"
nbr['host'].shell(cmd)
cmd = "config loopback del Loopback1"
nbr['host'].shell(cmd)
cmd = "config vrf del Vrf10"
nbr['host'].shell(cmd)

# cleanup dut
duthost = duthosts[enum_frontend_dut_hostname]
cmd = "config interface vrf unbind Loopback1"
duthost.shell(cmd)
cmd = "config loopback del Loopback1"
duthost.shell(cmd)
cmd = "config vrf del Vrf10"
duthost.shell(cmd)


def run_srv6(enum_frontend_dut_hostname, nbr, duthost):
""" Route added on All neighbor should be learned by the DUT"""
Logger.info("Adding routes on neighbors")

# configure bgp on neighbor
cmd = "config vrf add Vrf10"
nbr['host'].shell(cmd)
cmd = "config loopback add Loopback1"
nbr['host'].shell(cmd)
cmd = "config interface vrf bind Loopback1 Vrf10"
nbr['host'].shell(cmd)
cmd = "config interface ip add Loopback1 2001:db8:2::1"
nbr['host'].shell(cmd)
cmd = ("vtysh"
" -c 'configure'"
" -c 'ipv6 route add {}/{} Loopback1'"
" -c 'segment-routing'"
" -c 'srv6'"
" -c 'locators'"
" -c 'locator MAIN'"
" -c 'prefix fcbb:bbbb:1::/48 block-len 32 node-len 16 func-bits 16'"
" -c 'exit'"
" -c 'exit'"
" -c 'exit'"
" -c 'exit'"
" -c 'router bgp 64600'"
" -c 'address-family ipv6 unicast'"
" -c 'network {}/{}'"
" -c 'exit'"
" -c 'segment-routing srv6'"
" -c 'locator MAIN'"
" -c 'exit'"
" -c 'router bgp 64600 vrf Vrf10'"
" -c 'address-family ipv6 unicast'"
" -c 'sid vpn export auto'"
" -c 'rd vpn export 1:10'"
" -c 'rt vpn both 99:99'"
" -c 'import vpn'"
" -c 'export vpn'"
" -c 'redistribute connected'"
" -c 'exit'"
" -c 'exit'").format(V6_PREFIX_NBR, V6_MASK_NBR, V6_PREFIX_NBR, V6_MASK_NBR)
nbr['host'].shell(cmd)
Logger.info("Route %s added to :%s", V6_PREFIX_NBR)

# configure bgp on dut
cmd = "config vrf add Vrf10"
duthost.shell(cmd)
cmd = "config loopback add Loopback1"
duthost.shell(cmd)
cmd = "config interface vrf bind Loopback1 Vrf10"
duthost.shell(cmd)
cmd = "config interface ip add Loopback1 2001:db8:2::1"
duthost.shell(cmd)
cmd = ("vtysh"
" -c 'configure'"
" -c 'ipv6 route add {}/{} Loopback1'"
" -c 'segment-routing'"
" -c 'srv6'"
" -c 'locators'"
" -c 'locator MAIN'"
" -c 'prefix fcbb:bbbb:2::/48 block-len 32 node-len 16 func-bits 16'"
" -c 'exit'"
" -c 'exit'"
" -c 'exit'"
" -c 'exit'"
" -c 'router bgp 64601'"
" -c 'address-family ipv6 unicast'"
" -c 'network {}/{}'"
" -c 'exit'"
" -c 'segment-routing srv6'"
" -c 'locator MAIN'"
" -c 'exit'"
" -c 'router bgp 64601 vrf Vrf10'"
" -c 'address-family ipv6 unicast'"
" -c 'sid vpn export auto'"
" -c 'rd vpn export 2:10'"
" -c 'rt vpn both 99:99'"
" -c 'import vpn'"
" -c 'export vpn'"
" -c 'redistribute connected'"
" -c 'exit'"
" -c 'exit'").format(V6_PREFIX_DUT, V6_MASK_DUT, V6_PREFIX_DUT, V6_MASK_DUT)
duthost.shell(cmd)
Logger.info("Route %s added to :duthost", V6_PREFIX_DUT)

# check ROUTE_TABLE
Logger.info("checking DUT for route %s", V6_PREFIX_NBR)
cmd = "redis-cli -n 0 hgetall \"ROUTE_TABLE:Vrf10:{}\"".format(V6_PREFIX_NBR)
result = duthost.shell(cmd)
result = result['stdout']
Logger.info("Route table nexthops are %s", result)
py_assert(result != "", "The DUT did not program the SRv6 steering route")
py_assert("segments: Vrf10:2001:db8::/64" not in result,
"The DUT did not program the SRv6 steering route correctly, missing 'segments' field")
py_assert("source: fc00:0:1::1" not in result,
"The DUT did not program the SRv6 steering route correctly, missing 'source' field")

# check SRV6_SID_LIST_TABLE
Logger.info("checking DUT for route %s", V6_PREFIX_NBR)
cmd = "redis-cli -n 0 hgetall \"SRV6_SID_LIST_TABLE:Vrf10:{}\"".format(V6_PREFIX_NBR)
result = duthost.shell(cmd)
result = result['stdout']
Logger.info("Route table nexthops are %s", result)
py_assert(result != "", "The DUT did not program the SRv6 SID list")
py_assert("path: fcbb:bbbb:1:1::" not in result,
"The DUT did not program the SRv6 SID list correctly, missing 'path' field")

# check SRV6_MY_SID_TABLE
Logger.info("checking DUT for route %s", V6_PREFIX_NBR)
cmd = "redis-cli -n 0 hgetall \"SRV6_MY_SID_TABLE:32:16:16:0:fcbb:bbbb:2:1::\""
result = duthost.shell(cmd)
result = result['stdout']
Logger.info("Route table nexthops are %s", result)
py_assert(result != "", "The DUT did not program SRv6 MySid entry")
py_assert("action: udt6" not in result, "The DUT did not program SRv6 MySid entry, missing 'action' field")
py_assert("vrf: Vrf10" not in result, "The DUT did not program SRv6 MySid entry correcly, missing 'vrf' field")


def test_srv6(duthosts, enum_frontend_dut_hostname, setUp):
run_srv6(duthosts, enum_frontend_dut_hostname, setUp)

0 comments on commit 8a496ac

Please sign in to comment.