Skip to content

Commit

Permalink
[Everflow] Fixed show mirror-session, Acl rule remove failure, orchagent
Browse files Browse the repository at this point in the history
crash

Signed-off-by: Sakthivadivu Saravanaraj <sakthivadivu.saravanaraj@nokia.com>
  • Loading branch information
saksarav-nokia committed Aug 3, 2022
1 parent f2fded5 commit 7cf981e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
22 changes: 22 additions & 0 deletions orchagent/aclorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,11 @@ const vector<AclRangeConfig>& AclRule::getRangeConfig() const
return m_rangeConfig;
}

bool AclRule::getCreateCounter() const
{
return m_createCounter;
}

shared_ptr<AclRule> AclRule::makeShared(AclOrch *acl, MirrorOrch *mirror, DTelOrch *dtel, const string& rule, const string& table, const KeyOpFieldsValuesTuple& data)
{
shared_ptr<AclRule> aclRule;
Expand Down Expand Up @@ -1624,6 +1629,13 @@ bool AclRule::createCounter()
bool AclRule::removeRanges()
{
SWSS_LOG_ENTER();
if (!m_ranges.size())
{
//The Acl Rules which have mirror action will not have ranges created till the mirror becomes active
SWSS_LOG_INFO("No Acl Range created for ACL Rule %s in table %s", m_id.c_str(), m_pTable->getId().c_str());
return true;
}

for (const auto& rangeConfig: m_rangeConfig)
{
if (!AclRange::remove(rangeConfig.rangeType, rangeConfig.min, rangeConfig.max))
Expand Down Expand Up @@ -1924,6 +1936,16 @@ bool AclRuleMirror::activate()
setAction(it.first, attr.value.aclaction);
}

// If the rule with mirror action is removed and then mirror is activated, create the counter before rule is created
if (!hasCounter())
{
if (getCreateCounter() && !createCounter())
{
SWSS_LOG_ERROR("createCounter failed for Rule %s session %s", m_id.c_str(), m_sessionName.c_str());
return false;
}
}

if (!AclRule::createRule())
{
return false;
Expand Down
1 change: 1 addition & 0 deletions orchagent/aclorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class AclRule
sai_object_id_t getCounterOid() const;
bool hasCounter() const;
vector<sai_object_id_t> getInPorts() const;
bool getCreateCounter() const;

const vector<AclRangeConfig>& getRangeConfig() const;
static shared_ptr<AclRule> makeShared(AclOrch *acl, MirrorOrch *mirror, DTelOrch *dtel, const string& rule, const string& table, const KeyOpFieldsValuesTuple&);
Expand Down
63 changes: 37 additions & 26 deletions orchagent/mirrororch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extern sai_port_api_t *sai_port_api;
extern sai_object_id_t gSwitchId;
extern PortsOrch* gPortsOrch;
extern string gMySwitchType;
extern IntfsOrch *gIntfsOrch;

using namespace std::rel_ops;

Expand Down Expand Up @@ -583,13 +584,31 @@ void MirrorOrch::setSessionState(const string& name, const MirrorEntry& session,
if (attr.empty() || attr == MIRROR_SESSION_MONITOR_PORT)
{
Port port;
m_portsOrch->getPort(session.neighborInfo.portId, port);
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN) &&
(gIntfsOrch->isRemoteSystemPortIntf(session.neighborInfo.neighbor.alias)))
{
if (!m_portsOrch->getRecircPort(port, "Rec"))
{
SWSS_LOG_ERROR("Failed to get recirc prot mirror session %s", name.c_str());
return;
}
}
else
{
m_portsOrch->getPort(session.neighborInfo.portId, port);
}
fvVector.emplace_back(MIRROR_SESSION_MONITOR_PORT, port.m_alias);
}

if (attr.empty() || attr == MIRROR_SESSION_DST_MAC_ADDRESS)
{
value = session.neighborInfo.mac.to_string();
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
{
value = gMacAddress.to_string();
} else
{
value = session.neighborInfo.mac.to_string();
}
fvVector.emplace_back(MIRROR_SESSION_DST_MAC_ADDRESS, value);
}

Expand Down Expand Up @@ -999,9 +1018,9 @@ bool MirrorOrch::activateSession(const string& name, MirrorEntry& session)

attr.id = SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS;
// Use router mac as mirror dst mac in voq switch.
if (gMySwitchType == "voq")
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
{
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
}
else
{
Expand Down Expand Up @@ -1115,19 +1134,19 @@ bool MirrorOrch::updateSessionDstMac(const string& name, MirrorEntry& session)

sai_attribute_t attr;
attr.id = SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS;
if (gMySwitchType == "voq")
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
{
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
} else
{
memcpy(attr.value.mac, session.neighborInfo.mac.getMac(), sizeof(sai_mac_t));
memcpy(attr.value.mac, session.neighborInfo.mac.getMac(), sizeof(sai_mac_t));
}

sai_status_t status = sai_mirror_api->set_mirror_session_attribute(session.sessionId, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to update mirror session %s destination MAC to %s, rv:%d",
name.c_str(), session.neighborInfo.mac.to_string().c_str(), status);
name.c_str(), sai_serialize_mac(attr.value.mac).c_str(), status);
task_process_status handle_status = handleSaiSetStatus(SAI_API_MIRROR, status);
if (handle_status != task_success)
{
Expand All @@ -1136,7 +1155,7 @@ bool MirrorOrch::updateSessionDstMac(const string& name, MirrorEntry& session)
}

SWSS_LOG_NOTICE("Update mirror session %s destination MAC to %s",
name.c_str(), session.neighborInfo.mac.to_string().c_str());
name.c_str(), sai_serialize_mac(attr.value.mac).c_str());

setSessionState(name, session, MIRROR_SESSION_DST_MAC_ADDRESS);

Expand All @@ -1154,27 +1173,19 @@ bool MirrorOrch::updateSessionDstPort(const string& name, MirrorEntry& session)

sai_attribute_t attr;
attr.id = SAI_MIRROR_SESSION_ATTR_MONITOR_PORT;
if (session.type == MIRROR_SESSION_SPAN)
// Set monitor port to recirc port in voq switch.
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
{
attr.value.oid = session.neighborInfo.portId;
if (!m_portsOrch->getRecircPort(port, "Rec"))
{
SWSS_LOG_ERROR("Failed to get recirc prot mirror session %s", name.c_str());
return false;
}
attr.value.oid = port.m_port_id;
}
else
{
// Set monitor port to recirc port in voq switch.
if (gMySwitchType == "voq")
{
Port recirc_port;
if (!m_portsOrch->getRecircPort(recirc_port, "Rec"))
{
SWSS_LOG_ERROR("Failed to get recirc prot");
return false;
}
attr.value.oid = recirc_port.m_port_id;
}
else
{
attr.value.oid = session.neighborInfo.portId;
}
attr.value.oid = session.neighborInfo.portId;
}

sai_status_t status = sai_mirror_api->
Expand Down

0 comments on commit 7cf981e

Please sign in to comment.