aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStanislav Zaikin <zstaseg@gmail.com>2022-04-05 19:23:12 +0200
committerNeale Ranns <neale@graphiant.com>2022-05-05 00:19:12 +0000
commite5a3ae0179b807efc2202a47e11d698396dd0780 (patch)
tree15883a9f368705fab0128693c6ed4dd6fb475e3c /test
parent0ec1c6dc68570b8b824ff55205b4b133bffbf9e4 (diff)
policer: output interface policer
Type: improvement Change-Id: Ibc1b5059ed51c34334340534e9eb68121f556bce Signed-off-by: Stanislav Zaikin <zstaseg@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/test_ipsec_tun_if_esp.py18
-rw-r--r--test/test_policer_input.py43
-rw-r--r--test/vpp_policer.py16
3 files changed, 55 insertions, 22 deletions
diff --git a/test/test_ipsec_tun_if_esp.py b/test/test_ipsec_tun_if_esp.py
index 8b6f619b47f..14c9b3e3f11 100644
--- a/test/test_ipsec_tun_if_esp.py
+++ b/test/test_ipsec_tun_if_esp.py
@@ -25,7 +25,7 @@ from util import ppp
from vpp_papi import VppEnum
from vpp_papi_provider import CliFailedCommandError
from vpp_acl import AclRule, VppAcl, VppAclInterface
-from vpp_policer import PolicerAction, VppPolicer
+from vpp_policer import PolicerAction, VppPolicer, Dir
def config_tun_params(p, encryption_type, tun_if, src=None, dst=None):
@@ -513,7 +513,7 @@ class TestIpsec6TunIfEspHandoff(TemplateIpsec6TunIfEsp,
policer.add_vpp_config()
# Start policing on tun
- policer.apply_vpp_config(p.tun_if.sw_if_index, True)
+ policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, True)
for pol_bind in [1, 0]:
policer.bind_vpp_config(pol_bind, True)
@@ -557,7 +557,7 @@ class TestIpsec6TunIfEspHandoff(TemplateIpsec6TunIfEsp,
stats1['conform_packets'] +
stats1['violate_packets'])
- policer.apply_vpp_config(p.tun_if.sw_if_index, False)
+ policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, False)
policer.remove_vpp_config()
@@ -585,7 +585,7 @@ class TestIpsec4TunIfEspHandoff(TemplateIpsec4TunIfEsp,
policer.add_vpp_config()
# Start policing on tun
- policer.apply_vpp_config(p.tun_if.sw_if_index, True)
+ policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, True)
for pol_bind in [1, 0]:
policer.bind_vpp_config(pol_bind, True)
@@ -629,7 +629,7 @@ class TestIpsec4TunIfEspHandoff(TemplateIpsec4TunIfEsp,
stats1['conform_packets'] +
stats1['violate_packets'])
- policer.apply_vpp_config(p.tun_if.sw_if_index, False)
+ policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, False)
policer.remove_vpp_config()
@@ -2726,7 +2726,7 @@ class TestIpsecItf4(TemplateIpsec,
policer.add_vpp_config()
# Start policing on tun
- policer.apply_vpp_config(p.tun_if.sw_if_index, True)
+ policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, True)
self.verify_tun_44(p, count=n_pkts)
self.assertEqual(p.tun_if.get_rx_stats(), n_pkts)
@@ -2740,7 +2740,7 @@ class TestIpsecItf4(TemplateIpsec,
self.assertGreater(stats['violate_packets'], 0)
# Stop policing on tun
- policer.apply_vpp_config(p.tun_if.sw_if_index, False)
+ policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, False)
self.verify_tun_44(p, count=n_pkts)
# No new policer stats
@@ -3017,7 +3017,7 @@ class TestIpsecItf6(TemplateIpsec,
policer.add_vpp_config()
# Start policing on tun
- policer.apply_vpp_config(p.tun_if.sw_if_index, True)
+ policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, True)
self.verify_tun_66(p, count=n_pkts)
self.assertEqual(p.tun_if.get_rx_stats(), n_pkts)
@@ -3031,7 +3031,7 @@ class TestIpsecItf6(TemplateIpsec,
self.assertGreater(stats['violate_packets'], 0)
# Stop policing on tun
- policer.apply_vpp_config(p.tun_if.sw_if_index, False)
+ policer.apply_vpp_config(p.tun_if.sw_if_index, Dir.RX, False)
self.verify_tun_66(p, count=n_pkts)
# No new policer stats
diff --git a/test/test_policer_input.py b/test/test_policer_input.py
index c95f6643ff2..9a4266ceb12 100644
--- a/test/test_policer_input.py
+++ b/test/test_policer_input.py
@@ -8,13 +8,13 @@ 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
+from vpp_policer import VppPolicer, PolicerAction, Dir
NUM_PKTS = 67
class TestPolicerInput(VppTestCase):
- """ Policer on an input interface """
+ """ Policer on an interface """
vpp_worker_count = 2
def setUp(self):
@@ -38,8 +38,7 @@ class TestPolicerInput(VppTestCase):
i.admin_down()
super(TestPolicerInput, self).tearDown()
- def test_policer_input(self):
- """ Input Policing """
+ def policer_interface_test(self, dir: Dir):
pkts = self.pkt * NUM_PKTS
action_tx = PolicerAction(
@@ -51,8 +50,12 @@ class TestPolicerInput(VppTestCase):
violate_action=action_tx)
policer.add_vpp_config()
+ sw_if_index = (self.pg0.sw_if_index
+ if dir == Dir.RX
+ else self.pg1.sw_if_index)
+
# Start policing on pg0
- policer.apply_vpp_config(self.pg0.sw_if_index, True)
+ policer.apply_vpp_config(sw_if_index, dir, True)
rx = self.send_and_expect(self.pg0, pkts, self.pg1, worker=0)
stats = policer.get_stats()
@@ -63,7 +66,7 @@ class TestPolicerInput(VppTestCase):
self.assertGreater(stats['violate_packets'], 0)
# Stop policing on pg0
- policer.apply_vpp_config(self.pg0.sw_if_index, False)
+ policer.apply_vpp_config(sw_if_index, dir, False)
rx = self.send_and_expect(self.pg0, pkts, self.pg1, worker=0)
@@ -74,8 +77,15 @@ class TestPolicerInput(VppTestCase):
policer.remove_vpp_config()
- def test_policer_handoff(self):
- """ Worker thread handoff """
+ def test_policer_input(self):
+ """ Input Policing """
+ self.policer_interface_test(Dir.RX)
+
+ def test_policer_output(self):
+ """ Output Policing """
+ self.policer_interface_test(Dir.TX)
+
+ def policer_handoff_test(self, dir: Dir):
pkts = self.pkt * NUM_PKTS
action_tx = PolicerAction(
@@ -87,11 +97,15 @@ class TestPolicerInput(VppTestCase):
violate_action=action_tx)
policer.add_vpp_config()
+ sw_if_index = (self.pg0.sw_if_index
+ if dir == Dir.RX
+ else self.pg1.sw_if_index)
+
# Bind the policer to worker 1
policer.bind_vpp_config(1, True)
# Start policing on pg0
- policer.apply_vpp_config(self.pg0.sw_if_index, True)
+ policer.apply_vpp_config(sw_if_index, dir, True)
for worker in [0, 1]:
self.send_and_expect(self.pg0, pkts, self.pg1, worker=worker)
@@ -138,9 +152,18 @@ class TestPolicerInput(VppTestCase):
stats['violate_packets'])
# Stop policing on pg0
- policer.apply_vpp_config(self.pg0.sw_if_index, False)
+ policer.apply_vpp_config(sw_if_index, dir, False)
policer.remove_vpp_config()
+ def test_policer_handoff_input(self):
+ """ Worker thread handoff policer input"""
+ self.policer_handoff_test(Dir.RX)
+
+ def test_policer_handoff_output(self):
+ """ Worker thread handoff policer output"""
+ self.policer_handoff_test(Dir.TX)
+
+
if __name__ == '__main__':
unittest.main(testRunner=VppTestRunner)
diff --git a/test/vpp_policer.py b/test/vpp_policer.py
index 2c47eed75fd..0f3b073d6e3 100644
--- a/test/vpp_policer.py
+++ b/test/vpp_policer.py
@@ -1,5 +1,11 @@
from vpp_object import VppObject
from vpp_ip import INVALID_INDEX
+from enum import Enum
+
+
+class Dir(Enum):
+ RX = 0
+ TX = 1
class PolicerAction():
@@ -61,9 +67,13 @@ 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 apply_vpp_config(self, if_index, dir: Dir, apply):
+ if dir == Dir.RX:
+ self._test.vapi.policer_input(
+ name=self.name, sw_if_index=if_index, apply=apply)
+ else:
+ self._test.vapi.policer_output(
+ name=self.name, sw_if_index=if_index, apply=apply)
def query_vpp_config(self):
dump = self._test.vapi.policer_dump(