Skip to content

Commit

Permalink
Check if port VID exists in db on flex counter query (sonic-net#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored and lguohan committed Jun 4, 2019
1 parent 37b9dff commit 86e6caf
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,24 @@ sai_object_id_t translate_vid_to_rid(
return rid;
}

bool try_translate_vid_to_rid(
_In_ sai_object_id_t vid,
_Out_ sai_object_id_t& rid)
{
SWSS_LOG_ENTER();

try
{
rid = translate_vid_to_rid(vid);
return true;
}
catch (const std::exception& e)
{
// message was logged already when throwing
return false;
}
}

void translate_list_vid_to_rid(
_In_ sai_object_list_t &element)
{
Expand Down Expand Up @@ -1832,7 +1850,7 @@ std::vector<T> extractCounterIdsGeneric(
counterIdList.push_back(counterId);
}

return std::move(counterIdList);
return counterIdList;
}

template <typename T, typename F, typename G>
Expand Down Expand Up @@ -2869,7 +2887,7 @@ void processFlexCounterEvent(
}

const auto &key = kfvKey(kco);
const auto &op = kfvOp(kco);
std::string &op = kfvOp(kco);

std::size_t delimiter = key.find_first_of(":");
if (delimiter == std::string::npos)
Expand All @@ -2883,8 +2901,17 @@ void processFlexCounterEvent(

sai_object_id_t vid = SAI_NULL_OBJECT_ID;
sai_deserialize_object_id(vidStr, vid);
sai_object_id_t rid = translate_vid_to_rid(vid);
sai_object_type_t objectType = sai_object_type_query(rid);
sai_object_id_t rid;

if (!try_translate_vid_to_rid(vid, rid))
{
SWSS_LOG_WARN("port VID %s, was not found (probably port was removed/splitted) and will remove from counters now",
sai_serialize_object_id(vid).c_str());

op = DEL_COMMAND;
}

sai_object_type_t objectType = redis_sai_object_type_query(vid); // VID and RID will have the same object type
std::string objectTypeStr = sai_serialize_object_type(objectType);

if (op == DEL_COMMAND)
Expand Down

0 comments on commit 86e6caf

Please sign in to comment.