Skip to content

Commit

Permalink
Merge pull request #12261 from cscarpitta/srv6-encap-src-addr
Browse files Browse the repository at this point in the history
zebra: Add the support of the Source Addr param of the SRv6 Encapsulation
  • Loading branch information
riw777 authored Jan 2, 2024
2 parents de01b61 + 223d453 commit 54c2d32
Show file tree
Hide file tree
Showing 25 changed files with 979 additions and 7 deletions.
37 changes: 37 additions & 0 deletions doc/user/zebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,35 @@ FRR's cli or frr.conf or zebra.conf. This section shows how
to configure SRv6 on FRR. Of course SRv6 can be used as standalone,
and this section also helps that case.

.. clicmd:: show segment-routing srv6 manager [json]

This command dumps the SRv6 information configured on zebra, including
the encapsulation parameters (e.g., the IPv6 source address used for
the encapsulated packets).

Example::

router# sh segment-routing srv6 manager
Parameters:
Encapsulation:
Source Address:
Configured: fc00:0:1::1


To get the same information in json format, you can use the ``json`` keyword::

rose-srv6# sh segment-routing srv6 manager json
{
"parameters":{
"encapsulation":{
"sourceAddress":{
"configured":"fc00:0:1::1"
}
}
}
}


.. clicmd:: show segment-routing srv6 locator [json]

This command dump SRv6-locator configured on zebra. SRv6-locator is used
Expand Down Expand Up @@ -998,6 +1027,14 @@ and this section also helps that case.
!
...

.. clicmd:: encapsulation

Configure parameters for SRv6 encapsulation.

.. clicmd:: source-address X:X::X:X

Configure the source address of the outer encapsulating IPv6 header.

.. _multicast-rib-commands:

Multicast RIB Commands
Expand Down
1 change: 1 addition & 0 deletions lib/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ enum node_type {
SRV6_NODE, /* SRv6 node */
SRV6_LOCS_NODE, /* SRv6 locators node */
SRV6_LOC_NODE, /* SRv6 locator node */
SRV6_ENCAP_NODE, /* SRv6 encapsulation node */
VTY_NODE, /* Vty node. */
FPM_NODE, /* Dataplane FPM node. */
LINK_PARAMS_NODE, /* Link-parameters node */
Expand Down
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))
28 changes: 28 additions & 0 deletions vtysh/vtysh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,13 @@ static struct cmd_node srv6_loc_node = {
.prompt = "%s(config-srv6-locator)# ",
};

static struct cmd_node srv6_encap_node = {
.name = "srv6-encap",
.node = SRV6_ENCAP_NODE,
.parent_node = SRV6_NODE,
.prompt = "%s(config-srv6-encap)# "
};

#ifdef HAVE_PBRD
static struct cmd_node pbr_map_node = {
.name = "pbr-map",
Expand Down Expand Up @@ -1692,6 +1699,14 @@ DEFUNSH(VTYSH_ZEBRA, srv6_locator, srv6_locator_cmd,
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, srv6_encap, srv6_encap_cmd,
"encapsulation",
"Segment Routing SRv6 encapsulation\n")
{
vty->node = SRV6_ENCAP_NODE;
return CMD_SUCCESS;
}

#ifdef HAVE_BGPD
DEFUNSH(VTYSH_BGPD, router_bgp, router_bgp_cmd,
"router bgp [ASNUM [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
Expand Down Expand Up @@ -2507,6 +2522,14 @@ DEFUNSH(VTYSH_ZEBRA, exit_srv6_loc_config, exit_srv6_loc_config_cmd, "exit",
return CMD_SUCCESS;
}

DEFUNSH(VTYSH_ZEBRA, exit_srv6_encap, exit_srv6_encap_cmd, "exit",
"Exit from SRv6-encapsulation configuration mode\n")
{
if (vty->node == SRV6_ENCAP_NODE)
vty->node = SRV6_NODE;
return CMD_SUCCESS;
}

#ifdef HAVE_RIPD
DEFUNSH(VTYSH_RIPD, vtysh_exit_ripd, vtysh_exit_ripd_cmd, "exit",
"Exit current mode and down to previous mode\n")
Expand Down Expand Up @@ -5090,6 +5113,7 @@ void vtysh_init_vty(void)
install_element(SRV6_NODE, &srv6_locators_cmd);
install_element(SRV6_NODE, &exit_srv6_config_cmd);
install_element(SRV6_NODE, &vtysh_end_all_cmd);
install_element(SRV6_NODE, &srv6_encap_cmd);

install_node(&srv6_locs_node);
install_element(SRV6_LOCS_NODE, &srv6_locator_cmd);
Expand All @@ -5100,6 +5124,10 @@ void vtysh_init_vty(void)
install_element(SRV6_LOC_NODE, &exit_srv6_loc_config_cmd);
install_element(SRV6_LOC_NODE, &vtysh_end_all_cmd);

install_node(&srv6_encap_node);
install_element(SRV6_ENCAP_NODE, &exit_srv6_encap_cmd);
install_element(SRV6_ENCAP_NODE, &vtysh_end_all_cmd);

install_element(ENABLE_NODE, &vtysh_show_running_config_cmd);
install_element(ENABLE_NODE, &vtysh_copy_running_config_cmd);
install_element(ENABLE_NODE, &vtysh_copy_to_running_cmd);
Expand Down
1 change: 1 addition & 0 deletions zebra/dplane_fpm_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx)
case DPLANE_OP_TC_FILTER_ADD:
case DPLANE_OP_TC_FILTER_DELETE:
case DPLANE_OP_TC_FILTER_UPDATE:
case DPLANE_OP_SRV6_ENCAP_SRCADDR_SET:
case DPLANE_OP_NONE:
case DPLANE_OP_STARTUP_STAGE:
break;
Expand Down
Loading

0 comments on commit 54c2d32

Please sign in to comment.