Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
divyachandralekha committed Nov 29, 2024
1 parent 952734a commit c9be749
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 37 deletions.
38 changes: 38 additions & 0 deletions orchagent/fdborch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions orchagent/fdborch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions orchagent/stporch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion orchagent/stporch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Table> m_stpTable;
Expand Down
39 changes: 6 additions & 33 deletions tests/mock_tests/stporch_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace stporch_test

using ::testing::_;
using ::testing::Return;
using namespace fdb_syncd_flush_test;

class StpOrchTest : public MockOrchTest {
protected:
Expand Down Expand Up @@ -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_,
Expand All @@ -156,50 +157,22 @@ 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);

EXPECT_TRUE(result);
_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
}

0 comments on commit c9be749

Please sign in to comment.