From 487b3b70d22ec97a02e91b0030578514ba8e674e Mon Sep 17 00:00:00 2001 From: Kumaresh Perumal Date: Wed, 3 Nov 2021 15:48:32 -0700 Subject: [PATCH] Add CRM CLIs for SRV6 nexthop and my_sid_entry (#1883) * Add CRM CLIs for SRV6 nexthop and my_sid_entry --- crm/main.py | 44 ++++++- tests/crm_test.py | 156 +++++++++++++++++++++++ tests/mock_tables/asic0/config_db.json | 8 +- tests/mock_tables/asic0/counters_db.json | 6 +- tests/mock_tables/asic1/config_db.json | 8 +- tests/mock_tables/asic1/counters_db.json | 6 +- tests/mock_tables/config_db.json | 8 +- tests/mock_tables/counters_db.json | 6 +- 8 files changed, 234 insertions(+), 8 deletions(-) diff --git a/crm/main.py b/crm/main.py index 869c54b33bcd..f728f87dd991 100644 --- a/crm/main.py +++ b/crm/main.py @@ -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: @@ -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: @@ -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): @@ -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) @@ -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__': diff --git a/tests/crm_test.py b/tests/crm_test.py index 4f10b44d6933..24ced116ce6a 100644 --- a/tests/crm_test.py +++ b/tests/crm_test.py @@ -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 """ @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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") @@ -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']) @@ -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): diff --git a/tests/mock_tables/asic0/config_db.json b/tests/mock_tables/asic0/config_db.json index 79d6c30bb694..77874eb59ce7 100644 --- a/tests/mock_tables/asic0/config_db.json +++ b/tests/mock_tables/asic0/config_db.json @@ -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", diff --git a/tests/mock_tables/asic0/counters_db.json b/tests/mock_tables/asic0/counters_db.json index 99b89081edfc..44b78d823b67 100644 --- a/tests/mock_tables/asic0/counters_db.json +++ b/tests/mock_tables/asic0/counters_db.json @@ -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", diff --git a/tests/mock_tables/asic1/config_db.json b/tests/mock_tables/asic1/config_db.json index 733a35e6608e..f9fa66a0485f 100644 --- a/tests/mock_tables/asic1/config_db.json +++ b/tests/mock_tables/asic1/config_db.json @@ -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", diff --git a/tests/mock_tables/asic1/counters_db.json b/tests/mock_tables/asic1/counters_db.json index 269aa7ec6685..606ebd3fe8cd 100644 --- a/tests/mock_tables/asic1/counters_db.json +++ b/tests/mock_tables/asic1/counters_db.json @@ -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", diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 06305d30465e..2644012956f3 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -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" diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index 053165079e61..0ed15d8ca162 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -1902,7 +1902,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",