Skip to content

Commit

Permalink
Move Flush FDB from portsorch to fdborch
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasant committed May 29, 2020
1 parent 866bf7c commit e9be327
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 43 deletions.
19 changes: 18 additions & 1 deletion orchagent/fdborch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ void FdbOrch::update(SubjectType type, void *cntx)
updateVlanMember(*update);
break;
}
case SUBJECT_TYPE_PORT_OPER_STATE_CHANGE:
{
PortOperStateUpdate *update = reinterpret_cast<PortOperStateUpdate *>(cntx);
updatePortOperState(*update);
break;
}
default:
break;
}
Expand Down Expand Up @@ -436,7 +442,7 @@ void FdbOrch::flushFDBEntries(sai_object_id_t bridge_port_oid,

SWSS_LOG_ENTER();

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

void FdbOrch::updatePortOperState(const PortOperStateUpdate& update)
{
SWSS_LOG_ENTER();
if (update.operStatus == SAI_PORT_OPER_STATUS_DOWN)
{
swss::Port p = update.port;
flushFDBEntries(p.m_bridge_port_id, SAI_NULL_OBJECT_ID);
}
return;
}

void FdbOrch::updateVlanMember(const VlanMemberUpdate& update)
{
SWSS_LOG_ENTER();
Expand Down
1 change: 1 addition & 0 deletions orchagent/fdborch.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class FdbOrch: public Orch, public Subject, public Observer
void doTask(NotificationConsumer& consumer);

void updateVlanMember(const VlanMemberUpdate&);
void updatePortOperState(const PortOperStateUpdate&);
bool addFdbEntry(const FdbEntry&, const string&, const string&);
bool removeFdbEntry(const FdbEntry&);
void flushFDBEntries(sai_object_id_t bridge_port_oid,
Expand Down
1 change: 1 addition & 0 deletions orchagent/observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum SubjectType
SUBJECT_TYPE_MIRROR_SESSION_CHANGE,
SUBJECT_TYPE_INT_SESSION_CHANGE,
SUBJECT_TYPE_PORT_CHANGE,
SUBJECT_TYPE_PORT_OPER_STATE_CHANGE,
};

class Observer
Expand Down
71 changes: 30 additions & 41 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
Port p;
if (getPort(port_id, p))
{
PortUpdate update = {p, false };
PortUpdate update = {p, false};
notify(SUBJECT_TYPE_PORT_CHANGE, static_cast<void *>(&update));
}
}
Expand Down Expand Up @@ -2551,6 +2551,8 @@ void PortsOrch::doLagTask(Consumer &consumer)
// Retrieve attributes
uint32_t mtu = 0;
string learn_mode;
bool operation_status_changed = false;
string operation_status;

for (auto i : kfvFieldsValues(t))
{
Expand All @@ -2564,20 +2566,22 @@ void PortsOrch::doLagTask(Consumer &consumer)
}
else if (fvField(i) == "oper_status")
{
if (fvValue(i) == "down")
operation_status = fvValue(i);
if (!string_oper_status.count(operation_status))
{
gNeighOrch->ifChangeInformNextHop(alias, false);
Port lag;
if (getPort(alias, lag))
{
SWSS_LOG_NOTICE("Flushing FDB entries for %s with bridge port id: %" PRIx64
" as it is DOWN", alias.c_str(), lag.m_bridge_port_id);
flushFDBEntries(lag.m_bridge_port_id);
}
SWSS_LOG_ERROR("Invalid operation status value:%s", operation_status.c_str());
it++;
continue;
}
else

gNeighOrch->ifChangeInformNextHop(alias,
(operation_status == "down") ?
false : true);
Port lag
if (getPort(alias, lag))
{
gNeighOrch->ifChangeInformNextHop(alias, true);
operation_status_changed = (string_oper_status[operation_status] != lag.m_oper_status) ?
true : false;
}
}
}
Expand All @@ -2600,6 +2604,17 @@ void PortsOrch::doLagTask(Consumer &consumer)
}
else
{

if (!operation_status.empty())
{
l.m_oper_status = string_oper_status[operation_status];
m_portList[alias] = l;
}
if (operation_status_changed)
{
PortOperStateUpdate update = {l, string_oper_status[operation_status]};
notify(SUBJECT_TYPE_PORT_OPER_STATE_CHANGE, static_cast<void *>(&update));
}
if (mtu != 0)
{
l.m_mtu = mtu;
Expand Down Expand Up @@ -3154,9 +3169,6 @@ bool PortsOrch::removeBridgePort(Port &port)
return false;
}

/* Flush FDB entries pointing to this bridge port */
flushFDBEntries(port.m_bridge_port_id);

/* Remove bridge port */
status = sai_bridge_api->remove_bridge_port(port.m_bridge_port_id);
if (status != SAI_STATUS_SUCCESS)
Expand Down Expand Up @@ -3806,13 +3818,6 @@ void PortsOrch::doTask(NotificationConsumer &consumer)

updatePortOperStatus(port, status);

if (status == SAI_PORT_OPER_STATUS_DOWN)
{
SWSS_LOG_NOTICE("Flushing FDB entries for %s with bridge port id: %" PRIx64
" as it is DOWN", port.m_alias.c_str(), port.m_bridge_port_id);
flushFDBEntries(port.m_bridge_port_id);
}

/* update m_portList */
m_portList[port.m_alias] = port;
}
Expand Down Expand Up @@ -3844,6 +3849,9 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status)
{
SWSS_LOG_WARN("Inform nexthop operation failed for interface %s", port.m_alias.c_str());
}

PortOperStateUpdate update = {port, status};
notify(SUBJECT_TYPE_PORT_OPER_STATE_CHANGE, static_cast<void *>(&update));
}

/*
Expand Down Expand Up @@ -3997,22 +4005,3 @@ void PortsOrch::getPortSerdesVal(const std::string& val_str,
lane_values.push_back(lane_val);
}
}

void PortsOrch::flushFDBEntries(sai_object_id_t bridge_port_id)
{
sai_attribute_t attr;
vector<sai_attribute_t> attrs;
sai_status_t rv;

SWSS_LOG_INFO("Flushing the port with bridge port id: %" PRIx64, bridge_port_id);

attr.id = SAI_FDB_FLUSH_ATTR_BRIDGE_PORT_ID;
attr.value.oid = bridge_port_id;
attrs.push_back(attr);
rv = sai_fdb_api->flush_fdb_entries(gSwitchId, (uint32_t)attrs.size(), attrs.data());

if (rv != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Flush fdb by bridge port id: %" PRIx64 " failed: %d", bridge_port_id, rv);
}
}
16 changes: 15 additions & 1 deletion orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,27 @@ static const map<sai_port_oper_status_t, string> oper_status_strings =
{ SAI_PORT_OPER_STATUS_NOT_PRESENT, "not present" }
};

static const unordered_map<string, sai_port_oper_status_t> string_oper_status =
{
{ "unknown", SAI_PORT_OPER_STATUS_UNKNOWN },
{ "up", SAI_PORT_OPER_STATUS_UP },
{ "down", SAI_PORT_OPER_STATUS_DOWN },
{ "testing", SAI_PORT_OPER_STATUS_TESTING },
{ "not present", SAI_PORT_OPER_STATUS_NOT_PRESENT }
};

struct PortUpdate
{
Port port;
bool add;
};

struct PortOperStateUpdate
{
Port port;
sai_port_oper_status_t operStatus;
};

struct LagMemberUpdate
{
Port lag;
Expand Down Expand Up @@ -234,7 +249,6 @@ class PortsOrch : public Orch, public Subject
vector<uint32_t> &serdes_val);
bool getSaiAclBindPointType(Port::Type type,
sai_acl_bind_point_type_t &sai_acl_bind_type);
void flushFDBEntries(sai_object_id_t bridge_port_id);
};
#endif /* SWSS_PORTSORCH_H */

0 comments on commit e9be327

Please sign in to comment.