[fdborch]Add the support for a clear fdb cli#426
[fdborch]Add the support for a clear fdb cli#426lguohan merged 7 commits intosonic-net:masterfrom keboliu:clear-fdb-cli
Conversation
merge from Azure/sonic-swss master
orchagent/fdborch.cpp
Outdated
|
|
||
| for (auto observer: m_observers) | ||
| { | ||
| observer->update(SUBJECT_TYPE_FDB_CHANGE, static_cast<void *>(&update)); |
There was a problem hiding this comment.
you can cast to void pointer without any cast mechanisms.
Check https://stackoverflow.com/questions/18929225/casting-class-pointer-to-void-pointer
So
observer->update(SUBJECT_TYPE_FDB_CHANGE, &update); is enough
orchagent/fdborch.cpp
Outdated
|
|
||
| for (auto observer: m_observers) | ||
| { | ||
| observer->update(SUBJECT_TYPE_FDB_CHANGE, static_cast<void *>(&update)); |
There was a problem hiding this comment.
you can cast to void pointer without any cast mechanisms.
Check https://stackoverflow.com/questions/18929225/casting-class-pointer-to-void-pointer
So
observer->update(SUBJECT_TYPE_FDB_CHANGE, &update); is enough
orchagent/fdborch.cpp
Outdated
| break; | ||
|
|
||
| case SAI_FDB_EVENT_FLUSHED: | ||
| if( !bridge_port_id && !(entry->vlan_id)) |
There was a problem hiding this comment.
Parenthesis around entry->vlan_id are redundant
orchagent/fdborch.cpp
Outdated
|
|
||
| for (auto observer: m_observers) | ||
| { | ||
| observer->update(SUBJECT_TYPE_FDB_CHANGE, static_cast<void *>(&update)); |
There was a problem hiding this comment.
you can cast to void pointer without any cast mechanisms.
Check https://stackoverflow.com/questions/18929225/casting-class-pointer-to-void-pointer
So
observer->update(SUBJECT_TYPE_FDB_CHANGE, &update); is enough
orchagent/fdborch.cpp
Outdated
| } | ||
| } | ||
| } | ||
| else if(bridge_port_id && !(entry->vlan_id)) |
There was a problem hiding this comment.
redundand parenthesis around entry->vlan_id
orchagent/fdborch.cpp
Outdated
| /*this is a placeholder for flush port fdb case, not supported yet.*/ | ||
| SWSS_LOG_ERROR("FdbOrch notification: not supported flush type"); | ||
| } | ||
| else if(!bridge_port_id && (entry->vlan_id)) |
There was a problem hiding this comment.
redundand parenthesis around entry->vlan_id
orchagent/fdborch.cpp
Outdated
| case SAI_FDB_EVENT_FLUSHED: | ||
| if( !bridge_port_id && !(entry->vlan_id)) | ||
| { | ||
| for(set<FdbEntry>::iterator itr = m_entries.begin(); itr != m_entries.end(); ++itr ) |
There was a problem hiding this comment.
for (auto itr = ....)
orchagent/fdborch.cpp
Outdated
| break; | ||
|
|
||
| case SAI_FDB_EVENT_FLUSHED: | ||
| if( !bridge_port_id && !entry->vlan_id) |
There was a problem hiding this comment.
please follow existing code convention for the whitespaces.
There was a problem hiding this comment.
change to bridge_port_id == SAI_NULL_OBJECT_ID
| for (auto observer: m_observers) | ||
| { | ||
| observer->update(SUBJECT_TYPE_FDB_CHANGE, &update); | ||
| } |
There was a problem hiding this comment.
this is about the fdb flush, why touch both LEARNED, AGED, MOVE events?
There was a problem hiding this comment.
separate the handling FLUSH from AGED and MOVE, at the same time remove unnecessary type cast. No impaction to the handling of other events.
orchagent/fdborch.cpp
Outdated
| case SAI_FDB_EVENT_FLUSHED: | ||
| if( !bridge_port_id && !entry->vlan_id) | ||
| { | ||
| for(auto itr = m_entries.begin(); itr != m_entries.end(); ++itr ) |
There was a problem hiding this comment.
keep white space convention as existing code, thanks.
| /*this is a placeholder for flush vlan fdb case, not supported yet.*/ | ||
| SWSS_LOG_ERROR("FdbOrch notification: not supported flush vlan fdb action, port_id = %lu, vlan_id = %d.", bridge_port_id, entry->vlan_id); | ||
| } | ||
| else |
There was a problem hiding this comment.
@prsunny , in case the fdb flush will send notification of deleted mac one-by-one, does it fall into this category?
There was a problem hiding this comment.
Observed in testing that per-entry delete is coming with event type SAI_FDB_EVENT_AGED instead of event FLUSHED, which is handled in the above case. Also, I think, deleting mac one-by-one doesn't fall into this category as there could be multiple mac entries learnt on the same port-vlan combination
orchagent/fdborch.cpp
Outdated
| update.entry.vlan = itr->vlan; | ||
| update.add = false; | ||
|
|
||
| m_entries.erase(itr); |
There was a problem hiding this comment.
Looks to me as a non-standard way of deleting the elements of a set in for-loop as it invalidates the iterator after erase. It might have worked in test. Can you check this?
There was a problem hiding this comment.
Will check. and I am revising the solution as Guohan suggested, will update all of these with the new solution.
| /*this is a placeholder for flush vlan fdb case, not supported yet.*/ | ||
| SWSS_LOG_ERROR("FdbOrch notification: not supported flush vlan fdb action, port_id = %lu, vlan_id = %d.", bridge_port_id, entry->vlan_id); | ||
| } | ||
| else |
There was a problem hiding this comment.
Observed in testing that per-entry delete is coming with event type SAI_FDB_EVENT_AGED instead of event FLUSHED, which is handled in the above case. Also, I think, deleting mac one-by-one doesn't fall into this category as there could be multiple mac entries learnt on the same port-vlan combination
orchagent/fdborch.cpp
Outdated
| attr.id = SAI_FDB_FLUSH_ATTR_ENTRY_TYPE; | ||
| attr.value.s32 = SAI_FDB_FLUSH_ENTRY_TYPE_DYNAMIC; | ||
|
|
||
| status = sai_fdb_api->flush_fdb_entries(gSwitchId, 1, &attr); |
There was a problem hiding this comment.
when flushing all, there should be 0 attributes passed, all static and dynamic entries should be cleared
Signed-off-by: Wataru Ishida <ishida@nel-america.com>
What I did
revise the FdbOrch::update(sai_fdb_event_t type, const sai_fdb_entry_t* entry, sai_object_id_t bridge_port_id) function to support a clear fdb cli
Why I did it
the current implementation is assuming that SAI will send all the flushed fdb entries to upper layers, but actually SAI only send one event to indicate the flush type, like flush all, flush fdb entries in certain port or certain vlan. upper layer need to find out all the flushed fdb entries by itself and then update it.
How I verified it
tested on MLNX plat form with various flush fdb cases.
Details if related
design doc see https://github.com/Azure/SONiC/wiki/SONiC-Clear-FDB-CLI-Design