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