7
7
#include " logger.h"
8
8
#include " tokenize.h"
9
9
#include " fdborch.h"
10
+ #include " notifier.h"
10
11
11
12
extern sai_fdb_api_t *sai_fdb_api;
12
13
13
14
extern sai_object_id_t gSwitchId ;
14
15
extern PortsOrch* gPortsOrch ;
15
16
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
+
16
28
void FdbOrch::update (sai_fdb_event_t type, const sai_fdb_entry_t * entry, sai_object_id_t bridge_port_id)
17
29
{
18
30
SWSS_LOG_ENTER ();
@@ -34,21 +46,71 @@ void FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_obj
34
46
35
47
(void )m_entries.insert (update.entry );
36
48
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
+
37
55
break ;
56
+
38
57
case SAI_FDB_EVENT_AGED:
39
- case SAI_FDB_EVENT_FLUSHED:
40
58
case SAI_FDB_EVENT_MOVE:
41
59
update.add = false ;
42
60
43
61
(void )m_entries.erase (update.entry );
44
62
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
+
45
69
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 ;
47
85
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 ;
51
111
}
112
+
113
+ return ;
52
114
}
53
115
54
116
void FdbOrch::update (SubjectType type, void *cntx)
@@ -179,6 +241,55 @@ void FdbOrch::doTask(Consumer& consumer)
179
241
}
180
242
}
181
243
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
+
182
293
void FdbOrch::updateVlanMember (const VlanMemberUpdate& update)
183
294
{
184
295
SWSS_LOG_ENTER ();
0 commit comments