Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCLAG feature for SONIC #2514

Merged
merged 26 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions dockers/docker-iccpd/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{% 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 \
libdbus-1-3 \
libdaemon0 \
libpython2.7 \
# Install redis-tools dependencies
# TODO: implicitly install dependencies
libatomic1 \
libjemalloc1 \
liblua5.1-0 \
lua-bitop \
lua-cjson

RUN apt-get -y install ebtables
RUN apt-get -y install -f kmod

COPY \
{% for deb in docker_iccpd_debs.split(' ') -%}
debs/{{ deb }}{{' '}}
{%- endfor -%}
debs/

RUN dpkg -i \
{% for deb in docker_iccpd_debs.split(' ') -%}
debs/{{ deb }}{{' '}}
{%- endfor %}

COPY ["start.sh", "iccpd.sh", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["iccpd.j2", "/usr/share/sonic/templates/"]

RUN chmod +x /usr/bin/start.sh /usr/bin/iccpd.sh
RUN apt-get clean -y && \
apt-get autoclean -y && \
apt-get autoremove -y && \
rm -rf /debs

ENTRYPOINT ["/usr/bin/supervisord"]
10 changes: 10 additions & 0 deletions dockers/docker-iccpd/base_image_files/mclagdctl
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 iccpd mclagdctl "$@"
11 changes: 11 additions & 0 deletions dockers/docker-iccpd/iccpd.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% for mclag_id in MC_LAG %}
mclag_id:{{mclag_id}}
local_ip:{{MC_LAG[mclag_id]['local_ip']}}
peer_ip:{{MC_LAG[mclag_id]['peer_ip']}}
{% if MC_LAG[mclag_id].has_key('peer_link') %}
peer_link:{{MC_LAG[mclag_id]['peer_link']}}
{% endif %}
mclag_interface:{{MC_LAG[mclag_id]['mclag_interface']}}
{% endfor %}
system_mac:{{DEVICE_METADATA['localhost']['mac']}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there - I am testing iccpd, and observet his jinja does not render in any correct data format, whitespace control might need some looking at.

root@leaf-1-1:/etc/iccpd# cat iccpd.conf
mclag_id:1
    local_ip:
    peer_ip:172.16.0.5
            peer_link:PortChannel3
        mclag_interface:
system_mac:cc:37:ab:17:6a:00

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpsenior, We checked the format of iccpd.j2 carefully, and can not replicate this issue.

17 changes: 17 additions & 0 deletions dockers/docker-iccpd/iccpd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

function start_app {
rm -f /var/run/iccpd/*
mclagsyncd &
iccpd
}

function clean_up {
pkill -9 mclagsyncd
pkill -9 iccpd
exit
}

trap clean_up SIGTERM SIGKILL
start_app
read
18 changes: 18 additions & 0 deletions dockers/docker-iccpd/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash


ICCPD_CONF_PATH=/etc/iccpd

rm -rf $ICCPD_CONF_PATH
mkdir -p $ICCPD_CONF_PATH

sonic-cfggen -d -t /usr/share/sonic/templates/iccpd.j2 > $ICCPD_CONF_PATH/iccpd.conf

mkdir -p /var/sonic
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status

rm -f /var/run/rsyslogd.pid

supervisorctl start rsyslogd

supervisorctl start iccpd
29 changes: 29 additions & 0 deletions dockers/docker-iccpd/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[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:iccpd]
command=/usr/bin/iccpd.sh
priority=3
autostart=false
autorestart=false
stdout_logfile=syslog
stderr_logfile=syslog

3 changes: 3 additions & 0 deletions files/build_templates/docker_image_ctl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ start() {
{%- if docker_container_name != "database" %}
-v /usr/share/sonic/device/$PLATFORM/$HWSKU:/usr/share/sonic/hwsku:ro \
{%- endif %}
{%- if docker_container_name == "iccpd" %}
-v /lib/modules:/lib/modules:ro \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need lib modules?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MCLAG uses lib module ebtable_filter and ebtables

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document how ebtable_filter and ebtables are used in the design document, it needs to be review.

besides, even mclag is uses ebtable, it does not mean we need to mount /lib/modules into the docker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jianjundong, @shine4chen , can you please address this comment? Please raise a separate PR for this. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We found that lib module ebtable_filter and ebtables are already installed in the docker default by someone, thus no need to do this here. These codes are removed by lguohan in PR '[docker-iccp]: do not mount kernel module into iccp container (#4372)'.

{%- endif %}
{%- if sonic_asic_platform != "mellanox" %}
--tmpfs /tmp \
{%- endif %}
Expand Down
13 changes: 13 additions & 0 deletions files/build_templates/iccpd.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=ICCPD container
Requires=updategraph.service swss.service teamd.service
After=updategraph.service swss.service teamd.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
3 changes: 3 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ if [ -f {{service}} ]; then
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable {{service}}
fi
{% endfor %}
if [ -f iccpd.service ]; then
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl disable iccpd.service
fi
sudo LANG=C chroot $FILESYSTEM_ROOT fuser -km /sys || true
sudo LANG=C chroot $FILESYSTEM_ROOT umount -lf /sys
{% endif %}
Expand Down
16 changes: 16 additions & 0 deletions rules/docker-iccpd.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# docker image for iccpd agent

DOCKER_ICCPD = docker-iccpd.gz
abdosi marked this conversation as resolved.
Show resolved Hide resolved
$(DOCKER_ICCPD)_PATH = $(DOCKERS_PATH)/docker-iccpd
$(DOCKER_ICCPD)_DEPENDS += $(SWSS) $(REDIS_TOOLS) $(ICCPD)
$(DOCKER_ICCPD)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_STRETCH)
SONIC_DOCKER_IMAGES += $(DOCKER_ICCPD)
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_ICCPD)

SONIC_STRETCH_DOCKERS += $(DOCKER_ICCPD)

$(DOCKER_ICCPD)_CONTAINER_NAME = iccpd
$(DOCKER_ICCPD)_RUN_OPT += --net=host --privileged -t
abdosi marked this conversation as resolved.
Show resolved Hide resolved
$(DOCKER_ICCPD)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro

$(DOCKER_ICCPD)_BASE_IMAGE_FILES += mclagdctl:/usr/bin/mclagdctl
14 changes: 14 additions & 0 deletions rules/iccpd.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# iccpd package

ICCPD_VERSION = 0.0.5

ICCPD = iccpd_$(ICCPD_VERSION)_amd64.deb
$(ICCPD)_DEPENDS += $(LIBNL_GENL3_DEV) $(LIBNL_CLI_DEV)
$(ICCPD)_RDEPENDS += $(LIBNL_GENL3) $(LIBNL_CLI)
$(ICCPD)_SRC_PATH = $(SRC_PATH)/iccpd
SONIC_MAKE_DEBS += $(ICCPD)
# SONIC_STRETCH_DEBS += $(ICCPD)

# Export these variables so they can be used in a sub-make
export ICCPD_VERSION
export ICCPD
35 changes: 35 additions & 0 deletions src/iccpd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.ONESHELL:
SHELL = /bin/bash
.SHELLFLAGS += -e

MAIN_TARGET = iccpd_$(ICCPD_VERSION)_amd64.deb
DEB_PATH = debian

all: iccpd-build mclagdctl-build

iccpd-build:
make -C src

mclagdctl-build:
make -C src/mclagdctl

$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
make all
if [ ! -d $(DEB_PATH)/usr/bin ]; then
mkdir -p $(DEB_PATH)/usr/bin
fi
cp iccpd $(DEB_PATH)/usr/bin/iccpd
cp src/mclagdctl/mclagdctl $(DEB_PATH)/usr/bin/mclagdctl
chmod +x $(DEB_PATH)/usr/bin/iccpd
chmod +x $(DEB_PATH)/usr/bin/mclagdctl
md5sum $(DEB_PATH)/usr/bin/iccpd > $(DEB_PATH)/DEBIAN/md5sums
md5sum $(DEB_PATH)/usr/bin/mclagdctl >> $(DEB_PATH)/DEBIAN/md5sums
dpkg-deb -b $(DEB_PATH) $(DEST)/$(MAIN_TARGET)

clean: iccpd-clean mclagdctl-clean

iccpd-clean:
make -C src clean

mclagdctl-clean:
make -C src/mclagdctl clean
12 changes: 12 additions & 0 deletions src/iccpd/debian/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Package: iccpd-0.0.5-amd64
Source: nps
Version: 0.0.5
Architecture: amd64
Maintainer: Simon Ji <Simon.Ji@nephosinc.com>
Installed-Size: 1508
Depends:
Section: main
Priority: extra
Homepage: https://github.com/NephosInc/SONiC
Description:

73 changes: 73 additions & 0 deletions src/iccpd/include/app_csm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* app_csm.h
*
* Copyright(c) 2016-2019 Nephos/Estinet.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses/>.
*
* The full GNU General Public License is included in this distribution in
* the file called "COPYING".
*
* Maintainer: jianjun, grace Li from nephos
*/

#ifndef APP_CSM_H_
#define APP_CSM_H_

#include <sys/queue.h>

#include "../include/mlacp_fsm.h"

struct CSM;

enum APP_CONNECTION_STATE
{
APP_NONEXISTENT,
APP_RESET,
APP_CONNSENT,
APP_CONNREC,
APP_CONNECTING,
APP_OPERATIONAL
};

typedef enum APP_CONNECTION_STATE APP_CONNECTION_STATE_E;

struct AppCSM
{
struct mLACP mlacp;
APP_CONNECTION_STATE_E current_state;

uint32_t rx_connect_msg_id;
uint32_t tx_connect_msg_id;
uint32_t invalid_msg_id;

TAILQ_HEAD(app_msg_list, Msg) app_msg_list;

uint8_t invalid_msg : 1;
uint8_t nak_msg : 1;
};

void app_csm_init(struct CSM*, int all);
void app_csm_finalize(struct CSM*);
void app_csm_transit(struct CSM*);
int app_csm_prepare_iccp_msg(struct CSM*, char*, size_t);
void app_csm_enqueue_msg(struct CSM*, struct Msg*);
struct Msg* app_csm_dequeue_msg(struct CSM*);
void app_csm_correspond_from_msg(struct CSM*, struct Msg*);
void app_csm_correspond_from_connect_msg(struct CSM*, struct Msg*);
void app_csm_correspond_from_connect_ack_msg(struct CSM*, struct Msg*);
int app_csm_prepare_nak_msg(struct CSM*, char*, size_t);
int app_csm_prepare_connect_msg(struct CSM*, char*, size_t);
int app_csm_prepare_connect_ack_msg(struct CSM*, char*, size_t);

#endif /* APP_CSM_H_ */
Loading