Skip to content

Commit

Permalink
Merge branch 'sonic-net:master' into SAI_DBG_GEN_DUMP_support
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramd authored Dec 5, 2024
2 parents 747da04 + 8ba9448 commit 39fecb1
Show file tree
Hide file tree
Showing 17 changed files with 431 additions and 105 deletions.
17 changes: 17 additions & 0 deletions meta/SaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,20 @@ sai_status_t SaiInterface::clearStats(

return SAI_STATUS_NOT_IMPLEMENTED;
}

std::shared_ptr<SaiOptions> 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<SaiOptions> options)
{
SWSS_LOG_ENTER();

m_optionsMap[key] = options;
}
19 changes: 19 additions & 0 deletions meta/SaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ extern "C" {
#include "saimetadata.h"
}

#include "SaiOptions.h"

#include <map>
#include <memory>
#include <string>

#define SAIREDIS_DECLARE_EVERY_ENTRY(_X) \
SAI_METADATA_DECLARE_EVERY_ENTRY(_X)

Expand Down Expand Up @@ -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<SaiOptions> getOptions(
_In_ const std::string& key);

void setOptions(
_In_ const std::string& key,
_In_ std::shared_ptr<SaiOptions> options);

private:

std::map<std::string, std::shared_ptr<SaiOptions>> m_optionsMap;
};
}
11 changes: 11 additions & 0 deletions meta/SaiOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace sairedis
{
class SaiOptions
{
public:

virtual ~SaiOptions() = default;
};
}
9 changes: 3 additions & 6 deletions syncd/HardReiniter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ HardReiniter::HardReiniter(
_In_ std::shared_ptr<RedisClient> client,
_In_ std::shared_ptr<VirtualOidTranslator> translator,
_In_ std::shared_ptr<sairedis::SaiInterface> sai,
_In_ std::shared_ptr<NotificationHandler> handler,
_In_ bool checkAttrVersion):
_In_ std::shared_ptr<NotificationHandler> handler):
m_vendorSai(sai),
m_translator(translator),
m_client(client),
m_handler(handler),
m_checkAttrVersion(checkAttrVersion)
m_handler(handler)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -101,8 +99,7 @@ std::map<sai_object_id_t, std::shared_ptr<syncd::SaiSwitch>> HardReiniter::hardR
m_handler,
m_switchVidToRid.at(kvp.first),
m_switchRidToVid.at(kvp.first),
kvp.second,
m_checkAttrVersion);
kvp.second);

sr->hardReinit();

Expand Down
5 changes: 1 addition & 4 deletions syncd/HardReiniter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ namespace syncd
_In_ std::shared_ptr<RedisClient> client,
_In_ std::shared_ptr<VirtualOidTranslator> translator,
_In_ std::shared_ptr<sairedis::SaiInterface> sai,
_In_ std::shared_ptr<NotificationHandler> handler,
_In_ bool checkAttrVersion);
_In_ std::shared_ptr<NotificationHandler> handler);

virtual ~HardReiniter();

Expand Down Expand Up @@ -60,7 +59,5 @@ namespace syncd
std::shared_ptr<RedisClient> m_client;

std::shared_ptr<NotificationHandler> m_handler;

bool m_checkAttrVersion;
};
}
14 changes: 10 additions & 4 deletions syncd/SaiDiscovery.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SaiDiscovery.h"
#include "VendorSaiOptions.h"

#include "swss/logger.h"

Expand All @@ -19,8 +20,7 @@ using namespace syncd;
#define SAI_DISCOVERY_LIST_MAX_ELEMENTS 1024

SaiDiscovery::SaiDiscovery(
_In_ std::shared_ptr<sairedis::SaiInterface> sai,
_In_ bool checkAttrVersion):
_In_ std::shared_ptr<sairedis::SaiInterface> sai):
m_sai(sai)
{
SWSS_LOG_ENTER();
Expand All @@ -31,10 +31,16 @@ SaiDiscovery::SaiDiscovery(

if (status == SAI_STATUS_SUCCESS)
{
m_attrVersionChecker.enable(checkAttrVersion);
auto vso = std::dynamic_pointer_cast<VendorSaiOptions>(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
{
Expand Down
3 changes: 1 addition & 2 deletions syncd/SaiDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ namespace syncd
public:

SaiDiscovery(
_In_ std::shared_ptr<sairedis::SaiInterface> sai,
_In_ bool checkAttrVersion);
_In_ std::shared_ptr<sairedis::SaiInterface> sai);

virtual ~SaiDiscovery();

Expand Down
10 changes: 4 additions & 6 deletions syncd/SaiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ SaiSwitch::SaiSwitch(
_In_ std::shared_ptr<RedisClient> client,
_In_ std::shared_ptr<VirtualOidTranslator> translator,
_In_ std::shared_ptr<sairedis::SaiInterface> 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();

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

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

Expand Down
5 changes: 1 addition & 4 deletions syncd/SaiSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ namespace syncd
_In_ std::shared_ptr<RedisClient> client,
_In_ std::shared_ptr<VirtualOidTranslator> translator,
_In_ std::shared_ptr<sairedis::SaiInterface> vendorSai,
_In_ bool warmBoot,
_In_ bool checkAttrVersion);
_In_ bool warmBoot);

virtual ~SaiSwitch() = default;

Expand Down Expand Up @@ -354,7 +353,5 @@ namespace syncd
std::shared_ptr<VirtualOidTranslator> m_translator;

std::shared_ptr<RedisClient> m_client;

bool m_checkAttrVersion;
};
}
8 changes: 3 additions & 5 deletions syncd/SingleReiniter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ SingleReiniter::SingleReiniter(
_In_ std::shared_ptr<NotificationHandler> handler,
_In_ const ObjectIdMap& vidToRidMap,
_In_ const ObjectIdMap& ridToVidMap,
_In_ const std::vector<std::string>& asicKeys,
_In_ bool checkAttrVersion):
_In_ const std::vector<std::string>& 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();

Expand Down Expand Up @@ -319,7 +317,7 @@ void SingleReiniter::processSwitches()
* object, so when doing discover we will get full default ASIC view.
*/

m_sw = std::make_shared<SaiSwitch>(m_switch_vid, m_switch_rid, m_client, m_translator, m_vendorSai, false, m_checkAttrVersion);
m_sw = std::make_shared<SaiSwitch>(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
Expand Down
5 changes: 1 addition & 4 deletions syncd/SingleReiniter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ namespace syncd
_In_ std::shared_ptr<NotificationHandler> handler,
_In_ const ObjectIdMap& vidToRidMap,
_In_ const ObjectIdMap& ridToVidMap,
_In_ const std::vector<std::string>& asicKeys,
_In_ bool checkAttrVersion);
_In_ const std::vector<std::string>& asicKeys);

virtual ~SingleReiniter();

Expand Down Expand Up @@ -137,7 +136,5 @@ namespace syncd
std::shared_ptr<RedisClient> m_client;

std::shared_ptr<NotificationHandler> m_handler;

bool m_checkAttrVersion;
};
}
15 changes: 11 additions & 4 deletions syncd/Syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "RedisNotificationProducer.h"
#include "ZeroMQNotificationProducer.h"
#include "WatchdogScope.h"
#include "VendorSaiOptions.h"

#include "sairediscommon.h"

Expand Down Expand Up @@ -109,6 +110,12 @@ Syncd::Syncd(
m_enableSyncMode = true;
}

auto vso = std::make_shared<VendorSaiOptions>();

vso->m_checkAttrVersion = m_commandLineOptions->m_enableAttrVersionCheck;

m_vendorSai->setOptions(VendorSaiOptions::OPTIONS_KEY, vso);

m_manager = std::make_shared<FlexCounterManager>(m_vendorSai, m_contextConfig->m_dbCounters, m_commandLineOptions->m_supportingBulkCounterGroups);

loadProfileMap();
Expand Down Expand Up @@ -3166,7 +3173,7 @@ sai_status_t Syncd::processOidCreate(
* constructor, like getting all queues, ports, etc.
*/

m_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, objectRid, m_client, m_translator, m_vendorSai, false, m_commandLineOptions->m_enableAttrVersionCheck);
m_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, objectRid, m_client, m_translator, m_vendorSai, false);

m_mdioIpcServer->setSwitchId(objectRid);

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

Expand Down Expand Up @@ -4485,7 +4492,7 @@ void Syncd::onSwitchCreateInInitViewMode(

// make switch initialization and get all default data

m_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, switchRid, m_client, m_translator, m_vendorSai, false, m_commandLineOptions->m_enableAttrVersionCheck);
m_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, switchRid, m_client, m_translator, m_vendorSai, false);

m_mdioIpcServer->setSwitchId(switchRid);

Expand Down Expand Up @@ -4669,7 +4676,7 @@ void Syncd::performWarmRestartSingleSwitch(

// perform all get operations on existing switch

auto sw = m_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, switchRid, m_client, m_translator, m_vendorSai, true, m_commandLineOptions->m_enableAttrVersionCheck);
auto sw = m_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, switchRid, m_client, m_translator, m_vendorSai, true);

startDiagShell(switchRid);
}
Expand Down
17 changes: 17 additions & 0 deletions syncd/VendorSaiOptions.h
Original file line number Diff line number Diff line change
@@ -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;
};
}
Loading

0 comments on commit 39fecb1

Please sign in to comment.