Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[evpn]: Change frr template to support evpn #2838

Closed
wants to merge 3 commits into from
Closed
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
76 changes: 76 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,62 @@ route-map FROM_BGP_SPEAKER_V4 permit 10
!
route-map TO_BGP_SPEAKER_V4 deny 10
!
{% block vnet_bgp_instance %}
{% if VNET is defined %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does this VNET comes from?

Copy link
Contributor Author

@Pterosaur Pterosaur May 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

! 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
Copy link
Collaborator

@nikos-github nikos-github Apr 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe the circumstances, setup and requirements that need the allowas-in so that I can better understand? Especially under address-family ipv4, allowas-in shouldn't be needed but I'm looking forward to your explanation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is needed as the tor asn is re-used for different clusters.

{% 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 %}
{% endif %}
{% endblock vnet_bgp_instance %}
router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
Expand Down Expand Up @@ -116,7 +172,15 @@ 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'] }}
Expand All @@ -128,10 +192,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 +215,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 +232,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'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this jinja2.ext.do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/Azure/sonic-buildimage/pull/2838/files#diff-4c9b3f6e87e24e7256cd7abf5e0da806R97

We need a temp variable to store the interfaces that belong to the specified vnet. In this situation, the "do" action will be needed.

env.filters['sort_by_port_index'] = sort_by_port_index
env.filters['ipv4'] = is_ipv4
env.filters['ipv6'] = is_ipv6
Expand Down