Skip to content
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

[crm] add DRAM resource to crm utility #3593

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 25 additions & 2 deletions crm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class Crm:
"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","srv6_nexthop", "srv6_my_sid_entry"
"mpls_nexthop", "srv6_nexthop", "srv6_my_sid_entry", "dram"
)

resources = (
"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","srv6_nexthop", "srv6_my_sid_entry"
"mpls_inseg", "mpls_nexthop", "srv6_nexthop", "srv6_my_sid_entry", "dram"
)

acl_resources = (
Expand Down Expand Up @@ -592,6 +592,18 @@ def srv6_my_sid_entry(ctx):
srv6_my_sid_entry.add_command(low)
srv6_my_sid_entry.add_command(high)


@thresholds.group()
@click.pass_context
def dram(ctx):
"""CRM configuration for DRAM"""
ctx.obj["crm"].res_type = 'dram'


dram.add_command(type)
dram.add_command(low)
dram.add_command(high)

if device_info.get_platform_info().get('switch_type') == "dpu":
thresholds.add_command(config_dash)

Expand Down Expand Up @@ -795,6 +807,16 @@ def srv6_my_sid_entry(ctx):
elif ctx.obj["crm"].cli_mode == 'resources':
ctx.obj["crm"].show_resources('srv6_my_sid_entry')


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

thresholds.add_command(acl)
thresholds.add_command(all)
thresholds.add_command(fdb)
Expand All @@ -807,6 +829,7 @@ def srv6_my_sid_entry(ctx):
thresholds.add_command(dnat)
thresholds.add_command(srv6_nexthop)
thresholds.add_command(srv6_my_sid_entry)
thresholds.add_command(dram)

if device_info.get_platform_info().get('switch_type') == "dpu":
resources.add_command(show_dash)
Expand Down
92 changes: 92 additions & 0 deletions tests/crm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
mpls_nexthop percentage 70 85
srv6_nexthop percentage 70 85
srv6_my_sid_entry percentage 70 85
dram percentage 70 85

"""

Expand Down Expand Up @@ -186,6 +187,14 @@

"""

crm_show_thresholds_dram = """\

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

"""

crm_new_show_summary = """\

Polling Interval: 30 second(s)
Expand Down Expand Up @@ -344,6 +353,14 @@

"""

crm_new_show_thresholds_dram = """\

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

"""

crm_show_resources_acl_group = """\

Stage Bind Point Resource Name Used Count Available Count
Expand Down Expand Up @@ -402,6 +419,7 @@
mpls_nexthop 0 1024
srv6_nexthop 0 1024
srv6_my_sid_entry 0 1024
dram 1000 4000


Stage Bind Point Resource Name Used Count Available Count
Expand Down Expand Up @@ -564,6 +582,15 @@
srv6_nexthop 0 1024

"""

crm_show_resources_dram = """\

Resource Name Used Count Available Count
--------------- ------------ -----------------
dram 1000 4000

"""

crm_multi_asic_show_resources_acl_group = """\

ASIC0
Expand Down Expand Up @@ -664,6 +691,7 @@
mpls_nexthop 0 1024
srv6_nexthop 0 1024
srv6_my_sid_entry 0 1024
dram 1000 4000


ASIC1
Expand All @@ -686,6 +714,7 @@
mpls_nexthop 0 1024
srv6_nexthop 0 1024
srv6_my_sid_entry 0 1024
dram 1000 4000


ASIC0
Expand Down Expand Up @@ -1033,6 +1062,23 @@

"""

crm_multi_asic_show_resources_dram = """\

ASIC0

Resource Name Used Count Available Count
--------------- ------------ -----------------
dram 1000 4000


ASIC1

Resource Name Used Count Available Count
--------------- ------------ -----------------
dram 1000 4000

"""

crm_config_interval_too_big = "Error: Invalid value for \"INTERVAL\": 30000 is not in the valid range of 1 to 9999."

class TestCrm(object):
Expand Down Expand Up @@ -1330,6 +1376,22 @@ def test_crm_show_thresholds_ipmc(self):
assert result.exit_code == 0
assert result.output == crm_new_show_thresholds_ipmc

def test_crm_show_thresholds_dram(self):
runner = CliRunner()
db = Db()
result = runner.invoke(crm.cli, ['show', 'thresholds', 'dram'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_show_thresholds_dram
result = runner.invoke(crm.cli, ['config', 'thresholds', 'dram', 'high', '90'], obj=db)
print(sys.stderr, result.output)
result = runner.invoke(crm.cli, ['config', 'thresholds', 'dram', 'low', '60'], obj=db)
print(sys.stderr, result.output)
result = runner.invoke(crm.cli, ['show', 'thresholds', 'dram'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_new_show_thresholds_dram

def test_crm_show_resources_acl_group(self):
runner = CliRunner()
result = runner.invoke(crm.cli, ['show', 'resources', 'acl', 'group'])
Expand Down Expand Up @@ -1463,6 +1525,13 @@ def test_crm_show_resources_srv6_nexthop(self):
assert result.exit_code == 0
assert result.output == crm_show_resources_srv6_nexthop

def test_crm_show_resources_dram(self):
runner = CliRunner()
result = runner.invoke(crm.cli, ['show', 'resources', 'dram'])
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_show_resources_dram

@classmethod
def teardown_class(cls):
print("TEARDOWN")
Expand Down Expand Up @@ -1789,6 +1858,22 @@ def test_crm_show_thresholds_srv6_my_sid_entry(self):
assert result.exit_code == 0
assert result.output == crm_new_show_thresholds_srv6_my_sid_entry

def test_crm_show_thresholds_dram(self):
runner = CliRunner()
db = Db()
result = runner.invoke(crm.cli, ['show', 'thresholds', 'dram'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_show_thresholds_dram
result = runner.invoke(crm.cli, ['config', 'thresholds', 'dram', 'high', '90'], obj=db)
print(sys.stderr, result.output)
result = runner.invoke(crm.cli, ['config', 'thresholds', 'dram', 'low', '60'], obj=db)
print(sys.stderr, result.output)
result = runner.invoke(crm.cli, ['show', 'thresholds', 'dram'], obj=db)
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_new_show_thresholds_dram

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 @@ -1922,6 +2007,13 @@ def test_crm_multi_asic_show_resources_srv6_nexthop(self):
assert result.exit_code == 0
assert result.output == crm_multi_asic_show_resources_srv6_nexthop

def test_crm_multi_asic_show_resources_dram(self):
runner = CliRunner()
result = runner.invoke(crm.cli, ['show', 'resources', 'dram'])
print(sys.stderr, result.output)
assert result.exit_code == 0
assert result.output == crm_multi_asic_show_resources_dram


@classmethod
def teardown_class(cls):
Expand Down
5 changes: 4 additions & 1 deletion tests/mock_tables/asic0/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@
"srv6_my_sid_entry_low_threshold": "70",
"srv6_nexthop_threshold_type": "percentage",
"srv6_nexthop_high_threshold": "85",
"srv6_nexthop_low_threshold": "70"
"srv6_nexthop_low_threshold": "70",
"dram_threshold_type": "percentage",
"dram_high_threshold": "85",
"dram_low_threshold": "70"
},
"MUX_CABLE|Ethernet32": {
"state": "auto",
Expand Down
4 changes: 3 additions & 1 deletion tests/mock_tables/asic0/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -2396,7 +2396,9 @@
"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_stats_srv6_nexthop_available":"1024",
"crm_stats_dram_used":"1000",
"crm_stats_dram_available":"4000"
},
"CRM:ACL_STATS:EGRESS:PORT":{
"crm_stats_acl_table_used":"0",
Expand Down
5 changes: 4 additions & 1 deletion tests/mock_tables/asic1/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@
"srv6_my_sid_entry_low_threshold": "70",
"srv6_nexthop_threshold_type": "percentage",
"srv6_nexthop_high_threshold": "85",
"srv6_nexthop_low_threshold": "70"
"srv6_nexthop_low_threshold": "70",
"dram_threshold_type": "percentage",
"dram_high_threshold": "85",
"dram_low_threshold": "70"
},
"MUX_CABLE|Ethernet32": {
"state": "auto",
Expand Down
4 changes: 3 additions & 1 deletion tests/mock_tables/asic1/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,9 @@
"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_stats_srv6_nexthop_available":"1024",
"crm_stats_dram_used":"1000",
"crm_stats_dram_available":"4000"
},
"CRM:ACL_STATS:EGRESS:PORT":{
"crm_stats_acl_table_used":"0",
Expand Down
5 changes: 4 additions & 1 deletion tests/mock_tables/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,10 @@
"srv6_my_sid_entry_low_threshold": "70",
"srv6_nexthop_threshold_type": "percentage",
"srv6_nexthop_high_threshold": "85",
"srv6_nexthop_low_threshold": "70"
"srv6_nexthop_low_threshold": "70",
"dram_threshold_type": "percentage",
"dram_high_threshold": "85",
"dram_low_threshold": "70"
},
"CHASSIS_MODULE|LINE-CARD1": {
"admin_status": "down"
Expand Down
4 changes: 3 additions & 1 deletion tests/mock_tables/counters_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -2405,7 +2405,9 @@
"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_stats_srv6_nexthop_available":"1024",
"crm_stats_dram_used":"1000",
"crm_stats_dram_available":"4000"
},
"CRM:ACL_STATS:EGRESS:PORT":{
"crm_stats_acl_table_used":"0",
Expand Down
Loading