From 9263397112a16808e026a29bc4940f2bdd0c9058 Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Fri, 29 Sep 2023 10:15:22 +0200 Subject: [PATCH 1/5] [syncd] Change sai discovery log priority to info (#1296) When multiple asic are present and multiple ports are created then those log lines willpollute logs for no reason --- syncd/SaiDiscovery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncd/SaiDiscovery.cpp b/syncd/SaiDiscovery.cpp index a241fabdb..7ac75abca 100644 --- a/syncd/SaiDiscovery.cpp +++ b/syncd/SaiDiscovery.cpp @@ -313,7 +313,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()); } From 5450811372aba75e2b01b673144dcc4c983e13e5 Mon Sep 17 00:00:00 2001 From: jfeng-arista <98421150+jfeng-arista@users.noreply.github.com> Date: Sun, 8 Oct 2023 15:12:20 -0700 Subject: [PATCH 2/5] Add fabric ports related calls for vs tests. (#1301) Add fabric ports related calls for vs tests. This is the preparation for adding vs test for fabric daemon ( sonic-net/sonic-swss#2920 ) --- vslib/SwitchStateBase.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/vslib/SwitchStateBase.cpp b/vslib/SwitchStateBase.cpp index c4fa76cf0..3e19b45a6 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; From 7c07d81ba31fbc9b94ff1a028e0df0fba8877cfd Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Tue, 10 Oct 2023 10:29:30 +0300 Subject: [PATCH 3/5] [vslib]: Fix method signatures. (#1299) Signed-off-by: Nazarii Hnydyn --- vslib/SwitchMLNX2700.cpp | 9 +++++---- vslib/SwitchStateBase.cpp | 20 +++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) 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 3e19b45a6..7ec74a493 100644 --- a/vslib/SwitchStateBase.cpp +++ b/vslib/SwitchStateBase.cpp @@ -3653,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; } @@ -3769,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; } From d520642a5482c3e2d82dfac2adbce00c0ed656be Mon Sep 17 00:00:00 2001 From: Kamil Cudnik Date: Tue, 10 Oct 2023 09:30:14 +0200 Subject: [PATCH 4/5] [syncd] Respect each api log level after sai discovery (#1303) Previously log after sai discovery log level was set to NOTICE not respecting actual API log level or what user set via swsslog --- meta/SaiInterface.cpp | 10 +++++++++ meta/SaiInterface.h | 5 +++++ syncd/SaiDiscovery.cpp | 48 +++++++++++++++++++++++++++++++++++++++++- syncd/SaiDiscovery.h | 6 ++++++ syncd/VendorSai.cpp | 19 +++++++++++++++++ syncd/VendorSai.h | 8 +++++++ 6 files changed, 95 insertions(+), 1 deletion(-) 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 7ac75abca..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()); @@ -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; }; } From 65323ca51db8947e8a39db5c9c0ef1fe4b27a59f Mon Sep 17 00:00:00 2001 From: JunhongMao <134556118+JunhongMao@users.noreply.github.com> Date: Tue, 10 Oct 2023 17:36:32 -0400 Subject: [PATCH 5/5] [VOQ][saidump] To move saidump.sh from the sonic-buildimage repo to the sairedis repo (#1298) To fix the issue: sonic-net/sonic-buildimage#13561 The existing saidump use https://github.com/sonic-net/sonic-swss-common/blob/master/common/table_dump.lua script which loops the ASIC_DB more than 5 seconds and blocks other processes access. This solution uses the Redis SAVE command to save the snapshot of DB each time and recover later, instead of looping through each entry in the table. --- syncd/scripts/saidump.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 syncd/scripts/saidump.sh 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