Skip to content

Commit

Permalink
build p4-based sonic docker (#14)
Browse files Browse the repository at this point in the history
* add docker-sonic for p4 switch

* update build instructions
  • Loading branch information
lguohan committed Sep 28, 2016
1 parent 10e403d commit 7c0ff3e
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@
[submodule "sonic-swss"]
path = src/sonic-swss
url = https://github.com/Azure/sonic-swss
[submodule "src/p4-switch/switch"]
path = src/p4-switch/switch
url = https://github.com/lguohan/switch
[submodule "src/p4-bmv2/behavioral-model"]
path = src/p4-bmv2/behavioral-model
url = https://github.com/lguohan/behavioral-model
[submodule "src/p4c-bm/p4c-bm"]
path = src/p4c-bm/p4c-bm
url = https://github.com/krambn/p4c-bm
[submodule "src/p4-hlir/p4-hlir"]
path = src/p4-hlir/p4-hlir
url = https://github.com/p4lang/p4-hlir
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define build_docker
endef

## Rules: phony targets
.phony : brcm-all mlnx-all cavm-all
.phony : brcm-all mlnx-all cavm-all p4-all

## Rules: redirect to sub directory
src/%:
Expand Down Expand Up @@ -66,7 +66,7 @@ $(addprefix dockers/docker-syncd-mlnx/deps/,syncd_1.0.0_amd64.deb libsairedis_1.
mkdir -p `dirname $@` && cp $< $(dir $@)
dockers/docker-syncd-mlnx/deps/%.deb: src/%.deb
mkdir -p `dirname $@` && cp $< $(dir $@)

## Rules: docker-syncd-cavm
$(addprefix dockers/docker-syncd-cavm/deps/,$(CAVM-SDK-DEBS)) : dockers/docker-syncd-cavm/deps/%.deb : src/cavm-sdk/%.deb
mkdir -p `dirname $@` && cp $< $(dir $@)
Expand All @@ -83,6 +83,12 @@ $(addprefix dockers/docker-syncd/deps/,syncd_1.0.0_amd64.deb libsairedis_1.0.0_a
dockers/docker-syncd/deps/%.deb: src/%.deb
mkdir -p `dirname $@` && cp $< $(dir $@)

## Rules: docker-sonic (p4)
$(addprefix dockers/docker-sonic-p4/deps/,swss_1.0.0_amd64.deb syncd_1.0.0_amd64.deb libsairedis_1.0.0_amd64.deb) : dockers/docker-sonic-p4/deps/%.deb : src/p4/%.deb
mkdir -p `dirname $@` && cp $< $(dir $@)
dockers/docker-sonic-p4/deps/%.deb: src/%.deb
mkdir -p `dirname $@` && cp $< $(dir $@)

## Rules: docker images
target/docker-base.gz:
$(call build_docker,$(patsubst target/%.gz,%,$@),$@)
Expand Down Expand Up @@ -121,13 +127,16 @@ target/docker-database.gz: target/docker-base.gz
docker load < $<
$(call build_docker,$(patsubst target/%.gz,%,$@),$@)

target/docker-sonic-p4.gz: target/docker-base.gz $(addprefix dockers/docker-sonic-p4/deps/,libswsscommon_1.0.0_amd64.deb libhiredis0.13_0.13.3-2_amd64.deb quagga_0.99.24.1-2_amd64.deb syncd_1.0.0_amd64.deb swss_1.0.0_amd64.deb libsairedis_1.0.0_amd64.deb libthrift-0.9.3_0.9.3-2_amd64.deb redis-server_3.0.7-2_amd64.deb redis-tools_3.0.7-2_amd64.deb p4-bmv2_1.0.0_amd64.deb p4-switch_1.0.0_amd64.deb)
docker load < $<
$(call build_docker,$(patsubst target/%.gz,%,$@),$@)

## Rules: linux image content
deps/linux-image-3.16.0-4-amd64_%.deb: src/sonic-linux-kernel/linux-image-3.16.0-4-amd64_%.deb
mkdir -p `dirname $@` && cp $< $(dir $@)
deps/initramfs-tools_%.deb: src/initramfs-tools/initramfs-tools_%.deb
mkdir -p `dirname $@` && cp $< $(dir $@)

## Rules: linux image
target/sonic-generic.bin: deps/linux-image-3.16.0-4-amd64_3.16.7-ckt11-2+acs8u2_amd64.deb deps/initramfs-tools_0.120_all.deb
./build_debian.sh "$(USERNAME)" "$(PASSWORD_ENCRYPTED)" && TARGET_MACHINE=generic ./build_image.sh
target/sonic-aboot.bin: deps/linux-image-3.16.0-4-amd64_3.16.7-ckt11-2+acs8u2_amd64.deb deps/initramfs-tools_0.120_all.deb
Expand All @@ -141,3 +150,5 @@ mlnx-all: target/sonic-generic.bin $(addprefix target/,docker-syncd-mlnx.gz dock

## Note: docker-fpm.gz must be the last to build the implicit dependency fpmsyncd
cavm-all: $(addprefix target/,docker-syncd-cavm.gz docker-orchagent-cavm.gz docker-fpm.gz docker-database.gz)

p4-all: $(addprefix target/,docker-sonic-p4.gz)
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ If it is already cloned, however there is no files under ./dockers/docker-base/
## 2. Build environment
Build a docker image by [the Dockerfile](https://github.com/Azure/sonic-build-tools/blob/master/sonic-slave/Dockerfile) and build all remains in the docker container.

git clone https://github.com/Azure/sonic-build-tools
cd sonic-build-tools
./build.sh sonic-slave
docker run -v /var/run/docker.sock:/var/run/docker.sock -it local/sonic-slave bash

## 3. Get vendor SAI SDK
Obtain Switch Abstraction Interface (SAI) SDK from one of supported vendors (see the list in [Usage](#usage) Section), and place it in the directory ./src/[VENDOR]-sdk/ as filelist.txt in that directory.
Obtain Switch Abstraction Interface (SAI) SDK from one of supported vendors (see the list in [Usage](#usage) Section), and place it in the directory ./src/[VENDOR]-sdk/ as filelist.txt in that directory. Skip this step for p4 since it is an open source software switch.

# Usage
To build NOS installer image and docker images, run command line
Expand All @@ -27,6 +32,8 @@ To build NOS installer image and docker images, run command line
Supported VENDORs are:
- brcm: Broadcom
- mlnx: Mellanox
- cavm: Cavium
- p4: barefoot

For example, the user name is 'admin' and the password is 'YourPaSsWoRd'. To build all the images for Broadcom platform, use the command:

Expand All @@ -43,6 +50,7 @@ The target directory is ./target, containing the NOS installer image and docker
- docker-orchagent.gz: docker image for SWitch State Service (SWSS) (gzip tar archive)
- docker-syncd.gz: docker image for the daemon to sync database and Broadcom switch ASIC (gzip tar archive)
- docker-syncd-mlnx.gz: docker image for the daemon to sync database and Mellanox switch ASIC (gzip tar archive)
- docker-sonic-p4.gz: docker image for all-in-one for p4 software switch (gzip tar archive)

# Contribution guide

Expand Down
32 changes: 32 additions & 0 deletions dockers/docker-sonic-p4/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM docker-base

RUN apt-get update

RUN apt-get install -y net-tools ethtool tcpdump ifupdown

COPY ["deps/libthrift-0.9.3_*.deb", "deps/libhiredis0.13*.deb", "deps/redis-tools_*.deb", "deps/redis-server_*.deb", "deps/libswsscommon_*.deb", "deps/p4-bmv2_*.deb", "deps/p4-switch_*.deb", "deps/libsairedis_*.deb", "deps/syncd_*.deb", "deps/swss_*.deb", "deps/quagga_*.deb", "/deps/"]

RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/libthrift-0.9.3_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/libhiredis0.13*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/redis-tools_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/redis-server_*.deb

RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/libswsscommon_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/p4-bmv2_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/p4-switch_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/libsairedis_*.deb

RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/syncd_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/swss_*.deb
RUN dpkg_apt() { [ -f $1 ] && { dpkg -i $1 || apt-get -y install -f; } || return 1; }; dpkg_apt /deps/quagga_*.deb

ADD port_config.ini /port_config.ini
ADD startup.sh /scripts/startup.sh

ADD rsyslog.conf /etc/rsyslog.conf

## Clean up
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
RUN rm -rf /deps

ENTRYPOINT /bin/bash
5 changes: 5 additions & 0 deletions dockers/docker-sonic-p4/port_config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# alias lanes
Ethernet0 1
Ethernet1 2
Ethernet2 3
Ethernet3 4
68 changes: 68 additions & 0 deletions dockers/docker-sonic-p4/rsyslog.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
###############################################################################
# Managed by Ansible
# file: ansible/roles/acs/templates/rsyslog.conf.j2
###############################################################################
#
# /etc/rsyslog.conf Configuration file for rsyslog.
#
# For more information see
# /usr/share/doc/rsyslog-doc/html/rsyslog_conf.html


#################
#### MODULES ####
#################

$ModLoad imuxsock # provides support for local system logging
#$ModLoad imklog # provides kernel logging support
#$ModLoad immark # provides --MARK-- message capability

# provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514

# provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514


###########################
#### GLOBAL DIRECTIVES ####
###########################
#Set remote syslog server
*.* @172.17.0.1:514

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Define a custom template
$template ACSFileFormat,"%TIMESTAMP% %HOSTNAME% %syslogseverity-text:::uppercase% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
$ActionFileDefaultTemplate ACSFileFormat

#
# Set the default permissions for all log files.
#
$FileOwner root
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022

#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf


###############
#### RULES ####
###############

39 changes: 39 additions & 0 deletions dockers/docker-sonic-p4/startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

echo "Start rsyslog"
service rsyslog start

echo "Start redis server"
service redis-server start

echo "Veth setup"
/usr/share/bmpd/tools/veth_setup.sh > /tmp/veth_setup.log 2>&1

echo "Disable IPv6"
/usr/share/bmpd/tools/veth_disable_ipv6.sh > /tmp/veth_disable.log 2>&1

echo "Start BMV2"
/run_bm.sh > /tmp/run_bm.log 2>&1 &
sleep 15

redis-cli -n 1 set LOGLEVEL DEBUG

echo "Start Syncd"
syncd -N > /tmp/syncd.log 2>&1 &
sleep 10

echo "Start Orchagent"
orchagent $* > /tmp/orchagent.log 2>&1 &
sleep 10

echo "Start Portsyncd"
portsyncd -p /port_config.ini > /tmp/portsyncd.log 2>&1 &

echo "Start Intfsync"
intfsyncd > /tmp/intfsyncd.log 2>&1 &

echo "Start Neighsyncd"
neighsyncd > /tmp/neighsyncd.log 2>&1 &

echo "Start Fpmsyncd"
fpmsyncd > /tmp/fpmsyncd.log 2>&1 &
31 changes: 31 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ redis-server_3.0.7-2_amd64.deb redis-tools_3.0.7-2_amd64.deb redis-sentinel_3.0.
libhiredis0.13_0.13.3-2_amd64.deb libhiredis-dbg_0.13.3-2_amd64.deb libhiredis-dev_0.13.3-2_amd64.deb: redis-server_3.0.7-2_amd64.deb redis-tools_3.0.7-2_amd64.deb redis-sentinel_3.0.7-2_amd64.deb
pushd hiredis; ./build.sh; popd

libthrift-0.9.3_0.9.3-2_amd64.deb libthrift-dev_0.9.3-2_amd64.deb python-thrift_0.9.3-2_amd64.deb thrift-compiler_0.9.3-2_amd64.deb:
pushd thrift; ./build.sh; popd

p4-bmv2_1.0.0_amd64.deb: thrift-compiler_0.9.3-2_amd64.deb python-thrift_0.9.3-2_amd64.deb libthrift-0.9.3_0.9.3-2_amd64.deb libthrift-dev_0.9.3-2_amd64.deb
$(foreach dep, $^, $(call install_deb, $(dep)))
pushd p4-bmv2; ./build.sh; popd

python-p4-hlir_0.9.36-1_all.deb:
pushd p4-hlir; ./build.sh; popd

python-p4c-bm_1.0.0-5415c416-1_all.deb:
pushd p4c-bm; ./build.sh; popd

python-tenjin_1.1.1-1_all.deb:
pushd tenjin; ./build.sh; popd

p4-switch_1.0.0_amd64.deb: thrift-compiler_0.9.3-2_amd64.deb python-thrift_0.9.3-2_amd64.deb libthrift-0.9.3_0.9.3-2_amd64.deb libthrift-dev_0.9.3-2_amd64.deb python-p4-hlir_0.9.36-1_all.deb python-p4c-bm_1.0.0-5415c416-1_all.deb p4-bmv2_1.0.0_amd64.deb
$(foreach dep, $^, $(call install_deb, $(dep)))
pushd p4-switch; ./build.sh; popd

libswsscommon_1.0.0_amd64.deb libswsscommon-dev_1.0.0_amd64.deb: redis-server_3.0.7-2_amd64.deb redis-tools_3.0.7-2_amd64.deb libhiredis0.13_0.13.3-2_amd64.deb libhiredis-dev_0.13.3-2_amd64.deb
$(foreach dep, $^, $(call install_deb, $(dep)))
$(call build_project, sonic-swss-common)
Expand All @@ -53,6 +73,12 @@ cavm/syncd_1.0.0_amd64.deb cavm/libsairedis_1.0.0_amd64.deb cavm/libsairedis-dev
mkdir -p cavm
cp syncd_1.0.0_amd64.deb libsairedis_1.0.0_amd64.deb libsairedis-dev_1.0.0_amd64.deb cavm/

p4/syncd_1.0.0_amd64.deb p4/libsairedis_1.0.0_amd64.deb p4/libsairedis-dev_1.0.0_amd64.deb: libswsscommon_1.0.0_amd64.deb libswsscommon-dev_1.0.0_amd64.deb p4-switch_1.0.0_amd64.deb p4-bmv2_1.0.0_amd64.deb libthrift-0.9.3_0.9.3-2_amd64.deb
$(foreach dep, $^, $(call install_deb, $(dep)))
$(call build_project, sonic-sairedis)
mkdir -p p4
cp syncd_1.0.0_amd64.deb libsairedis_1.0.0_amd64.deb libsairedis-dev_1.0.0_amd64.deb p4/

## Note: fpmsyncd is one implicit target
brcm/swss_1.0.0_amd64.deb brcm/intfsyncd brcm/neighsyncd brcm/orchagent brcm/portsyncd brcm/routeresync brcm/swssconfig: brcm/syncd_1.0.0_amd64.deb brcm/libsairedis_1.0.0_amd64.deb brcm/libsairedis-dev_1.0.0_amd64.deb
$(foreach dep, $^, $(call install_deb, $(dep)))
Expand All @@ -74,6 +100,11 @@ cavm/swss_1.0.0_amd64.deb cavm/intfsyncd cavm/neighsyncd cavm/orchagent cavm/por
cp swss_1.0.0_amd64.deb cavm/
cp sonic-swss/debian/swss/usr/bin/fpmsyncd .

p4/swss_1.0.0_amd64.deb: p4/syncd_1.0.0_amd64.deb p4/libsairedis_1.0.0_amd64.deb p4/libsairedis-dev_1.0.0_amd64.deb
$(foreach dep, $^, $(call install_deb, $(dep)))
$(call build_project, sonic-swss)
cp swss_1.0.0_amd64.deb p4/

$(addprefix sonic-linux-kernel/,linux-headers-3.16.0-4-amd64_3.16.7-ckt11-2+acs8u2_amd64.deb linux-headers-3.16.0-4-common_3.16.7-ckt11-2+acs8u2_amd64.deb linux-image-3.16.0-4-amd64-dbg_3.16.7-ckt11-2+acs8u2_amd64.deb linux-image-3.16.0-4-amd64_3.16.7-ckt11-2+acs8u2_amd64.deb xen-linux-system-3.16.0-4-amd64_3.16.7-ckt11-2+acs8u2_amd64.deb):
pushd sonic-linux-kernel; sudo ./build.sh; popd

Expand Down
1 change: 1 addition & 0 deletions src/p4-bmv2/behavioral-model
Submodule behavioral-model added at 0eb0d5
5 changes: 5 additions & 0 deletions src/p4-bmv2/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash -x

pushd behavioral-model; ./autogen.sh; dpkg-buildpackage -us -uc -b -j4; popd

cp *.deb ../
7 changes: 7 additions & 0 deletions src/p4-hlir/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -x

pushd p4-hlir
python setup.py --command-packages=stdeb.command bdist_deb
popd

cp p4-hlir/deb_dist/*.deb ../
1 change: 1 addition & 0 deletions src/p4-hlir/p4-hlir
Submodule p4-hlir added at 0ab8e5
17 changes: 17 additions & 0 deletions src/p4-switch/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash -x

sudo pip install ctypesgen

sudo pip install crc16

pushd switch

mkdir -p p4-build/bmv2/switch
mkdir -p p4-build/bmv2/pd_thrift_gen

./autogen.sh
dpkg-buildpackage -us -uc -b -j4

popd

cp *.deb ../
1 change: 1 addition & 0 deletions src/p4-switch/switch
Submodule switch added at 8c80a1
7 changes: 7 additions & 0 deletions src/p4c-bm/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash -x

pushd p4c-bm
python setup.py --command-packages=stdeb.command bdist_deb
popd

cp p4c-bm/deb_dist/*.deb ../
1 change: 1 addition & 0 deletions src/p4c-bm/p4c-bm
Submodule p4c-bm added at 5415c4
8 changes: 8 additions & 0 deletions src/tenjin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -x

wget -nc http://pypi.python.org/packages/source/T/Tenjin/Tenjin-1.1.1.tar.gz
tar xzf Tenjin-1.1.1.tar.gz
pushd Tenjin-1.1.1
python setup.py --command-packages=stdeb.command bdist_deb
popd
cp Tenjin-1.1.1/deb_dist/*.deb ../
10 changes: 10 additions & 0 deletions src/thrift/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -x

wget -nc http://http.debian.net/debian/pool/main/t/thrift/thrift_0.9.3.orig.tar.gz
wget -nc http://http.debian.net/debian/pool/main/t/thrift/thrift_0.9.3-2.debian.tar.xz
wget -nc http://http.debian.net/debian/pool/main/t/thrift/thrift_0.9.3-2.dsc
dpkg-source -x thrift_0.9.3-2.dsc
cd thrift-0.9.3
dpkg-buildpackage -d -rfakeroot -b -us -uc
cd ..
cp *.deb ../

0 comments on commit 7c0ff3e

Please sign in to comment.