diff options
author | Jakub Grajciar <jgrajcia@cisco.com> | 2020-03-02 13:55:31 +0100 |
---|---|---|
committer | Jakub Grajciar <jgrajcia@cisco.com> | 2020-03-16 09:18:46 +0000 |
commit | 7c0eb56f40b3ccf8acd8f04e208aa50231aebeba (patch) | |
tree | 3df2939bf739d46eb6cb42767e5c402c3e0eac86 /test | |
parent | cd5a4a035c0c7a7ca9f915bee83abde085c05ad7 (diff) |
vxlan: vxlan/vxlan.api API cleanup
Use consistent API types.
Type: fix
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: I7f6f37ec6eed780322e2488d6eb0f5681945ba09
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/test_span.py | 8 | ||||
-rw-r--r-- | test/test_vxlan.py | 118 | ||||
-rw-r--r-- | test/test_vxlan6.py | 73 | ||||
-rw-r--r-- | test/vpp_vxlan_tunnel.py | 65 |
4 files changed, 172 insertions, 92 deletions
diff --git a/test/test_span.py b/test/test_span.py index 7d58bdfebd2..ecefe153706 100644 --- a/test/test_span.py +++ b/test/test_span.py @@ -11,6 +11,7 @@ from framework import VppTestCase, VppTestRunner from util import Host, ppp from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint, VppDot1ADSubint from vpp_gre_interface import VppGreInterface +from vpp_vxlan_tunnel import VppVxlanTunnel from collections import namedtuple from vpp_papi import VppEnum @@ -53,12 +54,11 @@ class TestSpan(VppTestCase): i.config_ip4() i.resolve_arp() - cls.vxlan = cls.vapi.vxlan_add_del_tunnel( - src_address=cls.pg2.local_ip4n, dst_address=cls.pg2.remote_ip4n, - is_add=1, vni=1111) - def setUp(self): super(TestSpan, self).setUp() + self.vxlan = VppVxlanTunnel(self, src=self.pg2.local_ip4, + dst=self.pg2.remote_ip4, vni=1111) + self.vxlan.add_vpp_config() self.reset_packet_infos() def tearDown(self): diff --git a/test/test_vxlan.py b/test/test_vxlan.py index 7613054882a..910611c63cc 100644 --- a/test/test_vxlan.py +++ b/test/test_vxlan.py @@ -12,6 +12,7 @@ from scapy.layers.inet import IP, UDP from scapy.layers.vxlan import VXLAN from scapy.utils import atol from vpp_ip_route import VppIpRoute, VppRoutePath +from vpp_vxlan_tunnel import VppVxlanTunnel from vpp_ip import INVALID_INDEX @@ -98,8 +99,9 @@ class TestVxlan(BridgeDomain, VppTestCase): rip.add_vpp_config() dest_ip4n = socket.inet_pton(socket.AF_INET, dest_ip4) - r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n, - dst_address=dest_ip4n, vni=vni) + r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4, + dst=dest_ip4, vni=vni) + r.add_vpp_config() cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni) @classmethod @@ -112,12 +114,14 @@ class TestVxlan(BridgeDomain, VppTestCase): vni_start = 10000 vni_end = vni_start + n_shared_dst_tunnels for vni in range(vni_start, vni_end): - r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n, - dst_address=cls.mcast_ip4n, - mcast_sw_if_index=1, - is_add=is_add, vni=vni) - if r.sw_if_index == 0xffffffff: - raise ValueError("bad sw_if_index: ~0") + r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4, + dst=cls.mcast_ip4, mcast_sw_if_index=1, vni=vni) + if is_add: + r.add_vpp_config() + if r.sw_if_index == 0xffffffff: + raise ValueError("bad sw_if_index: ~0") + else: + r.remove_vpp_config() @classmethod def add_shared_mcast_dst_load(cls): @@ -135,13 +139,15 @@ class TestVxlan(BridgeDomain, VppTestCase): n_distinct_dst_tunnels = 200 ip_range_start = 10 ip_range_end = ip_range_start + n_distinct_dst_tunnels - for dest_ip4n in ip4n_range(cls.mcast_ip4n, ip_range_start, - ip_range_end): - vni = bytearray(dest_ip4n)[3] - cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n, - dst_address=dest_ip4n, - mcast_sw_if_index=1, is_add=is_add, - vni=vni) + for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start, + ip_range_end): + vni = bytearray(socket.inet_pton(socket.AF_INET, dest_ip4))[3] + r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4, + dst=dest_ip4, mcast_sw_if_index=1, vni=vni) + if is_add: + r.add_vpp_config() + else: + r.remove_vpp_config() @classmethod def add_mcast_tunnels_load(cls): @@ -182,43 +188,6 @@ class TestVxlan(BridgeDomain, VppTestCase): cls.mcast_mac = "01:00:5e:%02x:%02x:%02x" % ( (iplong >> 16) & 0x7F, (iplong >> 8) & 0xFF, iplong & 0xFF) - # Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1 - # into BD. - cls.single_tunnel_bd = 1 - r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n, - dst_address=cls.pg0.remote_ip4n, - vni=cls.single_tunnel_bd) - cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, - bd_id=cls.single_tunnel_bd) - cls.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.single_tunnel_bd) - - # Setup vni 2 to test multicast flooding - cls.n_ucast_tunnels = 10 - cls.mcast_flood_bd = 2 - cls.create_vxlan_flood_test_bd(cls.mcast_flood_bd, - cls.n_ucast_tunnels) - r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip4n, - dst_address=cls.mcast_ip4n, - mcast_sw_if_index=1, - vni=cls.mcast_flood_bd) - cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, - bd_id=cls.mcast_flood_bd) - cls.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=cls.pg2.sw_if_index, bd_id=cls.mcast_flood_bd) - - # Add and delete mcast tunnels to check stability - cls.add_shared_mcast_dst_load() - cls.add_mcast_tunnels_load() - cls.del_shared_mcast_dst_load() - cls.del_mcast_tunnels_load() - - # Setup vni 3 to test unicast flooding - cls.ucast_flood_bd = 3 - cls.create_vxlan_flood_test_bd(cls.ucast_flood_bd, - cls.n_ucast_tunnels) - cls.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=cls.pg3.sw_if_index, bd_id=cls.ucast_flood_bd) except Exception: super(TestVxlan, cls).tearDownClass() raise @@ -227,6 +196,51 @@ class TestVxlan(BridgeDomain, VppTestCase): def tearDownClass(cls): super(TestVxlan, cls).tearDownClass() + def setUp(self): + super(TestVxlan, self).setUp() + # Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1 + # into BD. + self.single_tunnel_bd = 1 + r = VppVxlanTunnel(self, src=self.pg0.local_ip4, + dst=self.pg0.remote_ip4, vni=self.single_tunnel_bd) + r.add_vpp_config() + self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, + bd_id=self.single_tunnel_bd) + self.vapi.sw_interface_set_l2_bridge( + rx_sw_if_index=self.pg1.sw_if_index, bd_id=self.single_tunnel_bd) + + # Setup vni 2 to test multicast flooding + self.n_ucast_tunnels = 10 + self.mcast_flood_bd = 2 + self.create_vxlan_flood_test_bd(self.mcast_flood_bd, + self.n_ucast_tunnels) + r = VppVxlanTunnel(self, src=self.pg0.local_ip4, dst=self.mcast_ip4, + mcast_sw_if_index=1, vni=self.mcast_flood_bd) + r.add_vpp_config() + self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, + bd_id=self.mcast_flood_bd) + self.vapi.sw_interface_set_l2_bridge( + rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.mcast_flood_bd) + + # Add and delete mcast tunnels to check stability + self.add_shared_mcast_dst_load() + self.add_mcast_tunnels_load() + self.del_shared_mcast_dst_load() + self.del_mcast_tunnels_load() + + # Setup vni 3 to test unicast flooding + self.ucast_flood_bd = 3 + self.create_vxlan_flood_test_bd(self.ucast_flood_bd, + self.n_ucast_tunnels) + self.vapi.sw_interface_set_l2_bridge( + rx_sw_if_index=self.pg3.sw_if_index, bd_id=self.ucast_flood_bd) + + def test_decap(self): + """ Decapsulation test + from BridgeDoman + """ + super(TestVxlan, self).test_decap() + def test_encap_big_packet(self): """ Encapsulation test send big frame from pg1 Verify receipt of encapsulated frames on pg0 diff --git a/test/test_vxlan6.py b/test/test_vxlan6.py index b1fda508394..53658433ef7 100644 --- a/test/test_vxlan6.py +++ b/test/test_vxlan6.py @@ -10,6 +10,7 @@ from scapy.layers.inet6 import IPv6, UDP from scapy.layers.vxlan import VXLAN from scapy.utils import atol from vpp_ip_route import VppIpRoute, VppRoutePath +from vpp_vxlan_tunnel import VppVxlanTunnel from vpp_ip import INVALID_INDEX @@ -88,15 +89,14 @@ class TestVxlan6(BridgeDomain, VppTestCase): start = 10 end = start + n_ucast_tunnels for dest_ip6 in cls.ip_range(start, end): - dest_ip6n = socket.inet_pton(socket.AF_INET6, dest_ip6) # add host route so dest ip will not be resolved rip = VppIpRoute(cls, dest_ip6, 128, [VppRoutePath(cls.pg0.remote_ip6, INVALID_INDEX)], register=False) rip.add_vpp_config() - r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip6n, - dst_address=dest_ip6n, is_ipv6=1, - vni=vni) + r = VppVxlanTunnel(cls, src=cls.pg0.local_ip6, + dst=dest_ip6, vni=vni) + r.add_vpp_config() cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni) @classmethod @@ -135,38 +135,6 @@ class TestVxlan6(BridgeDomain, VppTestCase): cls.mcast_ip6n = socket.inet_pton(socket.AF_INET6, cls.mcast_ip6) cls.mcast_mac = "33:33:00:00:00:%02x" % (1) - # Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1 - # into BD. - cls.single_tunnel_bd = 1 - r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip6n, - dst_address=cls.pg0.remote_ip6n, - is_ipv6=1, - vni=cls.single_tunnel_bd) - cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, - bd_id=cls.single_tunnel_bd) - cls.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=cls.pg1.sw_if_index, bd_id=cls.single_tunnel_bd) - - # Setup vni 2 to test multicast flooding - cls.n_ucast_tunnels = 10 - cls.mcast_flood_bd = 2 - cls.create_vxlan_flood_test_bd(cls.mcast_flood_bd, - cls.n_ucast_tunnels) - r = cls.vapi.vxlan_add_del_tunnel(src_address=cls.pg0.local_ip6n, - dst_address=cls.mcast_ip6n, - mcast_sw_if_index=1, is_ipv6=1, - vni=cls.mcast_flood_bd) - cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, - bd_id=cls.mcast_flood_bd) - cls.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=cls.pg2.sw_if_index, bd_id=cls.mcast_flood_bd) - - # Setup vni 3 to test unicast flooding - cls.ucast_flood_bd = 3 - cls.create_vxlan_flood_test_bd(cls.ucast_flood_bd, - cls.n_ucast_tunnels) - cls.vapi.sw_interface_set_l2_bridge( - rx_sw_if_index=cls.pg3.sw_if_index, bd_id=cls.ucast_flood_bd) except Exception: super(TestVxlan6, cls).tearDownClass() raise @@ -175,6 +143,39 @@ class TestVxlan6(BridgeDomain, VppTestCase): def tearDownClass(cls): super(TestVxlan6, cls).tearDownClass() + def setUp(self): + super(TestVxlan6, self).setUp() + # Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1 + # into BD. + self.single_tunnel_bd = 1 + r = VppVxlanTunnel(self, src=self.pg0.local_ip6, + dst=self.pg0.remote_ip6, vni=self.single_tunnel_bd) + r.add_vpp_config() + self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, + bd_id=self.single_tunnel_bd) + self.vapi.sw_interface_set_l2_bridge( + rx_sw_if_index=self.pg1.sw_if_index, bd_id=self.single_tunnel_bd) + + # Setup vni 2 to test multicast flooding + self.n_ucast_tunnels = 10 + self.mcast_flood_bd = 2 + self.create_vxlan_flood_test_bd(self.mcast_flood_bd, + self.n_ucast_tunnels) + r = VppVxlanTunnel(self, src=self.pg0.local_ip6, dst=self.mcast_ip6, + mcast_sw_if_index=1, vni=self.mcast_flood_bd) + r.add_vpp_config() + self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, + bd_id=self.mcast_flood_bd) + self.vapi.sw_interface_set_l2_bridge( + rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.mcast_flood_bd) + + # Setup vni 3 to test unicast flooding + self.ucast_flood_bd = 3 + self.create_vxlan_flood_test_bd(self.ucast_flood_bd, + self.n_ucast_tunnels) + self.vapi.sw_interface_set_l2_bridge( + rx_sw_if_index=self.pg3.sw_if_index, bd_id=self.ucast_flood_bd) + # Method to define VPP actions before tear down of the test case. # Overrides tearDown method in VppTestCase class. # @param self The object pointer. diff --git a/test/vpp_vxlan_tunnel.py b/test/vpp_vxlan_tunnel.py new file mode 100644 index 00000000000..0f6ecb771f5 --- /dev/null +++ b/test/vpp_vxlan_tunnel.py @@ -0,0 +1,65 @@ +from vpp_interface import VppInterface +from vpp_papi import VppEnum + + +INDEX_INVALID = 0xffffffff + + +def find_vxlan_tunnel(test, src, dst, vni): + ts = test.vapi.vxlan_tunnel_dump(INDEX_INVALID) + for t in ts: + if src == str(t.src_address) and \ + dst == str(t.dst_address) and \ + t.vni == vni: + return t.sw_if_index + return INDEX_INVALID + + +class VppVxlanTunnel(VppInterface): + """ + VPP VXLAN interface + """ + + def __init__(self, test, src, dst, vni, mcast_itf=None, + mcast_sw_if_index=INDEX_INVALID, + decap_next_index=INDEX_INVALID, + encap_vrf_id=None, instance=0xffffffff): + """ Create VXLAN Tunnel interface """ + super(VppVxlanTunnel, self).__init__(test) + self.src = src + self.dst = dst + self.vni = vni + self.mcast_itf = mcast_itf + self.mcast_sw_if_index = mcast_sw_if_index + self.encap_vrf_id = encap_vrf_id + self.decap_next_index = decap_next_index + self.instance = instance + + if (self.mcast_itf): + self.mcast_sw_if_index = self.mcast_itf.sw_if_index + + def add_vpp_config(self): + reply = self.test.vapi.vxlan_add_del_tunnel( + is_add=1, src_address=self.src, dst_address=self.dst, vni=self.vni, + mcast_sw_if_index=self.mcast_sw_if_index, + encap_vrf_id=self.encap_vrf_id, + instance=self.instance, decap_next_index=self.decap_next_index) + self.set_sw_if_index(reply.sw_if_index) + self._test.registry.register(self, self._test.logger) + + def remove_vpp_config(self): + self.test.vapi.vxlan_add_del_tunnel( + is_add=0, src_address=self.src, dst_address=self.dst, vni=self.vni, + mcast_sw_if_index=self.mcast_sw_if_index, + encap_vrf_id=self.encap_vrf_id, instance=self.instance, + decap_next_index=self.decap_next_index) + + def query_vpp_config(self): + return (INDEX_INVALID != find_vxlan_tunnel(self._test, + self.src, + self.dst, + self.vni)) + + def object_id(self): + return "vxlan-%d-%d-%s-%s" % (self.sw_if_index, self.vni, + self.src, self.dst) |