Skip to content

Commit

Permalink
Policer counter test
Browse files Browse the repository at this point in the history
  • Loading branch information
shiraez authored and shiraez committed Dec 9, 2024
1 parent a91318a commit 0d62611
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tests/test_flex_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
}

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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)

0 comments on commit 0d62611

Please sign in to comment.