Skip to content

Commit

Permalink
orchagent: Fixing resolveFieldRefValue() bug multiple fields with sam…
Browse files Browse the repository at this point in the history
…e name (sonic-net#125)
  • Loading branch information
Shuotian Cheng authored Nov 4, 2016
1 parent bde9154 commit 20116a1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions orchagent/orch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ bool Orch::execute(string tableName)
bool Orch::parseReference(type_map &type_maps, string &ref_in, string &type_name, string &object_name)
{
SWSS_LOG_ENTER();

SWSS_LOG_DEBUG("input:%s", ref_in.c_str());
if (ref_in.size() < 3)
{
Expand Down Expand Up @@ -168,15 +169,16 @@ ref_resolve_status Orch::resolveFieldRefValue(
sai_object_id_t &sai_object)
{
SWSS_LOG_ENTER();
size_t count = 0;

bool hit = false;
for (auto i = kfvFieldsValues(tuple).begin(); i != kfvFieldsValues(tuple).end(); i++)
{
if (fvField(*i) == field_name)
{
SWSS_LOG_DEBUG("field:%s, value:%s", fvField(*i).c_str(), fvValue(*i).c_str());
if (count > 1)
if (hit)
{
SWSS_LOG_ERROR("Singleton field with name:%s must have only 1 instance, actual count:%d\n", field_name.c_str(), count);
SWSS_LOG_ERROR("Multiple same fields %s", field_name.c_str());
return ref_resolve_status::multiple_instances;
}
string ref_type_name, object_name;
Expand All @@ -185,12 +187,11 @@ ref_resolve_status Orch::resolveFieldRefValue(
return ref_resolve_status::not_resolved;
}
sai_object = (*(type_maps[ref_type_name]))[object_name];
count++;
hit = true;
}
}
if (0 == count)
if (!hit)
{
SWSS_LOG_NOTICE("field with name:%s not found\n", field_name.c_str());
return ref_resolve_status::field_not_found;
}
return ref_resolve_status::success;
Expand Down

0 comments on commit 20116a1

Please sign in to comment.