Skip to content

Commit

Permalink
Add db channel from context config to VS
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent 330c561 commit 3c3b369
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
6 changes: 4 additions & 2 deletions vslib/ContextConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ using namespace saivs;

ContextConfig::ContextConfig(
_In_ uint32_t guid,
_In_ const std::string& name):
_In_ const std::string& name,
_In_ const std::string& dbAsic):
m_guid(guid),
m_name(name)
m_name(name),
m_dbAsic(dbAsic)
{
SWSS_LOG_ENTER();

Expand Down
5 changes: 4 additions & 1 deletion vslib/ContextConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace saivs

ContextConfig(
_In_ uint32_t guid,
_In_ const std::string& name);
_In_ const std::string& name,
_In_ const std::string& dbAsic);

virtual ~ContextConfig();

Expand All @@ -26,6 +27,8 @@ namespace saivs

std::string m_name;

std::string m_dbAsic; // unit tests channel

std::shared_ptr<SwitchConfigContainer> m_scc;
};
}
8 changes: 5 additions & 3 deletions vslib/ContextConfigContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ std::shared_ptr<ContextConfigContainer> ContextConfigContainer::getDefault()

auto ccc = std::make_shared<ContextConfigContainer>();

auto cc = std::make_shared<ContextConfig>(0, "VirtualSwitch");
auto cc = std::make_shared<ContextConfig>(0, "VirtualSwitch", "ASIC_DB");

auto sc = std::make_shared<SwitchConfig>(0, "");

Expand Down Expand Up @@ -98,9 +98,11 @@ std::shared_ptr<ContextConfigContainer> ContextConfigContainer::loadFromFile(

const std::string& name = item["name"];

SWSS_LOG_NOTICE("contextConfig: guid: %u, name: %s", guid, name.c_str());
const std::string& dbAsic = item["dbAsic"];

auto cc = std::make_shared<ContextConfig>(guid, name);
SWSS_LOG_NOTICE("contextConfig: guid: %u, name: %s, dbAsic: %s", guid, name.c_str(), dbAsic.c_str());

auto cc = std::make_shared<ContextConfig>(guid, name, dbAsic);

for (size_t k = 0; k < item["switches"].size(); k++)
{
Expand Down
14 changes: 8 additions & 6 deletions vslib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Sai::Sai()
m_eventQueueThreadRun = false;

m_apiInitialized = false;

m_globalContext = 0;
}

Sai::~Sai()
Expand Down Expand Up @@ -154,19 +156,19 @@ sai_status_t Sai::initialize(

auto cstrGlobalContext = service_method_table->profile_get_value(0, SAI_KEY_VS_GLOBAL_CONTEXT);

uint32_t globalContext = 0;
m_globalContext = 0;

if (cstrGlobalContext != nullptr)
{
if (sscanf(cstrGlobalContext, "%u", &globalContext) != 1)
if (sscanf(cstrGlobalContext, "%u", &m_globalContext) != 1)
{
SWSS_LOG_WARN("failed to parse '%s' as uint32 using default globalContext", cstrGlobalContext);

globalContext = 0;
m_globalContext = 0;
}
}

SWSS_LOG_NOTICE("using globalContext = %u", globalContext);
SWSS_LOG_NOTICE("using globalContext = %u", m_globalContext);

auto cstrContextConfig = service_method_table->profile_get_value(0, SAI_KEY_VS_CONTEXT_CONFIG);

Expand All @@ -179,11 +181,11 @@ sai_status_t Sai::initialize(
m_contextMap[cc->m_guid] = context;
}

auto context = getContext(globalContext);
auto context = getContext(m_globalContext);

if (context == nullptr)
{
SWSS_LOG_ERROR("no context defined for global context %u", globalContext);
SWSS_LOG_ERROR("no context defined for global context %u", m_globalContext);

return SAI_STATUS_FAILURE;
}
Expand Down
4 changes: 3 additions & 1 deletion vslib/Sai.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ namespace saivs
_In_ sai_object_id_t objectId,
_In_ const sai_attribute_t *attr);

private: // unittests
protected: // unittests

void startUnittestThread();

Expand Down Expand Up @@ -326,6 +326,8 @@ namespace saivs

std::shared_ptr<CorePortIndexMapContainer> m_corePortIndexMapContainer;

uint32_t m_globalContext;

std::map<uint32_t, std::shared_ptr<Context>> m_contextMap;
};
}
13 changes: 10 additions & 3 deletions vslib/SaiUnittests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ void Sai::startUnittestThread()

m_unittestChannelThreadEvent = std::make_shared<swss::SelectableEvent>();

// TODO may require to pass correct DB information
m_dbNtf = std::make_shared<swss::DBConnector>("ASIC_DB", 0);
auto ctx = getContext(m_globalContext);

m_dbNtf = std::make_shared<swss::DBConnector>(ctx->getContextConfig()->m_dbAsic, 0);

m_unittestChannelNotificationConsumer = std::make_shared<swss::NotificationConsumer>(m_dbNtf.get(), SAI_VS_UNITTEST_CHANNEL);

Expand Down Expand Up @@ -277,7 +278,13 @@ void Sai::handleUnittestChannelOp(

for (const auto &v: values)
{
SWSS_LOG_DEBUG("attr: %s: %s", fvField(v).c_str(), fvValue(v).c_str());
SWSS_LOG_NOTICE("attr: %s: %s", fvField(v).c_str(), fvValue(v).c_str());
}

if (!m_apiInitialized)
{
SWSS_LOG_ERROR("api not initialized but received unittests requsts: op: %s, key: %s", op.c_str(), key.c_str());
return;
}

if (op == SAI_VS_UNITTEST_ENABLE_UNITTESTS)
Expand Down

0 comments on commit 3c3b369

Please sign in to comment.