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