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

Generate interface table to have an entry designated to default VRF. #2848

Merged
merged 7 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ isc-dhcp-relay-{{ vlan_name }}
{%- if VLAN[vlan_name]['dhcp_servers'] -%}
[program:isc-dhcp-relay-{{ vlan_name }}]
command=/usr/sbin/dhcrelay -d -m discard -a %%h:%%p %%P --name-alias-map-file /tmp/port-name-alias-map.txt -i {{ vlan_name }}
{%- for (name, prefix) in INTERFACE -%}
{%- for (name, prefix) in INTERFACE|pfx_filter -%}
{%- if prefix | ipv4 %} -i {{ name }}{% endif -%}
{%- endfor -%}
{%- for (name, prefix) in PORTCHANNEL_INTERFACE -%}
{%- for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter -%}
{%- if prefix | ipv4 %} -i {{ name }}{% endif -%}
{%- endfor -%}
{%- for dhcp_server in VLAN[vlan_name]['dhcp_servers'] %} {{ dhcp_server }}{% endfor %}
Expand Down
6 changes: 3 additions & 3 deletions dockers/docker-dhcp-relay/wait_for_intf.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ function wait_until_iface_ready


# Wait for all interfaces to be up and ready
{% for (name, prefix) in INTERFACE %}
{% for (name, prefix) in INTERFACE|pfx_filter %}
wait_until_iface_ready ${PORT_TABLE_PREFIX} {{ name }}
{% endfor %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }}
{% endfor %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
wait_until_iface_ready ${LAG_TABLE_PREFIX} {{ name }}
{% endfor %}
8 changes: 4 additions & 4 deletions dockers/docker-fpm-frr/bgpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
no bgp default ipv4-unicast
bgp graceful-restart restart-time 240
bgp graceful-restart
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% 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 %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
network {{ prefix | ip }}/32
{% elif prefix | ipv6 and name == 'Loopback0' %}
Expand All @@ -47,7 +47,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endblock bgp_init %}
{% endif %}
{% block vlan_advertisement %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
network {{ prefix }}
{% elif prefix | ipv6 %}
Expand Down Expand Up @@ -108,7 +108,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% 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 %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback1' %}
neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }}
{% endif %}
Expand Down
14 changes: 7 additions & 7 deletions dockers/docker-fpm-frr/frr.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ log facility local4
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for (name, prefix) in INTERFACE %}
{% for (name, prefix) in INTERFACE|pfx_filter %}
interface {{ name }}
link-detect
!
Expand All @@ -30,7 +30,7 @@ link-detect
!
{% block default_route %}
! set static default route to mgmt gateway as a backup to learned default
{% for (name, prefix) in MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% endif %}
Expand All @@ -41,7 +41,7 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% set lo_ipv4_addrs = [] %}
{% set lo_ipv6_addrs = [] %}
{% if LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback0' %}
{% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(prefix) %}
Expand Down Expand Up @@ -87,13 +87,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
bgp graceful-restart
{% endif %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% 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 %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
network {{ prefix | ip }}/32
{% elif prefix | ipv6 and name == 'Loopback0' %}
Expand All @@ -105,7 +105,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endblock bgp_init %}
{% endif %}
{% block vlan_advertisement %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
network {{ prefix }}
{% elif prefix | ipv6 %}
Expand Down Expand Up @@ -173,7 +173,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
neighbor {{ bgp_peer['name'] }} passive
neighbor {{ bgp_peer['name'] }} remote-as {{ deployment_id_asn_map[DEVICE_METADATA['localhost']['deployment_id']] }}
neighbor {{ bgp_peer['name'] }} ebgp-multihop 255
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback1' %}
neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }}
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions dockers/docker-fpm-frr/zebra.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enable password zebra
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for (name, prefix) in INTERFACE %}
{% for (name, prefix) in INTERFACE|pfx_filter %}
interface {{ name }}
link-detect
!
Expand All @@ -28,7 +28,7 @@ link-detect
!
{% block default_route %}
! set static default route to mgmt gateway as a backup to learned default
{% for (name, prefix) in MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% endif %}
Expand All @@ -39,7 +39,7 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% set lo_ipv4_addrs = [] %}
{% set lo_ipv6_addrs = [] %}
{% if LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback0' %}
{% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(prefix) %}
Expand Down
6 changes: 3 additions & 3 deletions dockers/docker-fpm-gobgp/zebra.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enable password zebra
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for (name, prefix) in INTERFACE %}
{% for (name, prefix) in INTERFACE|pfx_filter %}
interface {{ name }}
link-detect
!
Expand All @@ -28,7 +28,7 @@ link-detect
!
{% block default_route %}
! set static default route to mgmt gateway as a backup to learned default
{% for (name, prefix) in MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% endif %}
Expand All @@ -39,7 +39,7 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% set lo_ipv4_addrs = [] %}
{% set lo_ipv6_addrs = [] %}
{% if LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(prefix) %}
{% endif %}
Expand Down
8 changes: 4 additions & 4 deletions dockers/docker-fpm-quagga/bgpd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
no bgp default ipv4-unicast
bgp graceful-restart restart-time 240
bgp graceful-restart
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% 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 %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if prefix | ipv4 and name == 'Loopback0' %}
network {{ prefix | ip }}/32
{% elif prefix | ipv6 and name == 'Loopback0' %}
Expand All @@ -47,7 +47,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endblock bgp_init %}
{% endif %}
{% block vlan_advertisement %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
network {{ prefix }}
{% elif prefix | ipv6 %}
Expand Down Expand Up @@ -108,7 +108,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% 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 %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback1' %}
neighbor {{ bgp_peer['name'] }} update-source {{ prefix | ip }}
{% endif %}
Expand Down
6 changes: 3 additions & 3 deletions dockers/docker-fpm-quagga/zebra.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enable password zebra
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for (name, prefix) in INTERFACE %}
{% for (name, prefix) in INTERFACE|pfx_filter %}
interface {{ name }}
link-detect
!
Expand All @@ -28,7 +28,7 @@ link-detect
!
{% block default_route %}
! set static default route to mgmt gateway as a backup to learned default
{% for (name, prefix) in MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% endif %}
Expand All @@ -39,7 +39,7 @@ ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% set lo_ipv4_addrs = [] %}
{% set lo_ipv6_addrs = [] %}
{% if LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{% if name == 'Loopback0' %}
{% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(prefix) %}
Expand Down
8 changes: 4 additions & 4 deletions dockers/docker-orchagent/ipinip.json.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% set ipv6_addresses = [] %}
{% set ipv4_loopback_addresses = [] %}
{% set ipv6_loopback_addresses = [] %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
{%- if prefix | ipv4 and name == 'Loopback0' %}
{%- set ipv4_addresses = ipv4_addresses.append(prefix) %}
{%- set ipv4_loopback_addresses = ipv4_loopback_addresses.append(prefix) %}
Expand All @@ -12,23 +12,23 @@
{%- set ipv6_loopback_addresses = ipv6_loopback_addresses.append(prefix) %}
{%- endif %}
{% endfor %}
{% for (name, prefix) in INTERFACE %}
{% for (name, prefix) in INTERFACE|pfx_filter %}
{%- if prefix | ipv4 %}
{%- set ipv4_addresses = ipv4_addresses.append(prefix) %}
{%- endif %}
{%- if prefix | ipv6 %}
{%- set ipv6_addresses = ipv6_addresses.append(prefix) %}
{%- endif %}
{% endfor %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
{%- if prefix | ipv4 %}
{%- set ipv4_addresses = ipv4_addresses.append(prefix) %}
{%- endif %}
{%- if prefix | ipv6 %}
{%- set ipv6_addresses = ipv6_addresses.append(prefix) %}
{%- endif %}
{% endfor %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{%- if prefix | ipv4 %}
{%- set ipv4_addresses = ipv4_addresses.append(prefix) %}
{%- endif %}
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-router-advertiser/radvd.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{# If our configuration has VLAN interfaces... #}
{% if VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{# If this VLAN has an IPv6 address... #}
{% if prefix | ipv6 %}
interface {{ name }}
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-router-advertiser/wait_for_intf.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ function wait_until_iface_ready


# Wait for all interfaces to be up and ready
{% for (name, prefix) in VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }}
{% endfor %}
4 changes: 2 additions & 2 deletions files/image_config/interfaces/interfaces.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
auto lo
iface lo inet loopback
# Use command 'ip addr list dev lo' to check all addresses
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE|pfx_filter %}
iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static
address {{ prefix | ip }}
netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
Expand All @@ -22,7 +22,7 @@ iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static
# The management network interface
auto eth0
{% if MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
iface eth0 {{ 'inet' if prefix | ipv4 else 'inet6' }} static
address {{ prefix | ip }}
netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
Expand Down
2 changes: 1 addition & 1 deletion files/image_config/ntp/ntp.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ server {{ ntp_server }} iburst
#only listen on localhost and eth0 ips (default is to listen on all ip addresses)
interface ignore wildcard
{% if MGMT_INTERFACE %}
{% for (mgmt_intf, mgmt_prefix) in MGMT_INTERFACE %}
{% for (mgmt_intf, mgmt_prefix) in MGMT_INTERFACE|pfx_filter %}
interface listen {{ mgmt_prefix | ip }}
{% endfor %}
{% else %}
Expand Down
4 changes: 2 additions & 2 deletions files/scripts/arp_update
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

while /bin/true; do
# find L3 interfaces which are UP, send ipv6 multicast pings
echo "{% for (name, prefix) in INTERFACE %} {{name}} {% endfor %}" > /tmp/intf_tmp.j2
echo "{% for (name, prefix) in INTERFACE|pfx_filter %} {{name}} {% endfor %}" > /tmp/intf_tmp.j2
INTERFACE=`sonic-cfggen -d -t /tmp/intf_tmp.j2`
echo "{% for (name, prefix) in PORTCHANNEL_INTERFACE %} {{name}} {% endfor %}" > /tmp/pc_intf_tmp.j2
echo "{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %} {{name}} {% endfor %}" > /tmp/pc_intf_tmp.j2
PC_INTERFACE=`sonic-cfggen -d -t /tmp/pc_intf_tmp.j2`

ALL_INTERFACE="$INTERFACE $PC_INTERFACE"
Expand Down
7 changes: 6 additions & 1 deletion src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,16 @@ def parse_xml(filename, platform=None, port_config_file=None):
for intf in intfs:
if intf[0][0:4] == 'Vlan':
vlan_intfs[intf] = {}
vlan_intfs[intf[0]] = {}
elif vlan_invert_mapping.has_key(intf[0]):
vlan_intfs[(vlan_invert_mapping[intf[0]], intf[1])] = {}
vlan_intfs[vlan_invert_mapping[intf[0]]] = {}
elif intf[0][0:11] == 'PortChannel':
pc_intfs[intf] = {}
pc_intfs[intf[0]] = {}
else:
phyport_intfs[intf] = {}
phyport_intfs[intf[0]] = {}

results['INTERFACE'] = phyport_intfs
results['VLAN_INTERFACE'] = vlan_intfs
Expand Down Expand Up @@ -598,9 +602,10 @@ def parse_xml(filename, platform=None, port_config_file=None):

for pc_intf in pc_intfs.keys():
# remove portchannels not in PORTCHANNEL dictionary
if pc_intf[0] not in pcs:
if isinstance(pc_intf, tuple) and pc_intf[0] not in pcs:
print >> sys.stderr, "Warning: ignore '%s' interface '%s' as '%s' is not in the valid PortChannel list" % (pc_intf[0], pc_intf[1], pc_intf[0])
del pc_intfs[pc_intf]
pc_intfs.pop(pc_intf[0], None)

results['PORTCHANNEL_INTERFACE'] = pc_intfs

Expand Down
8 changes: 8 additions & 0 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ def unique_name(l):
new_list.append(item)
return new_list

def pfx_filter(value):
prsunny marked this conversation as resolved.
Show resolved Hide resolved
table = OrderedDict()
for key,val in value.items():
if not isinstance(key, tuple):
continue
table[key] = val
return table

class FormatConverter:
"""Convert config DB based schema to legacy minigraph based schema for backward capability.
Expand Down Expand Up @@ -234,6 +241,7 @@ def main():
env.filters['ipv4'] = is_ipv4
env.filters['ipv6'] = is_ipv6
env.filters['unique_name'] = unique_name
env.filters['pfx_filter'] = pfx_filter
for attr in ['ip', 'network', 'prefixlen', 'netmask']:
env.filters[attr] = partial(prefix_attr, attr)
template = env.get_template(template_file)
Expand Down
Loading