Skip to content

Commit

Permalink
simplify syncd start logic on different platforms (requires one image) (
Browse files Browse the repository at this point in the history
sonic-net#166)

* simplify syncd start logic on different platforms (requires one image)

* remove sai profiles
  • Loading branch information
lguohan authored Mar 3, 2017
1 parent 3d36c06 commit 22ea540
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 139 deletions.
100 changes: 48 additions & 52 deletions debian/syncd.init
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DAEMON_SYNCD=/usr/bin/syncd
DAEMON_DSSERVE=/usr/bin/dsserve
DAEMON_DSSERVE_ARGS="-d $DAEMON_SYNCD --diag"
ENABLE_SAITHRIFT=0
HWSKU_DIR=/usr/share/sonic/hwsku

if [ -x $DAEMON_DSSERVE ]; then
DAEMON=$DAEMON_DSSERVE
Expand All @@ -24,6 +25,22 @@ else
DAEMON=$DAEMON_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
Expand All @@ -34,68 +51,47 @@ start_bcm()
start_mlnx()
{
[ -e /dev/sxdevs/sxcdev ] || ( mkdir -p /dev/sxdevs && mknod /dev/sxdevs/sxcdev c 231 193 )
}

case "$1" in
start)
[ -r /etc/machine.conf ] && . /etc/machine.conf

if [ "$onie_platform" == "x86_64-dell_s6000_s1220-r0" ]; then
start_bcm
DAEMON_ARGS+=" -p /etc/syncd.d/dell_s6000.profile "
# 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

if [ ${ENABLE_SAITHRIFT} == 1 ]; then
DAEMON_ARGS+=" -r -m /etc/syncd.d/dell_s6000_port_map.ini"
fi

elif [ "$onie_platform" == "x86_64-dell_s6100_c2538-r0" ]; then
start_bcm
DAEMON_ARGS+=" -p /etc/syncd.d/dell_s6100.profile -N"

elif [ "$onie_platform" == "x86_64-dell_z9100_c2538-r0" ]; then
start_bcm
DAEMON_ARGS+=" -p /etc/syncd.d/dell_z9100.profile"
# 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
}

elif [ "$aboot_platform" == "x86_64-arista_7050_qx32" ]; then
start_bcm
DAEMON_ARGS+=" -p /etc/syncd.d/arista_a7050_qx32.profile"
start_cavium()
{
export XP_ROOT=/usr/bin/
}

elif [ "$onie_platform" == "x86_64-m3000-r0" ]; then
start_bcm
DAEMON_ARGS+=" -p /etc/syncd.d/m3000_r0.profile"
case "$1" in
start)
eval $(parse_yaml /etc/sonic/sonic_version.yml "sonic_")

elif [ "$onie_platform" == "x86_64-m3000-r1" ]; then
if [ $sonic_asic_type == "broadcom" ]; then
start_bcm
DAEMON_ARGS+=" -p /etc/syncd.d/m3000_r1.profile"

elif [ "$onie_platform" == "x86_64-mlnx_x86-r5.0.1400" ] || [ "$onie_platform" == "x86_64-mlnx_msn2700-r0" ]; then
DAEMON_ARGS+=" -p $HWSKU_DIR/sai.profile "
elif [ $sonic_asic_type == "mellanox" ]; then
start_mlnx
DAEMON_ARGS+=" -p /tmp/sai.profile "
elif [ $sonic_asic_type == "cavium" ]; then
DAEMON_ARGS+=" -p $HWSKU_DIR/sai.profile "
start_cavium
else
echo "Unknown asic type $sonic_asic_type"
exit 1
fi

# Check if there's no MAC in .profile already.
if ! grep DEVICE_MAC_ADDRESS /etc/syncd.d/mlnx_2700.profile > /dev/null
then
# 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 *.profile file.
echo "DEVICE_MAC_ADDRESS=$ALIGNED_MAC_ADDRESS" >> /etc/syncd.d/mlnx_2700.profile
fi

DAEMON_ARGS="-p /etc/syncd.d/mlnx_2700.profile"

if [ ${ENABLE_SAITHRIFT} == 1 ]; then
DAEMON_ARGS+=" -r -m /etc/syncd.d/msn2700_port_map.ini"
fi

elif [ "$onie_platform" == "x86_64-ingrasys_s9100-r0" ]; then
start_bcm
export OPENNSL_CONFIG_POST_INIT_FILE="/etc/bcm/th-ingrasys-s9100-32x100G.soc"
DAEMON_ARGS+=" -p /etc/syncd.d/ingrasys_s9100.profile -N"
if [ ${ENABLE_SAITHRIFT} == 1 ]; then
DAEMON_ARGS+=" -r -m $HWSKU_DIR/port_config.ini"
fi

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

start-stop-daemon --start --quiet --exec $DAEMON -- $DAEMON_ARGS
;;
stop)
Expand Down
1 change: 0 additions & 1 deletion debian/syncd.install
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
usr/bin/saidump
usr/bin/saiplayer
usr/bin/syncd*
etc/*
1 change: 0 additions & 1 deletion etc/syncd.d/arista_a7050_qx32.profile

This file was deleted.

1 change: 0 additions & 1 deletion etc/syncd.d/dell_s6000.profile

This file was deleted.

33 changes: 0 additions & 33 deletions etc/syncd.d/dell_s6000_port_map.ini

This file was deleted.

1 change: 0 additions & 1 deletion etc/syncd.d/dell_s6100.profile

This file was deleted.

1 change: 0 additions & 1 deletion etc/syncd.d/dell_z9100.profile

This file was deleted.

1 change: 0 additions & 1 deletion etc/syncd.d/ingrasys_s9100.profile

This file was deleted.

1 change: 0 additions & 1 deletion etc/syncd.d/m3000_r0.profile

This file was deleted.

1 change: 0 additions & 1 deletion etc/syncd.d/m3000_r1.profile

This file was deleted.

1 change: 0 additions & 1 deletion etc/syncd.d/mlnx_2700.profile

This file was deleted.

33 changes: 0 additions & 33 deletions etc/syncd.d/msn2700_port_map.ini

This file was deleted.

17 changes: 5 additions & 12 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,18 +1550,11 @@ void handlePortMap(const std::string& portMapFile)
if (line.size() > 0 && (line[0] == '#' || line[0] == ';'))
continue;

size_t pos = line.find(" ");
std::istringstream iss(line);
std::string name, lanes, alias;
iss >> name >> lanes >> alias;

if (pos == std::string::npos)
{
std::cerr << "port map parsing: not found ' ' in line" << line.c_str() << std::endl;
continue;
}

std::string fp_value = line.substr(0, pos);
std::string lanes = line.substr(pos + 1);
lanes.erase(lanes.begin(), std::find_if(lanes.begin(), lanes.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
std::istringstream iss(lanes);
iss.str(lanes);
std::string lane_str;
std::set<int> lane_set;

Expand All @@ -1571,7 +1564,7 @@ void handlePortMap(const std::string& portMapFile)
lane_set.insert(lane);
}

gPortMap.insert(std::pair<std::set<int>,std::string>(lane_set,fp_value));
gPortMap.insert(std::pair<std::set<int>,std::string>(lane_set, name));
}
}
#endif // SAITHRIFT
Expand Down

0 comments on commit 22ea540

Please sign in to comment.