Skip to content

Commit

Permalink
[mirror] Detach session dst ip from route orch LPM calculation regard…
Browse files Browse the repository at this point in the history
…less of session status at session CONFIG DB removal (sonic-net#1800)

* Detach dst ip from routeorch lpm calculation regardless of mirror session status
Signed-off-by: Wenda Ni <wonda.ni@gmail.com>
  • Loading branch information
wendani authored Jul 2, 2021
1 parent a39673d commit 1367646
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions orchagent/mirrororch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,17 +479,18 @@ task_process_status MirrorOrch::deleteEntry(const string& name)

if (session.status)
{
if (session.type != MIRROR_SESSION_SPAN)
{
m_routeOrch->detach(this, session.dstIp);
}
if (!deactivateSession(name, session))
{
SWSS_LOG_ERROR("Failed to remove mirror session %s", name.c_str());
return task_process_status::task_failed;
}
}

if (session.type != MIRROR_SESSION_SPAN)
{
m_routeOrch->detach(this, session.dstIp);
}

if (!session.policer.empty())
{
m_policerOrch->decreaseRefCount(session.policer);
Expand Down
15 changes: 15 additions & 0 deletions tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def get_mirror_session_state(self, name):
assert len(fvs) > 0
return { fv[0]: fv[1] for fv in fvs }

def check_syslog(self, dvs, marker, log, expected_cnt):
(ec, out) = dvs.runcmd(['sh', '-c', "awk \'/%s/,ENDFILE {print;}\' /var/log/syslog | grep \'%s\' | wc -l" % (marker, log)])
assert out.strip() == str(expected_cnt)

def test_MirrorAddRemove(self, dvs, testlog):
"""
Expand All @@ -120,9 +123,11 @@ def test_MirrorAddRemove(self, dvs, testlog):

session = "TEST_SESSION"

marker = dvs.add_log_marker()
# create mirror session
self.create_mirror_session(session, "1.1.1.1", "2.2.2.2", "0x6558", "8", "100", "0")
assert self.get_mirror_session_state(session)["status"] == "inactive"
self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP 2.2.2.2", 1)

# bring up Ethernet16
self.set_interface_status(dvs, "Ethernet16", "up")
Expand Down Expand Up @@ -193,8 +198,10 @@ def test_MirrorAddRemove(self, dvs, testlog):
self.set_interface_status(dvs, "Ethernet16", "down")
assert self.get_mirror_session_state(session)["status"] == "inactive"

marker = dvs.add_log_marker()
# remove mirror session
self.remove_mirror_session(session)
self.check_syslog(dvs, marker, "Detached next hop observer for destination IP 2.2.2.2", 1)

def create_vlan(self, dvs, vlan):
#dvs.runcmd("ip link del Bridge")
Expand Down Expand Up @@ -251,9 +258,11 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog):

session = "TEST_SESSION"

marker = dvs.add_log_marker()
# create mirror session
self.create_mirror_session(session, "5.5.5.5", "6.6.6.6", "0x6558", "8", "100", "0")
assert self.get_mirror_session_state(session)["status"] == "inactive"
self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP 6.6.6.6", 1)

# create vlan; create vlan member
self.create_vlan(dvs, "6")
Expand Down Expand Up @@ -339,8 +348,10 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog):
self.remove_vlan_member("6", "Ethernet4")
self.remove_vlan("6")

marker = dvs.add_log_marker()
# remove mirror session
self.remove_mirror_session(session)
self.check_syslog(dvs, marker, "Detached next hop observer for destination IP 6.6.6.6", 1)

def create_port_channel(self, dvs, channel):
tbl = swsscommon.ProducerStateTable(self.pdb, "LAG_TABLE")
Expand Down Expand Up @@ -388,9 +399,11 @@ def test_MirrorToLagAddRemove(self, dvs, testlog):

session = "TEST_SESSION"

marker = dvs.add_log_marker()
# create mirror session
self.create_mirror_session(session, "10.10.10.10", "11.11.11.11", "0x6558", "8", "100", "0")
assert self.get_mirror_session_state(session)["status"] == "inactive"
self.check_syslog(dvs, marker, "Attached next hop observer .* for destination IP 11.11.11.11", 1)

# create port channel; create port channel member
self.create_port_channel(dvs, "008")
Expand Down Expand Up @@ -436,8 +449,10 @@ def test_MirrorToLagAddRemove(self, dvs, testlog):
self.remove_port_channel_member("008", "Ethernet88")
self.remove_port_channel(dvs, "008")

marker = dvs.add_log_marker()
# remove mirror session
self.remove_mirror_session(session)
self.check_syslog(dvs, marker, "Detached next hop observer for destination IP 11.11.11.11", 1)


# Ignore testcase in Debian Jessie
Expand Down

0 comments on commit 1367646

Please sign in to comment.