Skip to content

Commit dcdc922

Browse files
author
Shuotian Cheng
authored
[show]: Add show policer command (#540)
root@sonic:# show policer Name Type Mode CIR CBS ------ ------- ------ ----- ----- test packets sr_tcm 100 100 Signed-off-by: Shu0T1an ChenG <[email protected]>
1 parent 82ef3ec commit dcdc922

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

acl_loader/main.py

+47-8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class AclLoader(object):
4949
ACL_TABLE_TYPE_MIRROR = "MIRROR"
5050
ACL_TABLE_TYPE_CTRLPLANE = "CTRLPLANE"
5151
MIRROR_SESSION = "MIRROR_SESSION"
52+
POLICER = "POLICER"
5253
SESSION_PREFIX = "everflow"
5354

5455
min_priority = 1
@@ -92,10 +93,11 @@ def __init__(self):
9293
self.read_tables_info()
9394
self.read_rules_info()
9495
self.read_sessions_info()
96+
self.read_policers_info()
9597

9698
def read_tables_info(self):
9799
"""
98-
Read ACL tables information from Config DB
100+
Read ACL_TABLE table from configuration database
99101
:return:
100102
"""
101103
self.tables_db_info = self.configdb.get_table(self.ACL_TABLE)
@@ -105,17 +107,27 @@ def get_tables_db_info(self):
105107

106108
def read_rules_info(self):
107109
"""
108-
Read rules information from Config DB
110+
Read ACL_RULE table from configuration database
109111
:return:
110112
"""
111113
self.rules_db_info = self.configdb.get_table(self.ACL_RULE)
112114

113115
def get_rules_db_info(self):
114116
return self.rules_db_info
115117

118+
def read_policers_info(self):
119+
"""
120+
Read POLICER table from configuration database
121+
:return:
122+
"""
123+
self.policers_db_info = self.configdb.get_table(self.POLICER)
124+
125+
def get_policers_db_info(self):
126+
return self.policers_db_info
127+
116128
def read_sessions_info(self):
117129
"""
118-
Read ACL tables information from Config DB
130+
Read MIRROR_SESSION table from configuration database
119131
:return:
120132
"""
121133
self.sessions_db_info = self.configdb.get_table(self.MIRROR_SESSION)
@@ -128,15 +140,11 @@ def read_sessions_info(self):
128140
self.sessions_db_info[key]["status"] = status
129141

130142
def get_sessions_db_info(self):
131-
"""
132-
Read mirror session information from Config DB
133-
:return:
134-
"""
135143
return self.sessions_db_info
136144

137145
def get_session_name(self):
138146
"""
139-
Read mirror session name from Config DB
147+
Get requested mirror session name or default session
140148
:return: Mirror session name
141149
"""
142150
if self.requested_session:
@@ -545,6 +553,25 @@ def show_session(self, session_name):
545553

546554
print(tabulate.tabulate(data, headers=header, tablefmt="simple", missingval=""))
547555

556+
557+
def show_policer(self, policer_name):
558+
"""
559+
Show policer configuration.
560+
:param policer_name: Optional. Policer name. Filter policers by specified name.
561+
:return:
562+
"""
563+
header = ("Name", "Type", "Mode", "CIR", "CBS")
564+
565+
data = []
566+
for key, val in self.get_policers_db_info().iteritems():
567+
if policer_name and key != policer_name:
568+
continue
569+
570+
data.append([key, val["meter_type"], val["mode"], val.get("cir", ""), val.get("cbs", "")])
571+
572+
print(tabulate.tabulate(data, headers=header, tablefmt="simple", missingval=""))
573+
574+
548575
def show_rule(self, table_name, rule_id):
549576
"""
550577
Show ACL rules configuration.
@@ -648,6 +675,18 @@ def session(ctx, session_name):
648675
acl_loader.show_session(session_name)
649676

650677

678+
@show.command()
679+
@click.argument('policer_name', type=click.STRING, required=False)
680+
@click.pass_context
681+
def policer(ctx, policer_name):
682+
"""
683+
Show policer configuration.
684+
:return:
685+
"""
686+
acl_loader = ctx.obj["acl_loader"]
687+
acl_loader.show_policer(policer_name)
688+
689+
651690
@show.command()
652691
@click.argument('table_name', type=click.STRING, required=False)
653692
@click.argument('rule_id', type=click.STRING, required=False)

show/main.py

+16
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,22 @@ def mirror_session(session_name, verbose):
16401640
run_command(cmd, display_cmd=verbose)
16411641

16421642

1643+
#
1644+
# 'policer' command ("show policer ...")
1645+
#
1646+
@cli.command()
1647+
@click.argument('policer_name', required=False)
1648+
@click.option('--verbose', is_flag=True, help="Enable verbose output")
1649+
def policer(policer_name, verbose):
1650+
"""Show existing policers"""
1651+
cmd = "acl-loader show policer"
1652+
1653+
if policer_name is not None:
1654+
cmd += " {}".format(policer_name)
1655+
1656+
run_command(cmd, display_cmd=verbose)
1657+
1658+
16431659
#
16441660
# 'acl' group ###
16451661
#

0 commit comments

Comments
 (0)