Skip to content

Commit

Permalink
Revert "[syncd] Introduce VendorSaiOptions class (sonic-net#1472)"
Browse files Browse the repository at this point in the history
This reverts commit 7835026.
  • Loading branch information
yxieca committed Dec 5, 2024
1 parent 8ba9448 commit 0901dd7
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 134 deletions.
17 changes: 0 additions & 17 deletions meta/SaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,20 +378,3 @@ 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: 0 additions & 19 deletions meta/SaiInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ 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 @@ -346,18 +340,5 @@ 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: 0 additions & 11 deletions meta/SaiOptions.h

This file was deleted.

9 changes: 6 additions & 3 deletions syncd/HardReiniter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ 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_ std::shared_ptr<NotificationHandler> handler,
_In_ bool checkAttrVersion):
m_vendorSai(sai),
m_translator(translator),
m_client(client),
m_handler(handler)
m_handler(handler),
m_checkAttrVersion(checkAttrVersion)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -99,7 +101,8 @@ 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);
kvp.second,
m_checkAttrVersion);

sr->hardReinit();

Expand Down
5 changes: 4 additions & 1 deletion syncd/HardReiniter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ 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_ std::shared_ptr<NotificationHandler> handler,
_In_ bool checkAttrVersion);

virtual ~HardReiniter();

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

std::shared_ptr<NotificationHandler> m_handler;

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

#include "swss/logger.h"

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

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

if (status == SAI_STATUS_SUCCESS)
{
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.enable(checkAttrVersion);
m_attrVersionChecker.setSaiApiVersion(version);

SWSS_LOG_NOTICE("check attr version %s, libsai api version: %lu",
(vso->m_checkAttrVersion ? "ENABLED" : "DISABLED"),
version);
SWSS_LOG_NOTICE("check attr version ENABLED, libsai api version: %lu", version);
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion syncd/SaiDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace syncd
public:

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

virtual ~SaiDiscovery();

Expand Down
10 changes: 6 additions & 4 deletions syncd/SaiSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ 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 warmBoot,
_In_ bool checkAttrVersion):
SaiSwitchInterface(switch_vid, switch_rid),
m_vendorSai(vendorSai),
m_warmBoot(warmBoot),
m_translator(translator),
m_client(client)
m_client(client),
m_checkAttrVersion(checkAttrVersion)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -661,7 +663,7 @@ void SaiSwitch::helperDiscover()
{
SWSS_LOG_ENTER();

SaiDiscovery sd(m_vendorSai);
SaiDiscovery sd(m_vendorSai, m_checkAttrVersion);

m_discovered_rids = sd.discover(m_switch_rid);

Expand Down Expand Up @@ -952,7 +954,7 @@ void SaiSwitch::onPostPortCreate(
{
SWSS_LOG_ENTER();

SaiDiscovery sd(m_vendorSai);
SaiDiscovery sd(m_vendorSai, m_checkAttrVersion);

auto discovered = sd.discover(port_rid);

Expand Down
5 changes: 4 additions & 1 deletion syncd/SaiSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ 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 warmBoot,
_In_ bool checkAttrVersion);

virtual ~SaiSwitch() = default;

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

std::shared_ptr<RedisClient> m_client;

bool m_checkAttrVersion;
};
}
8 changes: 5 additions & 3 deletions syncd/SingleReiniter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ SingleReiniter::SingleReiniter(
_In_ std::shared_ptr<NotificationHandler> handler,
_In_ const ObjectIdMap& vidToRidMap,
_In_ const ObjectIdMap& ridToVidMap,
_In_ const std::vector<std::string>& asicKeys):
_In_ const std::vector<std::string>& asicKeys,
_In_ bool checkAttrVersion):
m_vendorSai(sai),
m_vidToRidMap(vidToRidMap),
m_ridToVidMap(ridToVidMap),
m_asicKeys(asicKeys),
m_translator(translator),
m_client(client),
m_handler(handler)
m_handler(handler),
m_checkAttrVersion(checkAttrVersion)
{
SWSS_LOG_ENTER();

Expand Down Expand Up @@ -317,7 +319,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_sw = std::make_shared<SaiSwitch>(m_switch_vid, m_switch_rid, m_client, m_translator, m_vendorSai, false, m_checkAttrVersion);

/*
* We processed switch. We have switch vid/rid so we can process all
Expand Down
5 changes: 4 additions & 1 deletion syncd/SingleReiniter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace syncd
_In_ std::shared_ptr<NotificationHandler> handler,
_In_ const ObjectIdMap& vidToRidMap,
_In_ const ObjectIdMap& ridToVidMap,
_In_ const std::vector<std::string>& asicKeys);
_In_ const std::vector<std::string>& asicKeys,
_In_ bool checkAttrVersion);

virtual ~SingleReiniter();

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

std::shared_ptr<NotificationHandler> m_handler;

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

#include "sairediscommon.h"

Expand Down Expand Up @@ -110,12 +109,6 @@ 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 @@ -3143,7 +3136,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_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, objectRid, m_client, m_translator, m_vendorSai, false, m_commandLineOptions->m_enableAttrVersionCheck);

m_mdioIpcServer->setSwitchId(objectRid);

Expand Down Expand Up @@ -4360,7 +4353,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);
HardReiniter hr(m_client, m_translator, m_vendorSai, m_handler, m_commandLineOptions->m_enableAttrVersionCheck);

m_switches = hr.hardReinit();

Expand Down Expand Up @@ -4462,7 +4455,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_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, switchRid, m_client, m_translator, m_vendorSai, false, m_commandLineOptions->m_enableAttrVersionCheck);

m_mdioIpcServer->setSwitchId(switchRid);

Expand Down Expand Up @@ -4646,7 +4639,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);
auto sw = m_switches[switchVid] = std::make_shared<SaiSwitch>(switchVid, switchRid, m_client, m_translator, m_vendorSai, true, m_commandLineOptions->m_enableAttrVersionCheck);

startDiagShell(switchRid);
}
Expand Down
17 changes: 0 additions & 17 deletions syncd/VendorSaiOptions.h

This file was deleted.

1 change: 0 additions & 1 deletion tests/aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,3 @@ submodule
Enqueue
deque
apiversion
vso
34 changes: 0 additions & 34 deletions unittest/meta/TestSaiInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,37 +117,3 @@ 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<Opt>());
}

TEST(SaiInterface, getOptions)
{
DummySaiInterface ds;

auto opt = std::make_shared<Opt>();

opt->i = 42;

ds.setOptions("key", opt);

auto o = std::dynamic_pointer_cast<Opt>(ds.getOptions("key"));

EXPECT_NE(o, nullptr);

EXPECT_EQ(o->i, 42);

EXPECT_EQ(ds.getOptions("foo"), nullptr);
}

0 comments on commit 0901dd7

Please sign in to comment.