summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_ip4.py53
-rw-r--r--test/test_ip6.py58
-rw-r--r--test/test_neighbor.py8
-rw-r--r--test/vpp_ip.py48
-rw-r--r--test/vpp_papi_provider.py27
5 files changed, 103 insertions, 91 deletions
diff --git a/test/test_ip4.py b/test/test_ip4.py
index 35be24ca34d..b93241b652d 100644
--- a/test/test_ip4.py
+++ b/test/test_ip4.py
@@ -17,6 +17,7 @@ from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpMRoute, \
VppMRoutePath, VppMplsIpBind, \
VppMplsTable, VppIpTable, FibPathType, find_route, \
VppIpInterfaceAddress, find_route_in_dump, find_mroute_in_dump
+from vpp_ip import VppIpPuntPolicer, VppIpPuntRedirect
from vpp_sub_interface import VppSubInterface, VppDot1QSubint, VppDot1ADSubint
from vpp_papi import VppEnum
from vpp_neighbor import VppNeighbor
@@ -1477,9 +1478,9 @@ class TestIPPunt(VppTestCase):
# Configure a punt redirect via pg1.
#
nh_addr = self.pg1.remote_ip4
- self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
- self.pg1.sw_if_index,
- nh_addr)
+ ip_punt_redirect = VppIpPuntRedirect(self, self.pg0.sw_if_index,
+ self.pg1.sw_if_index, nh_addr)
+ ip_punt_redirect.add_vpp_config()
self.send_and_expect(self.pg0, pkts, self.pg1)
@@ -1488,7 +1489,8 @@ class TestIPPunt(VppTestCase):
#
policer = VppPolicer(self, "ip4-punt", 400, 0, 10, 0, rate_type=1)
policer.add_vpp_config()
- self.vapi.ip_punt_police(policer.policer_index)
+ ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index)
+ ip_punt_policer.add_vpp_config()
self.vapi.cli("clear trace")
self.pg0.add_stream(pkts)
@@ -1506,32 +1508,25 @@ class TestIPPunt(VppTestCase):
#
# remove the policer. back to full rx
#
- self.vapi.ip_punt_police(policer.policer_index, is_add=0)
+ ip_punt_policer.remove_vpp_config()
policer.remove_vpp_config()
self.send_and_expect(self.pg0, pkts, self.pg1)
#
# remove the redirect. expect full drop.
#
- self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
- self.pg1.sw_if_index,
- nh_addr,
- is_add=0)
+ ip_punt_redirect.remove_vpp_config()
self.send_and_assert_no_replies(self.pg0, pkts,
"IP no punt config")
#
# Add a redirect that is not input port selective
#
- self.vapi.ip_punt_redirect(0xffffffff,
- self.pg1.sw_if_index,
- nh_addr)
+ ip_punt_redirect = VppIpPuntRedirect(self, 0xffffffff,
+ self.pg1.sw_if_index, nh_addr)
+ ip_punt_redirect.add_vpp_config()
self.send_and_expect(self.pg0, pkts, self.pg1)
-
- self.vapi.ip_punt_redirect(0xffffffff,
- self.pg1.sw_if_index,
- nh_addr,
- is_add=0)
+ ip_punt_redirect.remove_vpp_config()
def test_ip_punt_dump(self):
""" IP4 punt redirect dump"""
@@ -1540,22 +1535,22 @@ class TestIPPunt(VppTestCase):
# Configure a punt redirects
#
nh_address = self.pg3.remote_ip4
- self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
- self.pg3.sw_if_index,
- nh_address)
- self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
- self.pg3.sw_if_index,
- nh_address)
- self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
- self.pg3.sw_if_index,
- '0.0.0.0')
+ ipr_03 = VppIpPuntRedirect(self, self.pg0.sw_if_index,
+ self.pg3.sw_if_index, nh_address)
+ ipr_13 = VppIpPuntRedirect(self, self.pg1.sw_if_index,
+ self.pg3.sw_if_index, nh_address)
+ ipr_23 = VppIpPuntRedirect(self, self.pg2.sw_if_index,
+ self.pg3.sw_if_index, "0.0.0.0")
+ ipr_03.add_vpp_config()
+ ipr_13.add_vpp_config()
+ ipr_23.add_vpp_config()
#
# Dump pg0 punt redirects
#
- punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index)
- for p in punts:
- self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
+ self.assertTrue(ipr_03.query_vpp_config())
+ self.assertTrue(ipr_13.query_vpp_config())
+ self.assertTrue(ipr_23.query_vpp_config())
#
# Dump punt redirects for all interfaces
diff --git a/test/test_ip6.py b/test/test_ip6.py
index 740e2e28510..e6067f67dd9 100644
--- a/test/test_ip6.py
+++ b/test/test_ip6.py
@@ -22,7 +22,7 @@ from six import moves
from framework import VppTestCase, VppTestRunner
from util import ppp, ip6_normalize, mk_ll_addr
from vpp_papi import VppEnum
-from vpp_ip import DpoProto
+from vpp_ip import DpoProto, VppIpPuntPolicer, VppIpPuntRedirect
from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, VppIpMRoute, \
VppMRoutePath, VppMplsIpBind, \
VppMplsRoute, VppMplsTable, VppIpTable, FibPathType, FibPathProto, \
@@ -2211,9 +2211,9 @@ class TestIP6Punt(VppTestCase):
# Configure a punt redirect via pg1.
#
nh_addr = self.pg1.remote_ip6
- self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
- self.pg1.sw_if_index,
- nh_addr)
+ ip_punt_redirect = VppIpPuntRedirect(self, self.pg0.sw_if_index,
+ self.pg1.sw_if_index, nh_addr)
+ ip_punt_redirect.add_vpp_config()
self.send_and_expect(self.pg0, pkts, self.pg1)
@@ -2222,7 +2222,9 @@ class TestIP6Punt(VppTestCase):
#
policer = VppPolicer(self, "ip6-punt", 400, 0, 10, 0, rate_type=1)
policer.add_vpp_config()
- self.vapi.ip_punt_police(policer.policer_index, is_ip6=1)
+ ip_punt_policer = VppIpPuntPolicer(self, policer.policer_index,
+ is_ip6=True)
+ ip_punt_policer.add_vpp_config()
self.vapi.cli("clear trace")
self.pg0.add_stream(pkts)
@@ -2240,32 +2242,25 @@ class TestIP6Punt(VppTestCase):
#
# remove the policer. back to full rx
#
- self.vapi.ip_punt_police(policer.policer_index, is_add=0, is_ip6=1)
+ ip_punt_policer.remove_vpp_config()
policer.remove_vpp_config()
self.send_and_expect(self.pg0, pkts, self.pg1)
#
# remove the redirect. expect full drop.
#
- self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
- self.pg1.sw_if_index,
- nh_addr,
- is_add=0)
+ ip_punt_redirect.remove_vpp_config()
self.send_and_assert_no_replies(self.pg0, pkts,
"IP no punt config")
#
# Add a redirect that is not input port selective
#
- self.vapi.ip_punt_redirect(0xffffffff,
- self.pg1.sw_if_index,
- nh_addr)
+ ip_punt_redirect = VppIpPuntRedirect(self, 0xffffffff,
+ self.pg1.sw_if_index, nh_addr)
+ ip_punt_redirect.add_vpp_config()
self.send_and_expect(self.pg0, pkts, self.pg1)
-
- self.vapi.ip_punt_redirect(0xffffffff,
- self.pg1.sw_if_index,
- nh_addr,
- is_add=0)
+ ip_punt_redirect.remove_vpp_config()
def test_ip_punt_dump(self):
""" IP6 punt redirect dump"""
@@ -2273,24 +2268,23 @@ class TestIP6Punt(VppTestCase):
#
# Configure a punt redirects
#
- nh_addr = self.pg3.remote_ip6
- self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
- self.pg3.sw_if_index,
- nh_addr)
- self.vapi.ip_punt_redirect(self.pg1.sw_if_index,
- self.pg3.sw_if_index,
- nh_addr)
- self.vapi.ip_punt_redirect(self.pg2.sw_if_index,
- self.pg3.sw_if_index,
- '0::0')
+ nh_address = self.pg3.remote_ip6
+ ipr_03 = VppIpPuntRedirect(self, self.pg0.sw_if_index,
+ self.pg3.sw_if_index, nh_address)
+ ipr_13 = VppIpPuntRedirect(self, self.pg1.sw_if_index,
+ self.pg3.sw_if_index, nh_address)
+ ipr_23 = VppIpPuntRedirect(self, self.pg2.sw_if_index,
+ self.pg3.sw_if_index, '0::0')
+ ipr_03.add_vpp_config()
+ ipr_13.add_vpp_config()
+ ipr_23.add_vpp_config()
#
# Dump pg0 punt redirects
#
- punts = self.vapi.ip_punt_redirect_dump(self.pg0.sw_if_index,
- is_ipv6=1)
- for p in punts:
- self.assertEqual(p.punt.rx_sw_if_index, self.pg0.sw_if_index)
+ self.assertTrue(ipr_03.query_vpp_config())
+ self.assertTrue(ipr_13.query_vpp_config())
+ self.assertTrue(ipr_23.query_vpp_config())
#
# Dump punt redirects for all interfaces
diff --git a/test/test_neighbor.py b/test/test_neighbor.py
index 2dc27a83b0a..7c13f9ffb0a 100644
--- a/test/test_neighbor.py
+++ b/test/test_neighbor.py
@@ -9,6 +9,7 @@ from vpp_neighbor import VppNeighbor, find_nbr
from vpp_ip_route import VppIpRoute, VppRoutePath, find_route, \
VppIpTable, DpoProto, FibPathType
from vpp_papi import VppEnum
+from vpp_ip import VppIpPuntRedirect
import scapy.compat
from scapy.packet import Raw
@@ -798,9 +799,9 @@ class ARPTestCase(VppTestCase):
#
# setup a punt redirect so packets from the uplink go to the tap
#
- self.vapi.ip_punt_redirect(self.pg0.sw_if_index,
- self.pg2.sw_if_index,
- self.pg0.local_ip4)
+ redirect = VppIpPuntRedirect(self, self.pg0.sw_if_index,
+ self.pg2.sw_if_index, self.pg0.local_ip4)
+ redirect.add_vpp_config()
p_tcp = (Ether(src=self.pg0.remote_mac,
dst=self.pg0.local_mac,) /
@@ -844,6 +845,7 @@ class ARPTestCase(VppTestCase):
'low': self.pg0._local_ip4_subnet,
'hi': self.pg0._local_ip4_bcast},
is_add=0)
+ redirect.remove_vpp_config()
def test_proxy_arp(self):
""" Proxy ARP """
diff --git a/test/vpp_ip.py b/test/vpp_ip.py
index 3c01ba5e4b8..e2367a3ce28 100644
--- a/test/vpp_ip.py
+++ b/test/vpp_ip.py
@@ -7,6 +7,7 @@ import logging
from ipaddress import ip_address
from socket import AF_INET, AF_INET6
from vpp_papi import VppEnum
+from vpp_object import VppObject
try:
text_type = unicode
except NameError:
@@ -133,3 +134,50 @@ class VppIpMPrefix():
self.gaddr == str(other.grp_address.ip6) and
self.saddr == str(other.src_address.ip6))
return NotImplemented
+
+
+class VppIpPuntPolicer(VppObject):
+ def __init__(self, test, policer_index, is_ip6=False):
+ self._test = test
+ self._policer_index = policer_index
+ self._is_ip6 = is_ip6
+
+ def add_vpp_config(self):
+ self._test.vapi.ip_punt_police(policer_index=self._policer_index,
+ is_ip6=self._is_ip6, is_add=True)
+
+ def remove_vpp_config(self):
+ self._test.vapi.ip_punt_police(policer_index=self._policer_index,
+ is_ip6=self._is_ip6, is_add=False)
+
+ def query_vpp_config(self):
+ NotImplemented
+
+
+class VppIpPuntRedirect(VppObject):
+ def __init__(self, test, rx_index, tx_index, nh_addr):
+ self._test = test
+ self._rx_index = rx_index
+ self._tx_index = tx_index
+ self._nh_addr = ip_address(nh_addr)
+
+ def encode(self):
+ return {"rx_sw_if_index": self._rx_index,
+ "tx_sw_if_index": self._tx_index, "nh": self._nh_addr}
+
+ def add_vpp_config(self):
+ self._test.vapi.ip_punt_redirect(punt=self.encode(), is_add=True)
+ self._test.registry.register(self, self._test.logger)
+
+ def remove_vpp_config(self):
+ self._test.vapi.ip_punt_redirect(punt=self.encode(), is_add=False)
+
+ def get_vpp_config(self):
+ is_ipv6 = True if self._nh_addr.version == 6 else False
+ return self._test.vapi.ip_punt_redirect_dump(
+ sw_if_index=self._rx_index, is_ipv6=is_ipv6)
+
+ def query_vpp_config(self):
+ if self.get_vpp_config():
+ return True
+ return False
diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py
index 56b01fdc0c9..d1a4eaf7fc6 100644
--- a/test/vpp_papi_provider.py
+++ b/test/vpp_papi_provider.py
@@ -49,8 +49,6 @@ defaultmapping = {
'classify_table_index': 4294967295, 'is_add': 1, },
'ip_mroute_add_del': {'is_add': 1, },
'ip_neighbor_add_del': {'is_add': 1, },
- 'ip_punt_police': {'is_add': 1, },
- 'ip_punt_redirect': {'is_add': 1, },
'ip_route_add_del': {'is_add': 1, },
'ipsec_interface_add_del_spd': {'is_add': 1, },
'ipsec_spd_add_del': {'is_add': 1, },
@@ -724,31 +722,6 @@ class VppPapiProvider(object):
return self.api(self.papi.sr_mpls_policy_del,
{'bsid': bsid})
- def ip_punt_police(self,
- policer_index,
- is_ip6=0,
- is_add=1):
- return self.api(self.papi.ip_punt_police,
- {'policer_index': policer_index,
- 'is_add': is_add,
- 'is_ip6': is_ip6})
-
- def ip_punt_redirect(self,
- rx_sw_if_index,
- tx_sw_if_index,
- address,
- is_add=1):
- return self.api(self.papi.ip_punt_redirect,
- {'punt': {'rx_sw_if_index': rx_sw_if_index,
- 'tx_sw_if_index': tx_sw_if_index,
- 'nh': address},
- 'is_add': is_add})
-
- def ip_punt_redirect_dump(self, sw_if_index, is_ipv6=0):
- return self.api(self.papi.ip_punt_redirect_dump,
- {'sw_if_index': sw_if_index,
- 'is_ipv6': is_ipv6})
-
def bier_table_add_del(self,
bti,
mpls_label,