Skip to content

Commit

Permalink
[sairedis] Client/Server support SAI fdb flush api (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik authored Jul 5, 2021
1 parent 5c2aaae commit 59fedfa
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/inc/ServerSai.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ namespace sairedis
_In_ const sai_object_id_t* object_ids,
_In_ const sai_status_t* statuses);

// NON QUAD API

sai_status_t processFdbFlush(
_In_ const swss::KeyOpFieldsValuesTuple &kco);

// QUERY API

sai_status_t processAttrCapabilityQuery(
Expand Down
38 changes: 34 additions & 4 deletions lib/src/ServerSai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,10 @@ sai_status_t ServerSai::processSingleEvent(
//
// if (op == REDIS_ASIC_STATE_COMMAND_CLEAR_STATS)
// return processClearStatsEvent(kco);
//
// if (op == REDIS_ASIC_STATE_COMMAND_FLUSH)
// return processFdbFlush(kco);
//

if (op == REDIS_ASIC_STATE_COMMAND_FLUSH)
return processFdbFlush(kco);

if (op == REDIS_ASIC_STATE_COMMAND_ATTR_CAPABILITY_QUERY)
return processAttrCapabilityQuery(kco);

Expand Down Expand Up @@ -1707,3 +1707,33 @@ sai_status_t ServerSai::processObjectTypeGetAvailabilityQuery(

return status;
}

sai_status_t ServerSai::processFdbFlush(
_In_ const swss::KeyOpFieldsValuesTuple &kco)
{
SWSS_LOG_ENTER();

auto& key = kfvKey(kco);
auto strSwitchOid = key.substr(key.find(":") + 1);

sai_object_id_t switchOid;
sai_deserialize_object_id(strSwitchOid, switchOid);

auto& values = kfvFieldsValues(kco);

for (const auto &v: values)
{
SWSS_LOG_DEBUG("attr: %s: %s", fvField(v).c_str(), fvValue(v).c_str());
}

SaiAttributeList list(SAI_OBJECT_TYPE_FDB_FLUSH, values, false);

sai_attribute_t *attr_list = list.get_attr_list();
uint32_t attr_count = list.get_attr_count();

sai_status_t status = m_sai->flushFdbEntries(switchOid, attr_count, attr_list);

m_selectableChannel->set(sai_serialize_status(status), {} , REDIS_ASIC_STATE_COMMAND_FLUSHRESPONSE);

return status;
}
48 changes: 48 additions & 0 deletions tests/testclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class TestClient

void test_query_api();

void test_fdb_flush();

private:

int profileGetNextValue(
Expand Down Expand Up @@ -411,6 +413,50 @@ void TestClient::test_query_api()
ASSERT_SUCCESS(sai_api_uninitialize());
}

void TestClient::test_fdb_flush()
{
SWSS_LOG_ENTER();

m_profileMap.clear();

m_profileMap[SAI_REDIS_KEY_ENABLE_CLIENT] = "true"; // act as a client

m_profileIter = m_profileMap.begin();

m_smt.profileGetValue = std::bind(&TestClient::profileGetValue, this, _1, _2);
m_smt.profileGetNextValue = std::bind(&TestClient::profileGetNextValue, this, _1, _2, _3);

m_test_services = m_smt.getServiceMethodTable();

ASSERT_SUCCESS(sai_api_initialize(0, &m_test_services));

sai_switch_api_t* switch_api;

ASSERT_SUCCESS(sai_api_query(SAI_API_SWITCH, (void**)&switch_api));

sai_attribute_t attr;

// connect to existing switch
attr.id = SAI_SWITCH_ATTR_INIT_SWITCH;
attr.value.booldata = false;

sai_object_id_t switch_id = SAI_NULL_OBJECT_ID;

ASSERT_SUCCESS(switch_api->create_switch(&switch_id, 1, &attr));

ASSERT_TRUE(switch_id != SAI_NULL_OBJECT_ID);

SWSS_LOG_NOTICE("switchId: %s", sai_serialize_object_id(switch_id).c_str());

sai_fdb_api_t* fdb_api;

ASSERT_SUCCESS(sai_api_query(SAI_API_FDB, (void**)&fdb_api));

ASSERT_SUCCESS(fdb_api->flush_fdb_entries(switch_id, 0, NULL));

ASSERT_SUCCESS(sai_api_uninitialize());
}

int main()
{
swss::Logger::getInstance().setMinPrio(swss::Logger::SWSS_DEBUG);
Expand All @@ -427,5 +473,7 @@ int main()

tc.test_query_api();

tc.test_fdb_flush();

return EXIT_SUCCESS;
}

0 comments on commit 59fedfa

Please sign in to comment.