|
| 1 | +# SPDX-License-Identifier: BSD-3-Clause |
| 2 | +# Copyright(c) 2025 University of New Hampshire |
| 3 | + |
| 4 | +"""Single core forwarding performance test suite. |
| 5 | +
|
| 6 | +This suite measures the amount of packets which can be forwarded by DPDK using a single core. |
| 7 | +The testsuites takes in as parameters a set of parameters, each consisting of a frame size, |
| 8 | +Tx/Rx descriptor count, and the expected MPPS to be forwarded by the DPDK application. The |
| 9 | +test leverages a performance traffic generator to send traffic at two paired TestPMD interfaces |
| 10 | +on the SUT system, which forward to one another and then back to the traffic generator's ports. |
| 11 | +The aggregate packets forwarded by the two TestPMD ports are compared against the expected MPPS |
| 12 | +baseline which is given in the test config, in order to determine the test result. |
| 13 | +""" |
| 14 | + |
| 15 | +from scapy.layers.inet import IP |
| 16 | +from scapy.layers.l2 import Ether |
| 17 | +from scapy.packet import Raw |
| 18 | + |
| 19 | +from api.capabilities import ( |
| 20 | + LinkTopology, |
| 21 | + requires_link_topology, |
| 22 | +) |
| 23 | +from api.packet import assess_performance_by_packet |
| 24 | +from api.test import verify, write_performance_json |
| 25 | +from api.testpmd import TestPmd |
| 26 | +from api.testpmd.config import RXRingParams, TXRingParams |
| 27 | +from framework.params.types import TestPmdParamsDict |
| 28 | +from framework.test_suite import BaseConfig, TestSuite, perf_test |
| 29 | + |
| 30 | + |
| 31 | +class Config(BaseConfig): |
| 32 | + """Performance test metrics.""" |
| 33 | + |
| 34 | + test_parameters: list[dict[str, int | float]] = [ |
| 35 | + {"frame_size": 64, "num_descriptors": 1024, "expected_mpps": 1.00}, |
| 36 | + {"frame_size": 128, "num_descriptors": 1024, "expected_mpps": 1.00}, |
| 37 | + {"frame_size": 256, "num_descriptors": 1024, "expected_mpps": 1.00}, |
| 38 | + {"frame_size": 512, "num_descriptors": 1024, "expected_mpps": 1.00}, |
| 39 | + {"frame_size": 1024, "num_descriptors": 1024, "expected_mpps": 1.00}, |
| 40 | + {"frame_size": 1518, "num_descriptors": 1024, "expected_mpps": 1.00}, |
| 41 | + ] |
| 42 | + delta_tolerance: float = 0.05 |
| 43 | + |
| 44 | + |
| 45 | +@requires_link_topology(LinkTopology.TWO_LINKS) |
| 46 | +class TestSingleCoreForwardPerf(TestSuite): |
| 47 | + """Single core forwarding performance test suite.""" |
| 48 | + |
| 49 | + config: Config |
| 50 | + |
| 51 | + def set_up_suite(self): |
| 52 | + """Set up the test suite.""" |
| 53 | + self.test_parameters = self.config.test_parameters |
| 54 | + self.delta_tolerance = self.config.delta_tolerance |
| 55 | + |
| 56 | + def _transmit(self, testpmd: TestPmd, frame_size: int) -> float: |
| 57 | + """Create a testpmd session with every rule in the given list, verify jump behavior. |
| 58 | +
|
| 59 | + Args: |
| 60 | + testpmd: The testpmd shell to use for forwarding packets. |
| 61 | + frame_size: The size of the frame to transmit. |
| 62 | +
|
| 63 | + Returns: |
| 64 | + The MPPS (millions of packets per second) forwarded by the SUT. |
| 65 | + """ |
| 66 | + # Build packet with dummy values, and account for the 14B and 20B Ether and IP headers |
| 67 | + packet = ( |
| 68 | + Ether(src="52:00:00:00:00:00") |
| 69 | + / IP(src="1.2.3.4", dst="192.18.1.0") |
| 70 | + / Raw(load="x" * (frame_size - 14 - 20)) |
| 71 | + ) |
| 72 | + |
| 73 | + testpmd.start() |
| 74 | + |
| 75 | + # Transmit for 30 seconds. |
| 76 | + stats = assess_performance_by_packet(packet=packet, duration=30) |
| 77 | + |
| 78 | + rx_mpps = stats.rx_pps / 1_000_000 |
| 79 | + |
| 80 | + return rx_mpps |
| 81 | + |
| 82 | + def _produce_stats_table(self, test_parameters: list[dict[str, int | float]]) -> None: |
| 83 | + """Display performance results in table format and write to structured JSON file. |
| 84 | +
|
| 85 | + Args: |
| 86 | + test_parameters: The expected and real stats per set of test parameters. |
| 87 | + """ |
| 88 | + header = f"{'Frame Size':>12} | {'TXD/RXD':>12} | {'Real MPPS':>12} | {'Expected MPPS':>14}" |
| 89 | + print("-" * len(header)) |
| 90 | + print(header) |
| 91 | + print("-" * len(header)) |
| 92 | + for params in test_parameters: |
| 93 | + print(f"{params['frame_size']:>12} | {params['num_descriptors']:>12} | ", end="") |
| 94 | + print(f"{params['measured_mpps']:>12.2f} | {params['expected_mpps']:>14.2f}") |
| 95 | + print("-" * len(header)) |
| 96 | + |
| 97 | + write_performance_json({"results": test_parameters}) |
| 98 | + |
| 99 | + @perf_test |
| 100 | + def single_core_forward_perf(self) -> None: |
| 101 | + """Validate expected single core forwarding performance. |
| 102 | +
|
| 103 | + Steps: |
| 104 | + * Create a packet according to the frame size specified in the test config. |
| 105 | + * Transmit from the traffic generator's ports 0 and 1 at above the expect. |
| 106 | + * Forward on TestPMD's interfaces 0 and 1 with 1 core. |
| 107 | +
|
| 108 | + Verify: |
| 109 | + * The resulting MPPS forwarded is greater than expected_mpps*(1-delta_tolerance). |
| 110 | + """ |
| 111 | + # Find SUT DPDK driver to determine driver specific performance optimization flags |
| 112 | + sut_dpdk_driver = self._ctx.sut_node.config.ports[0].os_driver_for_dpdk |
| 113 | + |
| 114 | + for params in self.test_parameters: |
| 115 | + frame_size = params["frame_size"] |
| 116 | + num_descriptors = params["num_descriptors"] |
| 117 | + |
| 118 | + driver_specific_testpmd_args: TestPmdParamsDict = { |
| 119 | + "tx_ring": TXRingParams(descriptors=num_descriptors), |
| 120 | + "rx_ring": RXRingParams(descriptors=num_descriptors), |
| 121 | + "nb_cores": 1, |
| 122 | + } |
| 123 | + |
| 124 | + if sut_dpdk_driver == "mlx5_core": |
| 125 | + driver_specific_testpmd_args["burst"] = 64 |
| 126 | + driver_specific_testpmd_args["mbcache"] = 512 |
| 127 | + elif sut_dpdk_driver == "i40e": |
| 128 | + driver_specific_testpmd_args["rx_queues"] = 2 |
| 129 | + driver_specific_testpmd_args["tx_queues"] = 2 |
| 130 | + |
| 131 | + with TestPmd( |
| 132 | + **driver_specific_testpmd_args, |
| 133 | + ) as testpmd: |
| 134 | + params["measured_mpps"] = self._transmit(testpmd, frame_size) |
| 135 | + params["performance_delta"] = ( |
| 136 | + float(params["measured_mpps"]) - float(params["expected_mpps"]) |
| 137 | + ) / float(params["expected_mpps"]) |
| 138 | + params["pass"] = float(params["performance_delta"]) >= -self.delta_tolerance |
| 139 | + |
| 140 | + self._produce_stats_table(self.test_parameters) |
| 141 | + |
| 142 | + for params in self.test_parameters: |
| 143 | + verify( |
| 144 | + params["pass"] is True, |
| 145 | + f"""Packets forwarded is less than {(1 -self.delta_tolerance)*100}% |
| 146 | + of the expected baseline. |
| 147 | + Measured MPPS = {params["measured_mpps"]} |
| 148 | + Expected MPPS = {params["expected_mpps"]}""", |
| 149 | + ) |
0 commit comments