-
Notifications
You must be signed in to change notification settings - Fork 715
[dump] implement ACL modules #2153
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ba39fd
[dump] implement ACL modules
stepanblyschak b69a0f7
fix review comments
stepanblyschak c0fc915
review comments
stepanblyschak 3a66f08
use raw_to_typed
stepanblyschak bf9188f
Merge branch 'master' of https://github.com/Azure/sonic-utilities int…
stepanblyschak 0ff5de4
internal review fixes
stepanblyschak a4e5614
remove unused import
stepanblyschak 94ad60b
fix review comment
stepanblyschak 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from dump.helper import create_template_dict | ||
from dump.match_infra import MatchRequest | ||
from swsscommon.swsscommon import SonicDBConfig | ||
|
||
from dump.match_helper import fetch_acl_counter_oid | ||
from .executor import Executor | ||
|
||
|
||
CFG_DB_SEPARATOR = SonicDBConfig.getSeparator("CONFIG_DB") | ||
ASIC_DB_SEPARATOR = SonicDBConfig.getSeparator("ASIC_DB") | ||
|
||
|
||
class Acl_Rule(Executor): | ||
""" | ||
Debug Dump Plugin for ACL Rule Module | ||
""" | ||
ARG_NAME = "acl_rule_name" | ||
|
||
def __init__(self, match_engine=None): | ||
super().__init__(match_engine) | ||
|
||
def get_all_args(self, ns=""): | ||
req = MatchRequest(db="CONFIG_DB", table="ACL_RULE", key_pattern="*", ns=ns) | ||
ret = self.match_engine.fetch(req) | ||
acl_rules = ret["keys"] | ||
return [key.split(CFG_DB_SEPARATOR, 1)[-1] for key in acl_rules] | ||
|
||
def execute(self, params): | ||
self.ret_temp = create_template_dict(dbs=["CONFIG_DB", "ASIC_DB"]) | ||
|
||
try: | ||
acl_table_name, acl_rule_name = params[self.ARG_NAME].split(CFG_DB_SEPARATOR, 1) | ||
except ValueError: | ||
raise ValueError(f"Invalid rule name passed {params[self.ARG_NAME]}") | ||
|
||
self.ns = params["namespace"] | ||
self.init_acl_rule_config_info(acl_table_name, acl_rule_name) | ||
self.init_acl_rule_asic_info(acl_table_name, acl_rule_name) | ||
return self.ret_temp | ||
|
||
def init_acl_rule_config_info(self, acl_table_name, acl_rule_name): | ||
req = MatchRequest(db="CONFIG_DB", table="ACL_RULE", | ||
key_pattern=CFG_DB_SEPARATOR.join([acl_table_name, acl_rule_name]), ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) | ||
|
||
def init_acl_rule_asic_info(self, acl_table_name, acl_rule_name): | ||
counter_oid = fetch_acl_counter_oid(self.match_engine, acl_table_name, acl_rule_name, self.ns) | ||
if not counter_oid: | ||
return | ||
|
||
req = MatchRequest(db="ASIC_DB", table=ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_COUNTER"]), | ||
key_pattern=counter_oid, return_fields=["SAI_ACL_COUNTER_ATTR_TABLE_ID"], ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) | ||
|
||
return_values = ret["return_values"] | ||
counter_object = return_values.get(ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_COUNTER", counter_oid]), {}) | ||
table_oid = counter_object.get("SAI_ACL_COUNTER_ATTR_TABLE_ID") | ||
if not table_oid: | ||
raise Exception("Invalid counter object without table OID in ASIC_DB") | ||
|
||
req = MatchRequest(db="ASIC_DB", table=ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_ENTRY"]), key_pattern="*", | ||
field="SAI_ACL_ENTRY_ATTR_TABLE_ID", value=table_oid, | ||
return_fields=["SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE"], ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) | ||
|
||
range_oids = set() | ||
for _, entry in ret["return_values"].items(): | ||
range_attr_value = entry.get("SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE") | ||
if not range_attr_value: | ||
continue | ||
ranges_attr_value = range_attr_value.split(ASIC_DB_SEPARATOR, 1) | ||
if len(range_attr_value) < 2: | ||
raise Exception("Invalid SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE field format") | ||
for oid in ranges_attr_value[1].split(','): | ||
range_oids.add(oid) | ||
|
||
for range_oid in range_oids: | ||
req = MatchRequest(db="ASIC_DB", table=ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_RANGE"]), | ||
key_pattern=range_oid, ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from dump.helper import create_template_dict | ||
from dump.match_infra import MatchRequest | ||
from swsscommon.swsscommon import SonicDBConfig | ||
|
||
from dump.match_helper import fetch_acl_counter_oid | ||
from .executor import Executor | ||
|
||
|
||
CFG_DB_SEPARATOR = SonicDBConfig.getSeparator("CONFIG_DB") | ||
ASIC_DB_SEPARATOR = SonicDBConfig.getSeparator("ASIC_DB") | ||
|
||
|
||
class Acl_Table(Executor): | ||
""" | ||
Debug Dump Plugin for ACL Table Module | ||
""" | ||
ARG_NAME = "acl_table_name" | ||
|
||
def __init__(self, match_engine=None): | ||
super().__init__(match_engine) | ||
|
||
def get_all_args(self, ns=""): | ||
req = MatchRequest(db="CONFIG_DB", table="ACL_TABLE", key_pattern="*", ns=ns) | ||
ret = self.match_engine.fetch(req) | ||
acl_tables = ret["keys"] | ||
return [key.split(CFG_DB_SEPARATOR)[-1] for key in acl_tables] | ||
|
||
def execute(self, params): | ||
self.ret_temp = create_template_dict(dbs=["CONFIG_DB", "ASIC_DB"]) | ||
acl_table_name = params[self.ARG_NAME] | ||
self.ns = params["namespace"] | ||
self.init_acl_table_config_info(acl_table_name) | ||
self.init_acl_table_asic_info(acl_table_name) | ||
return self.ret_temp | ||
|
||
def init_acl_table_config_info(self, acl_table_name): | ||
req = MatchRequest(db="CONFIG_DB", table="ACL_TABLE", key_pattern=acl_table_name, return_fields=["type"], ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) | ||
|
||
# Find corresponding ACL table type in CONFIG DB | ||
return_values = ret["return_values"] | ||
acl_table_type_name = return_values.get(CFG_DB_SEPARATOR.join(["ACL_TABLE", acl_table_name]), {}).get("type") | ||
req = MatchRequest(db="CONFIG_DB", table="ACL_TABLE_TYPE", key_pattern=acl_table_type_name, ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
# If not found don't add it to the table, it might be a default table type | ||
if ret["keys"]: | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) | ||
|
||
def init_acl_table_asic_info(self, acl_table_name): | ||
req = MatchRequest(db="CONFIG_DB", table="ACL_RULE", key_pattern=CFG_DB_SEPARATOR.join([acl_table_name, "*"]), ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
acl_rules = ret["keys"] | ||
if not acl_rules: | ||
return | ||
acl_rule_name = acl_rules[0].split(CFG_DB_SEPARATOR)[-1] | ||
|
||
counter_oid = fetch_acl_counter_oid(self.match_engine, acl_table_name, acl_rule_name, self.ns) | ||
if not counter_oid: | ||
return | ||
|
||
req = MatchRequest(db="ASIC_DB", table=ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_COUNTER"]), | ||
key_pattern=counter_oid, return_fields=["SAI_ACL_COUNTER_ATTR_TABLE_ID"], ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
|
||
return_values = ret["return_values"] | ||
counter_object = return_values.get(ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_COUNTER", counter_oid]), {}) | ||
table_oid = counter_object.get("SAI_ACL_COUNTER_ATTR_TABLE_ID") | ||
if not table_oid: | ||
raise Exception("Invalid counter object without table OID in ASIC_DB") | ||
|
||
req = MatchRequest(db="ASIC_DB", table=ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_TABLE"]), | ||
key_pattern=table_oid, ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) | ||
|
||
req = MatchRequest(db="ASIC_DB", table=ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER"]), | ||
key_pattern="*", field="SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID", | ||
value=table_oid, return_fields=["SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID"], ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) | ||
|
||
group_oids = set() | ||
for _, entry in ret["return_values"].items(): | ||
group_oids.add(entry.get("SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID")) | ||
|
||
for group_oid in group_oids: | ||
req = MatchRequest(db="ASIC_DB", table=ASIC_DB_SEPARATOR.join(["ASIC_STATE", "SAI_OBJECT_TYPE_ACL_TABLE_GROUP"]), | ||
key_pattern=group_oid, ns=self.ns) | ||
ret = self.match_engine.fetch(req) | ||
self.add_to_ret_template(req.table, req.db, ret["keys"], ret["error"]) |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE:oid:0x7000000000600": { | ||
"SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST": "2:SAI_ACL_BIND_POINT_TYPE_PORT,SAI_ACL_BIND_POINT_TYPE_LAG", | ||
"SAI_ACL_TABLE_ATTR_ACL_STAGE": "SAI_ACL_STAGE_INGRESS", | ||
"SAI_ACL_TABLE_ATTR_FIELD_ACL_ETHER_TYPE": "true" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc000000000601": { | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID": "oid:0xb0000000005f5", | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID": "oid:0x7000000000600", | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY": "100" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc000000000602": { | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID": "oid:0xb0000000005f7", | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID": "oid:0x7000000000600", | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY": "100" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP:oid:0xb0000000005f5": { | ||
"SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST": "1:SAI_ACL_BIND_POINT_TYPE_PORT", | ||
"SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE": "SAI_ACL_STAGE_INGRESS", | ||
"SAI_ACL_TABLE_GROUP_ATTR_TYPE": "SAI_ACL_TABLE_GROUP_TYPE_PARALLEL" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP:oid:0xb0000000005f7": { | ||
"SAI_ACL_TABLE_GROUP_ATTR_ACL_BIND_POINT_TYPE_LIST": "1:SAI_ACL_BIND_POINT_TYPE_PORT", | ||
"SAI_ACL_TABLE_GROUP_ATTR_ACL_STAGE": "SAI_ACL_STAGE_INGRESS", | ||
"SAI_ACL_TABLE_GROUP_ATTR_TYPE": "SAI_ACL_TABLE_GROUP_TYPE_PARALLEL" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8000000000609": { | ||
"SAI_ACL_ENTRY_ATTR_ACTION_COUNTER": "oid:0x9000000000606", | ||
"SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION": "SAI_PACKET_ACTION_FORWARD", | ||
"SAI_ACL_ENTRY_ATTR_ADMIN_STATE": "true", | ||
"SAI_ACL_ENTRY_ATTR_PRIORITY": "9995", | ||
"SAI_ACL_ENTRY_ATTR_TABLE_ID": "oid:0x7000000000600" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x9000000000606": { | ||
"SAI_ACL_COUNTER_ATTR_TABLE_ID": "oid:0x7000000000600", | ||
"SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT": "true", | ||
"SAI_ACL_COUNTER_ATTR_ENABLE_BYTES_COUNT": "true" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE:oid:0x7100000000600": { | ||
"SAI_ACL_TABLE_ATTR_ACL_BIND_POINT_TYPE_LIST": "2:SAI_ACL_BIND_POINT_TYPE_PORT,SAI_ACL_BIND_POINT_TYPE_LAG", | ||
"SAI_ACL_TABLE_ATTR_ACL_STAGE": "SAI_ACL_STAGE_INGRESS", | ||
"SAI_ACL_TABLE_ATTR_FIELD_ACL_ETHER_TYPE": "true" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc100000000601": { | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID": "oid:0xb0000000005f5", | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID": "oid:0x7100000000600", | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY": "100" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP_MEMBER:oid:0xc100000000602": { | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_GROUP_ID": "oid:0xb0000000005f7", | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_ACL_TABLE_ID": "oid:0x7100000000600", | ||
"SAI_ACL_TABLE_GROUP_MEMBER_ATTR_PRIORITY": "100" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_ENTRY:oid:0x8100000000609": { | ||
"SAI_ACL_ENTRY_ATTR_ACTION_COUNTER": "oid:0x9100000000606", | ||
"SAI_ACL_ENTRY_ATTR_ACTION_PACKET_ACTION": "SAI_PACKET_ACTION_FORWARD", | ||
"SAI_ACL_ENTRY_ATTR_ADMIN_STATE": "true", | ||
"SAI_ACL_ENTRY_ATTR_PRIORITY": "9995", | ||
"SAI_ACL_ENTRY_ATTR_TABLE_ID": "oid:0x7100000000600", | ||
"SAI_ACL_ENTRY_ATTR_FIELD_ACL_RANGE_TYPE": "2:oid:0xa100000000607,oid:0xa100000000608" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_COUNTER:oid:0x9100000000606": { | ||
"SAI_ACL_COUNTER_ATTR_TABLE_ID": "oid:0x7100000000600", | ||
"SAI_ACL_COUNTER_ATTR_ENABLE_PACKET_COUNT": "true", | ||
"SAI_ACL_COUNTER_ATTR_ENABLE_BYTES_COUNT": "true" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_RANGE:oid:0xa100000000607": { | ||
"SAI_ACL_RANGE_ATTR_LIMIT": "90,95", | ||
"SAI_ACL_RANGE_ATTR_TYPE": "SAI_ACL_RANGE_TYPE_L4_DST_PORT_RANGE" | ||
}, | ||
"ASIC_STATE:SAI_OBJECT_TYPE_ACL_RANGE:oid:0xa100000000608": { | ||
"SAI_ACL_RANGE_ATTR_LIMIT": "90,95", | ||
"SAI_ACL_RANGE_ATTR_TYPE": "SAI_ACL_RANGE_TYPE_L4_DST_PORT_RANGE" | ||
} | ||
} |
Oops, something went wrong.
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.
Argument can be removed
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.
Thanks, fixed