Skip to content

Commit

Permalink
Fix to pass the test SyncdMlnxTest.portBulkAddRemove
Browse files Browse the repository at this point in the history
Normally, setting SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER_GROUP and
SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER should provide a valid switch id.
Fall back to set to all contexts if SAI_NULL_OBJECT_ID is provided.
  • Loading branch information
byu343 committed Oct 2, 2024
1 parent 0c0ae57 commit 8941ffc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/Sai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ sai_status_t Sai::set(

for (auto& kvp: m_contextMap)
{
if (objectType == SAI_OBJECT_TYPE_SWITCH && (attr->id == SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER ||
attr->id == SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER_GROUP))
if (objectType == SAI_OBJECT_TYPE_SWITCH && objectId != SAI_NULL_OBJECT_ID &&
(attr->id == SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER ||
attr->id == SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER_GROUP))
{
if (!kvp.second->m_redisSai->containsSwitch(objectId))
{
Expand Down
10 changes: 5 additions & 5 deletions syncd/tests/TestSyncdMlnx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ TEST_F(SyncdMlnxTest, portBulkAddRemove)
attr.id = SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER_GROUP;
attr.value.ptr = (void*)&flexCounterGroupParam;

status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, &attr);
status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, m_switchId, &attr);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);

std::vector<swss::FieldValueTuple> fvVector, fvVectorExpected;
Expand Down Expand Up @@ -315,15 +315,15 @@ TEST_F(SyncdMlnxTest, portBulkAddRemove)
attr.id = SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER;
attr.value.ptr = (void*)&flexCounterParam;

status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, &attr);
status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, m_switchId, &attr);
ASSERT_EQ(status, SAI_STATUS_FAILURE);
ASSERT_FALSE(m_flexCounterTable->get(key, fvVector));

// Try with a good key
key = "PORT_STAT_COUNTER:" + sai_serialize_object_id(oidList[0]);
flexCounterParam.counter_key.list = (int8_t*)const_cast<char *>(key.c_str());
flexCounterParam.counter_key.count = (uint32_t)key.length();
status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, &attr);
status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, m_switchId, &attr);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);

ASSERT_TRUE(m_flexCounterTable->get(key, fvVector));
Expand All @@ -336,7 +336,7 @@ TEST_F(SyncdMlnxTest, portBulkAddRemove)
flexCounterParam.counter_field_name.count = 0;

// 3. Stop counter polling for the port
status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, &attr);
status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, m_switchId, &attr);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);
ASSERT_FALSE(m_flexCounterTable->get(key, fvVector));

Expand All @@ -351,7 +351,7 @@ TEST_F(SyncdMlnxTest, portBulkAddRemove)
attr.id = SAI_REDIS_SWITCH_ATTR_FLEX_COUNTER_GROUP;
attr.value.ptr = (void*)&flexCounterGroupParam;

status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, SAI_NULL_OBJECT_ID, &attr);
status = m_sairedis->set(SAI_OBJECT_TYPE_SWITCH, m_switchId, &attr);
ASSERT_EQ(status, SAI_STATUS_SUCCESS);
ASSERT_FALSE(m_flexCounterTable->get(key, fvVector));

Expand Down

0 comments on commit 8941ffc

Please sign in to comment.