From 003cf24353c845ef708d192b7da8d571537671e1 Mon Sep 17 00:00:00 2001 From: Neetha John Date: Tue, 22 Sep 2020 23:05:38 -0700 Subject: [PATCH] [dvs] Refactor and add buffer pool wm test (#1446) Signed-off-by: Neetha John --- tests/test_watermark.py | 137 ++++++++++++++++++++++++++-------------- 1 file changed, 90 insertions(+), 47 deletions(-) diff --git a/tests/test_watermark.py b/tests/test_watermark.py index 9a4250e4aac9..ee5dfd055e83 100644 --- a/tests/test_watermark.py +++ b/tests/test_watermark.py @@ -11,6 +11,7 @@ class SaiWmStats: queue_shared = "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES" pg_shared = "SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES" pg_headroom = "SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES" + buffer_pool = "SAI_BUFFER_POOL_STAT_WATERMARK_BYTES" class WmTables: @@ -19,13 +20,19 @@ class WmTables: user = "USER_WATERMARKS" +class WmFCEntry: + queue_stats_entry = {"QUEUE_COUNTER_ID_LIST": SaiWmStats.queue_shared} + pg_stats_entry = {"PG_COUNTER_ID_LIST": "{},{}".format(SaiWmStats.pg_shared, SaiWmStats.pg_headroom)} + buffer_stats_entry = {"BUFFER_POOL_COUNTER_ID_LIST": SaiWmStats.buffer_pool} + + class TestWatermark(object): DEFAULT_TELEMETRY_INTERVAL = 120 NEW_INTERVAL = 5 DEFAULT_POLL_INTERVAL = 10 - def setup_db(self, dvs): + def setup_dbs(self, dvs): self.asic_db = dvs.get_asic_db() self.counters_db = dvs.get_counters_db() self.config_db = dvs.get_config_db() @@ -58,7 +65,12 @@ def populate_asic(self, dvs, obj_type, attr, val): db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - oids = self.qs if obj_type == "SAI_OBJECT_TYPE_QUEUE" else self.pgs + if obj_type == "SAI_OBJECT_TYPE_QUEUE": + oids = self.qs + elif obj_type == "SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP": + oids = self.pgs + else: + oids = self.buffers for obj_id in oids: self.set_counter(dvs, obj_type, obj_id, attr, val) @@ -67,6 +79,7 @@ def populate_asic_all(self, dvs, val): self.populate_asic(dvs, "SAI_OBJECT_TYPE_QUEUE", SaiWmStats.queue_shared, val) self.populate_asic(dvs, "SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP", SaiWmStats.pg_shared, val) self.populate_asic(dvs, "SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP", SaiWmStats.pg_headroom, val) + self.populate_asic(dvs, "SAI_OBJECT_TYPE_BUFFER_POOL", SaiWmStats.buffer_pool, val) time.sleep(self.DEFAULT_POLL_INTERVAL) def verify_value(self, dvs, obj_ids, table_name, watermark_name, expected_value): @@ -89,18 +102,20 @@ def verify_value(self, dvs, obj_ids, table_name, watermark_name, expected_value) assert found, "no such watermark found" def set_up_flex_counter(self, dvs): - queue_stats_entry = {"QUEUE_COUNTER_ID_LIST": "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES"} for q in self.qs: self.flex_db.create_entry("FLEX_COUNTER_TABLE", "QUEUE_WATERMARK_STAT_COUNTER:{}".format(q), - queue_stats_entry) + WmFCEntry.queue_stats_entry) - pg_stats_entry = {"PG_COUNTER_ID_LIST": - "SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES,SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES"} for pg in self.pgs: self.flex_db.create_entry("FLEX_COUNTER_TABLE", "PG_WATERMARK_STAT_COUNTER:{}".format(pg), - pg_stats_entry) + WmFCEntry.pg_stats_entry) + + for buffer in self.buffers: + self.flex_db.create_entry("FLEX_COUNTER_TABLE", + "BUFFER_POOL_WATERMARK_STAT_COUNTER:{}".format(buffer), + WmFCEntry.buffer_stats_entry) fc_status_enable = {"FLEX_COUNTER_STATUS": "enable"} self.config_db.create_entry("FLEX_COUNTER_TABLE", @@ -109,16 +124,33 @@ def set_up_flex_counter(self, dvs): self.config_db.create_entry("FLEX_COUNTER_TABLE", "QUEUE_WATERMARK", fc_status_enable) + self.config_db.create_entry("FLEX_COUNTER_TABLE", + "BUFFER_POOL_WATERMARK", + fc_status_enable) + + self.populate_asic_all(dvs, "0") + + def clear_flex_counter(self, dvs): + for q in self.qs: + self.flex_db.delete_entry("FLEX_COUNTER_TABLE", + "QUEUE_WATERMARK_STAT_COUNTER:{}".format(q)) + + for pg in self.pgs: + self.flex_db.delete_entry("FLEX_COUNTER_TABLE", + "PG_WATERMARK_STAT_COUNTER:{}".format(pg)) - self.populate_asic(dvs, "SAI_OBJECT_TYPE_QUEUE", SaiWmStats.queue_shared, "0") - self.populate_asic(dvs, "SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP", SaiWmStats.pg_shared, "0") - self.populate_asic(dvs, "SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP", SaiWmStats.pg_headroom, "0") + for buffer in self.buffers: + self.flex_db.delete_entry("FLEX_COUNTER_TABLE", + "BUFFER_POOL_WATERMARK_STAT_COUNTER:{}".format(buffer)) - time.sleep(self.DEFAULT_TELEMETRY_INTERVAL*2) + self.config_db.delete_entry("FLEX_COUNTER_TABLE", "PG_WATERMARK") + self.config_db.delete_entry("FLEX_COUNTER_TABLE", "QUEUE_WATERMARK") + self.config_db.delete_entry("FLEX_COUNTER_TABLE", "BUFFER_POOL_WATERMARK") def set_up(self, dvs): self.qs = self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_QUEUE") self.pgs = self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP") + self.buffers = self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_POOL") db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) tbl = swsscommon.Table(db, "COUNTERS_QUEUE_TYPE_MAP") @@ -135,67 +167,78 @@ def set_up(self, dvs): self.mc_q.append(q) def test_telemetry_period(self, dvs): - self.setup_db(dvs) + self.setup_dbs(dvs) self.set_up(dvs) - self.set_up_flex_counter(dvs) - self.enable_unittests(dvs, "true") + try: + self.set_up_flex_counter(dvs) + self.enable_unittests(dvs, "true") - self.populate_asic_all(dvs, "100") + self.populate_asic_all(dvs, "100") - time.sleep(self.DEFAULT_TELEMETRY_INTERVAL + 1) + time.sleep(self.DEFAULT_TELEMETRY_INTERVAL + 1) - self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_shared, "0") - self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_headroom, "0") - self.verify_value(dvs, self.qs, WmTables.periodic, SaiWmStats.queue_shared, "0") + self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_shared, "0") + self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_headroom, "0") + self.verify_value(dvs, self.qs, WmTables.periodic, SaiWmStats.queue_shared, "0") + self.verify_value(dvs, self.buffers, WmTables.periodic, SaiWmStats.buffer_pool, "0") - self.populate_asic_all(dvs, "123") + self.populate_asic_all(dvs, "123") - dvs.runcmd("config watermark telemetry interval {}".format(5)) + dvs.runcmd("config watermark telemetry interval {}".format(5)) - time.sleep(self.DEFAULT_TELEMETRY_INTERVAL + 1) - time.sleep(self.NEW_INTERVAL + 1) + time.sleep(self.DEFAULT_TELEMETRY_INTERVAL + 1) + time.sleep(self.NEW_INTERVAL + 1) - self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_shared, "0") - self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_headroom, "0") - self.verify_value(dvs, self.qs, WmTables.periodic, SaiWmStats.queue_shared, "0") + self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_shared, "0") + self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_headroom, "0") + self.verify_value(dvs, self.qs, WmTables.periodic, SaiWmStats.queue_shared, "0") + self.verify_value(dvs, self.buffers, WmTables.periodic, SaiWmStats.buffer_pool, "0") - self.enable_unittests(dvs, "false") + finally: + self.clear_flex_counter(dvs) + self.enable_unittests(dvs, "false") @pytest.mark.skip(reason="This test is not stable enough") def test_lua_plugins(self, dvs): - self.setup_db(dvs) + self.setup_dbs(dvs) self.set_up(dvs) - self.set_up_flex_counter(dvs) - self.enable_unittests(dvs, "true") + try: + self.set_up_flex_counter(dvs) + self.enable_unittests(dvs, "true") - self.populate_asic_all(dvs, "192") + self.populate_asic_all(dvs, "192") - for table_name in [WmTables.user, WmTables.persistent]: - self.verify_value(dvs, self.qs, table_name, SaiWmStats.queue_shared, "192") - self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_headroom, "192") - self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_shared, "192") + for table_name in [WmTables.user, WmTables.persistent]: + self.verify_value(dvs, self.selected_qs, table_name, SaiWmStats.queue_shared, "192") + self.verify_value(dvs, self.selected_pgs, table_name, SaiWmStats.pg_headroom, "192") + self.verify_value(dvs, self.selected_pgs, table_name, SaiWmStats.pg_shared, "192") + self.verify_value(dvs, self.buffers, table_name, SaiWmStats.buffer_pool, "192") - self.populate_asic_all(dvs, "96") + self.populate_asic_all(dvs, "96") - for table_name in [WmTables.user, WmTables.persistent]: - self.verify_value(dvs, self.qs, table_name, SaiWmStats.queue_shared, "192") - self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_headroom, "192") - self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_shared, "192") + for table_name in [WmTables.user, WmTables.persistent]: + self.verify_value(dvs, self.selected_qs, table_name, SaiWmStats.queue_shared, "192") + self.verify_value(dvs, self.selected_pgs, table_name, SaiWmStats.pg_headroom, "192") + self.verify_value(dvs, self.selected_pgs, table_name, SaiWmStats.pg_shared, "192") + self.verify_value(dvs, self.buffers, table_name, SaiWmStats.buffer_pool, "192") - self.populate_asic_all(dvs, "288") + self.populate_asic_all(dvs, "288") - for table_name in [WmTables.user, WmTables.persistent]: - self.verify_value(dvs, self.qs, table_name, SaiWmStats.queue_shared, "288") - self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_headroom, "288") - self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_shared, "288") + for table_name in [WmTables.user, WmTables.persistent]: + self.verify_value(dvs, self.selected_qs, table_name, SaiWmStats.queue_shared, "288") + self.verify_value(dvs, self.selected_pgs, table_name, SaiWmStats.pg_headroom, "288") + self.verify_value(dvs, self.selected_pgs, table_name, SaiWmStats.pg_shared, "288") + self.verify_value(dvs, self.buffers, table_name, SaiWmStats.buffer_pool, "288") - self.enable_unittests(dvs, "false") + finally: + self.clear_flex_counter(dvs) + self.enable_unittests(dvs, "false") @pytest.mark.skip(reason="This test is not stable enough") def test_clear(self, dvs): - self.setup_db(dvs) + self.setup_dbs(dvs) self.set_up(dvs) self.enable_unittests(dvs, "true")