diff --git a/syncd/syncd.cpp b/syncd/syncd.cpp index 9e221dae15ae..a69114e6ce57 100644 --- a/syncd/syncd.cpp +++ b/syncd/syncd.cpp @@ -8,6 +8,7 @@ #include "swss/warm_restart.h" #include "swss/table.h" +#include "swss/redisapi.h" #include "TimerWatchdog.h" @@ -36,6 +37,7 @@ extern "C" { */ std::mutex g_mutex; +std::shared_ptr dbAsic; std::shared_ptr g_redisClient; std::shared_ptr getResponse; std::shared_ptr notifications; @@ -90,6 +92,9 @@ volatile bool g_asicInitViewMode = false; */ sai_object_id_t gSwitchId; +std::string fdbFlushSha; +std::string fdbFlushLuaScriptName = "fdb_flush.lua"; + struct cmdOptions { bool diagShell; @@ -4135,7 +4140,7 @@ int syncd_main(int argc, char **argv) } #endif // SAITHRIFT - std::shared_ptr dbAsic = std::make_shared(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); + dbAsic = std::make_shared(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); std::shared_ptr dbNtf = std::make_shared(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); std::shared_ptr dbFlexCounter = std::make_shared(FLEX_COUNTER_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); std::shared_ptr dbState = std::make_shared(STATE_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0); @@ -4157,6 +4162,9 @@ int syncd_main(int argc, char **argv) getResponse = std::make_shared(dbAsic.get(), "GETRESPONSE"); notifications = std::make_shared(dbNtf.get(), "NOTIFICATIONS"); + std::string fdbFlushLuaScript = swss::loadLuaScript(fdbFlushLuaScriptName); + fdbFlushSha = swss::loadRedisScript(dbAsic.get(), fdbFlushLuaScript); + g_veryFirstRun = isVeryFirstRun(); /* ignore warm logic here if syncd starts in Mellanox fastfast boot mode */ diff --git a/syncd/syncd.h b/syncd/syncd.h index 59974b205280..ca8e7f9b3142 100644 --- a/syncd/syncd.h +++ b/syncd/syncd.h @@ -93,6 +93,8 @@ sai_object_type_t getObjectTypeFromVid( extern std::shared_ptr notifications; extern std::shared_ptr g_redisClient; +extern std::shared_ptr dbAsic; +extern std::string fdbFlushSha; extern bool g_enableConsistencyCheck; diff --git a/syncd/syncd_notifications.cpp b/syncd/syncd_notifications.cpp index 1954ee9be4df..46426428432a 100644 --- a/syncd/syncd_notifications.cpp +++ b/syncd/syncd_notifications.cpp @@ -108,6 +108,7 @@ void redisPutFdbEntryToAsicView( { sai_object_id_t bv_id = fdb->fdb_entry.bv_id; sai_object_id_t port_oid = 0; + int flush_static = 0; for (uint32_t i = 0; i < fdb->attr_count; i++) { @@ -115,6 +116,10 @@ void redisPutFdbEntryToAsicView( { port_oid = fdb->attr[i].value.oid; } + else if(fdb->attr[i].id == SAI_FDB_ENTRY_ATTR_TYPE) + { + flush_static = (fdb->attr[i].value.s32 == SAI_FDB_ENTRY_TYPE_STATIC) ? 1 : 0; + } } @@ -138,24 +143,14 @@ void redisPutFdbEntryToAsicView( */ SWSS_LOG_NOTICE("received a flush all fdb event"); std::string pattern = ASIC_STATE_TABLE + std::string(":SAI_OBJECT_TYPE_FDB_ENTRY:*"); - for (const auto &fdbkey: g_redisClient->keys(pattern)) - { - /* we only remove dynamic fdb entries here, static fdb entries need to be deleted manually by user instead of flush */ - auto pEntryType = g_redisClient->hget(fdbkey, "SAI_FDB_ENTRY_ATTR_TYPE"); - if (pEntryType != NULL) - { - std::string strEntryType = *pEntryType; - if (strEntryType == "SAI_FDB_ENTRY_TYPE_DYNAMIC") - { - SWSS_LOG_DEBUG("remove fdb entry %s for SAI_FDB_EVENT_FLUSHED",fdbkey.c_str()); - g_redisClient->del(fdbkey); - } - } - else - { - SWSS_LOG_ERROR("found unknown type fdb entry, key %s", fdbkey.c_str()); - } - } + swss::RedisCommand command; + command.format( + "EVALSHA %s 3 %s %s %s", + fdbFlushSha.c_str(), + pattern.c_str(), + "", + std::to_string(flush_static).c_str()); + swss::RedisReply r(dbAsic.get(), command); } else if (port_oid && !bv_id) { @@ -176,7 +171,18 @@ void redisPutFdbEntryToAsicView( ] }] */ - SWSS_LOG_ERROR("received a flush port fdb event, port_oid = 0x%" PRIx64 ", bv_id = 0x%" PRIx64 ", unsupported", port_oid, bv_id); + SWSS_LOG_NOTICE("received a flush port fdb event, port_oid = 0x%lx, bv_id = 0x%lx", port_oid, bv_id); + std::string pattern = ASIC_STATE_TABLE + std::string(":SAI_OBJECT_TYPE_FDB_ENTRY:*"); + std::string port_str = sai_serialize_object_id(port_oid); + SWSS_LOG_NOTICE("pattern %s port_str %s", pattern.c_str(), port_str.c_str()); + swss::RedisCommand command; + command.format( + "EVALSHA %s 3 %s %s %s", + fdbFlushSha.c_str(), + pattern.c_str(), + port_str.c_str(), + std::to_string(flush_static).c_str()); + swss::RedisReply r(dbAsic.get(), command); } else if (!port_oid && bv_id) { @@ -197,12 +203,30 @@ void redisPutFdbEntryToAsicView( ] }] */ - SWSS_LOG_ERROR("received a flush vlan fdb event, port_oid = 0x%" PRIx64 ", bv_id = 0x%" PRIx64 ", unsupported", port_oid, bv_id); - + SWSS_LOG_NOTICE("received a flush vlan fdb event, port_oid = 0x%lx, bv_id = 0x%lx", port_oid, bv_id); + std::string pattern = ASIC_STATE_TABLE + std::string(":SAI_OBJECT_TYPE_FDB_ENTRY:*") + sai_serialize_object_id(bv_id) + std::string("*"); + swss::RedisCommand command; + command.format( + "EVALSHA %s 3 %s %s %s", + fdbFlushSha.c_str(), + pattern.c_str(), + "", + std::to_string(flush_static).c_str()); + swss::RedisReply r(dbAsic.get(), command); } else { - SWSS_LOG_ERROR("received a flush fdb event, port_oid = 0x%" PRIx64 ", bv_id = 0x%" PRIx64 ", unsupported", port_oid, bv_id); + SWSS_LOG_NOTICE("received a flush fdb event, port_oid = 0x%lx, bv_id = 0x%lx", port_oid, bv_id); + std::string pattern = ASIC_STATE_TABLE + std::string(":SAI_OBJECT_TYPE_FDB_ENTRY:*") + sai_serialize_object_id(bv_id) + std::string("*"); + std::string port_str = sai_serialize_object_id(port_oid); + swss::RedisCommand command; + command.format( + "EVALSHA %s 3 %s %s %s", + fdbFlushSha.c_str(), + pattern.c_str(), + port_str.c_str(), + std::to_string(flush_static).c_str()); + swss::RedisReply r(dbAsic.get(), command); } return;