Skip to content

Commit

Permalink
[sairedis] Fail get/clear api on objects created in init view mode (#930
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kcudnik authored and judyjoseph committed Oct 6, 2021
1 parent 2f5588c commit 3e8f83b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 55 additions & 1 deletion syncd/Syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,17 @@ sai_status_t Syncd::processClearStatsEvent(
sai_object_meta_key_t metaKey;
sai_deserialize_object_meta_key(key, metaKey);

if (isInitViewMode() && m_createdInInitView.find(metaKey.objectkey.key.object_id) != m_createdInInitView.end())
{
SWSS_LOG_WARN("CLEAR STATS api can't be used on %s since it's created in INIT_VIEW mode", key.c_str());

sai_status_t status = SAI_STATUS_INVALID_OBJECT_ID;

m_selectableChannel->set(sai_serialize_status(status), {}, REDIS_ASIC_STATE_COMMAND_GETRESPONSE);

return status;
}

if (!m_translator->tryTranslateVidToRid(metaKey))
{
SWSS_LOG_WARN("VID to RID translation failure: %s", key.c_str());
Expand Down Expand Up @@ -671,7 +682,16 @@ sai_status_t Syncd::processGetStatsEvent(
sai_object_meta_key_t metaKey;
sai_deserialize_object_meta_key(key, metaKey);

// TODO get stats on created object in init view mode could fail
if (isInitViewMode() && m_createdInInitView.find(metaKey.objectkey.key.object_id) != m_createdInInitView.end())
{
SWSS_LOG_WARN("GET STATS api can't be used on %s since it's created in INIT_VIEW mode", key.c_str());

sai_status_t status = SAI_STATUS_INVALID_OBJECT_ID;

m_selectableChannel->set(sai_serialize_status(status), {}, REDIS_ASIC_STATE_COMMAND_GETRESPONSE);

return status;
}

m_translator->translateVidToRid(metaKey);

Expand Down Expand Up @@ -863,6 +883,16 @@ sai_status_t Syncd::processBulkQuadEventInInitViewMode(

syncUpdateRedisBulkQuadEvent(api, statuses, objectType, objectIds, strAttributes);

for (auto& str: objectIds)
{
sai_object_id_t objectVid;
sai_deserialize_object_id(str, objectVid);

// in init view mode insert every created object except switch

m_createdInInitView.insert(objectVid);
}

return SAI_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -1457,6 +1487,7 @@ sai_status_t Syncd::processBulkOidCreate(
if (statuses[idx] == SAI_STATUS_SUCCESS)
{
m_translator->insertRidAndVid(objectRids[idx], objectVids[idx]);

SWSS_LOG_INFO("saved VID %s to RID %s",
sai_serialize_object_id(objectVids[idx]).c_str(),
sai_serialize_object_id(objectRids[idx]).c_str());
Expand Down Expand Up @@ -1703,6 +1734,12 @@ sai_status_t Syncd::processQuadInInitViewModeCreate(
{
onSwitchCreateInInitViewMode(objectVid, attr_count, attr_list);
}
else
{
// in init view mode insert every created object except switch

m_createdInInitView.insert(objectVid);
}
}

sendApiResponse(SAI_COMMON_API_CREATE, SAI_STATUS_SUCCESS);
Expand Down Expand Up @@ -1818,6 +1855,19 @@ sai_status_t Syncd::processQuadInInitViewModeGet(
sai_object_id_t objectVid;
sai_deserialize_object_id(strObjectId, objectVid);

if (isInitViewMode() && m_createdInInitView.find(objectVid) != m_createdInInitView.end())
{
SWSS_LOG_WARN("GET api can't be used on %s (%s) since it's created in INIT_VIEW mode",
strObjectId.c_str(),
sai_serialize_object_type(objectType).c_str());

status = SAI_STATUS_INVALID_OBJECT_ID;

sendGetResponse(objectType, strObjectId, switchVid, status, attr_count, attr_list);

return status;
}

switchVid = VidManager::switchIdQuery(objectVid);

SWSS_LOG_DEBUG("generic get (init view) for object type %s:%s",
Expand Down Expand Up @@ -3188,6 +3238,8 @@ sai_status_t Syncd::processNotifySyncd(

clearTempView();

m_createdInInitView.clear();

// NOTE: Currently as WARN to be easier to spot, later should be NOTICE.

SWSS_LOG_WARN("syncd switched to INIT VIEW mode, all op will be saved to TEMP view");
Expand Down Expand Up @@ -3240,6 +3292,8 @@ sai_status_t Syncd::processNotifySyncd(
*/

m_translator->clearLocalCache();

m_createdInInitView.clear();
}
else
{
Expand Down
2 changes: 2 additions & 0 deletions syncd/Syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ namespace syncd
std::shared_ptr<sairedis::ContextConfig> m_contextConfig;

std::shared_ptr<BreakConfig> m_breakConfig;

std::set<sai_object_id_t> m_createdInInitView;
};
}

0 comments on commit 3e8f83b

Please sign in to comment.