diff --git a/meta/SaiInterface.cpp b/meta/SaiInterface.cpp index 538896a6b..a07e97d4f 100644 --- a/meta/SaiInterface.cpp +++ b/meta/SaiInterface.cpp @@ -329,3 +329,13 @@ sai_status_t SaiInterface::switchMdioCl22Write( return SAI_STATUS_FAILURE; } + +sai_log_level_t SaiInterface::logGet( + _In_ sai_api_t api) +{ + SWSS_LOG_ENTER(); + + // default for all apis + + return SAI_LOG_LEVEL_NOTICE; +} diff --git a/meta/SaiInterface.h b/meta/SaiInterface.h index ba9b16e9a..fdd55ac00 100644 --- a/meta/SaiInterface.h +++ b/meta/SaiInterface.h @@ -316,5 +316,10 @@ namespace sairedis virtual sai_status_t logSet( _In_ sai_api_t api, _In_ sai_log_level_t log_level) = 0; + + public: // non SAI API + + virtual sai_log_level_t logGet( + _In_ sai_api_t api); }; } diff --git a/syncd/SaiDiscovery.cpp b/syncd/SaiDiscovery.cpp index a241fabdb..7f88846d9 100644 --- a/syncd/SaiDiscovery.cpp +++ b/syncd/SaiDiscovery.cpp @@ -264,11 +264,13 @@ std::set SaiDiscovery::discover( { SWSS_LOG_TIMER("discover"); + auto levels = getApiLogLevel(); + setApiLogLevel(SAI_LOG_LEVEL_CRITICAL); discover(startRid, discovered_rids); - setApiLogLevel(SAI_LOG_LEVEL_NOTICE); + setApiLogLevel(levels); } SWSS_LOG_NOTICE("discovered objects count: %zu", discovered_rids.size()); @@ -313,7 +315,7 @@ void SaiDiscovery::setApiLogLevel( if (status == SAI_STATUS_SUCCESS) { - SWSS_LOG_NOTICE("Setting SAI loglevel %s on %s", + SWSS_LOG_INFO("setting SAI loglevel %s on %s", sai_serialize_log_level(logLevel).c_str(), sai_serialize_api((sai_api_t)api).c_str()); } @@ -323,3 +325,47 @@ void SaiDiscovery::setApiLogLevel( } } } + +void SaiDiscovery::setApiLogLevel( + _In_ const std::map& levels) +{ + SWSS_LOG_ENTER(); + + // We start from 1 since 0 is SAI_API_UNSPECIFIED. + + for (uint32_t api = 1; api < sai_metadata_enum_sai_api_t.valuescount; ++api) + { + auto it = levels.find((sai_api_t)api); + + sai_log_level_t logLevel = (it == levels.end()) ? SAI_LOG_LEVEL_NOTICE : it->second; + + sai_status_t status = m_sai->logSet((sai_api_t)api, logLevel); + + if (status == SAI_STATUS_SUCCESS) + { + SWSS_LOG_INFO("setting SAI loglevel %s on %s", + sai_serialize_log_level(logLevel).c_str(), + sai_serialize_api((sai_api_t)api).c_str()); + } + else + { + SWSS_LOG_INFO("set loglevel failed: %s", sai_serialize_status(status).c_str()); + } + } +} + +std::map SaiDiscovery::getApiLogLevel() +{ + SWSS_LOG_ENTER(); + + std::map levels; + + // We start from 1 since 0 is SAI_API_UNSPECIFIED. + + for (uint32_t api = 1; api < sai_metadata_enum_sai_api_t.valuescount; ++api) + { + levels[(sai_api_t)api] = m_sai->logGet((sai_api_t)api); + } + + return levels; +} diff --git a/syncd/SaiDiscovery.h b/syncd/SaiDiscovery.h index a5d02f1de..c48372b08 100644 --- a/syncd/SaiDiscovery.h +++ b/syncd/SaiDiscovery.h @@ -4,6 +4,7 @@ #include #include +#include #include namespace syncd @@ -50,6 +51,11 @@ namespace syncd void setApiLogLevel( _In_ sai_log_level_t logLevel); + void setApiLogLevel( + _In_ const std::map& levels); + + std::map getApiLogLevel(); + private: std::shared_ptr m_sai; diff --git a/syncd/VendorSai.cpp b/syncd/VendorSai.cpp index 7aaf58805..a0234aa7d 100644 --- a/syncd/VendorSai.cpp +++ b/syncd/VendorSai.cpp @@ -1681,5 +1681,24 @@ sai_status_t VendorSai::logSet( { SWSS_LOG_ENTER(); + m_logLevelMap[api] = log_level; + return m_globalApis.log_set(api, log_level); } + +sai_log_level_t VendorSai::logGet( + _In_ sai_api_t api) +{ + SWSS_LOG_ENTER(); + + auto it = m_logLevelMap.find(api); + + if (it != m_logLevelMap.end()) + { + return it->second; + } + + // no level defined yet, just return default + + return SAI_LOG_LEVEL_NOTICE; +} diff --git a/syncd/VendorSai.h b/syncd/VendorSai.h index b64a34fda..7a6c4937f 100644 --- a/syncd/VendorSai.h +++ b/syncd/VendorSai.h @@ -10,6 +10,7 @@ extern "C" { #include #include #include +#include namespace syncd { @@ -201,6 +202,11 @@ namespace syncd _In_ sai_api_t api, _In_ sai_log_level_t log_level) override; + public: // extra API + + virtual sai_log_level_t logGet( + _In_ sai_api_t api) override; + private: bool m_apiInitialized; @@ -212,5 +218,7 @@ namespace syncd sai_apis_t m_apis; sai_global_apis_t m_globalApis; + + std::map m_logLevelMap; }; } diff --git a/syncd/scripts/saidump.sh b/syncd/scripts/saidump.sh new file mode 100755 index 000000000..034322ff3 --- /dev/null +++ b/syncd/scripts/saidump.sh @@ -0,0 +1,39 @@ +#!/bin/bash +set -e + +save_saidump_by_rdb() +{ + local filepath="/var/run/redis/sonic-db/database_config.json" + + # Get hostname, port, redis directory + local redis_config=$(python3 -c " +import json +with open('$filepath') as json_file: + data = json.load(json_file) + print(data['INSTANCES']['redis']['hostname'], data['INSTANCES']['redis']['port'], data['INSTANCES']['redis']['unix_socket_path'])") + + # split + redis_config=(${redis_config// / }) + local hostname=${redis_config[0]} + local port=${redis_config[1]} + local redis_dir=`dirname ${redis_config[2]}` + logger "saidump.sh: hostname:$hostname, port:$port, redis_dir:$redis_dir" + + logger "saidump.sh: [1] Config Redis consistency directory." + redis-cli -h $hostname -p $port CONFIG SET dir $redis_dir > /dev/null + + logger "saidump.sh: [2] SAVE." + redis-cli -h $hostname -p $port SAVE > /dev/null + + logger "saidump.sh: [3] Run rdb command to convert the dump files into JSON files." + rdb --command json $redis_dir/dump.rdb | tee $redis_dir/dump.json > /dev/null + + logger "saidump.sh: [4] Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump's result in standard output." + saidump -r $redis_dir/dump.json -m 100 + + logger "saidump.sh: [5] Clear the temporary files." + rm -f $redis_dir/dump.rdb + rm -f $redis_dir/dump.json +} + +save_saidump_by_rdb \ No newline at end of file diff --git a/vslib/SwitchMLNX2700.cpp b/vslib/SwitchMLNX2700.cpp index 651819b51..39994ec27 100644 --- a/vslib/SwitchMLNX2700.cpp +++ b/vslib/SwitchMLNX2700.cpp @@ -460,13 +460,14 @@ sai_status_t SwitchMLNX2700::queryTunnelPeerModeCapability( } sai_status_t SwitchMLNX2700::queryPortAutonegFecOverrideSupportCapability( - _Out_ sai_attr_capability_t *capability) + _Out_ sai_attr_capability_t *attr_capability) { SWSS_LOG_ENTER(); - capability->create_implemented = true; - capability->set_implemented = true; - capability->get_implemented = true; + attr_capability->create_implemented = true; + attr_capability->set_implemented = true; + attr_capability->get_implemented = true; + return SAI_STATUS_SUCCESS; } diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index c4fa76cf0..7ec74a493 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -2382,6 +2382,9 @@ sai_status_t SwitchStateBase::refresh_read_only( return SAI_STATUS_SUCCESS; case SAI_PORT_ATTR_FABRIC_ATTACHED: + case SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_ID: + case SAI_PORT_ATTR_FABRIC_ATTACHED_PORT_INDEX: + case SAI_PORT_ATTR_HW_LANE_LIST: return SAI_STATUS_SUCCESS; case SAI_PORT_ATTR_PORT_SERDES_ID: @@ -3429,7 +3432,7 @@ sai_status_t SwitchStateBase::create_fabric_ports() sai_attribute_t attr; attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED; - attr.value.booldata = false; + attr.value.booldata = true; CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, fabric_port_id, &attr)); @@ -3445,6 +3448,14 @@ sai_status_t SwitchStateBase::create_fabric_ports() attr.value.s32 = SAI_PORT_TYPE_FABRIC; CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, fabric_port_id, &attr)); + + attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED_SWITCH_ID; + attr.value.s32 = i; + CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, fabric_port_id, &attr)); + + attr.id = SAI_PORT_ATTR_FABRIC_ATTACHED_PORT_INDEX; + attr.value.s32 = i; + CHECK_STATUS(set(SAI_OBJECT_TYPE_PORT, fabric_port_id, &attr)); } return SAI_STATUS_SUCCESS; @@ -3642,13 +3653,14 @@ sai_status_t SwitchStateBase::queryTunnelPeerModeCapability( } sai_status_t SwitchStateBase::queryPortAutonegFecOverrideSupportCapability( - _Out_ sai_attr_capability_t *capability) + _Out_ sai_attr_capability_t *attr_capability) { SWSS_LOG_ENTER(); - capability->create_implemented = false; - capability->set_implemented = false; - capability->get_implemented = false; + attr_capability->create_implemented = false; + attr_capability->set_implemented = false; + attr_capability->get_implemented = false; + return SAI_STATUS_SUCCESS; } @@ -3758,17 +3770,18 @@ sai_status_t SwitchStateBase::queryAttributeCapability( _In_ sai_object_id_t switch_id, _In_ sai_object_type_t object_type, _In_ sai_attr_id_t attr_id, - _Out_ sai_attr_capability_t *capability) + _Out_ sai_attr_capability_t *attr_capability) { SWSS_LOG_ENTER(); if (object_type == SAI_OBJECT_TYPE_PORT && attr_id == SAI_PORT_ATTR_AUTO_NEG_FEC_MODE_OVERRIDE) { - return queryPortAutonegFecOverrideSupportCapability(capability); + return queryPortAutonegFecOverrideSupportCapability(attr_capability); } - capability->create_implemented = true; - capability->set_implemented = true; - capability->get_implemented = true; + + attr_capability->create_implemented = true; + attr_capability->set_implemented = true; + attr_capability->get_implemented = true; return SAI_STATUS_SUCCESS; }