Skip to content

Commit bac738f

Browse files
Add bgp container with gobgp (#358)
* Add go-1.7 into docker-slave * Create container docker-fpm-gobgp with gobgpd inside
1 parent adc296b commit bac738f

21 files changed

+382
-0
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM docker-fpm
2+
3+
## Make apt-get non-interactive
4+
ENV DEBIAN_FRONTEND=noninteractive
5+
6+
RUN apt-get update && apt-get install -y supervisor
7+
8+
COPY \
9+
{% for deb in docker_fpm_gobgp_debs.split(' ') -%}
10+
debs/{{ deb }}{{' '}}
11+
{%- endfor -%}
12+
debs/
13+
14+
RUN dpkg -i \
15+
{% for deb in docker_fpm_gobgp_debs.split(' ') -%}
16+
debs/{{ deb }}{{' '}}
17+
{%- endfor %}
18+
19+
## Clean up
20+
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
21+
RUN rm -rf /debs
22+
23+
COPY ["*.j2", "/usr/share/sonic/templates/"]
24+
COPY ["start.sh", "config.sh", "/usr/bin/"]
25+
COPY ["daemons", "/etc/quagga/"]
26+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
27+
28+
ENTRYPOINT /usr/bin/config.sh \
29+
&& /usr/bin/start.sh \
30+
&& /usr/bin/supervisord \
31+
&& /bin/bash

dockers/docker-fpm-gobgp/config.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
mkdir -p /etc/quagga
4+
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/gobgpd.conf.j2 >/etc/gobgp/gobgpd.conf
5+
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/zebra.conf.j2 >/etc/quagga/zebra.conf
6+
7+
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/isolate.j2 >/usr/sbin/bgp-isolate
8+
chown root:root /usr/sbin/bgp-isolate
9+
chmod 0755 /usr/sbin/bgp-isolate
10+
11+
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/unisolate.j2 >/usr/sbin/bgp-unisolate
12+
chown root:root /usr/sbin/bgp-unisolate
13+
chmod 0755 /usr/sbin/bgp-unisolate
14+
15+
mkdir -p /var/sonic
16+
echo "# Config files managed by sonic-config-engine" >/var/sonic/config_status
17+

dockers/docker-fpm-gobgp/daemons

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This file tells the quagga package which daemons to start.
2+
#
3+
# Entries are in the format: <daemon>=(yes|no|priority)
4+
# 0, "no" = disabled
5+
# 1, "yes" = highest priority
6+
# 2 .. 10 = lower priorities
7+
# Read /usr/share/doc/quagga/README.Debian for details.
8+
#
9+
# Sample configurations for these daemons can be found in
10+
# /usr/share/doc/quagga/examples/.
11+
#
12+
# ATTENTION:
13+
#
14+
# When activation a daemon at the first time, a config file, even if it is
15+
# empty, has to be present *and* be owned by the user and group "quagga", else
16+
# the daemon will not be started by /etc/init.d/quagga. The permissions should
17+
# be u=rw,g=r,o=.
18+
# When using "vtysh" such a config file is also needed. It should be owned by
19+
# group "quaggavty" and set to ug=rw,o= though. Check /etc/pam.d/quagga, too.
20+
#
21+
# The watchquagga daemon is always started. Per default in monitoring-only but
22+
# that can be changed via /etc/quagga/debian.conf.
23+
#
24+
zebra=yes
25+
bgpd=no
26+
ospfd=no
27+
ospf6d=no
28+
ripd=no
29+
ripngd=no
30+
isisd=no
31+
babeld=no
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[global.config]
2+
as = {{ minigraph_bgp_asn }}
3+
router-id = "{{ minigraph_lo_interfaces[0]['addr'] }}"
4+
{% for bgp_session in minigraph_bgp %}
5+
{% if bgp_session['asn'] != 0 %}
6+
[[neighbors]]
7+
[neighbors.config]
8+
peer-as = {{ bgp_session['asn'] }}
9+
neighbor-address = "{{ bgp_session['addr'] }}"
10+
[neighbors.graceful-restart.config]
11+
enabled = true
12+
[[neighbors.afi-safis]]
13+
[neighbors.afi-safis.config]
14+
{% if bgp_session['addr'] | ipv6 %}
15+
afi-safi-name = "ipv6-unicast"
16+
{% else %}
17+
afi-safi-name = "ipv4-unicast"
18+
{% endif %}
19+
[neighbors.afi-safis.mp-graceful-restart.config]
20+
enabled = true
21+
{% endif %}
22+
{% endfor %}
23+
[zebra]
24+
[zebra.config]
25+
enabled = true
26+
url = "unix:/var/run/quagga/zserv.api"
27+
redistribute-route-type-list = ["connect"]
28+

dockers/docker-fpm-gobgp/isolate.j2

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

dockers/docker-fpm-gobgp/start.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
service rsyslog start
4+
service quagga start
5+
fpmsyncd &
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[supervisord]
2+
nodaemon=true
3+
4+
[program:gobgpd]
5+
command=/usr/sbin/gobgpd -p -f /etc/gobgp/gobgpd.conf -r
6+
priority=1

dockers/docker-fpm-gobgp/unisolate.j2

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
echo Not implemented yet
4+
exit
5+
6+
## vtysh only accepts script in stdin, so cannot be directly used in shebang
7+
## Cut the tail of this script and feed vtysh stdin
8+
sed -n -e '9,$p' < "$0" | vtysh "$@"
9+
## Exit with vtysh return code
10+
exit $?
11+
12+
## vtysh script start from next line, which line number MUST eqaul in 'sed' command above
13+
14+
configure terminal
15+
router bgp {{ minigraph_bgp_asn }}
16+
{% for bgp_session in minigraph_bgp %}
17+
no neighbor {{ bgp_session['addr'] }} route-map ISOLATE out
18+
{% endfor %}
19+
exit
20+
exit
21+
22+
{% for bgp_session in minigraph_bgp %}
23+
clear ip bgp {{ bgp_session['addr'] }} soft out
24+
{% endfor %}
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
!
2+
{% block banner %}
3+
! =========== Managed by sonic-cfggen DO NOT edit manually! ====================
4+
! generated by templates/quagga/zebra.conf.j2 using minigraph_facts.py
5+
! file: zebra.conf
6+
!
7+
{% endblock banner %}
8+
!
9+
{% block sys_init %}
10+
hostname {{ inventory_hostname }}
11+
password zebra
12+
enable password zebra
13+
{% endblock sys_init %}
14+
!
15+
{% block interfaces %}
16+
! Enable link-detect (default disabled)
17+
{% for interface in minigraph_interfaces %}
18+
interface {{ interface['alias'] }}
19+
link-detect
20+
!
21+
{% endfor %}
22+
{% endblock interfaces %}
23+
!
24+
{% block default_route %}
25+
! set static default route to mgmt gateway as a backup to learned default
26+
ip route 0.0.0.0/0 {{ minigraph_mgmt_interface['gwaddr'] }} 200
27+
{% endblock default_route %}
28+
!
29+
{% block source_loopback %}
30+
! Set ip source to loopback for bgp learned routes
31+
route-map RM_SET_SRC permit 10
32+
set src {{ minigraph_lo_interfaces[0]['addr'] }}
33+
!
34+
{% set lo_ipv6_addrs = [] %}
35+
{% if minigraph_lo_interfaces is defined %}
36+
{% for interface in minigraph_lo_interfaces %}
37+
{% if interface['addr'] is defined and interface['addr']|ipv6 %}
38+
{% if lo_ipv6_addrs.append(interface['addr']) %}
39+
{% endif %}
40+
{% endif %}
41+
{% endfor %}
42+
{% endif %}
43+
{% if lo_ipv6_addrs|length > 0 %}
44+
route-map RM_SET_SRC6 permit 10
45+
set src {{ lo_ipv6_addrs[0] }}
46+
!
47+
{% endif %}
48+
ip protocol bgp route-map RM_SET_SRC
49+
!
50+
{% if lo_ipv6_addrs|length > 0 %}
51+
ipv6 protocol bgp route-map RM_SET_SRC6
52+
!
53+
{% endif %}
54+
{% endblock source_loopback %}
55+
!
56+
{% block logging %}
57+
log syslog informational
58+
log facility local4
59+
{% endblock logging %}
60+
!
61+

rules/docker-fpm-gobgp.mk

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# docker image for fpm-gobgp
2+
3+
DOCKER_FPM_GOBGP = docker-fpm-gobgp.gz
4+
$(DOCKER_FPM_GOBGP)_PATH = $(DOCKERS_PATH)/docker-fpm-gobgp
5+
$(DOCKER_FPM_GOBGP)_DEPENDS += $(GOBGP)
6+
$(DOCKER_FPM_GOBGP)_LOAD_DOCKERS += $(DOCKER_FPM)
7+
SONIC_DOCKER_IMAGES += $(DOCKER_FPM_GOBGP)
8+
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_FPM_GOBGP)
9+
10+
$(DOCKER_FPM_GOBGP)_CONTAINER_NAME = bgp
11+
$(DOCKER_FPM_GOBGP)_RUN_OPT += --net=host --privileged -t
12+
$(DOCKER_FPM_GOBGP)_RUN_OPT += --volumes-from database
13+
$(DOCKER_FPM_GOBGP)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
14+

rules/gobgp.mk

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# gobgp package
2+
3+
GOBGP = gobgp_1.16-01_amd64.deb
4+
$(GOBGP)_SRC_PATH = $(SRC_PATH)/gobgp
5+
SONIC_DPKG_DEBS += $(GOBGP)

sonic-slave/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ RUN echo "deb http://debian-archive.trafficmanager.net/debian/ jessie main contr
66
RUN echo "deb-src http://debian-archive.trafficmanager.net/debian/ jessie main contrib non-free" >> /etc/apt/sources.list
77
RUN echo "deb http://debian-archive.trafficmanager.net/debian-security/ jessie/updates main contrib non-free" >> /etc/apt/sources.list
88
RUN echo "deb-src http://debian-archive.trafficmanager.net/debian-security/ jessie/updates main contrib non-free" >> /etc/apt/sources.list
9+
RUN echo 'deb http://debian-archive.trafficmanager.net/debian jessie-backports main' >> /etc/apt/sources.list
910

1011
## Make apt-get non-interactive
1112
ENV DEBIAN_FRONTEND=noninteractive
@@ -70,6 +71,9 @@ RUN apt-get update && apt-get install -y dkms
7071
# For python3.5 build
7172
RUN apt-get update && apt-get install -y sharutils libncursesw5-dev libbz2-dev liblzma-dev libgdbm-dev tk-dev blt-dev libmpdec-dev libbluetooth-dev locales libsqlite3-dev libgpm2 time net-tools xvfb python-sphinx python3-sphinx
7273

74+
# For gobgp build
75+
RUN apt-get -yt jessie-backports install golang-go
76+
7377
RUN mkdir /var/run/sshd
7478
EXPOSE 22
7579

src/gobgp/Makefile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export GOPATH=/tmp/go
2+
3+
INSTALL := /usr/bin/install
4+
5+
all: gobgp gobgpd
6+
7+
gobgpd:
8+
go get -v github.com/osrg/gobgp/gobgpd
9+
10+
gobgp:
11+
go get -v github.com/osrg/gobgp/gobgp
12+
13+
install:
14+
$(INSTALL) -D ${GOPATH}/bin/gobgp $(DESTDIR)/usr/bin/gobgp
15+
$(INSTALL) -D ${GOPATH}/bin/gobgpd $(DESTDIR)/usr/sbin/gobgpd
16+
$(INSTALL) -D gobgpd.conf.sample $(DESTDIR)/etc/gobgp/gobgpd.conf.sample
17+
18+
deinstall:
19+
rm $(DESTDIR)/usr/bin/gobgp
20+
rm $(DESTDIR)/usr/sbin/gobgpd
21+
22+
clean:
23+
rm -fr ${GOPATH}

src/gobgp/debian/changelog

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
gobgp (1.16-01) UNRELEASED; urgency=low
2+
3+
* Initial release.
4+
5+
-- Pavel Shirshov <[email protected]> Sat, 25 Feb 2017 00:25:19 +0000

src/gobgp/debian/compat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9

src/gobgp/debian/control

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Source: gobgp
2+
Maintainer: Pavel Shirshov <[email protected]>
3+
Build-Depends: debhelper (>= 8.0.0),
4+
dh-systemd
5+
Standards-Version: 3.9.3
6+
Section: net
7+
8+
Package: gobgp
9+
Priority: extra
10+
Architecture: amd64
11+
Depends: ${shlibs:Depends}, ${misc:Depends}
12+
Description: gobgp BGP daemon

src/gobgp/debian/gobgp.dirs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
etc/gobgp

src/gobgp/debian/gobgp.init.d

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
#
3+
### BEGIN INIT INFO
4+
# Provides: gobgp
5+
# Required-Start: $local_fs $network $remote_fs $syslog
6+
# Required-Stop: $local_fs $network $remote_fs $syslog
7+
# Default-Start: 2 3 4 5
8+
# Default-Stop: 0 1 6
9+
# Short-Description: start and stop the gobgpd
10+
# Description: gobgpd is an implementation of bgp daemon in Go
11+
### END INIT INFO
12+
#
13+
14+
PATH=/bin:/usr/bin:/sbin:/usr/sbin
15+
D_PATH=/usr/sbin
16+
C_PATH=/etc/gobgp
17+
18+
. /lib/lsb/init-functions
19+
20+
#########################################################
21+
# Main program #
22+
#########################################################
23+
24+
case "$1" in
25+
start)
26+
if [ -f /etc/gobgp/gobgpd.conf ]
27+
then
28+
/usr/sbin/gobgpd -f /etc/gobgp/gobgpd.conf -r
29+
echo $! > /var/run/gobgpd.pid
30+
else
31+
echo /etc/gobgp/gobgpd.conf not found
32+
fi
33+
;;
34+
35+
stop)
36+
kill -9 $(echo /var/run/gobgpd.pid)
37+
;;
38+
39+
restart|force-reload)
40+
$0 stop $2
41+
sleep 1
42+
$0 start $2
43+
;;
44+
*)
45+
echo "Usage: /etc/init.d/gobgp {start|stop|restart|force-reload}"
46+
exit 1
47+
;;
48+
esac
49+
50+
exit 0

src/gobgp/debian/gobgp.service

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[Unit]
2+
Description=gobgp service
3+
After=network.target
4+
ConditionPathExists=/etc/gobgp/gobgpd.yml
5+
6+
[Service]
7+
EnvironmentFile=-/etc/default/gobgp
8+
ExecStart=/usr/sbin/gobgpd $DAEMON_ARGS
9+
#ExecReload=/bin/kill -HUP $MAINPID
10+
KillMode=process
11+
Restart=on-failure
12+
13+
[Install]
14+
WantedBy=multi-user.target
15+
Alias=gobgpd.service
16+

src/gobgp/debian/rules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/make -f
2+
%:
3+
dh $@ --with systemd

0 commit comments

Comments
 (0)