Skip to content

Commit 59fedfa

Browse files
authored
[sairedis] Client/Server support SAI fdb flush api (sonic-net#853)
1 parent 5c2aaae commit 59fedfa

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

lib/inc/ServerSai.h

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ namespace sairedis
337337
_In_ const sai_object_id_t* object_ids,
338338
_In_ const sai_status_t* statuses);
339339

340+
// NON QUAD API
341+
342+
sai_status_t processFdbFlush(
343+
_In_ const swss::KeyOpFieldsValuesTuple &kco);
344+
340345
// QUERY API
341346

342347
sai_status_t processAttrCapabilityQuery(

lib/src/ServerSai.cpp

+34-4
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,10 @@ sai_status_t ServerSai::processSingleEvent(
697697
//
698698
// if (op == REDIS_ASIC_STATE_COMMAND_CLEAR_STATS)
699699
// return processClearStatsEvent(kco);
700-
//
701-
// if (op == REDIS_ASIC_STATE_COMMAND_FLUSH)
702-
// return processFdbFlush(kco);
703-
//
700+
701+
if (op == REDIS_ASIC_STATE_COMMAND_FLUSH)
702+
return processFdbFlush(kco);
703+
704704
if (op == REDIS_ASIC_STATE_COMMAND_ATTR_CAPABILITY_QUERY)
705705
return processAttrCapabilityQuery(kco);
706706

@@ -1707,3 +1707,33 @@ sai_status_t ServerSai::processObjectTypeGetAvailabilityQuery(
17071707

17081708
return status;
17091709
}
1710+
1711+
sai_status_t ServerSai::processFdbFlush(
1712+
_In_ const swss::KeyOpFieldsValuesTuple &kco)
1713+
{
1714+
SWSS_LOG_ENTER();
1715+
1716+
auto& key = kfvKey(kco);
1717+
auto strSwitchOid = key.substr(key.find(":") + 1);
1718+
1719+
sai_object_id_t switchOid;
1720+
sai_deserialize_object_id(strSwitchOid, switchOid);
1721+
1722+
auto& values = kfvFieldsValues(kco);
1723+
1724+
for (const auto &v: values)
1725+
{
1726+
SWSS_LOG_DEBUG("attr: %s: %s", fvField(v).c_str(), fvValue(v).c_str());
1727+
}
1728+
1729+
SaiAttributeList list(SAI_OBJECT_TYPE_FDB_FLUSH, values, false);
1730+
1731+
sai_attribute_t *attr_list = list.get_attr_list();
1732+
uint32_t attr_count = list.get_attr_count();
1733+
1734+
sai_status_t status = m_sai->flushFdbEntries(switchOid, attr_count, attr_list);
1735+
1736+
m_selectableChannel->set(sai_serialize_status(status), {} , REDIS_ASIC_STATE_COMMAND_FLUSHRESPONSE);
1737+
1738+
return status;
1739+
}

tests/testclient.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class TestClient
2525

2626
void test_query_api();
2727

28+
void test_fdb_flush();
29+
2830
private:
2931

3032
int profileGetNextValue(
@@ -411,6 +413,50 @@ void TestClient::test_query_api()
411413
ASSERT_SUCCESS(sai_api_uninitialize());
412414
}
413415

416+
void TestClient::test_fdb_flush()
417+
{
418+
SWSS_LOG_ENTER();
419+
420+
m_profileMap.clear();
421+
422+
m_profileMap[SAI_REDIS_KEY_ENABLE_CLIENT] = "true"; // act as a client
423+
424+
m_profileIter = m_profileMap.begin();
425+
426+
m_smt.profileGetValue = std::bind(&TestClient::profileGetValue, this, _1, _2);
427+
m_smt.profileGetNextValue = std::bind(&TestClient::profileGetNextValue, this, _1, _2, _3);
428+
429+
m_test_services = m_smt.getServiceMethodTable();
430+
431+
ASSERT_SUCCESS(sai_api_initialize(0, &m_test_services));
432+
433+
sai_switch_api_t* switch_api;
434+
435+
ASSERT_SUCCESS(sai_api_query(SAI_API_SWITCH, (void**)&switch_api));
436+
437+
sai_attribute_t attr;
438+
439+
// connect to existing switch
440+
attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
441+
attr.value.booldata = false;
442+
443+
sai_object_id_t switch_id = SAI_NULL_OBJECT_ID;
444+
445+
ASSERT_SUCCESS(switch_api->create_switch(&switch_id, 1, &attr));
446+
447+
ASSERT_TRUE(switch_id != SAI_NULL_OBJECT_ID);
448+
449+
SWSS_LOG_NOTICE("switchId: %s", sai_serialize_object_id(switch_id).c_str());
450+
451+
sai_fdb_api_t* fdb_api;
452+
453+
ASSERT_SUCCESS(sai_api_query(SAI_API_FDB, (void**)&fdb_api));
454+
455+
ASSERT_SUCCESS(fdb_api->flush_fdb_entries(switch_id, 0, NULL));
456+
457+
ASSERT_SUCCESS(sai_api_uninitialize());
458+
}
459+
414460
int main()
415461
{
416462
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG);
@@ -427,5 +473,7 @@ int main()
427473

428474
tc.test_query_api();
429475

476+
tc.test_fdb_flush();
477+
430478
return EXIT_SUCCESS;
431479
}

0 commit comments

Comments
 (0)