Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 2 | |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 3 | import socket |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 4 | from util import ip4_range, reassemble4 |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 5 | import unittest |
| 6 | from framework import VppTestCase, VppTestRunner |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 7 | from template_bd import BridgeDomain |
| 8 | |
snaramre | 5d4b891 | 2019-12-13 23:39:35 +0000 | [diff] [blame] | 9 | from scapy.layers.l2 import Ether |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 10 | from scapy.packet import Raw, bind_layers |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 11 | from scapy.layers.inet import IP, UDP |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 12 | from scapy.layers.vxlan import VXLAN |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 13 | |
| 14 | import util |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 15 | from vpp_ip_route import VppIpRoute, VppRoutePath |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 16 | from vpp_vxlan_tunnel import VppVxlanTunnel |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 17 | from vpp_ip import INVALID_INDEX |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 18 | |
| 19 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 20 | class TestVxlan(BridgeDomain, VppTestCase): |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 21 | """ VXLAN Test Case """ |
| 22 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 23 | def __init__(self, *args): |
| 24 | BridgeDomain.__init__(self) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 25 | VppTestCase.__init__(self, *args) |
| 26 | |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 27 | def encapsulate(self, pkt, vni): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 28 | """ |
| 29 | Encapsulate the original payload frame by adding VXLAN header with its |
| 30 | UDP, IP and Ethernet fields |
| 31 | """ |
| 32 | return (Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) / |
| 33 | IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) / |
| 34 | UDP(sport=self.dport, dport=self.dport, chksum=0) / |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 35 | VXLAN(vni=vni, flags=self.flags) / |
| 36 | pkt) |
| 37 | |
Eyal Bari | cef1e2a | 2018-06-18 13:01:59 +0300 | [diff] [blame] | 38 | def ip_range(self, start, end): |
| 39 | """ range of remote ip's """ |
| 40 | return ip4_range(self.pg0.remote_ip4, start, end) |
| 41 | |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 42 | def encap_mcast(self, pkt, src_ip, src_mac, vni): |
| 43 | """ |
| 44 | Encapsulate the original payload frame by adding VXLAN header with its |
| 45 | UDP, IP and Ethernet fields |
| 46 | """ |
Eyal Bari | d81da8c | 2017-01-11 13:39:54 +0200 | [diff] [blame] | 47 | return (Ether(src=src_mac, dst=self.mcast_mac) / |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 48 | IP(src=src_ip, dst=self.mcast_ip4) / |
| 49 | UDP(sport=self.dport, dport=self.dport, chksum=0) / |
| 50 | VXLAN(vni=vni, flags=self.flags) / |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 51 | pkt) |
| 52 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 53 | def decapsulate(self, pkt): |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 54 | """ |
| 55 | Decapsulate the original payload frame by removing VXLAN header |
| 56 | """ |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 57 | # check if is set I flag |
| 58 | self.assertEqual(pkt[VXLAN].flags, int('0x8', 16)) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 59 | return pkt[VXLAN].payload |
| 60 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 61 | # Method for checking VXLAN encapsulation. |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 62 | # |
Eyal Bari | 6ae5ee7 | 2017-03-23 09:53:51 +0200 | [diff] [blame] | 63 | def check_encapsulation(self, pkt, vni, local_only=False, mcast_pkt=False): |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 64 | # TODO: add error messages |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 65 | # Verify source MAC is VPP_MAC and destination MAC is MY_MAC resolved |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 66 | # by VPP using ARP. |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 67 | self.assertEqual(pkt[Ether].src, self.pg0.local_mac) |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 68 | if not local_only: |
Eyal Bari | 6ae5ee7 | 2017-03-23 09:53:51 +0200 | [diff] [blame] | 69 | if not mcast_pkt: |
| 70 | self.assertEqual(pkt[Ether].dst, self.pg0.remote_mac) |
| 71 | else: |
| 72 | self.assertEqual(pkt[Ether].dst, type(self).mcast_mac) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 73 | # Verify VXLAN tunnel source IP is VPP_IP and destination IP is MY_IP. |
| 74 | self.assertEqual(pkt[IP].src, self.pg0.local_ip4) |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 75 | if not local_only: |
Eyal Bari | 6ae5ee7 | 2017-03-23 09:53:51 +0200 | [diff] [blame] | 76 | if not mcast_pkt: |
| 77 | self.assertEqual(pkt[IP].dst, self.pg0.remote_ip4) |
| 78 | else: |
| 79 | self.assertEqual(pkt[IP].dst, type(self).mcast_ip4) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 80 | # Verify UDP destination port is VXLAN 4789, source UDP port could be |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 81 | # arbitrary. |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 82 | self.assertEqual(pkt[UDP].dport, self.dport) |
Vladimir Isaev | 698eb87 | 2020-05-21 16:34:17 +0300 | [diff] [blame] | 83 | # Verify UDP checksum |
| 84 | self.assert_udp_checksum_valid(pkt) |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 85 | # Verify VNI |
| 86 | self.assertEqual(pkt[VXLAN].vni, vni) |
| 87 | |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 88 | @classmethod |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 89 | def create_vxlan_flood_test_bd(cls, vni, n_ucast_tunnels, port): |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 90 | # Create 10 ucast vxlan tunnels under bd |
| 91 | ip_range_start = 10 |
Eyal Bari | d81da8c | 2017-01-11 13:39:54 +0200 | [diff] [blame] | 92 | ip_range_end = ip_range_start + n_ucast_tunnels |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 93 | next_hop_address = cls.pg0.remote_ip4 |
| 94 | for dest_ip4 in ip4_range(next_hop_address, ip_range_start, |
| 95 | ip_range_end): |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 96 | # add host route so dest_ip4 will not be resolved |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 97 | rip = VppIpRoute(cls, dest_ip4, 32, |
| 98 | [VppRoutePath(next_hop_address, |
| 99 | INVALID_INDEX)], |
| 100 | register=False) |
| 101 | rip.add_vpp_config() |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 102 | |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 103 | r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4, |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 104 | src_port=port, dst_port=port, |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 105 | dst=dest_ip4, vni=vni) |
| 106 | r.add_vpp_config() |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 107 | cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni) |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 108 | |
| 109 | @classmethod |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 110 | def add_del_shared_mcast_dst_load(cls, port, is_add): |
Eyal Bari | 4bce290 | 2017-01-16 12:02:46 +0200 | [diff] [blame] | 111 | """ |
| 112 | add or del tunnels sharing the same mcast dst |
| 113 | to test vxlan ref_count mechanism |
| 114 | """ |
Gabriel Ganne | 7e665d6 | 2017-11-17 09:18:53 +0100 | [diff] [blame] | 115 | n_shared_dst_tunnels = 20 |
Eyal Bari | 4bce290 | 2017-01-16 12:02:46 +0200 | [diff] [blame] | 116 | vni_start = 10000 |
| 117 | vni_end = vni_start + n_shared_dst_tunnels |
| 118 | for vni in range(vni_start, vni_end): |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 119 | r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4, |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 120 | src_port=port, dst_port=port, |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 121 | dst=cls.mcast_ip4, mcast_sw_if_index=1, vni=vni) |
| 122 | if is_add: |
| 123 | r.add_vpp_config() |
| 124 | if r.sw_if_index == 0xffffffff: |
| 125 | raise ValueError("bad sw_if_index: ~0") |
| 126 | else: |
| 127 | r.remove_vpp_config() |
Eyal Bari | 4bce290 | 2017-01-16 12:02:46 +0200 | [diff] [blame] | 128 | |
| 129 | @classmethod |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 130 | def add_shared_mcast_dst_load(cls, port): |
| 131 | cls.add_del_shared_mcast_dst_load(port=port, is_add=1) |
Eyal Bari | 4bce290 | 2017-01-16 12:02:46 +0200 | [diff] [blame] | 132 | |
| 133 | @classmethod |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 134 | def del_shared_mcast_dst_load(cls, port): |
| 135 | cls.add_del_shared_mcast_dst_load(port=port, is_add=0) |
Eyal Bari | 4bce290 | 2017-01-16 12:02:46 +0200 | [diff] [blame] | 136 | |
| 137 | @classmethod |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 138 | def add_del_mcast_tunnels_load(cls, port, is_add): |
Eyal Bari | 4bce290 | 2017-01-16 12:02:46 +0200 | [diff] [blame] | 139 | """ |
| 140 | add or del tunnels to test vxlan stability |
| 141 | """ |
| 142 | n_distinct_dst_tunnels = 200 |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 143 | ip_range_start = 10 |
Eyal Bari | 4bce290 | 2017-01-16 12:02:46 +0200 | [diff] [blame] | 144 | ip_range_end = ip_range_start + n_distinct_dst_tunnels |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 145 | for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start, |
| 146 | ip_range_end): |
| 147 | vni = bytearray(socket.inet_pton(socket.AF_INET, dest_ip4))[3] |
| 148 | r = VppVxlanTunnel(cls, src=cls.pg0.local_ip4, |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 149 | src_port=port, dst_port=port, |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 150 | dst=dest_ip4, mcast_sw_if_index=1, vni=vni) |
| 151 | if is_add: |
| 152 | r.add_vpp_config() |
| 153 | else: |
| 154 | r.remove_vpp_config() |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 155 | |
| 156 | @classmethod |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 157 | def add_mcast_tunnels_load(cls, port): |
| 158 | cls.add_del_mcast_tunnels_load(port=port, is_add=1) |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 159 | |
| 160 | @classmethod |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 161 | def del_mcast_tunnels_load(cls, port): |
| 162 | cls.add_del_mcast_tunnels_load(port=port, is_add=0) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 163 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 164 | # Class method to start the VXLAN test case. |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 165 | # Overrides setUpClass method in VppTestCase class. |
| 166 | # Python try..except statement is used to ensure that the tear down of |
| 167 | # the class will be executed even if exception is raised. |
| 168 | # @param cls The class pointer. |
| 169 | @classmethod |
| 170 | def setUpClass(cls): |
| 171 | super(TestVxlan, cls).setUpClass() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 172 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 173 | try: |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 174 | cls.flags = 0x8 |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 175 | |
| 176 | # Create 2 pg interfaces. |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 177 | cls.create_pg_interfaces(range(4)) |
| 178 | for pg in cls.pg_interfaces: |
| 179 | pg.admin_up() |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 180 | |
| 181 | # Configure IPv4 addresses on VPP pg0. |
| 182 | cls.pg0.config_ip4() |
| 183 | |
| 184 | # Resolve MAC address for VPP's IP address on pg0. |
| 185 | cls.pg0.resolve_arp() |
| 186 | |
Eyal Bari | c4aaee1 | 2016-12-20 18:36:46 +0200 | [diff] [blame] | 187 | # Our Multicast address |
| 188 | cls.mcast_ip4 = '239.1.1.1' |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 189 | cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4) |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 190 | except Exception: |
Paul Vinciguerra | 2f15631 | 2020-05-02 22:34:40 -0400 | [diff] [blame] | 191 | cls.tearDownClass() |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 192 | raise |
| 193 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 194 | @classmethod |
| 195 | def tearDownClass(cls): |
| 196 | super(TestVxlan, cls).tearDownClass() |
| 197 | |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 198 | def setUp(self): |
| 199 | super(TestVxlan, self).setUp() |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 200 | |
| 201 | def createVxLANInterfaces(self, port=4789): |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 202 | # Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1 |
| 203 | # into BD. |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 204 | self.dport = port |
| 205 | |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 206 | self.single_tunnel_vni = 0x12345 |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 207 | self.single_tunnel_bd = 1 |
| 208 | r = VppVxlanTunnel(self, src=self.pg0.local_ip4, |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 209 | dst=self.pg0.remote_ip4, |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 210 | src_port=self.dport, dst_port=self.dport, |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 211 | vni=self.single_tunnel_vni) |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 212 | r.add_vpp_config() |
| 213 | self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, |
| 214 | bd_id=self.single_tunnel_bd) |
| 215 | self.vapi.sw_interface_set_l2_bridge( |
| 216 | rx_sw_if_index=self.pg1.sw_if_index, bd_id=self.single_tunnel_bd) |
| 217 | |
| 218 | # Setup vni 2 to test multicast flooding |
| 219 | self.n_ucast_tunnels = 10 |
| 220 | self.mcast_flood_bd = 2 |
| 221 | self.create_vxlan_flood_test_bd(self.mcast_flood_bd, |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 222 | self.n_ucast_tunnels, |
| 223 | self.dport) |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 224 | r = VppVxlanTunnel(self, src=self.pg0.local_ip4, dst=self.mcast_ip4, |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 225 | src_port=self.dport, dst_port=self.dport, |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 226 | mcast_sw_if_index=1, vni=self.mcast_flood_bd) |
| 227 | r.add_vpp_config() |
| 228 | self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, |
| 229 | bd_id=self.mcast_flood_bd) |
| 230 | self.vapi.sw_interface_set_l2_bridge( |
| 231 | rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.mcast_flood_bd) |
| 232 | |
| 233 | # Add and delete mcast tunnels to check stability |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 234 | self.add_shared_mcast_dst_load(self.dport) |
| 235 | self.add_mcast_tunnels_load(self.dport) |
| 236 | self.del_shared_mcast_dst_load(self.dport) |
| 237 | self.del_mcast_tunnels_load(self.dport) |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 238 | |
| 239 | # Setup vni 3 to test unicast flooding |
| 240 | self.ucast_flood_bd = 3 |
| 241 | self.create_vxlan_flood_test_bd(self.ucast_flood_bd, |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 242 | self.n_ucast_tunnels, |
| 243 | self.dport) |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 244 | self.vapi.sw_interface_set_l2_bridge( |
| 245 | rx_sw_if_index=self.pg3.sw_if_index, bd_id=self.ucast_flood_bd) |
| 246 | |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 247 | # Set scapy listen custom port for VxLAN |
| 248 | bind_layers(UDP, VXLAN, dport=self.dport) |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 249 | |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 250 | def encap_big_packet(self): |
Ole Troan | b3655e5 | 2018-08-16 22:08:49 +0200 | [diff] [blame] | 251 | self.vapi.sw_interface_set_mtu(self.pg0.sw_if_index, [1500, 0, 0, 0]) |
| 252 | |
| 253 | frame = (Ether(src='00:00:00:00:00:02', dst='00:00:00:00:00:01') / |
| 254 | IP(src='4.3.2.1', dst='1.2.3.4') / |
| 255 | UDP(sport=20000, dport=10000) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 256 | Raw(b'\xa5' * 1450)) |
Ole Troan | b3655e5 | 2018-08-16 22:08:49 +0200 | [diff] [blame] | 257 | |
| 258 | self.pg1.add_stream([frame]) |
| 259 | |
| 260 | self.pg0.enable_capture() |
| 261 | |
| 262 | self.pg_start() |
| 263 | |
| 264 | # Pick first received frame and check if it's correctly encapsulated. |
| 265 | out = self.pg0.get_capture(2) |
| 266 | ether = out[0] |
Ole Troan | 7f99183 | 2018-12-06 17:35:12 +0100 | [diff] [blame] | 267 | pkt = reassemble4(out) |
Ole Troan | b3655e5 | 2018-08-16 22:08:49 +0200 | [diff] [blame] | 268 | pkt = ether / pkt |
Neale Ranns | 91fd910 | 2020-04-03 07:46:28 +0000 | [diff] [blame] | 269 | self.check_encapsulation(pkt, self.single_tunnel_vni) |
Ole Troan | b3655e5 | 2018-08-16 22:08:49 +0200 | [diff] [blame] | 270 | |
| 271 | payload = self.decapsulate(pkt) |
| 272 | # TODO: Scapy bug? |
| 273 | # self.assert_eq_pkts(payload, frame) |
| 274 | |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 275 | """ |
| 276 | Tests with default port (4789) |
| 277 | """ |
| 278 | def test_decap(self): |
| 279 | """ Decapsulation test |
| 280 | from BridgeDoman |
| 281 | """ |
| 282 | self.createVxLANInterfaces() |
| 283 | super(TestVxlan, self).test_decap() |
| 284 | |
| 285 | def test_encap(self): |
| 286 | """ Encapsulation test |
| 287 | from BridgeDoman |
| 288 | """ |
| 289 | self.createVxLANInterfaces() |
| 290 | super(TestVxlan, self).test_encap() |
| 291 | |
| 292 | def test_encap_big_packet(self): |
| 293 | """ Encapsulation test send big frame from pg1 |
| 294 | Verify receipt of encapsulated frames on pg0 |
| 295 | """ |
| 296 | self.createVxLANInterfaces() |
| 297 | self.encap_big_packet() |
| 298 | |
| 299 | def test_ucast_flood(self): |
| 300 | """ Unicast flood test |
| 301 | from BridgeDoman |
| 302 | """ |
| 303 | self.createVxLANInterfaces() |
| 304 | super(TestVxlan, self).test_ucast_flood() |
| 305 | |
| 306 | def test_mcast_flood(self): |
| 307 | """ Multicast flood test |
| 308 | from BridgeDoman |
| 309 | """ |
| 310 | self.createVxLANInterfaces() |
| 311 | super(TestVxlan, self).test_mcast_flood() |
| 312 | |
| 313 | def test_mcast_rcv(self): |
| 314 | """ Multicast receive test |
| 315 | from BridgeDoman |
| 316 | """ |
| 317 | self.createVxLANInterfaces() |
| 318 | super(TestVxlan, self).test_mcast_rcv() |
| 319 | |
| 320 | """ |
| 321 | Tests with custom port |
| 322 | """ |
| 323 | def test_decap_custom_port(self): |
| 324 | """ Decapsulation test custom port |
| 325 | from BridgeDoman |
| 326 | """ |
| 327 | self.createVxLANInterfaces(1111) |
| 328 | super(TestVxlan, self).test_decap() |
| 329 | |
| 330 | def test_encap_custom_port(self): |
| 331 | """ Encapsulation test custom port |
| 332 | from BridgeDoman |
| 333 | """ |
| 334 | self.createVxLANInterfaces(1111) |
| 335 | super(TestVxlan, self).test_encap() |
| 336 | |
| 337 | def test_ucast_flood_custom_port(self): |
| 338 | """ Unicast flood test custom port |
| 339 | from BridgeDoman |
| 340 | """ |
| 341 | self.createVxLANInterfaces(1111) |
| 342 | super(TestVxlan, self).test_ucast_flood() |
| 343 | |
| 344 | def test_mcast_flood_custom_port(self): |
| 345 | """ Multicast flood test custom port |
| 346 | from BridgeDoman |
| 347 | """ |
| 348 | self.createVxLANInterfaces(1111) |
| 349 | super(TestVxlan, self).test_mcast_flood() |
| 350 | |
| 351 | def test_mcast_rcv_custom_port(self): |
| 352 | """ Multicast receive test custom port |
| 353 | from BridgeDoman |
| 354 | """ |
| 355 | self.createVxLANInterfaces(1111) |
| 356 | super(TestVxlan, self).test_mcast_rcv() |
| 357 | |
Klement Sekera | f62ae12 | 2016-10-11 11:47:09 +0200 | [diff] [blame] | 358 | # Method to define VPP actions before tear down of the test case. |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 359 | # Overrides tearDown method in VppTestCase class. |
| 360 | # @param self The object pointer. |
Artem Glazychev | 839dcc0 | 2020-12-01 02:39:21 +0700 | [diff] [blame] | 361 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 362 | def tearDown(self): |
| 363 | super(TestVxlan, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 364 | |
| 365 | def show_commands_at_teardown(self): |
| 366 | self.logger.info(self.vapi.cli("show bridge-domain 1 detail")) |
| 367 | self.logger.info(self.vapi.cli("show bridge-domain 2 detail")) |
| 368 | self.logger.info(self.vapi.cli("show bridge-domain 3 detail")) |
| 369 | self.logger.info(self.vapi.cli("show vxlan tunnel")) |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 370 | |
Matej Klotton | deb6984 | 2016-12-09 15:05:46 +0100 | [diff] [blame] | 371 | |
Neale Ranns | 1b5ca98 | 2020-12-16 13:06:58 +0000 | [diff] [blame] | 372 | class TestVxlan2(VppTestCase): |
| 373 | """ VXLAN Test Case """ |
| 374 | def setUp(self): |
| 375 | super(TestVxlan2, self).setUp() |
| 376 | |
| 377 | # Create 2 pg interfaces. |
| 378 | self.create_pg_interfaces(range(4)) |
| 379 | for pg in self.pg_interfaces: |
| 380 | pg.admin_up() |
| 381 | |
| 382 | # Configure IPv4 addresses on VPP pg0. |
| 383 | self.pg0.config_ip4() |
| 384 | self.pg0.resolve_arp() |
| 385 | |
| 386 | def tearDown(self): |
| 387 | super(TestVxlan2, self).tearDown() |
| 388 | |
| 389 | def test_xconnect(self): |
| 390 | """ VXLAN source address not local """ |
| 391 | |
| 392 | # |
| 393 | # test the broken configuration of a VXLAN tunnel whose |
| 394 | # source address is not local ot the box. packets sent |
| 395 | # through the tunnel should be dropped |
| 396 | # |
| 397 | t = VppVxlanTunnel(self, |
| 398 | src="10.0.0.5", |
| 399 | dst=self.pg0.local_ip4, |
| 400 | vni=1000) |
| 401 | t.add_vpp_config() |
| 402 | t.admin_up() |
| 403 | |
| 404 | self.vapi.sw_interface_set_l2_xconnect(t.sw_if_index, |
| 405 | self.pg1.sw_if_index, |
| 406 | enable=1) |
| 407 | self.vapi.sw_interface_set_l2_xconnect(self.pg1.sw_if_index, |
| 408 | t.sw_if_index, |
| 409 | enable=1) |
| 410 | |
| 411 | p = (Ether(src="00:11:22:33:44:55", |
| 412 | dst="00:00:00:11:22:33") / |
| 413 | IP(src="4.3.2.1", dst="1.2.3.4") / |
| 414 | UDP(sport=20000, dport=10000) / |
| 415 | Raw(b'\xa5' * 1450)) |
| 416 | |
| 417 | rx = self.send_and_assert_no_replies(self.pg1, [p]) |
| 418 | |
| 419 | |
Damjan Marion | f56b77a | 2016-10-03 19:44:57 +0200 | [diff] [blame] | 420 | if __name__ == '__main__': |
| 421 | unittest.main(testRunner=VppTestRunner) |