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

[docker-syncd-brcm] [docker-syncd-mlnx]: Properly manage syncd with supervisord #585

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
122 changes: 116 additions & 6 deletions platform/broadcom/docker-syncd-brcm/syncd.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,122 @@
#!/usr/bin/env bash
#
# Based on /etc/init.d/syncd

function clean_up {
service syncd stop
exit
CMD_SYNCD=/usr/bin/syncd

CMD_DSSERVE=/usr/bin/dsserve
CMD_DSSERVE_ARGS="$CMD_SYNCD --diag"

ENABLE_SAITHRIFT=0

PLATFORM_DIR=/usr/share/sonic/platform
HWSKU_DIR=/usr/share/sonic/hwsku

if [ -x $CMD_DSSERVE ]; then
CMD=$CMD_DSSERVE
CMD_ARGS=$CMD_DSSERVE_ARGS
else
CMD=$CMD_SYNCD
fi

parse_yaml() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to use sonic-cfggen instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be better, however, the syncd dockers are currently built from docker-base, not docker-config-engine, so they don't have sonic-cfggen available. I plan to create a new PR that will do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we could replace the docker-base with docker-config-engine.

local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}

start_bcm()
{
[ -e /dev/linux-bcm-knet ] || mknod /dev/linux-bcm-knet c 122 0
[ -e /dev/linux-user-bde ] || mknod /dev/linux-user-bde c 126 0
[ -e /dev/linux-kernel-bde ] || mknod /dev/linux-kernel-bde c 127 0
}

start_mlnx()
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is for mellanox platform. can we consider to still put this syncd.sh into the sairedis repo?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it also possible to take common parts to separate script so that it will be easier to maintain init.d and supervisord all at once?

{
[ -e /dev/sxdevs/sxcdev ] || ( mkdir -p /dev/sxdevs && mknod /dev/sxdevs/sxcdev c 231 193 )

# Read MAC address and align the last 6 bits.
MAC_ADDRESS=`ip link show eth0 | grep ether | awk '{print $2}'`
last_byte=`python -c "print '$MAC_ADDRESS'[-2:]"`
aligned_last_byte=`python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')"` # put mask and take away the 0x prefix
ALIGNED_MAC_ADDRESS=`python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'"` # put aligned byte into the end of MAC

# Write MAC address into /tmp/profile file.
cat $HWSKU_DIR/sai.profile > /tmp/sai.profile
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /tmp/sai.profile
}

trap clean_up SIGTERM SIGKILL
start_centec()
{
[ -e /dev/linux_dal ] || mknod /dev/linux_dal c 198 0
[ -e /dev/net/tun ] || ( mkdir -p /dev/net && mknod /dev/net/tun c 10 200 )

# Read MAC address and align the last 6 bits.
MAC_ADDRESS=`ip link show eth0 | grep ether | awk '{print $2}'`
last_byte=`python -c "print '$MAC_ADDRESS'[-2:]"`
aligned_last_byte=`python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')"` # put mask and take away the 0x prefix
ALIGNED_MAC_ADDRESS=`python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'"` # put aligned byte into the end of MAC

# Write MAC address into /tmp/profile file.

# Write MAC address into /tmp/profile file.
cat $HWSKU_DIR/sai.profile > /tmp/sai.profile
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /tmp/sai.profile
}

start_cavium()
{
export XP_ROOT=/usr/bin/
}

case "$(cat /proc/cmdline)" in
*fast-reboot*)
FAST_REBOOT='yes'
;;
*)
FAST_REBOOT='no'
;;
esac

eval $(parse_yaml /etc/sonic/sonic_version.yml "sonic_")

if [ $sonic_asic_type == "broadcom" ]; then
start_bcm
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile "
if [ $FAST_REBOOT == "yes" ];
then
CMD_ARGS+=" -t fast "
fi
elif [ $sonic_asic_type == "mellanox" ]; then
start_mlnx
CMD_ARGS+=" -p /tmp/sai.profile "
elif [ $sonic_asic_type == "cavium" ]; then
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile "
start_cavium
elif [ $sonic_asic_type == "centec" ]; then
start_centec
CMD_ARGS+=" -p /tmp/sai.profile "
else
echo "Unknown asic type $sonic_asic_type"
exit 1
fi

if [ ${ENABLE_SAITHRIFT} == 1 ]; then
CMD_ARGS+=" -r -m $HWSKU_DIR/port_config.ini"
fi

[ -r $PLATFORM_DIR/syncd.conf ] && . $PLATFORM_DIR/syncd.conf

service syncd start
exec ${CMD} ${CMD_ARGS}

read
4 changes: 4 additions & 0 deletions platform/mellanox/docker-syncd-mlnx/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ rm -f /var/run/rsyslogd.pid

supervisorctl start rsyslogd

# mlnx-fw-upgrade.sh will exit if firmware was actually upgraded
# or if some error occurs
. mlnx-fw-upgrade.sh

supervisorctl start syncd

125 changes: 114 additions & 11 deletions platform/mellanox/docker-syncd-mlnx/syncd.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,122 @@
#!/usr/bin/env bash
#
# Based on /etc/init.d/syncd

function clean_up {
service syncd stop
exit
CMD_SYNCD=/usr/bin/syncd

CMD_DSSERVE=/usr/bin/dsserve
CMD_DSSERVE_ARGS="$CMD_SYNCD --diag"

ENABLE_SAITHRIFT=0

PLATFORM_DIR=/usr/share/sonic/platform
HWSKU_DIR=/usr/share/sonic/hwsku

if [ -x $CMD_DSSERVE ]; then
CMD=$CMD_DSSERVE
CMD_ARGS=$CMD_DSSERVE_ARGS
else
CMD=$CMD_SYNCD
fi

parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}

start_bcm()
{
[ -e /dev/linux-bcm-knet ] || mknod /dev/linux-bcm-knet c 122 0
[ -e /dev/linux-user-bde ] || mknod /dev/linux-user-bde c 126 0
[ -e /dev/linux-kernel-bde ] || mknod /dev/linux-kernel-bde c 127 0
}

start_mlnx()
{
[ -e /dev/sxdevs/sxcdev ] || ( mkdir -p /dev/sxdevs && mknod /dev/sxdevs/sxcdev c 231 193 )

# Read MAC address and align the last 6 bits.
MAC_ADDRESS=`ip link show eth0 | grep ether | awk '{print $2}'`
last_byte=`python -c "print '$MAC_ADDRESS'[-2:]"`
aligned_last_byte=`python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')"` # put mask and take away the 0x prefix
ALIGNED_MAC_ADDRESS=`python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'"` # put aligned byte into the end of MAC

# Write MAC address into /tmp/profile file.
cat $HWSKU_DIR/sai.profile > /tmp/sai.profile
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /tmp/sai.profile
}

start_centec()
{
[ -e /dev/linux_dal ] || mknod /dev/linux_dal c 198 0
[ -e /dev/net/tun ] || ( mkdir -p /dev/net && mknod /dev/net/tun c 10 200 )

# Read MAC address and align the last 6 bits.
MAC_ADDRESS=`ip link show eth0 | grep ether | awk '{print $2}'`
last_byte=`python -c "print '$MAC_ADDRESS'[-2:]"`
aligned_last_byte=`python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')"` # put mask and take away the 0x prefix
ALIGNED_MAC_ADDRESS=`python -c "print '$MAC_ADDRESS'[:-2] + '$aligned_last_byte'"` # put aligned byte into the end of MAC

# Write MAC address into /tmp/profile file.

# Write MAC address into /tmp/profile file.
cat $HWSKU_DIR/sai.profile > /tmp/sai.profile
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /tmp/sai.profile
}

start_cavium()
{
export XP_ROOT=/usr/bin/
}

trap clean_up SIGTERM SIGKILL
case "$(cat /proc/cmdline)" in
*fast-reboot*)
FAST_REBOOT='yes'
;;
*)
FAST_REBOOT='no'
;;
esac

eval $(parse_yaml /etc/sonic/sonic_version.yml "sonic_")

if [ $sonic_asic_type == "broadcom" ]; then
start_bcm
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile "
if [ $FAST_REBOOT == "yes" ];
then
CMD_ARGS+=" -t fast "
fi
elif [ $sonic_asic_type == "mellanox" ]; then
start_mlnx
CMD_ARGS+=" -p /tmp/sai.profile "
elif [ $sonic_asic_type == "cavium" ]; then
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile "
start_cavium
elif [ $sonic_asic_type == "centec" ]; then
start_centec
CMD_ARGS+=" -p /tmp/sai.profile "
else
echo "Unknown asic type $sonic_asic_type"
exit 1
fi

# fw-upgrade will exit if firmware was actually upgraded or if some error
# occures
. mlnx-fw-upgrade.sh
if [ ${ENABLE_SAITHRIFT} == 1 ]; then
CMD_ARGS+=" -r -m $HWSKU_DIR/port_config.ini"
fi

# FIXME: the script cannot trap SIGTERM signal and it exits without clean_up
# Remove rsyslogd.pid file manually so that to start the rsyslog instantly
service syncd start
[ -r $PLATFORM_DIR/syncd.conf ] && . $PLATFORM_DIR/syncd.conf

read
exec ${CMD} ${CMD_ARGS}