Skip to content

Commit

Permalink
[show]: Add show policer command (#540)
Browse files Browse the repository at this point in the history
root@sonic:# show policer
Name    Type     Mode      CIR    CBS
------  -------  ------  -----  -----
test    packets  sr_tcm    100    100

Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng authored Jun 3, 2019
1 parent 82ef3ec commit dcdc922
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
55 changes: 47 additions & 8 deletions acl_loader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class AclLoader(object):
ACL_TABLE_TYPE_MIRROR = "MIRROR"
ACL_TABLE_TYPE_CTRLPLANE = "CTRLPLANE"
MIRROR_SESSION = "MIRROR_SESSION"
POLICER = "POLICER"
SESSION_PREFIX = "everflow"

min_priority = 1
Expand Down Expand Up @@ -92,10 +93,11 @@ def __init__(self):
self.read_tables_info()
self.read_rules_info()
self.read_sessions_info()
self.read_policers_info()

def read_tables_info(self):
"""
Read ACL tables information from Config DB
Read ACL_TABLE table from configuration database
:return:
"""
self.tables_db_info = self.configdb.get_table(self.ACL_TABLE)
Expand All @@ -105,17 +107,27 @@ def get_tables_db_info(self):

def read_rules_info(self):
"""
Read rules information from Config DB
Read ACL_RULE table from configuration database
:return:
"""
self.rules_db_info = self.configdb.get_table(self.ACL_RULE)

def get_rules_db_info(self):
return self.rules_db_info

def read_policers_info(self):
"""
Read POLICER table from configuration database
:return:
"""
self.policers_db_info = self.configdb.get_table(self.POLICER)

def get_policers_db_info(self):
return self.policers_db_info

def read_sessions_info(self):
"""
Read ACL tables information from Config DB
Read MIRROR_SESSION table from configuration database
:return:
"""
self.sessions_db_info = self.configdb.get_table(self.MIRROR_SESSION)
Expand All @@ -128,15 +140,11 @@ def read_sessions_info(self):
self.sessions_db_info[key]["status"] = status

def get_sessions_db_info(self):
"""
Read mirror session information from Config DB
:return:
"""
return self.sessions_db_info

def get_session_name(self):
"""
Read mirror session name from Config DB
Get requested mirror session name or default session
:return: Mirror session name
"""
if self.requested_session:
Expand Down Expand Up @@ -545,6 +553,25 @@ def show_session(self, session_name):

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


def show_policer(self, policer_name):
"""
Show policer configuration.
:param policer_name: Optional. Policer name. Filter policers by specified name.
:return:
"""
header = ("Name", "Type", "Mode", "CIR", "CBS")

data = []
for key, val in self.get_policers_db_info().iteritems():
if policer_name and key != policer_name:
continue

data.append([key, val["meter_type"], val["mode"], val.get("cir", ""), val.get("cbs", "")])

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


def show_rule(self, table_name, rule_id):
"""
Show ACL rules configuration.
Expand Down Expand Up @@ -648,6 +675,18 @@ def session(ctx, session_name):
acl_loader.show_session(session_name)


@show.command()
@click.argument('policer_name', type=click.STRING, required=False)
@click.pass_context
def policer(ctx, policer_name):
"""
Show policer configuration.
:return:
"""
acl_loader = ctx.obj["acl_loader"]
acl_loader.show_policer(policer_name)


@show.command()
@click.argument('table_name', type=click.STRING, required=False)
@click.argument('rule_id', type=click.STRING, required=False)
Expand Down
16 changes: 16 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,22 @@ def mirror_session(session_name, verbose):
run_command(cmd, display_cmd=verbose)


#
# 'policer' command ("show policer ...")
#
@cli.command()
@click.argument('policer_name', required=False)
@click.option('--verbose', is_flag=True, help="Enable verbose output")
def policer(policer_name, verbose):
"""Show existing policers"""
cmd = "acl-loader show policer"

if policer_name is not None:
cmd += " {}".format(policer_name)

run_command(cmd, display_cmd=verbose)


#
# 'acl' group ###
#
Expand Down

0 comments on commit dcdc922

Please sign in to comment.