Skip to content

Commit 191628c

Browse files
authored
Implement fdb flush api in virtual switch and metadata (sonic-net#292)
* Implement fdb flush api in virtual switch and metadata * Fix spelling * Adapt fdb flush to new fdb_entry with bv_id * Add fdb flush unit tests
1 parent a381f56 commit 191628c

File tree

4 files changed

+786
-7
lines changed

4 files changed

+786
-7
lines changed

meta/sai_meta.cpp

+98-1
Original file line numberDiff line numberDiff line change
@@ -4657,6 +4657,86 @@ DECLARE_META_GET_STATS_OID(tunnel);
46574657

46584658
// NOTIFICATIONS
46594659

4660+
static sai_mac_t zero_mac = { 0, 0, 0, 0, 0, 0 };
4661+
4662+
void meta_sai_on_fdb_flush_event_consolidated(
4663+
_In_ const sai_fdb_event_notification_data_t& data)
4664+
{
4665+
SWSS_LOG_ENTER();
4666+
4667+
// since we don't keep objects by type, we need to scan via all objects
4668+
// and find fdb entries
4669+
4670+
auto bpid = sai_metadata_get_attr_by_id(SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID, data.attr_count, data.attr);
4671+
auto type = sai_metadata_get_attr_by_id(SAI_FDB_ENTRY_ATTR_TYPE, data.attr_count, data.attr);
4672+
4673+
SWSS_LOG_NOTICE("processing consolidated fdb flush event of type: %s",
4674+
sai_metadata_get_fdb_entry_type_name((sai_fdb_entry_type_t)type->value.s32));
4675+
4676+
std::vector<sai_object_meta_key_t> toremove;
4677+
4678+
for (auto it = ObjectAttrHash.begin(); it != ObjectAttrHash.end(); ++it)
4679+
{
4680+
const std::string &key_fdb = it->first;
4681+
4682+
if (strstr(key_fdb.c_str(), "bvid") == NULL)
4683+
{
4684+
// this is not fdb_entry key
4685+
continue;
4686+
}
4687+
4688+
sai_object_meta_key_t meta_key_fdb;
4689+
4690+
meta_key_fdb.objecttype = SAI_OBJECT_TYPE_FDB_ENTRY;
4691+
4692+
sai_deserialize_object_meta_key(key_fdb, meta_key_fdb);
4693+
4694+
if (it->second.at(SAI_FDB_ENTRY_ATTR_TYPE)->getattr()->value.s32 != type->value.s32)
4695+
{
4696+
// entry type is not matching on this fdb entry
4697+
continue;
4698+
}
4699+
4700+
if (bpid != NULL)
4701+
{
4702+
if (it->second.find(SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID) == it->second.end())
4703+
{
4704+
// port is not defined for this fdb entry
4705+
continue;
4706+
}
4707+
4708+
if (it->second.at(SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID)->getattr()->value.oid != bpid->value.oid)
4709+
{
4710+
// bridge port is not matching this fdb entry
4711+
continue;
4712+
}
4713+
}
4714+
4715+
if (data.fdb_entry.bv_id != SAI_NULL_OBJECT_ID)
4716+
{
4717+
if (data.fdb_entry.bv_id != meta_key_fdb.objectkey.key.fdb_entry.bv_id)
4718+
{
4719+
// vlan/bridge id is not matching on this fdb entry
4720+
continue;
4721+
}
4722+
}
4723+
4724+
// this fdb entry is matching, removing
4725+
4726+
SWSS_LOG_INFO("removing %s", key_fdb.c_str());
4727+
4728+
// since meta_generic_validation_post_remove also modifies ObjectAttrHash
4729+
// we need to push this to a vector and remove in next loop
4730+
toremove.push_back(meta_key_fdb);
4731+
}
4732+
4733+
for (auto it = toremove.begin(); it != toremove.end(); ++it)
4734+
{
4735+
// remove selected objects
4736+
meta_generic_validation_post_remove(*it);
4737+
}
4738+
}
4739+
46604740
void meta_sai_on_fdb_event_single(
46614741
_In_ const sai_fdb_event_notification_data_t& data)
46624742
{
@@ -4709,11 +4789,28 @@ void meta_sai_on_fdb_event_single(
47094789
break;
47104790

47114791
case SAI_FDB_EVENT_AGED:
4792+
4793+
if (!object_exists(key_fdb))
4794+
{
4795+
SWSS_LOG_WARN("object key %s doesn't exist but received AGED event", key_fdb.c_str());
4796+
break;
4797+
}
4798+
4799+
meta_generic_validation_post_remove(meta_key_fdb);
4800+
4801+
break;
4802+
47124803
case SAI_FDB_EVENT_FLUSHED:
47134804

4805+
if (memcmp(data.fdb_entry.mac_address, zero_mac, sizeof(zero_mac)) == 0)
4806+
{
4807+
meta_sai_on_fdb_flush_event_consolidated(data);
4808+
break;
4809+
}
4810+
47144811
if (!object_exists(key_fdb))
47154812
{
4716-
SWSS_LOG_WARN("object key %s doesn't exist but received AGED/FLUSHED event", key_fdb.c_str());
4813+
SWSS_LOG_WARN("object key %s doesn't exist but received FLUSHED event", key_fdb.c_str());
47174814
break;
47184815
}
47194816

0 commit comments

Comments
 (0)