Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dockers/docker-dhcp-relay/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ RUN rm -rf /debs
COPY ["start.sh", "isc-dhcp-relay.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["isc-dhcp-relay.j2", "/usr/share/sonic/templates/"]
COPY ["wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]

ENTRYPOINT ["/usr/bin/supervisord"]
20 changes: 10 additions & 10 deletions dockers/docker-dhcp-relay/isc-dhcp-relay.j2
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
SERVERS="{{ dhcp_servers | join(' ') }}"
SERVERS="{{ DHCP_SERVER | join(' ') }}"

INTERFACES="
{%- set add_preceding_space = { 'flag': False } %}
{%- for interface in minigraph_interfaces %}
{%- if interface['addr'] | ipv4 %}
{%- for (name, prefix) in INTERFACE %}
{%- if prefix | ipv4 %}
{%- if add_preceding_space.flag %} {% endif %}
{{ interface['attachto'] }}
{{ name }}
{%- set _dummy = add_preceding_space.update({'flag': True}) %}
{%- endif %}
{%- endfor %}
{%- for vlan_interface in minigraph_vlan_interfaces %}
{%- if vlan_interface['addr'] | ipv4 %}
{%- for (name, prefix) in VLAN_INTERFACE %}
{%- if prefix | ipv4 %}
{%- if add_preceding_space.flag %} {% endif %}
{{ vlan_interface['attachto'] }}
{{ name }}
{%- set _dummy = add_preceding_space.update({'flag': True}) %}
{%- endif %}
{%- endfor %}
{%- for pc_interface in minigraph_portchannel_interfaces %}
{%- if pc_interface['addr'] | ipv4 %}
{%- for (name, prefix) in PORTCHANNEL_INTERFACE %}
{%- if prefix | ipv4 %}
{%- if add_preceding_space.flag %} {% endif %}
{{ pc_interface['attachto'] }}
{{ name }}
{%- set _dummy = add_preceding_space.update({'flag': True}) %}
{%- endif %}
{%- endfor %}"
Expand Down
34 changes: 4 additions & 30 deletions dockers/docker-dhcp-relay/start.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
#!/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
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

supervisorctl start rsyslogd

# Wait for all interfaces to come up before starting the DHCP relay

FRONT_PANEL_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
for IFACE in $FRONT_PANEL_IFACES; do
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
sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_intf.sh.j2 > /usr/bin/wait_for_intf.sh
chmod +x /usr/bin/wait_for_intf.sh
/usr/bin/wait_for_intf.sh

# Start the DHCP relay
supervisorctl start isc-dhcp-relay
28 changes: 28 additions & 0 deletions dockers/docker-dhcp-relay/wait_for_intf.sh.j2
Original file line number Diff line number Diff line change
@@ -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 %}

28 changes: 14 additions & 14 deletions dockers/docker-fpm-frr/bgpd.conf.j2
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
!
{% block banner %}
! =========== 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
!
{% endblock banner %}
!
{% block system_init %}
hostname {{ inventory_hostname }}
hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
password zebra
log syslog informational
log facility local4
Expand All @@ -23,25 +23,25 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
bgp bestpath as-path multipath-relax
no bgp default ipv4-unicast
{# 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 #}
{% for lo in minigraph_lo_interfaces %}
{% if lo['addr'] | ipv4 %}
network {{ lo['addr'] }}/32
{% elif lo['addr'] | ipv6 %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if prefix | ipv4 %}
network {{ prefix | ip }}/32
{% elif prefix | ipv6 %}
address-family ipv6
network {{ lo['addr'] }}/128
network {{ prefix | ip }}/128
exit-address-family
{% endif %}
{% endfor %}
{% endblock bgp_init %}
{% block vlan_advertisement %}
{% for vlan_interface in minigraph_vlan_interfaces %}
{% if vlan_interface['addr'] | ipv4 %}
network {{ vlan_interface['subnet'] }}
{% elif vlan_interface['addr'] | ipv6 %}
{% for (name, prefix) in VLAN_INTERFACE %}
{% if prefix | ipv4 %}
network {{ prefix }}
{% elif prefix | ipv6 %}
address-family ipv6
network {{ vlan_interface['subnet'] }}
network {{ prefix }}
exit-address-family
{% endif %}
{% endfor %}
Expand All @@ -51,7 +51,7 @@ router bgp {{ DEVICE_METADATA['localhost']['bgp_asn'] }}
{% if bgp_session['asn'] != 0 %}
neighbor {{ neighbor_addr }} remote-as {{ bgp_session['asn'] }}
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
{% endif %}
{% if neighbor_addr | ipv4 %}
Expand Down
8 changes: 4 additions & 4 deletions dockers/docker-fpm-frr/config.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

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 -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/bgpd.conf.j2 >/etc/frr/bgpd.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
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
chmod 0755 /usr/sbin/bgp-unisolate

Expand Down
40 changes: 24 additions & 16 deletions dockers/docker-fpm-frr/zebra.conf.j2
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
!
{% block banner %}
! =========== 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
!
{% endblock banner %}
!
{% block sys_init %}
hostname {{ inventory_hostname }}
hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
password zebra
enable password zebra
{% endblock sys_init %}
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for interface in minigraph_interfaces %}
interface {{ interface['attachto'] }}
{% for (name, prefix) in INTERFACE %}
interface {{ name }}
link-detect
!
{% endfor %}
{% for interface in minigraph_portchannels.keys() %}
interface {{ interface }}
{% for pc in PORTCHANNEL %}
interface {{ pc }}
link-detect
!
{% endfor %}
{% endblock interfaces %}
!
{% block default_route %}
! 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 %}
!
{% block source_loopback %}
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src {{ minigraph_lo_interfaces[0]['addr'] }}
!
{% set lo_ipv4_addrs = [] %}
{% set lo_ipv6_addrs = [] %}
{% if minigraph_lo_interfaces is defined %}
{% for interface in minigraph_lo_interfaces %}
{% if interface['addr'] is defined and interface['addr']|ipv6 %}
{% if lo_ipv6_addrs.append(interface['addr']) %}
{% if LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(prefix) %}
{% endif %}
{% else %}
{% if lo_ipv4_addrs.append(prefix) %}
{% endif %}
{% endif %}
{% endfor %}
{% 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 %}
route-map RM_SET_SRC6 permit 10
set src {{ lo_ipv6_addrs[0] }}
set src {{ lo_ipv6_addrs[0] | ip }}
!
{% endif %}
ip protocol bgp route-map RM_SET_SRC
Expand Down
2 changes: 1 addition & 1 deletion dockers/docker-fpm-gobgp/gobgpd.conf.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[global.config]
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() %}
{% if bgp_session['asn'] != 0 %}
[[neighbors]]
Expand Down
8 changes: 4 additions & 4 deletions dockers/docker-fpm-gobgp/start.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env bash

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 -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/gobgpd.conf.j2 > /etc/gobgp/gobgpd.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
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
chmod 0755 /usr/sbin/bgp-unisolate

Expand Down
40 changes: 24 additions & 16 deletions dockers/docker-fpm-gobgp/zebra.conf.j2
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
!
{% block banner %}
! =========== 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
!
{% endblock banner %}
!
{% block sys_init %}
hostname {{ inventory_hostname }}
hostname {{ DEVICE_METADATA['localhost']['hostname'] }}
password zebra
enable password zebra
{% endblock sys_init %}
!
{% block interfaces %}
! Enable link-detect (default disabled)
{% for interface in minigraph_interfaces %}
interface {{ interface['attachto'] }}
{% for (name, prefix) in INTERFACE %}
interface {{ name }}
link-detect
!
{% endfor %}
{% for interface in minigraph_portchannels.keys() %}
interface {{ interface }}
{% for pc in PORTCHANNEL %}
interface {{ pc }}
link-detect
!
{% endfor %}
{% endblock interfaces %}
!
{% block default_route %}
! 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 %}
!
{% block source_loopback %}
! Set ip source to loopback for bgp learned routes
route-map RM_SET_SRC permit 10
set src {{ minigraph_lo_interfaces[0]['addr'] }}
!
{% set lo_ipv4_addrs = [] %}
{% set lo_ipv6_addrs = [] %}
{% if minigraph_lo_interfaces is defined %}
{% for interface in minigraph_lo_interfaces %}
{% if interface['addr'] is defined and interface['addr']|ipv6 %}
{% if lo_ipv6_addrs.append(interface['addr']) %}
{% if LOOPBACK_INTERFACE %}
{% for (name, prefix) in LOOPBACK_INTERFACE %}
{% if prefix | ipv6 %}
{% if lo_ipv6_addrs.append(prefix) %}
{% endif %}
{% else %}
{% if lo_ipv4_addrs.append(prefix) %}
{% endif %}
{% endif %}
{% endfor %}
{% 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 %}
route-map RM_SET_SRC6 permit 10
set src {{ lo_ipv6_addrs[0] }}
set src {{ lo_ipv6_addrs[0] | ip }}
!
{% endif %}
ip protocol bgp route-map RM_SET_SRC
Expand Down
Loading