[configdb] Migrate minigraph configurations to DB (#942)

Modify minigraph parser output format so it fit DB schema
Modify configuration templates to fit new schema
Systemd services dependencies are modified so database starts before any configuration consumer
This commit is contained in:
Taoyu Li 2017-09-12 14:13:27 -07:00 committed by GitHub
parent bc73082922
commit c9cc7aea41
47 changed files with 458 additions and 428 deletions

View File

@ -25,5 +25,6 @@ RUN rm -rf /debs
COPY ["start.sh", "isc-dhcp-relay.sh", "/usr/bin/"] COPY ["start.sh", "isc-dhcp-relay.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["isc-dhcp-relay.j2", "/usr/share/sonic/templates/"] COPY ["isc-dhcp-relay.j2", "/usr/share/sonic/templates/"]
COPY ["wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
ENTRYPOINT ["/usr/bin/supervisord"] ENTRYPOINT ["/usr/bin/supervisord"]

View File

@ -1,25 +1,25 @@
SERVERS="{{ dhcp_servers | join(' ') }}" SERVERS="{{ DHCP_SERVER | join(' ') }}"
INTERFACES=" INTERFACES="
{%- set add_preceding_space = { 'flag': False } %} {%- set add_preceding_space = { 'flag': False } %}
{%- for interface in minigraph_interfaces %} {%- for (name, prefix) in INTERFACE %}
{%- if interface['addr'] | ipv4 %} {%- if prefix | ipv4 %}
{%- if add_preceding_space.flag %} {% endif %} {%- if add_preceding_space.flag %} {% endif %}
{{ interface['attachto'] }} {{ name }}
{%- set _dummy = add_preceding_space.update({'flag': True}) %} {%- set _dummy = add_preceding_space.update({'flag': True}) %}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{%- for vlan_interface in minigraph_vlan_interfaces %} {%- for (name, prefix) in VLAN_INTERFACE %}
{%- if vlan_interface['addr'] | ipv4 %} {%- if prefix | ipv4 %}
{%- if add_preceding_space.flag %} {% endif %} {%- if add_preceding_space.flag %} {% endif %}
{{ vlan_interface['attachto'] }} {{ name }}
{%- set _dummy = add_preceding_space.update({'flag': True}) %} {%- set _dummy = add_preceding_space.update({'flag': True}) %}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{%- for pc_interface in minigraph_portchannel_interfaces %} {%- for (name, prefix) in PORTCHANNEL_INTERFACE %}
{%- if pc_interface['addr'] | ipv4 %} {%- if prefix | ipv4 %}
{%- if add_preceding_space.flag %} {% endif %} {%- if add_preceding_space.flag %} {% endif %}
{{ pc_interface['attachto'] }} {{ name }}
{%- set _dummy = add_preceding_space.update({'flag': True}) %} {%- set _dummy = add_preceding_space.update({'flag': True}) %}
{%- endif %} {%- endif %}
{%- endfor %}" {%- endfor %}"

View File

@ -1,42 +1,16 @@
#!/usr/bin/env bash #!/usr/bin/env bash
function wait_until_iface_exists
{
IFACE=$1
echo "Waiting for interface ${IFACE}..."
# Wait for the interface to come up (i.e., 'ip link show' returns 0)
until ip link show $IFACE > /dev/null 2>&1; do
sleep 1
done
echo "Interface ${IFACE} is created"
}
# Create isc-dhcp-relay config file # Create isc-dhcp-relay config file
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/isc-dhcp-relay.j2 > /etc/default/isc-dhcp-relay sonic-cfggen -d -t /usr/share/sonic/templates/isc-dhcp-relay.j2 > /etc/default/isc-dhcp-relay
rm -f /var/run/rsyslogd.pid rm -f /var/run/rsyslogd.pid
supervisorctl start rsyslogd supervisorctl start rsyslogd
# Wait for all interfaces to come up before starting the DHCP relay # Wait for all interfaces to come up before starting the DHCP relay
sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_intf.sh.j2 > /usr/bin/wait_for_intf.sh
FRONT_PANEL_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/') chmod +x /usr/bin/wait_for_intf.sh
for IFACE in $FRONT_PANEL_IFACES; do /usr/bin/wait_for_intf.sh
wait_until_iface_exists $IFACE
done
VLAN_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_vlan_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
for IFACE in $VLAN_IFACES; do
wait_until_iface_exists $IFACE
done
PORTCHANNEL_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_portchannel_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
for IFACE in $PORTCHANNEL_IFACES; do
wait_until_iface_exists $IFACE
done
# Start the DHCP relay # Start the DHCP relay
supervisorctl start isc-dhcp-relay supervisorctl start isc-dhcp-relay

View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
function wait_until_iface_exists
{
IFACE=$1
echo "Waiting for interface ${IFACE}..."
# Wait for the interface to come up (i.e., 'ip link show' returns 0)
until ip link show $IFACE > /dev/null 2>&1; do
sleep 1
done
echo "Interface ${IFACE} is created"
}
# Wait for all interfaces to come up before starting the DHCP relay
{% for (name, prefix) in INTERFACE %}
wait_until_iface_exists {{ name }}
{% endfor %}
{% for (name, prefix) in VLAN_INTERFACE %}
wait_until_iface_exists {{ name }}
{% endfor %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE %}
wait_until_iface_exists {{ name }}
{% endfor %}

View File

@ -1,13 +1,13 @@
! !
{% block banner %} {% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 using minigraph_facts.py ! generated by templates/quagga/bgpd.conf.j2 with config DB data
! file: bgpd.conf ! file: bgpd.conf
! !
{% endblock banner %} {% endblock banner %}
! !
{% block system_init %} {% block system_init %}
hostname {{ inventory_hostname }} hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
password zebra password zebra
log syslog informational log syslog informational
log facility local4 log facility local4
@ -23,25 +23,25 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
bgp bestpath as-path multipath-relax bgp bestpath as-path multipath-relax
no bgp default ipv4-unicast no bgp default ipv4-unicast
{# TODO: use lo[0] for backward compatibility, will revisit the case with multiple lo interfaces #} {# TODO: use lo[0] for backward compatibility, will revisit the case with multiple lo interfaces #}
bgp router-id {{ minigraph_lo_interfaces[0]['addr'] }} bgp router-id {{ LOOPBACK_INTERFACE.keys()[0][1] }}
{# advertise loopback #} {# advertise loopback #}
{% for lo in minigraph_lo_interfaces %} {% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if lo['addr'] | ipv4 %} {% if prefix | ipv4 %}
network {{ lo['addr'] }}/32 network {{ prefix | ip }}/32
{% elif lo['addr'] | ipv6 %} {% elif prefix | ipv6 %}
address-family ipv6 address-family ipv6
network {{ lo['addr'] }}/128 network {{ prefix | ip }}/128
exit-address-family exit-address-family
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endblock bgp_init %} {% endblock bgp_init %}
{% block vlan_advertisement %} {% block vlan_advertisement %}
{% for vlan_interface in minigraph_vlan_interfaces %} {% for (name, prefix) in VLAN_INTERFACE %}
{% if vlan_interface['addr'] | ipv4 %} {% if prefix | ipv4 %}
network {{ vlan_interface['subnet'] }} network {{ prefix }}
{% elif vlan_interface['addr'] | ipv6 %} {% elif prefix | ipv6 %}
address-family ipv6 address-family ipv6
network {{ vlan_interface['subnet'] }} network {{ prefix }}
exit-address-family exit-address-family
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -51,7 +51,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if bgp_session['asn'] != 0 %} {% if bgp_session['asn'] != 0 %}
neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }} neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }}
neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }} neighbor {{ neighbor_addr }} description {{ bgp_session['name'] }}
{% if minigraph_devices[inventory_hostname]['type'] == 'ToRRouter' %} {% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor {{ neighbor_addr }} allowas-in 1 neighbor {{ neighbor_addr }} allowas-in 1
{% endif %} {% endif %}
{% if neighbor_addr | ipv4 %} {% if neighbor_addr | ipv4 %}

View File

@ -1,14 +1,14 @@
#!/bin/bash #!/bin/bash
mkdir -p /etc/frr mkdir -p /etc/frr
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/bgpd.conf.j2 >/etc/frr/bgpd.conf sonic-cfggen -d -t /usr/share/sonic/templates/bgpd.conf.j2 >/etc/frr/bgpd.conf
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/zebra.conf.j2 >/etc/frr/zebra.conf sonic-cfggen -d -t /usr/share/sonic/templates/zebra.conf.j2 >/etc/frr/zebra.conf
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/isolate.j2 >/usr/sbin/bgp-isolate sonic-cfggen -d -t /usr/share/sonic/templates/isolate.j2 >/usr/sbin/bgp-isolate
chown root:root /usr/sbin/bgp-isolate chown root:root /usr/sbin/bgp-isolate
chmod 0755 /usr/sbin/bgp-isolate chmod 0755 /usr/sbin/bgp-isolate
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/unisolate.j2 >/usr/sbin/bgp-unisolate sonic-cfggen -d -t /usr/share/sonic/templates/unisolate.j2 >/usr/sbin/bgp-unisolate
chown root:root /usr/sbin/bgp-unisolate chown root:root /usr/sbin/bgp-unisolate
chmod 0755 /usr/sbin/bgp-unisolate chmod 0755 /usr/sbin/bgp-unisolate

View File

@ -1,26 +1,26 @@
! !
{% block banner %} {% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/zebra.conf.j2 using minigraph_facts.py ! generated by templates/quagga/zebra.conf.j2 using config DB data
! file: zebra.conf ! file: zebra.conf
! !
{% endblock banner %} {% endblock banner %}
! !
{% block sys_init %} {% block sys_init %}
hostname {{ inventory_hostname }} hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
password zebra password zebra
enable password zebra enable password zebra
{% endblock sys_init %} {% endblock sys_init %}
! !
{% block interfaces %} {% block interfaces %}
! Enable link-detect (default disabled) ! Enable link-detect (default disabled)
{% for interface in minigraph_interfaces %} {% for (name, prefix) in INTERFACE %}
interface {{ interface['attachto'] }} interface {{ name }}
link-detect link-detect
! !
{% endfor %} {% endfor %}
{% for interface in minigraph_portchannels.keys() %} {% for pc in PORTCHANNEL %}
interface {{ interface }} interface {{ pc }}
link-detect link-detect
! !
{% endfor %} {% endfor %}
@ -28,26 +28,34 @@ link-detect
! !
{% block default_route %} {% block default_route %}
! set static default route to mgmt gateway as a backup to learned default ! set static default route to mgmt gateway as a backup to learned default
ip route 0.0.0.0/0 {{ minigraph_mgmt_interface['gwaddr'] }} 200 {% for (name, prefix) in MGMT_INTERFACE %}
{% if prefix | ipv4 %}
ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% endif %}
{% endfor %}
{% endblock default_route %} {% endblock default_route %}
! !
{% block source_loopback %} {% block source_loopback %}
! Set ip source to loopback for bgp learned routes {% set lo_ipv4_addrs = [] %}
route-map RM_SET_SRC permit 10
set src {{ minigraph_lo_interfaces[0]['addr'] }}
!
{% set lo_ipv6_addrs = [] %} {% set lo_ipv6_addrs = [] %}
{% if minigraph_lo_interfaces is defined %} {% if LOOPBACK_INTERFACE %}
{% for interface in minigraph_lo_interfaces %} {% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if interface['addr'] is defined and interface['addr']|ipv6 %} {% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(interface['addr']) %} {% if lo_ipv6_addrs.append(prefix) %}
{% endif %}
{% else %}
{% if lo_ipv4_addrs.append(prefix) %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src {{ lo_ipv4_addrs[0] | ip }}
!
{% if lo_ipv6_addrs|length > 0 %} {% if lo_ipv6_addrs|length > 0 %}
route-map RM_SET_SRC6 permit 10 route-map RM_SET_SRC6 permit 10
set src {{ lo_ipv6_addrs[0] }} set src {{ lo_ipv6_addrs[0] | ip }}
! !
{% endif %} {% endif %}
ip protocol bgp route-map RM_SET_SRC ip protocol bgp route-map RM_SET_SRC

View File

@ -1,6 +1,6 @@
[global.config] [global.config]
as = {{ DEVICE_METADATA['localhost']['bgp_asn'] }} as = {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
router-id = "{{ minigraph_lo_interfaces[0]['addr'] }}" router-id = "{{ LOOPBACK_INTERFACE.keys()[0][1] }}"
{% for neighbor_addr, bgp_session in BGP_NEIGHBOR.iteritems() %} {% for neighbor_addr, bgp_session in BGP_NEIGHBOR.iteritems() %}
{% if bgp_session['asn'] != 0 %} {% if bgp_session['asn'] != 0 %}
[[neighbors]] [[neighbors]]

View File

@ -1,14 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
mkdir -p /etc/quagga mkdir -p /etc/quagga
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/gobgpd.conf.j2 > /etc/gobgp/gobgpd.conf sonic-cfggen -d -t /usr/share/sonic/templates/gobgpd.conf.j2 > /etc/gobgp/gobgpd.conf
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/zebra.conf.j2 > /etc/quagga/zebra.conf sonic-cfggen -d -t /usr/share/sonic/templates/zebra.conf.j2 > /etc/quagga/zebra.conf
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/isolate.j2 > /usr/sbin/bgp-isolate sonic-cfggen -d -t /usr/share/sonic/templates/isolate.j2 > /usr/sbin/bgp-isolate
chown root:root /usr/sbin/bgp-isolate chown root:root /usr/sbin/bgp-isolate
chmod 0755 /usr/sbin/bgp-isolate chmod 0755 /usr/sbin/bgp-isolate
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/unisolate.j2 > /usr/sbin/bgp-unisolate sonic-cfggen -d -t /usr/share/sonic/templates/unisolate.j2 > /usr/sbin/bgp-unisolate
chown root:root /usr/sbin/bgp-unisolate chown root:root /usr/sbin/bgp-unisolate
chmod 0755 /usr/sbin/bgp-unisolate chmod 0755 /usr/sbin/bgp-unisolate

View File

@ -1,26 +1,26 @@
! !
{% block banner %} {% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/zebra.conf.j2 using minigraph_facts.py ! generated by templates/quagga/zebra.conf.j2 using config DB data
! file: zebra.conf ! file: zebra.conf
! !
{% endblock banner %} {% endblock banner %}
! !
{% block sys_init %} {% block sys_init %}
hostname {{ inventory_hostname }} hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
password zebra password zebra
enable password zebra enable password zebra
{% endblock sys_init %} {% endblock sys_init %}
! !
{% block interfaces %} {% block interfaces %}
! Enable link-detect (default disabled) ! Enable link-detect (default disabled)
{% for interface in minigraph_interfaces %} {% for (name, prefix) in INTERFACE %}
interface {{ interface['attachto'] }} interface {{ name }}
link-detect link-detect
! !
{% endfor %} {% endfor %}
{% for interface in minigraph_portchannels.keys() %} {% for pc in PORTCHANNEL %}
interface {{ interface }} interface {{ pc }}
link-detect link-detect
! !
{% endfor %} {% endfor %}
@ -28,26 +28,34 @@ link-detect
! !
{% block default_route %} {% block default_route %}
! set static default route to mgmt gateway as a backup to learned default ! set static default route to mgmt gateway as a backup to learned default
ip route 0.0.0.0/0 {{ minigraph_mgmt_interface['gwaddr'] }} 200 {% for (name, prefix) in MGMT_INTERFACE %}
{% if prefix | ipv4 %}
ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% endif %}
{% endfor %}
{% endblock default_route %} {% endblock default_route %}
! !
{% block source_loopback %} {% block source_loopback %}
! Set ip source to loopback for bgp learned routes {% set lo_ipv4_addrs = [] %}
route-map RM_SET_SRC permit 10
set src {{ minigraph_lo_interfaces[0]['addr'] }}
!
{% set lo_ipv6_addrs = [] %} {% set lo_ipv6_addrs = [] %}
{% if minigraph_lo_interfaces is defined %} {% if LOOPBACK_INTERFACE %}
{% for interface in minigraph_lo_interfaces %} {% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if interface['addr'] is defined and interface['addr']|ipv6 %} {% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(interface['addr']) %} {% if lo_ipv6_addrs.append(prefix) %}
{% endif %}
{% else %}
{% if lo_ipv4_addrs.append(prefix) %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src {{ lo_ipv4_addrs[0] | ip }}
!
{% if lo_ipv6_addrs|length > 0 %} {% if lo_ipv6_addrs|length > 0 %}
route-map RM_SET_SRC6 permit 10 route-map RM_SET_SRC6 permit 10
set src {{ lo_ipv6_addrs[0] }} set src {{ lo_ipv6_addrs[0] | ip }}
! !
{% endif %} {% endif %}
ip protocol bgp route-map RM_SET_SRC ip protocol bgp route-map RM_SET_SRC

View File

@ -1,13 +1,13 @@
! !
{% block banner %} {% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/bgpd.conf.j2 using minigraph_facts.py ! generated by templates/quagga/bgpd.conf.j2 with config DB data
! file: bgpd.conf ! file: bgpd.conf
! !
{% endblock banner %} {% endblock banner %}
! !
{% block system_init %} {% block system_init %}
hostname {{ inventory_hostname }} hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
password zebra password zebra
log syslog informational log syslog informational
log facility local4 log facility local4
@ -28,30 +28,34 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
bgp bestpath as-path multipath-relax bgp bestpath as-path multipath-relax
no bgp default ipv4-unicast no bgp default ipv4-unicast
{# Advertise graceful restart capability for ToR #} {# Advertise graceful restart capability for ToR #}
{% if minigraph_devices[inventory_hostname]['type'] == 'ToRRouter' %} {% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
bgp graceful-restart bgp graceful-restart
{% endif %} {% endif %}
{# TODO: use lo[0] for backward compatibility, will revisit the case with multiple lo interfaces #} {% for (name, prefix) in LOOPBACK_INTERFACE %}
bgp router-id {{ minigraph_lo_interfaces[0]['addr'] }} {# TODO: use v4 lo for backward compatibility, will revisit the case with multiple lo interfaces #}
{% if prefix | ipv4 %}
bgp router-id {{ prefix | ip }}
{% endif %}
{% endfor %}
{# advertise loopback #} {# advertise loopback #}
{% for lo in minigraph_lo_interfaces %} {% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if lo['addr'] | ipv4 %} {% if prefix | ipv4 %}
network {{ lo['addr'] }}/32 network {{ prefix | ip }}/32
{% elif lo['addr'] | ipv6 %} {% elif prefix | ipv6 %}
address-family ipv6 address-family ipv6
network {{ lo['addr'] }}/128 network {{ prefix | ip }}/128
exit-address-family exit-address-family
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endblock bgp_init %} {% endblock bgp_init %}
{% endif %} {% endif %}
{% block vlan_advertisement %} {% block vlan_advertisement %}
{% for vlan_interface in minigraph_vlan_interfaces %} {% for (name, prefix) in VLAN_INTERFACE %}
{% if vlan_interface['addr'] | ipv4 %} {% if prefix | ipv4 %}
network {{ vlan_interface['subnet'] }} network {{ prefix }}
{% elif vlan_interface['addr'] | ipv6 %} {% elif prefix | ipv6 %}
address-family ipv6 address-family ipv6
network {{ vlan_interface['subnet'] }} network {{ prefix }}
exit-address-family exit-address-family
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -66,7 +70,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endif %} {% endif %}
{% if neighbor_addr | ipv4 %} {% if neighbor_addr | ipv4 %}
address-family ipv4 address-family ipv4
{% if minigraph_devices[inventory_hostname]['type'] == 'ToRRouter' %} {% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor {{ neighbor_addr }} allowas-in 1 neighbor {{ neighbor_addr }} allowas-in 1
{% endif %} {% endif %}
neighbor {{ neighbor_addr }} activate neighbor {{ neighbor_addr }} activate
@ -75,7 +79,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endif %} {% endif %}
{% if neighbor_addr | ipv6 %} {% if neighbor_addr | ipv6 %}
address-family ipv6 address-family ipv6
{% if minigraph_devices[inventory_hostname]['type'] == 'ToRRouter' %} {% if DEVICE_METADATA['localhost']['type'] == 'ToRRouter' %}
neighbor {{ neighbor_addr }} allowas-in 1 neighbor {{ neighbor_addr }} allowas-in 1
{% endif %} {% endif %}
neighbor {{ neighbor_addr }} activate neighbor {{ neighbor_addr }} activate
@ -86,6 +90,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% endfor %} {% endfor %}
{% endblock bgp_sessions %} {% endblock bgp_sessions %}
{% block bgp_peers_with_range %} {% block bgp_peers_with_range %}
{% if BGP_PEER_RANGE %}
{% for bgp_peer in BGP_PEER_RANGE.values() %} {% for bgp_peer in BGP_PEER_RANGE.values() %}
neighbor {{ bgp_peer['name'] }} peer-group neighbor {{ bgp_peer['name'] }} peer-group
neighbor {{ bgp_peer['name'] }} passive neighbor {{ bgp_peer['name'] }} passive
@ -107,6 +112,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
maximum-paths 64 maximum-paths 64
exit-address-family exit-address-family
{% endfor %} {% endfor %}
{% endif %}
{% endblock bgp_peers_with_range %} {% endblock bgp_peers_with_range %}
! !
{% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %} {% if DEVICE_METADATA['localhost'].has_key('bgp_asn') %}

View File

@ -1,26 +1,26 @@
! !
{% block banner %} {% block banner %}
! =========== Managed by sonic-cfggen DO NOT edit manually! ==================== ! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
! generated by templates/quagga/zebra.conf.j2 using minigraph_facts.py ! generated by templates/quagga/zebra.conf.j2 using config DB data
! file: zebra.conf ! file: zebra.conf
! !
{% endblock banner %} {% endblock banner %}
! !
{% block sys_init %} {% block sys_init %}
hostname {{ inventory_hostname }} hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
password zebra password zebra
enable password zebra enable password zebra
{% endblock sys_init %} {% endblock sys_init %}
! !
{% block interfaces %} {% block interfaces %}
! Enable link-detect (default disabled) ! Enable link-detect (default disabled)
{% for interface in minigraph_interfaces %} {% for (name, prefix) in INTERFACE %}
interface {{ interface['attachto'] }} interface {{ name }}
link-detect link-detect
! !
{% endfor %} {% endfor %}
{% for interface in minigraph_portchannels.keys() %} {% for pc in PORTCHANNEL %}
interface {{ interface }} interface {{ pc }}
link-detect link-detect
! !
{% endfor %} {% endfor %}
@ -28,26 +28,34 @@ link-detect
! !
{% block default_route %} {% block default_route %}
! set static default route to mgmt gateway as a backup to learned default ! set static default route to mgmt gateway as a backup to learned default
ip route 0.0.0.0/0 {{ minigraph_mgmt_interface['gwaddr'] }} 200 {% for (name, prefix) in MGMT_INTERFACE %}
{% if prefix | ipv4 %}
ip route 0.0.0.0/0 {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} 200
{% endif %}
{% endfor %}
{% endblock default_route %} {% endblock default_route %}
! !
{% block source_loopback %} {% block source_loopback %}
! Set ip source to loopback for bgp learned routes {% set lo_ipv4_addrs = [] %}
route-map RM_SET_SRC permit 10
set src {{ minigraph_lo_interfaces[0]['addr'] }}
!
{% set lo_ipv6_addrs = [] %} {% set lo_ipv6_addrs = [] %}
{% if minigraph_lo_interfaces is defined %} {% if LOOPBACK_INTERFACE %}
{% for interface in minigraph_lo_interfaces %} {% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if interface['addr'] is defined and interface['addr']|ipv6 %} {% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(interface['addr']) %} {% if lo_ipv6_addrs.append(prefix) %}
{% endif %}
{% else %}
{% if lo_ipv4_addrs.append(prefix) %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src {{ lo_ipv4_addrs[0] | ip }}
!
{% if lo_ipv6_addrs|length > 0 %} {% if lo_ipv6_addrs|length > 0 %}
route-map RM_SET_SRC6 permit 10 route-map RM_SET_SRC6 permit 10
set src {{ lo_ipv6_addrs[0] }} set src {{ lo_ipv6_addrs[0] | ip }}
! !
{% endif %} {% endif %}
ip protocol bgp route-map RM_SET_SRC ip protocol bgp route-map RM_SET_SRC

View File

@ -1,5 +1,3 @@
{% for member in minigraph_ports.keys() %} {% for neighbor in DEVICE_NEIGHBOR %}
{% if member in minigraph_neighbors %} configure ports {{ DEVICE_NEIGHBOR[neighbor]['local_port'] }} lldp portidsubtype local {{ PORT[DEVICE_NEIGHBOR[neighbor]['local_port']]['alias'] }} description {{ neighbor }}:{{ DEVICE_NEIGHBOR[neighbor]['port'] }}
configure ports {{ member }} lldp portidsubtype local {{ minigraph_ports[member]['alias'] }} description {{ minigraph_neighbors[member]['name'] }}:{{ minigraph_neighbors[member]['port'] }}
{% endif %}
{% endfor %} {% endfor %}

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/lldpd.conf.j2 > /etc/lldpd.conf sonic-cfggen -d -t /usr/share/sonic/templates/lldpd.conf.j2 > /etc/lldpd.conf
mkdir -p /var/sonic mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status

View File

@ -4,7 +4,7 @@
# arp_update: Send gratuitous ARP requests to VLAN member neighbors to refresh # arp_update: Send gratuitous ARP requests to VLAN member neighbors to refresh
# the neighbors state. # the neighbors state.
VLAN=`sonic-cfggen -m /etc/sonic/minigraph.xml -v 'minigraph_vlans.keys() | join(" ")'` VLAN=`sonic-cfggen -d -v 'VLAN.keys() | join(" ") if VLAN'`
for vlan in $VLAN; do for vlan in $VLAN; do
# generate a list of arping commands: # generate a list of arping commands:
# arping -q -w 0 -c 1 -i <VLAN interface> <IP 1>; # arping -q -w 0 -c 1 -i <VLAN interface> <IP 1>;

View File

@ -2,8 +2,8 @@
{ {
"TUNNEL_DECAP_TABLE:IPINIP_TUNNEL" : { "TUNNEL_DECAP_TABLE:IPINIP_TUNNEL" : {
"tunnel_type":"IPINIP", "tunnel_type":"IPINIP",
"src_ip":"{{ minigraph_lo_interfaces[0]['addr'] }}", "src_ip":"{{ LOOPBACK_INTERFACE.keys()[0][1] | ip }}",
"dst_ip":"{{ minigraph_lo_interfaces[0]['addr'] }}", "dst_ip":"{{ LOOPBACK_INTERFACE.keys()[0][1] | ip }}",
{% if onie_switch_asic == "mlnx" %} {% if onie_switch_asic == "mlnx" %}
"dscp_mode":"uniform", "dscp_mode":"uniform",
"ecn_mode":"standard", "ecn_mode":"standard",

View File

@ -1,9 +1,10 @@
[ [
{% if erspan_dst %} {% if MIRROR_SESSION %}
{% for session in MIRROR_SESSION %}
{ {
"MIRROR_SESSION_TABLE:everflow": { "MIRROR_SESSION_TABLE:{{session}}": {
"src_ip": "{{ minigraph_lo_interfaces[0]['addr'] }}", "src_ip": "{{ MIRROR_SESSION[session]['src_ip'] }}",
"dst_ip": "{{ erspan_dst[0] }}", "dst_ip": "{{ MIRROR_SESSION[session]['dst_ip'] }}",
{% if onie_switch_asic == "mlnx" %} {% if onie_switch_asic == "mlnx" %}
"gre_type": "0x6558", "gre_type": "0x6558",
"queue": "1", "queue": "1",
@ -15,7 +16,9 @@
"ttl": "255" "ttl": "255"
}, },
"OP": "SET" "OP": "SET"
} }{% if not loop.last %},{% endif %}
{% endfor %}
{% endif %} {% endif %}
] ]

View File

@ -2,7 +2,7 @@
# Export platform information. Required to be able to write # Export platform information. Required to be able to write
# vendor specific code. # vendor specific code.
export platform=`sonic-cfggen -m /etc/sonic/minigraph.xml -v onie_switch_asic` export platform=`sonic-cfggen -v onie_switch_asic`
ASIC=`sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type` ASIC=`sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type`

View File

@ -1,11 +1,15 @@
[ [
{% for interface in ethernet_interfaces %} {% if PORT %}
{% for port in PORT %}
{% if PORT[port].has_key('speed') %}
{ {
"PORT_TABLE:{{ interface['name'] }}": { "PORT_TABLE:{{ port }}": {
"speed": "{{ interface['speed'] }}" "speed": "{{ PORT[port]['speed'] }}"
}, },
"OP": "SET" "OP": "SET"
}{% if not loop.last %},{% endif %} }{% if not loop.last %},{% endif %}
{% endif %}
{% endfor %} {% endfor %}
{% endif %}
] ]

View File

@ -2,11 +2,11 @@
mkdir -p /etc/swss/config.d/ mkdir -p /etc/swss/config.d/
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/mirror.json.j2 > /etc/swss/config.d/mirror.json sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/mirror.json.j2 > /etc/swss/config.d/mirror.json
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json
export platform=`sonic-cfggen -m /etc/sonic/minigraph.xml -v platform` export platform=`sonic-cfggen -v platform`
rm -f /var/run/rsyslogd.pid rm -f /var/run/rsyslogd.pid
@ -34,7 +34,7 @@ supervisorctl start neighsyncd
supervisorctl start swssconfig supervisorctl start swssconfig
# Start arp_update when VLAN exists # Start arp_update when VLAN exists
VLAN=`sonic-cfggen -m /etc/sonic/minigraph.xml -v 'minigraph_vlans.keys() | join(" ")'` VLAN=`sonic-cfggen -d -v 'VLAN.keys() | join(" ") if VLAN'`
if [ "$VLAN" != "" ]; then if [ "$VLAN" != "" ]; then
supervisorctl start arp_update supervisorctl start arp_update
fi fi

View File

@ -36,7 +36,7 @@ function fast_reboot {
# Restore FDB and ARP table ASAP # Restore FDB and ARP table ASAP
fast_reboot fast_reboot
HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -v minigraph_hwsku` HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -d -v DEVICE_METADATA["localhost"]["hwsku"]`
SWSSCONFIG_ARGS="00-copp.config.json ipinip.json mirror.json ports.json " SWSSCONFIG_ARGS="00-copp.config.json ipinip.json mirror.json ports.json "

View File

@ -1,5 +1,5 @@
{ {
{% for member in minigraph_ports.keys() %} {% for member in PORT %}
"{{member}}": "{{minigraph_ports[member]['alias']}}"{% if not loop.last %},{% endif %} "{{member}}": "{{PORT[member]['alias']}}"{% if not loop.last %},{% endif %}
{% endfor %} {% endfor %}
} }

View File

@ -13,18 +13,22 @@
# AGENT BEHAVIOUR # AGENT BEHAVIOUR
# #
{% if minigraph_mgmt_interface.addr | ipv4 %} {% if MGMT_INTERFACE %}
# Listen for connections on localhost, loopback ip and mgmt (eth0) ip # Listen for connections on localhost, loopback ip and mgmt (eth0) ip
agentAddress udp:127.0.0.1:161 agentAddress udp:127.0.0.1:161
agentAddress udp:{{ minigraph_mgmt_interface.addr }}:161 {% for (name, prefix) in MGMT_INTERFACE %}
{% for minigraph_lo_interface in minigraph_lo_interfaces %} {% if prefix | ipv4 %}
agentAddress udp:{{ prefix | ip }}:161
{% endif %}
{% endfor %}
# TODO: only support ipv4 lo addresses, add ipv6 support later # TODO: only support ipv4 lo addresses, add ipv6 support later
{% if minigraph_lo_interface.addr | ipv4 %} {% for (name, prefix) in LOOPBACK_INTERFACE %}
agentAddress udp:{{ minigraph_lo_interface.addr }}:161 {% if prefix | ipv4 %}
agentAddress udp:{{ prefix | ip }}:161
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% else %} {% else %}
# Listen on all addresses as mgmt ip not specified in minigraph # Listen on all addresses as mgmt ip not specified
agentAddress udp:161 agentAddress udp:161
{% endif %} {% endif %}

View File

@ -1,11 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
mkdir -p /etc/ssw mkdir -p /etc/ssw
sonic-cfggen -m /etc/sonic/minigraph.xml -y /etc/sonic/sonic_version.yml -t /usr/share/sonic/templates/sysDescription.j2 > /etc/ssw/sysDescription sonic-cfggen -d -y /etc/sonic/sonic_version.yml -t /usr/share/sonic/templates/sysDescription.j2 > /etc/ssw/sysDescription
mkdir -p /etc/snmp mkdir -p /etc/snmp
sonic-cfggen -m /etc/sonic/minigraph.xml -y /etc/sonic/snmp.yml -t /usr/share/sonic/templates/snmpd.conf.j2 > /etc/snmp/snmpd.conf sonic-cfggen -d -y /etc/sonic/snmp.yml -t /usr/share/sonic/templates/snmpd.conf.j2 > /etc/snmp/snmpd.conf
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/alias_map.j2 > /etc/snmp/alias_map.json sonic-cfggen -d -t /usr/share/sonic/templates/alias_map.j2 > /etc/snmp/alias_map.json
mkdir -p /var/sonic mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status

View File

@ -1 +1 @@
SONiC Software Version: SONiC.{{ build_version }} - HwSku: {{ minigraph_hwsku }} - Distribution: Debian {{ debian_version }} - Kernel: {{ kernel_version }} SONiC Software Version: SONiC.{{ build_version }} - HwSku: {{ DEVICE_METADATA['localhost']['hwsku'] }} - Distribution: Debian {{ debian_version }} - Kernel: {{ kernel_version }}

View File

@ -15,8 +15,8 @@ if [ "$SONIC_ASIC_TYPE" == "mellanox" -o "$SONIC_ASIC_TYPE" == "centec" ]; then
MAC_ADDRESS=$(python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC MAC_ADDRESS=$(python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC
fi fi
for pc in `sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_portchannels.keys() | join(' ')"`; do for pc in `sonic-cfggen -d -v "PORTCHANNEL.keys() | join(' ') if PORTCHANNEL"`; do
sonic-cfggen -m /etc/sonic/minigraph.xml -a '{"pc":"'$pc'","hwaddr":"'$MAC_ADDRESS'"}' -t /usr/share/sonic/templates/teamd.j2 > $TEAMD_CONF_PATH/$pc.conf sonic-cfggen -d -a '{"pc":"'$pc'","hwaddr":"'$MAC_ADDRESS'"}' -t /usr/share/sonic/templates/teamd.j2 > $TEAMD_CONF_PATH/$pc.conf
done done
mkdir -p /var/sonic mkdir -p /var/sonic

View File

@ -5,14 +5,14 @@
"name": "lacp", "name": "lacp",
"active": true, "active": true,
{# Use 75% links upperbound as min-links #} {# Use 75% links upperbound as min-links #}
"min_ports": {{ (minigraph_portchannels[pc]['members'] | length * 0.75) | round(0, 'ceil') | int }}, "min_ports": {{ (PORTCHANNEL[pc]['members'] | length * 0.75) | round(0, 'ceil') | int }},
"tx_hash": ["eth", "ipv4", "ipv6"] "tx_hash": ["eth", "ipv4", "ipv6"]
}, },
"link_watch": { "link_watch": {
"name": "ethtool" "name": "ethtool"
}, },
"ports": { "ports": {
{% for member in minigraph_portchannels[pc]['members'] %} {% for member in PORTCHANNEL[pc]['members'] %}
"{{ member }}": {}{% if not loop.last %},{% endif %} "{{ member }}": {}{% if not loop.last %},{% endif %}
{% endfor %} {% endfor %}

View File

@ -2,7 +2,9 @@
# Obtain our platform and HWSKU as we will mount directories with these names in each docker # Obtain our platform and HWSKU as we will mount directories with these names in each docker
PLATFORM=`sonic-cfggen -v platform` PLATFORM=`sonic-cfggen -v platform`
HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -v minigraph_hwsku` {%- if docker_container_name != "database" %}
HWSKU=`sonic-cfggen -d -v 'DEVICE_METADATA["localhost"]["hwsku"]'`
{%- endif %}
start() { start() {
docker inspect --type container {{docker_container_name}} &>/dev/null docker inspect --type container {{docker_container_name}} &>/dev/null
@ -16,9 +18,19 @@ start() {
{%- endif %} {%- endif %}
-v /var/run/redis:/var/run/redis:rw \ -v /var/run/redis:/var/run/redis:rw \
-v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \ -v /usr/share/sonic/device/$PLATFORM:/usr/share/sonic/platform:ro \
{%- if docker_container_name != "database" %}
-v /usr/share/sonic/device/$PLATFORM/$HWSKU:/usr/share/sonic/hwsku:ro \ -v /usr/share/sonic/device/$PLATFORM/$HWSKU:/usr/share/sonic/hwsku:ro \
{%- endif %}
--name={{docker_container_name}} {{docker_image_name}}:latest --name={{docker_container_name}} {{docker_image_name}}:latest
fi fi
{%- if docker_container_name == "database" %}
while true; do
if [[ "$(docker exec -i database redis-cli ping)" =~ PONG.* ]]; then
break
fi
sleep 1
done
{%- endif %}
} }
attach() { attach() {

View File

@ -5,6 +5,7 @@ Requires=database.service
Requires=opennsl-modules-3.16.0-4-amd64.service Requires=opennsl-modules-3.16.0-4-amd64.service
{% endif %} {% endif %}
After=database.service After=database.service
After=interfaces-config.service
{% if sonic_asic_platform == 'broadcom' %} {% if sonic_asic_platform == 'broadcom' %}
After=opennsl-modules-3.16.0-4-amd64.service After=opennsl-modules-3.16.0-4-amd64.service
{% endif %} {% endif %}

View File

@ -1,6 +1,7 @@
[Unit] [Unit]
Description=Update interfaces configuration Description=Update interfaces configuration
Before=database.service Requires=database.service
After=database.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/interfaces.j2 >/etc/network/interfaces sonic-cfggen -d -t /usr/share/sonic/templates/interfaces.j2 >/etc/network/interfaces
[ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid [ -f /var/run/dhclient.eth0.pid ] && kill `cat /var/run/dhclient.eth0.pid` && rm -f /var/run/dhclient.eth0.pid
service networking restart service networking restart
ifdown lo && ifup lo ifdown lo && ifup lo

View File

@ -10,34 +10,36 @@
auto lo auto lo
iface lo inet loopback iface lo inet loopback
# Use command 'ip addr list dev lo' to check all addresses # Use command 'ip addr list dev lo' to check all addresses
{% for minigraph_lo_interface in minigraph_lo_interfaces %} {% for (name, prefix) in LOOPBACK_INTERFACE %}
iface lo {{ 'inet' if minigraph_lo_interface['addr'] | ipv4 else 'inet6' }} static iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static
address {{ minigraph_lo_interface['addr'] }} address {{ prefix | ip }}
netmask {{ minigraph_lo_interface['mask'] }} netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
# #
{% endfor %} {% endfor %}
{% endblock loopback %} {% endblock loopback %}
{% block mgmt_interface %} {% block mgmt_interface %}
# The management network interface # The management network interface
auto eth0 auto eth0
{% if minigraph_mgmt_interface['addr'] %} {% if MGMT_INTERFACE %}
iface eth0 inet static {% for (name, prefix) in MGMT_INTERFACE %}
address {{ minigraph_mgmt_interface['addr'] }} iface eth0 {{ 'inet' if prefix | ipv4 else 'inet6' }} static
netmask {{ minigraph_mgmt_interface['mask'] }} address {{ prefix | ip }}
netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
########## management network policy routing rules ########## management network policy routing rules
# management port up rules # management port up rules
up ip route add default via {{ minigraph_mgmt_interface['gwaddr'] }} dev eth0 table default up ip route add default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table default
up ip rule add from {{ minigraph_mgmt_interface['addr'] }}/32 table default up ip rule add from {{ prefix | ip }}/32 table default
{% for prefix in forced_mgmt_routes %} {% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %}
up ip rule add to {{ prefix }} table default up ip rule add to {{ route }} table default
{% endfor %} {% endfor %}
# management port down rules # management port down rules
down ip route delete default via {{ minigraph_mgmt_interface['gwaddr'] }} dev eth0 table default down ip route delete default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table default
down ip rule delete from {{ minigraph_mgmt_interface['addr'] }}/32 table default down ip rule delete from {{ prefix | ip }}/32 table default
{% for prefix in forced_mgmt_routes %} {% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %}
down ip rule delete to {{ prefix }} table default down ip rule delete to {{ route }} table default
{% endfor %} {% endfor %}
{# TODO: COPP policy type rules #} {# TODO: COPP policy type rules #}
{% endfor %}
{% else %} {% else %}
iface eth0 inet dhcp iface eth0 inet dhcp
{% endif %} {% endif %}
@ -45,19 +47,18 @@ iface eth0 inet dhcp
{% endblock mgmt_interface %} {% endblock mgmt_interface %}
{% block front_panel_interfaces %} {% block front_panel_interfaces %}
# The switch front panel interfaces # The switch front panel interfaces
{% for interface in minigraph_interfaces %} {% for (name, prefix) in INTERFACE %}
allow-hotplug {{ interface['attachto'] }} allow-hotplug {{ name }}
iface {{ interface['attachto'] }} {{ 'inet' if interface['addr'] | ipv4 else 'inet6' }} static iface {{ name }} {{ 'inet' if prefix | ipv4 else 'inet6' }} static
mtu 9216 mtu 9216
address {{ interface['addr'] }} address {{ prefix | ip }}
netmask {{ interface['mask'] }} netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
# #
{% endfor %} {% endfor %}
{% if minigraph_vlans.keys() | length %} {% if VLAN %}
# "|| true" is added to suppress the error when interface is already a member of VLAN # "|| true" is added to suppress the error when interface is already a member of VLAN
{% endif %} {% for vlan in VLAN.keys()|sort %}
{% for vlan in minigraph_vlans.keys()|sort %} {% for member in VLAN[vlan]['members'] %}
{% for member in minigraph_vlans[vlan]['members'] %}
allow-hotplug {{ member }} allow-hotplug {{ member }}
iface {{ member }} inet manual iface {{ member }} inet manual
pre-up ifconfig {{ member }} up mtu 9216 pre-up ifconfig {{ member }} up mtu 9216
@ -66,12 +67,12 @@ iface {{ member }} inet manual
# #
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
{% if minigraph_portchannels.keys() | length %} {% endif %}
{% if PORTCHANNEL %}
# "|| true" is added to suppress the error when interface is already a member of LAG # "|| true" is added to suppress the error when interface is already a member of LAG
# "ip link show | grep -q master" is added to ensure interface is enslaved # "ip link show | grep -q master" is added to ensure interface is enslaved
{% endif %} {% for pc in PORTCHANNEL.keys()|sort %}
{% for pc in minigraph_portchannels.keys()|sort %} {% for member in PORTCHANNEL[pc]['members'] %}
{% for member in minigraph_portchannels[pc]['members'] %}
allow-hotplug {{ member }} allow-hotplug {{ member }}
iface {{ member }} inet manual iface {{ member }} inet manual
pre-up teamdctl {{ pc }} port add {{ member }} || true pre-up teamdctl {{ pc }} port add {{ member }} || true
@ -80,30 +81,31 @@ iface {{ member }} inet manual
# #
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
{% endif %}
{% endblock front_panel_interfaces %} {% endblock front_panel_interfaces %}
{% if minigraph_vlans.keys() | length %}
{% block vlan_interfaces %} {% block vlan_interfaces %}
{% if VLAN_INTERFACE %}
# Vlan interfaces # Vlan interfaces
{% for vlan_interface in minigraph_vlan_interfaces %} {% for (name, prefix) in VLAN_INTERFACE.keys() | sort %}
auto {{ vlan_interface['attachto'] }} auto {{ name }}
iface {{ vlan_interface['attachto'] }} {{ 'inet' if vlan_interface['addr'] | ipv4 else 'inet6' }} static iface {{ name }} {{ 'inet' if prefix | ipv4 else 'inet6' }} static
bridge_ports none bridge_ports none
address {{ vlan_interface['addr'] }} address {{ prefix | ip }}
netmask {{ vlan_interface['mask'] }} netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
{% endfor %} {% endfor %}
# #
{% endif %}
{% endblock vlan_interfaces %} {% endblock vlan_interfaces %}
{% endif %}
{% if minigraph_portchannels.keys() | length %}
{% block pc_interfaces %} {% block pc_interfaces %}
{% if PORTCHANNEL_INTERFACE %}
# Portchannel interfaces # Portchannel interfaces
{% for pc_interface in minigraph_portchannel_interfaces %} {% for (name, prefix) in PORTCHANNEL_INTERFACE.keys() | sort %}
allow-hotplug {{ pc_interface['attachto'] }} allow-hotplug {{ name }}
iface {{ pc_interface['attachto'] }} {{ 'inet' if pc_interface['addr'] | ipv4 else 'inet6' }} static iface {{ name }} {{ 'inet' if prefix | ipv4 else 'inet6' }} static
mtu 9216 mtu 9216
address {{ pc_interface['addr'] }} address {{ prefix | ip }}
netmask {{ pc_interface['mask'] }} netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
# #
{% endfor %} {% endfor %}
{% endblock pc_interfaces %}
{% endif %} {% endif %}
{% endblock pc_interfaces %}

View File

@ -1,6 +1,8 @@
[Unit] [Unit]
Description=Update NTP configuration Description=Update NTP configuration
Before=ntp.service Before=ntp.service
Requires=database.service
After=database.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -1,3 +1,3 @@
#!/bin/bash #!/bin/bash
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/ntp.conf.j2 >/etc/ntp.conf sonic-cfggen -d -t /usr/share/sonic/templates/ntp.conf.j2 >/etc/ntp.conf

View File

@ -23,13 +23,15 @@ filegen clockstats file clockstats type day enable
# pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will # pool.ntp.org maps to about 1000 low-stratum NTP servers. Your server will
# pick a different set every time it starts up. Please consider joining the # pick a different set every time it starts up. Please consider joining the
# pool: <http://www.pool.ntp.org/join.html> # pool: <http://www.pool.ntp.org/join.html>
{% for ntp_server in ntp_servers %} {% for ntp_server in NTP_SERVER %}
server {{ ntp_server }} iburst server {{ ntp_server }} iburst
{% endfor %} {% endfor %}
#only listen on localhost and eth0 ips (default is to listen on all ip addresses) #only listen on localhost and eth0 ips (default is to listen on all ip addresses)
interface ignore wildcard interface ignore wildcard
interface listen {{ minigraph_mgmt_interface.addr }} {% for (mgmt_intf, mgmt_prefix) in MGMT_INTERFACE %}
interface listen {{ mgmt_prefix | ip }}
{% endfor %}
interface listen 127.0.0.1 interface listen 127.0.0.1
# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for # Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for

View File

@ -1,5 +1,7 @@
[Unit] [Unit]
Description=Update rsyslog configuration Description=Update rsyslog configuration
Requires=database.service
After=database.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog.conf sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog.conf
systemctl restart rsyslog systemctl restart rsyslog

View File

@ -41,7 +41,7 @@ $template SONiCFileFormat,"%timegenerated%.%timegenerated:::date-subseconds% %HO
$ActionFileDefaultTemplate SONiCFileFormat $ActionFileDefaultTemplate SONiCFileFormat
#Set remote syslog server #Set remote syslog server
{% for server in syslog_servers %} {% for server in SYSLOG_SERVER %}
*.* @{{ server }}:514;SONiCFileFormat *.* @{{ server }}:514;SONiCFileFormat
{% endfor %} {% endfor %}

View File

@ -1,8 +1,6 @@
[Unit] [Unit]
Description=download minigraph from graph service Description=download minigraph from graph service
Before=ntp-config.service Before=database.service
Before=rsyslog-config.service
Before=interfaces-config.service
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -91,18 +91,20 @@ def parse_png(png, hname):
if enddevice == hname: if enddevice == hname:
if port_alias_map.has_key(endport): if port_alias_map.has_key(endport):
endport = port_alias_map[endport] endport = port_alias_map[endport]
neighbors[endport] = {'name': startdevice, 'port': startport} neighbors[startdevice] = {'local_port': endport, 'port': startport}
else: else:
if port_alias_map.has_key(startport): if port_alias_map.has_key(startport):
startport = port_alias_map[startport] startport = port_alias_map[startport]
neighbors[startport] = {'name': enddevice, 'port': endport} neighbors[enddevice] = {'local_port': startport, 'port': endport}
if child.tag == str(QName(ns, "Devices")): if child.tag == str(QName(ns, "Devices")):
for device in child.findall(str(QName(ns, "Device"))): for device in child.findall(str(QName(ns, "Device"))):
(lo_prefix, mgmt_prefix, name, hwsku, d_type) = parse_device(device) (lo_prefix, mgmt_prefix, name, hwsku, d_type) = parse_device(device)
lo_addr = None if not lo_prefix else lo_prefix.split('/')[0] device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
mgmt_addr = None if not mgmt_prefix else mgmt_prefix.split('/')[0] if neighbors.has_key(name):
devices[name] = {'lo_addr': lo_addr, 'type': d_type, 'mgmt_addr': mgmt_addr, 'hwsku': hwsku} neighbors[name].update(device_data)
else:
devices[name] = device_data
if child.tag == str(QName(ns, "DeviceInterfaceLinks")): if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
for if_link in child.findall(str(QName(ns, 'DeviceLinkBase'))): for if_link in child.findall(str(QName(ns, 'DeviceLinkBase'))):
@ -131,71 +133,28 @@ def parse_dpg(dpg, hname):
continue continue
ipintfs = child.find(str(QName(ns, "IPInterfaces"))) ipintfs = child.find(str(QName(ns, "IPInterfaces")))
intfs = [] intfs = {}
for ipintf in ipintfs.findall(str(QName(ns, "IPInterface"))): for ipintf in ipintfs.findall(str(QName(ns, "IPInterface"))):
intfalias = ipintf.find(str(QName(ns, "AttachTo"))).text intfalias = ipintf.find(str(QName(ns, "AttachTo"))).text
intfname = port_alias_map.get(intfalias, intfalias) intfname = port_alias_map.get(intfalias, intfalias)
ipprefix = ipintf.find(str(QName(ns, "Prefix"))).text ipprefix = ipintf.find(str(QName(ns, "Prefix"))).text
ipn = ipaddress.IPNetwork(ipprefix) intfs[(intfname, ipprefix)] = {}
ipaddr = ipn.ip
prefix_len = ipn.prefixlen
addr_bits = ipn.max_prefixlen
subnet = ipaddress.IPNetwork(str(ipn.network) + '/' + str(prefix_len))
ipmask = ipn.netmask
intf = {'addr': ipaddr, 'subnet': subnet}
if isinstance(ipn, ipaddress.IPv4Network):
intf['mask'] = ipmask
else:
intf['mask'] = str(prefix_len)
intf.update({'attachto': intfname, 'prefixlen': int(prefix_len)})
# TODO: remove peer_addr after dependency removed
ipaddr_val = int(ipn.ip)
peer_addr_val = None
if int(prefix_len) == addr_bits - 2:
if ipaddr_val & 0x3 == 1:
peer_addr_val = ipaddr_val + 1
else:
peer_addr_val = ipaddr_val - 1
elif int(prefix_len) == addr_bits - 1:
if ipaddr_val & 0x1 == 0:
peer_addr_val = ipaddr_val + 1
else:
peer_addr_val = ipaddr_val - 1
if peer_addr_val is not None:
intf['peer_addr'] = ipaddress.IPAddress(peer_addr_val)
intfs.append(intf)
lointfs = child.find(str(QName(ns, "LoopbackIPInterfaces"))) lointfs = child.find(str(QName(ns, "LoopbackIPInterfaces")))
lo_intfs = [] lo_intfs = {}
for lointf in lointfs.findall(str(QName(ns1, "LoopbackIPInterface"))): for lointf in lointfs.findall(str(QName(ns1, "LoopbackIPInterface"))):
intfname = lointf.find(str(QName(ns, "AttachTo"))).text intfname = lointf.find(str(QName(ns, "AttachTo"))).text
ipprefix = lointf.find(str(QName(ns1, "PrefixStr"))).text ipprefix = lointf.find(str(QName(ns1, "PrefixStr"))).text
ipn = ipaddress.IPNetwork(ipprefix) lo_intfs[(intfname, ipprefix)] = {}
ipaddr = ipn.ip
prefix_len = ipn.prefixlen
ipmask = ipn.netmask
lo_intf = {'name': intfname, 'addr': ipaddr, 'prefixlen': prefix_len}
if isinstance(ipn, ipaddress.IPv4Network):
lo_intf['mask'] = ipmask
else:
lo_intf['mask'] = str(prefix_len)
lo_intfs.append(lo_intf)
mgmtintfs = child.find(str(QName(ns, "ManagementIPInterfaces"))) mgmtintfs = child.find(str(QName(ns, "ManagementIPInterfaces")))
mgmt_intf = None mgmt_intf = {}
for mgmtintf in mgmtintfs.findall(str(QName(ns1, "ManagementIPInterface"))): for mgmtintf in mgmtintfs.findall(str(QName(ns1, "ManagementIPInterface"))):
intfname = mgmtintf.find(str(QName(ns, "AttachTo"))).text
ipprefix = mgmtintf.find(str(QName(ns1, "PrefixStr"))).text ipprefix = mgmtintf.find(str(QName(ns1, "PrefixStr"))).text
mgmtipn = ipaddress.IPNetwork(ipprefix) mgmtipn = ipaddress.IPNetwork(ipprefix)
# Ignore IPv6 management address
if mgmtipn.version == 6:
continue
ipaddr = mgmtipn.ip
prefix_len = str(mgmtipn.prefixlen)
ipmask = mgmtipn.netmask
gwaddr = ipaddress.IPAddress(int(mgmtipn.network) + 1) gwaddr = ipaddress.IPAddress(int(mgmtipn.network) + 1)
mgmt_intf = {'addr': ipaddr, 'prefixlen': prefix_len, 'mask': ipmask, 'gwaddr': gwaddr} mgmt_intf[(intfname, ipprefix)] = {'gwaddr': gwaddr}
pcintfs = child.find(str(QName(ns, "PortChannelInterfaces"))) pcintfs = child.find(str(QName(ns, "PortChannelInterfaces")))
pc_intfs = [] pc_intfs = []
@ -206,7 +165,7 @@ def parse_dpg(dpg, hname):
pcmbr_list = pcintfmbr.split(';') pcmbr_list = pcintfmbr.split(';')
for i, member in enumerate(pcmbr_list): for i, member in enumerate(pcmbr_list):
pcmbr_list[i] = port_alias_map.get(member, member) pcmbr_list[i] = port_alias_map.get(member, member)
pcs[pcintfname] = {'name': pcintfname, 'members': pcmbr_list} pcs[pcintfname] = {'members': pcmbr_list}
vlanintfs = child.find(str(QName(ns, "VlanInterfaces"))) vlanintfs = child.find(str(QName(ns, "VlanInterfaces")))
vlan_intfs = [] vlan_intfs = []
@ -218,7 +177,7 @@ def parse_dpg(dpg, hname):
vmbr_list = vintfmbr.split(';') vmbr_list = vintfmbr.split(';')
for i, member in enumerate(vmbr_list): for i, member in enumerate(vmbr_list):
vmbr_list[i] = port_alias_map.get(member, member) vmbr_list[i] = port_alias_map.get(member, member)
vlan_attributes = {'name': vintfname, 'members': vmbr_list, 'vlanid': vlanid} vlan_attributes = {'members': vmbr_list, 'vlanid': vlanid}
sonic_vlan_name = "Vlan%s" % vlanid sonic_vlan_name = "Vlan%s" % vlanid
vlans[sonic_vlan_name] = vlan_attributes vlans[sonic_vlan_name] = vlan_attributes
@ -243,7 +202,7 @@ def parse_dpg(dpg, hname):
acl_intfs = port_alias_map.values() acl_intfs = port_alias_map.values()
break; break;
if acl_intfs: if acl_intfs:
acls[aclname] = { 'AttachTo': acl_intfs, 'IsMirror': is_mirror } acls[aclname] = { 'policy_desc': aclname, 'ports': acl_intfs, 'type': 'mirror' if is_mirror else 'L3'}
return intfs, lo_intfs, mgmt_intf, vlans, pcs, acls return intfs, lo_intfs, mgmt_intf, vlans, pcs, acls
return None, None, None, None, None, None return None, None, None, None, None, None
@ -326,51 +285,17 @@ def parse_meta(meta, hname):
return syslog_servers, dhcp_servers, ntp_servers, mgmt_routes, erspan_dst, deployment_id return syslog_servers, dhcp_servers, ntp_servers, mgmt_routes, erspan_dst, deployment_id
def parse_deviceinfo(meta, hwsku): def parse_deviceinfo(meta, hwsku):
ethernet_interfaces = [] ethernet_interfaces = {}
for device_info in meta.findall(str(QName(ns, "DeviceInfo"))): for device_info in meta.findall(str(QName(ns, "DeviceInfo"))):
dev_sku = device_info.find(str(QName(ns, "HwSku"))).text dev_sku = device_info.find(str(QName(ns, "HwSku"))).text
if dev_sku == hwsku: if dev_sku == hwsku:
interfaces = device_info.find(str(QName(ns, "EthernetInterfaces"))) interfaces = device_info.find(str(QName(ns, "EthernetInterfaces")))
for interface in interfaces.findall(str(QName(ns1, "EthernetInterface"))): for interface in interfaces.findall(str(QName(ns1, "EthernetInterface"))):
name = interface.find(str(QName(ns, "InterfaceName"))).text alias = interface.find(str(QName(ns, "InterfaceName"))).text
speed = interface.find(str(QName(ns, "Speed"))).text speed = interface.find(str(QName(ns, "Speed"))).text
ethernet_interfaces.append({ 'name':name, 'speed':speed }) ethernet_interfaces[port_alias_map.get(alias, alias)] = speed
return ethernet_interfaces return ethernet_interfaces
def get_console_info(devices, dev, port):
for k, v in devices.items():
if k == dev:
break
else:
return {}
ret_val = v
ret_val.update({
'ts_port': port,
'ts_dev': dev
})
return ret_val
def get_mgmt_info(devices, dev, port):
for k, v in devices.items():
if k == dev:
break
else:
return {}
ret_val = v
ret_val.update({
'mgmt_port': port,
'mgmt_dev': dev
})
return ret_val
def parse_port_config(hwsku, platform=None, port_config_file=None): def parse_port_config(hwsku, platform=None, port_config_file=None):
port_config_candidates = [] port_config_candidates = []
if port_config_file != None: if port_config_file != None:
@ -401,7 +326,7 @@ def parse_port_config(hwsku, platform=None, port_config_file=None):
alias = name alias = name
else: else:
alias = tokens[2].strip() alias = tokens[2].strip()
ports[name] = {'name': name, 'alias': alias} ports[name] = {'alias': alias}
port_alias_map[alias] = name port_alias_map[alias] = name
return ports return ports
@ -424,7 +349,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
neighbors = None neighbors = None
devices = None devices = None
hostname = None hostname = None
ethernet_interfaces = [] port_speeds = {}
syslog_servers = [] syslog_servers = []
dhcp_servers = [] dhcp_servers = []
ntp_servers = [] ntp_servers = []
@ -455,93 +380,91 @@ def parse_xml(filename, platform=None, port_config_file=None):
elif child.tag == str(QName(ns, "MetadataDeclaration")): elif child.tag == str(QName(ns, "MetadataDeclaration")):
(syslog_servers, dhcp_servers, ntp_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname) (syslog_servers, dhcp_servers, ntp_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname)
elif child.tag == str(QName(ns, "DeviceInfos")): elif child.tag == str(QName(ns, "DeviceInfos")):
ethernet_interfaces = parse_deviceinfo(child, hwsku) port_speeds = parse_deviceinfo(child, hwsku)
results = {} results = {}
results['minigraph_hwsku'] = hwsku results['DEVICE_METADATA'] = {'localhost': {
# sorting by lambdas are not easily done without custom filters. 'bgp_asn': bgp_asn,
# TODO: add jinja2 filter to accept a lambda to sort a list of dictionaries by attribute. 'deployment_id': deployment_id,
# TODO: alternatively (preferred), implement class containers for multiple-attribute entries, enabling sort by attr 'hostname': hostname,
'hwsku': hwsku,
'type': devices[hostname]['type']
}}
results['BGP_NEIGHBOR'] = bgp_sessions results['BGP_NEIGHBOR'] = bgp_sessions
results['DEVICE_METADATA'] = {'localhost': { 'bgp_asn': bgp_asn }}
results['BGP_PEER_RANGE'] = bgp_peers_with_range results['BGP_PEER_RANGE'] = bgp_peers_with_range
# TODO: sort does not work properly on all interfaces of varying lengths. Need to sort by integer group(s). if mgmt_routes:
# TODO: differentiate v4 and v6
mgmt_intf.itervalues().next()['forced_mgmt_routes'] = mgmt_routes
results['MGMT_INTERFACE'] = mgmt_intf
results['LOOPBACK_INTERFACE'] = lo_intfs
phyport_intfs = [] phyport_intfs = {}
vlan_intfs = [] vlan_intfs = {}
pc_intfs = [] pc_intfs = {}
for intf in intfs: for intf in intfs:
intfname = intf['attachto'] if intf[0][0:4] == 'Vlan':
if intfname[0:4] == 'Vlan': vlan_intfs[intf] = {}
vlan_intfs.append(intf) elif intf[0][0:11] == 'PortChannel':
elif intfname[0:11] == 'PortChannel': pc_intfs[intf] = {}
pc_intfs.append(intf)
else: else:
phyport_intfs.append(intf) phyport_intfs[intf] = {}
results['minigraph_interfaces'] = sorted(phyport_intfs, key=lambda x: x['attachto']) results['INTERFACE'] = phyport_intfs
results['minigraph_vlan_interfaces'] = sorted(vlan_intfs, key=lambda x: x['attachto']) results['VLAN_INTERFACE'] = vlan_intfs
results['minigraph_portchannel_interfaces'] = sorted(pc_intfs, key=lambda x: x['attachto']) results['PORTCHANNEL_INTERFACE'] = pc_intfs
results['minigraph_ports'] = ports
results['minigraph_vlans'] = vlans for port_name in port_speeds:
results['minigraph_portchannels'] = pcs ports.setdefault(port_name, {})['speed'] = port_speeds[port_name]
results['minigraph_mgmt_interface'] = mgmt_intf results['PORT'] = ports
results['minigraph_lo_interfaces'] = lo_intfs results['PORTCHANNEL'] = pcs
results['minigraph_acls'] = acls results['VLAN'] = vlans
results['minigraph_neighbors'] = neighbors
results['minigraph_devices'] = devices results['DEVICE_NEIGHBOR'] = neighbors
results['minigraph_underlay_neighbors'] = u_neighbors results['SYSLOG_SERVER'] = dict((item, {}) for item in syslog_servers)
results['minigraph_underlay_devices'] = u_devices results['DHCP_SERVER'] = dict((item, {}) for item in dhcp_servers)
results['minigraph_as_xml'] = mini_graph_path results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers)
if devices != None:
results['minigraph_console'] = get_console_info(devices, console_dev, console_port) results['ACL_TABLE'] = acls
results['minigraph_mgmt'] = get_mgmt_info(devices, mgmt_dev, mgmt_port) mirror_sessions = {}
results['minigraph_hostname'] = hostname if erspan_dst:
results['inventory_hostname'] = hostname lo_addr = '0.0.0.0'
results['syslog_servers'] = syslog_servers for lo in lo_intfs:
results['dhcp_servers'] = dhcp_servers lo_network = ipaddress.IPNetwork(lo[1])
results['ntp_servers'] = ntp_servers if lo_network.version == 4:
results['forced_mgmt_routes'] = mgmt_routes lo_addr = str(lo_network.ip)
results['erspan_dst'] = erspan_dst break
results['deployment_id'] = deployment_id count = 0
results['ethernet_interfaces'] = ethernet_interfaces for dst in erspan_dst:
mirror_sessions['everflow{}'.format(count)] = {"dst_ip": dst, "src_ip": lo_addr}
count += 1
results['MIRROR_SESSION'] = mirror_sessions
return results return results
def parse_device_desc_xml(filename): def parse_device_desc_xml(filename):
root = ET.parse(filename).getroot() root = ET.parse(filename).getroot()
(lo_prefix, mgmt_prefix, hostname, hwsku, d_type) = parse_device(root) (lo_prefix, mgmt_prefix, hostname, hwsku, d_type) = parse_device(root)
results = {} results = {}
results['minigraph_hwsku'] = hwsku results['DEVICE_METADATA'] = {'localhost': {
results['minigraph_hostname'] = hostname 'hostname': hostname,
results['inventory_hostname'] = hostname 'hwsku': hwsku,
}}
lo_intfs = [] results['LOOPBACK_INTERFACE'] = {('lo', lo_prefix): {}}
ipn = ipaddress.IPNetwork(lo_prefix)
ipaddr = ipn.ip mgmt_intf = {}
prefix_len = ipn.prefixlen mgmtipn = ipaddress.IPNetwork(mgmt_prefix)
ipmask = ipn.netmask gwaddr = ipaddress.IPAddress(int(mgmtipn.network) + 1)
lo_intf = {'name': None, 'addr': ipaddr, 'prefixlen': prefix_len} results['MGMT_INTERFACE'] = {('eth0', mgmt_prefix): {'gwaddr': gwaddr}}
if isinstance(ipn, ipaddress.IPv4Network):
lo_intf['mask'] = ipmask
else:
lo_intf['mask'] = str(prefix_len)
lo_intfs.append(lo_intf)
results['minigraph_lo_interfaces'] = lo_intfs
mgmt_intf = None
mgmt_ipn = ipaddress.IPNetwork(mgmt_prefix)
ipaddr = mgmt_ipn.ip
prefix_len = str(mgmt_ipn.prefixlen)
ipmask = mgmt_ipn.netmask
gwaddr = ipaddress.IPAddress(int(mgmt_ipn.network) + 1)
mgmt_intf = {'addr': ipaddr, 'prefixlen': prefix_len, 'mask': ipmask, 'gwaddr': gwaddr}
results['minigraph_mgmt_interface'] = mgmt_intf
return results return results
port_alias_map = {} port_alias_map = {}
def print_parse_xml(filename): def print_parse_xml(filename):
results = parse_xml(filename) results = parse_xml(filename)
print(json.dumps(results, indent=3, cls=minigraph_encoder)) print(json.dumps(results, indent=3, cls=minigraph_encoder))

View File

@ -22,6 +22,7 @@ import yaml
import jinja2 import jinja2
import netaddr import netaddr
import json import json
from functools import partial
from minigraph import minigraph_encoder from minigraph import minigraph_encoder
from minigraph import parse_xml from minigraph import parse_xml
from minigraph import parse_device_desc_xml from minigraph import parse_device_desc_xml
@ -32,11 +33,11 @@ from swsssdk import ConfigDBConnector
def is_ipv4(value): def is_ipv4(value):
if not value: if not value:
return False return False
if isinstance(value, netaddr.IPAddress): if isinstance(value, netaddr.IPNetwork):
addr = value addr = value
else: else:
try: try:
addr = netaddr.IPAddress(str(value)) addr = netaddr.IPNetwork(str(value))
except: except:
return False return False
return addr.version == 4 return addr.version == 4
@ -44,15 +45,25 @@ def is_ipv4(value):
def is_ipv6(value): def is_ipv6(value):
if not value: if not value:
return False return False
if isinstance(value, netaddr.IPAddress): if isinstance(value, netaddr.IPNetwork):
addr = value addr = value
else: else:
try: try:
addr = netaddr.IPAddress(str(value)) addr = netaddr.IPNetwork(str(value))
except: except:
return False return False
return addr.version == 6 return addr.version == 6
def prefix_attr(attr, value):
if not value:
return None
else:
try:
prefix = netaddr.IPNetwork(str(value))
except:
return None
return str(getattr(prefix, attr))
def unique_name(l): def unique_name(l):
name_list = [] name_list = []
new_list = [] new_list = []
@ -79,10 +90,31 @@ TODO(taoyl): Current version of config db only supports BGP admin states.
def output_to_db(output_data): def output_to_db(output_data):
db_data = {} db_data = {}
for table_name in output_data: for table_name in output_data:
if table_name == 'BGP_NEIGHBOR' or table_name == 'BGP_PEER_RANGE' or table_name == 'DEVICE_METADATA': if table_name[0].isupper():
db_data[table_name] = output_data[table_name] db_data[table_name] = output_data[table_name]
return db_data return db_data
@staticmethod
def to_serialized(data):
for table in data:
if type(data[table]) is dict:
for key in data[table].keys():
new_key = ConfigDBConnector.serialize_key(key)
if new_key != key:
data[table][new_key] = data[table].pop(key)
return data
@staticmethod
def to_deserialized(data):
for table in data:
if type(data[table]) is dict:
for key in data[table].keys():
new_key = ConfigDBConnector.deserialize_key(key)
if new_key != key:
data[table][new_key] = data[table].pop(key)
return data
def deep_update(dst, src): def deep_update(dst, src):
for key, value in src.iteritems(): for key, value in src.iteritems():
if isinstance(value, dict): if isinstance(value, dict):
@ -138,11 +170,11 @@ def main():
for yaml_file in args.yaml: for yaml_file in args.yaml:
with open(yaml_file, 'r') as stream: with open(yaml_file, 'r') as stream:
additional_data = yaml.load(stream) additional_data = yaml.load(stream)
deep_update(data, additional_data) deep_update(data, FormatConverter.to_deserialized(additional_data))
for json_file in args.json: for json_file in args.json:
with open(json_file, 'r') as stream: with open(json_file, 'r') as stream:
deep_update(data, json.load(stream)) deep_update(data, FormatConverter.to_deserialized(json.load(stream)))
if args.additional_data != None: if args.additional_data != None:
deep_update(data, json.loads(args.additional_data)) deep_update(data, json.loads(args.additional_data))
@ -158,6 +190,8 @@ def main():
env.filters['ipv4'] = is_ipv4 env.filters['ipv4'] = is_ipv4
env.filters['ipv6'] = is_ipv6 env.filters['ipv6'] = is_ipv6
env.filters['unique_name'] = unique_name env.filters['unique_name'] = unique_name
for attr in ['ip', 'network', 'prefixlen', 'netmask']:
env.filters[attr] = partial(prefix_attr, attr)
template = env.get_template(template_file) template = env.get_template(template_file)
print template.render(data) print template.render(data)
@ -174,7 +208,7 @@ def main():
configdb.set_config(FormatConverter.output_to_db(data)) configdb.set_config(FormatConverter.output_to_db(data))
if args.print_data: if args.print_data:
print json.dumps(data, indent=4, cls=minigraph_encoder) print json.dumps(FormatConverter.to_serialized(data), indent=4, cls=minigraph_encoder)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -27,6 +27,16 @@ iface eth0 inet static
# management port down rules # management port down rules
down ip route delete default via 10.0.0.1 dev eth0 table default down ip route delete default via 10.0.0.1 dev eth0 table default
down ip rule delete from 10.0.0.100/32 table default down ip rule delete from 10.0.0.100/32 table default
iface eth0 inet6 static
address 2603:10e2:0:2902::8
netmask 64
########## management network policy routing rules
# management port up rules
up ip route add default via 2603:10e2:0:2902::1 dev eth0 table default
up ip rule add from 2603:10e2:0:2902::8/32 table default
# management port down rules
down ip route delete default via 2603:10e2:0:2902::1 dev eth0 table default
down ip rule delete from 2603:10e2:0:2902::8/32 table default
# #
# The switch front panel interfaces # The switch front panel interfaces
# "|| true" is added to suppress the error when interface is already a member of VLAN # "|| true" is added to suppress the error when interface is already a member of VLAN

View File

@ -1,6 +1,6 @@
[ [
{ {
"MIRROR_SESSION_TABLE:everflow": { "MIRROR_SESSION_TABLE:everflow0": {
"src_ip": "10.1.0.32", "src_ip": "10.1.0.32",
"dst_ip": "2.2.2.2", "dst_ip": "2.2.2.2",
"gre_type": "0x88be", "gre_type": "0x88be",

View File

@ -31,17 +31,17 @@ class TestCfgGen(TestCase):
self.assertEqual(output, '') self.assertEqual(output, '')
def test_device_desc(self): def test_device_desc(self):
argument = '-v minigraph_hwsku -M "' + self.sample_device_desc + '"' argument = '-v "DEVICE_METADATA[\'localhost\'][\'hwsku\']" -M "' + self.sample_device_desc + '"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), 'ACS-MSN2700') self.assertEqual(output.strip(), 'ACS-MSN2700')
def test_device_desc_mgmt_ip(self): def test_device_desc_mgmt_ip(self):
argument = '-v "minigraph_mgmt_interface[\'addr\']" -M "' + self.sample_device_desc + '"' argument = '-v "MGMT_INTERFACE.keys()[0]" -M "' + self.sample_device_desc + '"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), '10.0.1.5') self.assertEqual(output.strip(), "('eth0', '10.0.1.5/28')")
def test_minigraph_sku(self): def test_minigraph_sku(self):
argument = '-v minigraph_hwsku -m "' + self.sample_graph + '"' argument = '-v "DEVICE_METADATA[\'localhost\'][\'hwsku\']" -m "' + self.sample_graph + '"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), 'Force10-Z9100') self.assertEqual(output.strip(), 'Force10-Z9100')
@ -51,7 +51,7 @@ class TestCfgGen(TestCase):
self.assertTrue(len(output.strip()) > 0) self.assertTrue(len(output.strip()) > 0)
def test_jinja_expression(self): def test_jinja_expression(self):
argument = '-m "' + self.sample_graph + '" -v "minigraph_devices[minigraph_hostname][\'type\']"' argument = '-m "' + self.sample_graph + '" -v "DEVICE_METADATA[\'localhost\'][\'type\']"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), 'LeafRouter') self.assertEqual(output.strip(), 'LeafRouter')
@ -71,44 +71,44 @@ class TestCfgGen(TestCase):
self.assertEqual(output.strip(), 'value1\nvalue2') self.assertEqual(output.strip(), 'value1\nvalue2')
def test_minigraph_acl(self): def test_minigraph_acl(self):
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v minigraph_acls' argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v ACL_TABLE'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "{'dataacl': {'IsMirror': False, 'AttachTo': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}") self.assertEqual(output.strip(), "{'dataacl': {'type': 'L3', 'policy_desc': 'dataacl', 'ports': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")
def test_minigraph_interfaces(self): def test_minigraph_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v minigraph_interfaces' argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v \'INTERFACE.keys()\''
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "[{'subnet': IPv4Network('10.0.0.58/31'), 'peer_addr': IPv4Address('10.0.0.59'), 'addr': IPv4Address('10.0.0.58'), 'mask': IPv4Address('255.255.255.254'), 'attachto': 'Ethernet0', 'prefixlen': 31}, {'subnet': IPv6Network('fc00::74/126'), 'peer_addr': IPv6Address('fc00::76'), 'addr': IPv6Address('fc00::75'), 'mask': '126', 'attachto': 'Ethernet0', 'prefixlen': 126}]") self.assertEqual(output.strip(), "[('Ethernet0', '10.0.0.58/31'), ('Ethernet0', 'FC00::75/126')]")
def test_minigraph_vlans(self): def test_minigraph_vlans(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v minigraph_vlans' argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "{'Vlan1000': {'name': 'Vlan1000', 'members': ['Ethernet8'], 'vlanid': '1000'}}") self.assertEqual(output.strip(), "{'Vlan1000': {'members': ['Ethernet8'], 'vlanid': '1000'}}")
def test_minigraph_vlan_interfaces(self): def test_minigraph_vlan_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v minigraph_vlan_interfaces' argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "VLAN_INTERFACE.keys()"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "[{'prefixlen': 27, 'subnet': IPv4Network('192.168.0.0/27'), 'mask': IPv4Address('255.255.255.224'), 'addr': IPv4Address('192.168.0.1'), 'attachto': 'Vlan1000'}]") self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27')]")
def test_minigraph_portchannels(self): def test_minigraph_portchannels(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v minigraph_portchannels' argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v PORTCHANNEL'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "{'PortChannel01': {'name': 'PortChannel01', 'members': ['Ethernet4']}}") self.assertEqual(output.strip(), "{'PortChannel01': {'members': ['Ethernet4']}}")
def test_minigraph_portchannels_more_member(self): def test_minigraph_portchannels_more_member(self):
argument = '-m "' + self.sample_graph_pc_test + '" -p "' + self.port_config + '" -v minigraph_portchannels' argument = '-m "' + self.sample_graph_pc_test + '" -p "' + self.port_config + '" -v PORTCHANNEL'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "{'PortChannel01': {'name': 'PortChannel01', 'members': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}") self.assertEqual(output.strip(), "{'PortChannel01': {'members': ['Ethernet112', 'Ethernet116', 'Ethernet120', 'Ethernet124']}}")
def test_minigraph_portchannel_interfaces(self): def test_minigraph_portchannel_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v minigraph_portchannel_interfaces' argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORTCHANNEL_INTERFACE.keys()"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "[{'subnet': IPv4Network('10.0.0.56/31'), 'peer_addr': IPv4Address('10.0.0.57'), 'addr': IPv4Address('10.0.0.56'), 'mask': IPv4Address('255.255.255.254'), 'attachto': 'PortChannel01', 'prefixlen': 31}, {'subnet': IPv6Network('fc00::70/126'), 'peer_addr': IPv6Address('fc00::72'), 'addr': IPv6Address('fc00::71'), 'mask': '126', 'attachto': 'PortChannel01', 'prefixlen': 126}]") self.assertEqual(output.strip(), "[('PortChannel01', 'FC00::71/126'), ('PortChannel01', '10.0.0.56/31')]")
def test_minigraph_neighbors(self): def test_minigraph_neighbors(self):
argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v minigraph_neighbors' argument = '-m "' + self.sample_graph_t0 + '" -p "' + self.port_config + '" -v "DEVICE_NEIGHBOR[\'ARISTA01T1\']"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "{'Ethernet116': {'name': 'ARISTA02T1', 'port': 'Ethernet1/1'}, 'Ethernet124': {'name': 'ARISTA04T1', 'port': 'Ethernet1/1'}, 'Ethernet112': {'name': 'ARISTA01T1', 'port': 'Ethernet1/1'}, 'Ethernet120': {'name': 'ARISTA03T1', 'port': 'Ethernet1/1'}}") self.assertEqual(output.strip(), "{'mgmt_addr': None, 'hwsku': 'Arista', 'lo_addr': None, 'local_port': 'Ethernet112', 'type': 'LeafRouter', 'port': 'Ethernet1/1'}")
def test_minigraph_peers_with_range(self): def test_minigraph_peers_with_range(self):
argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v BGP_PEER_RANGE.values\(\)' argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v BGP_PEER_RANGE.values\(\)'
@ -116,11 +116,11 @@ class TestCfgGen(TestCase):
self.assertEqual(output.strip(), "[{'name': 'BGPSLBPassive', 'ip_range': ['10.10.10.10/26', '100.100.100.100/26']}]") self.assertEqual(output.strip(), "[{'name': 'BGPSLBPassive', 'ip_range': ['10.10.10.10/26', '100.100.100.100/26']}]")
def test_minigraph_deployment_id(self): def test_minigraph_deployment_id(self):
argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v deployment_id' argument = '-m "' + self.sample_graph_bgp_speaker + '" -p "' + self.port_config + '" -v "DEVICE_METADATA[\'localhost\'][\'deployment_id\']"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "1") self.assertEqual(output.strip(), "1")
def test_minigraph_ethernet_interfaces(self): def test_minigraph_ethernet_interfaces(self):
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v ethernet_interfaces' argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v "PORT[\'Ethernet8\']"'
output = self.run_script(argument) output = self.run_script(argument)
self.assertEqual(output.strip(), "[{'speed': '10000', 'name': 'fortyGigE0/0'}, {'speed': '25000', 'name': 'fortyGigE0/4'}, {'speed': '40000', 'name': 'fortyGigE0/8'}, {'speed': '1000000', 'name': 'fortyGigE0/12'}]") self.assertEqual(output.strip(), "{'alias': 'fortyGigE0/8', 'speed': '40000'}")

View File

@ -40,7 +40,7 @@ class TestJ2Files(TestCase):
self.assertTrue(filecmp.cmp(sample_output, self.output_file)) self.assertTrue(filecmp.cmp(sample_output, self.output_file))
# Test T0 minigraph # Test T0 minigraph
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -v "minigraph_portchannels.keys() | join(\' \')"' argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -v "PORTCHANNEL.keys() | join(\' \') if PORTCHANNEL"'
output = self.run_script(argument) # Mock the output via config.sh in docker-teamd output = self.run_script(argument) # Mock the output via config.sh in docker-teamd
pc_list = output.split() pc_list = output.split()
@ -51,7 +51,7 @@ class TestJ2Files(TestCase):
test_render_teamd(self, pc_name, self.t0_minigraph, sample_output) test_render_teamd(self, pc_name, self.t0_minigraph, sample_output)
# Test port channel test minigraph # Test port channel test minigraph
argument = '-m ' + self.pc_minigraph + ' -p ' + self.t0_port_config + ' -v "minigraph_portchannels.keys() | join(\' \')"' argument = '-m ' + self.pc_minigraph + ' -p ' + self.t0_port_config + ' -v "PORTCHANNEL.keys() | join(\' \') if PORTCHANNEL"'
output = self.run_script(argument) # Mock the output via config.sh in docker-teamd output = self.run_script(argument) # Mock the output via config.sh in docker-teamd
pc_list = output.split() pc_list = output.split()

View File

@ -110,13 +110,14 @@ def generate_rule_json(table_name, rule, max_priority, mirror):
rule_props["TCP_FLAGS"] = '0x{:02x}/0x{:02x}'.format(tcp_flags, tcp_flags) rule_props["TCP_FLAGS"] = '0x{:02x}/0x{:02x}'.format(tcp_flags, tcp_flags)
return rule_data return rule_data
def generate_table_json(aclset, aclname, ports, mirror, max_priority, output_path='.'): def generate_table_json(aclset, aclname, ports, t_type, max_priority, output_path='.'):
table_name = aclname.replace(" ", "_").replace("-", "_") table_name = aclname.replace(" ", "_").replace("-", "_")
#table_name = generate_random_table_name() #table_name = generate_random_table_name()
mirror = (t_type == 'mirror')
table_props = {} table_props = {}
table_props["policy_desc"] = table_name table_props["policy_desc"] = table_name
table_props["type"] = "mirror" if mirror else "L3" table_props["type"] = t_type
table_props["ports"] = ports table_props["ports"] = ports
table_data = [{}] table_data = [{}]
@ -138,7 +139,7 @@ def translate_acl_fixed_port(filename, output_path, port, max_priority):
yang_acl = pybindJSON.load(filename, openconfig_acl, "openconfig_acl") yang_acl = pybindJSON.load(filename, openconfig_acl, "openconfig_acl")
for aclsetname in yang_acl.acl.acl_sets.acl_set: for aclsetname in yang_acl.acl.acl_sets.acl_set:
aclset = yang_acl.acl.acl_sets.acl_set[aclsetname] aclset = yang_acl.acl.acl_sets.acl_set[aclsetname]
generate_table_json(aclset, aclsetname, port, max_priority, output_path) generate_table_json(aclset, aclsetname, port, 'l3', max_priority, output_path)
return return
def translate_acl(filename, output_path, mini_acl, max_priority): def translate_acl(filename, output_path, mini_acl, max_priority):
@ -146,10 +147,10 @@ def translate_acl(filename, output_path, mini_acl, max_priority):
for aclsetname in yang_acl.acl.acl_sets.acl_set: for aclsetname in yang_acl.acl.acl_sets.acl_set:
tablename = aclsetname.replace(" ", "_").replace("-", "_") tablename = aclsetname.replace(" ", "_").replace("-", "_")
if mini_acl.has_key(tablename): if mini_acl.has_key(tablename):
is_mirror = mini_acl[tablename]['IsMirror'] t_type = mini_acl[tablename]['type']
ports = ','.join(mini_acl[tablename]['AttachTo']) ports = ','.join(mini_acl[tablename]['ports'])
aclset = yang_acl.acl.acl_sets.acl_set[aclsetname] aclset = yang_acl.acl.acl_sets.acl_set[aclsetname]
generate_table_json(aclset, aclsetname, ports, is_mirror, max_priority, output_path) generate_table_json(aclset, aclsetname, ports, t_type, max_priority, output_path)
return return
def main(): def main():
@ -166,8 +167,8 @@ def main():
translate_acl_fixed_port(args.input, args.output_path, args.port, args.max_priority) translate_acl_fixed_port(args.input, args.output_path, args.port, args.max_priority)
elif args.minigraph: elif args.minigraph:
mini_data = parse_xml(args.minigraph, port_config_file=args.port_config) mini_data = parse_xml(args.minigraph, port_config_file=args.port_config)
if mini_data['minigraph_acls']: if mini_data['ACL_TABLE']:
translate_acl(args.input, args.output_path, mini_data['minigraph_acls'], args.max_priority) translate_acl(args.input, args.output_path, mini_data['ACL_TABLE'], args.max_priority)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

@ -1 +1 @@
Subproject commit 9b54b80f1783808c5ae2a30e189f24a7404a8c95 Subproject commit 7f8e7c5ad9747af1d8ce5317eb1ece65ed4c0c7a