Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 42 additions & 2 deletions crm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def show_thresholds(self, resource):
for res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor",
"nexthop_group_member", "nexthop_group", "acl_table", "acl_group", "acl_entry",
"acl_counter", "fdb_entry", "ipmc_entry", "snat_entry", "dnat_entry", "mpls_inseg",
"mpls_nexthop"]:
"mpls_nexthop","srv6_nexthop", "srv6_my_sid_entry"]:
try:
data.append([res, crm_info[res + "_threshold_type"], crm_info[res + "_low_threshold"], crm_info[res + "_high_threshold"]])
except KeyError:
Expand Down Expand Up @@ -100,7 +100,7 @@ def get_resources(self, resource):
if resource == 'all':
for res in ["ipv4_route", "ipv6_route", "ipv4_nexthop", "ipv6_nexthop", "ipv4_neighbor", "ipv6_neighbor",
"nexthop_group_member", "nexthop_group", "fdb_entry", "ipmc_entry", "snat_entry", "dnat_entry",
"mpls_inseg", "mpls_nexthop"]:
"mpls_inseg", "mpls_nexthop","srv6_nexthop", "srv6_my_sid_entry"]:
if 'crm_stats_' + res + "_used" in crm_stats.keys() and 'crm_stats_' + res + "_available" in crm_stats.keys():
data.append([res, crm_stats['crm_stats_' + res + "_used"], crm_stats['crm_stats_' + res + "_available"]])
else:
Expand Down Expand Up @@ -460,6 +460,26 @@ def counter(ctx):
counter.add_command(low)
counter.add_command(high)

@thresholds.group()
@click.pass_context
def srv6_nexthop(ctx):
"""CRM configuration for SRV6 Nexthop resource"""
ctx.obj["crm"].res_type = 'srv6_nexthop'

srv6_nexthop.add_command(type)
srv6_nexthop.add_command(low)
srv6_nexthop.add_command(high)

@thresholds.group()
@click.pass_context
def srv6_my_sid_entry(ctx):
"""CRM configuration for SRV6 MY_SID resource"""
ctx.obj["crm"].res_type = 'srv6_my_sid_entry'

srv6_my_sid_entry.add_command(type)
srv6_my_sid_entry.add_command(low)
srv6_my_sid_entry.add_command(high)

@cli.group()
@click.pass_context
def show(ctx):
Expand Down Expand Up @@ -644,6 +664,24 @@ def dnat(ctx):
elif ctx.obj["crm"].cli_mode == 'resources':
ctx.obj["crm"].show_resources('dnat_entry')

@resources.command()
@click.pass_context
def srv6_nexthop(ctx):
"""Show CRM information for SRV6 Nexthop"""
if ctx.obj["crm"].cli_mode == 'thresholds':
ctx.obj["crm"].show_thresholds('srv6_nexthop')
elif ctx.obj["crm"].cli_mode == 'resources':
ctx.obj["crm"].show_resources('srv6_nexthop')

@resources.command()
@click.pass_context
def srv6_my_sid_entry(ctx):
"""Show CRM information for SRV6 MY_SID entry"""
if ctx.obj["crm"].cli_mode == 'thresholds':
ctx.obj["crm"].show_thresholds('srv6_my_sid_entry')
elif ctx.obj["crm"].cli_mode == 'resources':
ctx.obj["crm"].show_resources('srv6_my_sid_entry')

thresholds.add_command(acl)
thresholds.add_command(all)
thresholds.add_command(fdb)
Expand All @@ -654,6 +692,8 @@ def dnat(ctx):
thresholds.add_command(ipmc)
thresholds.add_command(snat)
thresholds.add_command(dnat)
thresholds.add_command(srv6_nexthop)
thresholds.add_command(srv6_my_sid_entry)


if __name__ == '__main__':
Expand Down
156 changes: 156 additions & 0 deletions tests/crm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
dnat_entry percentage 70 85
mpls_inseg percentage 70 85
mpls_nexthop percentage 70 85
srv6_nexthop percentage 70 85
srv6_my_sid_entry percentage 70 85

"""

Expand Down Expand Up @@ -168,6 +170,22 @@

"""

crm_show_thresholds_srv6_my_sid_entry = """\

Resource Name Threshold Type Low Threshold High Threshold
----------------- ---------------- --------------- ----------------
srv6_my_sid_entry percentage 70 85

"""

crm_show_thresholds_srv6_nexthop = """\

Resource Name Threshold Type Low Threshold High Threshold
--------------- ---------------- --------------- ----------------
srv6_nexthop percentage 70 85

"""

crm_new_show_summary = """\

Polling Interval: 30 second(s)
Expand Down Expand Up @@ -302,6 +320,30 @@

"""

crm_new_show_thresholds_srv6_my_sid_entry = """\

Resource Name Threshold Type Low Threshold High Threshold
----------------- ---------------- --------------- ----------------
srv6_my_sid_entry percentage 60 90

"""

crm_new_show_thresholds_srv6_nexthop = """\

Resource Name Threshold Type Low Threshold High Threshold
--------------- ---------------- --------------- ----------------
srv6_nexthop percentage 60 90

"""

crm_new_show_thresholds_ipmc = """\

Resource Name Threshold Type Low Threshold High Threshold
--------------- ---------------- --------------- ----------------
ipmc_entry percentage 60 90

"""

crm_show_resources_acl_group = """\

Stage Bind Point Resource Name Used Count Available Count
Expand Down Expand Up @@ -358,6 +400,8 @@
dnat_entry 0 1024
mpls_inseg 0 1024
mpls_nexthop 0 1024
srv6_nexthop 0 1024
srv6_my_sid_entry 0 1024


Stage Bind Point Resource Name Used Count Available Count
Expand Down Expand Up @@ -505,6 +549,21 @@

"""

crm_show_resources_srv6_my_sid_entry = """\

Resource Name Used Count Available Count
----------------- ------------ -----------------
srv6_my_sid_entry 0 1024

"""

crm_show_resources_srv6_nexthop = """\

Resource Name Used Count Available Count
--------------- ------------ -----------------
srv6_nexthop 0 1024

"""
crm_multi_asic_show_resources_acl_group = """\

ASIC0
Expand Down Expand Up @@ -603,6 +662,8 @@
dnat_entry 0 1024
mpls_inseg 0 1024
mpls_nexthop 0 1024
srv6_nexthop 0 1024
srv6_my_sid_entry 0 1024


ASIC1
Expand All @@ -623,6 +684,8 @@
dnat_entry 0 1024
mpls_inseg 0 1024
mpls_nexthop 0 1024
srv6_nexthop 0 1024
srv6_my_sid_entry 0 1024


ASIC0
Expand Down Expand Up @@ -936,6 +999,39 @@

"""

crm_multi_asic_show_resources_srv6_my_sid_entry = """\

ASIC0

Resource Name Used Count Available Count
----------------- ------------ -----------------
srv6_my_sid_entry 0 1024


ASIC1

Resource Name Used Count Available Count
----------------- ------------ -----------------
srv6_my_sid_entry 0 1024

"""

crm_multi_asic_show_resources_srv6_nexthop = """\

ASIC0

Resource Name Used Count Available Count
--------------- ------------ -----------------
srv6_nexthop 0 1024


ASIC1

Resource Name Used Count Available Count
--------------- ------------ -----------------
srv6_nexthop 0 1024

"""

class TestCrm(object):
@classmethod
Expand Down Expand Up @@ -1339,6 +1435,20 @@ def test_crm_show_resources_ipmc(self):
assert result.exit_code == 0
assert result.output == crm_show_resources_ipmc

def test_crm_show_resources_srv6_my_sid_entry(self):
runner = CliRunner()
result = runner.invoke(crm.cli, ['show', 'resources', 'srv6-my-sid-entry'])
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_show_resources_srv6_my_sid_entry

def test_crm_show_resources_srv6_nexthop(self):
runner = CliRunner()
result = runner.invoke(crm.cli, ['show', 'resources', 'srv6-nexthop'])
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_show_resources_srv6_nexthop

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down Expand Up @@ -1633,6 +1743,38 @@ def test_crm_show_thresholds_ipmc(self):
assert result.output == crm_new_show_thresholds_ipmc


def test_crm_show_thresholds_srv6_nexthop(self):
runner = CliRunner()
db = Db()
result = runner.invoke(crm.cli, ['show', 'thresholds', 'srv6-nexthop'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_show_thresholds_srv6_nexthop
result = runner.invoke(crm.cli, ['config', 'thresholds', 'srv6-nexthop', 'high', '90'], obj=db)
print(sys.stderr, result.output)
result = runner.invoke(crm.cli, ['config', 'thresholds', 'srv6-nexthop', 'low', '60'], obj=db)
print(sys.stderr, result.output)
result = runner.invoke(crm.cli, ['show', 'thresholds', 'srv6-nexthop'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_new_show_thresholds_srv6_nexthop

def test_crm_show_thresholds_srv6_my_sid_entry(self):
runner = CliRunner()
db = Db()
result = runner.invoke(crm.cli, ['show', 'thresholds', 'srv6-my-sid-entry'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_show_thresholds_srv6_my_sid_entry
result = runner.invoke(crm.cli, ['config', 'thresholds', 'srv6-my-sid-entry', 'high', '90'], obj=db)
print(sys.stderr, result.output)
result = runner.invoke(crm.cli, ['config', 'thresholds', 'srv6-my-sid-entry', 'low', '60'], obj=db)
print(sys.stderr, result.output)
result = runner.invoke(crm.cli, ['show', 'thresholds', 'srv6-my-sid-entry'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_new_show_thresholds_srv6_my_sid_entry

def test_crm_multi_asic_show_resources_acl_group(self):
runner = CliRunner()
result = runner.invoke(crm.cli, ['show', 'resources', 'acl', 'group'])
Expand Down Expand Up @@ -1752,6 +1894,20 @@ def test_crm_multi_asic_show_resources_ipmc(self):
assert result.exit_code == 0
assert result.output == crm_multi_asic_show_resources_ipmc

def test_crm_multi_asic_show_resources_srv6_my_sid_entry(self):
runner = CliRunner()
result = runner.invoke(crm.cli, ['show', 'resources', 'srv6-my-sid-entry'])
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_multi_asic_show_resources_srv6_my_sid_entry

def test_crm_multi_asic_show_resources_srv6_nexthop(self):
runner = CliRunner()
result = runner.invoke(crm.cli, ['show', 'resources', 'srv6-nexthop'])
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_multi_asic_show_resources_srv6_nexthop


@classmethod
def teardown_class(cls):
Expand Down
8 changes: 7 additions & 1 deletion tests/mock_tables/asic0/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,13 @@
"mpls_inseg_low_threshold": "70",
"mpls_nexthop_threshold_type": "percentage",
"mpls_nexthop_high_threshold": "85",
"mpls_nexthop_low_threshold": "70"
"mpls_nexthop_low_threshold": "70",
"srv6_my_sid_entry_threshold_type": "percentage",
"srv6_my_sid_entry_high_threshold": "85",
"srv6_my_sid_entry_low_threshold": "70",
"srv6_nexthop_threshold_type": "percentage",
"srv6_nexthop_high_threshold": "85",
"srv6_nexthop_low_threshold": "70"
},
"MUX_CABLE|Ethernet32": {
"state": "auto",
Expand Down
6 changes: 5 additions & 1 deletion tests/mock_tables/asic0/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,11 @@
"crm_stats_mpls_inseg_used":"0",
"crm_stats_mpls_inseg_available":"1024",
"crm_stats_mpls_nexthop_used":"0",
"crm_stats_mpls_nexthop_available":"1024"
"crm_stats_mpls_nexthop_available":"1024",
"crm_stats_srv6_my_sid_entry_used":"0",
"crm_stats_srv6_my_sid_entry_available":"1024",
"crm_stats_srv6_nexthop_used":"0",
"crm_stats_srv6_nexthop_available":"1024"
},
"CRM:ACL_STATS:EGRESS:PORT":{
"crm_stats_acl_table_used":"0",
Expand Down
8 changes: 7 additions & 1 deletion tests/mock_tables/asic1/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@
"mpls_inseg_low_threshold": "70",
"mpls_nexthop_threshold_type": "percentage",
"mpls_nexthop_high_threshold": "85",
"mpls_nexthop_low_threshold": "70"
"mpls_nexthop_low_threshold": "70",
"srv6_my_sid_entry_threshold_type": "percentage",
"srv6_my_sid_entry_high_threshold": "85",
"srv6_my_sid_entry_low_threshold": "70",
"srv6_nexthop_threshold_type": "percentage",
"srv6_nexthop_high_threshold": "85",
"srv6_nexthop_low_threshold": "70"
},
"MUX_CABLE|Ethernet32": {
"state": "auto",
Expand Down
6 changes: 5 additions & 1 deletion tests/mock_tables/asic1/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,11 @@
"crm_stats_mpls_inseg_used":"0",
"crm_stats_mpls_inseg_available":"1024",
"crm_stats_mpls_nexthop_used":"0",
"crm_stats_mpls_nexthop_available":"1024"
"crm_stats_mpls_nexthop_available":"1024",
"crm_stats_srv6_my_sid_entry_used":"0",
"crm_stats_srv6_my_sid_entry_available":"1024",
"crm_stats_srv6_nexthop_used":"0",
"crm_stats_srv6_nexthop_available":"1024"
},
"CRM:ACL_STATS:EGRESS:PORT":{
"crm_stats_acl_table_used":"0",
Expand Down
8 changes: 7 additions & 1 deletion tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,13 @@
"mpls_inseg_low_threshold": "70",
"mpls_nexthop_threshold_type": "percentage",
"mpls_nexthop_high_threshold": "85",
"mpls_nexthop_low_threshold": "70"
"mpls_nexthop_low_threshold": "70",
"srv6_my_sid_entry_threshold_type": "percentage",
"srv6_my_sid_entry_high_threshold": "85",
"srv6_my_sid_entry_low_threshold": "70",
"srv6_nexthop_threshold_type": "percentage",
"srv6_nexthop_high_threshold": "85",
"srv6_nexthop_low_threshold": "70"
},
"CHASSIS_MODULE|LINE-CARD1": {
"admin_status": "down"
Expand Down
6 changes: 5 additions & 1 deletion tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,11 @@
"crm_stats_mpls_inseg_used":"0",
"crm_stats_mpls_inseg_available":"1024",
"crm_stats_mpls_nexthop_used":"0",
"crm_stats_mpls_nexthop_available":"1024"
"crm_stats_mpls_nexthop_available":"1024",
"crm_stats_srv6_my_sid_entry_used":"0",
"crm_stats_srv6_my_sid_entry_available":"1024",
"crm_stats_srv6_nexthop_used":"0",
"crm_stats_srv6_nexthop_available":"1024"
},
"CRM:ACL_STATS:EGRESS:PORT":{
"crm_stats_acl_table_used":"0",
Expand Down