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, |
Dave Wallace | 940a70f | 2024-04-03 12:31:42 -0400 | [diff] [blame] | 267 | ( |
| 268 | layer2["client_ip4_prefix"] |
| 269 | if x_connect_mode == "L2" |
| 270 | else layer3["client_ip4_prefix"] |
| 271 | ), |
| 272 | ( |
| 273 | layer2["client_ip6_prefix"] |
| 274 | if x_connect_mode == "L2" |
| 275 | else layer3["client_ip6_prefix"] |
| 276 | ), |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 277 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 278 | self.ingress_if_idx = self.create_af_packet( |
| 279 | version=client_if_version, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 280 | host_if_name=self.iprf_client_host_interface_on_vpp, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 281 | enable_gso=enable_client_if_gso, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 282 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 283 | self.ingress_if_idxes.append(self.ingress_if_idx) |
| 284 | self.vpp_interfaces.append(self.ingress_if_idx) |
| 285 | self.linux_interfaces.append( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 286 | ["", self.iprf_client_host_interface_on_vpp] |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 287 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 288 | self.linux_interfaces.append( |
| 289 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 290 | self.client_namespace, |
| 291 | self.iprf_client_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 292 | ] |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 293 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 294 | if enable_client_if_gso == 0: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 295 | disable_interface_gso("", self.iprf_client_host_interface_on_vpp) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 296 | disable_interface_gso( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 297 | self.client_namespace, |
| 298 | self.iprf_client_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 299 | ) |
| 300 | elif client_if_type == "tap" or client_if_type == "tun": |
| 301 | self.ingress_if_idx = self.create_tap_tun( |
| 302 | id=101, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 303 | host_namespace=self.client_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 304 | ip_version=ip_version, |
Dave Wallace | 940a70f | 2024-04-03 12:31:42 -0400 | [diff] [blame] | 305 | host_ip4_prefix=( |
| 306 | layer2["client_ip4_prefix"] |
| 307 | if x_connect_mode == "L2" |
| 308 | else layer3["client_ip4_prefix"] |
| 309 | ), |
| 310 | host_ip6_prefix=( |
| 311 | layer2["client_ip6_prefix"] |
| 312 | if x_connect_mode == "L2" |
| 313 | else layer3["client_ip6_prefix"] |
| 314 | ), |
| 315 | host_ip4_gw=( |
| 316 | vpp_client_nexthop |
| 317 | if x_connect_mode == "L3" and ip_version == 4 |
| 318 | else None |
| 319 | ), |
| 320 | host_ip6_gw=( |
| 321 | vpp_client_nexthop |
| 322 | if x_connect_mode == "L3" and ip_version == 6 |
| 323 | else None |
| 324 | ), |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 325 | int_type=client_if_type, |
| 326 | host_if_name=f"{client_if_type}0", |
| 327 | enable_gso=enable_client_if_gso, |
| 328 | enable_gro=enable_client_if_gro, |
| 329 | enable_checksum_offload=enable_client_if_checksum_offload, |
| 330 | ) |
| 331 | self.tap_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 | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 334 | self.linux_interfaces.append( |
| 335 | [self.client_namespace, f"{client_if_type}0"] |
| 336 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 337 | # Seeing TCP timeouts if tx=on & rx=on Linux tap & tun interfaces |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 338 | disable_interface_gso(self.client_namespace, f"{client_if_type}0") |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 339 | elif client_if_type == "memif": |
| 340 | self.ingress_if_idx = self.create_memif( |
| 341 | memif_id=0, mode=0 if x_connect_mode == "L2" else 1 |
| 342 | ) |
| 343 | self.memif_interfaces.append(self.ingress_if_idx) |
| 344 | self.ingress_if_idxes.append(self.ingress_if_idx) |
| 345 | self.vpp_interfaces.append(self.ingress_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 346 | else: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 347 | print( |
| 348 | f"Unsupported client interface type: {client_if_type} " |
| 349 | f"for test - ID={test['id']}" |
| 350 | ) |
| 351 | sys.exit(1) |
| 352 | for server_if_type in server_if_types: |
| 353 | if server_if_type == "af_packet": |
| 354 | create_host_interface( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 355 | self.iprf_server_host_interface_on_linux, |
| 356 | self.iprf_server_host_interface_on_vpp, |
| 357 | self.server_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 358 | server_ip4_prefix, |
| 359 | server_ip6_prefix, |
| 360 | ) |
| 361 | self.egress_if_idx = self.create_af_packet( |
| 362 | version=server_if_version, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 363 | host_if_name=self.iprf_server_host_interface_on_vpp, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 364 | enable_gso=enable_server_if_gso, |
| 365 | ) |
| 366 | self.egress_if_idxes.append(self.egress_if_idx) |
| 367 | self.vpp_interfaces.append(self.egress_if_idx) |
| 368 | self.linux_interfaces.append( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 369 | ["", self.iprf_server_host_interface_on_vpp] |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 370 | ) |
| 371 | self.linux_interfaces.append( |
| 372 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 373 | self.server_namespace, |
| 374 | self.iprf_server_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 375 | ] |
| 376 | ) |
| 377 | if enable_server_if_gso == 0: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 378 | disable_interface_gso("", self.iprf_server_host_interface_on_vpp) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 379 | disable_interface_gso( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 380 | self.server_namespace, |
| 381 | self.iprf_server_host_interface_on_linux, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 382 | ) |
| 383 | elif server_if_type == "tap" or server_if_type == "tun": |
| 384 | self.egress_if_idx = self.create_tap_tun( |
| 385 | id=102, |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 386 | host_namespace=self.server_namespace, |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 387 | ip_version=ip_version, |
Dave Wallace | 940a70f | 2024-04-03 12:31:42 -0400 | [diff] [blame] | 388 | host_ip4_prefix=( |
| 389 | layer2["server_ip4_prefix"] |
| 390 | if x_connect_mode == "L2" |
| 391 | else layer3["server_ip4_prefix"] |
| 392 | ), |
| 393 | host_ip6_prefix=( |
| 394 | layer2["server_ip6_prefix"] |
| 395 | if x_connect_mode == "L2" |
| 396 | else layer3["server_ip6_prefix"] |
| 397 | ), |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 398 | int_type=server_if_type, |
| 399 | host_if_name=f"{server_if_type}0", |
| 400 | enable_gso=enable_server_if_gso, |
| 401 | enable_gro=enable_server_if_gro, |
| 402 | enable_checksum_offload=enable_server_if_checksum_offload, |
| 403 | ) |
| 404 | self.tap_interfaces.append(self.egress_if_idx) |
| 405 | self.egress_if_idxes.append(self.egress_if_idx) |
| 406 | self.vpp_interfaces.append(self.egress_if_idx) |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 407 | self.linux_interfaces.append( |
| 408 | [self.server_namespace, f"{server_if_type}0"] |
| 409 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 410 | # Seeing TCP timeouts if tx=on & rx=on Linux tap & tun interfaces |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 411 | disable_interface_gso(self.server_namespace, f"{server_if_type}0") |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 412 | elif server_if_type == "memif": |
| 413 | self.egress_if_idx = self.create_memif( |
| 414 | memif_id=1, mode=0 if x_connect_mode == "L2" else 1 |
| 415 | ) |
| 416 | self.memif_interfaces.append(self.egress_if_idx) |
| 417 | self.egress_if_idxes.append(self.egress_if_idx) |
| 418 | self.vpp_interfaces.append(self.egress_if_idx) |
| 419 | else: |
| 420 | print( |
| 421 | f"Unsupported server interface type: {server_if_type} " |
| 422 | f"for test - ID={test['id']}" |
| 423 | ) |
| 424 | sys.exit(1) |
| 425 | self.if_types = set(client_if_types).union(set(server_if_types)) |
| 426 | # for memif testing: tapv2, memif & libmemif_app are connected |
| 427 | if "memif" not in self.if_types: |
| 428 | if x_connect_mode == "L2": |
| 429 | self.l2_connect_interfaces(1, self.ingress_if_idx, self.egress_if_idx) |
| 430 | elif x_connect_mode == "L3": |
| 431 | # L3 connect client & server side |
| 432 | vrf_id = layer3["ip4_vrf"] if ip_version == 4 else layer3["ip6_vrf"] |
| 433 | self.l3_connect_interfaces( |
| 434 | ip_version, |
| 435 | vrf_id, |
| 436 | (self.ingress_if_idx, vpp_client_prefix), |
| 437 | (self.egress_if_idx, vpp_server_prefix), |
| 438 | ) |
| 439 | # Setup namespace routing |
| 440 | if ip_version == 4: |
| 441 | add_namespace_route( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 442 | self.client_namespace, "0.0.0.0/0", vpp_client_nexthop |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 443 | ) |
| 444 | add_namespace_route( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 445 | self.server_namespace, "0.0.0.0/0", vpp_server_nexthop |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 446 | ) |
| 447 | else: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 448 | add_namespace_route( |
| 449 | self.client_namespace, "::/0", vpp_client_nexthop |
| 450 | ) |
| 451 | add_namespace_route( |
| 452 | self.server_namespace, "::/0", vpp_server_nexthop |
| 453 | ) |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 454 | else: |
| 455 | # connect: ingress tap & memif & egress tap and memif interfaces |
| 456 | if x_connect_mode == "L2": |
| 457 | self.l2_connect_interfaces(1, *self.ingress_if_idxes) |
| 458 | self.l2_connect_interfaces(2, *self.egress_if_idxes) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 459 | # Wait for Linux IPv6 stack to become ready |
| 460 | if ip_version == 6: |
| 461 | time.sleep(2) |
| 462 | |
| 463 | def tearDown(self): |
| 464 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 465 | for interface_if_idx in self.tap_interfaces: |
| 466 | self.vapi.tap_delete_v2(sw_if_index=interface_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 467 | except Exception: |
| 468 | pass |
| 469 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 470 | for interface_if_idx in self.memif_interfaces: |
| 471 | self.vapi.memif_delete(sw_if_index=interface_if_idx) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 472 | except Exception: |
| 473 | pass |
| 474 | try: |
| 475 | for interface in self.vapi.af_packet_dump(): |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 476 | if interface.host_if_name == self.iprf_client_host_interface_on_vpp: |
| 477 | self.vapi.af_packet_delete(self.iprf_client_host_interface_on_vpp) |
| 478 | elif interface.host_if_name == self.iprf_server_host_interface_on_vpp: |
| 479 | self.vapi.af_packet_delete(self.iprf_server_host_interface_on_vpp) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 480 | except Exception: |
| 481 | pass |
| 482 | try: |
| 483 | delete_host_interfaces( |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 484 | self.iprf_client_host_interface_on_linux, |
| 485 | self.iprf_server_host_interface_on_linux, |
| 486 | self.iprf_client_host_interface_on_vpp, |
| 487 | self.iprf_server_host_interface_on_vpp, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 488 | ) |
| 489 | except Exception: |
| 490 | pass |
| 491 | try: |
BenoƮt Ganne | ff570d3 | 2024-04-16 09:36:05 +0200 | [diff] [blame] | 492 | self.vapi.ip_table_add_del_v2( |
| 493 | is_add=0, table={"table_id": layer3["ip4_vrf"]} |
| 494 | ) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 495 | except Exception: |
| 496 | pass |
| 497 | try: |
BenoƮt Ganne | ff570d3 | 2024-04-16 09:36:05 +0200 | [diff] [blame] | 498 | self.vapi.ip_table_add_del_v2( |
| 499 | is_add=0, table={"table_id": layer3["ip6_vrf"]} |
| 500 | ) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 501 | except Exception: |
| 502 | pass |
| 503 | try: |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 504 | self.vapi.bridge_domain_add_del_v2(bd_id=1, is_add=0) |
| 505 | self.vapi.bridge_domain_add_del_v2(bd_id=2, is_add=0) |
| 506 | except Exception: |
| 507 | pass |
| 508 | try: |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 509 | delete_namespace( |
| 510 | [ |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 511 | self.client_namespace, |
| 512 | self.server_namespace, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 513 | ] |
| 514 | ) |
| 515 | except Exception: |
| 516 | pass |
| 517 | try: |
Naveen Joy | 0215ef1 | 2024-01-31 08:46:18 -0800 | [diff] [blame] | 518 | if hasattr(self, "iperf_cmd"): |
| 519 | stop_iperf(" ".join(self.iperf_cmd)) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 520 | except Exception: |
| 521 | pass |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 522 | try: |
| 523 | if self.memif_process: |
| 524 | self.memif_process.terminate() |
| 525 | self.memif_process.join() |
| 526 | except Exception: |
| 527 | pass |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 528 | |
| 529 | def create_af_packet(self, version, host_if_name, enable_gso=0): |
| 530 | """Create an af_packetv3 interface in VPP. |
| 531 | |
| 532 | Parameters: |
| 533 | version -- 2 for af_packet_create_v2 |
| 534 | -- 3 for af_packet_create_v3 |
| 535 | host_if_name -- host interface name |
| 536 | enable_gso -- Enable GSO on the interface when True |
| 537 | """ |
| 538 | af_packet_mode = VppEnum.vl_api_af_packet_mode_t |
| 539 | af_packet_interface_mode = af_packet_mode.AF_PACKET_API_MODE_ETHERNET |
| 540 | af_packet_flags = VppEnum.vl_api_af_packet_flags_t |
| 541 | af_packet_interface_flags = af_packet_flags.AF_PACKET_API_FLAG_QDISC_BYPASS |
| 542 | if enable_gso: |
| 543 | af_packet_interface_flags = ( |
| 544 | af_packet_interface_flags | af_packet_flags.AF_PACKET_API_FLAG_CKSUM_GSO |
| 545 | ) |
| 546 | if version == 2: |
| 547 | af_packet_interface_flags = ( |
| 548 | af_packet_interface_flags | af_packet_flags.AF_PACKET_API_FLAG_VERSION_2 |
| 549 | ) |
| 550 | api_args = { |
| 551 | "use_random_hw_addr": True, |
| 552 | "host_if_name": host_if_name, |
| 553 | "flags": af_packet_interface_flags, |
| 554 | } |
| 555 | api_args["mode"] = af_packet_interface_mode |
| 556 | result = self.vapi.af_packet_create_v3(**api_args) |
| 557 | sw_if_index = result.sw_if_index |
| 558 | # Enable software GSO chunking when interface doesn't support GSO offload |
| 559 | if enable_gso == 0: |
| 560 | self.vapi.feature_gso_enable_disable( |
| 561 | sw_if_index=sw_if_index, enable_disable=1 |
| 562 | ) |
| 563 | else: |
| 564 | self.vapi.feature_gso_enable_disable( |
| 565 | sw_if_index=sw_if_index, enable_disable=0 |
| 566 | ) |
| 567 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 568 | return sw_if_index |
| 569 | |
| 570 | def create_tap_tun( |
| 571 | self, |
| 572 | id, |
| 573 | host_namespace, |
| 574 | ip_version, |
| 575 | host_ip4_prefix=None, |
| 576 | host_ip6_prefix=None, |
| 577 | host_ip4_gw=None, |
| 578 | host_ip6_gw=None, |
| 579 | int_type="tap", |
| 580 | host_if_name=None, |
| 581 | enable_gso=0, |
| 582 | enable_gro=0, |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 583 | enable_checksum_offload=0, |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 584 | ): |
| 585 | """Create a tapv2 or tunv2 interface in VPP and attach to host. |
| 586 | |
| 587 | Parameters: |
| 588 | id -- interface ID |
| 589 | host_namespace -- host namespace to attach the tap/tun interface to |
| 590 | ip_version -- 4 or 6 |
| 591 | host_ip4_prefix -- ipv4 host interface address in CIDR notation |
| 592 | if ip_version=4 |
| 593 | host_ip6_prefix -- ipv6 host interface address in CIDR notation |
| 594 | if ip_version=6 |
| 595 | host_ip4_gw -- host IPv4 default gateway IP Address |
| 596 | host_ip6_gw -- host IPv6 default gateway IP address |
| 597 | int_type -- "tap" for tapv2 & "tun" for tunv2 interface |
| 598 | host_if_name -- host side interface name |
| 599 | enable_gso -- enable GSO |
| 600 | enable_gro -- enable GSO/GRO-Coalesce |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 601 | enable_checksum_offload -- enable checksum offload without gso |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 602 | """ |
| 603 | TapFlags = VppEnum.vl_api_tap_flags_t |
| 604 | tap_flags = 0 |
| 605 | if int_type == "tun": |
| 606 | tap_flags = TapFlags.TAP_API_FLAG_TUN |
| 607 | if enable_gro: |
| 608 | tap_flags = tap_flags | ( |
| 609 | TapFlags.TAP_API_FLAG_GSO | TapFlags.TAP_API_FLAG_GRO_COALESCE |
| 610 | ) |
| 611 | elif enable_gso: |
| 612 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_GSO |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 613 | elif enable_checksum_offload: |
| 614 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_CSUM_OFFLOAD |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 615 | elif int_type == "tap": |
| 616 | if enable_gro: |
| 617 | tap_flags = ( |
| 618 | TapFlags.TAP_API_FLAG_GSO | TapFlags.TAP_API_FLAG_GRO_COALESCE |
| 619 | ) |
| 620 | elif enable_gso: |
| 621 | tap_flags = TapFlags.TAP_API_FLAG_GSO |
Naveen Joy | ae916b3 | 2023-06-27 14:28:57 -0700 | [diff] [blame] | 622 | elif enable_checksum_offload: |
| 623 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_CSUM_OFFLOAD |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 624 | |
| 625 | api_args = { |
| 626 | "id": id, |
| 627 | "host_namespace_set": True, |
| 628 | "host_namespace": host_namespace, |
| 629 | "host_if_name_set": False, |
| 630 | "host_bridge_set": False, |
| 631 | "host_mac_addr_set": False, |
| 632 | } |
| 633 | if tap_flags != 0: |
| 634 | api_args["tap_flags"] = tap_flags |
| 635 | if ip_version == 4: |
| 636 | api_args["host_ip4_prefix"] = ip_interface(host_ip4_prefix) |
| 637 | api_args["host_ip4_prefix_set"] = True |
| 638 | if host_ip4_gw: |
| 639 | api_args["host_ip4_gw"] = ip_address(host_ip4_gw) |
| 640 | api_args["host_ip4_gw_set"] = True |
| 641 | if ip_version == 6: |
| 642 | api_args["host_ip6_prefix"] = ip_interface(host_ip6_prefix) |
| 643 | api_args["host_ip6_prefix_set"] = True |
| 644 | if host_ip6_gw: |
| 645 | api_args["host_ip6_gw"] = ip_address(host_ip6_gw) |
| 646 | api_args["host_ip6_gw_set"] = True |
| 647 | if host_if_name: |
| 648 | api_args["host_if_name"] = host_if_name |
| 649 | api_args["host_if_name_set"] = True |
| 650 | |
| 651 | result = self.vapi.tap_create_v2(**api_args) |
| 652 | sw_if_index = result.sw_if_index |
| 653 | # Enable software GSO chunking when interface doesn't support GSO offload and |
| 654 | # GRO coalesce |
| 655 | if enable_gso == 0 and enable_gro == 0: |
| 656 | self.vapi.feature_gso_enable_disable( |
| 657 | sw_if_index=sw_if_index, enable_disable=1 |
| 658 | ) |
| 659 | else: |
| 660 | self.vapi.feature_gso_enable_disable( |
| 661 | sw_if_index=sw_if_index, enable_disable=0 |
| 662 | ) |
| 663 | # Admin up |
| 664 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 665 | return sw_if_index |
| 666 | |
Naveen Joy | 70335e8 | 2023-07-28 16:33:30 -0700 | [diff] [blame] | 667 | def create_memif(self, memif_id, mode): |
| 668 | """Create memif interface in VPP. |
| 669 | |
| 670 | Parameters: |
| 671 | memif_id: A unique ID for the memif interface |
| 672 | mode: 0 = ethernet, 1 = ip, 2 = punt/inject |
| 673 | """ |
| 674 | # create memif interface with role=0 (i.e. master) |
| 675 | result = self.vapi.memif_create_v2( |
| 676 | role=0, mode=mode, id=memif_id, buffer_size=9216 |
| 677 | ) |
| 678 | sw_if_index = result.sw_if_index |
| 679 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 680 | return sw_if_index |
| 681 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 682 | def dump_bridge_domain_details(self, bd_id): |
| 683 | return self.vapi.bridge_domain_dump(bd_id=bd_id) |
| 684 | |
| 685 | def l2_connect_interfaces(self, bridge_id, *sw_if_idxs): |
| 686 | for if_idx in sw_if_idxs: |
| 687 | self.vapi.sw_interface_set_l2_bridge( |
| 688 | rx_sw_if_index=if_idx, bd_id=bridge_id, shg=0, port_type=0, enable=True |
| 689 | ) |
| 690 | |
| 691 | def l3_connect_interfaces(self, ip_version, vrf_id, *if_idx_ip_prefixes): |
| 692 | """Setup routing for (if_idx, ip_prefix) inside VPP. |
| 693 | |
| 694 | arguments: |
| 695 | if_idx_ip_prefixes -- sequence of (if_idx, ip_prefix) tuples |
| 696 | ip_version -- 4 or 6 |
| 697 | vrf_id -- vrf_id |
| 698 | """ |
| 699 | is_ipv6 = 0 if ip_version == 4 else 1 |
BenoƮt Ganne | ff570d3 | 2024-04-16 09:36:05 +0200 | [diff] [blame] | 700 | self.vapi.ip_table_add_del_v2( |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 701 | is_add=1, table={"table_id": vrf_id, "is_ip6": is_ipv6} |
| 702 | ) |
| 703 | for sw_if_index, ip_prefix in if_idx_ip_prefixes: |
| 704 | self.vapi.sw_interface_set_table( |
| 705 | sw_if_index=sw_if_index, is_ipv6=is_ipv6, vrf_id=vrf_id |
| 706 | ) |
| 707 | self.vapi.sw_interface_add_del_address( |
| 708 | sw_if_index=sw_if_index, is_add=1, prefix=ip_interface(ip_prefix) |
| 709 | ) |
| 710 | |
| 711 | def set_interfaces_mtu(self, mtu, ip_version, **kwargs): |
| 712 | """Set MTUs on VPP and Linux interfaces. |
| 713 | |
| 714 | arguments -- |
| 715 | mtu -- mtu value |
| 716 | ip_version - 4 or 6 |
| 717 | kwargs['vpp_interfaces'] -- list of vpp interface if indexes |
| 718 | kwargs['linux_interfaces'] -- list of tuples (namespace, interface_names) |
| 719 | return True if mtu is set, else False |
| 720 | """ |
| 721 | vpp_interfaces = kwargs.get("vpp_interfaces") |
| 722 | linux_interfaces = kwargs.get("linux_interfaces") |
| 723 | # IPv6 on Linux requires an MTU value >=1280 |
| 724 | if (ip_version == 6 and mtu >= 1280) or ip_version == 4: |
| 725 | for sw_if_idx in vpp_interfaces: |
| 726 | self.vapi.sw_interface_set_mtu( |
| 727 | sw_if_index=sw_if_idx, mtu=[mtu, 0, 0, 0] |
| 728 | ) |
| 729 | for namespace, interface_name in linux_interfaces: |
| 730 | set_interface_mtu( |
| 731 | namespace=namespace, |
| 732 | interface=interface_name, |
| 733 | mtu=mtu, |
| 734 | logger=self.logger, |
| 735 | ) |
| 736 | return True |
| 737 | else: |
| 738 | return False |
| 739 | |
| 740 | |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 741 | if __name__ == "__main__": |
| 742 | unittest.main(testRunner=VppTestRunner) |