Skip to content

Commit

Permalink
[evpn]: Change frr template to support evpn
Browse files Browse the repository at this point in the history
- Add extension "do" action to jinja environment in sonic-cfggen
- Change frr.conf.j2 to support evpn

Signed-off-by: zegan <[email protected]>
  • Loading branch information
Pterosaur committed Apr 30, 2019
1 parent 818bbe8 commit a8b68a4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
77 changes: 77 additions & 0 deletions dockers/docker-fpm-frr/frr.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,59 @@ route-map FROM_BGP_SPEAKER_V4 permit 10
!
route-map TO_BGP_SPEAKER_V4 deny 10
!
! Vnet BGP instance
{% for vnet_name, vnet_metadata in VNET.iteritems() %}
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }} vrf {{ vnet_name }}
no bgp default ipv4-unicast
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if prefix | ipv4 and name == 'Loopback0' %}
bgp router-id {{ prefix | ip }}
{% endif %}
{% endfor %}
{# got interfaces that belong this vnet #}
{% set interfaces_in_vnet = [] %}
{% for ((name, prefix), metadata) in INTERFACE.iteritems() %}
{% if metadata.has_key("vnet_name") and metadata["vnet_name"] == vnet_name %}
{% do interfaces_in_vnet.append( prefix | ip ) %}
{% endif %}
{% endfor %}
{% for neighbor_addr, bgp_session in BGP_NEIGHBOR.iteritems() %}
{% if bgp_session.has_key("local_addr") and bgp_session["local_addr"] in interfaces_in_vnet %}
{% if bgp_session['asn'] | int != 0 %}
neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }}
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
{# set the bgp neighbor timers if they have not default values #}
{% if (bgp_session['keepalive'] is defined and bgp_session['keepalive'] | int != 60)
or (bgp_session['holdtime'] is defined and bgp_session['holdtime'] | int != 180) %}
neighbor {{ neighbor_addr }} timers {{ bgp_session['keepalive'] }} {{ bgp_session['holdtime'] }}
{% 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' %}
neighbor {{ neighbor_addr }} shutdown
{% endif %}
{% if neighbor_addr | ipv4 %}
address-family ipv4
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor {{ neighbor_addr }} allowas-in 1
{% endif %}
neighbor {{ neighbor_addr }} activate
neighbor {{ neighbor_addr }} soft-reconfiguration inbound
{% if bgp_session['rrclient'] | int != 0 %}
neighbor {{ neighbor_addr }} route-reflector-client
{% endif %}
{% if bgp_session['nhopself'] | int != 0 %}
neighbor {{ neighbor_addr }} next-hop-self
{% endif %}
maximum-paths 64
exit-address-family
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
address-family l2vpn evpn
advertise ipv4 unicast
exit-address-family
{% endfor %}
!
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
Expand Down Expand Up @@ -116,10 +169,22 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endfor %}
{% endblock vlan_advertisement %}
{% block bgp_sessions %}
{# got interfaces that belong vnet #}
{% set interfaces_in_vnet = [] %}
{% for ((name, prefix), metadata) in INTERFACE.iteritems() %}
{% if metadata.has_key("vnet_name") %}
{% do interfaces_in_vnet.append( prefix | ip ) %}
{% endif %}
{% endfor %}
{% for neighbor_addr, bgp_session in BGP_NEIGHBOR.iteritems() %}

{% if not bgp_session.has_key("local_addr") or bgp_session["local_addr"] not in interfaces_in_vnet %}
{% if bgp_session['asn'] | int != 0 %}
neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }}
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
{% if bgp_session.has_key("local_addr") %}
neighbor {{ neighbor_addr }} update-source {{ bgp_session["local_addr"]}}
{%endif %}
{# set the bgp neighbor timers if they have not default values #}
{% if (bgp_session['keepalive'] is defined and bgp_session['keepalive'] | int != 60)
or (bgp_session['holdtime'] is defined and bgp_session['holdtime'] | int != 180) %}
Expand All @@ -128,10 +193,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% 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' %}
neighbor {{ neighbor_addr }} shutdown
{% endif %}
{% if not bgp_session.has_key("address-family") or bgp_session["address-family"] == "ip" %}
{% if neighbor_addr | ipv4 %}
address-family ipv4
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor {{ neighbor_addr }} allowas-in 1
{% elif bgp_session.has_key("allowas-in") %}
neighbor {{ neighbor_addr }} allowas-in {{ bgp_session["allowas-in"] }}
{% endif %}
neighbor {{ neighbor_addr }} activate
neighbor {{ neighbor_addr }} soft-reconfiguration inbound
Expand All @@ -148,6 +216,8 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
address-family ipv6
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor {{ neighbor_addr }} allowas-in 1
{% elif bgp_session.has_key("allowas-in") %}
neighbor {{ neighbor_addr }} allowas-in {{ bgp_session["allowas-in"] }}
{% endif %}
neighbor {{ neighbor_addr }} activate
neighbor {{ neighbor_addr }} soft-reconfiguration inbound
Expand All @@ -163,6 +233,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
maximum-paths 64
exit-address-family
{% endif %}
{% elif bgp_session["address-family"] == "evpn" %}
address-family l2vpn evpn
neighbor {{ neighbor_addr }} activate
advertise-all-vni
exit-address-family
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endblock bgp_sessions %}
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def main():
paths = ['/', '/usr/share/sonic/templates', os.path.dirname(template_file)]
loader = jinja2.FileSystemLoader(paths)

env = jinja2.Environment(loader=loader, trim_blocks=True)
env = jinja2.Environment(loader=loader, trim_blocks=True, extensions=['jinja2.ext.do'])
env.filters['sort_by_port_index'] = sort_by_port_index
env.filters['ipv4'] = is_ipv4
env.filters['ipv6'] = is_ipv6
Expand Down

0 comments on commit a8b68a4

Please sign in to comment.