Skip to content

Commit 13bda3c

Browse files
[Everflow/ERSPAN] Set correct destination port and mac address when the nexthop is updated for ERSPAN mirror destination (sonic-net#2392)
* [Everflow/ERSPAN] Set correct destination port and mac address when the nexthop is updated for ERSPAN mirror destination * [Everflow] Fixed show mirror-session, Acl rule remove failure, orchagent crash Signed-off-by: Sakthivadivu Saravanaraj <[email protected]>
1 parent 0ccb315 commit 13bda3c

File tree

4 files changed

+91
-13
lines changed

4 files changed

+91
-13
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

+45-9
Original file line numberDiff line numberDiff line change
@@ -583,13 +583,30 @@ void MirrorOrch::setSessionState(const string& name, const MirrorEntry& session,
583583
if (attr.empty() || attr == MIRROR_SESSION_MONITOR_PORT)
584584
{
585585
Port port;
586-
m_portsOrch->getPort(session.neighborInfo.portId, port);
586+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
587+
{
588+
if (!m_portsOrch->getRecircPort(port, "Rec"))
589+
{
590+
SWSS_LOG_ERROR("Failed to get recirc port for mirror session %s", name.c_str());
591+
return;
592+
}
593+
}
594+
else
595+
{
596+
m_portsOrch->getPort(session.neighborInfo.portId, port);
597+
}
587598
fvVector.emplace_back(MIRROR_SESSION_MONITOR_PORT, port.m_alias);
588599
}
589600

590601
if (attr.empty() || attr == MIRROR_SESSION_DST_MAC_ADDRESS)
591602
{
592-
value = session.neighborInfo.mac.to_string();
603+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
604+
{
605+
value = gMacAddress.to_string();
606+
} else
607+
{
608+
value = session.neighborInfo.mac.to_string();
609+
}
593610
fvVector.emplace_back(MIRROR_SESSION_DST_MAC_ADDRESS, value);
594611
}
595612

@@ -928,7 +945,7 @@ bool MirrorOrch::activateSession(const string& name, MirrorEntry& session)
928945
Port recirc_port;
929946
if (!m_portsOrch->getRecircPort(recirc_port, "Rec"))
930947
{
931-
SWSS_LOG_ERROR("Failed to get recirc prot");
948+
SWSS_LOG_ERROR("Failed to get recirc port");
932949
return false;
933950
}
934951
attr.value.oid = recirc_port.m_port_id;
@@ -999,9 +1016,9 @@ bool MirrorOrch::activateSession(const string& name, MirrorEntry& session)
9991016

10001017
attr.id = SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS;
10011018
// Use router mac as mirror dst mac in voq switch.
1002-
if (gMySwitchType == "voq")
1019+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
10031020
{
1004-
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
1021+
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
10051022
}
10061023
else
10071024
{
@@ -1115,13 +1132,19 @@ bool MirrorOrch::updateSessionDstMac(const string& name, MirrorEntry& session)
11151132

11161133
sai_attribute_t attr;
11171134
attr.id = SAI_MIRROR_SESSION_ATTR_DST_MAC_ADDRESS;
1118-
memcpy(attr.value.mac, session.neighborInfo.mac.getMac(), sizeof(sai_mac_t));
1135+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
1136+
{
1137+
memcpy(attr.value.mac, gMacAddress.getMac(), sizeof(sai_mac_t));
1138+
} else
1139+
{
1140+
memcpy(attr.value.mac, session.neighborInfo.mac.getMac(), sizeof(sai_mac_t));
1141+
}
11191142

11201143
sai_status_t status = sai_mirror_api->set_mirror_session_attribute(session.sessionId, &attr);
11211144
if (status != SAI_STATUS_SUCCESS)
11221145
{
11231146
SWSS_LOG_ERROR("Failed to update mirror session %s destination MAC to %s, rv:%d",
1124-
name.c_str(), session.neighborInfo.mac.to_string().c_str(), status);
1147+
name.c_str(), sai_serialize_mac(attr.value.mac).c_str(), status);
11251148
task_process_status handle_status = handleSaiSetStatus(SAI_API_MIRROR, status);
11261149
if (handle_status != task_success)
11271150
{
@@ -1130,7 +1153,7 @@ bool MirrorOrch::updateSessionDstMac(const string& name, MirrorEntry& session)
11301153
}
11311154

11321155
SWSS_LOG_NOTICE("Update mirror session %s destination MAC to %s",
1133-
name.c_str(), session.neighborInfo.mac.to_string().c_str());
1156+
name.c_str(), sai_serialize_mac(attr.value.mac).c_str());
11341157

11351158
setSessionState(name, session, MIRROR_SESSION_DST_MAC_ADDRESS);
11361159

@@ -1148,7 +1171,20 @@ bool MirrorOrch::updateSessionDstPort(const string& name, MirrorEntry& session)
11481171

11491172
sai_attribute_t attr;
11501173
attr.id = SAI_MIRROR_SESSION_ATTR_MONITOR_PORT;
1151-
attr.value.oid = session.neighborInfo.portId;
1174+
// Set monitor port to recirc port in voq switch.
1175+
if ((gMySwitchType == "voq") && (session.type == MIRROR_SESSION_ERSPAN))
1176+
{
1177+
if (!m_portsOrch->getRecircPort(port, "Rec"))
1178+
{
1179+
SWSS_LOG_ERROR("Failed to get recirc port for mirror session %s", name.c_str());
1180+
return false;
1181+
}
1182+
attr.value.oid = port.m_port_id;
1183+
}
1184+
else
1185+
{
1186+
attr.value.oid = session.neighborInfo.portId;
1187+
}
11521188

11531189
sai_status_t status = sai_mirror_api->
11541190
set_mirror_session_attribute(session.sessionId, &attr);

orchagent/neighorch.cpp

+23-4
Original file line numberDiff line numberDiff line change
@@ -597,18 +597,37 @@ void NeighOrch::decreaseNextHopRefCount(const NextHopKey &nexthop, uint32_t coun
597597

598598
bool NeighOrch::getNeighborEntry(const NextHopKey &nexthop, NeighborEntry &neighborEntry, MacAddress &macAddress)
599599
{
600+
Port inbp;
601+
string nbr_alias;
600602
if (!hasNextHop(nexthop))
601603
{
602604
return false;
603605
}
606+
if (gMySwitchType == "voq")
607+
{
608+
gPortsOrch->getInbandPort(inbp);
609+
assert(inbp.m_alias.length());
610+
}
604611

605612
for (const auto &entry : m_syncdNeighbors)
606613
{
607-
if (entry.first.ip_address == nexthop.ip_address && entry.first.alias == nexthop.alias)
614+
if (entry.first.ip_address == nexthop.ip_address)
608615
{
609-
neighborEntry = entry.first;
610-
macAddress = entry.second.mac;
611-
return true;
616+
if (m_intfsOrch->isRemoteSystemPortIntf(entry.first.alias))
617+
{
618+
//For remote system ports, nexthops are always on inband.
619+
nbr_alias = inbp.m_alias;
620+
}
621+
else
622+
{
623+
nbr_alias = entry.first.alias;
624+
}
625+
if (nbr_alias == nexthop.alias)
626+
{
627+
neighborEntry = entry.first;
628+
macAddress = entry.second.mac;
629+
return true;
630+
}
612631
}
613632
}
614633

0 commit comments

Comments
 (0)