From 031f53629706d47099785497372b14f5a30b9cc9 Mon Sep 17 00:00:00 2001 From: yangshiping <43633727+yangshp1987@users.noreply.github.com> Date: Thu, 20 May 2021 06:56:55 +0800 Subject: [PATCH] support flush FDB entries per port and per vlan (#1064) Fdb entries can be deleted with user specifying vlan or port or vlan&&port. Signed-off-by: yangshiping@jd.com --- orchagent/fdborch.cpp | 74 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/orchagent/fdborch.cpp b/orchagent/fdborch.cpp index cd4888bc1ccd..af46d958ecce 100644 --- a/orchagent/fdborch.cpp +++ b/orchagent/fdborch.cpp @@ -685,6 +685,10 @@ void FdbOrch::doTask(NotificationConsumer& consumer) std::string op; std::string data; std::vector values; + string alias; + string vlan; + Port port; + Port vlanPort; consumer.pop(op, data, values); @@ -706,14 +710,76 @@ void FdbOrch::doTask(NotificationConsumer& consumer) } else if (op == "PORT") { - /*place holder for flush port fdb*/ - SWSS_LOG_ERROR("Received unsupported flush port fdb request"); + alias = data; + if (alias.empty()) + { + SWSS_LOG_ERROR("Receive wrong port to flush fdb!"); + return; + } + if (!gPortsOrch->getPort(alias, port)) + { + SWSS_LOG_ERROR("Get Port from port(%s) failed!", alias.c_str()); + return; + } + if (port.m_bridge_port_id == SAI_NULL_OBJECT_ID) + { + return; + } + flushFDBEntries(port.m_bridge_port_id, SAI_NULL_OBJECT_ID); + SWSS_LOG_NOTICE("Clear fdb by port(%s)", alias.c_str()); return; } else if (op == "VLAN") { - /*place holder for flush vlan fdb*/ - SWSS_LOG_ERROR("Received unsupported flush vlan fdb request"); + vlan = data; + if (vlan.empty()) + { + SWSS_LOG_ERROR("Receive wrong vlan to flush fdb!"); + return; + } + if (!gPortsOrch->getPort(vlan, vlanPort)) + { + SWSS_LOG_ERROR("Get Port from vlan(%s) failed!", vlan.c_str()); + return; + } + if (vlanPort.m_vlan_info.vlan_oid == SAI_NULL_OBJECT_ID) + { + return; + } + flushFDBEntries(SAI_NULL_OBJECT_ID, vlanPort.m_vlan_info.vlan_oid); + SWSS_LOG_NOTICE("Clear fdb by vlan(%s)", vlan.c_str()); + return; + } + else if (op == "PORTVLAN") + { + size_t found = data.find('|'); + if (found != string::npos) + { + alias = data.substr(0, found); + vlan = data.substr(found+1); + } + if (alias.empty() || vlan.empty()) + { + SWSS_LOG_ERROR("Receive wrong port or vlan to flush fdb!"); + return; + } + if (!gPortsOrch->getPort(alias, port)) + { + SWSS_LOG_ERROR("Get Port from port(%s) failed!", alias.c_str()); + return; + } + if (!gPortsOrch->getPort(vlan, vlanPort)) + { + SWSS_LOG_ERROR("Get Port from vlan(%s) failed!", vlan.c_str()); + return; + } + if (port.m_bridge_port_id == SAI_NULL_OBJECT_ID || + vlanPort.m_vlan_info.vlan_oid == SAI_NULL_OBJECT_ID) + { + return; + } + flushFDBEntries(port.m_bridge_port_id, vlanPort.m_vlan_info.vlan_oid); + SWSS_LOG_NOTICE("Clear fdb by port(%s)+vlan(%s)", alias.c_str(), vlan.c_str()); return; } else