[sflow]: Build infrastructure changes to support sflow docker and utilities (#3251)

Introduce a new "sflow" container (if ENABLE_SFLOW is set). The new docker will include:
hsflowd : host-sflow based daemon is the sFlow agent
psample : Built from libpsample repository. Useful in debugging sampled packets/groups.
sflowtool : Locally dump sflow samples (e.g. with a in-unit collector)

In case of SONiC-VS, enable psample & act_sample kernel modules.

VS' syncd needs iproute2=4.20.0-2~bpo9+1 & libcap2-bin=1:2.25-1 to support tc-sample

tc-syncd is provided as a convenience tool for debugging (e.g. tc-syncd filter show ...)
This commit is contained in:
padmanarayana 2019-09-14 20:27:09 -07:00 committed by lguohan
parent ac1d2c1023
commit 75104bb35d
28 changed files with 500 additions and 0 deletions

View File

@ -0,0 +1,33 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-config-engine-stretch
ARG docker_container_name
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf
## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -f -y \
dmidecode \
libmnl0=1.0.4-2
{% if docker_sflow_debs.strip() -%}
# Copy locally-built Debian package dependencies
{{ copy_files("debs/", docker_sflow_debs.split(' '), "/debs/") }}
# Install locally-built Debian packages and implicitly install their dependencies
{{ install_debian_packages(docker_sflow_debs.split(' ')) }}
{%- endif %}
RUN apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /debs
RUN sed -ri '/^DAEMON_ARGS=""/c DAEMON_ARGS="-c /var/log/hsflowd.crash"' /etc/init.d/hsflowd
COPY ["start.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
ENTRYPOINT ["/usr/bin/supervisord"]

View File

@ -0,0 +1,10 @@
#!/bin/bash
DOCKER_EXEC_FLAGS="i"
# Determine whether stdout is on a terminal
if [ -t 1 ] ; then
DOCKER_EXEC_FLAGS+="t"
fi
docker exec -$DOCKER_EXEC_FLAGS sflow psample "$@"

View File

@ -0,0 +1,10 @@
#!/bin/bash
DOCKER_EXEC_FLAGS="i"
# Determine whether stdout is on a terminal
if [ -t 1 ] ; then
DOCKER_EXEC_FLAGS+="t"
fi
docker exec -$DOCKER_EXEC_FLAGS sflow sflowtool "$@"

7
dockers/docker-sflow/start.sh Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
rm -f /var/run/rsyslogd.pid
supervisorctl start rsyslogd
supervisorctl start sflowmgrd

View File

@ -0,0 +1,28 @@
[supervisord]
logfile_maxbytes=1MB
logfile_backups=2
nodaemon=true
[program:start.sh]
command=/usr/bin/start.sh
priority=1
autostart=true
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
[program:rsyslogd]
command=/usr/sbin/rsyslogd -n
priority=2
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog
[program:sflowmgrd]
command=/usr/bin/sflowmgrd
priority=3
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog

View File

@ -0,0 +1,14 @@
[Unit]
Description=sFlow container
Requires=swss.service
After=swss.service
Before=ntp-config.service
[Service]
User={{ sonicadmin_user }}
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
[Install]
WantedBy=multi-user.target

View File

@ -300,6 +300,14 @@ sudo cp $IMAGE_CONFIGS/platform/rc.local $FILESYSTEM_ROOT/etc/
## copy blacklist file
sudo cp $IMAGE_CONFIGS/platform/linux_kernel_bde.conf $FILESYSTEM_ROOT/etc/modprobe.d/
# Enable psample drivers to support sFlow on vs
{% if sonic_asic_platform == "vs" %}
sudo tee -a $FILESYSTEM_ROOT/etc/modules-load.d/modules.conf > /dev/null <<EOF
psample
act_sample
EOF
{% endif %}
## Bind docker path
if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then
sudo mkdir -p $FILESYSTEM_ROOT/dockerfs

View File

@ -8,6 +8,8 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install -f -y iproute2=4.20.0-2~bpo9+1 libcap2-bin=1:2.25-1
COPY \
{% for deb in docker_syncd_vs_debs.split(' ') -%}
debs/{{ deb }}{{' '}}

View File

@ -95,3 +95,6 @@ FRR_USER_GID = 300
# Default VS build memory preparation
DEFAULT_VS_PREPARE_MEM = yes
# ENABLE_SYSTEM_SFLOW - build docker-sonic-sflow for sFlow support
ENABLE_SFLOW = y

35
rules/docker-sflow.mk Normal file
View File

@ -0,0 +1,35 @@
# docker image for sFlow agent
DOCKER_SFLOW_STEM = docker-sflow
DOCKER_SFLOW = $(DOCKER_SFLOW_STEM).gz
DOCKER_SFLOW_DBG = $(DOCKER_SFLOW_STEM)-$(DBG_IMAGE_MARK).gz
$(DOCKER_SFLOW)_PATH = $(DOCKERS_PATH)/$(DOCKER_SFLOW_STEM)
$(DOCKER_SFLOW)_DEPENDS += $(SWSS) $(REDIS_TOOLS) $(HSFLOWD) $(SFLOWTOOL) $(PSAMPLE)
$(DOCKER_SFLOW)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS)
$(DOCKER_TEAMD)_DBG_DEPENDS += $(SWSS_DBG) $(LIBSWSSCOMMON_DBG)
$(DOCKER_SFLOW)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_IMAGE_PACKAGES)
$(DOCKER_SFLOW)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_STRETCH)
SONIC_DOCKER_IMAGES += $(DOCKER_SFLOW)
ifeq ($(ENABLE_SFLOW), y)
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_SFLOW)
SONIC_STRETCH_DOCKERS += $(DOCKER_SFLOW)
endif
SONIC_DOCKER_DBG_IMAGES += $(DOCKER_SFLOW_DBG)
ifeq ($(ENABLE_SFLOW), y)
SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_SFLOW_DBG)
SONIC_STRETCH_DBG_DOCKERS += $(DOCKER_SFLOW_DBG)
endif
$(DOCKER_SFLOW)_CONTAINER_NAME = sflow
$(DOCKER_SFLOW)_RUN_OPT += --net=host --privileged -t
$(DOCKER_SFLOW)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
$(DOCKER_SFLOW)_RUN_OPT += -v /host/warmboot:/var/warmboot
$(DOCKER_SFLOW)_BASE_IMAGE_FILES += psample:/usr/bin/psample
$(DOCKER_SFLOW)_BASE_IMAGE_FILES += sflowtool:/usr/bin/sflowtool

49
rules/sflow.mk Normal file
View File

@ -0,0 +1,49 @@
# host-sflow package
HSFLOWD_VERSION = 2.0.21
HSFLOWD_SUBVERSION = 8
export HSFLOWD_VERSION HSFLOWD_SUBVERSION
HSFLOWD = hsflowd_$(HSFLOWD_VERSION)-$(HSFLOWD_SUBVERSION)_$(CONFIGURED_ARCH).deb
$(HSFLOWD)_DEPENDS += $(LIBHIREDIS_DEV) $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON)
$(HSFLOWD)_SRC_PATH = $(SRC_PATH)/sflow/hsflowd
SONIC_MAKE_DEBS += $(HSFLOWD)
SONIC_STRETCH_DEBS += $(HSFLOWD)
HSFLOWD_DBG = hsflowd-dbg_$(HSFLOWD_VERSION)-$(HSFLOWD_SUBVERSION)_$(CONFIGURED_ARCH).deb
$(HSFLOWD_DBG)_DEPENDS += $(HSFLOWD)
$(HSFLOWD_DBG)_RDEPENDS += $(HSFLOWD)
$(eval $(call add_derived_package,$(HSFLOWD),$(HSFLOWD_DBG)))
export HSFLOWD HSFLOWD_DBG
# sflowtool package
SFLOWTOOL_VERSION = 5.04
export SFLOWTOOL_VERSION
SFLOWTOOL = sflowtool_$(SFLOWTOOL_VERSION)_$(CONFIGURED_ARCH).deb
$(SFLOWTOOL)_SRC_PATH = $(SRC_PATH)/sflow/sflowtool
SONIC_MAKE_DEBS += $(SFLOWTOOL)
SONIC_STRETCH_DEBS += $(SFLOWTOOL)
export SFLOWTOOL
# psample package
PSAMPLE_VERSION = 1.1
PSAMPLE_SUBVERSION = 1
export PSAMPLE_VERSION PSAMPLE_SUBVERSION
PSAMPLE = psample_$(PSAMPLE_VERSION)-$(PSAMPLE_SUBVERSION)_$(CONFIGURED_ARCH).deb
$(PSAMPLE)_SRC_PATH = $(SRC_PATH)/sflow/psample
SONIC_MAKE_DEBS += $(PSAMPLE)
SONIC_STRETCH_DEBS += $(PSAMPLE)
export PSAMPLE
# The .c, .cpp, .h & .hpp files under src/{$DBG_SRC_ARCHIVE list}
# are archived into debug one image to facilitate debugging.
#
DBG_SRC_ARCHIVE += sflow

View File

@ -108,6 +108,10 @@ ifeq ($(SONIC_INSTALL_DEBUG_TOOLS),y)
INSTALL_DEBUG_TOOLS = y
endif
ifeq ($(SONIC_ENABLE_SFLOW),y)
ENABLE_SFLOW = y
endif
include $(RULES_PATH)/functions
include $(RULES_PATH)/*.mk
ifneq ($(CONFIGURED_PLATFORM), undefined)
@ -192,6 +196,7 @@ $(info "KERNEL_PROCURE_METHOD" : "$(KERNEL_PROCURE_METHOD)")
$(info "BUILD_TIMESTAMP" : "$(BUILD_TIMESTAMP)")
$(info "BLDENV" : "$(BLDENV)")
$(info "VS_PREPARE_MEM" : "$(VS_PREPARE_MEM)")
$(info "ENABLE_SFLOW" : "$(ENABLE_SFLOW)")
$(info )
ifeq ($(SONIC_USE_DOCKER_BUILDKIT),y)

View File

@ -0,0 +1,29 @@
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e
MAIN_TARGET = $(HSFLOWD)
DERIVED_TARGET = $(HSFLOWD_DBG)
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
rm -fr ./host-sflow
git clone https://github.com/sflow/host-sflow
pushd ./host-sflow
git checkout -b sflow -f 996f5ec
# Apply patch series
stg init
stg import -s ../patch/series
mkdir -p debian
cp -r DEBIAN_build/* debian
chmod u+x debian/rules
sed -i -e s/_VERSION_/$(HSFLOWD_VERSION)-$(HSFLOWD_SUBVERSION)/g debian/changelog
dpkg-buildpackage -rfakeroot -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS) --buildinfo-option=-u. --changes-option=-u.
mv $(DERIVED_TARGET) $* $(DEST)/
popd
$(addprefix $(DEST)/, $(DERIVED_TARGET)): $(DEST)/% : $(DEST)/$(MAIN_TARGET)

View File

@ -0,0 +1,39 @@
diff -ruN a/src/Linux/linux/psample.h b/src/Linux/linux/psample.h
--- a/src/Linux/linux/psample.h 1969-12-31 16:00:00.000000000 -0800
+++ b/src/Linux/linux/psample.h 2019-07-20 08:45:58.715748881 -0700
@@ -0,0 +1,35 @@
+#ifndef __UAPI_PSAMPLE_H
+#define __UAPI_PSAMPLE_H
+
+enum {
+ /* sampled packet metadata */
+ PSAMPLE_ATTR_IIFINDEX,
+ PSAMPLE_ATTR_OIFINDEX,
+ PSAMPLE_ATTR_ORIGSIZE,
+ PSAMPLE_ATTR_SAMPLE_GROUP,
+ PSAMPLE_ATTR_GROUP_SEQ,
+ PSAMPLE_ATTR_SAMPLE_RATE,
+ PSAMPLE_ATTR_DATA,
+
+ /* commands attributes */
+ PSAMPLE_ATTR_GROUP_REFCOUNT,
+
+ __PSAMPLE_ATTR_MAX
+};
+
+enum psample_command {
+ PSAMPLE_CMD_SAMPLE,
+ PSAMPLE_CMD_GET_GROUP,
+ PSAMPLE_CMD_NEW_GROUP,
+ PSAMPLE_CMD_DEL_GROUP,
+};
+
+/* Can be overridden at runtime by module option */
+#define PSAMPLE_ATTR_MAX (__PSAMPLE_ATTR_MAX - 1)
+
+#define PSAMPLE_NL_MCGRP_CONFIG_NAME "config"
+#define PSAMPLE_NL_MCGRP_SAMPLE_NAME "packets"
+#define PSAMPLE_GENL_NAME "psample"
+#define PSAMPLE_GENL_VERSION 1
+
+#endif

View File

@ -0,0 +1,108 @@
diff -ruN a/DEBIAN_build/changelog b/DEBIAN_build/changelog
--- a/DEBIAN_build/changelog 1969-12-31 19:00:00.000000000 -0500
+++ b/DEBIAN_build/changelog 2019-08-19 22:52:10.171736403 -0400
@@ -0,0 +1,6 @@
+hsflowd (_VERSION_) stable; urgency=medium
+
+ [ DellEMC ]
+ * Initial release : hsflowd
+
+ -- DellEMC <support@dell.com> Mon, 29 Jul 2019 07:08:02 -0400
diff -ruN a/DEBIAN_build/compat b/DEBIAN_build/compat
--- a/DEBIAN_build/compat 1969-12-31 19:00:00.000000000 -0500
+++ b/DEBIAN_build/compat 2019-08-16 23:28:58.020938096 -0400
@@ -0,0 +1 @@
+9
diff -ruN a/DEBIAN_build/control b/DEBIAN_build/control
--- a/DEBIAN_build/control 2019-08-16 05:11:33.974949327 -0400
+++ b/DEBIAN_build/control 2019-08-19 21:28:07.155722725 -0400
@@ -1,9 +1,22 @@
-Package: _PACKAGE_
-Version: _VERSION_
-Section: admin
+Source: hsflowd
+Maintainer: Neil McKee [neil.mckee@inmon.com]
+Uploaders: DellEMC <support@dell.com>
+Section: net
+Priority: optional
+Build-Depends: dh-exec (>=0.3), debhelper (>= 9), autotools-dev
+Standards-Version: 1.0.0
+
+Package: hsflowd
+Section: admin
Priority: optional
-Architecture: all
+Architecture: any
Essential: no
-Maintainer: Neil McKee [neil.mckee@inmon.com]
Description: sFlow(R) monitoring agent
Homepage: sflow.net
+
+Package: hsflowd-dbg
+Architecture: any
+Section: debug
+Priority: extra
+Depends: hsflowd
+Description: debugging symbols for hsflowd
diff -ruN a/DEBIAN_build/rules b/DEBIAN_build/rules
--- a/DEBIAN_build/rules 1969-12-31 19:00:00.000000000 -0500
+++ b/DEBIAN_build/rules 2019-08-19 22:20:42.998569601 -0400
@@ -0,0 +1,31 @@
+#!/usr/bin/make -f
+
+# See debhelper(7) (uncomment to enable)
+# output every command that modifies files on the build system.
+export DH_VERBOSE = 1
+
+# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
+DPKG_EXPORT_BUILDFLAGS = 1
+include /usr/share/dpkg/default.mk
+
+%:
+ dh $@
+
+binary:
+ dh_gencontrol
+ dh_strip -phsflowd --dbg-package=hsflowd-dbg
+ dpkg-deb --build debian/hsflowd-dbg hsflowd-dbg_$(HSFLOWD_VERSION)-$(HSFLOWD_SUBVERSION)_$(CONFIGURED_ARCH).deb
+ dpkg-deb --build debian/hsflowd hsflowd_$(HSFLOWD_VERSION)-$(HSFLOWD_SUBVERSION)_$(CONFIGURED_ARCH).deb
+
+override_dh_auto_build:
+ make sonic-deb FEATURES="SONIC"
+
+override_dh_auto_configure:
+
+override_dh_auto_install:
+
+override_dh_auto_test:
+
+override_dh_auto_clean:
+
+override_dh_clean:
diff -ruN a/Makefile b/Makefile
--- a/Makefile 2019-08-16 21:34:25.167679297 -0400
+++ b/Makefile 2019-08-19 22:20:23.758479002 -0400
@@ -146,6 +146,23 @@
cd ..; \
dpkg-deb --build debian hsflowd_$${MYVER}-$${MYREL}_$$MYARCH.deb
+sonic-deb: $(PROG)
+ MYARCH=`uname -m|sed 's/x86_64/amd64/'`; \
+ MYVER=`./getVersion`; \
+ MYREL=`./getRelease`; \
+ PLATFORM=`uname`; \
+ mkdir -p debian/usr/sbin; \
+ mkdir -p debian/etc/init.d; \
+ mkdir -p debian/etc/hsflowd/modules; \
+ mkdir -p debian/lib/systemd/system; \
+ mkdir -p debian/etc/dbus-1/system.d; \
+ cd src/$$PLATFORM; $(MAKE) VERSION=$$MYVER RELEASE=$$MYREL INSTROOT="../../debian/hsflowd" install; cd ../..; \
+ pwd; \
+ cd debian/hsflowd; \
+ find . -type d | xargs chmod 755; \
+ md5sum `find usr etc -type f` > md5sums; \
+ cd ../..;
+
xenserver: xenrpm
cd xenserver-ddk; $(MAKE) clean; $(MAKE)

View File

@ -0,0 +1,2 @@
0001-host_sflow_psample.patch
0002-host_sflow_debian.patch

View File

@ -0,0 +1,20 @@
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e
MAIN_TARGET = $(PSAMPLE)
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
rm -fr ./libpsample
git clone https://github.com/Mellanox/libpsample.git
cp -r debian libpsample
pushd ./libpsample
git checkout -b libpsample -f e48fad2
dpkg-buildpackage -rfakeroot -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS)
popd
mv $* $(DEST)/

View File

@ -0,0 +1,6 @@
psample (1.1-1) UNRELEASED; urgency=medium
[ DellEMC ]
* Initial release : based on https://github.com/Mellanox/libpsample
-- DellEMC <support@dell.com> Mon, 29 Jul 2019 07:08:02 -0400

View File

@ -0,0 +1 @@
9

View File

@ -0,0 +1,11 @@
Source: psample
Maintainer: DellEMC <support@dell.com>
Section: devel
Priority: optional
Build-Depends: dh-exec (>=0.3), debhelper (>= 9), autotools-dev
Standards-Version: 1.0.0
Package: psample
Architecture: any
Depends: ${shlibs:Depends}
Description: This package contains psample from https://github.com/Mellanox/libpsample

View File

@ -0,0 +1,4 @@
bin/psample usr/bin
lib/libpsample.so.1.0 lib/x86_64-linux-gnu
lib/libpsample.so.1 lib/x86_64-linux-gnu
lib/libpsample.so lib/x86_64-linux-gnu

19
src/sflow/psample/debian/rules Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/make -f
# main packaging script based on dh7 syntax
%:
dh $@
override_dh_auto_build:
cmake . && make
override_dh_auto_install:
override_dh_auto_test:
override_dh_auto_clean:
override_dh_strip:
override_dh_clean:

View File

@ -0,0 +1,19 @@
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e
MAIN_TARGET = $(SFLOWTOOL)
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
rm -fr ./sflowtool
git clone https://github.com/sflow/sflowtool
cp -r debian sflowtool
pushd ./sflowtool
git checkout -b sflowtool -f 6c2963b
dpkg-buildpackage -rfakeroot -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS)
popd
mv $* $(DEST)/

View File

@ -0,0 +1,6 @@
sflowtool (5.04) UNRELEASED; urgency=medium
[ DellEMC ]
* Initial release : based on https://github.com/sflow/sflowtool
-- DellEMC <support@dell.com> Mon, 29 Jul 2019 07:08:02 -0400

View File

@ -0,0 +1 @@
9

View File

@ -0,0 +1,11 @@
Source: sflowtool
Maintainer: DellEMC <support@dell.com>
Section: devel
Priority: optional
Build-Depends: dh-exec (>=0.3), debhelper (>= 9), autotools-dev
Standards-Version: 1.0.0
Package: sflowtool
Architecture: any
Depends: ${shlibs:Depends}
Description: This package contains sflowtool from https://github.com/sflow/sflowtool

View File

@ -0,0 +1,19 @@
#!/usr/bin/make -f
# main packaging script based on dh7 syntax
%:
dh $@
override_dh_auto_build:
./boot.sh && ./configure && make
override_dh_auto_install:
override_dh_auto_test:
override_dh_auto_clean:
override_dh_strip:
override_dh_clean:

View File

@ -0,0 +1 @@
src/sflowtool usr/bin