diff --git a/meta/SaiInterface.cpp b/meta/SaiInterface.cpp index 3a95bc017..c91d08275 100644 --- a/meta/SaiInterface.cpp +++ b/meta/SaiInterface.cpp @@ -378,3 +378,20 @@ sai_status_t SaiInterface::clearStats( return SAI_STATUS_NOT_IMPLEMENTED; } + +std::shared_ptr SaiInterface::getOptions( + _In_ const std::string& key) +{ + SWSS_LOG_ENTER(); + + return m_optionsMap[key]; +} + +void SaiInterface::setOptions( + _In_ const std::string& key, + _In_ std::shared_ptr options) +{ + SWSS_LOG_ENTER(); + + m_optionsMap[key] = options; +} diff --git a/meta/SaiInterface.h b/meta/SaiInterface.h index 00c14aadb..524645ef8 100644 --- a/meta/SaiInterface.h +++ b/meta/SaiInterface.h @@ -5,6 +5,12 @@ extern "C" { #include "saimetadata.h" } +#include "SaiOptions.h" + +#include +#include +#include + #define SAIREDIS_DECLARE_EVERY_ENTRY(_X) \ SAI_METADATA_DECLARE_EVERY_ENTRY(_X) @@ -343,5 +349,18 @@ namespace sairedis virtual sai_log_level_t logGet( _In_ sai_api_t api); + + public: // non SAI API - options helper + + std::shared_ptr getOptions( + _In_ const std::string& key); + + void setOptions( + _In_ const std::string& key, + _In_ std::shared_ptr options); + + private: + + std::map> m_optionsMap; }; } diff --git a/meta/SaiOptions.h b/meta/SaiOptions.h new file mode 100644 index 000000000..2d053c6c5 --- /dev/null +++ b/meta/SaiOptions.h @@ -0,0 +1,11 @@ +#pragma once + +namespace sairedis +{ + class SaiOptions + { + public: + + virtual ~SaiOptions() = default; + }; +} diff --git a/syncd/HardReiniter.cpp b/syncd/HardReiniter.cpp index 9b621f8b0..8c714eb23 100644 --- a/syncd/HardReiniter.cpp +++ b/syncd/HardReiniter.cpp @@ -13,13 +13,11 @@ HardReiniter::HardReiniter( _In_ std::shared_ptr client, _In_ std::shared_ptr translator, _In_ std::shared_ptr sai, - _In_ std::shared_ptr handler, - _In_ bool checkAttrVersion): + _In_ std::shared_ptr handler): m_vendorSai(sai), m_translator(translator), m_client(client), - m_handler(handler), - m_checkAttrVersion(checkAttrVersion) + m_handler(handler) { SWSS_LOG_ENTER(); @@ -101,8 +99,7 @@ std::map> HardReiniter::hardR m_handler, m_switchVidToRid.at(kvp.first), m_switchRidToVid.at(kvp.first), - kvp.second, - m_checkAttrVersion); + kvp.second); sr->hardReinit(); diff --git a/syncd/HardReiniter.h b/syncd/HardReiniter.h index 435f38f16..9a032d16e 100644 --- a/syncd/HardReiniter.h +++ b/syncd/HardReiniter.h @@ -27,8 +27,7 @@ namespace syncd _In_ std::shared_ptr client, _In_ std::shared_ptr translator, _In_ std::shared_ptr sai, - _In_ std::shared_ptr handler, - _In_ bool checkAttrVersion); + _In_ std::shared_ptr handler); virtual ~HardReiniter(); @@ -60,7 +59,5 @@ namespace syncd std::shared_ptr m_client; std::shared_ptr m_handler; - - bool m_checkAttrVersion; }; } diff --git a/syncd/SaiDiscovery.cpp b/syncd/SaiDiscovery.cpp index 43e01016a..3ba89bc98 100644 --- a/syncd/SaiDiscovery.cpp +++ b/syncd/SaiDiscovery.cpp @@ -1,4 +1,5 @@ #include "SaiDiscovery.h" +#include "VendorSaiOptions.h" #include "swss/logger.h" @@ -19,8 +20,7 @@ using namespace syncd; #define SAI_DISCOVERY_LIST_MAX_ELEMENTS 1024 SaiDiscovery::SaiDiscovery( - _In_ std::shared_ptr sai, - _In_ bool checkAttrVersion): + _In_ std::shared_ptr sai): m_sai(sai) { SWSS_LOG_ENTER(); @@ -31,10 +31,16 @@ SaiDiscovery::SaiDiscovery( if (status == SAI_STATUS_SUCCESS) { - m_attrVersionChecker.enable(checkAttrVersion); + auto vso = std::dynamic_pointer_cast(sai->getOptions(VendorSaiOptions::OPTIONS_KEY)); + + // TODO check vso for null + + m_attrVersionChecker.enable(vso->m_checkAttrVersion); m_attrVersionChecker.setSaiApiVersion(version); - SWSS_LOG_NOTICE("check attr version ENABLED, libsai api version: %lu", version); + SWSS_LOG_NOTICE("check attr version %s, libsai api version: %lu", + (vso->m_checkAttrVersion ? "ENABLED" : "DISABLED"), + version); } else { diff --git a/syncd/SaiDiscovery.h b/syncd/SaiDiscovery.h index c677a5b87..b6f8cf053 100644 --- a/syncd/SaiDiscovery.h +++ b/syncd/SaiDiscovery.h @@ -20,8 +20,7 @@ namespace syncd public: SaiDiscovery( - _In_ std::shared_ptr sai, - _In_ bool checkAttrVersion); + _In_ std::shared_ptr sai); virtual ~SaiDiscovery(); diff --git a/syncd/SaiSwitch.cpp b/syncd/SaiSwitch.cpp index 4f11dba4c..fb711db4d 100644 --- a/syncd/SaiSwitch.cpp +++ b/syncd/SaiSwitch.cpp @@ -26,14 +26,12 @@ SaiSwitch::SaiSwitch( _In_ std::shared_ptr client, _In_ std::shared_ptr translator, _In_ std::shared_ptr vendorSai, - _In_ bool warmBoot, - _In_ bool checkAttrVersion): + _In_ bool warmBoot): SaiSwitchInterface(switch_vid, switch_rid), m_vendorSai(vendorSai), m_warmBoot(warmBoot), m_translator(translator), - m_client(client), - m_checkAttrVersion(checkAttrVersion) + m_client(client) { SWSS_LOG_ENTER(); @@ -663,7 +661,7 @@ void SaiSwitch::helperDiscover() { SWSS_LOG_ENTER(); - SaiDiscovery sd(m_vendorSai, m_checkAttrVersion); + SaiDiscovery sd(m_vendorSai); m_discovered_rids = sd.discover(m_switch_rid); @@ -954,7 +952,7 @@ void SaiSwitch::onPostPortCreate( { SWSS_LOG_ENTER(); - SaiDiscovery sd(m_vendorSai, m_checkAttrVersion); + SaiDiscovery sd(m_vendorSai); auto discovered = sd.discover(port_rid); diff --git a/syncd/SaiSwitch.h b/syncd/SaiSwitch.h index 4c317678a..d6bccfeed 100644 --- a/syncd/SaiSwitch.h +++ b/syncd/SaiSwitch.h @@ -34,8 +34,7 @@ namespace syncd _In_ std::shared_ptr client, _In_ std::shared_ptr translator, _In_ std::shared_ptr vendorSai, - _In_ bool warmBoot, - _In_ bool checkAttrVersion); + _In_ bool warmBoot); virtual ~SaiSwitch() = default; @@ -354,7 +353,5 @@ namespace syncd std::shared_ptr m_translator; std::shared_ptr m_client; - - bool m_checkAttrVersion; }; } diff --git a/syncd/SingleReiniter.cpp b/syncd/SingleReiniter.cpp index 6844d3cf7..6f5355736 100644 --- a/syncd/SingleReiniter.cpp +++ b/syncd/SingleReiniter.cpp @@ -22,16 +22,14 @@ SingleReiniter::SingleReiniter( _In_ std::shared_ptr handler, _In_ const ObjectIdMap& vidToRidMap, _In_ const ObjectIdMap& ridToVidMap, - _In_ const std::vector& asicKeys, - _In_ bool checkAttrVersion): + _In_ const std::vector& asicKeys): m_vendorSai(sai), m_vidToRidMap(vidToRidMap), m_ridToVidMap(ridToVidMap), m_asicKeys(asicKeys), m_translator(translator), m_client(client), - m_handler(handler), - m_checkAttrVersion(checkAttrVersion) + m_handler(handler) { SWSS_LOG_ENTER(); @@ -319,7 +317,7 @@ void SingleReiniter::processSwitches() * object, so when doing discover we will get full default ASIC view. */ - m_sw = std::make_shared(m_switch_vid, m_switch_rid, m_client, m_translator, m_vendorSai, false, m_checkAttrVersion); + m_sw = std::make_shared(m_switch_vid, m_switch_rid, m_client, m_translator, m_vendorSai, false); /* * We processed switch. We have switch vid/rid so we can process all diff --git a/syncd/SingleReiniter.h b/syncd/SingleReiniter.h index b6a27eaab..e33b26af8 100644 --- a/syncd/SingleReiniter.h +++ b/syncd/SingleReiniter.h @@ -32,8 +32,7 @@ namespace syncd _In_ std::shared_ptr handler, _In_ const ObjectIdMap& vidToRidMap, _In_ const ObjectIdMap& ridToVidMap, - _In_ const std::vector& asicKeys, - _In_ bool checkAttrVersion); + _In_ const std::vector& asicKeys); virtual ~SingleReiniter(); @@ -137,7 +136,5 @@ namespace syncd std::shared_ptr m_client; std::shared_ptr m_handler; - - bool m_checkAttrVersion; }; } diff --git a/syncd/Syncd.cpp b/syncd/Syncd.cpp index 7092afb3b..30c11ffd0 100644 --- a/syncd/Syncd.cpp +++ b/syncd/Syncd.cpp @@ -12,6 +12,7 @@ #include "RedisNotificationProducer.h" #include "ZeroMQNotificationProducer.h" #include "WatchdogScope.h" +#include "VendorSaiOptions.h" #include "sairediscommon.h" @@ -109,6 +110,12 @@ Syncd::Syncd( m_enableSyncMode = true; } + auto vso = std::make_shared(); + + vso->m_checkAttrVersion = m_commandLineOptions->m_enableAttrVersionCheck; + + m_vendorSai->setOptions(VendorSaiOptions::OPTIONS_KEY, vso); + m_manager = std::make_shared(m_vendorSai, m_contextConfig->m_dbCounters, m_commandLineOptions->m_supportingBulkCounterGroups); loadProfileMap(); @@ -3166,7 +3173,7 @@ sai_status_t Syncd::processOidCreate( * constructor, like getting all queues, ports, etc. */ - m_switches[switchVid] = std::make_shared(switchVid, objectRid, m_client, m_translator, m_vendorSai, false, m_commandLineOptions->m_enableAttrVersionCheck); + m_switches[switchVid] = std::make_shared(switchVid, objectRid, m_client, m_translator, m_vendorSai, false); m_mdioIpcServer->setSwitchId(objectRid); @@ -4383,7 +4390,7 @@ void Syncd::onSyncdStart( SWSS_LOG_THROW("performing hard reinit, but there are %zu switches defined, bug!", m_switches.size()); } - HardReiniter hr(m_client, m_translator, m_vendorSai, m_handler, m_commandLineOptions->m_enableAttrVersionCheck); + HardReiniter hr(m_client, m_translator, m_vendorSai, m_handler); m_switches = hr.hardReinit(); @@ -4485,7 +4492,7 @@ void Syncd::onSwitchCreateInInitViewMode( // make switch initialization and get all default data - m_switches[switchVid] = std::make_shared(switchVid, switchRid, m_client, m_translator, m_vendorSai, false, m_commandLineOptions->m_enableAttrVersionCheck); + m_switches[switchVid] = std::make_shared(switchVid, switchRid, m_client, m_translator, m_vendorSai, false); m_mdioIpcServer->setSwitchId(switchRid); @@ -4669,7 +4676,7 @@ void Syncd::performWarmRestartSingleSwitch( // perform all get operations on existing switch - auto sw = m_switches[switchVid] = std::make_shared(switchVid, switchRid, m_client, m_translator, m_vendorSai, true, m_commandLineOptions->m_enableAttrVersionCheck); + auto sw = m_switches[switchVid] = std::make_shared(switchVid, switchRid, m_client, m_translator, m_vendorSai, true); startDiagShell(switchRid); } diff --git a/syncd/VendorSaiOptions.h b/syncd/VendorSaiOptions.h new file mode 100644 index 000000000..4c66e81d3 --- /dev/null +++ b/syncd/VendorSaiOptions.h @@ -0,0 +1,17 @@ +#pragma once + +#include "meta/SaiOptions.h" + +namespace syncd +{ + class VendorSaiOptions: + public sairedis::SaiOptions + { + public: + static constexpr const char *OPTIONS_KEY = "vok"; + + public: + + bool m_checkAttrVersion = false; + }; +} diff --git a/syncd/scripts/brcm_common_config_ut.sh b/syncd/scripts/brcm_common_config_ut.sh new file mode 100644 index 000000000..9f3dcb1e1 --- /dev/null +++ b/syncd/scripts/brcm_common_config_ut.sh @@ -0,0 +1,119 @@ +#!/bin/bash +###BRCM Common config UT#### +HWSKU_DIR=/usr/share/sonic/hwsku +SAI_PROFILE_DIR=/etc/sai.d +PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common +PLT_SAI_PROFILE=$(find $SAI_PROFILE_DIR -name 'sai.profile') +readline=$(grep SAI_INIT_CONFIG_FILE $PLT_SAI_PROFILE) +PLATFORM_DIR=/usr/share/sonic/platform + +PLT_CONFIG_BCM="" +PLT_CONFIG_YML="" + +if [ ${readline: -3} == "bcm" ]; then + PLT_CONFIG_BCM=${readline#*=} +elif [ ${readline: -3} == "yml" ]; then + PLT_CONFIG_YML=${readline#*=} +fi + +if [ ! -z "$PLT_CONFIG_BCM" ] && [ -f $PLATFORM_DIR/common_config_support ] ; then + CONFIG_BCM=$(find /tmp -name '*.bcm') + + #Get first three characters of chip id + readline=$(grep '0x14e4' /proc/linux-kernel-bde) + chip_id=${readline#*0x14e4:0x} + chip_id=${chip_id::3} + COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm') + check_override=false + check_pass=false + + #Check if common config does apply to config bcm correctly + while read line + do + line=$( echo $line | xargs ) + if [ ! -z "$line" ];then + if [ "${line::1}" == '#' ];then + echo "Skip checking line starting with #" + elif [ "$line" == "[High Inheritance Precedence]" ];then + echo "Checking High Inheritance property..." + check_override=true + elif [ "$line" == "[Low Inheritance Precedence]" ];then + echo "Checking Low Inheritance property..." + check_override=false + else + if $check_override ;then + if grep -q "$line" $CONFIG_BCM ;then + check_pass=true + else + echo "Fail: Checking overwite properties not existing.." + return + fi + else + sedline=${line%=*} + if grep -q $sedline $CONFIG_BCM ;then + check_pass=true + else + echo "Fail: Checking properties not existing.." + return + fi + fi + fi + fi + done < $COMMON_CONFIG_BCM + if $check_pass ;then + echo "PASS: Checking Common config merged Success" + fi +fi + +if [ ! -z "$PLT_CONFIG_YML" ] && [ -f $PLATFORM_DIR/common_config_support ]; then + CONFIG_YML=$(find /tmp -name '*.yml') + + #Get first three characters of chip id + readline=$(grep '0:14e4' /proc/linux_ngbde) + chip_id=${readline#*0:14e4:} + chip_id=${chip_id::3} + COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm') + check_override=false + check_pass=false + + #Check if common config does apply to config bcm correctly + while read line + do + line=$( echo $line | xargs ) + if [ ! -z "$line" ];then + if [ "${line::1}" == '#' ];then + echo "Skip checking line starting with #" + elif [ "$line" == "[High Inheritance Precedence]" ];then + echo "Checking High Inheritance property..." + check_override=true + elif [ "$line" == "[Low Inheritance Precedence]" ];then + echo "Checking Low Inheritance property..." + check_override=false + else + if $check_override ;then + if grep -q "$line" $CONFIG_YML ;then + check_pass=true + else + echo "Fail: Checking overwite properties not existing.." + check_pass=false + return + fi + else + sedline=${line%:*} + if grep -q $sedline $CONFIG_YML ;then + check_pass=true + else + echo "Fail: Checking properties not existing.." + check_pass=false + return + fi + fi + fi + fi + done < $COMMON_CONFIG_BCM + + if $check_pass ;then + echo "PASS: Checking Common config merged Success" + fi + +fi diff --git a/syncd/scripts/syncd_init_common.sh b/syncd/scripts/syncd_init_common.sh index db36529d2..cb72ab834 100644 --- a/syncd/scripts/syncd_init_common.sh +++ b/syncd/scripts/syncd_init_common.sh @@ -11,6 +11,7 @@ ENABLE_SAITHRIFT=0 TEMPLATES_DIR=/usr/share/sonic/templates PLATFORM_DIR=/usr/share/sonic/platform HWSKU_DIR=/usr/share/sonic/hwsku +SAI_PROFILE_DIR=/etc/sai.d VARS_FILE=$TEMPLATES_DIR/swss_vars.j2 @@ -26,10 +27,8 @@ else CMD_ARGS= fi -# Use temporary view between init and apply except when in fast-reboot -if [[ "$(cat /proc/cmdline)" != *"SONIC_BOOT_TYPE=fast-reboot"* ]]; then - CMD_ARGS+=" -u" -fi +# Use temporary view between init view and apply view +CMD_ARGS+=" -u" # Create a folder for SAI failure dump files mkdir -p /var/log/sai_failure_dump/ @@ -124,74 +123,188 @@ config_syncd_cisco_8000() fi } -config_syncd_bcm() +function merge_config_bcm_files() { + to_file=$1 + from_file=$2 + message=$3 + override=false + echo "" >> $to_file + echo "# Start of $message" >> $to_file + while read line + do + line=$( echo $line | xargs ) + if [ ! -z "$line" ];then + if [ "${line::1}" == '#' ];then + echo $line >> $to_file + elif [ "$line" == "[Low Inheritance Precedence]" ];then + override=false + echo "# $line" >> $to_file + elif [ "$line" == "[High Inheritance Precedence]" ];then + override=true + echo "# $line" >> $to_file + echo "Merge properties with override $override" + else + sedline=${line%=*} + if grep -q $sedline $to_file ;then + if $override ;then + echo "Override the config $(grep $sedline $to_file) with $line in $to_file" + prop=${line:0:`expr index $line =`} + sed -i "/$prop/d" $to_file + echo $line >> $to_file + else + grepline=$(grep $sedline $to_file) + if [ "${grepline::1}" == '#' ];then + echo $line >> $to_file + else + echo "Keep the config $(grep $sedline $to_file) in $to_file" + fi + fi + else + echo $line >> $to_file + fi + fi + fi + done < $from_file + echo "# End of $message" >> $to_file + echo "Merged $from_file to $to_file" +} - if [ -f $PLATFORM_DIR/common_config_support ];then - - PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common - - cp -f $HWSKU_DIR/*.config.bcm /tmp - cp -f /etc/sai.d/sai.profile /tmp - CONFIG_BCM=$(find /tmp -name '*.bcm') - PLT_CONFIG_BCM=$(find $HWSKU_DIR -name '*.bcm') - SAI_PROFILE=$(find /tmp -name 'sai.profile') - sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE - - #Get first three characters of chip id - readline=$(grep '0x14e4' /proc/linux-kernel-bde) - chip_id=${readline#*0x14e4:0x} - chip_id=${chip_id::3} - COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -name '*.bcm') - - if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then - for file in $CONFIG_BCM; do - echo "" >> $file - echo "# Start of chip common properties" >> $file - while read line - do - line=$( echo $line | xargs ) - if [ ! -z "$line" ];then - if [ "${line::1}" == '#' ];then - echo $line >> $file +function merge_config_yml_files() +{ + to_file=$1 + from_file=$2 + message=$3 + override=false + merged_cnt=0 + echo "" >> $to_file + echo "# Start of $message" >> $to_file + while read line + do + line=$( echo $line | xargs ) + if [ ! -z "$line" ];then + if [ "${line::1}" == '#' ];then + echo " $line" >> $to_file + elif [ "$line" == "[Low Inheritance Precedence]" ];then + override=false + echo " # $line" >> $to_file + elif [ "$line" == "[High Inheritance Precedence]" ];then + override=true + echo " # $line" >> $to_file + echo "Merge properties with override $override" + else + sedline=${line%:*} + if grep -q $sedline $to_file ;then + if $override ;then + echo "Override the config $(grep $sedline $to_file) with $line in $to_file" + prop=${line:0:`expr index "$line" :`} + sed -i "/$prop/d" $to_file + echo " $line" >> $to_file + merged_cnt+=1 else - sedline=${line%=*} - if grep -q $sedline $file ;then - echo "Keep the config $(grep $sedline $file) in $file" - else - echo $line >> $file - fi + grepline=$(grep $sedline $to_file) + grepline="${grepline#"${grepline%%[![:space:]]*}"}" + if [ "${grepline::1}" == '#' ];then + echo " $line" >> $to_file + merged_cnt+=1 + else + echo "Keep the config $(grep $sedline $to_file) in $to_file" + fi fi - fi - done < $COMMON_CONFIG_BCM - echo "# End of chip common properties" >> $file - done - echo "Merging $PLT_CONFIG_BCM with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_BCM" - fi - - #sync the file system - sync - - # copy the final config.bcm and sai.profile to the shared folder for 'show tech' - cp -f /tmp/sai.profile /var/run/sswsyncd/ - cp -f /tmp/*.bcm /var/run/sswsyncd/ - - if [ -f "/tmp/sai.profile" ]; then - CMD_ARGS+=" -p /tmp/sai.profile" - elif [ -f "/etc/sai.d/sai.profile" ]; then - CMD_ARGS+=" -p /etc/sai.d/sai.profile" - else - CMD_ARGS+=" -p $HWSKU_DIR/sai.profile" - fi + else + echo " $line" >> $to_file + merged_cnt+=1 + fi + fi + fi + done < $from_file - else + if [ $merged_cnt -gt 0 ]; then + sed -i "/# Start of/a \ global:" $to_file + sed -i "/# Start of/a \ 0:" $to_file + sed -i "/# Start of/a \bcm_device:" $to_file + sed -i "/# Start of/a \---" $to_file + fi + echo "# End of $message" >> $to_file + if [ $merged_cnt -gt 0 ]; then + sed -i "/# End of/i \..." $to_file + fi + echo "Merged $from_file to $to_file" +} - if [ -f "/etc/sai.d/sai.profile" ]; then - CMD_ARGS+=" -p /etc/sai.d/sai.profile" - else - CMD_ARGS+=" -p $HWSKU_DIR/sai.profile" - fi +config_syncd_bcm() +{ + PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common + PLT_CONFIG_BCM="" + PLT_CONFIG_YML="" + PLT_SAI_PROFILE=$(find $SAI_PROFILE_DIR -name 'sai.profile') + readline=$(grep SAI_INIT_CONFIG_FILE $PLT_SAI_PROFILE) + if [ ${readline: -3} == "bcm" ]; then + PLT_CONFIG_BCM=${readline#*=} + elif [ ${readline: -3} == "yml" ]; then + PLT_CONFIG_YML=${readline#*=} + fi + if [ ! -z "$PLT_CONFIG_BCM" ] && [ -f $PLATFORM_DIR/common_config_support ] ; then + cp -f $PLT_CONFIG_BCM /tmp + cp -f /etc/sai.d/sai.profile /tmp + CONFIG_BCM=$(find /tmp -name '*.bcm') + SAI_PROFILE=$(find /tmp -name 'sai.profile') + sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE + + #Get first three characters of chip id + readline=$(grep '0x14e4' /proc/linux-kernel-bde) + chip_id=${readline#*0x14e4:0x} + chip_id=${chip_id::3} + COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm') + + if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then + for file in $CONFIG_BCM; do + merge_config_bcm_files $file $COMMON_CONFIG_BCM "chip common properties" + done + echo "Merging $PLT_CONFIG_BCM with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_BCM" + fi + #sync the file system + sync + + # copy the final config.bcm and sai.profile to the shared folder for 'show tech' + cp -f /tmp/sai.profile /var/run/sswsyncd/ + cp -f /tmp/*.bcm /var/run/sswsyncd/ + fi + + if [ ! -z "$PLT_CONFIG_YML" ] && [ -f $PLATFORM_DIR/common_config_support ]; then + cp -f $PLT_CONFIG_YML /tmp + cp -f /etc/sai.d/sai.profile /tmp + CONFIG_YML=$(find /tmp -name '*.yml') + SAI_PROFILE=$(find /tmp -name 'sai.profile') + sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE + + #Get first three characters of chip id + readline=$(grep '0:14e4' /proc/linux_ngbde) + chip_id=${readline#*0:14e4:} + chip_id=${chip_id::3} + COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm') + + if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then + for file in $CONFIG_YML; do + merge_config_yml_files $file $COMMON_CONFIG_BCM "chip common properties" + done + echo "Merging $PLT_CONFIG_YML with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_YML " + fi + #sync the file system + sync + + # copy the final config.bcm and sai.profile to the shared folder for 'show tech' + cp -f /tmp/sai.profile /var/run/sswsyncd/ + cp -f /tmp/*.yml /var/run/sswsyncd/ + fi + + if [ -f "/tmp/sai.profile" ]; then + CMD_ARGS+=" -p /tmp/sai.profile" + elif [ -f "/etc/sai.d/sai.profile" ]; then + CMD_ARGS+=" -p /etc/sai.d/sai.profile" + else + CMD_ARGS+=" -p $HWSKU_DIR/sai.profile" fi if [ -f "$HWSKU_DIR/context_config.json" ]; then @@ -519,4 +632,3 @@ config_syncd() [ -r $PLATFORM_DIR/syncd.conf ] && . $PLATFORM_DIR/syncd.conf } - diff --git a/tests/aspell.en.pws b/tests/aspell.en.pws index a51e8f4c6..4a99b8dec 100644 --- a/tests/aspell.en.pws +++ b/tests/aspell.en.pws @@ -479,3 +479,4 @@ submodule Enqueue deque apiversion +vso diff --git a/unittest/meta/TestSaiInterface.cpp b/unittest/meta/TestSaiInterface.cpp index 19a095ab8..cf35fc113 100644 --- a/unittest/meta/TestSaiInterface.cpp +++ b/unittest/meta/TestSaiInterface.cpp @@ -117,3 +117,37 @@ TEST(SaiInterface, stats_meter_bucket_entry) EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, s->getStatsExt(m, 0, nullptr, SAI_STATS_MODE_READ, nullptr)); EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, s->clearStats(m, 0, nullptr)); } + +class Opt: + public SaiOptions +{ + public: + + int i; +}; + +TEST(SaiInterface, setOptions) +{ + DummySaiInterface ds; + + ds.setOptions("key", std::make_shared()); +} + +TEST(SaiInterface, getOptions) +{ + DummySaiInterface ds; + + auto opt = std::make_shared(); + + opt->i = 42; + + ds.setOptions("key", opt); + + auto o = std::dynamic_pointer_cast(ds.getOptions("key")); + + EXPECT_NE(o, nullptr); + + EXPECT_EQ(o->i, 42); + + EXPECT_EQ(ds.getOptions("foo"), nullptr); +}