[bgpcfgd]: Split one bgp mega-template to chunks. (#4143)

The one big bgp configuration template was splitted into chunks.

Currently we have three types of bgp neighbor peers:

general bgp peers. They are represented by CONFIG_DB::BGP_NEIGHBOR table entries
dynamic bgp peers. They are represented by CONFIG_DB::BGP_PEER_RANGE table entries
monitors bgp peers. They are represented by CONFIG_DB::BGP_MONITORS table entries
This PR introduces three templates for each peer type:

bgp policies: represent policieas that will be applied to the bgp peer-group (ip prefix-lists, route-maps, etc)
bgp peer-group: represent bgp peer group which has common configuration for the bgp peer type and uses bgp routing policy from the previous item
bgp peer-group instance: represent bgp configuration, which will be used to instatiate a bgp peer-group for the bgp peer-type. Usually this one is simple, consist of the referral to the bgp peer-group, bgp peer description and bgp peer ip address.
This PR redefined constant.yml file. Now this file has a setting for to use or don't use bgp_neighbor metadata. This file has more parameters for now, which are not used. They will be used in the next iteration of bgpcfgd.

Currently all tests have been disabled. I'm going to create next PR with the tests right after this PR is merged.

I'm going to introduce better bgpcfgd in a short time. It will include support of dynamic changes for the templates.

FIX:: #4231
This commit is contained in:
pavel-shirshov 2020-04-23 09:42:22 -07:00 committed by GitHub
parent 9129378097
commit 057ced0391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 1477 additions and 864 deletions

View File

@ -39,8 +39,8 @@ RUN apt-get clean -y && \
apt-get autoremove -y && \ apt-get autoremove -y && \
rm -rf /debs ~/.cache rm -rf /debs ~/.cache
COPY ["frr", "/usr/share/sonic/templates"]
COPY ["bgpcfgd", "start.sh", "/usr/bin/"] COPY ["bgpcfgd", "start.sh", "/usr/bin/"]
COPY ["*.j2", "/usr/share/sonic/templates/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["snmp.conf", "/etc/snmp/frr.conf"] COPY ["snmp.conf", "/etc/snmp/frr.conf"]
COPY ["TSA", "/usr/bin/TSA"] COPY ["TSA", "/usr/bin/TSA"]

View File

@ -1,22 +1,38 @@
#!/bin/bash #!/bin/bash
function check_not_installed()
{
c=0 c=0
config=$(vtysh -c "show run") config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2" for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
echo "$config" | grep -q "route-map $route_map_name permit 2"
c=$((c+$?)) c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3" echo "$config" | grep -q "route-map $route_map_name deny 3"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$((c+$?)) c=$((c+$?))
done
return $c
}
if [[ $c -eq 4 ]]; check_not_installed
not_installed=$?
if [[ $not_installed -ne 0 ]];
then then
TSA_FILE=$(mktemp) TSA_FILE=$(mktemp)
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE" for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
case "$route_map_name" in
*V4*)
ip_version=V4
;;
*V6*)
ip_version=V6
;;
esac
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\", \"ip_version\": \"$ip_version\"}" -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE"
vtysh -f "$TSA_FILE" vtysh -f "$TSA_FILE"
rm -f "$TSA_FILE" rm -f "$TSA_FILE"
done
echo "System Mode: Normal -> Maintenance" echo "System Mode: Normal -> Maintenance"
else else
echo "System is already in Maintenance mode" echo "System is already in Maintenance mode"

View File

@ -1,22 +1,33 @@
#!/bin/bash #!/bin/bash
function check_installed()
{
c=0 c=0
e=0
config=$(vtysh -c "show run") config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2" for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
echo "$config" | grep -q "route-map $route_map_name permit 2"
c=$((c+$?)) c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3" e=$((e+1))
c=$((c+$?)) echo "$config" | grep -q "route-map $route_map_name deny 3"
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$((c+$?)) c=$((c+$?))
e=$((e+1))
done
return $((e-c))
}
if [[ $c -eq 0 ]]; check_installed
installed=$?
if [[ $installed -ne 0 ]];
then then
TSB_FILE=$(mktemp) TSB_FILE=$(mktemp)
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE" for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\"}" -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE"
vtysh -f "$TSB_FILE" vtysh -f "$TSB_FILE"
rm -f "$TSB_FILE" rm -f "$TSB_FILE"
done
echo "System Mode: Maintenance -> Normal" echo "System Mode: Maintenance -> Normal"
else else
echo "System is already in Normal mode" echo "System is already in Normal mode"

View File

@ -1,21 +1,48 @@
#!/bin/bash #!/bin/bash
echo "Traffic Shift Check:" function check_not_installed()
{
c=0 c=0
config=$(vtysh -c "show run") config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2" for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
echo "$config" | grep -q "route-map $route_map_name permit 2"
c=$((c+$?)) c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3" echo "$config" | grep -q "route-map $route_map_name deny 3"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$((c+$?)) c=$((c+$?))
done
return $c
}
if [[ $c -eq 4 ]]; function check_installed()
{
c=0
e=0
config=$(vtysh -c "show run")
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
echo "$config" | grep -q "route-map $route_map_name permit 2"
c=$((c+$?))
e=$((e+1))
echo "$config" | grep -q "route-map $route_map_name deny 3"
c=$((c+$?))
e=$((e+1))
done
return $((e-c))
}
echo "Traffic Shift Check:"
check_not_installed
not_installed=$?
check_installed
installed=$?
if [[ $installed -eq 0 ]];
then then
echo "System Mode: Normal" echo "System Mode: Normal"
elif [[ $c -eq 0 ]]; elif [[ $not_installed -eq 0 ]];
then then
echo "System Mode: Maintenance" echo "System Mode: Maintenance"
else else

File diff suppressed because it is too large Load Diff

View File

@ -1,180 +0,0 @@
!
{% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %}
{% block bgp_init %}
!
! bgp multiple-instance
!
route-map FROM_BGP_SPEAKER_V4 permit 10
!
route-map TO_BGP_SPEAKER_V4 deny 10
!
{# generate loopback prefix-lists #}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
ip prefix-list PL_LoopbackV4 permit {{ prefix | ip }}/32
{% elif prefix | ipv6 and name == 'Loopback0' %}
ipv6 prefix-list PL_LoopbackV6 permit {{ prefix | replace('/128', '/64') | ip_network }}/64
{% endif %}
{% endfor %}
!
{# generate default peer route-maps #}
!
route-map TO_BGP_PEER_V4 permit 100
!
route-map TO_BGP_PEER_V6 permit 100
!
{% if DEVICE_METADATA['localhost']['type'] == 'InternalFrontend' %}
route-map HIDE_INTERNAL permit 10
set community local-AS
!
{% endif %}
{% if DEVICE_METADATA['localhost']['type'] == 'InternalBackend' %}
route-map OVERRIDE_ORIGINATOR_ID permit 10
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
set originator-id {{ prefix | ip }}
{% endif %}
{% endfor %}
!
{% endif %}
{% if BGP_MONITORS is defined and BGP_MONITORS|length > 0 %}
route-map FROM_BGPMON deny 10
!
route-map TO_BGPMON permit 10
!
{% endif %}
!
route-map ISOLATE permit 10
set as-path prepend {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
!
route-map set-next-hop-global-v6 permit 10
set ipv6 next-hop prefer-global
!
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if DEVICE_METADATA['localhost']['type'] == 'InternalFrontend' %}
redistribute connected route-map HIDE_INTERNAL
{% endif %}
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
no bgp default ipv4-unicast
bgp graceful-restart restart-time 240
bgp graceful-restart
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
bgp graceful-restart preserve-fw-state
{% endif %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
bgp router-id {{ prefix | ip }}
{% endif %}
{% endfor %}
{# advertise loopback #}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
network {{ prefix | ip }}/32
{% elif prefix | ipv6 and name == 'Loopback0' %}
address-family ipv6
network {{ prefix | ip }}/64
exit-address-family
{% endif %}
{% endfor %}
{% endblock bgp_init %}
{% endif %}
{% block vlan_advertisement %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
network {{ prefix }}
{% elif prefix | ipv6 %}
address-family ipv6
network {{ prefix }}
exit-address-family
{% endif %}
{% endfor %}
{% endblock vlan_advertisement %}
{% block maximum_paths %}
address-family ipv4
maximum-paths 64
exit-address-family
address-family ipv6
maximum-paths 64
exit-address-family
{% endblock maximum_paths %}
{% block peers_peer_group %}
neighbor PEER_V4 peer-group
neighbor PEER_V6 peer-group
address-family ipv4
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor PEER_V4 allowas-in 1
{% endif %}
neighbor PEER_V4 soft-reconfiguration inbound
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out
exit-address-family
address-family ipv6
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor PEER_V6 allowas-in 1
{% endif %}
neighbor PEER_V6 soft-reconfiguration inbound
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out
exit-address-family
{% endblock peers_peer_group %}
{% block bgp_peers_with_range %}
{% if BGP_PEER_RANGE %}
{% for bgp_peer in BGP_PEER_RANGE.values() %}
neighbor {{ bgp_peer['name'] }} peer-group
neighbor {{ bgp_peer['name'] }} passive
{% if bgp_peer['peer_asn'] is defined %}
neighbor {{ bgp_peer['name'] }} remote-as {{ bgp_peer['peer_asn'] }}
{% else %}
neighbor {{ bgp_peer['name'] }} remote-as {{ constants.deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']] }}
{% endif %}
neighbor {{ bgp_peer['name'] }} ebgp-multihop 255
neighbor {{ bgp_peer['name'] }} soft-reconfiguration inbound
{% if bgp_peer['src_address'] is defined %}
neighbor {{ bgp_peer['name'] }} update-source {{ bgp_peer['src_address'] | ip }}
{% else %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback1' %}
neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }}
{% endif %}
{% endfor %}
{% endif %}
neighbor {{ bgp_peer['name'] }} route-map FROM_BGP_SPEAKER_V4 in
neighbor {{ bgp_peer['name'] }} route-map TO_BGP_SPEAKER_V4 out
{% for ip_range in bgp_peer['ip_range'] %}
bgp listen range {{ip_range}} peer-group {{ bgp_peer['name'] }}
{% endfor %}
address-family ipv4
neighbor {{ bgp_peer['name'] }} activate
exit-address-family
address-family ipv6
neighbor {{ bgp_peer['name'] }} activate
exit-address-family
{% endfor %}
{% endif %}
{% endblock bgp_peers_with_range %}
{% block bgp_monitors %}
{% if BGP_MONITORS is defined and BGP_MONITORS|length > 0 %}
neighbor BGPMON peer-group
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
neighbor BGPMON update-source {{ prefix | ip }}
{% endif %}
{% endfor %}
neighbor BGPMON route-map FROM_BGPMON in
neighbor BGPMON route-map TO_BGPMON out
neighbor BGPMON send-community
neighbor BGPMON maximum-prefix 1
{% for neighbor_addr, bgp_session in BGP_MONITORS.items() %}
neighbor {{ neighbor_addr }} remote-as {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
neighbor {{ neighbor_addr }} peer-group BGPMON
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
neighbor {{ neighbor_addr }} activate
{% if DEVICE_METADATA['localhost']['type'] == 'InternalBackend' %}
neighbor {{ neighbor_addr }} route-map OVERRIDE_ORIGINATOR_ID in
{% endif %}
address-family ipv6
neighbor {{ neighbor_addr }} activate
exit-address-family
{% endfor %}
{% endif %}
{% endblock bgp_monitors %}
!

View File

@ -1,10 +0,0 @@
route-map TO_BGP_PEER_V4 permit 2
match ip address prefix-list PL_LoopbackV4
set community {{ constants.traffic_shift_community }}
route-map TO_BGP_PEER_V4 deny 3
!
route-map TO_BGP_PEER_V6 permit 2
match ipv6 address prefix-list PL_LoopbackV6
set community {{ constants.traffic_shift_community }}
route-map TO_BGP_PEER_V6 deny 3
!

View File

@ -1,6 +0,0 @@
no route-map TO_BGP_PEER_V4 permit 2
no route-map TO_BGP_PEER_V4 deny 3
!
no route-map TO_BGP_PEER_V6 permit 2
no route-map TO_BGP_PEER_V6 deny 3
!

View File

@ -1,18 +0,0 @@
!
{% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/frr/frr.conf.j2 with config DB data
! file: frr.conf
!
{% endblock banner %}
!
{% include "daemons.common.conf.j2" %}
!
agentx
!
{% include "zebra.interfaces.conf.j2" %}
!
{% include "staticd.default_route.conf.j2" %}
!
{% include "bgpd.conf.default.j2" %}
!

View File

@ -1,4 +1,8 @@
! !
! template: bgpd/bgpd.conf.j2
!
{% from "common/functions.conf.j2" import get_ipv4_loopback_address, get_ipv6_loopback_address %}
!
{% block banner %} {% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 with config DB data ! generated by templates/quagga/bgpd.conf.j2 with config DB data
@ -6,13 +10,15 @@
! !
{% endblock banner %} {% endblock banner %}
! !
{% include "daemons.common.conf.j2" %} {% include "common/daemons.common.conf.j2" %}
! !
agentx agentx
! !
{% if DEVICE_METADATA['localhost']['type'] == "SpineChassisFrontendRouter" %} {% if DEVICE_METADATA['localhost']['type'] == "SpineChassisFrontendRouter" %}
{% include "bgpd.conf.spine_chassis_frontend_router.j2" %} {% include "bgpd.spine_chassis_frontend_router.conf.j2" %}
{% endif %} {% endif %}
! !
{% include "bgpd.conf.default.j2" %} {% include "bgpd.main.conf.j2" %}
!
! end of template: bgpd/bgpd.conf.j2
! !

View File

@ -0,0 +1,81 @@
!
! template: bgpd/bgpd.main.conf.j2
!
! bgp multiple-instance
!
! BGP configuration
!
! TSA configuration
!
ip prefix-list PL_LoopbackV4 permit {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/32
!
{% if get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") != 'None' %}
ipv6 prefix-list PL_LoopbackV6 permit {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | replace('/128', '/64') | ip_network }}/64
{% endif %}
!
!
{% if DEVICE_METADATA['localhost']['type'] == 'InternalFrontend' %}
route-map HIDE_INTERNAL permit 10
set community local-AS
!
{% endif %}
!
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
!
{% block bgp_init %}
bgp log-neighbor-changes
no bgp default ipv4-unicast
!
{% if constants.bgp.multipath_relax.enabled is defined and constants.bgp.multipath_relax.enabled %}
bgp bestpath as-path multipath-relax
{% endif %}
!
{% if constants.bgp.graceful_restart.enabled is defined and constants.bgp.graceful_restart.enabled %}
bgp graceful-restart restart-time {{ constants.bgp.graceful_restart.restart_time | default(240) }}
bgp graceful-restart
bgp graceful-restart preserve-fw-state
{% endif %}
!
{# set router-id #}
bgp router-id {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}
!
{# advertise loopback #}
network {{ get_ipv4_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/32
!
{% if get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") != 'None' %}
address-family ipv6
network {{ get_ipv6_loopback_address(LOOPBACK_INTERFACE, "Loopback0") | ip }}/64
exit-address-family
{% endif %}
{% endblock bgp_init %}
!
{% block vlan_advertisement %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
network {{ prefix }}
{% elif prefix | ipv6 %}
address-family ipv6
network {{ prefix }}
exit-address-family
{% endif %}
{% endfor %}
{% endblock vlan_advertisement %}
!
!
{% if DEVICE_METADATA['localhost']['type'] == 'InternalFrontend' %}
redistribute connected route-map HIDE_INTERNAL
{% endif %}
!
{% if constants.bgp.maximum_paths.enabled is defined and constants.bgp.maximum_paths.enabled %}
{% block maximum_paths %}
address-family ipv4
maximum-paths {{ constants.bgp.maximum_paths.ipv4 | default(64) }}
exit-address-family
address-family ipv6
maximum-paths {{ constants.bgp.maximum_paths.ipv6 | default(64) }}
exit-address-family
{% endblock maximum_paths %}
{% endif %}
!
! end of template: bgpd/bgpd.main.conf.j2
!

View File

@ -0,0 +1,38 @@
!
! template: bgpd/templates/dynamic/instance.conf.j2
!
{% from "common/functions.conf.j2" import get_ipv4_loopback_address %}
!
neighbor {{ bgp_session['name'] }} peer-group
neighbor {{ bgp_session['name'] }} passive
neighbor {{ bgp_session['name'] }} ebgp-multihop 255
neighbor {{ bgp_session['name'] }} soft-reconfiguration inbound
neighbor {{ bgp_session['name'] }} route-map FROM_BGP_SPEAKER in
neighbor {{ bgp_session['name'] }} route-map TO_BGP_SPEAKER out
!
{% if bgp_session['peer_asn'] is defined %}
neighbor {{ bgp_session['name'] }} remote-as {{ bgp_session['peer_asn'] }}
{% else %}
neighbor {{ bgp_session['name'] }} remote-as {{ constants.deployment_id_asn_map[CONFIG_DB__DEVICE_METADATA['localhost']['deployment_id']] }}
{% endif %}
!
{# FIXME: bgp_session['ip_range'] check the type #}
{% for ip_range in bgp_session['ip_range'].split(',') %}
bgp listen range {{ ip_range }} peer-group {{ bgp_session['name'] }}
{% endfor %}
!
{% if bgp_session['src_address'] is defined %}
neighbor {{ bgp_session['name'] }} update-source {{ bgp_session['src_address'] | ip }}
{% else %}
neighbor {{ bgp_session['name'] }} update-source {{ get_ipv4_loopback_address(CONFIG_DB__LOOPBACK_INTERFACE, "Loopback1") | ip }}
{% endif %}
!
address-family ipv4
neighbor {{ bgp_session['name'] }} activate
exit-address-family
address-family ipv6
neighbor {{ bgp_session['name'] }} activate
exit-address-family
!
! end of template: bgpd/templates/BGP_SPEAKER/instance.conf.j2
!

View File

@ -0,0 +1,7 @@
!
! template: bgpd/templates/BGP_SPEAKER/peer-group.conf.j2
!
! nothing is here
!
! end of template: bgpd/templates/BGP_SPEAKER/peer-group.conf.j2
!

View File

@ -0,0 +1,9 @@
!
! template: bgpd/templates/BGP_SPEAKER/policies.conf.j2
!
route-map FROM_BGP_SPEAKER permit 10
!
route-map TO_BGP_SPEAKER deny 1
!
! end of template: bgpd/templates/BGP_SPEAKER/policies.conf.j2
!

View File

@ -1,4 +1,6 @@
{% block bgp_peer %} !
! template: bgpd/templates/general/instance.conf.j2
!
neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }} neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }}
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }} neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
{# set the bgp neighbor timers if they have not default values #} {# set the bgp neighbor timers if they have not default values #}
@ -6,27 +8,34 @@
or (bgp_session['holdtime'] is defined and bgp_session['holdtime'] | int != 180) %} or (bgp_session['holdtime'] is defined and bgp_session['holdtime'] | int != 180) %}
neighbor {{ neighbor_addr }} timers {{ bgp_session['keepalive'] }} {{ bgp_session['holdtime'] }} neighbor {{ neighbor_addr }} timers {{ bgp_session['keepalive'] }} {{ bgp_session['holdtime'] }}
{% endif %} {% endif %}
{% if bgp_session.has_key('admin_status') and bgp_session['admin_status'] == 'down' or not bgp_session.has_key('admin_status') and DEVICE_METADATA['localhost'].has_key('default_bgp_status') and DEVICE_METADATA['localhost']['default_bgp_status'] == 'down' %} !
{% if bgp_session.has_key('admin_status') and bgp_session['admin_status'] == 'down' or not bgp_session.has_key('admin_status') and CONFIG_DB__DEVICE_METADATA['localhost'].has_key('default_bgp_status') and CONFIG_DB__DEVICE_METADATA['localhost']['default_bgp_status'] == 'down' %}
neighbor {{ neighbor_addr }} shutdown neighbor {{ neighbor_addr }} shutdown
{% endif %} {% endif %}
!
{% if neighbor_addr | ipv4 %} {% if neighbor_addr | ipv4 %}
address-family ipv4 address-family ipv4
neighbor {{ neighbor_addr }} peer-group PEER_V4 neighbor {{ neighbor_addr }} peer-group PEER_V4
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'InternalBackend' %}
neighbor {{ neighbor_addr }} route-map FROM_BGP_PEER_V4_INT in
{% endif %}
{% elif neighbor_addr | ipv6 %} {% elif neighbor_addr | ipv6 %}
address-family ipv6 address-family ipv6
{% if bgp_session['asn'] != DEVICE_METADATA['localhost']['bgp_asn'] %}
neighbor {{ neighbor_addr }} route-map set-next-hop-global-v6 in
{% endif %}
neighbor {{ neighbor_addr }} peer-group PEER_V6 neighbor {{ neighbor_addr }} peer-group PEER_V6
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'InternalBackend' %}
neighbor {{ neighbor_addr }} route-map FROM_BGP_PEER_V6_INT in
{% endif %} {% endif %}
{% endif %}
!
{% if bgp_session['rrclient'] | int != 0 %} {% if bgp_session['rrclient'] | int != 0 %}
neighbor {{ neighbor_addr }} route-reflector-client neighbor {{ neighbor_addr }} route-reflector-client
{% endif %} {% endif %}
!
{% if bgp_session['nhopself'] | int != 0 %} {% if bgp_session['nhopself'] | int != 0 %}
neighbor {{ neighbor_addr }} next-hop-self neighbor {{ neighbor_addr }} next-hop-self
{% endif %} {% endif %}
{% if bgp_session["asn"] == DEVICE_METADATA['localhost']['bgp_asn'] !
and DEVICE_METADATA['localhost']['type'] == "SpineChassisFrontendRouter" %} {% if bgp_session["asn"] == bgp_asn and CONFIG_DB__DEVICE_METADATA['localhost']['type'] == "SpineChassisFrontendRouter" %}
address-family l2vpn evpn address-family l2vpn evpn
neighbor {{ neighbor_addr }} activate neighbor {{ neighbor_addr }} activate
advertise-all-vni advertise-all-vni
@ -34,4 +43,6 @@
{% endif %} {% endif %}
neighbor {{ neighbor_addr }} activate neighbor {{ neighbor_addr }} activate
exit-address-family exit-address-family
{% endblock bgp_peer %} !
! end of template: bgpd/templates/general/instance.conf.j2
!

View File

@ -0,0 +1,24 @@
!
! template: bgpd/templates/general/peer-group.conf.j2
!
neighbor PEER_V4 peer-group
neighbor PEER_V6 peer-group
address-family ipv4
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor PEER_V4 allowas-in 1
{% endif %}
neighbor PEER_V4 soft-reconfiguration inbound
neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out
exit-address-family
address-family ipv6
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor PEER_V6 allowas-in 1
{% endif %}
neighbor PEER_V6 soft-reconfiguration inbound
neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out
exit-address-family
!
! end of template: bgpd/templates/general/peer-group.conf.j2
!

View File

@ -0,0 +1,30 @@
!
! template: bgpd/templates/general/policies.conf.j2
!
!
!
route-map FROM_BGP_PEER_V4 permit 100
!
route-map TO_BGP_PEER_V4 permit 100
!
!
route-map FROM_BGP_PEER_V6 permit 1
set ipv6 next-hop prefer-global
!
route-map FROM_BGP_PEER_V6 permit 100
!
route-map TO_BGP_PEER_V6 permit 100
!
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'InternalBackend' %}
route-map FROM_BGP_PEER_V4_INT permit 2
set originator-id {{ loopback0_ipv4 | ip }}
!
route-map FROM_BGP_PEER_V6_INT permit 1
set ipv6 next-hop prefer-global
!
route-map FROM_BGP_PEER_V6_INT permit 2
set originator-id {{ loopback0_ipv4 | ip }}
{% endif %}
!
! end of template: bgpd/templates/general/policies.conf.j2
!

View File

@ -0,0 +1,13 @@
!
! template: bgpd/templates/monitors/instance.conf.j2
!
neighbor {{ neighbor_addr }} remote-as {{ bgp_asn }}
neighbor {{ neighbor_addr }} peer-group BGPMON
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
neighbor {{ neighbor_addr }} activate
address-family ipv6
neighbor {{ neighbor_addr }} activate
exit-address-family
!
! end of template: bgpd/templates/BGPMON/instance.conf.j2
!

View File

@ -0,0 +1,12 @@
!
! template: bgpd/templates/BGPMON/peer-group.conf.j2
!
neighbor BGPMON peer-group
neighbor BGPMON update-source {{ loopback0_ipv4 | ip }}
neighbor BGPMON route-map FROM_BGPMON in
neighbor BGPMON route-map TO_BGPMON out
neighbor BGPMON send-community
neighbor BGPMON maximum-prefix 1
!
! end of template: bgpd/templates/BGPMON/peer-group.conf.j2
!

View File

@ -0,0 +1,9 @@
!
! template: bgpd/templates/BGPMON/policies.conf.j2
!
route-map FROM_BGPMON deny 10
!
route-map TO_BGPMON permit 10
!
! end of template: bgpd/templates/BGPMON/policies.conf.j2
!

View File

@ -0,0 +1,5 @@
route-map {{ route_map_name }} permit 2
match ip address prefix-list PL_Loopback{{ ip_version }}
set community {{ constants.bgp.traffic_shift_community }}
route-map {{ route_map_name }} deny 3
!

View File

@ -0,0 +1,3 @@
no route-map {{ route_map_name }} permit 2
no route-map {{ route_map_name }} deny 3
!

View File

@ -1,3 +1,4 @@
! template: common/daemons.common.conf.j2
! !
{% block sys_init %} {% block sys_init %}
hostname {{ DEVICE_METADATA['localhost']['hostname'] }} hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
@ -10,3 +11,4 @@ log syslog informational
log facility local4 log facility local4
{% endblock logging %} {% endblock logging %}
! !
! end of template: common/daemons.common.conf.j2

View File

@ -0,0 +1,23 @@
{% macro get_ipv4_loopback_address(interfaces, loopbackname) -%}
{% set L = namespace(ip=None) %}
{% for name, prefix in interfaces|pfx_filter %}
{% if name == loopbackname %}
{% if prefix | ipv4 %}
{% set L.ip = prefix %}
{% endif %}
{% endif %}
{% endfor %}
{{ L.ip }}
{%- endmacro %}
{% macro get_ipv6_loopback_address(interfaces, loopbackname) -%}
{% set L = namespace(ip=None) %}
{% for name, prefix in interfaces|pfx_filter %}
{% if name == loopbackname %}
{% if prefix | ipv6 %}
{% set L.ip = prefix %}
{% endif %}
{% endif %}
{% endfor %}
{{ L.ip }}
{%- endmacro %}

View File

@ -0,0 +1,19 @@
!
{% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/frr.conf.j2 with config DB data
! file: frr.conf
!
{% endblock banner %}
!
{% include "common/daemons.common.conf.j2" %}
{% from "common/functions.conf.j2" import get_ipv4_loopback_address, get_ipv6_loopback_address %}
!
agentx
!
{% include "zebra/zebra.interfaces.conf.j2" %}
!
{% include "staticd/staticd.default_route.conf.j2" %}
!
{% include "bgpd/bgpd.main.conf.j2" %}
!

View File

@ -6,7 +6,7 @@
! !
{% endblock banner %} {% endblock banner %}
! !
{% include "daemons.common.conf.j2" %} {% include "common/daemons.common.conf.j2" %}
! !
{% include "staticd.default_route.conf.j2" %} {% include "staticd.default_route.conf.j2" %}
! !

View File

@ -1,12 +1,12 @@
! !
{% block banner %} {% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/zebra.conf.j2 using config DB data ! generated by templates/zebra/zebra.conf.j2 using config DB data
! file: zebra.conf ! file: zebra.conf
! !
{% endblock banner %} {% endblock banner %}
! !
{% include "daemons.common.conf.j2" %} {% include "common/daemons.common.conf.j2" %}
! !
{% include "zebra.interfaces.conf.j2" %} {% include "zebra.interfaces.conf.j2" %}
! !

View File

@ -0,0 +1,25 @@
!
{% block vrf %}
{% if VNET is defined %}
{% for vnet_name, vnet_metadata in VNET.iteritems() %}
vrf {{ vnet_name }}
vni {{ vnet_metadata['vni'] }}
!
{% endfor %}
{% endif %}
{% endblock vrf %}
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for (name, prefix) in INTERFACE|pfx_filter %}
interface {{ name }}
link-detect
!
{% endfor %}
{% for pc in PORTCHANNEL %}
interface {{ pc }}
link-detect
!
{% endfor %}
{% endblock interfaces %}
!

View File

@ -0,0 +1,8 @@
!
! Set ip source to loopback for bgp learned routes
!
route-map {{ rm_name }} permit 10
set src {{ lo_ip }}
!
ip{{ ip_proto }} protocol bgp route-map {{ rm_name }}
!

View File

@ -5,9 +5,9 @@ mkdir -p /etc/frr
CONFIG_TYPE=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["docker_routing_config_mode"]'` CONFIG_TYPE=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["docker_routing_config_mode"]'`
if [ -z "$CONFIG_TYPE" ] || [ "$CONFIG_TYPE" == "separated" ]; then if [ -z "$CONFIG_TYPE" ] || [ "$CONFIG_TYPE" == "separated" ]; then
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.conf.j2 > /etc/frr/bgpd.conf sonic-cfggen -d -t /usr/share/sonic/templates/bgpd/bgpd.conf.j2 -y /etc/sonic/constants.yml > /etc/frr/bgpd.conf
sonic-cfggen -d -t /usr/share/sonic/templates/zebra.conf.j2 > /etc/frr/zebra.conf sonic-cfggen -d -t /usr/share/sonic/templates/zebra/zebra.conf.j2 > /etc/frr/zebra.conf
sonic-cfggen -d -t /usr/share/sonic/templates/staticd.conf.j2 > /etc/frr/staticd.conf sonic-cfggen -d -t /usr/share/sonic/templates/staticd/staticd.conf.j2 > /etc/frr/staticd.conf
echo "no service integrated-vtysh-config" > /etc/frr/vtysh.conf echo "no service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/frr.conf rm -f /etc/frr/frr.conf
elif [ "$CONFIG_TYPE" == "unified" ]; then elif [ "$CONFIG_TYPE" == "unified" ]; then

View File

@ -1,60 +0,0 @@
!
{% block vrf %}
{% if VNET is defined %}
{% for vnet_name, vnet_metadata in VNET.iteritems() %}
vrf {{ vnet_name }}
vni {{ vnet_metadata['vni'] }}
!
{% endfor %}
{% endif %}
{% endblock vrf %}
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for (name, prefix) in INTERFACE|pfx_filter %}
interface {{ name }}
link-detect
!
{% endfor %}
{% for pc in PORTCHANNEL %}
interface {{ pc }}
link-detect
!
{% endfor %}
{% endblock interfaces %}
!
{% block source_loopback %}
{% set lo_ipv4_addrs = [] %}
{% set lo_ipv6_addrs = [] %}
{% if LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback0' %}
{% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(prefix) %}
{% endif %}
{% else %}
{% if lo_ipv4_addrs.append(prefix) %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
! Set ip source to loopback for bgp learned routes
{% if lo_ipv4_addrs|length > 0 -%}
route-map RM_SET_SRC permit 10
set src {{ lo_ipv4_addrs[0] | ip }}
!
{% endif %}
{% if lo_ipv6_addrs|length > 0 %}
route-map RM_SET_SRC6 permit 10
set src {{ lo_ipv6_addrs[0] | ip }}
!
{% endif %}
ip protocol bgp route-map RM_SET_SRC
!
{% if lo_ipv6_addrs|length > 0 %}
ipv6 protocol bgp route-map RM_SET_SRC6
!
{% endif %}
{% endblock source_loopback %}
!

View File

@ -1,4 +1,34 @@
constants: constants:
deployment_id_asn_map: deployment_id_asn_map:
"1" : 65432 "1" : 65432
"2" : 65433
bgp:
traffic_shift_community: 12345:12345 traffic_shift_community: 12345:12345
families:
- ipv4
- ipv6
use_deployment_id: false
use_neighbors_meta: false
graceful_restart:
enabled: true
restart_time: 240
multipath_relax:
enabled: true
maximum_paths:
enabled: true
ipv4: 64
ipv6: 64
peers:
general: # peer_type
db_table: "BGP_NEIGHBOR"
template_dir: "general"
monitors: # peer_type
enabled: true
db_table: "BGP_MONITORS"
peer_group: "BGPMON"
template_dir: "monitors"
dynamic: # peer_type
enabled: true
db_table: "BGP_PEER_RANGE"
peer_group: "BGP_SPEAKER"
template_dir: "dynamic"

2
src/sonic-config-engine/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
dist/
tests/output

View File

@ -204,6 +204,7 @@ def main():
parser.add_argument("-s", "--redis-unix-sock-file", help="unix sock file for redis connection") parser.add_argument("-s", "--redis-unix-sock-file", help="unix sock file for redis connection")
group = parser.add_mutually_exclusive_group() group = parser.add_mutually_exclusive_group()
group.add_argument("-t", "--template", help="render the data with the template file") group.add_argument("-t", "--template", help="render the data with the template file")
parser.add_argument("-T", "--template_dir", help="search base for the template files", action='store')
group.add_argument("-v", "--var", help="print the value of a variable, support jinja2 expression") group.add_argument("-v", "--var", help="print the value of a variable, support jinja2 expression")
group.add_argument("--var-json", help="print the value of a variable, in json format") group.add_argument("--var-json", help="print the value of a variable, in json format")
group.add_argument("-w", "--write-to-db", help="write config into configdb", action='store_true') group.add_argument("-w", "--write-to-db", help="write config into configdb", action='store_true')
@ -273,9 +274,12 @@ def main():
}}} }}}
deep_update(data, hardware_data) deep_update(data, hardware_data)
if args.template != None: if args.template is not None:
template_file = os.path.abspath(args.template) template_file = os.path.abspath(args.template)
paths = ['/', '/usr/share/sonic/templates', os.path.dirname(template_file)] paths = ['/', '/usr/share/sonic/templates', os.path.dirname(template_file)]
if args.template_dir is not None:
template_dir = os.path.abspath(args.template_dir)
paths.append(template_dir)
loader = jinja2.FileSystemLoader(paths) loader = jinja2.FileSystemLoader(paths)
redis_bcc = RedisBytecodeCache(SonicV2Connector(host='127.0.0.1')) redis_bcc = RedisBytecodeCache(SonicV2Connector(host='127.0.0.1'))

View File

@ -1,9 +1,13 @@
! !
! template: bgpd/bgpd.conf.j2
!
!
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 with config DB data ! generated by templates/quagga/bgpd.conf.j2 with config DB data
! file: bgpd.conf ! file: bgpd.conf
! !
! !
! template: common/daemons.common.conf.j2
! !
hostname switch-t0 hostname switch-t0
password zebra password zebra
@ -11,79 +15,57 @@ enable password zebra
! !
log syslog informational log syslog informational
log facility local4 log facility local4
!! !
! end of template: common/daemons.common.conf.j2!
agentx agentx
! !
! !
! !
! template: bgpd/bgpd.main.conf.j2
! !
! bgp multiple-instance ! bgp multiple-instance
! !
route-map FROM_BGP_SPEAKER_V4 permit 10 ! BGP configuration
! !
route-map TO_BGP_SPEAKER_V4 deny 10 ! TSA configuration
! !
ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32 ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64 ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
! !
! !
route-map TO_BGP_PEER_V4 permit 100
!
route-map TO_BGP_PEER_V6 permit 100
!
route-map FROM_BGPMON deny 10
!
route-map TO_BGPMON permit 10
!
!
route-map ISOLATE permit 10
set as-path prepend 65100
!
route-map set-next-hop-global-v6 permit 10
set ipv6 next-hop prefer-global
! !
router bgp 65100 router bgp 65100
!
bgp log-neighbor-changes bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
no bgp default ipv4-unicast no bgp default ipv4-unicast
!
bgp bestpath as-path multipath-relax
!
bgp graceful-restart restart-time 240 bgp graceful-restart restart-time 240
bgp graceful-restart bgp graceful-restart
bgp graceful-restart preserve-fw-state bgp graceful-restart preserve-fw-state
!
bgp router-id 10.1.0.32 bgp router-id 10.1.0.32
!
network 10.1.0.32/32 network 10.1.0.32/32
!
address-family ipv6 address-family ipv6
network fc00:1::32/64 network fc00:1::32/64
exit-address-family exit-address-family
!
network 192.168.0.1/27 network 192.168.0.1/27
!
!
!
address-family ipv4 address-family ipv4
maximum-paths 64 maximum-paths 64
exit-address-family exit-address-family
address-family ipv6 address-family ipv6
maximum-paths 64 maximum-paths 64
exit-address-family exit-address-family
neighbor PEER_V4 peer-group !
neighbor PEER_V6 peer-group ! end of template: bgpd/bgpd.main.conf.j2
address-family ipv4
neighbor PEER_V4 allowas-in 1
neighbor PEER_V4 soft-reconfiguration inbound
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out
exit-address-family
address-family ipv6
neighbor PEER_V6 allowas-in 1
neighbor PEER_V6 soft-reconfiguration inbound
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out
exit-address-family
neighbor BGPMON peer-group
neighbor BGPMON update-source 10.1.0.32
neighbor BGPMON route-map FROM_BGPMON in
neighbor BGPMON route-map TO_BGPMON out
neighbor BGPMON send-community
neighbor BGPMON maximum-prefix 1
neighbor 10.20.30.40 remote-as 65100
neighbor 10.20.30.40 peer-group BGPMON
neighbor 10.20.30.40 description BGPMonitor
neighbor 10.20.30.40 activate
address-family ipv6
neighbor 10.20.30.40 activate
exit-address-family
!! !!
! end of template: bgpd/bgpd.conf.j2
!

View File

@ -1,9 +1,10 @@
! !
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/frr/frr.conf.j2 with config DB data ! generated by templates/frr.conf.j2 with config DB data
! file: frr.conf ! file: frr.conf
! !
! !
! template: common/daemons.common.conf.j2
! !
hostname switch-t0 hostname switch-t0
password zebra password zebra
@ -11,7 +12,8 @@ enable password zebra
! !
log syslog informational log syslog informational
log facility local4 log facility local4
!! !
! end of template: common/daemons.common.conf.j2!
agentx agentx
! !
! !
@ -29,93 +31,55 @@ link-detect
interface PortChannel04 interface PortChannel04
link-detect link-detect
! !
!
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src 10.1.0.32
!
route-map RM_SET_SRC6 permit 10
set src fc00:1::32
!
ip protocol bgp route-map RM_SET_SRC
!
ipv6 protocol bgp route-map RM_SET_SRC6
!
!! !!
! !
! set static default route to mgmt gateway as a backup to learned default ! 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 ip route 0.0.0.0/0 10.0.0.1 200
!! !!
! !
! template: bgpd/bgpd.main.conf.j2
! !
! bgp multiple-instance ! bgp multiple-instance
! !
route-map FROM_BGP_SPEAKER_V4 permit 10 ! BGP configuration
! !
route-map TO_BGP_SPEAKER_V4 deny 10 ! TSA configuration
! !
ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32 ip prefix-list PL_LoopbackV4 permit 10.1.0.32/32
!
ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64 ipv6 prefix-list PL_LoopbackV6 permit fc00:1::/64
! !
! !
route-map TO_BGP_PEER_V4 permit 100
!
route-map TO_BGP_PEER_V6 permit 100
!
route-map FROM_BGPMON deny 10
!
route-map TO_BGPMON permit 10
!
!
route-map ISOLATE permit 10
set as-path prepend 65100
!
route-map set-next-hop-global-v6 permit 10
set ipv6 next-hop prefer-global
! !
router bgp 65100 router bgp 65100
!
bgp log-neighbor-changes bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
no bgp default ipv4-unicast no bgp default ipv4-unicast
!
bgp bestpath as-path multipath-relax
!
bgp graceful-restart restart-time 240 bgp graceful-restart restart-time 240
bgp graceful-restart bgp graceful-restart
bgp graceful-restart preserve-fw-state bgp graceful-restart preserve-fw-state
!
bgp router-id 10.1.0.32 bgp router-id 10.1.0.32
!
network 10.1.0.32/32 network 10.1.0.32/32
!
address-family ipv6 address-family ipv6
network fc00:1::32/64 network fc00:1::32/64
exit-address-family exit-address-family
!
network 192.168.0.1/27 network 192.168.0.1/27
!
!
!
address-family ipv4 address-family ipv4
maximum-paths 64 maximum-paths 64
exit-address-family exit-address-family
address-family ipv6 address-family ipv6
maximum-paths 64 maximum-paths 64
exit-address-family exit-address-family
neighbor PEER_V4 peer-group !
neighbor PEER_V6 peer-group ! end of template: bgpd/bgpd.main.conf.j2
address-family ipv4
neighbor PEER_V4 allowas-in 1
neighbor PEER_V4 soft-reconfiguration inbound
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out
exit-address-family
address-family ipv6
neighbor PEER_V6 allowas-in 1
neighbor PEER_V6 soft-reconfiguration inbound
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out
exit-address-family
neighbor BGPMON peer-group
neighbor BGPMON update-source 10.1.0.32
neighbor BGPMON route-map FROM_BGPMON in
neighbor BGPMON route-map TO_BGPMON out
neighbor BGPMON send-community
neighbor BGPMON maximum-prefix 1
neighbor 10.20.30.40 remote-as 65100
neighbor 10.20.30.40 peer-group BGPMON
neighbor 10.20.30.40 description BGPMonitor
neighbor 10.20.30.40 activate
address-family ipv6
neighbor 10.20.30.40 activate
exit-address-family
!! !!

View File

@ -4,6 +4,7 @@
! file: staticd.conf ! file: staticd.conf
! !
! !
! template: common/daemons.common.conf.j2
! !
hostname switch-t0 hostname switch-t0
password zebra password zebra
@ -11,7 +12,8 @@ enable password zebra
! !
log syslog informational log syslog informational
log facility local4 log facility local4
!! !
! end of template: common/daemons.common.conf.j2!
! !
! set static default route to mgmt gateway as a backup to learned default ! 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 ip route 0.0.0.0/0 10.0.0.1 200

View File

@ -1,9 +1,13 @@
! !
! template: bgpd/bgpd.conf.j2
!
!
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 with config DB data ! generated by templates/quagga/bgpd.conf.j2 with config DB data
! file: bgpd.conf ! file: bgpd.conf
! !
! !
! template: common/daemons.common.conf.j2
! !
hostname SpineFront01 hostname SpineFront01
password zebra password zebra
@ -11,7 +15,8 @@ enable password zebra
! !
log syslog informational log syslog informational
log facility local4 log facility local4
!! !
! end of template: common/daemons.common.conf.j2!
agentx agentx
! !
! !
@ -37,49 +42,46 @@ router bgp 4000 vrf VnetFE
exit-address-family exit-address-family
!! !!
! !
! template: bgpd/bgpd.main.conf.j2
! !
! bgp multiple-instance ! bgp multiple-instance
! !
route-map FROM_BGP_SPEAKER_V4 permit 10 ! BGP configuration
! !
route-map TO_BGP_SPEAKER_V4 deny 10 ! TSA configuration
! !
ip prefix-list PL_LoopbackV4 permit 4.0.0.0/32 ip prefix-list PL_LoopbackV4 permit 4.0.0.0/32
! !
! !
route-map TO_BGP_PEER_V4 permit 100
! !
route-map TO_BGP_PEER_V6 permit 100
!
!
route-map ISOLATE permit 10
set as-path prepend 4000
!
route-map set-next-hop-global-v6 permit 10
set ipv6 next-hop prefer-global
! !
router bgp 4000 router bgp 4000
!
bgp log-neighbor-changes bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
no bgp default ipv4-unicast no bgp default ipv4-unicast
!
bgp bestpath as-path multipath-relax
!
bgp graceful-restart restart-time 240 bgp graceful-restart restart-time 240
bgp graceful-restart bgp graceful-restart
bgp graceful-restart preserve-fw-state
!
bgp router-id 4.0.0.0 bgp router-id 4.0.0.0
!
network 4.0.0.0/32 network 4.0.0.0/32
!
!
!
!
!
address-family ipv4 address-family ipv4
maximum-paths 64 maximum-paths 64
exit-address-family exit-address-family
address-family ipv6 address-family ipv6
maximum-paths 64 maximum-paths 64
exit-address-family exit-address-family
neighbor PEER_V4 peer-group !
neighbor PEER_V6 peer-group ! end of template: bgpd/bgpd.main.conf.j2
address-family ipv4
neighbor PEER_V4 soft-reconfiguration inbound
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out
exit-address-family
address-family ipv6
neighbor PEER_V6 soft-reconfiguration inbound
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out
exit-address-family
!! !!
! end of template: bgpd/bgpd.conf.j2
!

View File

@ -1,9 +1,10 @@
! !
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/zebra.conf.j2 using config DB data ! generated by templates/zebra/zebra.conf.j2 using config DB data
! file: zebra.conf ! file: zebra.conf
! !
! !
! template: common/daemons.common.conf.j2
! !
hostname SpineFront01 hostname SpineFront01
password zebra password zebra
@ -11,7 +12,8 @@ enable password zebra
! !
log syslog informational log syslog informational
log facility local4 log facility local4
!! !
! end of template: common/daemons.common.conf.j2!
! !
vrf VnetFE vrf VnetFE
vni 9000 vni 9000
@ -27,11 +29,4 @@ link-detect
interface Ethernet8 interface Ethernet8
link-detect link-detect
! !
!
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src 4.0.0.0
!
ip protocol bgp route-map RM_SET_SRC
!
!! !!

View File

@ -1,9 +1,10 @@
! !
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/zebra.conf.j2 using config DB data ! generated by templates/zebra/zebra.conf.j2 using config DB data
! file: zebra.conf ! file: zebra.conf
! !
! !
! template: common/daemons.common.conf.j2
! !
hostname SpineFront01 hostname SpineFront01
password zebra password zebra
@ -11,7 +12,8 @@ enable password zebra
! !
log syslog informational log syslog informational
log facility local4 log facility local4
!! !
! end of template: common/daemons.common.conf.j2!
! !
vrf VnetFE vrf VnetFE
vni 8000 vni 8000
@ -27,11 +29,4 @@ link-detect
interface Ethernet8 interface Ethernet8
link-detect link-detect
! !
!
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src 4.0.0.0
!
ip protocol bgp route-map RM_SET_SRC
!
!! !!

View File

@ -1,9 +1,10 @@
! !
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/zebra.conf.j2 using config DB data ! generated by templates/zebra/zebra.conf.j2 using config DB data
! file: zebra.conf ! file: zebra.conf
! !
! !
! template: common/daemons.common.conf.j2
! !
hostname switch-t0 hostname switch-t0
password zebra password zebra
@ -11,7 +12,8 @@ enable password zebra
! !
log syslog informational log syslog informational
log facility local4 log facility local4
!! !
! end of template: common/daemons.common.conf.j2!
! !
! !
! Enable link-detect (default disabled) ! Enable link-detect (default disabled)
@ -27,17 +29,4 @@ link-detect
interface PortChannel04 interface PortChannel04
link-detect link-detect
! !
!
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src 10.1.0.32
!
route-map RM_SET_SRC6 permit 10
set src fc00:1::32
!
ip protocol bgp route-map RM_SET_SRC
!
ipv6 protocol bgp route-map RM_SET_SRC6
!
!! !!

View File

@ -37,8 +37,11 @@ class TestCfgGen(TestCase):
return subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True) return subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True)
def run_case(self, template, target): def run_case(self, template, target):
conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-frr', template) template_dir = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-frr', "frr")
cmd = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + conf_template + ' > ' + self.output_file conf_template = os.path.join(template_dir, template)
constants = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'constants', 'constants.yml')
cmd_args = self.t0_minigraph, self.t0_port_config, constants, conf_template, template_dir, self.output_file
cmd = "-m %s -p %s -y %s -t %s -T %s > %s" % cmd_args
self.run_script(cmd) self.run_script(cmd)
original_filename = os.path.join(self.test_dir, 'sample_output', target) original_filename = os.path.join(self.test_dir, 'sample_output', target)
@ -52,11 +55,11 @@ class TestCfgGen(TestCase):
self.assertTrue(*self.run_case('frr.conf.j2', 'frr.conf')) self.assertTrue(*self.run_case('frr.conf.j2', 'frr.conf'))
def test_bgpd_frr(self): def test_bgpd_frr(self):
self.assertTrue(*self.run_case('bgpd.conf.j2', 'bgpd_frr.conf')) self.assertTrue(*self.run_case('bgpd/bgpd.conf.j2', 'bgpd_frr.conf'))
def test_zebra_frr(self): def test_zebra_frr(self):
self.assertTrue(*self.run_case('zebra.conf.j2', 'zebra_frr.conf')) self.assertTrue(*self.run_case('zebra/zebra.conf.j2', 'zebra_frr.conf'))
def test_staticd_frr(self): def test_staticd_frr(self):
self.assertTrue(*self.run_case('staticd.conf.j2', 'staticd_frr.conf')) self.assertTrue(*self.run_case('staticd/staticd.conf.j2', 'staticd_frr.conf'))

View File

@ -30,8 +30,11 @@ class TestJ2FilesT2ChassisFe(TestCase):
return subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True) return subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True)
def run_case(self, minigraph, template, target): def run_case(self, minigraph, template, target):
conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-frr', template) template_dir = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-frr', "frr")
cmd = '-m ' + minigraph + ' -p ' + self.t2_chassis_fe_port_config + ' -t ' + conf_template + ' > ' + self.output_file conf_template = os.path.join(template_dir, template)
constants = os.path.join(self.test_dir, '..', '..', '..', 'files', 'image_config', 'constants', 'constants.yml')
cmd_args = minigraph, self.t2_chassis_fe_port_config, constants, conf_template, template_dir, self.output_file
cmd = "-m %s -p %s -y %s -t %s -T %s > %s" % cmd_args
self.run_script(cmd) self.run_script(cmd)
original_filename = os.path.join(self.test_dir, 'sample_output', target) original_filename = os.path.join(self.test_dir, 'sample_output', target)
@ -42,13 +45,13 @@ class TestJ2FilesT2ChassisFe(TestCase):
# Test zebra.conf in FRR docker for a T2 chassis frontend (fe) # Test zebra.conf in FRR docker for a T2 chassis frontend (fe)
def test_t2_chassis_fe_zebra_frr(self): def test_t2_chassis_fe_zebra_frr(self):
self.assertTrue(*self.run_case(self.t2_chassis_fe_minigraph, 'zebra.conf.j2', 't2-chassis-fe-zebra.conf')) self.assertTrue(*self.run_case(self.t2_chassis_fe_minigraph, 'zebra/zebra.conf.j2', 't2-chassis-fe-zebra.conf'))
# Test zebra.conf in FRR docker for a T2 chassis frontend (fe) switch with specified VNI # Test zebra.conf in FRR docker for a T2 chassis frontend (fe) switch with specified VNI
def test_t2_chassis_fe_vni_zebra_frr(self): def test_t2_chassis_fe_vni_zebra_frr(self):
self.assertTrue(*self.run_case(self.t2_chassis_fe_vni_minigraph, 'zebra.conf.j2', 't2-chassis-fe-vni-zebra.conf')) self.assertTrue(*self.run_case(self.t2_chassis_fe_vni_minigraph, 'zebra/zebra.conf.j2', 't2-chassis-fe-vni-zebra.conf'))
# Test bgpd.conf in FRR docker for a T2 chassis frontend (fe) # Test bgpd.conf in FRR docker for a T2 chassis frontend (fe)
def test_t2_chassis_frontend_bgpd_frr(self): def test_t2_chassis_frontend_bgpd_frr(self):
self.assertTrue(*self.run_case(self.t2_chassis_fe_minigraph, 'bgpd.conf.j2', 't2-chassis-fe-bgpd.conf')) self.assertTrue(*self.run_case(self.t2_chassis_fe_minigraph, 'bgpd/bgpd.conf.j2', 't2-chassis-fe-bgpd.conf'))