Skip to content

Commit

Permalink
[sflow]: Build infrastructure changes to support sflow docker and uti…
Browse files Browse the repository at this point in the history
…lities (#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 ...)
  • Loading branch information
padmanarayana authored and lguohan committed Sep 15, 2019
1 parent ac1d2c1 commit 75104bb
Show file tree
Hide file tree
Showing 28 changed files with 500 additions and 0 deletions.
33 changes: 33 additions & 0 deletions dockers/docker-sflow/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -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"]
10 changes: 10 additions & 0 deletions dockers/docker-sflow/base_image_files/psample
Original file line number Diff line number Diff line change
@@ -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 "$@"
10 changes: 10 additions & 0 deletions dockers/docker-sflow/base_image_files/sflowtool
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions dockers/docker-sflow/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

rm -f /var/run/rsyslogd.pid

supervisorctl start rsyslogd

supervisorctl start sflowmgrd
28 changes: 28 additions & 0 deletions dockers/docker-sflow/supervisord.conf
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions files/build_templates/sflow.service.j2
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions platform/vs/docker-syncd-vs/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}{{' '}}
Expand Down
3 changes: 3 additions & 0 deletions rules/config
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 35 additions & 0 deletions rules/docker-sflow.mk
Original file line number Diff line number Diff line change
@@ -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 changes: 49 additions & 0 deletions rules/sflow.mk
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions src/sflow/hsflowd/Makefile
Original file line number Diff line number Diff line change
@@ -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)
39 changes: 39 additions & 0 deletions src/sflow/hsflowd/patch/0001-host_sflow_psample.patch
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 75104bb

Please sign in to comment.