77#include " logger.h"
88#include " tokenize.h"
99#include " fdborch.h"
10+ #include " notifier.h"
1011
1112extern sai_fdb_api_t *sai_fdb_api;
1213
1314extern sai_object_id_t gSwitchId ;
1415extern PortsOrch* gPortsOrch ;
1516
17+ FdbOrch::FdbOrch (DBConnector *db, string tableName, PortsOrch *port) :
18+ Orch(db, tableName),
19+ m_portsOrch(port),
20+ m_table(Table(db, tableName))
21+ {
22+ m_portsOrch->attach (this );
23+ auto consumer = new NotificationConsumer (db, " FLUSHFDBREQUEST" );
24+ auto fdbNotification = new Notifier (consumer, this );
25+ Orch::addExecutor (" " , fdbNotification);
26+ }
27+
1628void FdbOrch::update (sai_fdb_event_t type, const sai_fdb_entry_t * entry, sai_object_id_t bridge_port_id)
1729{
1830 SWSS_LOG_ENTER ();
@@ -34,21 +46,71 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj
3446
3547 (void )m_entries.insert (update.entry );
3648 SWSS_LOG_DEBUG (" FdbOrch notification: mac %s was inserted into vlan %d" , update.entry .mac .to_string ().c_str (), entry->vlan_id );
49+
50+ for (auto observer: m_observers)
51+ {
52+ observer->update (SUBJECT_TYPE_FDB_CHANGE, &update);
53+ }
54+
3755 break ;
56+
3857 case SAI_FDB_EVENT_AGED:
39- case SAI_FDB_EVENT_FLUSHED:
4058 case SAI_FDB_EVENT_MOVE:
4159 update.add = false ;
4260
4361 (void )m_entries.erase (update.entry );
4462 SWSS_LOG_DEBUG (" FdbOrch notification: mac %s was removed from vlan %d" , update.entry .mac .to_string ().c_str (), entry->vlan_id );
63+
64+ for (auto observer: m_observers)
65+ {
66+ observer->update (SUBJECT_TYPE_FDB_CHANGE, &update);
67+ }
68+
4569 break ;
46- }
70+
71+ case SAI_FDB_EVENT_FLUSHED:
72+ if (bridge_port_id == SAI_NULL_OBJECT_ID && !entry->vlan_id )
73+ {
74+ for (auto itr = m_entries.begin (); itr != m_entries.end ();)
75+ {
76+ /*
77+ TODO: here should only delete the dynamic fdb entries,
78+ but unfortunately in structure FdbEntry currently have
79+ no member to indicate the fdb entry type,
80+ if there is static mac added, here will have issue.
81+ */
82+ update.entry .mac = itr->mac ;
83+ update.entry .vlan = itr->vlan ;
84+ update.add = false ;
4785
48- for (auto observer: m_observers)
49- {
50- observer->update (SUBJECT_TYPE_FDB_CHANGE, static_cast <void *>(&update));
86+ itr = m_entries.erase (itr);
87+
88+ SWSS_LOG_DEBUG (" FdbOrch notification: mac %s was removed" , update.entry .mac .to_string ().c_str ());
89+
90+ for (auto observer: m_observers)
91+ {
92+ observer->update (SUBJECT_TYPE_FDB_CHANGE, &update);
93+ }
94+ }
95+ }
96+ else if (bridge_port_id && !entry->vlan_id )
97+ {
98+ /* this is a placeholder for flush port fdb case, not supported yet.*/
99+ SWSS_LOG_ERROR (" FdbOrch notification: not supported flush port fdb action, port_id = %lu, vlan_id = %d." , bridge_port_id, entry->vlan_id );
100+ }
101+ else if (bridge_port_id == SAI_NULL_OBJECT_ID && entry->vlan_id )
102+ {
103+ /* this is a placeholder for flush vlan fdb case, not supported yet.*/
104+ SWSS_LOG_ERROR (" FdbOrch notification: not supported flush vlan fdb action, port_id = %lu, vlan_id = %d." , bridge_port_id, entry->vlan_id );
105+ }
106+ else
107+ {
108+ SWSS_LOG_ERROR (" FdbOrch notification: not supported flush fdb action, port_id = %lu, vlan_id = %d." , bridge_port_id, entry->vlan_id );
109+ }
110+ break ;
51111 }
112+
113+ return ;
52114}
53115
54116void FdbOrch::update (SubjectType type, void *cntx)
@@ -179,6 +241,55 @@ void FdbOrch::doTask(Consumer& consumer)
179241 }
180242}
181243
244+ void FdbOrch::doTask (NotificationConsumer& consumer)
245+ {
246+ SWSS_LOG_ENTER ();
247+
248+ if (!gPortsOrch ->isInitDone ())
249+ {
250+ return ;
251+ }
252+
253+ sai_status_t status;
254+ std::string op;
255+ std::string data;
256+ std::vector<swss::FieldValueTuple> values;
257+
258+ consumer.pop (op, data, values);
259+
260+ if (op == " ALL" )
261+ {
262+ /*
263+ * so far only support flush all the FDB entris
264+ * flush per port and flush per vlan will be added later.
265+ */
266+ status = sai_fdb_api->flush_fdb_entries (gSwitchId , 0 , NULL );
267+ if (status != SAI_STATUS_SUCCESS)
268+ {
269+ SWSS_LOG_ERROR (" Flush fdb failed, return code %x" , status);
270+ }
271+
272+ return ;
273+ }
274+ else if (op == " PORT" )
275+ {
276+ /* place holder for flush port fdb*/
277+ SWSS_LOG_ERROR (" Received unsupported flush port fdb request" );
278+ return ;
279+ }
280+ else if (op == " VLAN" )
281+ {
282+ /* place holder for flush vlan fdb*/
283+ SWSS_LOG_ERROR (" Received unsupported flush vlan fdb request" );
284+ return ;
285+ }
286+ else
287+ {
288+ SWSS_LOG_ERROR (" Received unknown flush fdb request" );
289+ return ;
290+ }
291+ }
292+
182293void FdbOrch::updateVlanMember (const VlanMemberUpdate& update)
183294{
184295 SWSS_LOG_ENTER ();
0 commit comments