From c9be7496e2a9949c45dd2e3b643b6dfe2fdab38a Mon Sep 17 00:00:00 2001 From: Divya Chandralekha Date: Fri, 29 Nov 2024 01:03:45 -0800 Subject: [PATCH] Fix errors --- orchagent/fdborch.cpp | 38 ++++++++++++++++++++++++++++++++ orchagent/fdborch.h | 1 + orchagent/stporch.cpp | 6 ++--- orchagent/stporch.h | 1 - tests/mock_tests/stporch_ut.cpp | 39 +++++---------------------------- 5 files changed, 48 insertions(+), 37 deletions(-) diff --git a/orchagent/fdborch.cpp b/orchagent/fdborch.cpp index 03c854fee3..e3f9f67957 100644 --- a/orchagent/fdborch.cpp +++ b/orchagent/fdborch.cpp @@ -1138,6 +1138,44 @@ void FdbOrch::flushFDBEntries(sai_object_id_t bridge_port_oid, } } } +void FdbOrch::flushFdbByVlan(const string &alias, bool flush_static) +{ + sai_status_t status; + Port vlan; + sai_attribute_t vlan_attr[2]; + + if (!m_portsOrch->getPort(alias, vlan)) + { + SWSS_LOG_NOTICE("could not locate vlan from alias %s", alias.c_str()); + return; + } + SWSS_LOG_NOTICE("Start: Flush by vlan %s vlan_oid 0x%lx flush_static %d", + alias.c_str(), vlan.m_vlan_info.vlan_oid, flush_static); + + vlan_attr[0].id = SAI_FDB_FLUSH_ATTR_BV_ID; + vlan_attr[0].value.oid = vlan.m_vlan_info.vlan_oid; + if (!flush_static) + { + vlan_attr[1].id = SAI_FDB_FLUSH_ATTR_ENTRY_TYPE; + vlan_attr[1].value.s32 = SAI_FDB_FLUSH_ENTRY_TYPE_DYNAMIC; + status = sai_fdb_api->flush_fdb_entries(gSwitchId, 2, vlan_attr); + } + else + { + status = sai_fdb_api->flush_fdb_entries(gSwitchId, 1, vlan_attr); + } + if (status != SAI_STATUS_SUCCESS) + { + SWSS_LOG_ERROR("Flush fdb failed, return code %x", status); + } + else + { + SWSS_LOG_NOTICE("End: Flush by vlan %s vlan_oid 0x%lx flush_static %d", + alias.c_str(), vlan.m_vlan_info.vlan_oid, flush_static); + } + + return; +} void FdbOrch::notifyObserversFDBFlush(Port &port, sai_object_id_t& bvid) { diff --git a/orchagent/fdborch.h b/orchagent/fdborch.h index 9e71bc8c6b..e225c64ea0 100644 --- a/orchagent/fdborch.h +++ b/orchagent/fdborch.h @@ -102,6 +102,7 @@ class FdbOrch: public Orch, public Subject, public Observer static const int fdborch_pri; void flushFDBEntries(sai_object_id_t bridge_port_oid, sai_object_id_t vlan_oid); + void flushFdbByVlan(const string &, bool flush_static); void notifyObserversFDBFlush(Port &p, sai_object_id_t&); private: diff --git a/orchagent/stporch.cpp b/orchagent/stporch.cpp index 9ff89f4f3c..39212b4527 100644 --- a/orchagent/stporch.cpp +++ b/orchagent/stporch.cpp @@ -8,8 +8,8 @@ extern sai_stp_api_t *sai_stp_api; extern sai_vlan_api_t *sai_vlan_api; extern sai_switch_api_t *sai_switch_api; -extern FdbOrch *gFdbOrch; -extern PortsOrch* gPortsOrch; +extern FdbOrch *gFdbOrch; +extern PortsOrch *gPortsOrch; extern sai_object_id_t gSwitchId; @@ -368,7 +368,7 @@ bool StpOrch::stpVlanFdbFlush(string vlan_alias) return false; } - //gFdbOrch->flushFdbByVlan(vlan_alias, 0); + gFdbOrch->flushFdbByVlan(vlan_alias, 0); SWSS_LOG_NOTICE("Set STP FDB flush vlan %s ", vlan_alias.c_str()); return true; diff --git a/orchagent/stporch.h b/orchagent/stporch.h index 5b1269602e..154ac7695b 100644 --- a/orchagent/stporch.h +++ b/orchagent/stporch.h @@ -26,7 +26,6 @@ class StpOrch : public Orch bool updateMaxStpInstance(uint32_t max_stp_instance); bool removeStpPorts(Port &port); bool removeVlanFromStpInstance(string vlan, sai_uint16_t stp_instance); - bool stpVlanPortFdbFlush(string port_alias, string vlan_alias); private: unique_ptr m_stpTable; diff --git a/tests/mock_tests/stporch_ut.cpp b/tests/mock_tests/stporch_ut.cpp index 67e0295af2..57291133b1 100644 --- a/tests/mock_tests/stporch_ut.cpp +++ b/tests/mock_tests/stporch_ut.cpp @@ -28,6 +28,7 @@ namespace stporch_test using ::testing::_; using ::testing::Return; + using namespace fdb_syncd_flush_test; class StpOrchTest : public MockOrchTest { protected: @@ -134,7 +135,7 @@ namespace stporch_test bool result; std::cout << "TestAddRemoveStpPort::1 " << std::endl; - EXPECT_TRUE(gPortsOrch->getPort(ETHERNET0, port)); + ASSERT_TRUE(gPortsOrch->getPort(ETHERNET0, port)); std::cout << "TestAddRemoveStpPort::2 " << std::endl; EXPECT_CALL(mock_sai_stp_, @@ -156,10 +157,10 @@ namespace stporch_test EXPECT_TRUE(result); std::cout << "TestAddRemoveStpPort::4 " << std::endl; EXPECT_CALL(mock_sai_stp_, - remove_stp_port(stp_port_oid)).WillOnce(::testing::Return(SAI_STATUS_SUCCESS)); + remove_stp_port(_)).WillOnce(::testing::Return(SAI_STATUS_SUCCESS)); EXPECT_CALL(mock_sai_stp_, - remove_stp(stp_oid)).WillOnce(::testing::Return(SAI_STATUS_SUCCESS)); + remove_stp(_)).WillOnce(::testing::Return(SAI_STATUS_SUCCESS)); std::cout << "TestAddRemoveStpPort::5 " << std::endl; result = stpOrch->removeStpPort(port, stp_instance); @@ -167,39 +168,11 @@ namespace stporch_test _unhook_sai_stp_api(); } } -#if 0 - TEST_F(StpOrchTest, TestRemoveStpPort) { - Port port; - sai_uint16_t stp_instance = 1; - - ASSERT_TRUE(gPortsOrch->getPort(ETHERNET0, port)); - EXPECT_CALL(*mock_sai_stp, - remove_stp_port(_)).WillOnce(::testing::Return(SAI_STATUS_SUCCESS)); - - bool result = stpOrch->removeStpPort(port, stp_instance); - - EXPECT_TRUE(result); - } -} TEST_F(StpOrchTest, TestStpVlanFdbFlush) { string vlan_alias = "Vlan100"; - - EXPECT_CALL(*mock_sai_stp, set_stp_instance_attribute(_, _)).Times(0); - + bool result = stpOrch->stpVlanFdbFlush(vlan_alias); EXPECT_TRUE(result); -} - -TEST_F(StpOrchTest, TestStpVlanPortFdbFlush) { - string port_alias = "Ethernet0"; - string vlan_alias = "Vlan100"; - - EXPECT_CALL(*mock_sai_stp, set_stp_instance_attribute(_, _)).Times(0); - - bool result = stpOrch->stpVlanPortFdbFlush(port_alias, vlan_alias); - - EXPECT_TRUE(result); -} -#endif \ No newline at end of file +} \ No newline at end of file