summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/templates/frr/bgpd.frr.tmpl9
-rw-r--r--interface-definitions/include/bgp/afi-export-import.xml.i13
-rwxr-xr-xsmoketest/scripts/cli/test_protocols_bgp.py25
-rwxr-xr-xsrc/conf_mode/protocols_bgp.py11
4 files changed, 53 insertions, 5 deletions
diff --git a/data/templates/frr/bgpd.frr.tmpl b/data/templates/frr/bgpd.frr.tmpl
index a21a2fefe..2f2e94ce0 100644
--- a/data/templates/frr/bgpd.frr.tmpl
+++ b/data/templates/frr/bgpd.frr.tmpl
@@ -311,8 +311,15 @@ router bgp {{ local_as }} {{ 'vrf ' ~ vrf if vrf is defined and vrf is not none
{% if afi_config.export is defined and afi_config.export.vpn is defined %}
export vpn
{% endif %}
-{% if afi_config.import is defined and afi_config.import.vpn is defined %}
+{% if afi_config.import is defined and afi_config.import is not none %}
+{% if afi_config.import.vpn is defined %}
import vpn
+{% endif %}
+{% if afi_config.import.vrf is defined and afi_config.import.vrf is not none %}
+{% for vrf in afi_config.import.vrf %}
+ import vrf {{ vrf }}
+{% endfor %}
+{% endif %}
{% endif %}
{% if afi_config.local_install is defined and afi_config.local_install is not none %}
{% for interface in afi_config.local_install.interface %}
diff --git a/interface-definitions/include/bgp/afi-export-import.xml.i b/interface-definitions/include/bgp/afi-export-import.xml.i
index ad54c723e..86817cdb3 100644
--- a/interface-definitions/include/bgp/afi-export-import.xml.i
+++ b/interface-definitions/include/bgp/afi-export-import.xml.i
@@ -23,6 +23,19 @@
<valueless/>
</properties>
</leafNode>
+ <leafNode name="vrf">
+ <properties>
+ <help>VRF to import from</help>
+ <valueHelp>
+ <format>txt</format>
+ <description>VRF instance name</description>
+ </valueHelp>
+ <completionHelp>
+ <path>vrf name</path>
+ </completionHelp>
+ <multi/>
+ </properties>
+ </leafNode>
</children>
</node>
<!-- include end -->
diff --git a/smoketest/scripts/cli/test_protocols_bgp.py b/smoketest/scripts/cli/test_protocols_bgp.py
index 22e892e26..7a470abf9 100755
--- a/smoketest/scripts/cli/test_protocols_bgp.py
+++ b/smoketest/scripts/cli/test_protocols_bgp.py
@@ -628,6 +628,9 @@ class TestProtocolsBGP(VyOSUnitTestSHIM.TestCase):
# templates and Jinja2 FRR template.
table = '1000'
+ self.cli_set(base_path + ['local-as', ASN])
+ # testing only one AFI is sufficient as it's generic code
+
for vrf in vrfs:
vrf_base = ['vrf', 'name', vrf]
self.cli_set(vrf_base + ['table', table])
@@ -636,15 +639,26 @@ class TestProtocolsBGP(VyOSUnitTestSHIM.TestCase):
self.cli_set(vrf_base + ['protocols', 'bgp', 'route-map', route_map_in])
table = str(int(table) + 1000)
+ # import VRF routes do main RIB
+ self.cli_set(base_path + ['address-family', 'ipv6-unicast', 'import', 'vrf', vrf])
+
self.cli_commit()
+ # Verify FRR bgpd configuration
+ frrconfig = self.getFRRconfig(f'router bgp {ASN}')
+ self.assertIn(f'router bgp {ASN}', frrconfig)
+ self.assertIn(f' address-family ipv6 unicast', frrconfig)
+
+
for vrf in vrfs:
+ self.assertIn(f' import vrf {vrf}', frrconfig)
+
# Verify FRR bgpd configuration
- frrconfig = self.getFRRconfig(f'router bgp {ASN} vrf {vrf}')
- self.assertIn(f'router bgp {ASN} vrf {vrf}', frrconfig)
- self.assertIn(f' bgp router-id {router_id}', frrconfig)
+ frr_vrf_config = self.getFRRconfig(f'router bgp {ASN} vrf {vrf}')
+ self.assertIn(f'router bgp {ASN} vrf {vrf}', frr_vrf_config)
+ self.assertIn(f' bgp router-id {router_id}', frr_vrf_config)
- # CCC: Currently this is not working as FRR() class does not support
+ # XXX: Currently this is not working as FRR() class does not support
# route-maps for multiple vrfs because the modify_section() only works
# on lines and not text blocks.
#
@@ -694,6 +708,7 @@ class TestProtocolsBGP(VyOSUnitTestSHIM.TestCase):
self.assertIn(f' neighbor {interface} activate', frrconfig)
self.assertIn(f' exit-address-family', frrconfig)
+
def test_bgp_13_solo(self):
remote_asn = str(int(ASN) + 150)
neighbor = '192.0.2.55'
@@ -710,9 +725,11 @@ class TestProtocolsBGP(VyOSUnitTestSHIM.TestCase):
self.assertIn(f'router bgp {ASN}', frrconfig)
self.assertIn(f' neighbor {neighbor} solo', frrconfig)
+
def test_bgp_14_vpn(self):
remote_asn = str(int(ASN) + 150)
neighbor = '192.0.2.55'
+ vrf_name = 'red'
self.cli_set(base_path + ['local-as', ASN])
# testing only one AFI is sufficient as it's generic code
diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py
index fb128db7b..7fc4a2247 100755
--- a/src/conf_mode/protocols_bgp.py
+++ b/src/conf_mode/protocols_bgp.py
@@ -23,6 +23,7 @@ from vyos.config import Config
from vyos.configdict import dict_merge
from vyos.configverify import verify_prefix_list
from vyos.configverify import verify_route_map
+from vyos.configverify import verify_vrf
from vyos.template import is_ip
from vyos.template import is_interface
from vyos.template import render_to_string
@@ -238,6 +239,16 @@ def verify(bgp):
raise ConfigError('Missing mandatory configuration option for '\
f'{afi} administrative distance {key}!')
+ if afi in ['ipv4_unicast', 'ipv6_unicast']:
+ if 'import' in afi_config and 'vrf' in afi_config['import']:
+ # Check if VRF exists
+ verify_vrf(afi_config['import']['vrf'])
+
+ # FRR error: please unconfigure vpn to vrf commands before
+ # using import vrf commands
+ if 'vpn' in afi_config['import'] or dict_search('export.vpn', afi_config) != None:
+ raise ConfigError('Please unconfigure VPN to VRF commands before '\
+ 'using "import vrf" commands!')
return None
def generate(bgp):