Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 96 additions & 2 deletions dockers/docker-fpm-frr/frr/bgpd/bgpd.main.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,111 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if (FEATURE is defined) and
(('frr_bmp' in FEATURE and 'state' in FEATURE['frr_bmp'] and FEATURE['frr_bmp']['state'] == 'enabled') or
('bmp' in FEATURE and 'state' in FEATURE['bmp'] and FEATURE['bmp']['state'] == 'enabled')) %}
{# Global mirror buffer limit #}
!
{% if BMP is defined and 'global' in BMP and 'mirror-buffer-limit' in BMP['global'] %}
bmp mirror buffer-limit {{ BMP['global']['mirror-buffer-limit'] }}
{% else %}
bmp mirror buffer-limit 4294967214
{% endif %}
!
{# Iterate over all BMP targets from BMP_TARGET table #}
{# First, check if any targets are configured #}
{% set has_targets = namespace(value=false) %}
{% if BMP_TARGET is defined and BMP_TARGET|length > 0 %}
{% set has_targets.value = true %}
{% endif %}
{# Backward compatibility: If no targets configured, create default sonic-bmp target #}
{% if not has_targets.value %}
bmp targets sonic-bmp
bmp stats interval 1000
bmp monitor ipv4 unicast pre-policy
bmp monitor ipv6 unicast pre-policy
bmp connect 127.0.0.1 port 5000 min-retry 10000 max-retry 15000
exit
!
!
{% endif %}
{% else %}
{# Process configured targets from BMP_TARGET table #}
{% set afi_safi_map = {
'ipv4_unicast': ('ipv4', 'unicast'),
'ipv6_unicast': ('ipv6', 'unicast'),
'ipv4_multicast': ('ipv4', 'multicast'),
'ipv6_multicast': ('ipv6', 'multicast'),
'l2vpn_evpn': ('l2vpn', 'evpn'),
'ipv4_vpn': ('ipv4', 'vpn'),
'ipv6_vpn': ('ipv6', 'vpn')
} %}
{% for target_key, target_value in BMP_TARGET.items() %}
{% set target_name = target_key if target_key is string else target_key[0] %}
bmp targets {{ target_name }}
{# Check if stats-interval is configured for this target #}
{% if target_value is mapping and 'stats-interval' in target_value %}
bmp stats interval {{ target_value['stats-interval'] }}
{% endif %}
{# Check if mirror is enabled for this target #}
{% if target_value is mapping and 'mirror' in target_value and target_value['mirror'] == 'true' %}
bmp mirror
{% endif %}
{# Collect all AFI/SAFI configs for this target from BMP_TARGET_AFI_SAFI table #}
{% if BMP_TARGET_AFI_SAFI is defined %}
{% for afi_safi_key, afi_safi_value in BMP_TARGET_AFI_SAFI.items() %}
{% set afi_safi_target = none %}
{% set afi_safi_name = none %}
{% if afi_safi_key is string %}
{% set parts = afi_safi_key.split('|') %}
{% if parts|length >= 2 %}
{% set afi_safi_target = parts[0] %}
{% set afi_safi_name = parts[1] %}
{% endif %}
{% elif afi_safi_key is iterable and afi_safi_key|length >= 2 %}
{% set afi_safi_target = afi_safi_key[0] %}
{% set afi_safi_name = afi_safi_key[1] %}
{% endif %}
{% if afi_safi_target == target_name and afi_safi_name is not none and afi_safi_name in afi_safi_map %}
{% set afi, safi = afi_safi_map[afi_safi_name] %}
{% if afi_safi_value.get('adj-rib-in-pre') == 'true' %}
bmp monitor {{ afi }} {{ safi }} pre-policy
{% endif %}
{% if afi_safi_value.get('adj-rib-in-post') == 'true' %}
bmp monitor {{ afi }} {{ safi }} post-policy
{% endif %}
{% if afi_safi_value.get('loc-rib') == 'true' %}
bmp monitor {{ afi }} {{ safi }} loc-rib
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{# Collect all collectors for this target from BMP_TARGET_COLLECTOR table #}
{% if BMP_TARGET_COLLECTOR is defined %}
{% for collector_key, collector_value in BMP_TARGET_COLLECTOR.items() %}
{% set collector_target = none %}
{% set collector_ip = none %}
{% set collector_port = none %}
{% if collector_key is string %}
{% set parts = collector_key.split('|') %}
{% if parts|length >= 3 %}
{% set collector_target = parts[0] %}
{% set collector_ip = parts[1] %}
{% set collector_port = parts[2] %}
{% endif %}
{% elif collector_key is iterable and collector_key|length >= 3 %}
{% set collector_target = collector_key[0] %}
{% set collector_ip = collector_key[1] %}
{% set collector_port = collector_key[2] %}
{% endif %}
{% if collector_target == target_name and collector_ip is not none and collector_port is not none %}
{% set min_retry = collector_value.get('min-retry', '30000') %}
{% set max_retry = collector_value.get('max-retry', '720000') %}
bmp connect {{ collector_ip }} port {{ collector_port }} min-retry {{ min_retry }} max-retry {{ max_retry }}
{% endif %}
{% endfor %}
{% endif %}
exit
!
{% endfor %}
{% endif %}{# end else (has_targets) #}
!
{% endif %}{# end if FEATURE bmp enabled #}
{# set router-id #}
{% if DEVICE_METADATA['localhost']['sub_role'] == 'BackEnd' or voq_chassis is defined or DEVICE_METADATA['localhost']['switch_type'] == 'chassis-packet' %}
{% if 'bgp_router_id' in DEVICE_METADATA['localhost'] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ router bgp 65100
bmp monitor ipv4 unicast pre-policy
bmp monitor ipv6 unicast pre-policy
bmp connect 127.0.0.1 port 5000 min-retry 10000 max-retry 15000
exit
!
!
bgp router-id 10.1.0.32
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
!
! template: bgpd/bgpd.conf.j2
!
!
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 with config DB data
! file: bgpd.conf
!
!
! template: common/daemons.common.conf.j2
!
hostname switch-t0
password zebra
enable password zebra
!
log syslog informational
log facility local4
!
! end of template: common/daemons.common.conf.j2!
agentx
!
!
!
! template: bgpd/bgpd.main.conf.j2
!
! bgp multiple-instance
!
! BGP configuration
!
! TSA configuration
!
ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.0.0/27
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 192.168.200.0/27
!
!
!
router bgp 65100
!
bgp log-neighbor-changes
bgp suppress-fib-pending
no bgp default ipv4-unicast
no bgp ebgp-requires-policy
!
bgp bestpath as-path multipath-relax
!
bgp graceful-restart restart-time 240
bgp graceful-restart
bgp graceful-restart preserve-fw-state
bgp graceful-restart select-defer-time 45
!
!
bmp mirror buffer-limit 1000000000
!
bmp targets production
bmp stats interval 2000
bmp monitor ipv4 unicast pre-policy
bmp connect 192.168.1.100 port 5000 min-retry 30000 max-retry 720000
exit
!
bmp targets troubleshooting
bmp stats interval 500
bmp mirror
bmp monitor ipv4 unicast pre-policy
bmp monitor ipv4 unicast post-policy
bmp monitor l2vpn evpn loc-rib
bmp connect 10.0.0.1 port 6000 min-retry 20000 max-retry 600000
exit
!
!
bgp router-id 10.1.0.32
!
network 10.1.0.32/32
!
address-family ipv6
network fc00:1::32/64
exit-address-family
!
network 192.168.0.1/27
network 192.168.200.1/27
!
!
!
address-family ipv4
maximum-paths 514
exit-address-family
address-family ipv6
maximum-paths 514
exit-address-family
!
! end of template: bgpd/bgpd.main.conf.j2
!!
! end of template: bgpd/bgpd.conf.j2
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
!
! template: bgpd/bgpd.conf.j2
!
!
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 with config DB data
! file: bgpd.conf
!
!
! template: common/daemons.common.conf.j2
!
hostname switch-t0
password zebra
enable password zebra
!
log syslog informational
log facility local4
!
! end of template: common/daemons.common.conf.j2!
agentx
!
!
!
! template: bgpd/bgpd.main.conf.j2
!
! bgp multiple-instance
!
! BGP configuration
!
! TSA configuration
!
ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 5 permit 192.168.0.0/27
!
ip prefix-list LOCAL_VLAN_IPV4_PREFIX seq 10 permit 192.168.200.0/27
!
!
!
router bgp 65100
!
bgp log-neighbor-changes
bgp suppress-fib-pending
no bgp default ipv4-unicast
no bgp ebgp-requires-policy
!
bgp bestpath as-path multipath-relax
!
bgp graceful-restart restart-time 240
bgp graceful-restart
bgp graceful-restart preserve-fw-state
bgp graceful-restart select-defer-time 45
!
!
bmp mirror buffer-limit 4294967214
!
bmp targets production
bmp stats interval 5000
bmp mirror
bmp monitor ipv4 unicast pre-policy
bmp monitor ipv6 unicast post-policy
bmp connect 192.168.1.100 port 5000 min-retry 30000 max-retry 720000
exit
!
!
bgp router-id 10.1.0.32
!
network 10.1.0.32/32
!
address-family ipv6
network fc00:1::32/64
exit-address-family
!
network 192.168.0.1/27
network 192.168.200.1/27
!
!
!
address-family ipv4
maximum-paths 514
exit-address-family
address-family ipv6
maximum-paths 514
exit-address-family
!
! end of template: bgpd/bgpd.main.conf.j2
!!
! end of template: bgpd/bgpd.conf.j2
!
40 changes: 39 additions & 1 deletion src/sonic-config-engine/tests/test_frr.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,42 @@ def test_zebra_frr_dualtor(self):

def test_bgpd_frr_bmp(self):
extra_data = {"FEATURE": {"frr_bmp": {"state": "enabled"}}}
self.assertTrue(*self.run_case('bgpd/bgpd.conf.j2', 'bgpd_frr_bmp.conf', extra_data=extra_data))
self.assertTrue(*self.run_case('bgpd/bgpd.conf.j2', 'bgpd_frr_bmp.conf', extra_data=extra_data))

def test_bgpd_frr_bmp_single_target(self):
extra_data = {
"FEATURE": {"frr_bmp": {"state": "enabled"}},
"BMP_TARGET": {
"production": {"mirror": "true", "stats-interval": "5000"}
},
"BMP_TARGET_COLLECTOR": {
"production|192.168.1.100|5000": {"min-retry": "30000", "max-retry": "720000"}
},
"BMP_TARGET_AFI_SAFI": {
"production|ipv4_unicast": {"adj-rib-in-pre": "true", "adj-rib-in-post": "false", "loc-rib": "false"},
"production|ipv6_unicast": {"adj-rib-in-pre": "false", "adj-rib-in-post": "true", "loc-rib": "false"}
}
}
self.assertTrue(*self.run_case('bgpd/bgpd.conf.j2', 'bgpd_frr_bmp_single_target.conf', extra_data=extra_data))

def test_bgpd_frr_bmp_multiple_targets(self):
extra_data = {
"FEATURE": {"frr_bmp": {"state": "enabled"}},
"BMP": {
"global": {"mirror-buffer-limit": "1000000000"}
},
"BMP_TARGET": {
"production": {"mirror": "false", "stats-interval": "2000"},
"troubleshooting": {"mirror": "true", "stats-interval": "500"}
},
"BMP_TARGET_COLLECTOR": {
"production|192.168.1.100|5000": {"min-retry": "30000", "max-retry": "720000"},
"troubleshooting|10.0.0.1|6000": {"min-retry": "20000", "max-retry": "600000"}
},
"BMP_TARGET_AFI_SAFI": {
"production|ipv4_unicast": {"adj-rib-in-pre": "true", "adj-rib-in-post": "false", "loc-rib": "false"},
"troubleshooting|ipv4_unicast": {"adj-rib-in-pre": "true", "adj-rib-in-post": "true", "loc-rib": "false"},
"troubleshooting|l2vpn_evpn": {"adj-rib-in-pre": "false", "adj-rib-in-post": "false", "loc-rib": "true"}
}
}
self.assertTrue(*self.run_case('bgpd/bgpd.conf.j2', 'bgpd_frr_bmp_multiple_targets.conf', extra_data=extra_data))
Loading
Loading