Skip to content

Commit e9be327

Browse files
author
Vasant
committed
Move Flush FDB from portsorch to fdborch
1 parent 866bf7c commit e9be327

File tree

5 files changed

+65
-43
lines changed

5 files changed

+65
-43
lines changed

orchagent/fdborch.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ void FdbOrch::update(SubjectType type, void *cntx)
228228
updateVlanMember(*update);
229229
break;
230230
}
231+
case SUBJECT_TYPE_PORT_OPER_STATE_CHANGE:
232+
{
233+
PortOperStateUpdate *update = reinterpret_cast<PortOperStateUpdate *>(cntx);
234+
updatePortOperState(*update);
235+
break;
236+
}
231237
default:
232238
break;
233239
}
@@ -436,7 +442,7 @@ void FdbOrch::flushFDBEntries(sai_object_id_t bridge_port_oid,
436442

437443
SWSS_LOG_ENTER();
438444

439-
if (SAI_NULL_OBJECT_ID == bridge_port_oid ||
445+
if (SAI_NULL_OBJECT_ID == bridge_port_oid &&
440446
SAI_NULL_OBJECT_ID == vlan_oid)
441447
{
442448
SWSS_LOG_WARN("Couldn't flush FDB. Bridge port OID: 0x%" PRIx64 " bvid:%" PRIx64 ",",
@@ -461,6 +467,17 @@ void FdbOrch::flushFDBEntries(sai_object_id_t bridge_port_oid,
461467
}
462468
}
463469

470+
void FdbOrch::updatePortOperState(const PortOperStateUpdate& update)
471+
{
472+
SWSS_LOG_ENTER();
473+
if (update.operStatus == SAI_PORT_OPER_STATUS_DOWN)
474+
{
475+
swss::Port p = update.port;
476+
flushFDBEntries(p.m_bridge_port_id, SAI_NULL_OBJECT_ID);
477+
}
478+
return;
479+
}
480+
464481
void FdbOrch::updateVlanMember(const VlanMemberUpdate& update)
465482
{
466483
SWSS_LOG_ENTER();

orchagent/fdborch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class FdbOrch: public Orch, public Subject, public Observer
6060
void doTask(NotificationConsumer& consumer);
6161

6262
void updateVlanMember(const VlanMemberUpdate&);
63+
void updatePortOperState(const PortOperStateUpdate&);
6364
bool addFdbEntry(const FdbEntry&, const string&, const string&);
6465
bool removeFdbEntry(const FdbEntry&);
6566
void flushFDBEntries(sai_object_id_t bridge_port_oid,

orchagent/observer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ enum SubjectType
1616
SUBJECT_TYPE_MIRROR_SESSION_CHANGE,
1717
SUBJECT_TYPE_INT_SESSION_CHANGE,
1818
SUBJECT_TYPE_PORT_CHANGE,
19+
SUBJECT_TYPE_PORT_OPER_STATE_CHANGE,
1920
};
2021

2122
class Observer

orchagent/portsorch.cpp

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
22952295
Port p;
22962296
if (getPort(port_id, p))
22972297
{
2298-
PortUpdate update = {p, false };
2298+
PortUpdate update = {p, false};
22992299
notify(SUBJECT_TYPE_PORT_CHANGE, static_cast<void *>(&update));
23002300
}
23012301
}
@@ -2551,6 +2551,8 @@ void PortsOrch::doLagTask(Consumer &consumer)
25512551
// Retrieve attributes
25522552
uint32_t mtu = 0;
25532553
string learn_mode;
2554+
bool operation_status_changed = false;
2555+
string operation_status;
25542556

25552557
for (auto i : kfvFieldsValues(t))
25562558
{
@@ -2564,20 +2566,22 @@ void PortsOrch::doLagTask(Consumer &consumer)
25642566
}
25652567
else if (fvField(i) == "oper_status")
25662568
{
2567-
if (fvValue(i) == "down")
2569+
operation_status = fvValue(i);
2570+
if (!string_oper_status.count(operation_status))
25682571
{
2569-
gNeighOrch->ifChangeInformNextHop(alias, false);
2570-
Port lag;
2571-
if (getPort(alias, lag))
2572-
{
2573-
SWSS_LOG_NOTICE("Flushing FDB entries for %s with bridge port id: %" PRIx64
2574-
" as it is DOWN", alias.c_str(), lag.m_bridge_port_id);
2575-
flushFDBEntries(lag.m_bridge_port_id);
2576-
}
2572+
SWSS_LOG_ERROR("Invalid operation status value:%s", operation_status.c_str());
2573+
it++;
2574+
continue;
25772575
}
2578-
else
2576+
2577+
gNeighOrch->ifChangeInformNextHop(alias,
2578+
(operation_status == "down") ?
2579+
false : true);
2580+
Port lag
2581+
if (getPort(alias, lag))
25792582
{
2580-
gNeighOrch->ifChangeInformNextHop(alias, true);
2583+
operation_status_changed = (string_oper_status[operation_status] != lag.m_oper_status) ?
2584+
true : false;
25812585
}
25822586
}
25832587
}
@@ -2600,6 +2604,17 @@ void PortsOrch::doLagTask(Consumer &consumer)
26002604
}
26012605
else
26022606
{
2607+
2608+
if (!operation_status.empty())
2609+
{
2610+
l.m_oper_status = string_oper_status[operation_status];
2611+
m_portList[alias] = l;
2612+
}
2613+
if (operation_status_changed)
2614+
{
2615+
PortOperStateUpdate update = {l, string_oper_status[operation_status]};
2616+
notify(SUBJECT_TYPE_PORT_OPER_STATE_CHANGE, static_cast<void *>(&update));
2617+
}
26032618
if (mtu != 0)
26042619
{
26052620
l.m_mtu = mtu;
@@ -3154,9 +3169,6 @@ bool PortsOrch::removeBridgePort(Port &port)
31543169
return false;
31553170
}
31563171

3157-
/* Flush FDB entries pointing to this bridge port */
3158-
flushFDBEntries(port.m_bridge_port_id);
3159-
31603172
/* Remove bridge port */
31613173
status = sai_bridge_api->remove_bridge_port(port.m_bridge_port_id);
31623174
if (status != SAI_STATUS_SUCCESS)
@@ -3806,13 +3818,6 @@ void PortsOrch::doTask(NotificationConsumer &consumer)
38063818

38073819
updatePortOperStatus(port, status);
38083820

3809-
if (status == SAI_PORT_OPER_STATUS_DOWN)
3810-
{
3811-
SWSS_LOG_NOTICE("Flushing FDB entries for %s with bridge port id: %" PRIx64
3812-
" as it is DOWN", port.m_alias.c_str(), port.m_bridge_port_id);
3813-
flushFDBEntries(port.m_bridge_port_id);
3814-
}
3815-
38163821
/* update m_portList */
38173822
m_portList[port.m_alias] = port;
38183823
}
@@ -3844,6 +3849,9 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status)
38443849
{
38453850
SWSS_LOG_WARN("Inform nexthop operation failed for interface %s", port.m_alias.c_str());
38463851
}
3852+
3853+
PortOperStateUpdate update = {port, status};
3854+
notify(SUBJECT_TYPE_PORT_OPER_STATE_CHANGE, static_cast<void *>(&update));
38473855
}
38483856

38493857
/*
@@ -3997,22 +4005,3 @@ void PortsOrch::getPortSerdesVal(const std::string& val_str,
39974005
lane_values.push_back(lane_val);
39984006
}
39994007
}
4000-
4001-
void PortsOrch::flushFDBEntries(sai_object_id_t bridge_port_id)
4002-
{
4003-
sai_attribute_t attr;
4004-
vector<sai_attribute_t> attrs;
4005-
sai_status_t rv;
4006-
4007-
SWSS_LOG_INFO("Flushing the port with bridge port id: %" PRIx64, bridge_port_id);
4008-
4009-
attr.id = SAI_FDB_FLUSH_ATTR_BRIDGE_PORT_ID;
4010-
attr.value.oid = bridge_port_id;
4011-
attrs.push_back(attr);
4012-
rv = sai_fdb_api->flush_fdb_entries(gSwitchId, (uint32_t)attrs.size(), attrs.data());
4013-
4014-
if (rv != SAI_STATUS_SUCCESS)
4015-
{
4016-
SWSS_LOG_ERROR("Flush fdb by bridge port id: %" PRIx64 " failed: %d", bridge_port_id, rv);
4017-
}
4018-
}

orchagent/portsorch.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,27 @@ static const map<sai_port_oper_status_t, string> oper_status_strings =
3030
{ SAI_PORT_OPER_STATUS_NOT_PRESENT, "not present" }
3131
};
3232

33+
static const unordered_map<string, sai_port_oper_status_t> string_oper_status =
34+
{
35+
{ "unknown", SAI_PORT_OPER_STATUS_UNKNOWN },
36+
{ "up", SAI_PORT_OPER_STATUS_UP },
37+
{ "down", SAI_PORT_OPER_STATUS_DOWN },
38+
{ "testing", SAI_PORT_OPER_STATUS_TESTING },
39+
{ "not present", SAI_PORT_OPER_STATUS_NOT_PRESENT }
40+
};
41+
3342
struct PortUpdate
3443
{
3544
Port port;
3645
bool add;
3746
};
3847

48+
struct PortOperStateUpdate
49+
{
50+
Port port;
51+
sai_port_oper_status_t operStatus;
52+
};
53+
3954
struct LagMemberUpdate
4055
{
4156
Port lag;
@@ -234,7 +249,6 @@ class PortsOrch : public Orch, public Subject
234249
vector<uint32_t> &serdes_val);
235250
bool getSaiAclBindPointType(Port::Type type,
236251
sai_acl_bind_point_type_t &sai_acl_bind_type);
237-
void flushFDBEntries(sai_object_id_t bridge_port_id);
238252
};
239253
#endif /* SWSS_PORTSORCH_H */
240254

0 commit comments

Comments
 (0)