Skip to content

Commit

Permalink
Layer 2 Forwarding Enhancements (sonic-net#510)
Browse files Browse the repository at this point in the history
Added code changes related to Layer 2 Forwarding Enhancement:

As part of L2 enhancements, per port, per vlan and per port-vlan fdb flush support has been added. The fdb flush response from SAI comes as individual mac delete as mentioned in the HLD. The change here is to follow the same way for VS as well.

Regarding SAI_FDB_EVENT_FLUSHED, it is handled in sync only for 'flush all' case and handling SAI_FDB_EVENT_FLUSHED for per port and per port-vlan will require hgetall on all fdb keys. So, individual mac delete response is preferred.

Another change is to move fdb handling to fdborch. As the fdb reference count is now maintained in fdborch as well, need to move the sai redis fdb handling also there to avoid the reference counts to go out of sync between the two.
  • Loading branch information
anilkpandey authored and lguohan committed Nov 27, 2019
1 parent 27a93ff commit 34a4202
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 23 deletions.
10 changes: 9 additions & 1 deletion syncd/syncd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "swss/warm_restart.h"
#include "swss/table.h"
#include "swss/redisapi.h"

#include "TimerWatchdog.h"

Expand Down Expand Up @@ -36,6 +37,7 @@ extern "C" {
*/
std::mutex g_mutex;

std::shared_ptr<swss::DBConnector> dbAsic;
std::shared_ptr<swss::RedisClient> g_redisClient;
std::shared_ptr<swss::ProducerTable> getResponse;
std::shared_ptr<swss::NotificationProducer> notifications;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -4135,7 +4140,7 @@ int syncd_main(int argc, char **argv)
}
#endif // SAITHRIFT

std::shared_ptr<swss::DBConnector> dbAsic = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
dbAsic = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
std::shared_ptr<swss::DBConnector> dbNtf = std::make_shared<swss::DBConnector>(ASIC_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
std::shared_ptr<swss::DBConnector> dbFlexCounter = std::make_shared<swss::DBConnector>(FLEX_COUNTER_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
std::shared_ptr<swss::DBConnector> dbState = std::make_shared<swss::DBConnector>(STATE_DB, swss::DBConnector::DEFAULT_UNIXSOCKET, 0);
Expand All @@ -4157,6 +4162,9 @@ int syncd_main(int argc, char **argv)
getResponse = std::make_shared<swss::ProducerTable>(dbAsic.get(), "GETRESPONSE");
notifications = std::make_shared<swss::NotificationProducer>(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 */
Expand Down
2 changes: 2 additions & 0 deletions syncd/syncd.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ sai_object_type_t getObjectTypeFromVid(

extern std::shared_ptr<swss::NotificationProducer> notifications;
extern std::shared_ptr<swss::RedisClient> g_redisClient;
extern std::shared_ptr<swss::DBConnector> dbAsic;
extern std::string fdbFlushSha;

extern bool g_enableConsistencyCheck;

Expand Down
68 changes: 46 additions & 22 deletions syncd/syncd_notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ 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++)
{
if(fdb->attr[i].id == SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID)
{
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;
}
}


Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down

0 comments on commit 34a4202

Please sign in to comment.