Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | import unittest |
| 3 | from ipaddress import ip_address, ip_interface |
| 4 | from vpp_qemu_utils import ( |
| 5 | create_namespace, |
| 6 | delete_namespace, |
| 7 | create_host_interface, |
| 8 | delete_host_interfaces, |
| 9 | set_interface_mtu, |
| 10 | disable_interface_gso, |
| 11 | add_namespace_route, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 12 | libmemif_test_app, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 13 | ) |
| 14 | from vpp_iperf import start_iperf, stop_iperf |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 15 | from framework import VppTestCase |
| 16 | from asfframework import VppTestRunner, tag_fixme_debian11, is_distro_debian11 |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 17 | from config import config |
| 18 | from vpp_papi import VppEnum |
| 19 | import time |
| 20 | import sys |
| 21 | from vm_test_config import test_config |
| 22 | |
| 23 | # |
| 24 | # Tests for: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 25 | # - tapv2, tunv2, af_packet_v2/v3 & memif interfaces. |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 26 | # - reads test config from the file vm_test_config.py |
| 27 | # - Uses iPerf to send TCP/IP streams to VPP |
| 28 | # - VPP ingress interface runs the iperf client |
| 29 | # - VPP egress interface runs the iperf server |
| 30 | # - Runs tests specified in the vm_test_config module and verifies that: |
| 31 | # - TCP over IPv4 and IPv6 is enabled correctly for Bridged and Routed topologies. |
| 32 | # sending jumbo frames (9000/9001 MTUs) with GSO/GRO is enabled correctly. |
| 33 | # sending VPP buffer-sized frames(2048 MTU) with GSO/GRO is enabled correctly. |
| 34 | # sending standard frames (1500 MTU) with GSO/GRO is enabled correctly. |
| 35 | # sending smaller frames (512 MTU) with GSO/GRO is enabled correctly for IPv4 |
| 36 | # sending odd sized frames (9001, 2049 MTU) with GSO/GRO is enabled correctly. |
| 37 | # |
| 38 | |
| 39 | |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 40 | class TestSelector: |
| 41 | """Selects specified test(s) from vm_test_config to run |
| 42 | |
| 43 | The selected_test field specifies a comma separated or range(s) of |
| 44 | tests to run (default='' i.e all_tests) e.g. setting the selected_tests |
| 45 | attribute to "1,3-4,19-23" runs tests with ID's 1, 3, 4, 19, 20, 21, |
| 46 | 22 & 23 from the spec file vm_test_config |
| 47 | """ |
| 48 | |
| 49 | def __init__(self, selected_tests="") -> None: |
| 50 | self.selected_tests = selected_tests |
| 51 | |
| 52 | def filter_tests(self, test): |
| 53 | """Works with the filter fn. to include only selected tests.""" |
| 54 | |
| 55 | if self.selected_tests: |
| 56 | selection = self.selected_tests |
| 57 | else: |
| 58 | selection = test_config["tests_to_run"] |
| 59 | |
| 60 | if not selection or selection == " ": |
| 61 | return True |
| 62 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 63 | test_ids_to_run = [] |
| 64 | for test_id in selection.split(","): |
| 65 | if "-" in test_id.strip(): |
| 66 | start, end = map(int, test_id.split("-")) |
| 67 | test_ids_to_run.extend(list(range(start, end + 1))) |
| 68 | elif test_id.strip(): |
| 69 | test_ids_to_run.append(int(test_id)) |
| 70 | return test["id"] in test_ids_to_run |
| 71 | |
| 72 | |
| 73 | # Test Config variables |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 74 | af_packet_config = test_config["af_packet"] |
| 75 | layer2 = test_config["L2"] |
| 76 | layer3 = test_config["L3"] |
| 77 | |
| 78 | |
| 79 | def create_test(test_name, test, ip_version, mtu): |
| 80 | """Create and return a unittest method for a test.""" |
| 81 | |
Andrew Yourtchenko | 9ba6dcf | 2023-06-20 14:52:08 +0000 | [diff] [blame] | 82 | @unittest.skipIf( |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 83 | is_distro_debian11, "FIXME intermittent test failures on debian11 distro" |
| 84 | ) |
| 85 | @unittest.skipIf( |
Andrew Yourtchenko | 9ba6dcf | 2023-06-20 14:52:08 +0000 | [diff] [blame] | 86 | config.skip_netns_tests, "netns not available or disabled from cli" |
| 87 | ) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 88 | def test_func(self): |
| 89 | self.logger.debug(f"Starting unittest:{test_name}") |
| 90 | self.setUpTestToplogy(test=test, ip_version=ip_version) |
| 91 | result = self.set_interfaces_mtu( |
| 92 | mtu=mtu, |
| 93 | ip_version=ip_version, |
| 94 | vpp_interfaces=self.vpp_interfaces, |
| 95 | linux_interfaces=self.linux_interfaces, |
| 96 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 97 | if "memif" in self.if_types: |
| 98 | self.logger.debug("Starting libmemif test_app for memif test") |
| 99 | self.memif_process = libmemif_test_app( |
| 100 | memif_sock_path=self.get_memif_sock_path(), logger=self.logger |
| 101 | ) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 102 | if result is True: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 103 | # Start an instance of an iperf server using |
| 104 | # a unique port. Save the iperf cmdline for |
| 105 | # terminating the iperf_server process after the test. |
| 106 | self.iperf_cmd = start_iperf( |
| 107 | ip_version=6, |
| 108 | client_ns=self.client_namespace, |
| 109 | server_ns=self.server_namespace, |
| 110 | server_only=True, |
| 111 | server_args=f"-p {self.iperf_port}", |
| 112 | logger=self.logger, |
| 113 | ) |
| 114 | # Send traffic between iperf client & server |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 115 | self.assertTrue( |
| 116 | start_iperf( |
| 117 | ip_version=ip_version, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 118 | client_ns=self.client_namespace, |
| 119 | server_ns=self.server_namespace, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 120 | server_ipv4_address=self.server_ip4_address, |
| 121 | server_ipv6_address=self.server_ip6_address, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 122 | client_args=f"-p {self.iperf_port}", |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 123 | client_only=True, |
| 124 | duration=2, |
| 125 | logger=self.logger, |
| 126 | ) |
| 127 | ) |
| 128 | else: |
Klement Sekera | ceed1e3 | 2024-03-08 10:24:46 +0100 | [diff] [blame] | 129 | return unittest.skip( |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 130 | f"Skipping test:{test_name} as mtu:{mtu} is " |
| 131 | f"invalid for TCP/IPv{ip_version}" |
| 132 | ) |
| 133 | |
| 134 | test_func.__name__ = test_name |
| 135 | return test_func |
| 136 | |
| 137 | |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 138 | def generate_vpp_interface_tests(tests, test_class): |
| 139 | """Generate unittests for testing vpp interfaces |
| 140 | |
| 141 | Generates unittests from test spec. and sets them as attributes |
| 142 | to the test_class. |
| 143 | Args: |
| 144 | tests : list of test specs from vm_test_config['tests'] |
| 145 | test_class : the name of the test class to which the |
| 146 | generated tests are set as attributes. |
| 147 | """ |
| 148 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 149 | for test in tests: |
| 150 | for ip_version in test_config["ip_versions"]: |
| 151 | for mtu in test_config["mtus"]: |
| 152 | test_name = ( |
| 153 | f"test_id_{test['id']}_" |
| 154 | + f"client_{test['client_if_type']}" |
| 155 | + f"_v{test['client_if_version']}_" |
| 156 | + f"gso_{test.get('client_if_gso', 0)}_" |
| 157 | + f"gro_{test.get('client_if_gro', 0)}_" |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 158 | + f"checksum_{test.get('client_if_checksum_offload', 0)}_" |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 159 | + f"to_server_{test['server_if_type']}" |
| 160 | + f"_v{test['server_if_version']}_" |
| 161 | + f"gso_{test.get('server_if_gso', 0)}_" |
| 162 | + f"gro_{test.get('server_if_gro', 0)}_" |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 163 | + f"checksum_{test.get('server_if_checksum_offload', 0)}_" |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 164 | + f"mtu_{mtu}_mode_{test['x_connect_mode']}_" |
| 165 | + f"tcp_ipv{ip_version}" |
| 166 | ) |
| 167 | test_func = create_test( |
| 168 | test_name=test_name, test=test, ip_version=ip_version, mtu=mtu |
| 169 | ) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 170 | setattr(test_class, test_name, test_func) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 171 | |
| 172 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 173 | @tag_fixme_debian11 |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 174 | class TestVPPInterfacesQemu: |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 175 | """Test VPP interfaces inside a QEMU VM for IPv4/v6. |
| 176 | |
| 177 | Test Setup: |
| 178 | Linux_ns1--iperfClient--host-int1--vpp-af_packet-int1--VPP-BD |
| 179 | --vppaf_packet_int2--host-int2--iperfServer--Linux_ns2 |
| 180 | """ |
| 181 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 182 | def setUpTestToplogy(self, test, ip_version): |
| 183 | """Setup the test topology. |
| 184 | |
| 185 | 1. Create Linux Namespaces for iPerf Client & Server. |
| 186 | 2. Create VPP iPerf client and server virtual interfaces. |
| 187 | 3. Enable desired vif features such as GSO & GRO. |
| 188 | 3. Cross-Connect interfaces in VPP using L2 or L3. |
| 189 | """ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 190 | |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 191 | # Need to support multiple interface types as the memif interface |
| 192 | # in VPP is connected to the iPerf client & server by x-connecting |
| 193 | # to a tap interface in their respective namespaces. |
| 194 | client_if_types = test["client_if_type"].split(",") |
| 195 | server_if_types = test["server_if_type"].split(",") |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 196 | client_if_version = test["client_if_version"] |
| 197 | server_if_version = test["server_if_version"] |
| 198 | x_connect_mode = test["x_connect_mode"] |
| 199 | # server ip4/ip6 addresses required by iperf client |
| 200 | server_ip4_prefix = ( |
| 201 | layer2["server_ip4_prefix"] |
| 202 | if x_connect_mode == "L2" |
| 203 | else layer3["server_ip4_prefix"] |
| 204 | ) |
| 205 | server_ip6_prefix = ( |
| 206 | layer2["server_ip6_prefix"] |
| 207 | if x_connect_mode == "L2" |
| 208 | else layer3["server_ip6_prefix"] |
| 209 | ) |
| 210 | self.server_ip4_address = str(ip_interface(server_ip4_prefix).ip) |
| 211 | self.server_ip6_address = str(ip_interface(server_ip6_prefix).ip) |
| 212 | # next-hop IP address on VPP for routing from client & server namespaces |
| 213 | vpp_client_prefix = ( |
| 214 | layer3["vpp_client_ip4_prefix"] |
| 215 | if ip_version == 4 |
| 216 | else layer3["vpp_client_ip6_prefix"] |
| 217 | ) |
| 218 | vpp_client_nexthop = str(ip_interface(vpp_client_prefix).ip) |
| 219 | vpp_server_prefix = ( |
| 220 | layer3["vpp_server_ip4_prefix"] |
| 221 | if ip_version == 4 |
| 222 | else layer3["vpp_server_ip6_prefix"] |
| 223 | ) |
| 224 | vpp_server_nexthop = str(ip_interface(vpp_server_prefix).ip) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 225 | # Create unique namespaces for iperf client & iperf server to |
| 226 | # prevent conflicts when TEST_JOBS > 1 |
| 227 | self.client_namespace = test_config["client_namespace"] + str(test["id"]) |
| 228 | self.server_namespace = test_config["server_namespace"] + str(test["id"]) |
| 229 | create_namespace([self.client_namespace, self.server_namespace]) |
| 230 | # Set a unique iPerf port for parallel server and client runs |
| 231 | self.iperf_port = 5000 + test["id"] |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 232 | # IPerf client & server ingress/egress interface indexes in VPP |
| 233 | self.tap_interfaces = [] |
| 234 | self.memif_interfaces = [] |
| 235 | self.ingress_if_idxes = [] |
| 236 | self.egress_if_idxes = [] |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 237 | self.vpp_interfaces = [] |
| 238 | self.linux_interfaces = [] |
| 239 | enable_client_if_gso = test.get("client_if_gso", 0) |
| 240 | enable_server_if_gso = test.get("server_if_gso", 0) |
| 241 | enable_client_if_gro = test.get("client_if_gro", 0) |
| 242 | enable_server_if_gro = test.get("server_if_gro", 0) |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 243 | enable_client_if_checksum_offload = test.get("client_if_checksum_offload", 0) |
| 244 | enable_server_if_checksum_offload = test.get("server_if_checksum_offload", 0) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 245 | |
| 246 | # Create unique host interfaces in Linux and VPP for connecting to iperf |
| 247 | # client & iperf server to prevent conflicts when TEST_JOBS > 1 |
| 248 | self.iprf_client_host_interface_on_linux = af_packet_config[ |
| 249 | "iprf_client_interface_on_linux" |
| 250 | ] + str(test["id"]) |
| 251 | self.iprf_client_host_interface_on_vpp = af_packet_config[ |
| 252 | "iprf_client_interface_on_vpp" |
| 253 | ] + str(test["id"]) |
| 254 | self.iprf_server_host_interface_on_linux = af_packet_config[ |
| 255 | "iprf_server_interface_on_linux" |
| 256 | ] + str(test["id"]) |
| 257 | self.iprf_server_host_interface_on_vpp = af_packet_config[ |
| 258 | "iprf_server_interface_on_vpp" |
| 259 | ] + str(test["id"]) |
| 260 | # Handle client interface types |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 261 | for client_if_type in client_if_types: |
| 262 | if client_if_type == "af_packet": |
| 263 | create_host_interface( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 264 | self.iprf_client_host_interface_on_linux, |
| 265 | self.iprf_client_host_interface_on_vpp, |
| 266 | self.client_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 267 | layer2["client_ip4_prefix"] |
| 268 | if x_connect_mode == "L2" |
| 269 | else layer3["client_ip4_prefix"], |
| 270 | layer2["client_ip6_prefix"] |
| 271 | if x_connect_mode == "L2" |
| 272 | else layer3["client_ip6_prefix"], |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 273 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 274 | self.ingress_if_idx = self.create_af_packet( |
| 275 | version=client_if_version, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 276 | host_if_name=self.iprf_client_host_interface_on_vpp, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 277 | enable_gso=enable_client_if_gso, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 278 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 279 | self.ingress_if_idxes.append(self.ingress_if_idx) |
| 280 | self.vpp_interfaces.append(self.ingress_if_idx) |
| 281 | self.linux_interfaces.append( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 282 | ["", self.iprf_client_host_interface_on_vpp] |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 283 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 284 | self.linux_interfaces.append( |
| 285 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 286 | self.client_namespace, |
| 287 | self.iprf_client_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 288 | ] |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 289 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 290 | if enable_client_if_gso == 0: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 291 | disable_interface_gso("", self.iprf_client_host_interface_on_vpp) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 292 | disable_interface_gso( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 293 | self.client_namespace, |
| 294 | self.iprf_client_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 295 | ) |
| 296 | elif client_if_type == "tap" or client_if_type == "tun": |
| 297 | self.ingress_if_idx = self.create_tap_tun( |
| 298 | id=101, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 299 | host_namespace=self.client_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 300 | ip_version=ip_version, |
| 301 | host_ip4_prefix=layer2["client_ip4_prefix"] |
| 302 | if x_connect_mode == "L2" |
| 303 | else layer3["client_ip4_prefix"], |
| 304 | host_ip6_prefix=layer2["client_ip6_prefix"] |
| 305 | if x_connect_mode == "L2" |
| 306 | else layer3["client_ip6_prefix"], |
| 307 | host_ip4_gw=vpp_client_nexthop |
| 308 | if x_connect_mode == "L3" and ip_version == 4 |
| 309 | else None, |
| 310 | host_ip6_gw=vpp_client_nexthop |
| 311 | if x_connect_mode == "L3" and ip_version == 6 |
| 312 | else None, |
| 313 | int_type=client_if_type, |
| 314 | host_if_name=f"{client_if_type}0", |
| 315 | enable_gso=enable_client_if_gso, |
| 316 | enable_gro=enable_client_if_gro, |
| 317 | enable_checksum_offload=enable_client_if_checksum_offload, |
| 318 | ) |
| 319 | self.tap_interfaces.append(self.ingress_if_idx) |
| 320 | self.ingress_if_idxes.append(self.ingress_if_idx) |
| 321 | self.vpp_interfaces.append(self.ingress_if_idx) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 322 | self.linux_interfaces.append( |
| 323 | [self.client_namespace, f"{client_if_type}0"] |
| 324 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 325 | # Seeing TCP timeouts if tx=on & rx=on Linux tap & tun interfaces |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 326 | disable_interface_gso(self.client_namespace, f"{client_if_type}0") |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 327 | elif client_if_type == "memif": |
| 328 | self.ingress_if_idx = self.create_memif( |
| 329 | memif_id=0, mode=0 if x_connect_mode == "L2" else 1 |
| 330 | ) |
| 331 | self.memif_interfaces.append(self.ingress_if_idx) |
| 332 | self.ingress_if_idxes.append(self.ingress_if_idx) |
| 333 | self.vpp_interfaces.append(self.ingress_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 334 | else: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 335 | print( |
| 336 | f"Unsupported client interface type: {client_if_type} " |
| 337 | f"for test - ID={test['id']}" |
| 338 | ) |
| 339 | sys.exit(1) |
| 340 | for server_if_type in server_if_types: |
| 341 | if server_if_type == "af_packet": |
| 342 | create_host_interface( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 343 | self.iprf_server_host_interface_on_linux, |
| 344 | self.iprf_server_host_interface_on_vpp, |
| 345 | self.server_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 346 | server_ip4_prefix, |
| 347 | server_ip6_prefix, |
| 348 | ) |
| 349 | self.egress_if_idx = self.create_af_packet( |
| 350 | version=server_if_version, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 351 | host_if_name=self.iprf_server_host_interface_on_vpp, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 352 | enable_gso=enable_server_if_gso, |
| 353 | ) |
| 354 | self.egress_if_idxes.append(self.egress_if_idx) |
| 355 | self.vpp_interfaces.append(self.egress_if_idx) |
| 356 | self.linux_interfaces.append( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 357 | ["", self.iprf_server_host_interface_on_vpp] |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 358 | ) |
| 359 | self.linux_interfaces.append( |
| 360 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 361 | self.server_namespace, |
| 362 | self.iprf_server_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 363 | ] |
| 364 | ) |
| 365 | if enable_server_if_gso == 0: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 366 | disable_interface_gso("", self.iprf_server_host_interface_on_vpp) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 367 | disable_interface_gso( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 368 | self.server_namespace, |
| 369 | self.iprf_server_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 370 | ) |
| 371 | elif server_if_type == "tap" or server_if_type == "tun": |
| 372 | self.egress_if_idx = self.create_tap_tun( |
| 373 | id=102, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 374 | host_namespace=self.server_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 375 | ip_version=ip_version, |
| 376 | host_ip4_prefix=layer2["server_ip4_prefix"] |
| 377 | if x_connect_mode == "L2" |
| 378 | else layer3["server_ip4_prefix"], |
| 379 | host_ip6_prefix=layer2["server_ip6_prefix"] |
| 380 | if x_connect_mode == "L2" |
| 381 | else layer3["server_ip6_prefix"], |
| 382 | int_type=server_if_type, |
| 383 | host_if_name=f"{server_if_type}0", |
| 384 | enable_gso=enable_server_if_gso, |
| 385 | enable_gro=enable_server_if_gro, |
| 386 | enable_checksum_offload=enable_server_if_checksum_offload, |
| 387 | ) |
| 388 | self.tap_interfaces.append(self.egress_if_idx) |
| 389 | self.egress_if_idxes.append(self.egress_if_idx) |
| 390 | self.vpp_interfaces.append(self.egress_if_idx) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 391 | self.linux_interfaces.append( |
| 392 | [self.server_namespace, f"{server_if_type}0"] |
| 393 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 394 | # Seeing TCP timeouts if tx=on & rx=on Linux tap & tun interfaces |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 395 | disable_interface_gso(self.server_namespace, f"{server_if_type}0") |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 396 | elif server_if_type == "memif": |
| 397 | self.egress_if_idx = self.create_memif( |
| 398 | memif_id=1, mode=0 if x_connect_mode == "L2" else 1 |
| 399 | ) |
| 400 | self.memif_interfaces.append(self.egress_if_idx) |
| 401 | self.egress_if_idxes.append(self.egress_if_idx) |
| 402 | self.vpp_interfaces.append(self.egress_if_idx) |
| 403 | else: |
| 404 | print( |
| 405 | f"Unsupported server interface type: {server_if_type} " |
| 406 | f"for test - ID={test['id']}" |
| 407 | ) |
| 408 | sys.exit(1) |
| 409 | self.if_types = set(client_if_types).union(set(server_if_types)) |
| 410 | # for memif testing: tapv2, memif & libmemif_app are connected |
| 411 | if "memif" not in self.if_types: |
| 412 | if x_connect_mode == "L2": |
| 413 | self.l2_connect_interfaces(1, self.ingress_if_idx, self.egress_if_idx) |
| 414 | elif x_connect_mode == "L3": |
| 415 | # L3 connect client & server side |
| 416 | vrf_id = layer3["ip4_vrf"] if ip_version == 4 else layer3["ip6_vrf"] |
| 417 | self.l3_connect_interfaces( |
| 418 | ip_version, |
| 419 | vrf_id, |
| 420 | (self.ingress_if_idx, vpp_client_prefix), |
| 421 | (self.egress_if_idx, vpp_server_prefix), |
| 422 | ) |
| 423 | # Setup namespace routing |
| 424 | if ip_version == 4: |
| 425 | add_namespace_route( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 426 | self.client_namespace, "0.0.0.0/0", vpp_client_nexthop |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 427 | ) |
| 428 | add_namespace_route( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 429 | self.server_namespace, "0.0.0.0/0", vpp_server_nexthop |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 430 | ) |
| 431 | else: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 432 | add_namespace_route( |
| 433 | self.client_namespace, "::/0", vpp_client_nexthop |
| 434 | ) |
| 435 | add_namespace_route( |
| 436 | self.server_namespace, "::/0", vpp_server_nexthop |
| 437 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 438 | else: |
| 439 | # connect: ingress tap & memif & egress tap and memif interfaces |
| 440 | if x_connect_mode == "L2": |
| 441 | self.l2_connect_interfaces(1, *self.ingress_if_idxes) |
| 442 | self.l2_connect_interfaces(2, *self.egress_if_idxes) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 443 | # Wait for Linux IPv6 stack to become ready |
| 444 | if ip_version == 6: |
| 445 | time.sleep(2) |
| 446 | |
| 447 | def tearDown(self): |
| 448 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 449 | for interface_if_idx in self.tap_interfaces: |
| 450 | self.vapi.tap_delete_v2(sw_if_index=interface_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 451 | except Exception: |
| 452 | pass |
| 453 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 454 | for interface_if_idx in self.memif_interfaces: |
| 455 | self.vapi.memif_delete(sw_if_index=interface_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 456 | except Exception: |
| 457 | pass |
| 458 | try: |
| 459 | for interface in self.vapi.af_packet_dump(): |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 460 | if interface.host_if_name == self.iprf_client_host_interface_on_vpp: |
| 461 | self.vapi.af_packet_delete(self.iprf_client_host_interface_on_vpp) |
| 462 | elif interface.host_if_name == self.iprf_server_host_interface_on_vpp: |
| 463 | self.vapi.af_packet_delete(self.iprf_server_host_interface_on_vpp) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 464 | except Exception: |
| 465 | pass |
| 466 | try: |
| 467 | delete_host_interfaces( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 468 | self.iprf_client_host_interface_on_linux, |
| 469 | self.iprf_server_host_interface_on_linux, |
| 470 | self.iprf_client_host_interface_on_vpp, |
| 471 | self.iprf_server_host_interface_on_vpp, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 472 | ) |
| 473 | except Exception: |
| 474 | pass |
| 475 | try: |
| 476 | self.vapi.ip_table_add_del(is_add=0, table={"table_id": layer3["ip4_vrf"]}) |
| 477 | except Exception: |
| 478 | pass |
| 479 | try: |
| 480 | self.vapi.ip_table_add_del(is_add=0, table={"table_id": layer3["ip6_vrf"]}) |
| 481 | except Exception: |
| 482 | pass |
| 483 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 484 | self.vapi.bridge_domain_add_del_v2(bd_id=1, is_add=0) |
| 485 | self.vapi.bridge_domain_add_del_v2(bd_id=2, is_add=0) |
| 486 | except Exception: |
| 487 | pass |
| 488 | try: |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 489 | delete_namespace( |
| 490 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 491 | self.client_namespace, |
| 492 | self.server_namespace, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 493 | ] |
| 494 | ) |
| 495 | except Exception: |
| 496 | pass |
| 497 | try: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 498 | if hasattr(self, "iperf_cmd"): |
| 499 | stop_iperf(" ".join(self.iperf_cmd)) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 500 | except Exception: |
| 501 | pass |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 502 | try: |
| 503 | if self.memif_process: |
| 504 | self.memif_process.terminate() |
| 505 | self.memif_process.join() |
| 506 | except Exception: |
| 507 | pass |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 508 | |
| 509 | def create_af_packet(self, version, host_if_name, enable_gso=0): |
| 510 | """Create an af_packetv3 interface in VPP. |
| 511 | |
| 512 | Parameters: |
| 513 | version -- 2 for af_packet_create_v2 |
| 514 | -- 3 for af_packet_create_v3 |
| 515 | host_if_name -- host interface name |
| 516 | enable_gso -- Enable GSO on the interface when True |
| 517 | """ |
| 518 | af_packet_mode = VppEnum.vl_api_af_packet_mode_t |
| 519 | af_packet_interface_mode = af_packet_mode.AF_PACKET_API_MODE_ETHERNET |
| 520 | af_packet_flags = VppEnum.vl_api_af_packet_flags_t |
| 521 | af_packet_interface_flags = af_packet_flags.AF_PACKET_API_FLAG_QDISC_BYPASS |
| 522 | if enable_gso: |
| 523 | af_packet_interface_flags = ( |
| 524 | af_packet_interface_flags | af_packet_flags.AF_PACKET_API_FLAG_CKSUM_GSO |
| 525 | ) |
| 526 | if version == 2: |
| 527 | af_packet_interface_flags = ( |
| 528 | af_packet_interface_flags | af_packet_flags.AF_PACKET_API_FLAG_VERSION_2 |
| 529 | ) |
| 530 | api_args = { |
| 531 | "use_random_hw_addr": True, |
| 532 | "host_if_name": host_if_name, |
| 533 | "flags": af_packet_interface_flags, |
| 534 | } |
| 535 | api_args["mode"] = af_packet_interface_mode |
| 536 | result = self.vapi.af_packet_create_v3(**api_args) |
| 537 | sw_if_index = result.sw_if_index |
| 538 | # Enable software GSO chunking when interface doesn't support GSO offload |
| 539 | if enable_gso == 0: |
| 540 | self.vapi.feature_gso_enable_disable( |
| 541 | sw_if_index=sw_if_index, enable_disable=1 |
| 542 | ) |
| 543 | else: |
| 544 | self.vapi.feature_gso_enable_disable( |
| 545 | sw_if_index=sw_if_index, enable_disable=0 |
| 546 | ) |
| 547 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 548 | return sw_if_index |
| 549 | |
| 550 | def create_tap_tun( |
| 551 | self, |
| 552 | id, |
| 553 | host_namespace, |
| 554 | ip_version, |
| 555 | host_ip4_prefix=None, |
| 556 | host_ip6_prefix=None, |
| 557 | host_ip4_gw=None, |
| 558 | host_ip6_gw=None, |
| 559 | int_type="tap", |
| 560 | host_if_name=None, |
| 561 | enable_gso=0, |
| 562 | enable_gro=0, |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 563 | enable_checksum_offload=0, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 564 | ): |
| 565 | """Create a tapv2 or tunv2 interface in VPP and attach to host. |
| 566 | |
| 567 | Parameters: |
| 568 | id -- interface ID |
| 569 | host_namespace -- host namespace to attach the tap/tun interface to |
| 570 | ip_version -- 4 or 6 |
| 571 | host_ip4_prefix -- ipv4 host interface address in CIDR notation |
| 572 | if ip_version=4 |
| 573 | host_ip6_prefix -- ipv6 host interface address in CIDR notation |
| 574 | if ip_version=6 |
| 575 | host_ip4_gw -- host IPv4 default gateway IP Address |
| 576 | host_ip6_gw -- host IPv6 default gateway IP address |
| 577 | int_type -- "tap" for tapv2 & "tun" for tunv2 interface |
| 578 | host_if_name -- host side interface name |
| 579 | enable_gso -- enable GSO |
| 580 | enable_gro -- enable GSO/GRO-Coalesce |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 581 | enable_checksum_offload -- enable checksum offload without gso |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 582 | """ |
| 583 | TapFlags = VppEnum.vl_api_tap_flags_t |
| 584 | tap_flags = 0 |
| 585 | if int_type == "tun": |
| 586 | tap_flags = TapFlags.TAP_API_FLAG_TUN |
| 587 | if enable_gro: |
| 588 | tap_flags = tap_flags | ( |
| 589 | TapFlags.TAP_API_FLAG_GSO | TapFlags.TAP_API_FLAG_GRO_COALESCE |
| 590 | ) |
| 591 | elif enable_gso: |
| 592 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_GSO |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 593 | elif enable_checksum_offload: |
| 594 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_CSUM_OFFLOAD |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 595 | elif int_type == "tap": |
| 596 | if enable_gro: |
| 597 | tap_flags = ( |
| 598 | TapFlags.TAP_API_FLAG_GSO | TapFlags.TAP_API_FLAG_GRO_COALESCE |
| 599 | ) |
| 600 | elif enable_gso: |
| 601 | tap_flags = TapFlags.TAP_API_FLAG_GSO |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 602 | elif enable_checksum_offload: |
| 603 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_CSUM_OFFLOAD |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 604 | |
| 605 | api_args = { |
| 606 | "id": id, |
| 607 | "host_namespace_set": True, |
| 608 | "host_namespace": host_namespace, |
| 609 | "host_if_name_set": False, |
| 610 | "host_bridge_set": False, |
| 611 | "host_mac_addr_set": False, |
| 612 | } |
| 613 | if tap_flags != 0: |
| 614 | api_args["tap_flags"] = tap_flags |
| 615 | if ip_version == 4: |
| 616 | api_args["host_ip4_prefix"] = ip_interface(host_ip4_prefix) |
| 617 | api_args["host_ip4_prefix_set"] = True |
| 618 | if host_ip4_gw: |
| 619 | api_args["host_ip4_gw"] = ip_address(host_ip4_gw) |
| 620 | api_args["host_ip4_gw_set"] = True |
| 621 | if ip_version == 6: |
| 622 | api_args["host_ip6_prefix"] = ip_interface(host_ip6_prefix) |
| 623 | api_args["host_ip6_prefix_set"] = True |
| 624 | if host_ip6_gw: |
| 625 | api_args["host_ip6_gw"] = ip_address(host_ip6_gw) |
| 626 | api_args["host_ip6_gw_set"] = True |
| 627 | if host_if_name: |
| 628 | api_args["host_if_name"] = host_if_name |
| 629 | api_args["host_if_name_set"] = True |
| 630 | |
| 631 | result = self.vapi.tap_create_v2(**api_args) |
| 632 | sw_if_index = result.sw_if_index |
| 633 | # Enable software GSO chunking when interface doesn't support GSO offload and |
| 634 | # GRO coalesce |
| 635 | if enable_gso == 0 and enable_gro == 0: |
| 636 | self.vapi.feature_gso_enable_disable( |
| 637 | sw_if_index=sw_if_index, enable_disable=1 |
| 638 | ) |
| 639 | else: |
| 640 | self.vapi.feature_gso_enable_disable( |
| 641 | sw_if_index=sw_if_index, enable_disable=0 |
| 642 | ) |
| 643 | # Admin up |
| 644 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 645 | return sw_if_index |
| 646 | |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 647 | def create_memif(self, memif_id, mode): |
| 648 | """Create memif interface in VPP. |
| 649 | |
| 650 | Parameters: |
| 651 | memif_id: A unique ID for the memif interface |
| 652 | mode: 0 = ethernet, 1 = ip, 2 = punt/inject |
| 653 | """ |
| 654 | # create memif interface with role=0 (i.e. master) |
| 655 | result = self.vapi.memif_create_v2( |
| 656 | role=0, mode=mode, id=memif_id, buffer_size=9216 |
| 657 | ) |
| 658 | sw_if_index = result.sw_if_index |
| 659 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 660 | return sw_if_index |
| 661 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 662 | def dump_bridge_domain_details(self, bd_id): |
| 663 | return self.vapi.bridge_domain_dump(bd_id=bd_id) |
| 664 | |
| 665 | def l2_connect_interfaces(self, bridge_id, *sw_if_idxs): |
| 666 | for if_idx in sw_if_idxs: |
| 667 | self.vapi.sw_interface_set_l2_bridge( |
| 668 | rx_sw_if_index=if_idx, bd_id=bridge_id, shg=0, port_type=0, enable=True |
| 669 | ) |
| 670 | |
| 671 | def l3_connect_interfaces(self, ip_version, vrf_id, *if_idx_ip_prefixes): |
| 672 | """Setup routing for (if_idx, ip_prefix) inside VPP. |
| 673 | |
| 674 | arguments: |
| 675 | if_idx_ip_prefixes -- sequence of (if_idx, ip_prefix) tuples |
| 676 | ip_version -- 4 or 6 |
| 677 | vrf_id -- vrf_id |
| 678 | """ |
| 679 | is_ipv6 = 0 if ip_version == 4 else 1 |
| 680 | self.vapi.ip_table_add_del( |
| 681 | is_add=1, table={"table_id": vrf_id, "is_ip6": is_ipv6} |
| 682 | ) |
| 683 | for sw_if_index, ip_prefix in if_idx_ip_prefixes: |
| 684 | self.vapi.sw_interface_set_table( |
| 685 | sw_if_index=sw_if_index, is_ipv6=is_ipv6, vrf_id=vrf_id |
| 686 | ) |
| 687 | self.vapi.sw_interface_add_del_address( |
| 688 | sw_if_index=sw_if_index, is_add=1, prefix=ip_interface(ip_prefix) |
| 689 | ) |
| 690 | |
| 691 | def set_interfaces_mtu(self, mtu, ip_version, **kwargs): |
| 692 | """Set MTUs on VPP and Linux interfaces. |
| 693 | |
| 694 | arguments -- |
| 695 | mtu -- mtu value |
| 696 | ip_version - 4 or 6 |
| 697 | kwargs['vpp_interfaces'] -- list of vpp interface if indexes |
| 698 | kwargs['linux_interfaces'] -- list of tuples (namespace, interface_names) |
| 699 | return True if mtu is set, else False |
| 700 | """ |
| 701 | vpp_interfaces = kwargs.get("vpp_interfaces") |
| 702 | linux_interfaces = kwargs.get("linux_interfaces") |
| 703 | # IPv6 on Linux requires an MTU value >=1280 |
| 704 | if (ip_version == 6 and mtu >= 1280) or ip_version == 4: |
| 705 | for sw_if_idx in vpp_interfaces: |
| 706 | self.vapi.sw_interface_set_mtu( |
| 707 | sw_if_index=sw_if_idx, mtu=[mtu, 0, 0, 0] |
| 708 | ) |
| 709 | for namespace, interface_name in linux_interfaces: |
| 710 | set_interface_mtu( |
| 711 | namespace=namespace, |
| 712 | interface=interface_name, |
| 713 | mtu=mtu, |
| 714 | logger=self.logger, |
| 715 | ) |
| 716 | return True |
| 717 | else: |
| 718 | return False |
| 719 | |
| 720 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 721 | if __name__ == "__main__": |
| 722 | unittest.main(testRunner=VppTestRunner) |