diff --git a/.github/workflows/ci-p4tools.yml b/.github/workflows/ci-p4tools.yml index de2fe523c5d..7f5c6d9e064 100644 --- a/.github/workflows/ci-p4tools.yml +++ b/.github/workflows/ci-p4tools.yml @@ -37,8 +37,9 @@ jobs: - name: Build (Ubuntu 22.04) run: | tools/ci-build.sh + pip3 list --verbose - name: Run tests (Ubuntu 22.04) # Need to use sudo for the eBPF kernel tests. - run: sudo -E ctest -R "testgen|smith" --output-on-failure --schedule-random + run: sudo -E PTF_PACKET_MANIPULATION_MODULE="bf_pktpy.ptf.packet_pktpy" ctest -R "testgen|smith" --output-on-failure --schedule-random working-directory: ./build diff --git a/.github/workflows/ci-ptf.yml b/.github/workflows/ci-ptf.yml index 3304f705ae4..ca13c2cb6ad 100644 --- a/.github/workflows/ci-ptf.yml +++ b/.github/workflows/ci-ptf.yml @@ -51,6 +51,7 @@ jobs: - name: Build (Ubuntu 20.04) run: | tools/ci-build.sh + pip3 list --verbose - name: Run PTF tests for eBPF backend (Ubuntu 20.04) run: sudo -E ./test.sh diff --git a/.github/workflows/ci-test-debian.yml b/.github/workflows/ci-test-debian.yml index 8645a72bd8e..773b0c77775 100644 --- a/.github/workflows/ci-test-debian.yml +++ b/.github/workflows/ci-test-debian.yml @@ -48,10 +48,11 @@ jobs: - name: Build (Ubuntu 22.04, GCC) run: | tools/ci-build.sh + pip3 list --verbose - name: Run tests (Ubuntu 22.04) # Need to use sudo for the eBPF kernel tests and need to avoid p4tc_stf tests. - run: sudo -E ctest --output-on-failure --schedule-random -E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup" + run: sudo -E PTF_PACKET_MANIPULATION_MODULE="bf_pktpy.ptf.packet_pktpy" ctest --output-on-failure --schedule-random -E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup" working-directory: ./build if: matrix.unity == 'ON' && matrix.gtest == 'ON' @@ -90,5 +91,5 @@ jobs: tools/ci-build.sh - name: Run tests (Ubuntu 22.04) - run: ctest --output-on-failure --schedule-random -R tofino + run: PTF_PACKET_MANIPULATION_MODULE="bf_pktpy.ptf.packet_pktpy" ctest --output-on-failure --schedule-random -R tofino working-directory: ./build diff --git a/.github/workflows/ci-test-fedora.yml b/.github/workflows/ci-test-fedora.yml index 3ba995b08f3..e1f0c04222e 100644 --- a/.github/workflows/ci-test-fedora.yml +++ b/.github/workflows/ci-test-fedora.yml @@ -47,9 +47,10 @@ jobs: run: | ./bootstrap.sh -DCMAKE_BUILD_TYPE=Release -DCMAKE_UNITY_BUILD=ON --build-generator "Ninja" cmake --build build -- -j $(nproc) + pip3 list --verbose - name: Run p4c tests (Fedora Linux) run: | # Avoid running p4tc stf tests for now - export PATH="$HOME/.local/bin:$PATH"; ctest --output-on-failure --schedule-random -E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup" + export PATH="$HOME/.local/bin:$PATH"; export PTF_PACKET_MANIPULATION_MODULE="bf_pktpy.ptf.packet_pktpy"; ctest --output-on-failure --schedule-random -E "p4tc_samples_stf|p4tc_cleanup|p4tc_setup" working-directory: ./build diff --git a/.github/workflows/ci-test-mac.yml b/.github/workflows/ci-test-mac.yml index 5cbe13fd110..7dca88d0463 100644 --- a/.github/workflows/ci-test-mac.yml +++ b/.github/workflows/ci-test-mac.yml @@ -54,11 +54,12 @@ jobs: ./bootstrap.sh -DENABLE_GC=ON -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_UNITY_BUILD=ON -DENABLE_TEST_TOOLS=ON -DENABLE_WERROR=ON --build-generator "Ninja" cmake --build build -- -j $(nproc) + pip3 list --verbose - name: Run tests (MacOS) run: | source ~/.bash_profile - ctest --output-on-failure --schedule-random -E "bpf|ubpf|testgen|smith|p4tc" + PTF_PACKET_MANIPULATION_MODULE="bf_pktpy.ptf.packet_pktpy" ctest --output-on-failure --schedule-random -E "bpf|ubpf|testgen|smith|p4tc" working-directory: ./build # Build and test p4c on MacOS 13 on x86. @@ -105,5 +106,5 @@ jobs: - name: Run tests (MacOS) run: | source ~/.bash_profile - ctest --output-on-failure --schedule-random -E "bpf|ubpf|testgen|smith|p4tc" + PTF_PACKET_MANIPULATION_MODULE="bf_pktpy.ptf.packet_pktpy" ctest --output-on-failure --schedule-random -E "bpf|ubpf|testgen|smith|p4tc" working-directory: ./build diff --git a/.github/workflows/ci-ubuntu-p4tc-stf.yml b/.github/workflows/ci-ubuntu-p4tc-stf.yml index 62b7c6a3093..f691690f850 100644 --- a/.github/workflows/ci-ubuntu-p4tc-stf.yml +++ b/.github/workflows/ci-ubuntu-p4tc-stf.yml @@ -37,6 +37,7 @@ jobs: - name: Build (Ubuntu 22.04, GCC) run: | tools/ci-build.sh + pip3 list --verbose - name: Run tests (Ubuntu 22.04) # Need to use sudo for the eBPF kernel tests. diff --git a/CMakeLists.txt b/CMakeLists.txt index cb89acdf83a..6e1de20d938 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -284,10 +284,6 @@ find_python_module (re REQUIRED) # other packages find_package (Doxygen) find_package (BMV2) -# If we have found simple switch or psa switch or pna_nic, we also need scapy. -if(SIMPLE_SWITCH OR PSA_SWITCH OR PNA_NIC) - find_python_module (scapy REQUIRED) -endif() # enable CTest enable_testing () diff --git a/backends/bmv2/README.md b/backends/bmv2/README.md index 5a0e0322013..57e963b4f80 100644 --- a/backends/bmv2/README.md +++ b/backends/bmv2/README.md @@ -30,8 +30,6 @@ To run and test this back-end you need some additional tools: - the BMv2 behavioral model itself. Installation instructions are available [here](https://github.com/p4lang/behavioral-model#installing-bmv2). You may need to update your dynamic libraries after installing bmv2: `sudo ldconfig` -- the Python scapy library `sudo pip3 install scapy` - # Unsupported P4_16 language features Here are some unsupported features we are aware of. We will update this list as diff --git a/backends/ebpf/README.md b/backends/ebpf/README.md index 0ee14ed370a..fd07051dfdc 100644 --- a/backends/ebpf/README.md +++ b/backends/ebpf/README.md @@ -237,7 +237,8 @@ Additionally, the eBPF compiler test suite has the following python dependencies - The python ply package to parse .stf testing files. -- The python scapy package to read and write pcap files. +- The python scapy package, to easily construct test packets with + selected sequences of headers. You can install these using: ``` diff --git a/backends/ebpf/tests/test.sh b/backends/ebpf/tests/test.sh index 5395639fc02..217a0395fda 100755 --- a/backends/ebpf/tests/test.sh +++ b/backends/ebpf/tests/test.sh @@ -179,6 +179,7 @@ for xdp_enabled in "${XDP[@]}" ; do TEST_PARAMS+=";xdp='$xdp_enabled';xdp2tc='$xdp2tc_mode'" # Start tests ptf \ + --packet-manipulation-module ptf.packet_scapy \ --test-dir ptf/ \ --test-params="$TEST_PARAMS" \ --interface 0@s1-eth0 --interface 1@s1-eth1 --interface 2@s1-eth2 --interface 3@s1-eth3 \ diff --git a/backends/tc/runtime/send_packet b/backends/tc/runtime/send_packet index 4cf4f9e8591..179a5335145 100755 --- a/backends/tc/runtime/send_packet +++ b/backends/tc/runtime/send_packet @@ -1,10 +1,22 @@ #!/usr/bin/env python3 # Copyright 2025 Intel Corporation -# SPDX-License-Identifier: GPL-2.0-only -# Reason-GPL: imports-scapy +# SPDX-License-Identifier: Apache-2.0 +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import argparse -from scapy.all import sendp, rdpcap +import ptf +from ptf.pcap_writer import rdpcap +from ptf.packet import sendp PARSER = argparse.ArgumentParser() PARSER.add_argument("pcap_file", help="PCAP file to send") diff --git a/requirements.txt b/requirements.txt index 21c86cb21cd..4adf8a454d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,11 +3,10 @@ pyroute2==0.7.3 ply==3.11 # Version 0.10.0 -ptf @ git+https://github.com/p4lang/ptf@d016cdfe99f2d609cc9c7fd7f8c414b56d5b3c5c +ptf @ git+https://github.com/p4lang/ptf@e29ef7ec0bd34d4ceef88016383e53238ab5383c # FIXME: We should figure out a way to synchronize P4Runtime versions across CMake and Python. # This is the same commit hash as defined in the top-level CMakelists.txt p4runtime @ git+https://github.com/p4lang/p4runtime@ec4eb5ef70dbcbcbf2f8357a4b2b8c2f218845a5#subdirectory=py -scapy==2.5.0 clang-format==18.1.0 isort==5.13.2; python_version > '3.6' black==24.3.0; python_version > '3.6' diff --git a/tools/ci-build.sh b/tools/ci-build.sh index 0d25df3ba1c..d6773c84cc2 100755 --- a/tools/ci-build.sh +++ b/tools/ci-build.sh @@ -207,6 +207,7 @@ function install_ptf_ebpf_test_deps() ( make "-j$(nproc)" sudo make install popd + sudo pip3 install scapy==2.5.0 ) if [[ "${ENABLE_EBPF}" == "ON" ]] ; then diff --git a/tools/install_fedora_deps.sh b/tools/install_fedora_deps.sh index b72f7c577a1..9261d5a1506 100755 --- a/tools/install_fedora_deps.sh +++ b/tools/install_fedora_deps.sh @@ -50,6 +50,7 @@ sudo dnf install -y -q \ pkg-config \ procps-ng \ python3 \ + python3-devel \ python3-pip \ python3-thrift \ readline-devel \