diff --git a/counterpoll/main.py b/counterpoll/main.py index dbbbe7aac5..8c67aa1fc2 100644 --- a/counterpoll/main.py +++ b/counterpoll/main.py @@ -5,6 +5,7 @@ BUFFER_POOL_WATERMARK = "BUFFER_POOL_WATERMARK" PORT_BUFFER_DROP = "PORT_BUFFER_DROP" +PG_DROP = "PG_DROP" DISABLE = "disable" ENABLE = "enable" DEFLT_60_SEC= "default (60000)" @@ -123,6 +124,45 @@ def disable(): port_info['FLEX_COUNTER_STATUS'] = DISABLE configdb.mod_entry("FLEX_COUNTER_TABLE", PORT_BUFFER_DROP, port_info) +# Ingress PG drop packet stat +@cli.group() +@click.pass_context +def pg_drop(ctx): + """ Ingress PG drop counter commands """ + ctx.obj = swsssdk.ConfigDBConnector() + ctx.obj.connect() + +@pg_drop.command() +@click.argument('poll_interval', type=click.IntRange(1000, 30000)) +@click.pass_context +def interval(ctx, poll_interval): + """ + Set pg_drop packets counter query interval + interval is between 1s and 30s. + """ + + port_info = {} + port_info['POLL_INTERVAL'] = poll_interval + ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info) + +@pg_drop.command() +@click.pass_context +def enable(ctx): + """ Enable pg_drop counter query """ + + port_info = {} + port_info['FLEX_COUNTER_STATUS'] = ENABLE + ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info) + +@pg_drop.command() +@click.pass_context +def disable(ctx): + """ Disable pg_drop counter query """ + + port_info = {} + port_info['FLEX_COUNTER_STATUS'] = DISABLE + ctx.obj.mod_entry("FLEX_COUNTER_TABLE", PG_DROP, port_info) + # RIF counter commands @cli.group() def rif(): @@ -212,6 +252,7 @@ def show(): rif_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'RIF') queue_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE_WATERMARK') pg_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PG_WATERMARK') + pg_drop_info = configdb.get_entry('FLEX_COUNTER_TABLE', PG_DROP) buffer_pool_wm_info = configdb.get_entry('FLEX_COUNTER_TABLE', BUFFER_POOL_WATERMARK) header = ("Type", "Interval (in ms)", "Status") @@ -228,6 +269,8 @@ def show(): data.append(["QUEUE_WATERMARK_STAT", queue_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), queue_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)]) if pg_wm_info: data.append(["PG_WATERMARK_STAT", pg_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), pg_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)]) + if pg_drop_info: + data.append(['PG_DROP_STAT', pg_drop_info.get("POLL_INTERVAL", DEFLT_10_SEC), pg_drop_info.get("FLEX_COUNTER_STATUS", DISABLE)]) if buffer_pool_wm_info: data.append(["BUFFER_POOL_WATERMARK_STAT", buffer_pool_wm_info.get("POLL_INTERVAL", DEFLT_10_SEC), buffer_pool_wm_info.get("FLEX_COUNTER_STATUS", DISABLE)]) diff --git a/tests/counterpoll_test.py b/tests/counterpoll_test.py index d179553abc..07fe5aaea2 100644 --- a/tests/counterpoll_test.py +++ b/tests/counterpoll_test.py @@ -7,6 +7,7 @@ import time from click.testing import CliRunner from shutil import copyfile +from utilities_common.db import Db test_path = os.path.dirname(os.path.abspath(__file__)) modules_path = os.path.dirname(test_path) @@ -25,6 +26,7 @@ PORT_BUFFER_DROP 60000 enable QUEUE_WATERMARK_STAT 10000 enable PG_WATERMARK_STAT 10000 enable +PG_DROP_STAT 10000 enable """ class TestCounterpoll(object): @@ -54,6 +56,14 @@ def test_port_buffer_drop_interval_too_short(self): assert result.exit_code == 2 assert expected in result.output + def test_pg_drop_interval_too_long(self): + runner = CliRunner() + result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands["interval"], ["50000"]) + print(result.output) + expected = "Invalid value for \"POLL_INTERVAL\": 50000 is not in the valid range of 1000 to 30000." + assert result.exit_code == 2 + assert expected in result.output + @pytest.fixture(scope='class') def _get_config_db_file(self): sample_config_db_file = os.path.join(test_path, "counterpoll_input", "config_db.json") @@ -76,6 +86,30 @@ def test_update_counter_config_db_status(self, status, _get_config_db_file): for counter, counter_config in config_db["FLEX_COUNTER_TABLE"].items(): assert counter_config["FLEX_COUNTER_STATUS"] == status + @pytest.mark.parametrize("status", ["disable", "enable"]) + def test_update_pg_drop_status(self, status): + runner = CliRunner() + db = Db() + + result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands[status], [], obj=db.cfgdb) + print(result.exit_code, result.output) + assert result.exit_code == 0 + + table = db.cfgdb.get_table('FLEX_COUNTER_TABLE') + assert status == table["PG_DROP"]["FLEX_COUNTER_STATUS"] + + def test_update_pg_drop_interval(self): + runner = CliRunner() + db = Db() + test_interval = "20000" + + result = runner.invoke(counterpoll.cli.commands["pg-drop"].commands["interval"], [test_interval], obj=db.cfgdb) + print(result.exit_code, result.output) + assert result.exit_code == 0 + + table = db.cfgdb.get_table('FLEX_COUNTER_TABLE') + assert test_interval == table["PG_DROP"]["POLL_INTERVAL"] + @classmethod def teardown_class(cls): print("TEARDOWN") diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 21676feb57..ec1ba9686c 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -1262,6 +1262,10 @@ "POLL_INTERVAL": "10000", "FLEX_COUNTER_STATUS": "enable" }, + "FLEX_COUNTER_TABLE|PG_DROP": { + "POLL_INTERVAL": "10000", + "FLEX_COUNTER_STATUS": "enable" + }, "PFC_WD|Ethernet0": { "action": "drop", "detection_time": "600",