Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit d0d3f88

Browse files
padmanarayanaamaneti
authored andcommitted
[JIRA SONIC-9750] sflow : Build infrastructure changes to support sflow docker and utilities (sonic-net#3251)
Dev sanity: http://10.59.132.240:9009/projects/csg_sonic/sanity/logs/dev-sanity-th2-td3-03/sonic_dev_sanity_190923_0503_1739 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 ...) (cherry picked from commit 75104bb) Change-Id: I6ed669e756f01f79462fc320b80b8a31dd448adf
1 parent 359429d commit d0d3f88

File tree

28 files changed

+510
-0
lines changed

28 files changed

+510
-0
lines changed

dockers/docker-sflow/Dockerfile.j2

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
2+
FROM {{docker_sflow_load_image}}
3+
4+
ARG docker_container_name
5+
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf
6+
7+
## Make apt-get non-interactive
8+
ENV DEBIAN_FRONTEND=noninteractive
9+
10+
RUN apt-get update && \
11+
apt-get install -f -y \
12+
dmidecode \
13+
libmnl0=1.0.4-2
14+
15+
{% if docker_sflow_debs.strip() -%}
16+
# Copy locally-built Debian package dependencies
17+
{{ copy_files("debs/", docker_sflow_debs.split(' '), "/debs/") }}
18+
19+
# Install locally-built Debian packages and implicitly install their dependencies
20+
{{ install_debian_packages(docker_sflow_debs.split(' ')) }}
21+
{%- endif %}
22+
23+
RUN apt-get clean -y && \
24+
apt-get autoclean -y && \
25+
apt-get autoremove -y && \
26+
rm -rf /debs
27+
28+
RUN sed -ri '/^DAEMON_ARGS=""/c DAEMON_ARGS="-c /var/log/hsflowd.crash"' /etc/init.d/hsflowd
29+
30+
COPY ["start.sh", "/usr/bin/"]
31+
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
32+
33+
ENTRYPOINT ["/usr/bin/supervisord"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
DOCKER_EXEC_FLAGS="i"
4+
5+
# Determine whether stdout is on a terminal
6+
if [ -t 1 ] ; then
7+
DOCKER_EXEC_FLAGS+="t"
8+
fi
9+
10+
docker exec -$DOCKER_EXEC_FLAGS sflow psample "$@"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
DOCKER_EXEC_FLAGS="i"
4+
5+
# Determine whether stdout is on a terminal
6+
if [ -t 1 ] ; then
7+
DOCKER_EXEC_FLAGS+="t"
8+
fi
9+
10+
docker exec -$DOCKER_EXEC_FLAGS sflow sflowtool "$@"

dockers/docker-sflow/start.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
rm -f /var/run/rsyslogd.pid
4+
5+
supervisorctl start rsyslogd
6+
7+
supervisorctl start sflowmgrd

dockers/docker-sflow/supervisord.conf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[supervisord]
2+
logfile_maxbytes=1MB
3+
logfile_backups=2
4+
nodaemon=true
5+
6+
[program:start.sh]
7+
command=/usr/bin/start.sh
8+
priority=1
9+
autostart=true
10+
autorestart=false
11+
stdout_logfile=syslog
12+
stderr_logfile=syslog
13+
14+
[program:rsyslogd]
15+
command=/usr/sbin/rsyslogd -n
16+
priority=2
17+
autostart=false
18+
autorestart=false
19+
stdout_logfile=syslog
20+
stderr_logfile=syslog
21+
22+
[program:sflowmgrd]
23+
command=/usr/bin/sflowmgrd
24+
priority=3
25+
autostart=false
26+
autorestart=false
27+
stdout_logfile=syslog
28+
stderr_logfile=syslog
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=sFlow container
3+
Requires=swss.service
4+
After=swss.service
5+
Before=ntp-config.service
6+
7+
[Service]
8+
User={{ sonicadmin_user }}
9+
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start
10+
ExecStart=/usr/bin/{{docker_container_name}}.sh wait
11+
ExecStop=/usr/bin/{{docker_container_name}}.sh stop
12+
13+
[Install]
14+
WantedBy=multi-user.target

files/build_templates/sonic_debian_extension.j2

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
## PARAMETERS:
99
## FILESYSTEM_ROOT
1010
## Path to debian file system root directory
11+
if [ -z "$CONFIGURED_ARCH" ]; then
12+
CONFIGURED_ARCH=amd64
13+
fi
1114

1215
FILESYSTEM_ROOT=$1
1316
[ -n "$FILESYSTEM_ROOT" ] || {
@@ -379,6 +382,20 @@ sudo cp $IMAGE_CONFIGS/platform/rc.local $FILESYSTEM_ROOT/etc/
379382
## copy blacklist file
380383
sudo cp $IMAGE_CONFIGS/platform/linux_kernel_bde.conf $FILESYSTEM_ROOT/etc/modprobe.d/
381384

385+
# Enable psample drivers to support sFlow on vs
386+
{% if sonic_asic_platform == "vs" %}
387+
sudo tee -a $FILESYSTEM_ROOT/etc/modules-load.d/modules.conf > /dev/null <<EOF
388+
psample
389+
act_sample
390+
EOF
391+
{% endif %}
392+
393+
## Bind docker path
394+
if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then
395+
sudo mkdir -p $FILESYSTEM_ROOT/dockerfs
396+
sudo mount --bind dockerfs $FILESYSTEM_ROOT/dockerfs
397+
fi
398+
382399
{% if installer_images.strip() -%}
383400
sudo chroot $FILESYSTEM_ROOT docker info
384401
{% for image in installer_images.strip().split(' ') -%}

platform/vs/docker-syncd-vs/Dockerfile.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ ENV DEBIAN_FRONTEND=noninteractive
88

99
RUN apt-get update
1010

11+
RUN apt-get install -f -y iproute2=4.20.0-2~bpo9+1 libcap2-bin=1:2.25-1
12+
1113
COPY \
1214
{% for deb in docker_syncd_vs_debs.split(' ') -%}
1315
debs/{{ deb }}{{' '}}

rules/config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ SONIC_DPKG_CACHE_SOURCE=/projects/csg_sonic/dpkg_cache
131131
# Default VS build memory preparation
132132
DEFAULT_VS_PREPARE_MEM = yes
133133

134+
# ENABLE_SYSTEM_SFLOW - build docker-sonic-sflow for sFlow support
135+
ENABLE_SFLOW = y
136+
134137
# Docker local registry server info where
135138
# Docker base images are pushed and pulled from the local docker registry
136139
DOCKER_REGISTRY_SERVER=10.75.139.137:5000

rules/docker-sflow.mk

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# docker image for sFlow agent
2+
3+
DOCKER_SFLOW_STEM = docker-sflow
4+
DOCKER_SFLOW = $(DOCKER_SFLOW_STEM).gz
5+
DOCKER_SFLOW_DBG = $(DOCKER_SFLOW_STEM)-$(DBG_IMAGE_MARK).gz
6+
7+
$(DOCKER_SFLOW)_PATH = $(DOCKERS_PATH)/$(DOCKER_SFLOW_STEM)
8+
9+
$(DOCKER_SFLOW)_DEPENDS += $(SWSS) $(REDIS_TOOLS) $(HSFLOWD) $(SFLOWTOOL) $(PSAMPLE)
10+
$(DOCKER_SFLOW)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS)
11+
$(DOCKER_TEAMD)_DBG_DEPENDS += $(SWSS_DBG) $(LIBSWSSCOMMON_DBG)
12+
$(DOCKER_SFLOW)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_IMAGE_PACKAGES)
13+
14+
$(DOCKER_SFLOW)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_STRETCH)
15+
16+
SONIC_DOCKER_IMAGES += $(DOCKER_SFLOW)
17+
ifeq ($(ENABLE_SFLOW), y)
18+
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_SFLOW)
19+
SONIC_STRETCH_DOCKERS += $(DOCKER_SFLOW)
20+
endif
21+
22+
SONIC_DOCKER_DBG_IMAGES += $(DOCKER_SFLOW_DBG)
23+
ifeq ($(ENABLE_SFLOW), y)
24+
SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_SFLOW_DBG)
25+
SONIC_STRETCH_DBG_DOCKERS += $(DOCKER_SFLOW_DBG)
26+
endif
27+
28+
$(DOCKER_SFLOW)_CONTAINER_NAME = sflow
29+
$(DOCKER_SFLOW)_RUN_OPT += --net=host --privileged -t
30+
$(DOCKER_SFLOW)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro
31+
$(DOCKER_SFLOW)_RUN_OPT += -v /host/warmboot:/var/warmboot
32+
33+
$(DOCKER_SFLOW)_BASE_IMAGE_FILES += psample:/usr/bin/psample
34+
$(DOCKER_SFLOW)_BASE_IMAGE_FILES += sflowtool:/usr/bin/sflowtool
35+

rules/sflow.mk

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# host-sflow package
2+
3+
HSFLOWD_VERSION = 2.0.21
4+
HSFLOWD_SUBVERSION = 8
5+
CONFIGURED_ARCH=amd64
6+
export HSFLOWD_VERSION HSFLOWD_SUBVERSION
7+
8+
HSFLOWD = hsflowd_$(HSFLOWD_VERSION)-$(HSFLOWD_SUBVERSION)_$(CONFIGURED_ARCH).deb
9+
$(HSFLOWD)_DEPENDS += $(LIBHIREDIS_DEV) $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON)
10+
$(HSFLOWD)_SRC_PATH = $(SRC_PATH)/sflow/hsflowd
11+
12+
SONIC_MAKE_DEBS += $(HSFLOWD)
13+
SONIC_STRETCH_DEBS += $(HSFLOWD)
14+
15+
HSFLOWD_DBG = hsflowd-dbg_$(HSFLOWD_VERSION)-$(HSFLOWD_SUBVERSION)_$(CONFIGURED_ARCH).deb
16+
$(HSFLOWD_DBG)_DEPENDS += $(HSFLOWD)
17+
$(HSFLOWD_DBG)_RDEPENDS += $(HSFLOWD)
18+
$(eval $(call add_derived_package,$(HSFLOWD),$(HSFLOWD_DBG)))
19+
20+
export HSFLOWD HSFLOWD_DBG
21+
22+
# sflowtool package
23+
24+
SFLOWTOOL_VERSION = 5.04
25+
export SFLOWTOOL_VERSION
26+
27+
SFLOWTOOL = sflowtool_$(SFLOWTOOL_VERSION)_$(CONFIGURED_ARCH).deb
28+
$(SFLOWTOOL)_SRC_PATH = $(SRC_PATH)/sflow/sflowtool
29+
30+
SONIC_MAKE_DEBS += $(SFLOWTOOL)
31+
SONIC_STRETCH_DEBS += $(SFLOWTOOL)
32+
export SFLOWTOOL
33+
34+
# psample package
35+
36+
PSAMPLE_VERSION = 1.1
37+
PSAMPLE_SUBVERSION = 1
38+
export PSAMPLE_VERSION PSAMPLE_SUBVERSION
39+
40+
PSAMPLE = psample_$(PSAMPLE_VERSION)-$(PSAMPLE_SUBVERSION)_$(CONFIGURED_ARCH).deb
41+
$(PSAMPLE)_SRC_PATH = $(SRC_PATH)/sflow/psample
42+
43+
SONIC_MAKE_DEBS += $(PSAMPLE)
44+
SONIC_STRETCH_DEBS += $(PSAMPLE)
45+
export PSAMPLE
46+
47+
# The .c, .cpp, .h & .hpp files under src/{$DBG_SRC_ARCHIVE list}
48+
# are archived into debug one image to facilitate debugging.
49+
#
50+
DBG_SRC_ARCHIVE += sflow

slave.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ ifeq ($(SONIC_INSTALL_DEBUG_TOOLS),y)
9292
INSTALL_DEBUG_TOOLS = y
9393
endif
9494

95+
ifeq ($(SONIC_ENABLE_SFLOW),y)
96+
ENABLE_SFLOW = y
97+
endif
98+
9599
include $(RULES_PATH)/config
96100
include $(RULES_PATH)/functions
97101
include $(RULES_PATH)/*.mk
@@ -249,6 +253,7 @@ $(info "BLDENV" : "$(BLDENV)")
249253
$(info "VS_PREPARE_MEM" : "$(VS_PREPARE_MEM)")
250254
$(info "VERSION" : "$(SONIC_GET_VERSION)")
251255
$(info "PDDF_SUPPORT" : "$(PDDF_SUPPORT)")
256+
$(info "ENABLE_SFLOW" : "$(ENABLE_SFLOW)")
252257
$(info )
253258

254259
###############################################################################

src/sflow/hsflowd/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.ONESHELL:
2+
SHELL = /bin/bash
3+
.SHELLFLAGS += -e
4+
5+
MAIN_TARGET = $(HSFLOWD)
6+
DERIVED_TARGET = $(HSFLOWD_DBG)
7+
8+
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
9+
rm -fr ./host-sflow
10+
git clone https://github.com/sflow/host-sflow
11+
12+
pushd ./host-sflow
13+
git checkout -b sflow -f 996f5ec
14+
15+
# Apply patch series
16+
stg init
17+
stg import -s ../patch/series
18+
19+
mkdir -p debian
20+
cp -r DEBIAN_build/* debian
21+
chmod u+x debian/rules
22+
sed -i -e s/_VERSION_/$(HSFLOWD_VERSION)-$(HSFLOWD_SUBVERSION)/g debian/changelog
23+
24+
dpkg-buildpackage -rfakeroot -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS) --buildinfo-option=-u. --changes-option=-u.
25+
26+
mv $(DERIVED_TARGET) $* $(DEST)/
27+
popd
28+
29+
$(addprefix $(DEST)/, $(DERIVED_TARGET)): $(DEST)/% : $(DEST)/$(MAIN_TARGET)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
diff -ruN a/src/Linux/linux/psample.h b/src/Linux/linux/psample.h
2+
--- a/src/Linux/linux/psample.h 1969-12-31 16:00:00.000000000 -0800
3+
+++ b/src/Linux/linux/psample.h 2019-07-20 08:45:58.715748881 -0700
4+
@@ -0,0 +1,35 @@
5+
+#ifndef __UAPI_PSAMPLE_H
6+
+#define __UAPI_PSAMPLE_H
7+
+
8+
+enum {
9+
+ /* sampled packet metadata */
10+
+ PSAMPLE_ATTR_IIFINDEX,
11+
+ PSAMPLE_ATTR_OIFINDEX,
12+
+ PSAMPLE_ATTR_ORIGSIZE,
13+
+ PSAMPLE_ATTR_SAMPLE_GROUP,
14+
+ PSAMPLE_ATTR_GROUP_SEQ,
15+
+ PSAMPLE_ATTR_SAMPLE_RATE,
16+
+ PSAMPLE_ATTR_DATA,
17+
+
18+
+ /* commands attributes */
19+
+ PSAMPLE_ATTR_GROUP_REFCOUNT,
20+
+
21+
+ __PSAMPLE_ATTR_MAX
22+
+};
23+
+
24+
+enum psample_command {
25+
+ PSAMPLE_CMD_SAMPLE,
26+
+ PSAMPLE_CMD_GET_GROUP,
27+
+ PSAMPLE_CMD_NEW_GROUP,
28+
+ PSAMPLE_CMD_DEL_GROUP,
29+
+};
30+
+
31+
+/* Can be overridden at runtime by module option */
32+
+#define PSAMPLE_ATTR_MAX (__PSAMPLE_ATTR_MAX - 1)
33+
+
34+
+#define PSAMPLE_NL_MCGRP_CONFIG_NAME "config"
35+
+#define PSAMPLE_NL_MCGRP_SAMPLE_NAME "packets"
36+
+#define PSAMPLE_GENL_NAME "psample"
37+
+#define PSAMPLE_GENL_VERSION 1
38+
+
39+
+#endif

0 commit comments

Comments
 (0)