diff --git a/backends/tc/runtime/send_packet b/backends/tc/runtime/send_packet index 0fa171c4d0f..4cf4f9e8591 100755 --- a/backends/tc/runtime/send_packet +++ b/backends/tc/runtime/send_packet @@ -1,15 +1,7 @@ #!/usr/bin/env python3 -# 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. +# Copyright 2025 Intel Corporation +# SPDX-License-Identifier: GPL-2.0-only +# Reason-GPL: imports-scapy import argparse from scapy.all import sendp, rdpcap diff --git a/backends/tc/test_infra.py b/backends/tc/test_infra.py index ad35683dd7a..e0f0630bf22 100644 --- a/backends/tc/test_infra.py +++ b/backends/tc/test_infra.py @@ -10,13 +10,13 @@ # 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. -""" Represents the call which contains all methods needed to execute a TC - test. Currently five phases are defined: - 1. Invokes the specified compiler on a provided p4 file. - 2. Parses an stf file and generates a pcap output. - 3. Loads the generated template nd the eBPF binaries - 4. Feeds the generated pcap test packets into scapy - 5. Evaluates the output with the expected result from the .stf file +"""Represents the call which contains all methods needed to execute a TC + test. Currently five phases are defined: +1. Invokes the specified compiler on a provided p4 file. +2. Parses an stf file and generates a pcap output. +3. Loads the generated template nd the eBPF binaries +4. Feeds the generated pcap test packets into ptf.pcap_writer.PcapWriter +5. Evaluates the output with the expected result from the .stf file """ import difflib @@ -40,9 +40,8 @@ sys.path.append(str(FILE_DIR.joinpath("../../tools"))) sys.path.append(str(FILE_DIR.joinpath("../ebpf/targets"))) -import scapy.utils as scapy_util import testutils -from scapy.all import sendp +from ptf.pcap_writer import LINKTYPE_ETHERNET, PcapWriter, rdpcap from stf.stf_parser import STFParser PCAP_PREFIX = "pcap" # match pattern @@ -271,12 +270,10 @@ def _send_pcap_files(self, iface_pkts_map): for iface, pkts in iface_pkts_map.items(): direction = "in" infile = self.filename(self.runtimedir, iface, direction) - # Linktype 1 the Ethernet Link Type, see also 'man pcap-linktype' - fp = scapy_util.RawPcapWriter(infile, linktype=1) - fp._write_header(None) + fp = PcapWriter(infile, linktype=LINKTYPE_ETHERNET) for pkt_data in pkts: try: - fp._write_packet(pkt_data) + fp.write(pkt_data) except ValueError: testutils.log.error(f"Invalid packet data {pkt_data}") return testutils.ProcessResult("", testutils.FAILURE) @@ -502,7 +499,7 @@ def check_outputs(self): packets = [] else: try: - packets = scapy_util.rdpcap(file) + packets = rdpcap(file) except Exception as e: testutils.log.error("Corrupt pcap file %s\n%s", file, e) return testutils.FAILURE