tests: verify policer stats in punt tests 73/30973/2
authorBrian Russell <brian@graphiant.com>
Wed, 27 Jan 2021 14:45:22 +0000 (14:45 +0000)
committerNeale Ranns <neale@graphiant.com>
Tue, 2 Feb 2021 15:05:44 +0000 (15:05 +0000)
Add verification of policer stats in the IP[46] punt paths.

Type: test
Signed-off-by: Brian Russell <brian@graphiant.com>
Change-Id: I8b1035afc2d3abe4e98bdb3a76e87a0dd131ef4b

test/test_ip4.py
test/test_ip6.py
test/vpp_policer.py

index c99ab63..47f0af3 100644 (file)
@@ -1533,6 +1533,14 @@ class TestIPPunt(IPPuntSetup, VppTestCase):
         # but not equal to the number sent, since some were policed
         #
         rx = self.pg1._get_capture(1)
+
+        stats = policer.get_stats()
+
+        # Single rate policer - expect conform, violate but no exceed
+        self.assertGreater(stats['conform_packets'], 0)
+        self.assertEqual(stats['exceed_packets'], 0)
+        self.assertGreater(stats['violate_packets'], 0)
+
         self.assertGreater(len(rx), 0)
         self.assertLess(len(rx), len(pkts))
 
@@ -1636,6 +1644,24 @@ class TestIPPuntHandoff(IPPuntSetup, VppTestCase):
             if worker == 0:
                 self.logger.debug(self.vapi.cli("show trace max 100"))
 
+        # Combined stats, all threads
+        stats = policer.get_stats()
+
+        # Single rate policer - expect conform, violate but no exceed
+        self.assertGreater(stats['conform_packets'], 0)
+        self.assertEqual(stats['exceed_packets'], 0)
+        self.assertGreater(stats['violate_packets'], 0)
+
+        # Worker 0, should have done all the policing
+        stats0 = policer.get_stats(worker=0)
+        self.assertEqual(stats, stats0)
+
+        # Worker 1, should have handed everything off
+        stats1 = policer.get_stats(worker=1)
+        self.assertEqual(stats1['conform_packets'], 0)
+        self.assertEqual(stats1['exceed_packets'], 0)
+        self.assertEqual(stats1['violate_packets'], 0)
+
         #
         # Clean up
         #
index 2aab4de..a3da665 100644 (file)
@@ -2248,6 +2248,13 @@ class TestIP6Punt(IP6PuntSetup, VppTestCase):
         # but not equal to the number sent, since some were policed
         #
         rx = self.pg1._get_capture(1)
+        stats = policer.get_stats()
+
+        # Single rate policer - expect conform, violate but no exceed
+        self.assertGreater(stats['conform_packets'], 0)
+        self.assertEqual(stats['exceed_packets'], 0)
+        self.assertGreater(stats['violate_packets'], 0)
+
         self.assertGreater(len(rx), 0)
         self.assertLess(len(rx), len(pkts))
 
@@ -2352,6 +2359,24 @@ class TestIP6PuntHandoff(IP6PuntSetup, VppTestCase):
             if worker == 0:
                 self.logger.debug(self.vapi.cli("show trace max 100"))
 
+        # Combined stats, all threads
+        stats = policer.get_stats()
+
+        # Single rate policer - expect conform, violate but no exceed
+        self.assertGreater(stats['conform_packets'], 0)
+        self.assertEqual(stats['exceed_packets'], 0)
+        self.assertGreater(stats['violate_packets'], 0)
+
+        # Worker 0, should have done all the policing
+        stats0 = policer.get_stats(worker=0)
+        self.assertEqual(stats, stats0)
+
+        # Worker 1, should have handed everything off
+        stats1 = policer.get_stats(worker=1)
+        self.assertEqual(stats1['conform_packets'], 0)
+        self.assertEqual(stats1['exceed_packets'], 0)
+        self.assertEqual(stats1['violate_packets'], 0)
+
         #
         # Clean up
         #
index 49d1185..7f6d819 100644 (file)
@@ -67,3 +67,24 @@ class VppPolicer(VppObject):
 
     def object_id(self):
         return ("policer-%s" % (self.name))
+
+    def get_stats(self, worker=None):
+        conform = self._test.statistics.get_counter("/net/policer/conform")
+        exceed = self._test.statistics.get_counter("/net/policer/exceed")
+        violate = self._test.statistics.get_counter("/net/policer/violate")
+
+        counters = {"conform": conform, "exceed": exceed, "violate": violate}
+
+        total = {}
+        for name, c in counters.items():
+            total[f'{name}_packets'] = 0
+            total[f'{name}_bytes'] = 0
+            for i in range(len(c)):
+                t = c[i]
+                if worker is not None and i != worker + 1:
+                    continue
+                stat_index = self._policer_index
+                total[f'{name}_packets'] += t[stat_index]['packets']
+                total[f'{name}_bytes'] += t[stat_index]['bytes']
+
+        return total