Skip to content

Commit

Permalink
[Dash] Handle FC update for existing ENI objects
Browse files Browse the repository at this point in the history
Signed-off-by: vkarri <vkarri@nvidia.com>
  • Loading branch information
vivekrnv committed Nov 13, 2024
1 parent ea3e76f commit 56c29ca
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
29 changes: 21 additions & 8 deletions orchagent/dash/dashorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,33 +965,46 @@ void DashOrch::removeEniFromFC(sai_object_id_t oid, const string &name)

m_eni_name_table->hdel("", name);
m_eni_stat_manager.clearCounterIdList(oid);
SWSS_LOG_DEBUG("Unregistered eni %s to Flex counter", name.c_str());
SWSS_LOG_INFO("Unregistering FC for %s, id: %s", name.c_str(), sai_serialize_object_id(oid).c_str());
}

void DashOrch::clearEniFCStats()
void DashOrch::refreshEniFCStats(bool install)
{
for (auto it = eni_entries_.begin(); it != eni_entries_.end(); it++)
{
removeEniFromFC(it->second.eni_id, it->first);
if (install)
{
addEniToFC(it->second.eni_id, it->first);
}
else
{
removeEniFromFC(it->second.eni_id, it->first);
}
}
}

void DashOrch::handleFCStatusUpdate(bool enabled)
{
if (!enabled && m_eni_fc_status)
bool prev_enabled = m_eni_fc_status;
m_eni_fc_status = enabled; /* Update the status */
if (!enabled && prev_enabled)
{
m_fc_update_timer->stop();
clearEniFCStats();
refreshEniFCStats(false); /* Clear any existing FC entries */
}
else if (enabled && !m_eni_fc_status)
else if (enabled && !prev_enabled)
{
refreshEniFCStats(true);
m_fc_update_timer->start();
}
m_eni_fc_status = enabled;
}

void DashOrch::addEniToFC(sai_object_id_t oid, const string &name)
{
if (!m_eni_fc_status)
{
return ;
}
auto was_empty = m_eni_stat_work_queue.empty();
m_eni_stat_work_queue[oid] = name;
if (was_empty)
Expand All @@ -1017,7 +1030,7 @@ void DashOrch::doTask(SelectableTimer &timer)

if (!gTraditionalFlexCounter || m_vid_to_rid_table->hget("", id, value))
{
SWSS_LOG_INFO("Registering %s, id %s", it->second.c_str(), id.c_str());
SWSS_LOG_INFO("Registering FC for ENI: %s, id %s", it->second.c_str(), id.c_str());
std::vector<FieldValueTuple> eniNameFvs;
eniNameFvs.emplace_back(it->second, id);
m_eni_name_table->set("", eniNameFvs);
Expand Down
2 changes: 1 addition & 1 deletion orchagent/dash/dashorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ class DashOrch : public ZmqOrch
void doTask(swss::SelectableTimer&);
void addEniToFC(sai_object_id_t oid, const std::string& name);
void removeEniFromFC(sai_object_id_t oid, const std::string& name);
void clearEniFCStats();
void refreshEniFCStats(bool);
};
31 changes: 31 additions & 0 deletions tests/mock_tests/flexcounter_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "json.h"
#include "ut_helper.h"
#include "mock_orchagent_main.h"
#include "mock_orch_test.h"
#include "dashorch.h"
#include "mock_table.h"
#include "notifier.h"
#define private public
Expand Down Expand Up @@ -842,4 +844,33 @@ namespace flexcounter_test
std::make_tuple(true, true),
std::make_tuple(true, false))
);

using namespace mock_orch_test;
class EniStatFlexCounterTest : public MockOrchTest
{
virtual void PostSetUp() {
_hook_sai_switch_api();
}

virtual void PreTearDown() {
_unhook_sai_switch_api();
}
};

TEST_F(EniStatFlexCounterTest, TestStatusUpdate)
{
/* Add a mock ENI */
EniEntry tmp_entry;
tmp_entry.eni_id = 0x7008000000020;
m_DashOrch->eni_entries_["497f23d7-f0ac-4c99-a98f-59b470e8c7b"] = tmp_entry;

/* Should create ENI Counter stats for existing ENI's */
m_DashOrch->handleFCStatusUpdate(true);
m_DashOrch->doTask(*(m_DashOrch->m_fc_update_timer));
ASSERT_TRUE(checkFlexCounter(ENI_STAT_COUNTER_FLEX_COUNTER_GROUP, tmp_entry.eni_id, ENI_COUNTER_ID_LIST));

/* This should delete the STATS */
m_DashOrch->handleFCStatusUpdate(false);
ASSERT_FALSE(checkFlexCounter(ENI_STAT_COUNTER_FLEX_COUNTER_GROUP, tmp_entry.eni_id, ENI_COUNTER_ID_LIST));
}
}

0 comments on commit 56c29ca

Please sign in to comment.