Skip to content

Commit fe497a9

Browse files
committed
Let bgp docker generate configuration by itself
1 parent 03660d9 commit fe497a9

File tree

9 files changed

+654
-0
lines changed

9 files changed

+654
-0
lines changed

dockers/docker-bgp/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ FROM docker-base
33
COPY deps/quagga_*.deb /deps/
44
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; } && \
55
dpkg_apt /deps/quagga_*.deb && \
6+
apt-get update && \
7+
apt-get -y install -f python-jinja2 python-netaddr python-ipaddr python-lxml && \
68
apt-get clean -y && apt-get autoclean -y && apt-get autoremove -y && \
79
rm -rf /deps
810

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

1114
ENTRYPOINT service rsyslog start \
15+
&& /etc/swss/config.sh \
1216
&& service quagga start \
1317
&& /bin/bash

dockers/docker-bgp/bgpd.conf.j2

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
!
2+
{% block banner %}
3+
! =========== Managed by Ansible DO NOT EDIT! ========================
4+
! generated by templates/quagga/bgpd.conf.j2 using minigraph_facts.py
5+
! file: bgpd.conf
6+
!
7+
{% endblock banner %}
8+
!
9+
{% block system_init %}
10+
hostname {{ inventory_hostname }}
11+
password zebra
12+
log syslog informational
13+
log facility local4
14+
! enable password {# {{ en_passwd }} TODO: param needed #}
15+
{% endblock system_init %}
16+
!
17+
{% block bgp_init %}
18+
!
19+
! bgp multiple-instance
20+
!
21+
router bgp {{ minigraph_bgp_asn }}
22+
bgp log-neighbor-changes
23+
bgp bestpath as-path multipath-relax
24+
{# TODO: use lo[0] for backward compatibility, will revisit the case with multiple lo interfaces #}
25+
bgp router-id {{ minigraph_lo_interfaces[0]['addr'] }}
26+
{# advertise loopback #}
27+
{% for lo in minigraph_lo_interfaces %}
28+
{% if lo['addr'] | ipv4 %}
29+
network {{ lo['addr'] }}/32
30+
{% elif lo['addr'] | ipv6 %}
31+
address-family ipv6
32+
network {{ lo['addr'] }}/128
33+
exit-address-family
34+
{% endif %}
35+
{% endfor %}
36+
{% endblock bgp_init %}
37+
{% block vlan_advertisement %}
38+
{% for interface in minigraph_interfaces %}
39+
{% if interface['name'].startswith('Vlan') %}
40+
network {{ interface['subnet'] }}
41+
{% endif %}
42+
{% endfor %}
43+
{% endblock vlan_advertisement %}
44+
{% block bgp_sessions %}
45+
{% for bgp_session in minigraph_bgp %}
46+
{% if bgp_session['asn'] != 0 %}
47+
neighbor {{ bgp_session['addr'] }} remote-as {{ bgp_session['asn'] }}
48+
neighbor {{ bgp_session['addr'] }} description {{ bgp_session['name'] }}
49+
{% if bgp_session['addr'] | ipv6 %}
50+
address-family ipv6
51+
neighbor {{ bgp_session['addr'] }} activate
52+
maximum-paths 64
53+
exit-address-family
54+
{% endif %}
55+
{% endif %}
56+
{% endfor %}
57+
{% endblock bgp_sessions %}
58+
!
59+
maximum-paths 64
60+
!
61+
route-map ISOLATE permit 10
62+
set as-path prepend {{ minigraph_bgp_asn }}
63+
!

dockers/docker-bgp/config.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
cd /etc/swss
4+
5+
awk '{system("python render_config.py -m /etc/swss/minigraph.xml "$1 ">"$2" && chown "$3" "$2" && chmod "$4" "$2)}' template_list
6+

dockers/docker-bgp/isolate.j2

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
## vtysh only accepts script in stdin, so cannot be directly used in shebang
3+
## Cut the tail of this script and feed vtysh stdin
4+
sed -n -e '9,$p' < "$0" | vtysh "$@"
5+
## Exit with vtysh return code
6+
exit $?
7+
8+
## vtysh script start from next line, which line number MUST eqaul in 'sed' command above
9+
10+
configure terminal
11+
router bgp {{ minigraph_bgp_asn }}
12+
{% for bgp_session in minigraph_bgp %}
13+
neighbor {{ bgp_session['addr'] }} route-map ISOLATE out
14+
{% endfor %}
15+
exit
16+
exit
17+
18+
{% for bgp_session in minigraph_bgp %}
19+
clear ip bgp {{ bgp_session['addr'] }} soft out
20+
{% endfor %}

0 commit comments

Comments
 (0)