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: |
| 129 | print( |
| 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 | |
Andrew Yourtchenko | 9ba6dcf | 2023-06-20 14:52:08 +0000 | [diff] [blame] | 149 | if config.skip_netns_tests: |
| 150 | print("Skipping netns tests") |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 151 | for test in tests: |
| 152 | for ip_version in test_config["ip_versions"]: |
| 153 | for mtu in test_config["mtus"]: |
| 154 | test_name = ( |
| 155 | f"test_id_{test['id']}_" |
| 156 | + f"client_{test['client_if_type']}" |
| 157 | + f"_v{test['client_if_version']}_" |
| 158 | + f"gso_{test.get('client_if_gso', 0)}_" |
| 159 | + f"gro_{test.get('client_if_gro', 0)}_" |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 160 | + f"checksum_{test.get('client_if_checksum_offload', 0)}_" |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 161 | + f"to_server_{test['server_if_type']}" |
| 162 | + f"_v{test['server_if_version']}_" |
| 163 | + f"gso_{test.get('server_if_gso', 0)}_" |
| 164 | + f"gro_{test.get('server_if_gro', 0)}_" |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 165 | + f"checksum_{test.get('server_if_checksum_offload', 0)}_" |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 166 | + f"mtu_{mtu}_mode_{test['x_connect_mode']}_" |
| 167 | + f"tcp_ipv{ip_version}" |
| 168 | ) |
| 169 | test_func = create_test( |
| 170 | test_name=test_name, test=test, ip_version=ip_version, mtu=mtu |
| 171 | ) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 172 | setattr(test_class, test_name, test_func) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 173 | |
| 174 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 175 | @tag_fixme_debian11 |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 176 | class TestVPPInterfacesQemu: |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 177 | """Test VPP interfaces inside a QEMU VM for IPv4/v6. |
| 178 | |
| 179 | Test Setup: |
| 180 | Linux_ns1--iperfClient--host-int1--vpp-af_packet-int1--VPP-BD |
| 181 | --vppaf_packet_int2--host-int2--iperfServer--Linux_ns2 |
| 182 | """ |
| 183 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 184 | def setUpTestToplogy(self, test, ip_version): |
| 185 | """Setup the test topology. |
| 186 | |
| 187 | 1. Create Linux Namespaces for iPerf Client & Server. |
| 188 | 2. Create VPP iPerf client and server virtual interfaces. |
| 189 | 3. Enable desired vif features such as GSO & GRO. |
| 190 | 3. Cross-Connect interfaces in VPP using L2 or L3. |
| 191 | """ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 192 | |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 193 | # Need to support multiple interface types as the memif interface |
| 194 | # in VPP is connected to the iPerf client & server by x-connecting |
| 195 | # to a tap interface in their respective namespaces. |
| 196 | client_if_types = test["client_if_type"].split(",") |
| 197 | server_if_types = test["server_if_type"].split(",") |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 198 | client_if_version = test["client_if_version"] |
| 199 | server_if_version = test["server_if_version"] |
| 200 | x_connect_mode = test["x_connect_mode"] |
| 201 | # server ip4/ip6 addresses required by iperf client |
| 202 | server_ip4_prefix = ( |
| 203 | layer2["server_ip4_prefix"] |
| 204 | if x_connect_mode == "L2" |
| 205 | else layer3["server_ip4_prefix"] |
| 206 | ) |
| 207 | server_ip6_prefix = ( |
| 208 | layer2["server_ip6_prefix"] |
| 209 | if x_connect_mode == "L2" |
| 210 | else layer3["server_ip6_prefix"] |
| 211 | ) |
| 212 | self.server_ip4_address = str(ip_interface(server_ip4_prefix).ip) |
| 213 | self.server_ip6_address = str(ip_interface(server_ip6_prefix).ip) |
| 214 | # next-hop IP address on VPP for routing from client & server namespaces |
| 215 | vpp_client_prefix = ( |
| 216 | layer3["vpp_client_ip4_prefix"] |
| 217 | if ip_version == 4 |
| 218 | else layer3["vpp_client_ip6_prefix"] |
| 219 | ) |
| 220 | vpp_client_nexthop = str(ip_interface(vpp_client_prefix).ip) |
| 221 | vpp_server_prefix = ( |
| 222 | layer3["vpp_server_ip4_prefix"] |
| 223 | if ip_version == 4 |
| 224 | else layer3["vpp_server_ip6_prefix"] |
| 225 | ) |
| 226 | vpp_server_nexthop = str(ip_interface(vpp_server_prefix).ip) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 227 | # Create unique namespaces for iperf client & iperf server to |
| 228 | # prevent conflicts when TEST_JOBS > 1 |
| 229 | self.client_namespace = test_config["client_namespace"] + str(test["id"]) |
| 230 | self.server_namespace = test_config["server_namespace"] + str(test["id"]) |
| 231 | create_namespace([self.client_namespace, self.server_namespace]) |
| 232 | # Set a unique iPerf port for parallel server and client runs |
| 233 | self.iperf_port = 5000 + test["id"] |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 234 | # IPerf client & server ingress/egress interface indexes in VPP |
| 235 | self.tap_interfaces = [] |
| 236 | self.memif_interfaces = [] |
| 237 | self.ingress_if_idxes = [] |
| 238 | self.egress_if_idxes = [] |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 239 | self.vpp_interfaces = [] |
| 240 | self.linux_interfaces = [] |
| 241 | enable_client_if_gso = test.get("client_if_gso", 0) |
| 242 | enable_server_if_gso = test.get("server_if_gso", 0) |
| 243 | enable_client_if_gro = test.get("client_if_gro", 0) |
| 244 | enable_server_if_gro = test.get("server_if_gro", 0) |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 245 | enable_client_if_checksum_offload = test.get("client_if_checksum_offload", 0) |
| 246 | enable_server_if_checksum_offload = test.get("server_if_checksum_offload", 0) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 247 | |
| 248 | # Create unique host interfaces in Linux and VPP for connecting to iperf |
| 249 | # client & iperf server to prevent conflicts when TEST_JOBS > 1 |
| 250 | self.iprf_client_host_interface_on_linux = af_packet_config[ |
| 251 | "iprf_client_interface_on_linux" |
| 252 | ] + str(test["id"]) |
| 253 | self.iprf_client_host_interface_on_vpp = af_packet_config[ |
| 254 | "iprf_client_interface_on_vpp" |
| 255 | ] + str(test["id"]) |
| 256 | self.iprf_server_host_interface_on_linux = af_packet_config[ |
| 257 | "iprf_server_interface_on_linux" |
| 258 | ] + str(test["id"]) |
| 259 | self.iprf_server_host_interface_on_vpp = af_packet_config[ |
| 260 | "iprf_server_interface_on_vpp" |
| 261 | ] + str(test["id"]) |
| 262 | # Handle client interface types |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 263 | for client_if_type in client_if_types: |
| 264 | if client_if_type == "af_packet": |
| 265 | create_host_interface( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 266 | self.iprf_client_host_interface_on_linux, |
| 267 | self.iprf_client_host_interface_on_vpp, |
| 268 | self.client_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 269 | layer2["client_ip4_prefix"] |
| 270 | if x_connect_mode == "L2" |
| 271 | else layer3["client_ip4_prefix"], |
| 272 | layer2["client_ip6_prefix"] |
| 273 | if x_connect_mode == "L2" |
| 274 | else layer3["client_ip6_prefix"], |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 275 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 276 | self.ingress_if_idx = self.create_af_packet( |
| 277 | version=client_if_version, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 278 | host_if_name=self.iprf_client_host_interface_on_vpp, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 279 | enable_gso=enable_client_if_gso, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 280 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 281 | self.ingress_if_idxes.append(self.ingress_if_idx) |
| 282 | self.vpp_interfaces.append(self.ingress_if_idx) |
| 283 | self.linux_interfaces.append( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 284 | ["", self.iprf_client_host_interface_on_vpp] |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 285 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 286 | self.linux_interfaces.append( |
| 287 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 288 | self.client_namespace, |
| 289 | self.iprf_client_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 290 | ] |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 291 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 292 | if enable_client_if_gso == 0: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 293 | disable_interface_gso("", self.iprf_client_host_interface_on_vpp) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 294 | disable_interface_gso( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 295 | self.client_namespace, |
| 296 | self.iprf_client_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 297 | ) |
| 298 | elif client_if_type == "tap" or client_if_type == "tun": |
| 299 | self.ingress_if_idx = self.create_tap_tun( |
| 300 | id=101, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 301 | host_namespace=self.client_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 302 | ip_version=ip_version, |
| 303 | host_ip4_prefix=layer2["client_ip4_prefix"] |
| 304 | if x_connect_mode == "L2" |
| 305 | else layer3["client_ip4_prefix"], |
| 306 | host_ip6_prefix=layer2["client_ip6_prefix"] |
| 307 | if x_connect_mode == "L2" |
| 308 | else layer3["client_ip6_prefix"], |
| 309 | host_ip4_gw=vpp_client_nexthop |
| 310 | if x_connect_mode == "L3" and ip_version == 4 |
| 311 | else None, |
| 312 | host_ip6_gw=vpp_client_nexthop |
| 313 | if x_connect_mode == "L3" and ip_version == 6 |
| 314 | else None, |
| 315 | int_type=client_if_type, |
| 316 | host_if_name=f"{client_if_type}0", |
| 317 | enable_gso=enable_client_if_gso, |
| 318 | enable_gro=enable_client_if_gro, |
| 319 | enable_checksum_offload=enable_client_if_checksum_offload, |
| 320 | ) |
| 321 | self.tap_interfaces.append(self.ingress_if_idx) |
| 322 | self.ingress_if_idxes.append(self.ingress_if_idx) |
| 323 | self.vpp_interfaces.append(self.ingress_if_idx) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 324 | self.linux_interfaces.append( |
| 325 | [self.client_namespace, f"{client_if_type}0"] |
| 326 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 327 | # Seeing TCP timeouts if tx=on & rx=on Linux tap & tun interfaces |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 328 | disable_interface_gso(self.client_namespace, f"{client_if_type}0") |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 329 | elif client_if_type == "memif": |
| 330 | self.ingress_if_idx = self.create_memif( |
| 331 | memif_id=0, mode=0 if x_connect_mode == "L2" else 1 |
| 332 | ) |
| 333 | self.memif_interfaces.append(self.ingress_if_idx) |
| 334 | self.ingress_if_idxes.append(self.ingress_if_idx) |
| 335 | self.vpp_interfaces.append(self.ingress_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 336 | else: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 337 | print( |
| 338 | f"Unsupported client interface type: {client_if_type} " |
| 339 | f"for test - ID={test['id']}" |
| 340 | ) |
| 341 | sys.exit(1) |
| 342 | for server_if_type in server_if_types: |
| 343 | if server_if_type == "af_packet": |
| 344 | create_host_interface( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 345 | self.iprf_server_host_interface_on_linux, |
| 346 | self.iprf_server_host_interface_on_vpp, |
| 347 | self.server_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 348 | server_ip4_prefix, |
| 349 | server_ip6_prefix, |
| 350 | ) |
| 351 | self.egress_if_idx = self.create_af_packet( |
| 352 | version=server_if_version, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 353 | host_if_name=self.iprf_server_host_interface_on_vpp, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 354 | enable_gso=enable_server_if_gso, |
| 355 | ) |
| 356 | self.egress_if_idxes.append(self.egress_if_idx) |
| 357 | self.vpp_interfaces.append(self.egress_if_idx) |
| 358 | self.linux_interfaces.append( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 359 | ["", self.iprf_server_host_interface_on_vpp] |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 360 | ) |
| 361 | self.linux_interfaces.append( |
| 362 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 363 | self.server_namespace, |
| 364 | self.iprf_server_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 365 | ] |
| 366 | ) |
| 367 | if enable_server_if_gso == 0: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 368 | disable_interface_gso("", self.iprf_server_host_interface_on_vpp) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 369 | disable_interface_gso( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 370 | self.server_namespace, |
| 371 | self.iprf_server_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 372 | ) |
| 373 | elif server_if_type == "tap" or server_if_type == "tun": |
| 374 | self.egress_if_idx = self.create_tap_tun( |
| 375 | id=102, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 376 | host_namespace=self.server_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 377 | ip_version=ip_version, |
| 378 | host_ip4_prefix=layer2["server_ip4_prefix"] |
| 379 | if x_connect_mode == "L2" |
| 380 | else layer3["server_ip4_prefix"], |
| 381 | host_ip6_prefix=layer2["server_ip6_prefix"] |
| 382 | if x_connect_mode == "L2" |
| 383 | else layer3["server_ip6_prefix"], |
| 384 | int_type=server_if_type, |
| 385 | host_if_name=f"{server_if_type}0", |
| 386 | enable_gso=enable_server_if_gso, |
| 387 | enable_gro=enable_server_if_gro, |
| 388 | enable_checksum_offload=enable_server_if_checksum_offload, |
| 389 | ) |
| 390 | self.tap_interfaces.append(self.egress_if_idx) |
| 391 | self.egress_if_idxes.append(self.egress_if_idx) |
| 392 | self.vpp_interfaces.append(self.egress_if_idx) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 393 | self.linux_interfaces.append( |
| 394 | [self.server_namespace, f"{server_if_type}0"] |
| 395 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 396 | # Seeing TCP timeouts if tx=on & rx=on Linux tap & tun interfaces |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 397 | disable_interface_gso(self.server_namespace, f"{server_if_type}0") |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 398 | elif server_if_type == "memif": |
| 399 | self.egress_if_idx = self.create_memif( |
| 400 | memif_id=1, mode=0 if x_connect_mode == "L2" else 1 |
| 401 | ) |
| 402 | self.memif_interfaces.append(self.egress_if_idx) |
| 403 | self.egress_if_idxes.append(self.egress_if_idx) |
| 404 | self.vpp_interfaces.append(self.egress_if_idx) |
| 405 | else: |
| 406 | print( |
| 407 | f"Unsupported server interface type: {server_if_type} " |
| 408 | f"for test - ID={test['id']}" |
| 409 | ) |
| 410 | sys.exit(1) |
| 411 | self.if_types = set(client_if_types).union(set(server_if_types)) |
| 412 | # for memif testing: tapv2, memif & libmemif_app are connected |
| 413 | if "memif" not in self.if_types: |
| 414 | if x_connect_mode == "L2": |
| 415 | self.l2_connect_interfaces(1, self.ingress_if_idx, self.egress_if_idx) |
| 416 | elif x_connect_mode == "L3": |
| 417 | # L3 connect client & server side |
| 418 | vrf_id = layer3["ip4_vrf"] if ip_version == 4 else layer3["ip6_vrf"] |
| 419 | self.l3_connect_interfaces( |
| 420 | ip_version, |
| 421 | vrf_id, |
| 422 | (self.ingress_if_idx, vpp_client_prefix), |
| 423 | (self.egress_if_idx, vpp_server_prefix), |
| 424 | ) |
| 425 | # Setup namespace routing |
| 426 | if ip_version == 4: |
| 427 | add_namespace_route( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 428 | self.client_namespace, "0.0.0.0/0", vpp_client_nexthop |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 429 | ) |
| 430 | add_namespace_route( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 431 | self.server_namespace, "0.0.0.0/0", vpp_server_nexthop |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 432 | ) |
| 433 | else: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 434 | add_namespace_route( |
| 435 | self.client_namespace, "::/0", vpp_client_nexthop |
| 436 | ) |
| 437 | add_namespace_route( |
| 438 | self.server_namespace, "::/0", vpp_server_nexthop |
| 439 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 440 | else: |
| 441 | # connect: ingress tap & memif & egress tap and memif interfaces |
| 442 | if x_connect_mode == "L2": |
| 443 | self.l2_connect_interfaces(1, *self.ingress_if_idxes) |
| 444 | self.l2_connect_interfaces(2, *self.egress_if_idxes) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 445 | # Wait for Linux IPv6 stack to become ready |
| 446 | if ip_version == 6: |
| 447 | time.sleep(2) |
| 448 | |
| 449 | def tearDown(self): |
| 450 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 451 | for interface_if_idx in self.tap_interfaces: |
| 452 | self.vapi.tap_delete_v2(sw_if_index=interface_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 453 | except Exception: |
| 454 | pass |
| 455 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 456 | for interface_if_idx in self.memif_interfaces: |
| 457 | self.vapi.memif_delete(sw_if_index=interface_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 458 | except Exception: |
| 459 | pass |
| 460 | try: |
| 461 | for interface in self.vapi.af_packet_dump(): |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 462 | if interface.host_if_name == self.iprf_client_host_interface_on_vpp: |
| 463 | self.vapi.af_packet_delete(self.iprf_client_host_interface_on_vpp) |
| 464 | elif interface.host_if_name == self.iprf_server_host_interface_on_vpp: |
| 465 | self.vapi.af_packet_delete(self.iprf_server_host_interface_on_vpp) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 466 | except Exception: |
| 467 | pass |
| 468 | try: |
| 469 | delete_host_interfaces( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 470 | self.iprf_client_host_interface_on_linux, |
| 471 | self.iprf_server_host_interface_on_linux, |
| 472 | self.iprf_client_host_interface_on_vpp, |
| 473 | self.iprf_server_host_interface_on_vpp, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 474 | ) |
| 475 | except Exception: |
| 476 | pass |
| 477 | try: |
| 478 | self.vapi.ip_table_add_del(is_add=0, table={"table_id": layer3["ip4_vrf"]}) |
| 479 | except Exception: |
| 480 | pass |
| 481 | try: |
| 482 | self.vapi.ip_table_add_del(is_add=0, table={"table_id": layer3["ip6_vrf"]}) |
| 483 | except Exception: |
| 484 | pass |
| 485 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 486 | self.vapi.bridge_domain_add_del_v2(bd_id=1, is_add=0) |
| 487 | self.vapi.bridge_domain_add_del_v2(bd_id=2, is_add=0) |
| 488 | except Exception: |
| 489 | pass |
| 490 | try: |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 491 | delete_namespace( |
| 492 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 493 | self.client_namespace, |
| 494 | self.server_namespace, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 495 | ] |
| 496 | ) |
| 497 | except Exception: |
| 498 | pass |
| 499 | try: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 500 | if hasattr(self, "iperf_cmd"): |
| 501 | stop_iperf(" ".join(self.iperf_cmd)) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 502 | except Exception: |
| 503 | pass |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 504 | try: |
| 505 | if self.memif_process: |
| 506 | self.memif_process.terminate() |
| 507 | self.memif_process.join() |
| 508 | except Exception: |
| 509 | pass |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 510 | |
| 511 | def create_af_packet(self, version, host_if_name, enable_gso=0): |
| 512 | """Create an af_packetv3 interface in VPP. |
| 513 | |
| 514 | Parameters: |
| 515 | version -- 2 for af_packet_create_v2 |
| 516 | -- 3 for af_packet_create_v3 |
| 517 | host_if_name -- host interface name |
| 518 | enable_gso -- Enable GSO on the interface when True |
| 519 | """ |
| 520 | af_packet_mode = VppEnum.vl_api_af_packet_mode_t |
| 521 | af_packet_interface_mode = af_packet_mode.AF_PACKET_API_MODE_ETHERNET |
| 522 | af_packet_flags = VppEnum.vl_api_af_packet_flags_t |
| 523 | af_packet_interface_flags = af_packet_flags.AF_PACKET_API_FLAG_QDISC_BYPASS |
| 524 | if enable_gso: |
| 525 | af_packet_interface_flags = ( |
| 526 | af_packet_interface_flags | af_packet_flags.AF_PACKET_API_FLAG_CKSUM_GSO |
| 527 | ) |
| 528 | if version == 2: |
| 529 | af_packet_interface_flags = ( |
| 530 | af_packet_interface_flags | af_packet_flags.AF_PACKET_API_FLAG_VERSION_2 |
| 531 | ) |
| 532 | api_args = { |
| 533 | "use_random_hw_addr": True, |
| 534 | "host_if_name": host_if_name, |
| 535 | "flags": af_packet_interface_flags, |
| 536 | } |
| 537 | api_args["mode"] = af_packet_interface_mode |
| 538 | result = self.vapi.af_packet_create_v3(**api_args) |
| 539 | sw_if_index = result.sw_if_index |
| 540 | # Enable software GSO chunking when interface doesn't support GSO offload |
| 541 | if enable_gso == 0: |
| 542 | self.vapi.feature_gso_enable_disable( |
| 543 | sw_if_index=sw_if_index, enable_disable=1 |
| 544 | ) |
| 545 | else: |
| 546 | self.vapi.feature_gso_enable_disable( |
| 547 | sw_if_index=sw_if_index, enable_disable=0 |
| 548 | ) |
| 549 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 550 | return sw_if_index |
| 551 | |
| 552 | def create_tap_tun( |
| 553 | self, |
| 554 | id, |
| 555 | host_namespace, |
| 556 | ip_version, |
| 557 | host_ip4_prefix=None, |
| 558 | host_ip6_prefix=None, |
| 559 | host_ip4_gw=None, |
| 560 | host_ip6_gw=None, |
| 561 | int_type="tap", |
| 562 | host_if_name=None, |
| 563 | enable_gso=0, |
| 564 | enable_gro=0, |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 565 | enable_checksum_offload=0, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 566 | ): |
| 567 | """Create a tapv2 or tunv2 interface in VPP and attach to host. |
| 568 | |
| 569 | Parameters: |
| 570 | id -- interface ID |
| 571 | host_namespace -- host namespace to attach the tap/tun interface to |
| 572 | ip_version -- 4 or 6 |
| 573 | host_ip4_prefix -- ipv4 host interface address in CIDR notation |
| 574 | if ip_version=4 |
| 575 | host_ip6_prefix -- ipv6 host interface address in CIDR notation |
| 576 | if ip_version=6 |
| 577 | host_ip4_gw -- host IPv4 default gateway IP Address |
| 578 | host_ip6_gw -- host IPv6 default gateway IP address |
| 579 | int_type -- "tap" for tapv2 & "tun" for tunv2 interface |
| 580 | host_if_name -- host side interface name |
| 581 | enable_gso -- enable GSO |
| 582 | enable_gro -- enable GSO/GRO-Coalesce |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 583 | enable_checksum_offload -- enable checksum offload without gso |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 584 | """ |
| 585 | TapFlags = VppEnum.vl_api_tap_flags_t |
| 586 | tap_flags = 0 |
| 587 | if int_type == "tun": |
| 588 | tap_flags = TapFlags.TAP_API_FLAG_TUN |
| 589 | if enable_gro: |
| 590 | tap_flags = tap_flags | ( |
| 591 | TapFlags.TAP_API_FLAG_GSO | TapFlags.TAP_API_FLAG_GRO_COALESCE |
| 592 | ) |
| 593 | elif enable_gso: |
| 594 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_GSO |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 595 | elif enable_checksum_offload: |
| 596 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_CSUM_OFFLOAD |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 597 | elif int_type == "tap": |
| 598 | if enable_gro: |
| 599 | tap_flags = ( |
| 600 | TapFlags.TAP_API_FLAG_GSO | TapFlags.TAP_API_FLAG_GRO_COALESCE |
| 601 | ) |
| 602 | elif enable_gso: |
| 603 | tap_flags = TapFlags.TAP_API_FLAG_GSO |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 604 | elif enable_checksum_offload: |
| 605 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_CSUM_OFFLOAD |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 606 | |
| 607 | api_args = { |
| 608 | "id": id, |
| 609 | "host_namespace_set": True, |
| 610 | "host_namespace": host_namespace, |
| 611 | "host_if_name_set": False, |
| 612 | "host_bridge_set": False, |
| 613 | "host_mac_addr_set": False, |
| 614 | } |
| 615 | if tap_flags != 0: |
| 616 | api_args["tap_flags"] = tap_flags |
| 617 | if ip_version == 4: |
| 618 | api_args["host_ip4_prefix"] = ip_interface(host_ip4_prefix) |
| 619 | api_args["host_ip4_prefix_set"] = True |
| 620 | if host_ip4_gw: |
| 621 | api_args["host_ip4_gw"] = ip_address(host_ip4_gw) |
| 622 | api_args["host_ip4_gw_set"] = True |
| 623 | if ip_version == 6: |
| 624 | api_args["host_ip6_prefix"] = ip_interface(host_ip6_prefix) |
| 625 | api_args["host_ip6_prefix_set"] = True |
| 626 | if host_ip6_gw: |
| 627 | api_args["host_ip6_gw"] = ip_address(host_ip6_gw) |
| 628 | api_args["host_ip6_gw_set"] = True |
| 629 | if host_if_name: |
| 630 | api_args["host_if_name"] = host_if_name |
| 631 | api_args["host_if_name_set"] = True |
| 632 | |
| 633 | result = self.vapi.tap_create_v2(**api_args) |
| 634 | sw_if_index = result.sw_if_index |
| 635 | # Enable software GSO chunking when interface doesn't support GSO offload and |
| 636 | # GRO coalesce |
| 637 | if enable_gso == 0 and enable_gro == 0: |
| 638 | self.vapi.feature_gso_enable_disable( |
| 639 | sw_if_index=sw_if_index, enable_disable=1 |
| 640 | ) |
| 641 | else: |
| 642 | self.vapi.feature_gso_enable_disable( |
| 643 | sw_if_index=sw_if_index, enable_disable=0 |
| 644 | ) |
| 645 | # Admin up |
| 646 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 647 | return sw_if_index |
| 648 | |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 649 | def create_memif(self, memif_id, mode): |
| 650 | """Create memif interface in VPP. |
| 651 | |
| 652 | Parameters: |
| 653 | memif_id: A unique ID for the memif interface |
| 654 | mode: 0 = ethernet, 1 = ip, 2 = punt/inject |
| 655 | """ |
| 656 | # create memif interface with role=0 (i.e. master) |
| 657 | result = self.vapi.memif_create_v2( |
| 658 | role=0, mode=mode, id=memif_id, buffer_size=9216 |
| 659 | ) |
| 660 | sw_if_index = result.sw_if_index |
| 661 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 662 | return sw_if_index |
| 663 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 664 | def dump_bridge_domain_details(self, bd_id): |
| 665 | return self.vapi.bridge_domain_dump(bd_id=bd_id) |
| 666 | |
| 667 | def l2_connect_interfaces(self, bridge_id, *sw_if_idxs): |
| 668 | for if_idx in sw_if_idxs: |
| 669 | self.vapi.sw_interface_set_l2_bridge( |
| 670 | rx_sw_if_index=if_idx, bd_id=bridge_id, shg=0, port_type=0, enable=True |
| 671 | ) |
| 672 | |
| 673 | def l3_connect_interfaces(self, ip_version, vrf_id, *if_idx_ip_prefixes): |
| 674 | """Setup routing for (if_idx, ip_prefix) inside VPP. |
| 675 | |
| 676 | arguments: |
| 677 | if_idx_ip_prefixes -- sequence of (if_idx, ip_prefix) tuples |
| 678 | ip_version -- 4 or 6 |
| 679 | vrf_id -- vrf_id |
| 680 | """ |
| 681 | is_ipv6 = 0 if ip_version == 4 else 1 |
| 682 | self.vapi.ip_table_add_del( |
| 683 | is_add=1, table={"table_id": vrf_id, "is_ip6": is_ipv6} |
| 684 | ) |
| 685 | for sw_if_index, ip_prefix in if_idx_ip_prefixes: |
| 686 | self.vapi.sw_interface_set_table( |
| 687 | sw_if_index=sw_if_index, is_ipv6=is_ipv6, vrf_id=vrf_id |
| 688 | ) |
| 689 | self.vapi.sw_interface_add_del_address( |
| 690 | sw_if_index=sw_if_index, is_add=1, prefix=ip_interface(ip_prefix) |
| 691 | ) |
| 692 | |
| 693 | def set_interfaces_mtu(self, mtu, ip_version, **kwargs): |
| 694 | """Set MTUs on VPP and Linux interfaces. |
| 695 | |
| 696 | arguments -- |
| 697 | mtu -- mtu value |
| 698 | ip_version - 4 or 6 |
| 699 | kwargs['vpp_interfaces'] -- list of vpp interface if indexes |
| 700 | kwargs['linux_interfaces'] -- list of tuples (namespace, interface_names) |
| 701 | return True if mtu is set, else False |
| 702 | """ |
| 703 | vpp_interfaces = kwargs.get("vpp_interfaces") |
| 704 | linux_interfaces = kwargs.get("linux_interfaces") |
| 705 | # IPv6 on Linux requires an MTU value >=1280 |
| 706 | if (ip_version == 6 and mtu >= 1280) or ip_version == 4: |
| 707 | for sw_if_idx in vpp_interfaces: |
| 708 | self.vapi.sw_interface_set_mtu( |
| 709 | sw_if_index=sw_if_idx, mtu=[mtu, 0, 0, 0] |
| 710 | ) |
| 711 | for namespace, interface_name in linux_interfaces: |
| 712 | set_interface_mtu( |
| 713 | namespace=namespace, |
| 714 | interface=interface_name, |
| 715 | mtu=mtu, |
| 716 | logger=self.logger, |
| 717 | ) |
| 718 | return True |
| 719 | else: |
| 720 | return False |
| 721 | |
| 722 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 723 | if __name__ == "__main__": |
| 724 | unittest.main(testRunner=VppTestRunner) |