Skip to content

Commit

Permalink
Let bgp docker generate configuration by itself
Browse files Browse the repository at this point in the history
  • Loading branch information
taoyl-ms committed Dec 29, 2016
1 parent 03660d9 commit fe497a9
Show file tree
Hide file tree
Showing 9 changed files with 654 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dockers/docker-bgp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ FROM docker-base
COPY deps/quagga_*.deb /deps/
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; } && \
dpkg_apt /deps/quagga_*.deb && \
apt-get update && \
apt-get -y install -f python-jinja2 python-netaddr python-ipaddr python-lxml && \
apt-get clean -y && apt-get autoclean -y && apt-get autoremove -y && \
rm -rf /deps

COPY daemons /etc/quagga/
COPY ["*.j2", "config.sh", "template_list", "*.py", "/etc/swss/"]

ENTRYPOINT service rsyslog start \
&& /etc/swss/config.sh \
&& service quagga start \
&& /bin/bash
63 changes: 63 additions & 0 deletions dockers/docker-bgp/bgpd.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
!
{% block banner %}
! =========== Managed by Ansible DO NOT EDIT! ========================
! generated by templates/quagga/bgpd.conf.j2 using minigraph_facts.py
! file: bgpd.conf
!
{% endblock banner %}
!
{% block system_init %}
hostname {{ inventory_hostname }}
password zebra
log syslog informational
log facility local4
! enable password {# {{ en_passwd }} TODO: param needed #}
{% endblock system_init %}
!
{% block bgp_init %}
!
! bgp multiple-instance
!
router bgp {{ minigraph_bgp_asn }}
bgp log-neighbor-changes
bgp bestpath as-path multipath-relax
{# TODO: use lo[0] for backward compatibility, will revisit the case with multiple lo interfaces #}
bgp router-id {{ minigraph_lo_interfaces[0]['addr'] }}
{# advertise loopback #}
{% for lo in minigraph_lo_interfaces %}
{% if lo['addr'] | ipv4 %}
network {{ lo['addr'] }}/32
{% elif lo['addr'] | ipv6 %}
address-family ipv6
network {{ lo['addr'] }}/128
exit-address-family
{% endif %}
{% endfor %}
{% endblock bgp_init %}
{% block vlan_advertisement %}
{% for interface in minigraph_interfaces %}
{% if interface['name'].startswith('Vlan') %}
network {{ interface['subnet'] }}
{% endif %}
{% endfor %}
{% endblock vlan_advertisement %}
{% block bgp_sessions %}
{% for bgp_session in minigraph_bgp %}
{% if bgp_session['asn'] != 0 %}
neighbor {{ bgp_session['addr'] }} remote-as {{ bgp_session['asn'] }}
neighbor {{ bgp_session['addr'] }} description {{ bgp_session['name'] }}
{% if bgp_session['addr'] | ipv6 %}
address-family ipv6
neighbor {{ bgp_session['addr'] }} activate
maximum-paths 64
exit-address-family
{% endif %}
{% endif %}
{% endfor %}
{% endblock bgp_sessions %}
!
maximum-paths 64
!
route-map ISOLATE permit 10
set as-path prepend {{ minigraph_bgp_asn }}
!
6 changes: 6 additions & 0 deletions dockers/docker-bgp/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd /etc/swss

awk '{system("python render_config.py -m /etc/swss/minigraph.xml "$1 ">"$2" && chown "$3" "$2" && chmod "$4" "$2)}' template_list

20 changes: 20 additions & 0 deletions dockers/docker-bgp/isolate.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
## vtysh only accepts script in stdin, so cannot be directly used in shebang
## Cut the tail of this script and feed vtysh stdin
sed -n -e '9,$p' < "$0" | vtysh "$@"
## Exit with vtysh return code
exit $?

## vtysh script start from next line, which line number MUST eqaul in 'sed' command above

configure terminal
router bgp {{ minigraph_bgp_asn }}
{% for bgp_session in minigraph_bgp %}
neighbor {{ bgp_session['addr'] }} route-map ISOLATE out
{% endfor %}
exit
exit

{% for bgp_session in minigraph_bgp %}
clear ip bgp {{ bgp_session['addr'] }} soft out
{% endfor %}
Loading

0 comments on commit fe497a9

Please sign in to comment.