Skip to content

Commit 736a332

Browse files
authored
[acl mirror action] Mirror session ref count fix at acl rule attachment (sonic-net#1761)
* Fix mirror session ref count at acl rule attachement Signed-off-by: wenda.ni <[email protected]>
1 parent d2bcccf commit 736a332

2 files changed

Lines changed: 36 additions & 16 deletions

File tree

orchagent/aclorch.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,13 +1225,6 @@ bool AclRuleMirror::create()
12251225
SWSS_LOG_THROW("Failed to get mirror session state for session %s", m_sessionName.c_str());
12261226
}
12271227

1228-
// Increase session reference count regardless of state to deny
1229-
// attempt to remove mirror session with attached ACL rules.
1230-
if (!m_pMirrorOrch->increaseRefCount(m_sessionName))
1231-
{
1232-
SWSS_LOG_THROW("Failed to increase mirror session reference count for session %s", m_sessionName.c_str());
1233-
}
1234-
12351228
if (!state)
12361229
{
12371230
return true;
@@ -1254,6 +1247,11 @@ bool AclRuleMirror::create()
12541247
return false;
12551248
}
12561249

1250+
if (!m_pMirrorOrch->increaseRefCount(m_sessionName))
1251+
{
1252+
SWSS_LOG_THROW("Failed to increase mirror session reference count for session %s", m_sessionName.c_str());
1253+
}
1254+
12571255
m_state = true;
12581256

12591257
return true;

tests/test_mirror.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,11 @@ def test_AclBindMirrorPerStage(self, dvs, testlog):
805805
self.remove_ip_address("Ethernet32", "20.0.0.0/31")
806806
self.set_interface_status(dvs, "Ethernet32", "down")
807807

808-
def test_AclBindMirror(self, dvs, testlog):
808+
def _test_AclBindMirror(self, dvs, testlog, create_seq_test=False):
809809
"""
810810
This test tests ACL associated with mirror session with DSCP value
811811
The DSCP value is tested on both with mask and without mask
812812
"""
813-
self.setup_db(dvs)
814813

815814
session = "MIRROR_SESSION"
816815
acl_table = "MIRROR_TABLE"
@@ -820,27 +819,44 @@ def test_AclBindMirror(self, dvs, testlog):
820819
self.set_interface_status(dvs, "Ethernet32", "up")
821820
self.add_ip_address("Ethernet32", "20.0.0.0/31")
822821
self.add_neighbor("Ethernet32", "20.0.0.1", "02:04:06:08:10:12")
823-
self.add_route(dvs, "4.4.4.4", "20.0.0.1")
822+
if create_seq_test == False:
823+
self.add_route(dvs, "4.4.4.4", "20.0.0.1")
824824

825825
# create mirror session
826826
self.create_mirror_session(session, "3.3.3.3", "4.4.4.4", "0x6558", "8", "100", "0")
827-
assert self.get_mirror_session_state(session)["status"] == "active"
827+
assert self.get_mirror_session_state(session)["status"] == ("active" if create_seq_test == False else "inactive")
828828

829-
# assert mirror session in asic database
829+
# check mirror session in asic database
830830
tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_MIRROR_SESSION")
831-
assert len(tbl.getKeys()) == 1
832-
mirror_session_oid = tbl.getKeys()[0]
831+
assert len(tbl.getKeys()) == (1 if create_seq_test == False else 0)
832+
if create_seq_test == False:
833+
mirror_session_oid = tbl.getKeys()[0]
833834

834835
# create acl table
835836
self.create_acl_table(acl_table, ["Ethernet0", "Ethernet4"])
836837

837838
# create acl rule with dscp value 48
838839
self.create_mirror_acl_dscp_rule(acl_table, acl_rule, "48", session)
839840

840-
# assert acl rule is created
841+
# acl rule creation check
841842
tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_ENTRY")
842843
rule_entries = [k for k in tbl.getKeys() if k not in dvs.asicdb.default_acl_entries]
843-
assert len(rule_entries) == 1
844+
assert len(rule_entries) == (1 if create_seq_test == False else 0)
845+
846+
if create_seq_test == True:
847+
self.add_route(dvs, "4.4.4.4", "20.0.0.1")
848+
849+
assert self.get_mirror_session_state(session)["status"] == "active"
850+
851+
# assert mirror session in asic database
852+
tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_MIRROR_SESSION")
853+
assert len(tbl.getKeys()) == 1
854+
mirror_session_oid = tbl.getKeys()[0]
855+
856+
# assert acl rule is created
857+
tbl = swsscommon.Table(self.adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_ENTRY")
858+
rule_entries = [k for k in tbl.getKeys() if k not in dvs.asicdb.default_acl_entries]
859+
assert len(rule_entries) == 1
844860

845861
(status, fvs) = tbl.get(rule_entries[0])
846862
assert status == True
@@ -888,6 +904,12 @@ def test_AclBindMirror(self, dvs, testlog):
888904
self.remove_ip_address("Ethernet32", "20.0.0.0/31")
889905
self.set_interface_status(dvs, "Ethernet32", "down")
890906

907+
def test_AclBindMirror(self, dvs, testlog):
908+
self.setup_db(dvs)
909+
910+
self._test_AclBindMirror(dvs, testlog)
911+
self._test_AclBindMirror(dvs, testlog, create_seq_test=True)
912+
891913

892914
# Add Dummy always-pass test at end as workaroud
893915
# for issue when Flaky fail on final test it invokes module tear-down before retrying

0 commit comments

Comments
 (0)