Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into ledamping_1
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish1805 authored Oct 21, 2023
2 parents 4047de8 + 65323ca commit 41bd8d8
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 16 deletions.
10 changes: 10 additions & 0 deletions meta/SaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions meta/SaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
50 changes: 48 additions & 2 deletions syncd/SaiDiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,13 @@ std::set<sai_object_id_t> 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());
Expand Down Expand Up @@ -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());
}
Expand All @@ -323,3 +325,47 @@ void SaiDiscovery::setApiLogLevel(
}
}
}

void SaiDiscovery::setApiLogLevel(
_In_ const std::map<sai_api_t, sai_log_level_t>& 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<sai_api_t, sai_log_level_t> SaiDiscovery::getApiLogLevel()
{
SWSS_LOG_ENTER();

std::map<sai_api_t, sai_log_level_t> 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;
}
6 changes: 6 additions & 0 deletions syncd/SaiDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <memory>
#include <set>
#include <map>
#include <unordered_map>

namespace syncd
Expand Down Expand Up @@ -50,6 +51,11 @@ namespace syncd
void setApiLogLevel(
_In_ sai_log_level_t logLevel);

void setApiLogLevel(
_In_ const std::map<sai_api_t, sai_log_level_t>& levels);

std::map<sai_api_t, sai_log_level_t> getApiLogLevel();

private:

std::shared_ptr<sairedis::SaiInterface> m_sai;
Expand Down
19 changes: 19 additions & 0 deletions syncd/VendorSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions syncd/VendorSai.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C" {
#include <vector>
#include <memory>
#include <mutex>
#include <map>

namespace syncd
{
Expand Down Expand Up @@ -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;
Expand All @@ -212,5 +218,7 @@ namespace syncd
sai_apis_t m_apis;

sai_global_apis_t m_globalApis;

std::map<sai_api_t, sai_log_level_t> m_logLevelMap;
};
}
39 changes: 39 additions & 0 deletions syncd/scripts/saidump.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 5 additions & 4 deletions vslib/SwitchMLNX2700.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
33 changes: 23 additions & 10 deletions vslib/SwitchStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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));

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

0 comments on commit 41bd8d8

Please sign in to comment.