Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
[JIRA SONIC-694] Placeholder for VRF Lite support
Browse files Browse the repository at this point in the history
Minigraph migration and jinja2 template changes for INTF_PREFIX_TABLE
changes from PRs:
sonic-net#2848

Change-Id: Ia6c3bf37702b20c57f7f808299a5a861fce15e11
  • Loading branch information
preetham-singh committed Jun 13, 2019
1 parent 1773338 commit d5e8193
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 43 deletions.
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
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 @@ -11,7 +11,7 @@
{% if VLAN_INTERFACE %}
{% set interfaces = [] %}
{% set INTF_CFG = dict() %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% if prefix | ipv6 %}
{% if name not in INTF_CFG %}
{% set x=INTF_CFG.__setitem__(name, []|list) %}
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 %}
6 changes: 4 additions & 2 deletions files/image_config/interfaces/interfaces.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
auto lo
iface lo inet loopback
# Use command 'ip addr list dev lo' to check all addresses
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if 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 }}
#
{% endfor %}
{% endif %}
{% endblock loopback %}
{% block mgmt_interface %}

Expand Down Expand Up @@ -50,7 +52,7 @@ iface {{ port }} inet6 dhcp

{% else %}
{% 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):
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
6 changes: 3 additions & 3 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_minigraph_mgmt_ports(self):
def test_minigraph_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "INTERFACE.keys()"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), ('Ethernet0', 'FC00::75/126')]")
self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), 'Ethernet0', ('Ethernet0', 'FC00::75/126')]")

def test_minigraph_vlans(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN'
Expand All @@ -122,7 +122,7 @@ def test_minigraph_vlan_members(self):
def test_minigraph_vlan_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "VLAN_INTERFACE.keys()"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27')]")
self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27'), 'Vlan1000']")

def test_minigraph_portchannels(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v PORTCHANNEL'
Expand All @@ -142,7 +142,7 @@ def test_minigraph_portchannel_members(self):
def test_minigraph_portchannel_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORTCHANNEL_INTERFACE.keys()"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "[('PortChannel01', 'FC00::71/126'), ('PortChannel01', '10.0.0.56/31')]")
self.assertEqual(output.strip(), "['PortChannel01', ('PortChannel01', '10.0.0.56/31'), ('PortChannel01', 'FC00::71/126')]")

def test_minigraph_neighbors(self):
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "DEVICE_NEIGHBOR[\'Ethernet124\']"'
Expand Down
Loading

0 comments on commit d5e8193

Please sign in to comment.