Skip to content

Commit

Permalink
Initial commit for adding non-template bgpcfgd script
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaozhenhong committed Aug 10, 2020
1 parent 08f3b97 commit 47f5736
Show file tree
Hide file tree
Showing 22 changed files with 5,347 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dockers/docker-fpm-frr/docker_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mkdir -p /etc/supervisor/conf.d
sonic-cfggen -d -t /usr/share/sonic/templates/supervisord/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf

CONFIG_TYPE=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["docker_routing_config_mode"]'`
TEMPL_CONFIG=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["bgp_template_config"]'`

if [[ ! -z "$NAMESPACE_ID" ]]; then
# FRR is not running in host namespace so we need to delete
Expand Down Expand Up @@ -34,12 +35,17 @@ if [ -z "$CONFIG_TYPE" ] || [ "$CONFIG_TYPE" == "separated" ]; then
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/zebra.conf.j2 > /etc/frr/zebra.conf
sonic-cfggen -d -t /usr/share/sonic/templates/staticd/staticd.conf.j2 > /etc/frr/staticd.conf
if [ -n "$TEMPL_CONFIG" ] && [ "$TEMPL_CONFIG" == "false" ]; then
sonic-cfggen -d -t /usr/share/sonic/templates/bgdd/bfdd.conf.j2 > /etc/frr/bfdd.conf
sonic-cfggen -d -t /usr/share/sonic/templates/ospfd/ospfd.conf.j2 > /etc/frr/ospfd.conf
fi
echo "no service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/frr.conf
elif [ "$CONFIG_TYPE" == "unified" ]; then
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/frr.conf.j2 >/etc/frr/frr.conf
echo "service integrated-vtysh-config" > /etc/frr/vtysh.conf
rm -f /etc/frr/bgpd.conf /etc/frr/zebra.conf /etc/frr/staticd.conf
rm -f /etc/frr/bfdd.conf /etc/frr/ospfd.conf /etc/frr/pimd.conf
fi

chown -R frr:frr /etc/frr/
Expand Down
91 changes: 91 additions & 0 deletions dockers/docker-fpm-frr/frr/bfdd/bfdd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
!
{% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/frr/bfd.conf.j2 with config DB data
! file: bfd.conf
!
{% endblock banner %}
!
{% block bfd_shop_peers %}
{% if BFD_PEER_SINGLE_HOP %}
bfd
{% for (peer_key, peer_info) in BFD_PEER_SINGLE_HOP.iteritems() %}
{% set peer_args = '' %}
{% if peer_key[0] != 'null' %}
{% set peer_args = peer_args~' '~'peer'~' '~peer_key[0] %}
{% endif %}
{% if peer_key[1] != 'null' %}
{% set peer_args = peer_args~' '~'interface'~' '~peer_key[1] %}
{% endif %}
{% if peer_key[2] != 'null' %}
{% set peer_args = peer_args~' '~'vrf'~' '~peer_key[2] %}
{% endif %}
{% if peer_key[3] != 'null' %}
{% set peer_args = peer_args~' '~'local-address'~' '~peer_key[3] %}
{% endif %}
{{ peer_args }}
{# set the bfd peer timers #}
{% if (peer_info['desired-minimum-tx-interval'] is defined and peer_info['desired-minimum-tx-interval'] | int != 300) %}
transmit-interval {{ peer_info['desired-minimum-tx-interval'] }}
{% endif %}
{% if (peer_info['required-minimum-receive'] is defined and peer_info['required-minimum-receive'] | int != 300) %}
receive-interval {{ peer_info['required-minimum-receive'] }}
{% endif %}
{% if (peer_info['detection-multiplier'] is defined and peer_info['detection-multiplier'] | int != 3) %}
detect-multiplier {{ peer_info['detection-multiplier'] }}
{% endif %}
{% if (peer_info['echo-active'] is defined and peer_info['echo-active'] != 'false') %}
echo-mode
{% endif %}
{% if (peer_info['desired-minimum-echo-receive'] is defined and peer_info['desired-minimum-echo-receive'] | int != 50) %}
echo-interval {{ peer_info['desired-minimum-echo-receive'] }}
{% endif %}
{% if (peer_info['enabled'] is defined and peer_info['enabled'] == 'true') %}
no shutdown
{% else %}
shutdown
{% endif %}
!
{% endfor %}
!
{% endif %}
{% endblock bfd_shop_peers%}
{% block bfd_mhop_peers %}
{% if BFD_PEER_MULTI_HOP %}
bfd
{% for (peer_key, peer_info) in BFD_PEER_MULTI_HOP.iteritems() %}
{% set peer_args = '' %}
{% if peer_key[0] != 'null' %}
{% set peer_args = peer_args~' '~'peer'~' '~peer_key[0] %}
{% endif %}
{% if peer_key[1] != 'null' %}
{% set peer_args = peer_args~' '~'interface'~' '~peer_key[1] %}
{% endif %}
{% if peer_key[2] != 'null' %}
{% set peer_args = peer_args~' '~'vrf'~' '~peer_key[2] %}
{% endif %}
{% if peer_key[3] != 'null' %}
{% set peer_args = peer_args~' '~'local-address'~' '~peer_key[3] %}
{% endif %}
{% set peer_args = peer_args~' '~'multihop' %}
{{ peer_args }}
{# set the bfd peer timers #}
{% if (peer_info['desired-minimum-tx-interval'] is defined and peer_info['desired-minimum-tx-interval'] | int != 300) %}
transmit-interval {{ peer_info['desired-minimum-tx-interval'] }}
{% endif %}
{% if (peer_info['required-minimum-receive'] is defined and peer_info['required-minimum-receive'] | int != 300) %}
receive-interval {{ peer_info['required-minimum-receive'] }}
{% endif %}
{% if (peer_info['detection-multiplier'] is defined and peer_info['detection-multiplier'] | int != 3) %}
detect-multiplier {{ peer_info['detection-multiplier'] }}
{% endif %}
{% if (peer_info['enabled'] is defined and peer_info['enabled'] == 'true') %}
no shutdown
{% else %}
shutdown
{% endif %}
!
{% endfor %}
!
{% endif %}
{% endblock bfd_mhop_peers%}
78 changes: 78 additions & 0 deletions dockers/docker-fpm-frr/frr/bgpd/bgpd.conf.db.addr_family.evpn.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{% if af_val.has_key('advertise-all-vni') and af_val['advertise-all-vni'] == 'true' %}
advertise-all-vni
{% endif %}
{% if af_val.has_key('autort') %}
autort {{af_val['autort']}}
{% endif %}
{% if af_val.has_key('advertise-default-gw') and af_val['advertise-default-gw'] == 'true' %}
advertise-default-gw
{% endif %}
{% if af_val.has_key('dad-enabled') and af_val.has_key('dad-max-moves') and af_val.has_key('dad-time') %}
dup-addr-detection max-moves {{af_val['dad-max-moves']}} time {{af_val['dad-time']}}
{% endif %}
{% if af_val.has_key('dad-freeze') %}
dup-addr-detection freeze {{af_val['dad-freeze']}}
{% endif %}
{% if af_val.has_key('advertise-ipv4-unicast') and af_val['advertise-ipv4-unicast'] == 'true' %}
advertise ipv4 unicast
{% endif %}
{% if af_val.has_key('advertise-ipv6-unicast') and af_val['advertise-ipv6-unicast'] == 'true' %}
advertise ipv6 unicast
{% endif %}
{% if af_val.has_key('default-originate-ipv4') and af_val['default-originate-ipv4'] == 'true' %}
default-originate ipv4
{% endif %}
{% if af_val.has_key('default-originate-ipv6') and af_val['default-originate-ipv6'] == 'true' %}
default-originate ipv6
{% endif %}
{% if af_val.has_key('route-distinguisher') %}
rd {{af_val['route-distinguisher']}}
{% endif %}
{% if af_val.has_key('import-rts') %}
{% for irt in af_val['import-rts'] %}
route-target import {{irt}}
{% endfor %}
{% endif %}
{% if af_val.has_key('export-rts') %}
{% for irt in af_val['export-rts'] %}
route-target export {{irt}}
{% endfor %}
{% endif %}
{% if BGP_GLOBALS_EVPN_RT is defined and BGP_GLOBALS_EVPN_RT|length > 0 %}
{% for evpn_rt_key, evpn_rt_val in BGP_GLOBALS_EVPN_RT.iteritems() %}
{% if vrf == evpn_rt_key[0] %}
route-target {{evpn_rt_val['route-target-type']}} {{evpn_rt_key[2]}}
{% endif %}
{% endfor %}
{% endif %}
{% if BGP_GLOBALS_EVPN_VNI is defined and BGP_GLOBALS_EVPN_VNI|length > 0 %}
{% for vni_key, vni_val in BGP_GLOBALS_EVPN_VNI.iteritems() %}
{% if vrf == vni_key[0] %}
vni {{vni_key[2]}}
{% if vni_val.has_key('route-distinguisher') %}
rd {{vni_val['route-distinguisher']}}
{% endif %}
{% if vni_val.has_key('import-rts') %}
{% for irt in vni_val['import-rts'] %}
route-target import {{irt}}
{% endfor %}
{% endif %}
{% if vni_val.has_key('export-rts') %}
{% for irt in vni_val['export-rts'] %}
route-target export {{irt}}
{% endfor %}
{% endif %}
{% if BGP_GLOBALS_EVPN_VNI_RT is defined and BGP_GLOBALS_EVPN_VNI_RT|length > 0 %}
{% for vni_rt_key, vni_rt_val in BGP_GLOBALS_EVPN_VNI_RT.iteritems() %}
{% if vrf == vni_rt_key[0] and vni_key[2] == vni_rt_key[2] %}
route-target {{vni_rt_val['route-target-type']}} {{vni_rt_key[3]}}
{% endif %}
{% endfor %}
{% endif %}
{% if vni_val.has_key('advertise-default-gw') and vni_val['advertise-default-gw'] == 'true' %}
advertise-default-gw
{% endif %}
exit-vni
{% endif %}
{% endfor %}
{% endif %}
143 changes: 143 additions & 0 deletions dockers/docker-fpm-frr/frr/bgpd/bgpd.conf.db.addr_family.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{# -----------------------------------------------------------------------------------------#}
{# this is invoked with the "vrf" variable set #}
{# -----------------------------------------------------------------------------------------#}
{# -------address-family --------------------------- #}
{% if (BGP_GLOBALS_AF is defined and BGP_GLOBALS_AF|length > 0) or
(BGP_GLOBALS_AF_NETWORK is defined and BGP_GLOBALS_AF_NETWORK|length > 0) or
(BGP_GLOBALS_AF_AGGREGATE_ADDR is defined and BGP_GLOBALS_AF_AGGREGATE_ADDR|length > 0) or
(ROUTE_REDISTRIBUTE is defined and ROUTE_REDISTRIBUTE|length > 0) or
(BGP_PEER_GROUP_AF is defined and BGP_PEER_GROUP_AF|length > 0) or
(BGP_NEIGHBOR_AF is defined and BGP_NEIGHBOR_AF|length > 0) %}
{% set af_str_map = { 'ipv4_unicast': 'ipv4', 'ipv6_unicast':'ipv6', 'l2vpn_evpn':'l2vpn'} %}
{% set safi_str_map = { 'ipv4_unicast': 'unicast', 'ipv6_unicast':'unicast', 'l2vpn_evpn':'evpn'} %}
{% for af, af_str in af_str_map|dictsort %}
!
address-family {{af_str}} {{safi_str_map[af]}}
{% if BGP_GLOBALS_AF is defined and BGP_GLOBALS_AF|length > 0 %}
{% for af_key, af_val in BGP_GLOBALS_AF.iteritems() %}
{% if vrf == af_key[0] and af == af_key[1] %}
{% if af_val.has_key('ebgp_route_distance') and af_val.has_key('ibgp_route_distance') and af_val.has_key('local_route_distance') %}
distance bgp {{af_val['ebgp_route_distance']}} {{af_val['ibgp_route_distance']}} {{af_val['local_route_distance']}}
{% endif %}
{% if af_val.has_key('import_vrf') %}
import vrf {{af_val['import_vrf']}}
{% endif %}
{% if af_val.has_key('import_vrf_route_map') %}
import vrf route-map {{af_val['import_vrf_route_map']}}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{# ------- network-prefix --------------------------- #}
{% if BGP_GLOBALS_AF_NETWORK is defined and BGP_GLOBALS_AF_NETWORK|length > 0 %}
{% for af_nw_key, af_nw_val in BGP_GLOBALS_AF_NETWORK.iteritems() %}
{% if vrf == af_nw_key[0] and af == af_nw_key[1] %}
{% set af_nw_ns = namespace(nw_end = '') %}
{% if af_nw_val.has_key('backdoor') and af_nw_val['backdoor'] == 'true' %}
{% set af_nw_ns.nw_end = 'backdoor ' %}
{% endif %}
{% if af_nw_val.has_key('policy') %}
{% set af_nw_ns.nw_end = af_nw_ns.nw_end + 'route-map ' + af_nw_val['policy'] %}
{% endif %}
network {{af_nw_key[2]}} {{af_nw_ns.nw_end}}
{% endif %}
{% endfor %}
{% endif %}
{# ------- network-prefix end --------------------------- #}
{# ------- aggregate-prefix -Start--------------------------- #}
{% if BGP_GLOBALS_AF_AGGREGATE_ADDR is defined and BGP_GLOBALS_AF_AGGREGATE_ADDR|length > 0 %}
{% for af_ag_key, af_ag_val in BGP_GLOBALS_AF_AGGREGATE_ADDR.iteritems() %}
{% set af_ag_ns = namespace(ag_end = '') %}
{% if vrf == af_ag_key[0] and af == af_ag_key[1] %}
{% if af_ag_val.has_key('as_set') and af_ag_val['as_set'] == 'true' %}
{% set af_ag_ns.ag_end = 'as-set ' %}
{% endif %}
{% if af_ag_val.has_key('summary_only') and af_ag_val['summary_only'] == 'true' %}
{% set af_ag_ns.ag_end = af_ag_ns.ag_end + 'summary-only' %}
{% endif %}
aggregate-address {{af_ag_key[2]}} {{af_ag_ns.ag_end}}
{% endif %}
{% endfor %}
{% endif %}
{# ------- aggregate-prefix - End --------------------------- #}
{# ------- redistribute - Start --------------------------- #}
{% if ROUTE_REDISTRIBUTE is defined and ROUTE_REDISTRIBUTE|length > 0 %}
{% for rr_key, rr_val in ROUTE_REDISTRIBUTE.items() %}
{% if vrf == rr_key[0] and af_str == rr_key[3] %}
{% if rr_val.has_key('route_map') %}
{% for rmap in rr_val['route_map'] %}
redistribute {{rr_key[1]}} route-map {{rmap}}
{% endfor %}
{% else %}
redistribute {{rr_key[1]}}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{# ------- redistribute - End ----------------------------- #}
{# ------- peer-group af--------------------------- #}
{% if BGP_PEER_GROUP_AF is defined and BGP_PEER_GROUP_AF|length > 0 %}
{% for n_af_key, n_af_val in BGP_PEER_GROUP_AF.items() %}
{% if vrf == n_af_key[0] and af == n_af_key[2] %}
{% set nbr_name = n_af_key[1] %}
{% include "bgpd.conf.db.nbr_af.j2" %}
{% endif %}
{% endfor %}
{% endif %}
{# ------- peer-group af end --------------------------- #}
{# ------- neighbor af--------------------------- #}
{% if BGP_NEIGHBOR_AF is defined and BGP_NEIGHBOR_AF|length > 0 %}
{% for n_af_key, n_af_val in BGP_NEIGHBOR_AF.items() %}
{% if vrf == n_af_key[0] and af == n_af_key[2] %}
{% set nbr_name = n_af_key[1] %}
{% include "bgpd.conf.db.nbr_af.j2" %}
{% endif %}
{% endfor %}
{% endif %}
{# ------- neighbor af end --------------------------- #}
{% if BGP_GLOBALS_AF is defined and BGP_GLOBALS_AF|length > 0 %}
{% for af_key, af_val in BGP_GLOBALS_AF.items() %}
{% if vrf == af_key[0] and af == af_key[1] %}
{# -------bgp dampen - start--------------------------- #}
{% if af_val.has_key('route_flap_dampen') and af_val['route_flap_dampen'] == 'true' %}
{% set ns = namespace(route_dampen = '') %}
{% if af_val.has_key('route_flap_dampen_half_life') %}
{% set ns.route_dampen = ns.route_dampen + af_val['route_flap_dampen_half_life'] + ' ' %}
{% if af_val.has_key('route_flap_dampen_reuse_threshold') %}
{% set ns.route_dampen = ns.route_dampen + af_val['route_flap_dampen_reuse_threshold'] + ' ' %}
{% if af_val.has_key('route_flap_dampen_suppress_threshold') %}
{% set ns.route_dampen = ns.route_dampen + af_val['route_flap_dampen_suppress_threshold'] + ' ' %}
{% if af_val.has_key('route_flap_dampen_max_suppress') %}
{% set ns.route_dampen = ns.route_dampen + af_val['route_flap_dampen_max_suppress'] + ' ' %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
bgp dampening {{ns.route_dampen}}
{% endif %}
{# -------bgp dampen - end --------------------------- #}
{% if af_val.has_key('max_ebgp_paths') %}
maximum-paths {{af_val['max_ebgp_paths']}}
{% endif %}
{% if af_val.has_key('max_ibgp_paths') %}
{% set ns = namespace(max_ibgp = af_val['max_ibgp_paths']) %}
{% if af_val.has_key('ibgp_equal_cluster_length') and af_val['ibgp_equal_cluster_length'] == 'true' %}
{% set ns.max_ibgp = ns.max_ibgp + ' equal-cluster-length' %}
{% endif %}
maximum-paths ibgp {{ns.max_ibgp}}
{% endif %}
{% if af_val.has_key('route_download_filter') %}
table-map {{af_val['route_download_filter']}}
{% endif %}
{# -------bgp evpn - start --------------------------- #}
{% if af == 'l2vpn_evpn' %}
{% include "bgpd.conf.db.addr_family.evpn.j2" %}
{% endif %}
{# -------bgp evpn - end --------------------------- #}
{% endif %}
{% endfor %}
{% endif %}
exit-address-family
{% endfor %}
{% endif %}
{# -------address-family end --------------------------- #}
54 changes: 54 additions & 0 deletions dockers/docker-fpm-frr/frr/bgpd/bgpd.conf.db.comm_list.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{# ------------------------------------------------------------------------------------ #}
{% if (COMMUNITY_SET is defined and COMMUNITY_SET|length > 0) or
(EXTENDED_COMMUNITY_SET is defined and EXTENDED_COMMUNITY_SET|length >0) %}
!
{% endif %}
{# ------------------------------------------------------------------------------------ #}
{% if COMMUNITY_SET is defined and COMMUNITY_SET|length > 0 %}
{% for cm_key, cm_val in COMMUNITY_SET.items() %}
{% if cm_val.has_key('set_type') and cm_val.has_key('match_action') and cm_val.has_key('community_member') %}
{% if cm_val['match_action']|lower == 'all' %}
{% set ns = namespace(cm_list = '') %}
{% for cm in cm_val['community_member'] %}
{% set ns.cm_list = ns.cm_list + cm + ' ' %}
{% endfor %}
bgp community-list {{cm_val['set_type']|lower}} {{cm_key}} permit {{ns.cm_list}}
{% elif cm_val['match_action']|lower == 'any' %}
{% for cm in cm_val['community_member'] %}
bgp community-list {{cm_val['set_type']|lower}} {{cm_key}} permit {{cm}}
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{# ------------------------------------------------------------------------------------ #}
{% if EXTENDED_COMMUNITY_SET is defined and EXTENDED_COMMUNITY_SET|length > 0 %}
{% for cm_key, cm_val in EXTENDED_COMMUNITY_SET.items() %}
{% if cm_val.has_key('set_type') and cm_val.has_key('match_action') and cm_val.has_key('community_member') %}
{% if cm_val['match_action']|lower == 'all' %}
{% set ns = namespace(cm_list = '') %}
{% for cm in cm_val['community_member'] %}
{% if 'route-target' in cm %}
{% set ns.cm_list = ns.cm_list + 'rt ' + cm[13:] + ' ' %}
{% elif 'route-origin' in cm %}
{% set ns.cm_list = ns.cm_list + 'soo ' + cm[13:] + ' ' %}
{% else %}
{% set ns.cm_list = ns.cm_list + cm + ' ' %}
{% endif %}
{% endfor %}
bgp extcommunity-list {{cm_val['set_type']|lower}} {{cm_key}} permit {{ns.cm_list}}
{% elif cm_val['match_action']|lower == 'any' %}
{% for cm in cm_val['community_member'] %}
{% if 'route-target' in cm %}
bgp extcommunity-list {{cm_val['set_type']|lower}} {{cm_key}} permit rt {{cm[13:]}}
{% elif 'route-origin' in cm %}
bgp extcommunity-list {{cm_val['set_type']|lower}} {{cm_key}} permit soo {{cm[13:]}}
{% else %}
bgp extcommunity-list {{cm_val['set_type']|lower}} {{cm_key}} permit {{cm}}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{# ------------------------------------------------------------------------------------ #}
Loading

0 comments on commit 47f5736

Please sign in to comment.