From ce9cfe7bf609cb62d2c6b035345430268847a9d1 Mon Sep 17 00:00:00 2001 From: Prabhat Aravind Date: Tue, 2 May 2023 22:50:29 -0700 Subject: [PATCH] [tests/copp]: Update copp mgmt tests to support new rate-limits * Rate limits are being set for bgp, lacp, dhcp, lldp, udld and macsec via a copp cfg change. This is the corresponding sonic-mgmt change Signed-off-by: Prabhat Aravind --- .../test/files/ptftests/py3/copp_tests.py | 52 +++++-------------- tests/copp/test_copp.py | 29 +++-------- 2 files changed, 19 insertions(+), 62 deletions(-) diff --git a/ansible/roles/test/files/ptftests/py3/copp_tests.py b/ansible/roles/test/files/ptftests/py3/copp_tests.py index 7207e364b47..b6f4702eca4 100644 --- a/ansible/roles/test/files/ptftests/py3/copp_tests.py +++ b/ansible/roles/test/files/ptftests/py3/copp_tests.py @@ -238,34 +238,6 @@ def printStats(self, pkt_send_count, recv_count, time_delta, tx_pps, rx_pps): self.log('RX PPS = %d' % rx_pps) -class NoPolicyTest(ControlPlaneBaseTest): - def __init__(self): - ControlPlaneBaseTest.__init__(self) - self.needPreSend = False - - def check_constraints(self, send_count, recv_count, time_delta_ms, rx_pps): - pkt_rx_limit = send_count * 0.90 - - self.log("") - self.log("Checking constraints (NoPolicy):") - self.log( - "rx_pps (%d) > NO_POLICER_LIMIT (%d): %s" % - (int(rx_pps), int(self.NO_POLICER_LIMIT), - str(rx_pps > self.NO_POLICER_LIMIT)) - ) - self.log( - "recv_count (%d) > pkt_rx_limit (%d): %s" % - (int(recv_count), int(pkt_rx_limit), str(recv_count > pkt_rx_limit)) - ) - - if self.has_trap: - assert (rx_pps > self.NO_POLICER_LIMIT) - assert (recv_count > pkt_rx_limit) - else: - assert (rx_pps < self.NO_POLICER_LIMIT) - assert (recv_count < pkt_rx_limit) - - class PolicyTest(ControlPlaneBaseTest): def __init__(self): ControlPlaneBaseTest.__init__(self) @@ -351,9 +323,9 @@ def contruct_packet(self, port_number): # SONIC configuration has no policer limiting for DHCP -class DHCPTest(NoPolicyTest): +class DHCPTest(PolicyTest): def __init__(self): - NoPolicyTest.__init__(self) + PolicyTest.__init__(self) def runTest(self): self.log("DHCPTest") @@ -385,9 +357,9 @@ def contruct_packet(self, port_number): # SONIC configuration has no policer limiting for DHCPv6 -class DHCP6Test(NoPolicyTest): +class DHCP6Test(PolicyTest): def __init__(self): - NoPolicyTest.__init__(self) + PolicyTest.__init__(self) def runTest(self): self.log("DHCP6Test") @@ -439,9 +411,9 @@ def contruct_packet(self, port_number): # SONIC configuration has no policer limiting for LLDP -class LLDPTest(NoPolicyTest): +class LLDPTest(PolicyTest): def __init__(self): - NoPolicyTest.__init__(self) + PolicyTest.__init__(self) def runTest(self): self.log("LLDPTest") @@ -460,9 +432,9 @@ def contruct_packet(self, port_number): # SONIC configuration has no policer limiting for UDLD -class UDLDTest(NoPolicyTest): +class UDLDTest(PolicyTest): def __init__(self): - NoPolicyTest.__init__(self) + PolicyTest.__init__(self) def runTest(self): self.log("UDLDTest") @@ -486,9 +458,9 @@ def contruct_packet(self, port_number): # SONIC configuration has no policer limiting for BGP -class BGPTest(NoPolicyTest): +class BGPTest(PolicyTest): def __init__(self): - NoPolicyTest.__init__(self) + PolicyTest.__init__(self) def runTest(self): self.log("BGPTest") @@ -509,9 +481,9 @@ def contruct_packet(self, port_number): # SONIC configuration has no policer limiting for LACP -class LACPTest(NoPolicyTest): +class LACPTest(PolicyTest): def __init__(self): - NoPolicyTest.__init__(self) + PolicyTest.__init__(self) def runTest(self): self.log("LACPTest") diff --git a/tests/copp/test_copp.py b/tests/copp/test_copp.py index 7f977f50b85..209407c8f78 100644 --- a/tests/copp/test_copp.py +++ b/tests/copp/test_copp.py @@ -74,35 +74,20 @@ class TestCOPP(object): @pytest.mark.parametrize("protocol", ["ARP", "IP2ME", "SNMP", - "SSH"]) - def test_policer(self, protocol, duthosts, enum_rand_one_per_hwsku_frontend_hostname, - ptfhost, copp_testbed, dut_type): - """ - Validates that rate-limited COPP groups work as expected. - - Checks that the policer enforces the rate limit for protocols - that have a set rate limit. - """ - duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] - _copp_runner(duthost, - ptfhost, - protocol, - copp_testbed, - dut_type) - - @pytest.mark.parametrize("protocol", ["BGP", + "SSH", "DHCP", "DHCP6", + "BGP", "LACP", "LLDP", "UDLD"]) - def test_no_policer(self, protocol, duthosts, enum_rand_one_per_hwsku_frontend_hostname, - ptfhost, copp_testbed, dut_type): + def test_policer(self, protocol, duthosts, enum_rand_one_per_hwsku_frontend_hostname, + ptfhost, copp_testbed, dut_type): """ - Validates that non-rate-limited COPP groups work as expected. + Validates that rate-limited COPP groups work as expected. - Checks that the policer does not enforce a rate limit for protocols - that do not have any set rate limit. + Checks that the policer enforces the rate limit for protocols + that have a set rate limit. """ duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] _copp_runner(duthost,