-
Notifications
You must be signed in to change notification settings - Fork 543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[acl]: test different subnet masks #481
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
203005a
Add files via upload
simone-dell a0af570
Test case: ACL rule with diff subnet masks
simone-dell 9774f33
changing addition of acl rules to a loop to avoid redundancy
simone-dell 5a729d5
added a helper function to improve code efficiency
simone-dell a063846
Merge branch 'master' into SubnetMaskAclTest
simone-dell 85c787d
Update test_acl.py
simone-dell 87b7839
Merge branch 'master' into SubnetMaskAclTest
prsunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -779,3 +779,105 @@ def test_V6AclTableDeletion(self, dvs): | |
keys = atbl.getKeys() | ||
# only the default table was left | ||
assert len(keys) == 1 | ||
|
||
def test_RulesWithDiffMaskLengths(self, dvs): | ||
db = swsscommon.DBConnector(4, dvs.redis_sock, 0) | ||
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) | ||
|
||
bind_ports = ["Ethernet0", "Ethernet4"] | ||
# create ACL_TABLE in config db | ||
tbl = swsscommon.Table(db, "ACL_TABLE") | ||
fvs = swsscommon.FieldValuePairs([("policy_desc", "test"), ("type", "L3"), ("ports", ",".join(bind_ports))]) | ||
tbl.set("test_subnet", fvs) | ||
|
||
time.sleep(2) | ||
|
||
subnet_mask_rules = 0 | ||
#create ACL rules | ||
tbl = swsscommon.Table(db, "ACL_RULE") | ||
rules = [ [("PRIORITY", "10"), ("PACKET_ACTION", "FORWARD"), ("SRC_IP", "23.103.0.0/18")], | ||
[("PRIORITY", "20"), ("PACKET_ACTION", "FORWARD"), ("SRC_IP", "104.44.94.0/23")], | ||
[("PRIORITY", "30"), ("PACKET_ACTION", "FORWARD"), ("DST_IP", "172.16.0.0/12")], | ||
[("PRIORITY", "40"), ("PACKET_ACTION", "FORWARD"), ("DST_IP", "100.64.0.0/10")], | ||
[("PRIORITY", "50"), ("PACKET_ACTION", "FORWARD"), ("DST_IP", "104.146.32.0/19")], | ||
[("PRIORITY", "60"), ("PACKET_ACTION", "FORWARD"), ("SRC_IP", "21.0.0.0/8")] ] | ||
for rule in rules: | ||
fvs = swsscommon.FieldValuePairs(rule) | ||
subnet_mask_rules += 1 | ||
tbl.set( "test_subnet|acl_test_rule%s" % subnet_mask_rules, fvs ) | ||
|
||
time.sleep(1) | ||
|
||
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_ENTRY") | ||
keys = atbl.getKeys() | ||
|
||
acl_entry = [k for k in keys if k not in dvs.asicdb.default_acl_entries] | ||
assert len(acl_entry) == subnet_mask_rules | ||
|
||
matched_masks = 0 | ||
for entry in acl_entry: | ||
(status, fvs) = atbl.get(entry) | ||
assert status == True | ||
assert len(fvs) == 6 | ||
if ('SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP', '23.103.0.0&mask:255.255.192.0') in fvs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is code redundancy in the block as well. can you define a function as below as use the function to check all entries in acl_entry?
|
||
matched_masks += 1 | ||
for fv in fvs: | ||
if fv[0] == "SAI_ACL_ENTRY_ATTR_PRIORITY": | ||
assert fv[1] == "10" | ||
elif fv[0] == "SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION": | ||
assert fv[1] == "SAI_PACKET_ACTION_FORWARD" | ||
if ('SAI_ACL_ENTRY_ATTR_FIELD_DST_IP', '100.64.0.0&mask:255.192.0.0') in fvs: | ||
matched_masks += 1 | ||
for fv in fvs: | ||
if fv[0] == "SAI_ACL_ENTRY_ATTR_PRIORITY": | ||
assert fv[1] == "40" | ||
elif fv[0] == "SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION": | ||
assert fv[1] == "SAI_PACKET_ACTION_FORWARD" | ||
if ('SAI_ACL_ENTRY_ATTR_FIELD_DST_IP', '172.16.0.0&mask:255.240.0.0') in fvs: | ||
matched_masks += 1 | ||
for fv in fvs: | ||
if fv[0] == "SAI_ACL_ENTRY_ATTR_PRIORITY": | ||
assert fv[1] == "30" | ||
elif fv[0] == "SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION": | ||
assert fv[1] == "SAI_PACKET_ACTION_FORWARD" | ||
if ('SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP', '104.44.94.0&mask:255.255.254.0') in fvs: | ||
matched_masks += 1 | ||
for fv in fvs: | ||
if fv[0] == "SAI_ACL_ENTRY_ATTR_PRIORITY": | ||
assert fv[1] == "20" | ||
elif fv[0] == "SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION": | ||
assert fv[1] == "SAI_PACKET_ACTION_FORWARD" | ||
if ('SAI_ACL_ENTRY_ATTR_FIELD_SRC_IP', '21.0.0.0&mask:255.0.0.0') in fvs: | ||
matched_masks += 1 | ||
for fv in fvs: | ||
if fv[0] == "SAI_ACL_ENTRY_ATTR_PRIORITY": | ||
assert fv[1] == "60" | ||
elif fv[0] == "SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION": | ||
assert fv[1] == "SAI_PACKET_ACTION_FORWARD" | ||
if ('SAI_ACL_ENTRY_ATTR_FIELD_DST_IP', '104.146.32.0&mask:255.255.224.0') in fvs: | ||
matched_masks += 1 | ||
for fv in fvs: | ||
if fv[0] == "SAI_ACL_ENTRY_ATTR_PRIORITY": | ||
assert fv[1] == "50" | ||
elif fv[0] == "SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION": | ||
assert fv[1] == "SAI_PACKET_ACTION_FORWARD" | ||
|
||
assert matched_masks == subnet_mask_rules | ||
|
||
while subnet_mask_rules > 0: | ||
tbl._del("test_subnet|acl_test_rule%s" % subnet_mask_rules) | ||
subnet_mask_rules -= 1 | ||
|
||
time.sleep(1) | ||
|
||
(status, fvs) = atbl.get(acl_entry[0]) | ||
assert status == False | ||
|
||
tbl = swsscommon.Table(db, "ACL_TABLE") | ||
tbl._del("test_subnet") | ||
|
||
time.sleep(1) | ||
|
||
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE") | ||
keys = atbl.getKeys() | ||
assert len(keys) == 1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use for loop to simplify the logic? there are quite a few redundant code here.