From ed58684e3694e322b51f8948ec62d76a1c1920af Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sun, 27 Dec 2020 01:54:34 -0800 Subject: [PATCH] [docker-frr]: add static ipv6 loopback route to allow bgp to advertise prefix frr does not advertise route if local route is not reachable, as a result loopback route /64 is not advertised to the neighbors. Add static route allows frr to advertise the route to its peers Signed-off-by: Guohan Lu --- dockers/docker-fpm-frr/frr/frr.conf.j2 | 2 ++ dockers/docker-fpm-frr/frr/staticd/staticd.conf.j2 | 2 ++ .../frr/staticd/staticd.loopback_route.conf.j2 | 10 ++++++++++ .../tests/data/sonic-cfggen/frr.conf.j2/all.conf | 5 +++++ .../tests/data/sonic-cfggen/staticd/staticd.conf | 4 ++++ .../tests/data/sonic-cfggen/staticd/staticd.conf.json | 3 +++ .../sonic-cfggen/staticd/staticd.loopback_route.conf | 4 ++++ .../staticd/staticd.loopback_route.conf.json | 5 +++++ src/sonic-bgpcfgd/tests/test_sonic-cfggen.py | 6 ++++++ .../tests/sample_output/py2/frr.conf | 5 +++++ .../tests/sample_output/py2/staticd_frr.conf | 5 +++++ .../tests/sample_output/py3/frr.conf | 5 +++++ .../tests/sample_output/py3/staticd_frr.conf | 5 +++++ src/sonic-config-engine/tests/test_frr.py | 8 ++++++-- 14 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 dockers/docker-fpm-frr/frr/staticd/staticd.loopback_route.conf.j2 create mode 100644 src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.loopback_route.conf create mode 100644 src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.loopback_route.conf.json diff --git a/dockers/docker-fpm-frr/frr/frr.conf.j2 b/dockers/docker-fpm-frr/frr/frr.conf.j2 index 9e5def4ba0..9990079036 100644 --- a/dockers/docker-fpm-frr/frr/frr.conf.j2 +++ b/dockers/docker-fpm-frr/frr/frr.conf.j2 @@ -15,5 +15,7 @@ agentx ! {% include "staticd/staticd.default_route.conf.j2" %} ! +{% include "staticd/staticd.loopback_route.conf.j2" %} +! {% include "bgpd/bgpd.main.conf.j2" %} ! diff --git a/dockers/docker-fpm-frr/frr/staticd/staticd.conf.j2 b/dockers/docker-fpm-frr/frr/staticd/staticd.conf.j2 index 932871dfce..4831325276 100644 --- a/dockers/docker-fpm-frr/frr/staticd/staticd.conf.j2 +++ b/dockers/docker-fpm-frr/frr/staticd/staticd.conf.j2 @@ -10,3 +10,5 @@ ! {% include "staticd.default_route.conf.j2" %} ! +{% include "staticd.loopback_route.conf.j2" %} +! diff --git a/dockers/docker-fpm-frr/frr/staticd/staticd.loopback_route.conf.j2 b/dockers/docker-fpm-frr/frr/staticd/staticd.loopback_route.conf.j2 new file mode 100644 index 0000000000..95c2a901e4 --- /dev/null +++ b/dockers/docker-fpm-frr/frr/staticd/staticd.loopback_route.conf.j2 @@ -0,0 +1,10 @@ +! +{% from "common/functions.conf.j2" import get_ipv4_loopback_address, get_ipv6_loopback_address, get_vnet_interfaces %} +! +{% block loopback_route %} +! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix +{% if get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") != 'None' %} +ipv6 route {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | replace('/128', '/64') | ip_network }}/64 Loopback0 +{% endif %} +{% endblock loopback_route %} +! diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf index da63c01adc..8effc1a9f8 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/frr.conf.j2/all.conf @@ -36,6 +36,11 @@ link-detect ip route 0.0.0.0/0 10.10.10.1 200 !! ! +! +! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix +ipv6 route fc00::/64 Loopback0 +! +!! ! template: bgpd/bgpd.main.conf.j2 ! ! bgp multiple-instance diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.conf index 522c0d36f2..59bbe983af 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.conf +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.conf @@ -17,3 +17,7 @@ log facility local4 ! set static default route to mgmt gateway as a backup to learned default ip route 0.0.0.0/0 10.10.10.1 200 !! +! +! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix +ipv6 route fc00:1::/64 Loopback0 +!! diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.conf.json b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.conf.json index 37f660d101..0cbd67c7ef 100644 --- a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.conf.json +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.conf.json @@ -8,5 +8,8 @@ "eth0|10.10.10.10/24": { "gwaddr": "10.10.10.1" } + }, + "LOOPBACK_INTERFACE": { + "Loopback0|FC00:1::32/128": {} } } diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.loopback_route.conf b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.loopback_route.conf new file mode 100644 index 0000000000..27078305d4 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.loopback_route.conf @@ -0,0 +1,4 @@ +! +! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix +ipv6 route fc00:1::/64 Loopback0 +!! diff --git a/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.loopback_route.conf.json b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.loopback_route.conf.json new file mode 100644 index 0000000000..ffd3c2a2a1 --- /dev/null +++ b/src/sonic-bgpcfgd/tests/data/sonic-cfggen/staticd/staticd.loopback_route.conf.json @@ -0,0 +1,5 @@ +{ + "LOOPBACK_INTERFACE": { + "Loopback0|FC00:1::32/128": {} + } +} diff --git a/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py b/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py index f49f0a0a42..a9c93749d5 100644 --- a/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py +++ b/src/sonic-bgpcfgd/tests/test_sonic-cfggen.py @@ -75,6 +75,12 @@ def test_staticd_default_route(): "staticd/staticd.default_route.conf.json", "staticd/staticd.default_route.conf") +def test_staticd_loopback_route(): + run_test("staticd.loopback_route.conf.j2", + "staticd/staticd.loopback_route.conf.j2", + "staticd/staticd.loopback_route.conf.json", + "staticd/staticd.loopback_route.conf") + def test_staticd(): run_test("staticd.conf.j2", "staticd/staticd.conf.j2", diff --git a/src/sonic-config-engine/tests/sample_output/py2/frr.conf b/src/sonic-config-engine/tests/sample_output/py2/frr.conf index f0264e4b30..0b72a5aee9 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/frr.conf +++ b/src/sonic-config-engine/tests/sample_output/py2/frr.conf @@ -39,6 +39,11 @@ link-detect ip route 0.0.0.0/0 10.0.0.1 200 !! ! +! +! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix +ipv6 route fc00:1::/64 Loopback0 +!! +! ! template: bgpd/bgpd.main.conf.j2 ! ! bgp multiple-instance diff --git a/src/sonic-config-engine/tests/sample_output/py2/staticd_frr.conf b/src/sonic-config-engine/tests/sample_output/py2/staticd_frr.conf index 31a11d8578..54d83525b1 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/staticd_frr.conf +++ b/src/sonic-config-engine/tests/sample_output/py2/staticd_frr.conf @@ -18,3 +18,8 @@ log facility local4 ! set static default route to mgmt gateway as a backup to learned default ip route 0.0.0.0/0 10.0.0.1 200 !! +! +! +! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix +ipv6 route fc00:1::/64 Loopback0 +!! diff --git a/src/sonic-config-engine/tests/sample_output/py3/frr.conf b/src/sonic-config-engine/tests/sample_output/py3/frr.conf index 5f80b6071a..045b7fb96a 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/frr.conf +++ b/src/sonic-config-engine/tests/sample_output/py3/frr.conf @@ -39,6 +39,11 @@ link-detect ip route 0.0.0.0/0 10.0.0.1 200 !! ! +! +! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix +ipv6 route fc00:1::/64 Loopback0 +!! +! ! template: bgpd/bgpd.main.conf.j2 ! ! bgp multiple-instance diff --git a/src/sonic-config-engine/tests/sample_output/py3/staticd_frr.conf b/src/sonic-config-engine/tests/sample_output/py3/staticd_frr.conf index 31a11d8578..54d83525b1 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/staticd_frr.conf +++ b/src/sonic-config-engine/tests/sample_output/py3/staticd_frr.conf @@ -18,3 +18,8 @@ log facility local4 ! set static default route to mgmt gateway as a backup to learned default ip route 0.0.0.0/0 10.0.0.1 200 !! +! +! +! add static ipv6 /64 loopback route to allow bgpd to advertise the loopback route prefix +ipv6 route fc00:1::/64 Loopback0 +!! diff --git a/src/sonic-config-engine/tests/test_frr.py b/src/sonic-config-engine/tests/test_frr.py index 386ce42e02..4998db2d5b 100644 --- a/src/sonic-config-engine/tests/test_frr.py +++ b/src/sonic-config-engine/tests/test_frr.py @@ -39,7 +39,12 @@ class TestCfgGen(TestCase): return output def run_diff(self, file1, file2): - return subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True) + output = subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True) + + if utils.PY3x: + output = output.decode() + + return output def run_case(self, template, target): template_dir = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-frr', "frr") @@ -55,7 +60,6 @@ class TestCfgGen(TestCase): return r, "Diff:\n" + diff_output - def test_config_frr(self): self.assertTrue(*self.run_case('frr.conf.j2', 'frr.conf'))