From 0d626112eb2183ee7a14f4b999ad057db0dcf235 Mon Sep 17 00:00:00 2001 From: shiraez Date: Tue, 3 Dec 2024 12:40:56 +0200 Subject: [PATCH] Policer counter test --- tests/test_flex_counters.py | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/test_flex_counters.py b/tests/test_flex_counters.py index 1963248c2f..a81f045bad 100644 --- a/tests/test_flex_counters.py +++ b/tests/test_flex_counters.py @@ -78,6 +78,13 @@ 'name_map': 'COUNTERS_ROUTE_NAME_MAP', 'pre_test': 'pre_route_flow_counter_test', 'post_test': 'post_route_flow_counter_test', + }, + 'policer_counter': { + 'key': 'POLICER', + 'group_name': 'POLICER_STAT_COUNTER', + 'name_map': 'COUNTERS_POLICER_NAME_MAP', + 'pre_test': 'pre_policer_counter_test', + 'post_test': 'post_policer_counter_test', } } @@ -184,6 +191,16 @@ def pre_route_flow_counter_test(self, meta_data): dvs.servers[1].runcmd("ping -6 -c 1 2001::1") dvs.runcmd("vtysh -c \"configure terminal\" -c \"ipv6 route 2000::/64 2001::2\"") + def pre_policer_counter_test(self, meta_data): + self.config_db.db_connection.hset("POLICER|policer1", "meter_type", "packets") + self.config_db.db_connection.hset("POLICER|policer1", "mode", "sr_tcm") + self.config_db.db_connection.hset("POLICER|policer1", "cir", "600") + self.config_db.db_connection.hset("POLICER|policer1", "cbs", "600") + self.config_db.db_connection.hset("POLICER|policer1", "red_packet_action", "drop") + + def post_policer_counter_test(self, meta_data): + self.config_db.db_connection.hdel('POLICER|policer1', "NULL") + def post_rif_counter_test(self, meta_data): self.config_db.db_connection.hdel('INTERFACE|Ethernet0|192.168.0.1/24', "NULL") @@ -740,3 +757,55 @@ def test_create_remove_buffer_watermark_queue_pg_counter(self, dvs): index = '8' if 'queue' in counterpoll_type else '7' self.wait_for_buffer_pg_queue_counter(meta_data['name_map'], 'Ethernet0', index, False) self.wait_for_id_list_remove(meta_data['group_name'], "Ethernet0", counter_oid) + + + def test_create_remove_policer_counter(self, dvs): + """Test creation and removal of policer counters + + Args: + dvs (object): virtual switch object + + Test steps: + 1. Enable policer flex counters + 2. Configure new policer + 3. Verify counter is automatically created + 4. Remove the policer + 5. Verify counter is automatically removed + """ + self.setup_dbs(dvs) + meta_data = counter_group_meta['policer_counter'] + + # Enable flex counter group for policer + self.set_flex_counter_group_status(meta_data['key'], meta_data['name_map']) + + # Create a test policer + self.config_db.create_entry('POLICER', 'policer1', { + 'meter_type': 'bytes', + 'mode': 'sr_tcm', + 'cir': '600000', + 'cbs': '600000', + 'red_packet_action': 'drop' + }) + + # Wait for counter to be created and verify + for _ in range(NUMBER_OF_RETRIES): + counter_oid = self.counters_db.db_connection.hget(meta_data['name_map'], 'policer1') + if counter_oid: + break + time.sleep(1) + + assert counter_oid is not None, "Policer counter was not created" + self.wait_for_id_list(meta_data['group_name'], 'policer1', counter_oid) + + # Remove policer + self.config_db.delete_entry('POLICER', 'policer1') + + # Wait for counter to be removed and verify + for _ in range(NUMBER_OF_RETRIES): + counter_oid = self.counters_db.db_connection.hget(meta_data['name_map'], 'policer1') + if not counter_oid: + break + time.sleep(1) + + assert counter_oid is None, "Policer counter was not removed" + self.wait_for_id_list_remove(meta_data['group_name'], 'policer1', counter_oid) \ No newline at end of file