Skip to content

Commit 7cf981e

Browse files
[Everflow] Fixed show mirror-session, Acl rule remove failure, orchagent
crash Signed-off-by: Sakthivadivu Saravanaraj <[email protected]>
1 parent f2fded5 commit 7cf981e

File tree

3 files changed

+60
-26
lines changed

3 files changed

+60
-26
lines changed

orchagent/aclorch.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,11 @@ const vector<AclRangeConfig>& AclRule::getRangeConfig() const
14771477
return m_rangeConfig;
14781478
}
14791479

1480+
bool AclRule::getCreateCounter() const
1481+
{
1482+
return m_createCounter;
1483+
}
1484+
14801485
shared_ptr<AclRule> AclRule::makeShared(AclOrch *acl, MirrorOrch *mirror, DTelOrch *dtel, const string& rule, const string& table, const KeyOpFieldsValuesTuple& data)
14811486
{
14821487
shared_ptr<AclRule> aclRule;
@@ -1624,6 +1629,13 @@ bool AclRule::createCounter()
16241629
bool AclRule::removeRanges()
16251630
{
16261631
SWSS_LOG_ENTER();
1632+
if (!m_ranges.size())
1633+
{
1634+
//The Acl Rules which have mirror action will not have ranges created till the mirror becomes active
1635+
SWSS_LOG_INFO("No Acl Range created for ACL Rule %s in table %s", m_id.c_str(), m_pTable->getId().c_str());
1636+
return true;
1637+
}
1638+
16271639
for (const auto& rangeConfig: m_rangeConfig)
16281640
{
16291641
if (!AclRange::remove(rangeConfig.rangeType, rangeConfig.min, rangeConfig.max))
@@ -1924,6 +1936,16 @@ bool AclRuleMirror::activate()
19241936
setAction(it.first, attr.value.aclaction);
19251937
}
19261938

1939+
// If the rule with mirror action is removed and then mirror is activated, create the counter before rule is created
1940+
if (!hasCounter())
1941+
{
1942+
if (getCreateCounter() && !createCounter())
1943+
{
1944+
SWSS_LOG_ERROR("createCounter failed for Rule %s session %s", m_id.c_str(), m_sessionName.c_str());
1945+
return false;
1946+
}
1947+
}
1948+
19271949
if (!AclRule::createRule())
19281950
{
19291951
return false;

orchagent/aclorch.h

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class AclRule
263263
sai_object_id_t getCounterOid() const;
264264
bool hasCounter() const;
265265
vector<sai_object_id_t> getInPorts() const;
266+
bool getCreateCounter() const;
266267

267268
const vector<AclRangeConfig>& getRangeConfig() const;
268269
static shared_ptr<AclRule> makeShared(AclOrch *acl, MirrorOrch *mirror, DTelOrch *dtel, const string& rule, const string& table, const KeyOpFieldsValuesTuple&);

orchagent/mirrororch.cpp

+37-26
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern sai_port_api_t *sai_port_api;
5050
extern sai_object_id_t gSwitchId;
5151
extern PortsOrch* gPortsOrch;
5252
extern string gMySwitchType;
53+
extern IntfsOrch *gIntfsOrch;
5354

5455
using namespace std::rel_ops;
5556

@@ -583,13 +584,31 @@ void MirrorOrch::setSessionState(const string& name, const MirrorEntry& session,
583584
if (attr.empty() || attr == MIRROR_SESSION_MONITOR_PORT)
584585
{
585586
Port port;
586-
m_portsOrch->getPort(session.neighborInfo.portId, port);
587+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN) &&
588+
(gIntfsOrch->isRemoteSystemPortIntf(session.neighborInfo.neighbor.alias)))
589+
{
590+
if (!m_portsOrch->getRecircPort(port, "Rec"))
591+
{
592+
SWSS_LOG_ERROR("Failed to get recirc prot mirror session %s", name.c_str());
593+
return;
594+
}
595+
}
596+
else
597+
{
598+
m_portsOrch->getPort(session.neighborInfo.portId, port);
599+
}
587600
fvVector.emplace_back(MIRROR_SESSION_MONITOR_PORT, port.m_alias);
588601
}
589602

590603
if (attr.empty() || attr == MIRROR_SESSION_DST_MAC_ADDRESS)
591604
{
592-
value = session.neighborInfo.mac.to_string();
605+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
606+
{
607+
value = gMacAddress.to_string();
608+
} else
609+
{
610+
value = session.neighborInfo.mac.to_string();
611+
}
593612
fvVector.emplace_back(MIRROR_SESSION_DST_MAC_ADDRESS, value);
594613
}
595614

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

10001019
attr.id = SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS;
10011020
// Use router mac as mirror dst mac in voq switch.
1002-
if (gMySwitchType == "voq")
1021+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
10031022
{
1004-
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
1023+
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
10051024
}
10061025
else
10071026
{
@@ -1115,19 +1134,19 @@ bool MirrorOrch::updateSessionDstMac(const string& name, MirrorEntry& session)
11151134

11161135
sai_attribute_t attr;
11171136
attr.id = SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS;
1118-
if (gMySwitchType == "voq")
1137+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
11191138
{
1120-
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
1139+
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
11211140
} else
11221141
{
1123-
memcpy(attr.value.mac, session.neighborInfo.mac.getMac(), sizeof(sai_mac_t));
1142+
memcpy(attr.value.mac, session.neighborInfo.mac.getMac(), sizeof(sai_mac_t));
11241143
}
11251144

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

11381157
SWSS_LOG_NOTICE("Update mirror session %s destination MAC to %s",
1139-
name.c_str(), session.neighborInfo.mac.to_string().c_str());
1158+
name.c_str(), sai_serialize_mac(attr.value.mac).c_str());
11401159

11411160
setSessionState(name, session, MIRROR_SESSION_DST_MAC_ADDRESS);
11421161

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

11551174
sai_attribute_t attr;
11561175
attr.id = SAI_MIRROR_SESSION_ATTR_MONITOR_PORT;
1157-
if (session.type == MIRROR_SESSION_SPAN)
1176+
// Set monitor port to recirc port in voq switch.
1177+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
11581178
{
1159-
attr.value.oid = session.neighborInfo.portId;
1179+
if (!m_portsOrch->getRecircPort(port, "Rec"))
1180+
{
1181+
SWSS_LOG_ERROR("Failed to get recirc prot mirror session %s", name.c_str());
1182+
return false;
1183+
}
1184+
attr.value.oid = port.m_port_id;
11601185
}
11611186
else
11621187
{
1163-
// Set monitor port to recirc port in voq switch.
1164-
if (gMySwitchType == "voq")
1165-
{
1166-
Port recirc_port;
1167-
if (!m_portsOrch->getRecircPort(recirc_port, "Rec"))
1168-
{
1169-
SWSS_LOG_ERROR("Failed to get recirc prot");
1170-
return false;
1171-
}
1172-
attr.value.oid = recirc_port.m_port_id;
1173-
}
1174-
else
1175-
{
1176-
attr.value.oid = session.neighborInfo.portId;
1177-
}
1188+
attr.value.oid = session.neighborInfo.portId;
11781189
}
11791190

11801191
sai_status_t status = sai_mirror_api->

0 commit comments

Comments
 (0)