Skip to content

[acl_loader] show acl rule counter in command "show acl rule" #566

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,13 @@ def show_rule(self, table_name, rule_id):
:param rule_id: Optional. ACL rule name. Filter rule by specified rule name.
:return:
"""
header = ("Table", "Rule", "Priority", "Action", "Match")
header = ("Table", "Rule", "Priority", "Action", "Match", "Packets", "Bytes")

ignore_list = ["PRIORITY", "PACKET_ACTION", "MIRROR_ACTION"]

counter_db = SonicV2Connector(host="127.0.0.1")
counter_db.connect(counter_db.COUNTERS_DB)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you move these two lines to below? right above the part you add the counter querying logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean move those two lines above the "counter_db.get_all", right? If yes, then it will re-create a socket with Redis DB for each ACL rule. IMO, it is not a good way, as we can use just one socket to get the counters for all ACL rules, no need to create connection with Redis DB again and again.

raw_data = []
for (tname, rid), val in self.get_rules_db_info().iteritems():

Expand All @@ -609,7 +612,15 @@ def show_rule(self, table_name, rule_id):
if len(matches) == 0:
matches.append("N/A")

rule_data = [[tname, rid, priority, action, matches[0]]]
count_packets = "N/A"
count_bytes = "N/A"
counters = counter_db.get_all(counter_db.COUNTERS_DB, "COUNTERS:{}:{}".format(tname, rid))
if isinstance(counters, dict):
if 'Packets' in counters:
count_packets = counters['Packets']
if 'Bytes' in counters:
count_bytes = counters['Bytes']
rule_data = [[tname, rid, priority, action, matches[0], count_packets, count_bytes]]
if len(matches) > 1:
for m in matches[1:]:
rule_data.append(["", "", "", "", m])
Expand Down