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, |
| 12 | ) |
| 13 | from vpp_iperf import start_iperf, stop_iperf |
| 14 | from framework import VppTestCase, VppTestRunner |
| 15 | from config import config |
| 16 | from vpp_papi import VppEnum |
| 17 | import time |
| 18 | import sys |
| 19 | from vm_test_config import test_config |
| 20 | |
| 21 | # |
| 22 | # Tests for: |
| 23 | # - tapv2, tunv2 & af_packet_v2 & v3 interfaces. |
| 24 | # - reads test config from the file vm_test_config.py |
| 25 | # - Uses iPerf to send TCP/IP streams to VPP |
| 26 | # - VPP ingress interface runs the iperf client |
| 27 | # - VPP egress interface runs the iperf server |
| 28 | # - Runs tests specified in the vm_test_config module and verifies that: |
| 29 | # - TCP over IPv4 and IPv6 is enabled correctly for Bridged and Routed topologies. |
| 30 | # sending jumbo frames (9000/9001 MTUs) with GSO/GRO is enabled correctly. |
| 31 | # sending VPP buffer-sized frames(2048 MTU) with GSO/GRO is enabled correctly. |
| 32 | # sending standard frames (1500 MTU) with GSO/GRO is enabled correctly. |
| 33 | # sending smaller frames (512 MTU) with GSO/GRO is enabled correctly for IPv4 |
| 34 | # sending odd sized frames (9001, 2049 MTU) with GSO/GRO is enabled correctly. |
| 35 | # |
| 36 | |
| 37 | |
| 38 | def filter_tests(test): |
| 39 | """Filter test IDs to include only those selected to run.""" |
| 40 | selection = test_config["tests_to_run"] |
| 41 | if not selection or selection == " ": |
| 42 | return True |
| 43 | else: |
| 44 | test_ids_to_run = [] |
| 45 | for test_id in selection.split(","): |
| 46 | if "-" in test_id.strip(): |
| 47 | start, end = map(int, test_id.split("-")) |
| 48 | test_ids_to_run.extend(list(range(start, end + 1))) |
| 49 | elif test_id.strip(): |
| 50 | test_ids_to_run.append(int(test_id)) |
| 51 | return test["id"] in test_ids_to_run |
| 52 | |
| 53 | |
| 54 | # Test Config variables |
| 55 | client_namespace = test_config["client_namespace"] |
| 56 | server_namespace = test_config["server_namespace"] |
| 57 | tests = filter(filter_tests, test_config["tests"]) |
| 58 | af_packet_config = test_config["af_packet"] |
| 59 | layer2 = test_config["L2"] |
| 60 | layer3 = test_config["L3"] |
| 61 | |
| 62 | |
| 63 | def create_test(test_name, test, ip_version, mtu): |
| 64 | """Create and return a unittest method for a test.""" |
| 65 | |
Andrew Yourtchenko | 9ba6dcf | 2023-06-20 14:52:08 +0000 | [diff] [blame] | 66 | @unittest.skipIf( |
| 67 | config.skip_netns_tests, "netns not available or disabled from cli" |
| 68 | ) |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 69 | def test_func(self): |
| 70 | self.logger.debug(f"Starting unittest:{test_name}") |
| 71 | self.setUpTestToplogy(test=test, ip_version=ip_version) |
| 72 | result = self.set_interfaces_mtu( |
| 73 | mtu=mtu, |
| 74 | ip_version=ip_version, |
| 75 | vpp_interfaces=self.vpp_interfaces, |
| 76 | linux_interfaces=self.linux_interfaces, |
| 77 | ) |
| 78 | # Start the Iperf server in dual stack mode & run iperf client |
| 79 | if result is True: |
| 80 | start_iperf(ip_version=6, server_only=True, logger=self.logger) |
| 81 | self.assertTrue( |
| 82 | start_iperf( |
| 83 | ip_version=ip_version, |
| 84 | server_ipv4_address=self.server_ip4_address, |
| 85 | server_ipv6_address=self.server_ip6_address, |
| 86 | client_only=True, |
| 87 | duration=2, |
| 88 | logger=self.logger, |
| 89 | ) |
| 90 | ) |
| 91 | else: |
| 92 | print( |
| 93 | f"Skipping test:{test_name} as mtu:{mtu} is " |
| 94 | f"invalid for TCP/IPv{ip_version}" |
| 95 | ) |
| 96 | |
| 97 | test_func.__name__ = test_name |
| 98 | return test_func |
| 99 | |
| 100 | |
| 101 | def generate_vpp_interface_tests(): |
| 102 | """Generate unittests for testing vpp interfaces.""" |
Andrew Yourtchenko | 9ba6dcf | 2023-06-20 14:52:08 +0000 | [diff] [blame] | 103 | if config.skip_netns_tests: |
| 104 | print("Skipping netns tests") |
Naveen Joy | e416893 | 2022-10-04 14:22:05 -0700 | [diff] [blame] | 105 | for test in tests: |
| 106 | for ip_version in test_config["ip_versions"]: |
| 107 | for mtu in test_config["mtus"]: |
| 108 | test_name = ( |
| 109 | f"test_id_{test['id']}_" |
| 110 | + f"client_{test['client_if_type']}" |
| 111 | + f"_v{test['client_if_version']}_" |
| 112 | + f"gso_{test.get('client_if_gso', 0)}_" |
| 113 | + f"gro_{test.get('client_if_gro', 0)}_" |
| 114 | + f"to_server_{test['server_if_type']}" |
| 115 | + f"_v{test['server_if_version']}_" |
| 116 | + f"gso_{test.get('server_if_gso', 0)}_" |
| 117 | + f"gro_{test.get('server_if_gro', 0)}_" |
| 118 | + f"mtu_{mtu}_mode_{test['x_connect_mode']}_" |
| 119 | + f"tcp_ipv{ip_version}" |
| 120 | ) |
| 121 | test_func = create_test( |
| 122 | test_name=test_name, test=test, ip_version=ip_version, mtu=mtu |
| 123 | ) |
| 124 | setattr(TestVPPInterfacesQemu, test_name, test_func) |
| 125 | |
| 126 | |
| 127 | class TestVPPInterfacesQemu(VppTestCase): |
| 128 | """Test VPP interfaces inside a QEMU VM for IPv4/v6. |
| 129 | |
| 130 | Test Setup: |
| 131 | Linux_ns1--iperfClient--host-int1--vpp-af_packet-int1--VPP-BD |
| 132 | --vppaf_packet_int2--host-int2--iperfServer--Linux_ns2 |
| 133 | """ |
| 134 | |
| 135 | @classmethod |
| 136 | def setUpClass(cls): |
| 137 | super(TestVPPInterfacesQemu, cls).setUpClass() |
| 138 | |
| 139 | @classmethod |
| 140 | def tearDownClass(cls): |
| 141 | super(TestVPPInterfacesQemu, cls).tearDownClass() |
| 142 | |
| 143 | def setUpTestToplogy(self, test, ip_version): |
| 144 | """Setup the test topology. |
| 145 | |
| 146 | 1. Create Linux Namespaces for iPerf Client & Server. |
| 147 | 2. Create VPP iPerf client and server virtual interfaces. |
| 148 | 3. Enable desired vif features such as GSO & GRO. |
| 149 | 3. Cross-Connect interfaces in VPP using L2 or L3. |
| 150 | """ |
| 151 | super(TestVPPInterfacesQemu, self).setUp() |
| 152 | client_if_type = test["client_if_type"] |
| 153 | server_if_type = test["server_if_type"] |
| 154 | client_if_version = test["client_if_version"] |
| 155 | server_if_version = test["server_if_version"] |
| 156 | x_connect_mode = test["x_connect_mode"] |
| 157 | # server ip4/ip6 addresses required by iperf client |
| 158 | server_ip4_prefix = ( |
| 159 | layer2["server_ip4_prefix"] |
| 160 | if x_connect_mode == "L2" |
| 161 | else layer3["server_ip4_prefix"] |
| 162 | ) |
| 163 | server_ip6_prefix = ( |
| 164 | layer2["server_ip6_prefix"] |
| 165 | if x_connect_mode == "L2" |
| 166 | else layer3["server_ip6_prefix"] |
| 167 | ) |
| 168 | self.server_ip4_address = str(ip_interface(server_ip4_prefix).ip) |
| 169 | self.server_ip6_address = str(ip_interface(server_ip6_prefix).ip) |
| 170 | # next-hop IP address on VPP for routing from client & server namespaces |
| 171 | vpp_client_prefix = ( |
| 172 | layer3["vpp_client_ip4_prefix"] |
| 173 | if ip_version == 4 |
| 174 | else layer3["vpp_client_ip6_prefix"] |
| 175 | ) |
| 176 | vpp_client_nexthop = str(ip_interface(vpp_client_prefix).ip) |
| 177 | vpp_server_prefix = ( |
| 178 | layer3["vpp_server_ip4_prefix"] |
| 179 | if ip_version == 4 |
| 180 | else layer3["vpp_server_ip6_prefix"] |
| 181 | ) |
| 182 | vpp_server_nexthop = str(ip_interface(vpp_server_prefix).ip) |
| 183 | create_namespace([client_namespace, server_namespace]) |
| 184 | self.vpp_interfaces = [] |
| 185 | self.linux_interfaces = [] |
| 186 | enable_client_if_gso = test.get("client_if_gso", 0) |
| 187 | enable_server_if_gso = test.get("server_if_gso", 0) |
| 188 | enable_client_if_gro = test.get("client_if_gro", 0) |
| 189 | enable_server_if_gro = test.get("server_if_gro", 0) |
| 190 | ## Handle client interface types |
| 191 | if client_if_type == "af_packet": |
| 192 | create_host_interface( |
| 193 | af_packet_config["iprf_client_interface_on_linux"], |
| 194 | af_packet_config["iprf_client_interface_on_vpp"], |
| 195 | client_namespace, |
| 196 | layer2["client_ip4_prefix"] |
| 197 | if x_connect_mode == "L2" |
| 198 | else layer3["client_ip4_prefix"], |
| 199 | layer2["client_ip6_prefix"] |
| 200 | if x_connect_mode == "L2" |
| 201 | else layer3["client_ip6_prefix"], |
| 202 | ) |
| 203 | self.ingress_if_idx = self.create_af_packet( |
| 204 | version=client_if_version, |
| 205 | host_if_name=af_packet_config["iprf_client_interface_on_vpp"], |
| 206 | enable_gso=enable_client_if_gso, |
| 207 | ) |
| 208 | self.vpp_interfaces.append(self.ingress_if_idx) |
| 209 | self.linux_interfaces.append( |
| 210 | ["", af_packet_config["iprf_client_interface_on_vpp"]] |
| 211 | ) |
| 212 | self.linux_interfaces.append( |
| 213 | [client_namespace, af_packet_config["iprf_client_interface_on_linux"]] |
| 214 | ) |
| 215 | if enable_client_if_gso == 0: |
| 216 | disable_interface_gso( |
| 217 | "", af_packet_config["iprf_client_interface_on_vpp"] |
| 218 | ) |
| 219 | disable_interface_gso( |
| 220 | client_namespace, af_packet_config["iprf_client_interface_on_linux"] |
| 221 | ) |
| 222 | elif client_if_type == "tap" or client_if_type == "tun": |
| 223 | self.ingress_if_idx = self.create_tap_tun( |
| 224 | id=101, |
| 225 | host_namespace=client_namespace, |
| 226 | ip_version=ip_version, |
| 227 | host_ip4_prefix=layer2["client_ip4_prefix"] |
| 228 | if x_connect_mode == "L2" |
| 229 | else layer3["client_ip4_prefix"], |
| 230 | host_ip6_prefix=layer2["client_ip6_prefix"] |
| 231 | if x_connect_mode == "L2" |
| 232 | else layer3["client_ip6_prefix"], |
| 233 | host_ip4_gw=vpp_client_nexthop |
| 234 | if x_connect_mode == "L3" and ip_version == 4 |
| 235 | else None, |
| 236 | host_ip6_gw=vpp_client_nexthop |
| 237 | if x_connect_mode == "L3" and ip_version == 6 |
| 238 | else None, |
| 239 | int_type=client_if_type, |
| 240 | host_if_name=f"{client_if_type}0", |
| 241 | enable_gso=enable_client_if_gso, |
| 242 | enable_gro=enable_client_if_gro, |
| 243 | ) |
| 244 | self.vpp_interfaces.append(self.ingress_if_idx) |
| 245 | self.linux_interfaces.append([client_namespace, f"{client_if_type}0"]) |
| 246 | # Seeing TCP timeouts if tx=on & rx=on Linux tap & tun interfaces |
| 247 | disable_interface_gso(client_namespace, f"{client_if_type}0") |
| 248 | else: |
| 249 | print( |
| 250 | f"Unsupported client interface type: {client_if_type} " |
| 251 | f"for test - ID={test['id']}" |
| 252 | ) |
| 253 | sys.exit(1) |
| 254 | |
| 255 | if server_if_type == "af_packet": |
| 256 | create_host_interface( |
| 257 | af_packet_config["iprf_server_interface_on_linux"], |
| 258 | af_packet_config["iprf_server_interface_on_vpp"], |
| 259 | server_namespace, |
| 260 | server_ip4_prefix, |
| 261 | server_ip6_prefix, |
| 262 | ) |
| 263 | self.egress_if_idx = self.create_af_packet( |
| 264 | version=server_if_version, |
| 265 | host_if_name=af_packet_config["iprf_server_interface_on_vpp"], |
| 266 | enable_gso=enable_server_if_gso, |
| 267 | ) |
| 268 | self.vpp_interfaces.append(self.egress_if_idx) |
| 269 | self.linux_interfaces.append( |
| 270 | ["", af_packet_config["iprf_server_interface_on_vpp"]] |
| 271 | ) |
| 272 | self.linux_interfaces.append( |
| 273 | [server_namespace, af_packet_config["iprf_server_interface_on_linux"]] |
| 274 | ) |
| 275 | if enable_server_if_gso == 0: |
| 276 | disable_interface_gso( |
| 277 | "", af_packet_config["iprf_server_interface_on_vpp"] |
| 278 | ) |
| 279 | disable_interface_gso( |
| 280 | server_namespace, af_packet_config["iprf_server_interface_on_linux"] |
| 281 | ) |
| 282 | elif server_if_type == "tap" or server_if_type == "tun": |
| 283 | self.egress_if_idx = self.create_tap_tun( |
| 284 | id=102, |
| 285 | host_namespace=server_namespace, |
| 286 | ip_version=ip_version, |
| 287 | host_ip4_prefix=layer2["server_ip4_prefix"] |
| 288 | if x_connect_mode == "L2" |
| 289 | else layer3["server_ip4_prefix"], |
| 290 | host_ip6_prefix=layer2["server_ip6_prefix"] |
| 291 | if x_connect_mode == "L2" |
| 292 | else layer3["server_ip6_prefix"], |
| 293 | int_type=server_if_type, |
| 294 | host_if_name=f"{server_if_type}0", |
| 295 | enable_gso=enable_server_if_gso, |
| 296 | enable_gro=enable_server_if_gro, |
| 297 | ) |
| 298 | self.vpp_interfaces.append(self.egress_if_idx) |
| 299 | self.linux_interfaces.append([server_namespace, f"{server_if_type}0"]) |
| 300 | # Seeing TCP timeouts if tx=on & rx=on Linux tap & tun interfaces |
| 301 | disable_interface_gso(server_namespace, f"{server_if_type}0") |
| 302 | else: |
| 303 | print( |
| 304 | f"Unsupported server interface type: {server_if_type} " |
| 305 | f"for test - ID={test['id']}" |
| 306 | ) |
| 307 | sys.exit(1) |
| 308 | |
| 309 | if x_connect_mode == "L2": |
| 310 | self.l2_connect_interfaces(1, self.ingress_if_idx, self.egress_if_idx) |
| 311 | elif x_connect_mode == "L3": |
| 312 | # L3 connect client & server side |
| 313 | vrf_id = layer3["ip4_vrf"] if ip_version == 4 else layer3["ip6_vrf"] |
| 314 | self.l3_connect_interfaces( |
| 315 | ip_version, |
| 316 | vrf_id, |
| 317 | (self.ingress_if_idx, vpp_client_prefix), |
| 318 | (self.egress_if_idx, vpp_server_prefix), |
| 319 | ) |
| 320 | # Setup namespace routing |
| 321 | if ip_version == 4: |
| 322 | add_namespace_route(client_namespace, "0.0.0.0/0", vpp_client_nexthop) |
| 323 | add_namespace_route(server_namespace, "0.0.0.0/0", vpp_server_nexthop) |
| 324 | else: |
| 325 | add_namespace_route(client_namespace, "::/0", vpp_client_nexthop) |
| 326 | add_namespace_route(server_namespace, "::/0", vpp_server_nexthop) |
| 327 | # Wait for Linux IPv6 stack to become ready |
| 328 | if ip_version == 6: |
| 329 | time.sleep(2) |
| 330 | |
| 331 | def tearDown(self): |
| 332 | try: |
| 333 | self.vapi.tap_delete_v2(self.ingress_if_idx) |
| 334 | except Exception: |
| 335 | pass |
| 336 | try: |
| 337 | self.vapi.tap_delete_v2(self.egress_if_idx) |
| 338 | except Exception: |
| 339 | pass |
| 340 | try: |
| 341 | for interface in self.vapi.af_packet_dump(): |
| 342 | if ( |
| 343 | interface.host_if_name |
| 344 | == af_packet_config["iprf_client_interface_on_vpp"] |
| 345 | ): |
| 346 | self.vapi.af_packet_delete( |
| 347 | af_packet_config["iprf_client_interface_on_vpp"] |
| 348 | ) |
| 349 | elif ( |
| 350 | interface.host_if_name |
| 351 | == af_packet_config["iprf_server_interface_on_vpp"] |
| 352 | ): |
| 353 | self.vapi.af_packet_delete( |
| 354 | af_packet_config["iprf_server_interface_on_vpp"] |
| 355 | ) |
| 356 | except Exception: |
| 357 | pass |
| 358 | try: |
| 359 | delete_host_interfaces( |
| 360 | af_packet_config["iprf_client_interface_on_linux"], |
| 361 | af_packet_config["iprf_server_interface_on_linux"], |
| 362 | af_packet_config["iprf_client_interface_on_vpp"], |
| 363 | af_packet_config["iprf_server_interface_on_vpp"], |
| 364 | ) |
| 365 | except Exception: |
| 366 | pass |
| 367 | try: |
| 368 | self.vapi.ip_table_add_del(is_add=0, table={"table_id": layer3["ip4_vrf"]}) |
| 369 | except Exception: |
| 370 | pass |
| 371 | try: |
| 372 | self.vapi.ip_table_add_del(is_add=0, table={"table_id": layer3["ip6_vrf"]}) |
| 373 | except Exception: |
| 374 | pass |
| 375 | try: |
| 376 | delete_namespace( |
| 377 | [ |
| 378 | client_namespace, |
| 379 | server_namespace, |
| 380 | ] |
| 381 | ) |
| 382 | except Exception: |
| 383 | pass |
| 384 | try: |
| 385 | stop_iperf() |
| 386 | except Exception: |
| 387 | pass |
| 388 | |
| 389 | def create_af_packet(self, version, host_if_name, enable_gso=0): |
| 390 | """Create an af_packetv3 interface in VPP. |
| 391 | |
| 392 | Parameters: |
| 393 | version -- 2 for af_packet_create_v2 |
| 394 | -- 3 for af_packet_create_v3 |
| 395 | host_if_name -- host interface name |
| 396 | enable_gso -- Enable GSO on the interface when True |
| 397 | """ |
| 398 | af_packet_mode = VppEnum.vl_api_af_packet_mode_t |
| 399 | af_packet_interface_mode = af_packet_mode.AF_PACKET_API_MODE_ETHERNET |
| 400 | af_packet_flags = VppEnum.vl_api_af_packet_flags_t |
| 401 | af_packet_interface_flags = af_packet_flags.AF_PACKET_API_FLAG_QDISC_BYPASS |
| 402 | if enable_gso: |
| 403 | af_packet_interface_flags = ( |
| 404 | af_packet_interface_flags | af_packet_flags.AF_PACKET_API_FLAG_CKSUM_GSO |
| 405 | ) |
| 406 | if version == 2: |
| 407 | af_packet_interface_flags = ( |
| 408 | af_packet_interface_flags | af_packet_flags.AF_PACKET_API_FLAG_VERSION_2 |
| 409 | ) |
| 410 | api_args = { |
| 411 | "use_random_hw_addr": True, |
| 412 | "host_if_name": host_if_name, |
| 413 | "flags": af_packet_interface_flags, |
| 414 | } |
| 415 | api_args["mode"] = af_packet_interface_mode |
| 416 | result = self.vapi.af_packet_create_v3(**api_args) |
| 417 | sw_if_index = result.sw_if_index |
| 418 | # Enable software GSO chunking when interface doesn't support GSO offload |
| 419 | if enable_gso == 0: |
| 420 | self.vapi.feature_gso_enable_disable( |
| 421 | sw_if_index=sw_if_index, enable_disable=1 |
| 422 | ) |
| 423 | else: |
| 424 | self.vapi.feature_gso_enable_disable( |
| 425 | sw_if_index=sw_if_index, enable_disable=0 |
| 426 | ) |
| 427 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 428 | return sw_if_index |
| 429 | |
| 430 | def create_tap_tun( |
| 431 | self, |
| 432 | id, |
| 433 | host_namespace, |
| 434 | ip_version, |
| 435 | host_ip4_prefix=None, |
| 436 | host_ip6_prefix=None, |
| 437 | host_ip4_gw=None, |
| 438 | host_ip6_gw=None, |
| 439 | int_type="tap", |
| 440 | host_if_name=None, |
| 441 | enable_gso=0, |
| 442 | enable_gro=0, |
| 443 | ): |
| 444 | """Create a tapv2 or tunv2 interface in VPP and attach to host. |
| 445 | |
| 446 | Parameters: |
| 447 | id -- interface ID |
| 448 | host_namespace -- host namespace to attach the tap/tun interface to |
| 449 | ip_version -- 4 or 6 |
| 450 | host_ip4_prefix -- ipv4 host interface address in CIDR notation |
| 451 | if ip_version=4 |
| 452 | host_ip6_prefix -- ipv6 host interface address in CIDR notation |
| 453 | if ip_version=6 |
| 454 | host_ip4_gw -- host IPv4 default gateway IP Address |
| 455 | host_ip6_gw -- host IPv6 default gateway IP address |
| 456 | int_type -- "tap" for tapv2 & "tun" for tunv2 interface |
| 457 | host_if_name -- host side interface name |
| 458 | enable_gso -- enable GSO |
| 459 | enable_gro -- enable GSO/GRO-Coalesce |
| 460 | """ |
| 461 | TapFlags = VppEnum.vl_api_tap_flags_t |
| 462 | tap_flags = 0 |
| 463 | if int_type == "tun": |
| 464 | tap_flags = TapFlags.TAP_API_FLAG_TUN |
| 465 | if enable_gro: |
| 466 | tap_flags = tap_flags | ( |
| 467 | TapFlags.TAP_API_FLAG_GSO | TapFlags.TAP_API_FLAG_GRO_COALESCE |
| 468 | ) |
| 469 | elif enable_gso: |
| 470 | tap_flags = tap_flags | TapFlags.TAP_API_FLAG_GSO |
| 471 | elif int_type == "tap": |
| 472 | if enable_gro: |
| 473 | tap_flags = ( |
| 474 | TapFlags.TAP_API_FLAG_GSO | TapFlags.TAP_API_FLAG_GRO_COALESCE |
| 475 | ) |
| 476 | elif enable_gso: |
| 477 | tap_flags = TapFlags.TAP_API_FLAG_GSO |
| 478 | |
| 479 | api_args = { |
| 480 | "id": id, |
| 481 | "host_namespace_set": True, |
| 482 | "host_namespace": host_namespace, |
| 483 | "host_if_name_set": False, |
| 484 | "host_bridge_set": False, |
| 485 | "host_mac_addr_set": False, |
| 486 | } |
| 487 | if tap_flags != 0: |
| 488 | api_args["tap_flags"] = tap_flags |
| 489 | if ip_version == 4: |
| 490 | api_args["host_ip4_prefix"] = ip_interface(host_ip4_prefix) |
| 491 | api_args["host_ip4_prefix_set"] = True |
| 492 | if host_ip4_gw: |
| 493 | api_args["host_ip4_gw"] = ip_address(host_ip4_gw) |
| 494 | api_args["host_ip4_gw_set"] = True |
| 495 | if ip_version == 6: |
| 496 | api_args["host_ip6_prefix"] = ip_interface(host_ip6_prefix) |
| 497 | api_args["host_ip6_prefix_set"] = True |
| 498 | if host_ip6_gw: |
| 499 | api_args["host_ip6_gw"] = ip_address(host_ip6_gw) |
| 500 | api_args["host_ip6_gw_set"] = True |
| 501 | if host_if_name: |
| 502 | api_args["host_if_name"] = host_if_name |
| 503 | api_args["host_if_name_set"] = True |
| 504 | |
| 505 | result = self.vapi.tap_create_v2(**api_args) |
| 506 | sw_if_index = result.sw_if_index |
| 507 | # Enable software GSO chunking when interface doesn't support GSO offload and |
| 508 | # GRO coalesce |
| 509 | if enable_gso == 0 and enable_gro == 0: |
| 510 | self.vapi.feature_gso_enable_disable( |
| 511 | sw_if_index=sw_if_index, enable_disable=1 |
| 512 | ) |
| 513 | else: |
| 514 | self.vapi.feature_gso_enable_disable( |
| 515 | sw_if_index=sw_if_index, enable_disable=0 |
| 516 | ) |
| 517 | # Admin up |
| 518 | self.vapi.sw_interface_set_flags(sw_if_index=sw_if_index, flags=1) |
| 519 | return sw_if_index |
| 520 | |
| 521 | def dump_bridge_domain_details(self, bd_id): |
| 522 | return self.vapi.bridge_domain_dump(bd_id=bd_id) |
| 523 | |
| 524 | def l2_connect_interfaces(self, bridge_id, *sw_if_idxs): |
| 525 | for if_idx in sw_if_idxs: |
| 526 | self.vapi.sw_interface_set_l2_bridge( |
| 527 | rx_sw_if_index=if_idx, bd_id=bridge_id, shg=0, port_type=0, enable=True |
| 528 | ) |
| 529 | |
| 530 | def l3_connect_interfaces(self, ip_version, vrf_id, *if_idx_ip_prefixes): |
| 531 | """Setup routing for (if_idx, ip_prefix) inside VPP. |
| 532 | |
| 533 | arguments: |
| 534 | if_idx_ip_prefixes -- sequence of (if_idx, ip_prefix) tuples |
| 535 | ip_version -- 4 or 6 |
| 536 | vrf_id -- vrf_id |
| 537 | """ |
| 538 | is_ipv6 = 0 if ip_version == 4 else 1 |
| 539 | self.vapi.ip_table_add_del( |
| 540 | is_add=1, table={"table_id": vrf_id, "is_ip6": is_ipv6} |
| 541 | ) |
| 542 | for sw_if_index, ip_prefix in if_idx_ip_prefixes: |
| 543 | self.vapi.sw_interface_set_table( |
| 544 | sw_if_index=sw_if_index, is_ipv6=is_ipv6, vrf_id=vrf_id |
| 545 | ) |
| 546 | self.vapi.sw_interface_add_del_address( |
| 547 | sw_if_index=sw_if_index, is_add=1, prefix=ip_interface(ip_prefix) |
| 548 | ) |
| 549 | |
| 550 | def set_interfaces_mtu(self, mtu, ip_version, **kwargs): |
| 551 | """Set MTUs on VPP and Linux interfaces. |
| 552 | |
| 553 | arguments -- |
| 554 | mtu -- mtu value |
| 555 | ip_version - 4 or 6 |
| 556 | kwargs['vpp_interfaces'] -- list of vpp interface if indexes |
| 557 | kwargs['linux_interfaces'] -- list of tuples (namespace, interface_names) |
| 558 | return True if mtu is set, else False |
| 559 | """ |
| 560 | vpp_interfaces = kwargs.get("vpp_interfaces") |
| 561 | linux_interfaces = kwargs.get("linux_interfaces") |
| 562 | # IPv6 on Linux requires an MTU value >=1280 |
| 563 | if (ip_version == 6 and mtu >= 1280) or ip_version == 4: |
| 564 | for sw_if_idx in vpp_interfaces: |
| 565 | self.vapi.sw_interface_set_mtu( |
| 566 | sw_if_index=sw_if_idx, mtu=[mtu, 0, 0, 0] |
| 567 | ) |
| 568 | for namespace, interface_name in linux_interfaces: |
| 569 | set_interface_mtu( |
| 570 | namespace=namespace, |
| 571 | interface=interface_name, |
| 572 | mtu=mtu, |
| 573 | logger=self.logger, |
| 574 | ) |
| 575 | return True |
| 576 | else: |
| 577 | return False |
| 578 | |
| 579 | |
| 580 | generate_vpp_interface_tests() |
| 581 | |
| 582 | if __name__ == "__main__": |
| 583 | unittest.main(testRunner=VppTestRunner) |