aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Russell <brian@graphiant.com>2021-02-17 15:54:52 +0000
committerNeale Ranns <neale@graphiant.com>2021-02-19 10:48:20 +0000
commit6e6920d4e096bd158a0057ce0f8dd8a08cbabf72 (patch)
tree95c897162eef66b8fad8092d47a096541451c9d8
parentb046830173a95b9f2d72865b3389174b7b7ff5d9 (diff)
tests: test input policer
Apply a policer to an interface, check it's policing packets. Remove it and check it no longer polices packets. Type: test Signed-off-by: Brian Russell <brian@graphiant.com> Change-Id: I6f694c8a9804cadf010b5831770aaae81f42e027
-rw-r--r--src/vnet/policer/test/test_policer_input.py74
-rw-r--r--test/vpp_policer.py4
2 files changed, 78 insertions, 0 deletions
diff --git a/src/vnet/policer/test/test_policer_input.py b/src/vnet/policer/test/test_policer_input.py
new file mode 100644
index 00000000000..a8457b61d71
--- /dev/null
+++ b/src/vnet/policer/test/test_policer_input.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python3
+# Copyright (c) 2021 Graphiant, Inc.
+
+import unittest
+import scapy.compat
+from scapy.layers.inet import IP, UDP
+from scapy.layers.l2 import Ether
+from scapy.packet import Raw
+from framework import VppTestCase, VppTestRunner
+from vpp_papi import VppEnum
+from vpp_policer import VppPolicer, PolicerAction
+
+NUM_PKTS = 67
+
+
+class TestPolicerInput(VppTestCase):
+ """ Policer on an input interface """
+
+ def setUp(self):
+ super(TestPolicerInput, self).setUp()
+
+ self.create_pg_interfaces(range(2))
+ for i in self.pg_interfaces:
+ i.admin_up()
+ i.config_ip4()
+ i.resolve_arp()
+
+ self.pkt = (Ether(src=self.pg0.remote_mac,
+ dst=self.pg0.local_mac) /
+ IP(src=self.pg0.remote_ip4, dst=self.pg1.remote_ip4) /
+ UDP(sport=1234, dport=1234) /
+ Raw(b'\xa5' * 100))
+
+ def tearDown(self):
+ for i in self.pg_interfaces:
+ i.unconfig_ip4()
+ i.admin_down()
+ super(TestPolicerInput, self).tearDown()
+
+ def test_policer_input(self):
+ action_tx = PolicerAction(
+ VppEnum.vl_api_sse2_qos_action_type_t.SSE2_QOS_ACTION_API_TRANSMIT,
+ 0)
+ policer = VppPolicer(self, "pol1", 80, 0, 1000, 0,
+ conform_action=action_tx,
+ exceed_action=action_tx,
+ violate_action=action_tx)
+ policer.add_vpp_config()
+
+ # Start policing on pg0
+ policer.apply_vpp_config(self.pg0.sw_if_index, True)
+
+ rx = self.send_and_expect(self.pg0, self.pkt * NUM_PKTS, self.pg1)
+ stats = policer.get_stats()
+
+ # Single rate, 2 colour 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)
+
+ # Stop policing on pg0
+ policer.apply_vpp_config(self.pg0.sw_if_index, False)
+
+ rx = self.send_and_expect(self.pg0, self.pkt * NUM_PKTS, self.pg1)
+ statsnew = policer.get_stats()
+
+ # No new packets counted
+ self.assertEqual(stats, statsnew)
+
+ policer.remove_vpp_config()
+
+
+if __name__ == '__main__':
+ unittest.main(testRunner=VppTestRunner)
diff --git a/test/vpp_policer.py b/test/vpp_policer.py
index 387ab270214..2c47eed75fd 100644
--- a/test/vpp_policer.py
+++ b/test/vpp_policer.py
@@ -61,6 +61,10 @@ class VppPolicer(VppObject):
self._test.vapi.policer_bind(name=self.name, worker_index=worker,
bind_enable=bind)
+ def apply_vpp_config(self, if_index, apply):
+ self._test.vapi.policer_input(name=self.name, sw_if_index=if_index,
+ apply=apply)
+
def query_vpp_config(self):
dump = self._test.vapi.policer_dump(
match_name_valid=True, match_name=self.name)