From 5f32c84933c9d7f68eacca7b8b0a36b1fbffe4df Mon Sep 17 00:00:00 2001 From: Yakiv Huryk Date: Mon, 24 Jun 2024 18:59:20 +0300 Subject: [PATCH] [CRM] add DRAM resource to crm utility Signed-off-by: Yakiv Huryk --- crm/main.py | 27 ++++++- tests/crm_test.py | 92 ++++++++++++++++++++++++ tests/mock_tables/asic0/config_db.json | 5 +- tests/mock_tables/asic0/counters_db.json | 4 +- tests/mock_tables/asic1/config_db.json | 5 +- tests/mock_tables/asic1/counters_db.json | 4 +- tests/mock_tables/config_db.json | 5 +- tests/mock_tables/counters_db.json | 4 +- 8 files changed, 138 insertions(+), 8 deletions(-) diff --git a/crm/main.py b/crm/main.py index 998ff23fc4..581decf867 100644 --- a/crm/main.py +++ b/crm/main.py @@ -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 = ( @@ -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) @@ -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) @@ -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) diff --git a/tests/crm_test.py b/tests/crm_test.py index 6b3f32ed9d..ce8f8dab25 100644 --- a/tests/crm_test.py +++ b/tests/crm_test.py @@ -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 """ @@ -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) @@ -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 @@ -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 @@ -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 @@ -664,6 +691,7 @@ mpls_nexthop 0 1024 srv6_nexthop 0 1024 srv6_my_sid_entry 0 1024 +dram 1000 4000 ASIC1 @@ -686,6 +714,7 @@ mpls_nexthop 0 1024 srv6_nexthop 0 1024 srv6_my_sid_entry 0 1024 +dram 1000 4000 ASIC0 @@ -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): @@ -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']) @@ -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") @@ -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']) @@ -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): diff --git a/tests/mock_tables/asic0/config_db.json b/tests/mock_tables/asic0/config_db.json index 593170630f..97115cfc9c 100644 --- a/tests/mock_tables/asic0/config_db.json +++ b/tests/mock_tables/asic0/config_db.json @@ -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", diff --git a/tests/mock_tables/asic0/counters_db.json b/tests/mock_tables/asic0/counters_db.json index 610662a019..5f8d76d383 100644 --- a/tests/mock_tables/asic0/counters_db.json +++ b/tests/mock_tables/asic0/counters_db.json @@ -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", diff --git a/tests/mock_tables/asic1/config_db.json b/tests/mock_tables/asic1/config_db.json index 5c1d9f344c..75bfc29d04 100644 --- a/tests/mock_tables/asic1/config_db.json +++ b/tests/mock_tables/asic1/config_db.json @@ -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", diff --git a/tests/mock_tables/asic1/counters_db.json b/tests/mock_tables/asic1/counters_db.json index 1455f069c0..38e21ee272 100644 --- a/tests/mock_tables/asic1/counters_db.json +++ b/tests/mock_tables/asic1/counters_db.json @@ -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", diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 187efed553..782f502566 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -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" diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index 9e553c2901..d84373537c 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -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",